print.html 677 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001
  1. <!DOCTYPE HTML>
  2. <html lang="en" class="sidebar-visible no-js light">
  3. <head>
  4. <!-- Book generated using mdBook -->
  5. <meta charset="UTF-8">
  6. <title>Synapse</title>
  7. <meta name="robots" content="noindex" />
  8. <!-- Custom HTML head -->
  9. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  10. <meta name="description" content="">
  11. <meta name="viewport" content="width=device-width, initial-scale=1">
  12. <meta name="theme-color" content="#ffffff" />
  13. <link rel="icon" href="favicon.svg">
  14. <link rel="shortcut icon" href="favicon.png">
  15. <link rel="stylesheet" href="css/variables.css">
  16. <link rel="stylesheet" href="css/general.css">
  17. <link rel="stylesheet" href="css/chrome.css">
  18. <link rel="stylesheet" href="css/print.css" media="print">
  19. <!-- Fonts -->
  20. <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
  21. <link rel="stylesheet" href="fonts/fonts.css">
  22. <!-- Highlight.js Stylesheets -->
  23. <link rel="stylesheet" href="highlight.css">
  24. <link rel="stylesheet" href="tomorrow-night.css">
  25. <link rel="stylesheet" href="ayu-highlight.css">
  26. <!-- Custom theme stylesheets -->
  27. <link rel="stylesheet" href="docs/website_files/table-of-contents.css">
  28. <link rel="stylesheet" href="docs/website_files/remove-nav-buttons.css">
  29. <link rel="stylesheet" href="docs/website_files/indent-section-headers.css">
  30. </head>
  31. <body>
  32. <!-- Provide site root to javascript -->
  33. <script type="text/javascript">
  34. var path_to_root = "";
  35. var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
  36. </script>
  37. <!-- Work around some values being stored in localStorage wrapped in quotes -->
  38. <script type="text/javascript">
  39. try {
  40. var theme = localStorage.getItem('mdbook-theme');
  41. var sidebar = localStorage.getItem('mdbook-sidebar');
  42. if (theme.startsWith('"') && theme.endsWith('"')) {
  43. localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
  44. }
  45. if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
  46. localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
  47. }
  48. } catch (e) { }
  49. </script>
  50. <!-- Set the theme before any content is loaded, prevents flash -->
  51. <script type="text/javascript">
  52. var theme;
  53. try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
  54. if (theme === null || theme === undefined) { theme = default_theme; }
  55. var html = document.querySelector('html');
  56. html.classList.remove('no-js')
  57. html.classList.remove('light')
  58. html.classList.add(theme);
  59. html.classList.add('js');
  60. </script>
  61. <!-- Hide / unhide sidebar before it is displayed -->
  62. <script type="text/javascript">
  63. var html = document.querySelector('html');
  64. var sidebar = 'hidden';
  65. if (document.body.clientWidth >= 1080) {
  66. try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
  67. sidebar = sidebar || 'visible';
  68. }
  69. html.classList.remove('sidebar-visible');
  70. html.classList.add("sidebar-" + sidebar);
  71. </script>
  72. <nav id="sidebar" class="sidebar" aria-label="Table of contents">
  73. <div class="sidebar-scrollbox">
  74. <ol class="chapter"><li class="chapter-item expanded affix "><li class="part-title">Introduction</li><li class="chapter-item expanded "><a href="welcome_and_overview.html">Welcome and Overview</a></li><li class="chapter-item expanded affix "><li class="part-title">Setup</li><li class="chapter-item expanded "><a href="setup/installation.html">Installation</a></li><li class="chapter-item expanded "><a href="postgres.html">Using Postgres</a></li><li class="chapter-item expanded "><a href="reverse_proxy.html">Configuring a Reverse Proxy</a></li><li class="chapter-item expanded "><a href="setup/forward_proxy.html">Configuring a Forward/Outbound Proxy</a></li><li class="chapter-item expanded "><a href="turn-howto.html">Configuring a Turn Server</a></li><li class="chapter-item expanded "><a href="delegate.html">Delegation</a></li><li class="chapter-item expanded affix "><li class="part-title">Upgrading</li><li class="chapter-item expanded "><a href="upgrade.html">Upgrading between Synapse Versions</a></li><li class="chapter-item expanded "><a href="MSC1711_certificates_FAQ.html">Upgrading from pre-Synapse 1.0</a></li><li class="chapter-item expanded affix "><li class="part-title">Usage</li><li class="chapter-item expanded "><a href="federate.html">Federation</a></li><li class="chapter-item expanded "><a href="usage/configuration/index.html">Configuration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/configuration/homeserver_sample_config.html">Homeserver Sample Config File</a></li><li class="chapter-item expanded "><a href="usage/configuration/logging_sample_config.html">Logging Sample Config File</a></li><li class="chapter-item expanded "><a href="structured_logging.html">Structured Logging</a></li><li class="chapter-item expanded "><a href="templates.html">Templates</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/index.html">User Authentication</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single-Sign On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="openid.html">OpenID Connect</a></li><li class="chapter-item expanded "><div>SAML</div></li><li class="chapter-item expanded "><div>CAS</div></li><li class="chapter-item expanded "><a href="sso_mapping_providers.html">SSO Mapping Providers</a></li></ol></li><li class="chapter-item expanded "><a href="password_auth_providers.html">Password Auth Providers</a></li><li class="chapter-item expanded "><a href="jwt.html">JSON Web Tokens</a></li></ol></li><li class="chapter-item expanded "><a href="CAPTCHA_SETUP.html">Registration Captcha</a></li><li class="chapter-item expanded "><a href="application_services.html">Application Services</a></li><li class="chapter-item expanded "><a href="server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="consent_tracking.html">Consent Tracking</a></li><li class="chapter-item expanded "><a href="url_previews.html">URL Previews</a></li><li class="chapter-item expanded "><a href="user_directory.html">User Directory</a></li><li class="chapter-item expanded "><a href="message_retention_policies.html">Message Retention Policies</a></li><li class="chapter-item expanded "><a href="modules.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Third Party Rules</div></li><li class="chapter-item expanded "><a href="spam_checker.html">Spam Checker</a></li><li class="chapter-item expanded "><a href="presence_router_module.html">Presence Router</a></li><li class="chapter-item expanded "><div>Media Storage Providers</div></li></ol></li><li class="chapter-item expanded "><a href="workers.html">Workers</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="synctl_workers.html">Using synctl with Workers</a></li><li class="chapter-item expanded "><a href="systemd-with-workers/index.html">Systemd</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/index.html">Administration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/admin_api/index.html">Admin API</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="admin_api/account_validity.html">Account Validity</a></li><li class="chapter-item expanded "><a href="admin_api/delete_group.html">Delete Group</a></li><li class="chapter-item expanded "><a href="admin_api/event_reports.html">Event Reports</a></li><li class="chapter-item expanded "><a href="admin_api/media_admin_api.html">Media</a></li><li class="chapter-item expanded "><a href="admin_api/purge_history_api.html">Purge History</a></li><li class="chapter-item expanded "><a href="admin_api/purge_room.html">Purge Rooms</a></li><li class="chapter-item expanded "><a href="admin_api/register_api.html">Register Users</a></li><li class="chapter-item expanded "><a href="admin_api/room_membership.html">Manipulate Room Membership</a></li><li class="chapter-item expanded "><a href="admin_api/rooms.html">Rooms</a></li><li class="chapter-item expanded "><a href="admin_api/server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="admin_api/shutdown_room.html">Shutdown Room</a></li><li class="chapter-item expanded "><a href="admin_api/statistics.html">Statistics</a></li><li class="chapter-item expanded "><a href="admin_api/user_admin_api.html">Users</a></li><li class="chapter-item expanded "><a href="admin_api/version_api.html">Server Version</a></li></ol></li><li class="chapter-item expanded "><a href="manhole.html">Manhole</a></li><li class="chapter-item expanded "><a href="metrics-howto.html">Monitoring</a></li><li class="chapter-item expanded "><a href="usage/administration/request_log.html">Request log format</a></li><li class="chapter-item expanded "><div>Scripts</div></li></ol></li><li class="chapter-item expanded "><li class="part-title">Development</li><li class="chapter-item expanded "><a href="development/contributing_guide.html">Contributing Guide</a></li><li class="chapter-item expanded "><a href="code_style.html">Code Style</a></li><li class="chapter-item expanded "><a href="development/git.html">Git Usage</a></li><li class="chapter-item expanded "><div>Testing</div></li><li class="chapter-item expanded "><a href="opentracing.html">OpenTracing</a></li><li class="chapter-item expanded "><a href="development/database_schema.html">Database Schemas</a></li><li class="chapter-item expanded "><div>Synapse Architecture</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="log_contexts.html">Log Contexts</a></li><li class="chapter-item expanded "><a href="replication.html">Replication</a></li><li class="chapter-item expanded "><a href="tcp_replication.html">TCP Replication</a></li></ol></li><li class="chapter-item expanded "><a href="development/internal_documentation/index.html">Internal Documentation</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single Sign-On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="development/cas.html">CAS</a></li></ol></li><li class="chapter-item expanded "><a href="development/room-dag-concepts.html">Room DAG concepts</a></li><li class="chapter-item expanded "><div>State Resolution</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="auth_chain_difference_algorithm.html">The Auth Chain Difference Algorithm</a></li></ol></li><li class="chapter-item expanded "><a href="media_repository.html">Media Repository</a></li><li class="chapter-item expanded "><a href="room_and_user_statistics.html">Room and User Statistics</a></li></ol></li><li class="chapter-item expanded "><div>Scripts</div></li><li class="chapter-item expanded affix "><li class="part-title">Other</li><li class="chapter-item expanded "><a href="deprecation_policy.html">Dependency Deprecation Policy</a></li></ol>
  75. </div>
  76. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  77. </nav>
  78. <div id="page-wrapper" class="page-wrapper">
  79. <div class="page">
  80. <div id="menu-bar-hover-placeholder"></div>
  81. <div id="menu-bar" class="menu-bar sticky bordered">
  82. <div class="left-buttons">
  83. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  84. <i class="fa fa-bars"></i>
  85. </button>
  86. <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
  87. <i class="fa fa-paint-brush"></i>
  88. </button>
  89. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  90. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  91. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  94. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  95. </ul>
  96. <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
  97. <i class="fa fa-search"></i>
  98. </button>
  99. </div>
  100. <h1 class="menu-title">Synapse</h1>
  101. <div class="right-buttons">
  102. <a href="print.html" title="Print this book" aria-label="Print this book">
  103. <i id="print-button" class="fa fa-print"></i>
  104. </a>
  105. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  106. <i id="git-repository-button" class="fa fa-github"></i>
  107. </a>
  108. </div>
  109. </div>
  110. <div id="search-wrapper" class="hidden">
  111. <form id="searchbar-outer" class="searchbar-outer">
  112. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  113. </form>
  114. <div id="searchresults-outer" class="searchresults-outer hidden">
  115. <div id="searchresults-header" class="searchresults-header"></div>
  116. <ul id="searchresults">
  117. </ul>
  118. </div>
  119. </div>
  120. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  121. <script type="text/javascript">
  122. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  123. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  124. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  125. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  126. });
  127. </script>
  128. <div id="content" class="content">
  129. <main>
  130. <!-- Page table of contents -->
  131. <div class="sidetoc">
  132. <nav class="pagetoc"></nav>
  133. </div>
  134. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="introduction"><a class="header" href="#introduction">Introduction</a></h1>
  135. <p>Welcome to the documentation repository for Synapse, the reference
  136. <a href="https://matrix.org">Matrix</a> homeserver implementation.</p>
  137. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="installation-instructions"><a class="header" href="#installation-instructions">Installation Instructions</a></h1>
  138. <p>There are 3 steps to follow under <strong>Installation Instructions</strong>.</p>
  139. <ul>
  140. <li><a href="setup/installation.html#installation-instructions">Installation Instructions</a>
  141. <ul>
  142. <li><a href="setup/installation.html#choosing-your-server-name">Choosing your server name</a></li>
  143. <li><a href="setup/installation.html#installing-synapse">Installing Synapse</a>
  144. <ul>
  145. <li><a href="setup/installation.html#installing-from-source">Installing from source</a>
  146. <ul>
  147. <li><a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a>
  148. <ul>
  149. <li><a href="setup/installation.html#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></li>
  150. <li><a href="setup/installation.html#archlinux">ArchLinux</a></li>
  151. <li><a href="setup/installation.html#centosfedora">CentOS/Fedora</a></li>
  152. <li><a href="setup/installation.html#macos">macOS</a></li>
  153. <li><a href="setup/installation.html#opensuse">OpenSUSE</a></li>
  154. <li><a href="setup/installation.html#openbsd">OpenBSD</a></li>
  155. <li><a href="setup/installation.html#windows">Windows</a></li>
  156. </ul>
  157. </li>
  158. </ul>
  159. </li>
  160. <li><a href="setup/installation.html#prebuilt-packages">Prebuilt packages</a>
  161. <ul>
  162. <li><a href="setup/installation.html#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></li>
  163. <li><a href="setup/installation.html#debianubuntu">Debian/Ubuntu</a>
  164. <ul>
  165. <li><a href="setup/installation.html#matrixorg-packages">Matrix.org packages</a></li>
  166. <li><a href="setup/installation.html#downstream-debian-packages">Downstream Debian packages</a></li>
  167. <li><a href="setup/installation.html#downstream-ubuntu-packages">Downstream Ubuntu packages</a></li>
  168. </ul>
  169. </li>
  170. <li><a href="setup/installation.html#fedora">Fedora</a></li>
  171. <li><a href="setup/installation.html#opensuse-1">OpenSUSE</a></li>
  172. <li><a href="setup/installation.html#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></li>
  173. <li><a href="setup/installation.html#archlinux-1">ArchLinux</a></li>
  174. <li><a href="setup/installation.html#void-linux">Void Linux</a></li>
  175. <li><a href="setup/installation.html#freebsd">FreeBSD</a></li>
  176. <li><a href="setup/installation.html#openbsd-1">OpenBSD</a></li>
  177. <li><a href="setup/installation.html#nixos">NixOS</a></li>
  178. </ul>
  179. </li>
  180. </ul>
  181. </li>
  182. <li><a href="setup/installation.html#setting-up-synapse">Setting up Synapse</a>
  183. <ul>
  184. <li><a href="setup/installation.html#using-postgresql">Using PostgreSQL</a></li>
  185. <li><a href="setup/installation.html#tls-certificates">TLS certificates</a></li>
  186. <li><a href="setup/installation.html#client-well-known-uri">Client Well-Known URI</a></li>
  187. <li><a href="setup/installation.html#email">Email</a></li>
  188. <li><a href="setup/installation.html#registering-a-user">Registering a user</a></li>
  189. <li><a href="setup/installation.html#setting-up-a-turn-server">Setting up a TURN server</a></li>
  190. <li><a href="setup/installation.html#url-previews">URL previews</a></li>
  191. <li><a href="setup/installation.html#troubleshooting-installation">Troubleshooting Installation</a></li>
  192. </ul>
  193. </li>
  194. </ul>
  195. </li>
  196. </ul>
  197. <h2 id="choosing-your-server-name"><a class="header" href="#choosing-your-server-name">Choosing your server name</a></h2>
  198. <p>It is important to choose the name for your server before you install Synapse,
  199. because it cannot be changed later.</p>
  200. <p>The server name determines the &quot;domain&quot; part of user-ids for users on your
  201. server: these will all be of the format <code>@user:my.domain.name</code>. It also
  202. determines how other matrix servers will reach yours for federation.</p>
  203. <p>For a test configuration, set this to the hostname of your server. For a more
  204. production-ready setup, you will probably want to specify your domain
  205. (<code>example.com</code>) rather than a matrix-specific hostname here (in the same way
  206. that your email address is probably <code>user@example.com</code> rather than
  207. <code>user@email.example.com</code>) - but doing so may require more advanced setup: see
  208. <a href="setup/../federate.html">Setting up Federation</a>.</p>
  209. <h2 id="installing-synapse"><a class="header" href="#installing-synapse">Installing Synapse</a></h2>
  210. <h3 id="installing-from-source"><a class="header" href="#installing-from-source">Installing from source</a></h3>
  211. <p>(Prebuilt packages are available for some platforms - see <a href="setup/installation.html#prebuilt-packages">Prebuilt packages</a>.)</p>
  212. <p>When installing from source please make sure that the <a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a> are already installed.</p>
  213. <p>System requirements:</p>
  214. <ul>
  215. <li>POSIX-compliant system (tested on Linux &amp; OS X)</li>
  216. <li>Python 3.5.2 or later, up to Python 3.9.</li>
  217. <li>At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org</li>
  218. </ul>
  219. <p>To install the Synapse homeserver run:</p>
  220. <pre><code class="language-sh">mkdir -p ~/synapse
  221. virtualenv -p python3 ~/synapse/env
  222. source ~/synapse/env/bin/activate
  223. pip install --upgrade pip
  224. pip install --upgrade setuptools
  225. pip install matrix-synapse
  226. </code></pre>
  227. <p>This will download Synapse from <a href="https://pypi.org/project/matrix-synapse">PyPI</a>
  228. and install it, along with the python libraries it uses, into a virtual environment
  229. under <code>~/synapse/env</code>. Feel free to pick a different directory if you
  230. prefer.</p>
  231. <p>This Synapse installation can then be later upgraded by using pip again with the
  232. update flag:</p>
  233. <pre><code class="language-sh">source ~/synapse/env/bin/activate
  234. pip install -U matrix-synapse
  235. </code></pre>
  236. <p>Before you can start Synapse, you will need to generate a configuration
  237. file. To do this, run (in your virtualenv, as before):</p>
  238. <pre><code class="language-sh">cd ~/synapse
  239. python -m synapse.app.homeserver \
  240. --server-name my.domain.name \
  241. --config-path homeserver.yaml \
  242. --generate-config \
  243. --report-stats=[yes|no]
  244. </code></pre>
  245. <p>... substituting an appropriate value for <code>--server-name</code>.</p>
  246. <p>This command will generate you a config file that you can then customise, but it will
  247. also generate a set of keys for you. These keys will allow your homeserver to
  248. identify itself to other homeserver, so don't lose or delete them. It would be
  249. wise to back them up somewhere safe. (If, for whatever reason, you do need to
  250. change your homeserver's keys, you may find that other homeserver have the
  251. old key cached. If you update the signing key, you should change the name of the
  252. key in the <code>&lt;server name&gt;.signing.key</code> file (the second word) to something
  253. different. See the <a href="https://matrix.org/docs/spec/server_server/latest.html#retrieving-server-keys">spec</a> for more information on key management).</p>
  254. <p>To actually run your new homeserver, pick a working directory for Synapse to
  255. run (e.g. <code>~/synapse</code>), and:</p>
  256. <pre><code class="language-sh">cd ~/synapse
  257. source env/bin/activate
  258. synctl start
  259. </code></pre>
  260. <h4 id="platform-specific-prerequisites"><a class="header" href="#platform-specific-prerequisites">Platform-specific prerequisites</a></h4>
  261. <p>Synapse is written in Python but some of the libraries it uses are written in
  262. C. So before we can install Synapse itself we need a working C compiler and the
  263. header files for Python C extensions.</p>
  264. <h5 id="debianubunturaspbian"><a class="header" href="#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></h5>
  265. <p>Installing prerequisites on Ubuntu or Debian:</p>
  266. <pre><code class="language-sh">sudo apt install build-essential python3-dev libffi-dev \
  267. python3-pip python3-setuptools sqlite3 \
  268. libssl-dev virtualenv libjpeg-dev libxslt1-dev
  269. </code></pre>
  270. <h5 id="archlinux"><a class="header" href="#archlinux">ArchLinux</a></h5>
  271. <p>Installing prerequisites on ArchLinux:</p>
  272. <pre><code class="language-sh">sudo pacman -S base-devel python python-pip \
  273. python-setuptools python-virtualenv sqlite3
  274. </code></pre>
  275. <h5 id="centosfedora"><a class="header" href="#centosfedora">CentOS/Fedora</a></h5>
  276. <p>Installing prerequisites on CentOS or Fedora Linux:</p>
  277. <pre><code class="language-sh">sudo dnf install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
  278. libwebp-devel libxml2-devel libxslt-devel libpq-devel \
  279. python3-virtualenv libffi-devel openssl-devel python3-devel
  280. sudo dnf groupinstall &quot;Development Tools&quot;
  281. </code></pre>
  282. <h5 id="macos"><a class="header" href="#macos">macOS</a></h5>
  283. <p>Installing prerequisites on macOS:</p>
  284. <p>You may need to install the latest Xcode developer tools:</p>
  285. <pre><code class="language-sh">xcode-select --install
  286. </code></pre>
  287. <p>On ARM-based Macs you may need to explicitly install libjpeg which is a pillow dependency. You can use Homebrew (https://brew.sh):</p>
  288. <pre><code class="language-sh"> brew install jpeg
  289. </code></pre>
  290. <p>On macOS Catalina (10.15) you may need to explicitly install OpenSSL
  291. via brew and inform <code>pip</code> about it so that <code>psycopg2</code> builds:</p>
  292. <pre><code class="language-sh">brew install openssl@1.1
  293. export LDFLAGS=&quot;-L/usr/local/opt/openssl/lib&quot;
  294. export CPPFLAGS=&quot;-I/usr/local/opt/openssl/include&quot;
  295. </code></pre>
  296. <h5 id="opensuse"><a class="header" href="#opensuse">OpenSUSE</a></h5>
  297. <p>Installing prerequisites on openSUSE:</p>
  298. <pre><code class="language-sh">sudo zypper in -t pattern devel_basis
  299. sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
  300. python-devel libffi-devel libopenssl-devel libjpeg62-devel
  301. </code></pre>
  302. <h5 id="openbsd"><a class="header" href="#openbsd">OpenBSD</a></h5>
  303. <p>A port of Synapse is available under <code>net/synapse</code>. The filesystem
  304. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  305. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  306. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  307. <p>To be able to build Synapse's dependency on python the <code>WRKOBJDIR</code>
  308. (cf. <code>bsd.port.mk(5)</code>) for building python, too, needs to be on a filesystem
  309. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>).</p>
  310. <p>Creating a <code>WRKOBJDIR</code> for building python under <code>/usr/local</code> (which on a
  311. default OpenBSD installation is mounted with <code>wxallowed</code>):</p>
  312. <pre><code class="language-sh">doas mkdir /usr/local/pobj_wxallowed
  313. </code></pre>
  314. <p>Assuming <code>PORTS_PRIVSEP=Yes</code> (cf. <code>bsd.port.mk(5)</code>) and <code>SUDO=doas</code> are
  315. configured in <code>/etc/mk.conf</code>:</p>
  316. <pre><code class="language-sh">doas chown _pbuild:_pbuild /usr/local/pobj_wxallowed
  317. </code></pre>
  318. <p>Setting the <code>WRKOBJDIR</code> for building python:</p>
  319. <pre><code class="language-sh">echo WRKOBJDIR_lang/python/3.7=/usr/local/pobj_wxallowed \\nWRKOBJDIR_lang/python/2.7=/usr/local/pobj_wxallowed &gt;&gt; /etc/mk.conf
  320. </code></pre>
  321. <p>Building Synapse:</p>
  322. <pre><code class="language-sh">cd /usr/ports/net/synapse
  323. make install
  324. </code></pre>
  325. <h5 id="windows"><a class="header" href="#windows">Windows</a></h5>
  326. <p>If you wish to run or develop Synapse on Windows, the Windows Subsystem For
  327. Linux provides a Linux environment on Windows 10 which is capable of using the
  328. Debian, Fedora, or source installation methods. More information about WSL can
  329. be found at <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">https://docs.microsoft.com/en-us/windows/wsl/install-win10</a> for
  330. Windows 10 and <a href="https://docs.microsoft.com/en-us/windows/wsl/install-on-server">https://docs.microsoft.com/en-us/windows/wsl/install-on-server</a>
  331. for Windows Server.</p>
  332. <h3 id="prebuilt-packages"><a class="header" href="#prebuilt-packages">Prebuilt packages</a></h3>
  333. <p>As an alternative to installing from source, prebuilt packages are available
  334. for a number of platforms.</p>
  335. <h4 id="docker-images-and-ansible-playbooks"><a class="header" href="#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></h4>
  336. <p>There is an official synapse image available at
  337. <a href="https://hub.docker.com/r/matrixdotorg/synapse">https://hub.docker.com/r/matrixdotorg/synapse</a> which can be used with
  338. the docker-compose file available at
  339. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/docker">contrib/docker</a>.
  340. Further information on this including configuration options is available in the README
  341. on hub.docker.com.</p>
  342. <p>Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a
  343. Dockerfile to automate a synapse server in a single Docker image, at
  344. <a href="https://hub.docker.com/r/avhost/docker-matrix/tags/">https://hub.docker.com/r/avhost/docker-matrix/tags/</a></p>
  345. <p>Slavi Pantaleev has created an Ansible playbook,
  346. which installs the offical Docker image of Matrix Synapse
  347. along with many other Matrix-related services (Postgres database, Element, coturn,
  348. ma1sd, SSL support, etc.).
  349. For more details, see
  350. <a href="https://github.com/spantaleev/matrix-docker-ansible-deploy">https://github.com/spantaleev/matrix-docker-ansible-deploy</a></p>
  351. <h4 id="debianubuntu"><a class="header" href="#debianubuntu">Debian/Ubuntu</a></h4>
  352. <h5 id="matrixorg-packages"><a class="header" href="#matrixorg-packages">Matrix.org packages</a></h5>
  353. <p>Matrix.org provides Debian/Ubuntu packages of Synapse via
  354. <a href="https://packages.matrix.org/debian/">https://packages.matrix.org/debian/</a>. To install the latest release:</p>
  355. <pre><code class="language-sh">sudo apt install -y lsb-release wget apt-transport-https
  356. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  357. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main&quot; |
  358. sudo tee /etc/apt/sources.list.d/matrix-org.list
  359. sudo apt update
  360. sudo apt install matrix-synapse-py3
  361. </code></pre>
  362. <p>Packages are also published for release candidates. To enable the prerelease
  363. channel, add <code>prerelease</code> to the <code>sources.list</code> line. For example:</p>
  364. <pre><code class="language-sh">sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  365. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main prerelease&quot; |
  366. sudo tee /etc/apt/sources.list.d/matrix-org.list
  367. sudo apt update
  368. sudo apt install matrix-synapse-py3
  369. </code></pre>
  370. <p>The fingerprint of the repository signing key (as shown by <code>gpg /usr/share/keyrings/matrix-org-archive-keyring.gpg</code>) is
  371. <code>AAF9AE843A7584B5A3E4CD2BCF45A512DE2DA058</code>.</p>
  372. <h5 id="downstream-debian-packages"><a class="header" href="#downstream-debian-packages">Downstream Debian packages</a></h5>
  373. <p>We do not recommend using the packages from the default Debian <code>buster</code>
  374. repository at this time, as they are old and suffer from known security
  375. vulnerabilities. You can install the latest version of Synapse from
  376. <a href="setup/installation.html#matrixorg-packages">our repository</a> or from <code>buster-backports</code>. Please
  377. see the <a href="https://backports.debian.org/Instructions/">Debian documentation</a>
  378. for information on how to use backports.</p>
  379. <p>If you are using Debian <code>sid</code> or testing, Synapse is available in the default
  380. repositories and it should be possible to install it simply with:</p>
  381. <pre><code class="language-sh">sudo apt install matrix-synapse
  382. </code></pre>
  383. <h5 id="downstream-ubuntu-packages"><a class="header" href="#downstream-ubuntu-packages">Downstream Ubuntu packages</a></h5>
  384. <p>We do not recommend using the packages in the default Ubuntu repository
  385. at this time, as they are old and suffer from known security vulnerabilities.
  386. The latest version of Synapse can be installed from <a href="setup/installation.html#matrixorg-packages">our repository</a>.</p>
  387. <h4 id="fedora"><a class="header" href="#fedora">Fedora</a></h4>
  388. <p>Synapse is in the Fedora repositories as <code>matrix-synapse</code>:</p>
  389. <pre><code class="language-sh">sudo dnf install matrix-synapse
  390. </code></pre>
  391. <p>Oleg Girko provides Fedora RPMs at
  392. <a href="https://obs.infoserver.lv/project/monitor/matrix-synapse">https://obs.infoserver.lv/project/monitor/matrix-synapse</a></p>
  393. <h4 id="opensuse-1"><a class="header" href="#opensuse-1">OpenSUSE</a></h4>
  394. <p>Synapse is in the OpenSUSE repositories as <code>matrix-synapse</code>:</p>
  395. <pre><code class="language-sh">sudo zypper install matrix-synapse
  396. </code></pre>
  397. <h4 id="suse-linux-enterprise-server"><a class="header" href="#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></h4>
  398. <p>Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at
  399. <a href="https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/">https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/</a></p>
  400. <h4 id="archlinux-1"><a class="header" href="#archlinux-1">ArchLinux</a></h4>
  401. <p>The quickest way to get up and running with ArchLinux is probably with the community package
  402. <a href="https://www.archlinux.org/packages/community/any/matrix-synapse/">https://www.archlinux.org/packages/community/any/matrix-synapse/</a>, which should pull in most of
  403. the necessary dependencies.</p>
  404. <p>pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):</p>
  405. <pre><code class="language-sh">sudo pip install --upgrade pip
  406. </code></pre>
  407. <p>If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  408. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  409. compile it under the right architecture. (This should not be needed if
  410. installing under virtualenv):</p>
  411. <pre><code class="language-sh">sudo pip uninstall py-bcrypt
  412. sudo pip install py-bcrypt
  413. </code></pre>
  414. <h4 id="void-linux"><a class="header" href="#void-linux">Void Linux</a></h4>
  415. <p>Synapse can be found in the void repositories as 'synapse':</p>
  416. <pre><code class="language-sh">xbps-install -Su
  417. xbps-install -S synapse
  418. </code></pre>
  419. <h4 id="freebsd"><a class="header" href="#freebsd">FreeBSD</a></h4>
  420. <p>Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:</p>
  421. <ul>
  422. <li>Ports: <code>cd /usr/ports/net-im/py-matrix-synapse &amp;&amp; make install clean</code></li>
  423. <li>Packages: <code>pkg install py37-matrix-synapse</code></li>
  424. </ul>
  425. <h4 id="openbsd-1"><a class="header" href="#openbsd-1">OpenBSD</a></h4>
  426. <p>As of OpenBSD 6.7 Synapse is available as a pre-compiled binary. The filesystem
  427. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  428. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  429. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  430. <p>Installing Synapse:</p>
  431. <pre><code class="language-sh">doas pkg_add synapse
  432. </code></pre>
  433. <h4 id="nixos"><a class="header" href="#nixos">NixOS</a></h4>
  434. <p>Robin Lambertz has packaged Synapse for NixOS at:
  435. <a href="https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/matrix-synapse.nix">https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/matrix-synapse.nix</a></p>
  436. <h2 id="setting-up-synapse"><a class="header" href="#setting-up-synapse">Setting up Synapse</a></h2>
  437. <p>Once you have installed synapse as above, you will need to configure it.</p>
  438. <h3 id="using-postgresql"><a class="header" href="#using-postgresql">Using PostgreSQL</a></h3>
  439. <p>By default Synapse uses an <a href="https://sqlite.org/">SQLite</a> database and in doing so trades
  440. performance for convenience. Almost all installations should opt to use <a href="https://www.postgresql.org">PostgreSQL</a>
  441. instead. Advantages include:</p>
  442. <ul>
  443. <li>significant performance improvements due to the superior threading and
  444. caching model, smarter query optimiser</li>
  445. <li>allowing the DB to be run on separate hardware</li>
  446. </ul>
  447. <p>For information on how to install and use PostgreSQL in Synapse, please see
  448. <a href="setup/../postgres.html">Using Postgres</a></p>
  449. <p>SQLite is only acceptable for testing purposes. SQLite should not be used in
  450. a production server. Synapse will perform poorly when using
  451. SQLite, especially when participating in large rooms.</p>
  452. <h3 id="tls-certificates"><a class="header" href="#tls-certificates">TLS certificates</a></h3>
  453. <p>The default configuration exposes a single HTTP port on the local
  454. interface: <code>http://localhost:8008</code>. It is suitable for local testing,
  455. but for any practical use, you will need Synapse's APIs to be served
  456. over HTTPS.</p>
  457. <p>The recommended way to do so is to set up a reverse proxy on port
  458. <code>8448</code>. You can find documentation on doing so in
  459. <a href="setup/../reverse_proxy.html">the reverse proxy documentation</a>.</p>
  460. <p>Alternatively, you can configure Synapse to expose an HTTPS port. To do
  461. so, you will need to edit <code>homeserver.yaml</code>, as follows:</p>
  462. <ul>
  463. <li>First, under the <code>listeners</code> section, uncomment the configuration for the
  464. TLS-enabled listener. (Remove the hash sign (<code>#</code>) at the start of
  465. each line). The relevant lines are like this:</li>
  466. </ul>
  467. <pre><code class="language-yaml"> - port: 8448
  468. type: http
  469. tls: true
  470. resources:
  471. - names: [client, federation]
  472. </code></pre>
  473. <ul>
  474. <li>
  475. <p>You will also need to uncomment the <code>tls_certificate_path</code> and
  476. <code>tls_private_key_path</code> lines under the <code>TLS</code> section. You will need to manage
  477. provisioning of these certificates yourself.</p>
  478. <p>If you are using your own certificate, be sure to use a <code>.pem</code> file that
  479. includes the full certificate chain including any intermediate certificates
  480. (for instance, if using certbot, use <code>fullchain.pem</code> as your certificate, not
  481. <code>cert.pem</code>).</p>
  482. </li>
  483. </ul>
  484. <p>For a more detailed guide to configuring your server for federation, see
  485. <a href="setup/../federate.html">Federation</a>.</p>
  486. <h3 id="client-well-known-uri"><a class="header" href="#client-well-known-uri">Client Well-Known URI</a></h3>
  487. <p>Setting up the client Well-Known URI is optional but if you set it up, it will
  488. allow users to enter their full username (e.g. <code>@user:&lt;server_name&gt;</code>) into clients
  489. which support well-known lookup to automatically configure the homeserver and
  490. identity server URLs. This is useful so that users don't have to memorize or think
  491. about the actual homeserver URL you are using.</p>
  492. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/client</code> should return JSON in
  493. the following format.</p>
  494. <pre><code class="language-json">{
  495. &quot;m.homeserver&quot;: {
  496. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  497. }
  498. }
  499. </code></pre>
  500. <p>It can optionally contain identity server information as well.</p>
  501. <pre><code class="language-json">{
  502. &quot;m.homeserver&quot;: {
  503. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  504. },
  505. &quot;m.identity_server&quot;: {
  506. &quot;base_url&quot;: &quot;https://&lt;identity.example.com&gt;&quot;
  507. }
  508. }
  509. </code></pre>
  510. <p>To work in browser based clients, the file must be served with the appropriate
  511. Cross-Origin Resource Sharing (CORS) headers. A recommended value would be
  512. <code>Access-Control-Allow-Origin: *</code> which would allow all browser based clients to
  513. view it.</p>
  514. <p>In nginx this would be something like:</p>
  515. <pre><code class="language-nginx">location /.well-known/matrix/client {
  516. return 200 '{&quot;m.homeserver&quot;: {&quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;}}';
  517. default_type application/json;
  518. add_header Access-Control-Allow-Origin *;
  519. }
  520. </code></pre>
  521. <p>You should also ensure the <code>public_baseurl</code> option in <code>homeserver.yaml</code> is set
  522. correctly. <code>public_baseurl</code> should be set to the URL that clients will use to
  523. connect to your server. This is the same URL you put for the <code>m.homeserver</code>
  524. <code>base_url</code> above.</p>
  525. <pre><code class="language-yaml">public_baseurl: &quot;https://&lt;matrix.example.com&gt;&quot;
  526. </code></pre>
  527. <h3 id="email"><a class="header" href="#email">Email</a></h3>
  528. <p>It is desirable for Synapse to have the capability to send email. This allows
  529. Synapse to send password reset emails, send verifications when an email address
  530. is added to a user's account, and send email notifications to users when they
  531. receive new messages.</p>
  532. <p>To configure an SMTP server for Synapse, modify the configuration section
  533. headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>, <code>smtp_port</code>
  534. and <code>notif_from</code> fields filled out. You may also need to set <code>smtp_user</code>,
  535. <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  536. <p>If email is not configured, password reset, registration and notifications via
  537. email will be disabled.</p>
  538. <h3 id="registering-a-user"><a class="header" href="#registering-a-user">Registering a user</a></h3>
  539. <p>The easiest way to create a new user is to do so from a client like <a href="https://element.io/">Element</a>.</p>
  540. <p>Alternatively, you can do so from the command line. This can be done as follows:</p>
  541. <ol>
  542. <li>If synapse was installed via pip, activate the virtualenv as follows (if Synapse was
  543. installed via a prebuilt package, <code>register_new_matrix_user</code> should already be
  544. on the search path):
  545. <pre><code class="language-sh">cd ~/synapse
  546. source env/bin/activate
  547. synctl start # if not already running
  548. </code></pre>
  549. </li>
  550. <li>Run the following command:
  551. <pre><code class="language-sh">register_new_matrix_user -c homeserver.yaml http://localhost:8008
  552. </code></pre>
  553. </li>
  554. </ol>
  555. <p>This will prompt you to add details for the new user, and will then connect to
  556. the running Synapse to create the new user. For example:</p>
  557. <pre><code>New user localpart: erikj
  558. Password:
  559. Confirm password:
  560. Make admin [no]:
  561. Success!
  562. </code></pre>
  563. <p>This process uses a setting <code>registration_shared_secret</code> in
  564. <code>homeserver.yaml</code>, which is shared between Synapse itself and the
  565. <code>register_new_matrix_user</code> script. It doesn't matter what it is (a random
  566. value is generated by <code>--generate-config</code>), but it should be kept secret, as
  567. anyone with knowledge of it can register users, including admin accounts,
  568. on your server even if <code>enable_registration</code> is <code>false</code>.</p>
  569. <h3 id="setting-up-a-turn-server"><a class="header" href="#setting-up-a-turn-server">Setting up a TURN server</a></h3>
  570. <p>For reliable VoIP calls to be routed via this homeserver, you MUST configure
  571. a TURN server. See <a href="setup/../turn-howto.html">TURN setup</a> for details.</p>
  572. <h3 id="url-previews"><a class="header" href="#url-previews">URL previews</a></h3>
  573. <p>Synapse includes support for previewing URLs, which is disabled by default. To
  574. turn it on you must enable the <code>url_preview_enabled: True</code> config parameter
  575. and explicitly specify the IP ranges that Synapse is not allowed to spider for
  576. previewing in the <code>url_preview_ip_range_blacklist</code> configuration parameter.
  577. This is critical from a security perspective to stop arbitrary Matrix users
  578. spidering 'internal' URLs on your network. At the very least we recommend that
  579. your loopback and RFC1918 IP addresses are blacklisted.</p>
  580. <p>This also requires the optional <code>lxml</code> python dependency to be installed. This
  581. in turn requires the <code>libxml2</code> library to be available - on Debian/Ubuntu this
  582. means <code>apt-get install libxml2-dev</code>, or equivalent for your OS.</p>
  583. <h3 id="troubleshooting-installation"><a class="header" href="#troubleshooting-installation">Troubleshooting Installation</a></h3>
  584. <p><code>pip</code> seems to leak <em>lots</em> of memory during installation. For instance, a Linux
  585. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  586. happens, you will have to individually install the dependencies which are
  587. failing, e.g.:</p>
  588. <pre><code class="language-sh">pip install twisted
  589. </code></pre>
  590. <p>If you have any other problems, feel free to ask in
  591. <a href="https://matrix.to/#/#synapse:matrix.org">#synapse:matrix.org</a>.</p>
  592. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="using-postgres"><a class="header" href="#using-postgres">Using Postgres</a></h1>
  593. <p>Synapse supports PostgreSQL versions 9.6 or later.</p>
  594. <h2 id="install-postgres-client-libraries"><a class="header" href="#install-postgres-client-libraries">Install postgres client libraries</a></h2>
  595. <p>Synapse will require the python postgres client library in order to
  596. connect to a postgres database.</p>
  597. <ul>
  598. <li>
  599. <p>If you are using the <a href="setup/installation.html#matrixorg-packages">matrix.org debian/ubuntu
  600. packages</a>, the necessary python
  601. library will already be installed, but you will need to ensure the
  602. low-level postgres library is installed, which you can do with
  603. <code>apt install libpq5</code>.</p>
  604. </li>
  605. <li>
  606. <p>For other pre-built packages, please consult the documentation from
  607. the relevant package.</p>
  608. </li>
  609. <li>
  610. <p>If you installed synapse <a href="setup/installation.html#installing-from-source">in a
  611. virtualenv</a>, you can install
  612. the library with:</p>
  613. <pre><code>~/synapse/env/bin/pip install &quot;matrix-synapse[postgres]&quot;
  614. </code></pre>
  615. <p>(substituting the path to your virtualenv for <code>~/synapse/env</code>, if
  616. you used a different path). You will require the postgres
  617. development files. These are in the <code>libpq-dev</code> package on
  618. Debian-derived distributions.</p>
  619. </li>
  620. </ul>
  621. <h2 id="set-up-database"><a class="header" href="#set-up-database">Set up database</a></h2>
  622. <p>Assuming your PostgreSQL database user is called <code>postgres</code>, first authenticate as the database user with:</p>
  623. <pre><code>su - postgres
  624. # Or, if your system uses sudo to get administrative rights
  625. sudo -u postgres bash
  626. </code></pre>
  627. <p>Then, create a postgres user and a database with:</p>
  628. <pre><code># this will prompt for a password for the new user
  629. createuser --pwprompt synapse_user
  630. createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse
  631. </code></pre>
  632. <p>The above will create a user called <code>synapse_user</code>, and a database called
  633. <code>synapse</code>.</p>
  634. <p>Note that the PostgreSQL database <em>must</em> have the correct encoding set
  635. (as shown above), otherwise it will not be able to store UTF8 strings.</p>
  636. <p>You may need to enable password authentication so <code>synapse_user</code> can
  637. connect to the database. See
  638. <a href="https://www.postgresql.org/docs/current/auth-pg-hba-conf.html">https://www.postgresql.org/docs/current/auth-pg-hba-conf.html</a>.</p>
  639. <h2 id="synapse-config"><a class="header" href="#synapse-config">Synapse config</a></h2>
  640. <p>When you are ready to start using PostgreSQL, edit the <code>database</code>
  641. section in your config file to match the following lines:</p>
  642. <pre><code class="language-yaml">database:
  643. name: psycopg2
  644. args:
  645. user: &lt;user&gt;
  646. password: &lt;pass&gt;
  647. database: &lt;db&gt;
  648. host: &lt;host&gt;
  649. cp_min: 5
  650. cp_max: 10
  651. </code></pre>
  652. <p>All key, values in <code>args</code> are passed to the <code>psycopg2.connect(..)</code>
  653. function, except keys beginning with <code>cp_</code>, which are consumed by the
  654. twisted adbapi connection pool. See the <a href="https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS">libpq
  655. documentation</a>
  656. for a list of options which can be passed.</p>
  657. <p>You should consider tuning the <code>args.keepalives_*</code> options if there is any danger of
  658. the connection between your homeserver and database dropping, otherwise Synapse
  659. may block for an extended period while it waits for a response from the
  660. database server. Example values might be:</p>
  661. <pre><code class="language-yaml">database:
  662. args:
  663. # ... as above
  664. # seconds of inactivity after which TCP should send a keepalive message to the server
  665. keepalives_idle: 10
  666. # the number of seconds after which a TCP keepalive message that is not
  667. # acknowledged by the server should be retransmitted
  668. keepalives_interval: 10
  669. # the number of TCP keepalives that can be lost before the client's connection
  670. # to the server is considered dead
  671. keepalives_count: 3
  672. </code></pre>
  673. <h2 id="tuning-postgres"><a class="header" href="#tuning-postgres">Tuning Postgres</a></h2>
  674. <p>The default settings should be fine for most deployments. For larger
  675. scale deployments tuning some of the settings is recommended, details of
  676. which can be found at
  677. <a href="https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server">https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server</a>.</p>
  678. <p>In particular, we've found tuning the following values helpful for
  679. performance:</p>
  680. <ul>
  681. <li><code>shared_buffers</code></li>
  682. <li><code>effective_cache_size</code></li>
  683. <li><code>work_mem</code></li>
  684. <li><code>maintenance_work_mem</code></li>
  685. <li><code>autovacuum_work_mem</code></li>
  686. </ul>
  687. <p>Note that the appropriate values for those fields depend on the amount
  688. of free memory the database host has available.</p>
  689. <h2 id="porting-from-sqlite"><a class="header" href="#porting-from-sqlite">Porting from SQLite</a></h2>
  690. <h3 id="overview"><a class="header" href="#overview">Overview</a></h3>
  691. <p>The script <code>synapse_port_db</code> allows porting an existing synapse server
  692. backed by SQLite to using PostgreSQL. This is done in as a two phase
  693. process:</p>
  694. <ol>
  695. <li>Copy the existing SQLite database to a separate location and run
  696. the port script against that offline database.</li>
  697. <li>Shut down the server. Rerun the port script to port any data that
  698. has come in since taking the first snapshot. Restart server against
  699. the PostgreSQL database.</li>
  700. </ol>
  701. <p>The port script is designed to be run repeatedly against newer snapshots
  702. of the SQLite database file. This makes it safe to repeat step 1 if
  703. there was a delay between taking the previous snapshot and being ready
  704. to do step 2.</p>
  705. <p>It is safe to at any time kill the port script and restart it.</p>
  706. <p>Note that the database may take up significantly more (25% - 100% more)
  707. space on disk after porting to Postgres.</p>
  708. <h3 id="using-the-port-script"><a class="header" href="#using-the-port-script">Using the port script</a></h3>
  709. <p>Firstly, shut down the currently running synapse server and copy its
  710. database file (typically <code>homeserver.db</code>) to another location. Once the
  711. copy is complete, restart synapse. For instance:</p>
  712. <pre><code>./synctl stop
  713. cp homeserver.db homeserver.db.snapshot
  714. ./synctl start
  715. </code></pre>
  716. <p>Copy the old config file into a new config file:</p>
  717. <pre><code>cp homeserver.yaml homeserver-postgres.yaml
  718. </code></pre>
  719. <p>Edit the database section as described in the section <em>Synapse config</em>
  720. above and with the SQLite snapshot located at <code>homeserver.db.snapshot</code>
  721. simply run:</p>
  722. <pre><code>synapse_port_db --sqlite-database homeserver.db.snapshot \
  723. --postgres-config homeserver-postgres.yaml
  724. </code></pre>
  725. <p>The flag <code>--curses</code> displays a coloured curses progress UI.</p>
  726. <p>If the script took a long time to complete, or time has otherwise passed
  727. since the original snapshot was taken, repeat the previous steps with a
  728. newer snapshot.</p>
  729. <p>To complete the conversion shut down the synapse server and run the port
  730. script one last time, e.g. if the SQLite database is at <code>homeserver.db</code>
  731. run:</p>
  732. <pre><code>synapse_port_db --sqlite-database homeserver.db \
  733. --postgres-config homeserver-postgres.yaml
  734. </code></pre>
  735. <p>Once that has completed, change the synapse config to point at the
  736. PostgreSQL database configuration file <code>homeserver-postgres.yaml</code>:</p>
  737. <pre><code>./synctl stop
  738. mv homeserver.yaml homeserver-old-sqlite.yaml
  739. mv homeserver-postgres.yaml homeserver.yaml
  740. ./synctl start
  741. </code></pre>
  742. <p>Synapse should now be running against PostgreSQL.</p>
  743. <h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
  744. <h3 id="alternative-auth-methods"><a class="header" href="#alternative-auth-methods">Alternative auth methods</a></h3>
  745. <p>If you get an error along the lines of <code>FATAL: Ident authentication failed for user &quot;synapse_user&quot;</code>, you may need to use an authentication method other than
  746. <code>ident</code>:</p>
  747. <ul>
  748. <li>
  749. <p>If the <code>synapse_user</code> user has a password, add the password to the <code>database:</code>
  750. section of <code>homeserver.yaml</code>. Then add the following to <code>pg_hba.conf</code>:</p>
  751. <pre><code>host synapse synapse_user ::1/128 md5 # or `scram-sha-256` instead of `md5` if you use that
  752. </code></pre>
  753. </li>
  754. <li>
  755. <p>If the <code>synapse_user</code> user does not have a password, then a password doesn't
  756. have to be added to <code>homeserver.yaml</code>. But the following does need to be added
  757. to <code>pg_hba.conf</code>:</p>
  758. <pre><code>host synapse synapse_user ::1/128 trust
  759. </code></pre>
  760. </li>
  761. </ul>
  762. <p>Note that line order matters in <code>pg_hba.conf</code>, so make sure that if you do add a
  763. new line, it is inserted before:</p>
  764. <pre><code>host all all ::1/128 ident
  765. </code></pre>
  766. <h3 id="fixing-incorrect-collate-or-ctype"><a class="header" href="#fixing-incorrect-collate-or-ctype">Fixing incorrect <code>COLLATE</code> or <code>CTYPE</code></a></h3>
  767. <p>Synapse will refuse to set up a new database if it has the wrong values of
  768. <code>COLLATE</code> and <code>CTYPE</code> set, and will log warnings on existing databases. Using
  769. different locales can cause issues if the locale library is updated from
  770. underneath the database, or if a different version of the locale is used on any
  771. replicas.</p>
  772. <p>The safest way to fix the issue is to dump the database and recreate it with
  773. the correct locale parameter (as shown above). It is also possible to change the
  774. parameters on a live database and run a <code>REINDEX</code> on the entire database,
  775. however extreme care must be taken to avoid database corruption.</p>
  776. <p>Note that the above may fail with an error about duplicate rows if corruption
  777. has already occurred, and such duplicate rows will need to be manually removed.</p>
  778. <h3 id="fixing-inconsistent-sequences-error"><a class="header" href="#fixing-inconsistent-sequences-error">Fixing inconsistent sequences error</a></h3>
  779. <p>Synapse uses Postgres sequences to generate IDs for various tables. A sequence
  780. and associated table can get out of sync if, for example, Synapse has been
  781. downgraded and then upgraded again.</p>
  782. <p>To fix the issue shut down Synapse (including any and all workers) and run the
  783. SQL command included in the error message. Once done Synapse should start
  784. successfully.</p>
  785. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="using-a-reverse-proxy-with-synapse"><a class="header" href="#using-a-reverse-proxy-with-synapse">Using a reverse proxy with Synapse</a></h1>
  786. <p>It is recommended to put a reverse proxy such as
  787. <a href="https://nginx.org/en/docs/http/ngx_http_proxy_module.html">nginx</a>,
  788. <a href="https://httpd.apache.org/docs/current/mod/mod_proxy_http.html">Apache</a>,
  789. <a href="https://caddyserver.com/docs/quick-starts/reverse-proxy">Caddy</a>,
  790. <a href="https://www.haproxy.org/">HAProxy</a> or
  791. <a href="https://man.openbsd.org/relayd.8">relayd</a> in front of Synapse. One advantage
  792. of doing so is that it means that you can expose the default https port
  793. (443) to Matrix clients without needing to run Synapse with root
  794. privileges.</p>
  795. <p>You should configure your reverse proxy to forward requests to <code>/_matrix</code> or
  796. <code>/_synapse/client</code> to Synapse, and have it set the <code>X-Forwarded-For</code> and
  797. <code>X-Forwarded-Proto</code> request headers.</p>
  798. <p>You should remember that Matrix clients and other Matrix servers do not
  799. necessarily need to connect to your server via the same server name or
  800. port. Indeed, clients will use port 443 by default, whereas servers default to
  801. port 8448. Where these are different, we refer to the 'client port' and the
  802. 'federation port'. See <a href="https://matrix.org/docs/spec/server_server/latest#resolving-server-names">the Matrix
  803. specification</a>
  804. for more details of the algorithm used for federation connections, and
  805. <a href="delegate.html">Delegation</a> for instructions on setting up delegation.</p>
  806. <p><strong>NOTE</strong>: Your reverse proxy must not <code>canonicalise</code> or <code>normalise</code>
  807. the requested URI in any way (for example, by decoding <code>%xx</code> escapes).
  808. Beware that Apache <em>will</em> canonicalise URIs unless you specify
  809. <code>nocanon</code>.</p>
  810. <p>Let's assume that we expect clients to connect to our server at
  811. <code>https://matrix.example.com</code>, and other servers to connect at
  812. <code>https://example.com:8448</code>. The following sections detail the configuration of
  813. the reverse proxy and the homeserver.</p>
  814. <h2 id="homeserver-configuration"><a class="header" href="#homeserver-configuration">Homeserver Configuration</a></h2>
  815. <p>The HTTP configuration will need to be updated for Synapse to correctly record
  816. client IP addresses and generate redirect URLs while behind a reverse proxy. </p>
  817. <p>In <code>homeserver.yaml</code> set <code>x_forwarded: true</code> in the port 8008 section and
  818. consider setting <code>bind_addresses: ['127.0.0.1']</code> so that the server only
  819. listens to traffic on localhost. (Do not change <code>bind_addresses</code> to <code>127.0.0.1</code>
  820. when using a containerized Synapse, as that will prevent it from responding
  821. to proxied traffic.)</p>
  822. <h2 id="reverse-proxy-configuration-examples"><a class="header" href="#reverse-proxy-configuration-examples">Reverse-proxy configuration examples</a></h2>
  823. <p><strong>NOTE</strong>: You only need one of these.</p>
  824. <h3 id="nginx"><a class="header" href="#nginx">nginx</a></h3>
  825. <pre><code>server {
  826. listen 443 ssl http2;
  827. listen [::]:443 ssl http2;
  828. # For the federation port
  829. listen 8448 ssl http2 default_server;
  830. listen [::]:8448 ssl http2 default_server;
  831. server_name matrix.example.com;
  832. location ~* ^(\/_matrix|\/_synapse\/client) {
  833. proxy_pass http://localhost:8008;
  834. proxy_set_header X-Forwarded-For $remote_addr;
  835. proxy_set_header X-Forwarded-Proto $scheme;
  836. proxy_set_header Host $host;
  837. # Nginx by default only allows file uploads up to 1M in size
  838. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  839. client_max_body_size 50M;
  840. }
  841. }
  842. </code></pre>
  843. <p><strong>NOTE</strong>: Do not add a path after the port in <code>proxy_pass</code>, otherwise nginx will
  844. canonicalise/normalise the URI.</p>
  845. <h3 id="caddy-1"><a class="header" href="#caddy-1">Caddy 1</a></h3>
  846. <pre><code>matrix.example.com {
  847. proxy /_matrix http://localhost:8008 {
  848. transparent
  849. }
  850. proxy /_synapse/client http://localhost:8008 {
  851. transparent
  852. }
  853. }
  854. example.com:8448 {
  855. proxy / http://localhost:8008 {
  856. transparent
  857. }
  858. }
  859. </code></pre>
  860. <h3 id="caddy-2"><a class="header" href="#caddy-2">Caddy 2</a></h3>
  861. <pre><code>matrix.example.com {
  862. reverse_proxy /_matrix/* http://localhost:8008
  863. reverse_proxy /_synapse/client/* http://localhost:8008
  864. }
  865. example.com:8448 {
  866. reverse_proxy http://localhost:8008
  867. }
  868. </code></pre>
  869. <p><a href="delegate.html">Delegation</a> example:</p>
  870. <pre><code>(matrix-well-known-header) {
  871. # Headers
  872. header Access-Control-Allow-Origin &quot;*&quot;
  873. header Access-Control-Allow-Methods &quot;GET, POST, PUT, DELETE, OPTIONS&quot;
  874. header Access-Control-Allow-Headers &quot;Origin, X-Requested-With, Content-Type, Accept, Authorization&quot;
  875. header Content-Type &quot;application/json&quot;
  876. }
  877. example.com {
  878. handle /.well-known/matrix/server {
  879. import matrix-well-known-header
  880. respond `{&quot;m.server&quot;:&quot;matrix.example.com:443&quot;}`
  881. }
  882. handle /.well-known/matrix/client {
  883. import matrix-well-known-header
  884. respond `{&quot;m.homeserver&quot;:{&quot;base_url&quot;:&quot;https://matrix.example.com&quot;},&quot;m.identity_server&quot;:{&quot;base_url&quot;:&quot;https://identity.example.com&quot;}}`
  885. }
  886. }
  887. matrix.example.com {
  888. reverse_proxy /_matrix/* http://localhost:8008
  889. reverse_proxy /_synapse/client/* http://localhost:8008
  890. }
  891. </code></pre>
  892. <h3 id="apache"><a class="header" href="#apache">Apache</a></h3>
  893. <pre><code>&lt;VirtualHost *:443&gt;
  894. SSLEngine on
  895. ServerName matrix.example.com
  896. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  897. AllowEncodedSlashes NoDecode
  898. ProxyPreserveHost on
  899. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  900. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  901. ProxyPass /_synapse/client http://127.0.0.1:8008/_synapse/client nocanon
  902. ProxyPassReverse /_synapse/client http://127.0.0.1:8008/_synapse/client
  903. &lt;/VirtualHost&gt;
  904. &lt;VirtualHost *:8448&gt;
  905. SSLEngine on
  906. ServerName example.com
  907. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  908. AllowEncodedSlashes NoDecode
  909. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  910. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  911. &lt;/VirtualHost&gt;
  912. </code></pre>
  913. <p><strong>NOTE</strong>: ensure the <code>nocanon</code> options are included.</p>
  914. <p><strong>NOTE 2</strong>: It appears that Synapse is currently incompatible with the ModSecurity module for Apache (<code>mod_security2</code>). If you need it enabled for other services on your web server, you can disable it for Synapse's two VirtualHosts by including the following lines before each of the two <code>&lt;/VirtualHost&gt;</code> above:</p>
  915. <pre><code>&lt;IfModule security2_module&gt;
  916. SecRuleEngine off
  917. &lt;/IfModule&gt;
  918. </code></pre>
  919. <p><strong>NOTE 3</strong>: Missing <code>ProxyPreserveHost on</code> can lead to a redirect loop.</p>
  920. <h3 id="haproxy"><a class="header" href="#haproxy">HAProxy</a></h3>
  921. <pre><code>frontend https
  922. bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
  923. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  924. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  925. http-request set-header X-Forwarded-For %[src]
  926. # Matrix client traffic
  927. acl matrix-host hdr(host) -i matrix.example.com
  928. acl matrix-path path_beg /_matrix
  929. acl matrix-path path_beg /_synapse/client
  930. use_backend matrix if matrix-host matrix-path
  931. frontend matrix-federation
  932. bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
  933. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  934. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  935. http-request set-header X-Forwarded-For %[src]
  936. default_backend matrix
  937. backend matrix
  938. server matrix 127.0.0.1:8008
  939. </code></pre>
  940. <h3 id="relayd"><a class="header" href="#relayd">Relayd</a></h3>
  941. <pre><code>table &lt;webserver&gt; { 127.0.0.1 }
  942. table &lt;matrixserver&gt; { 127.0.0.1 }
  943. http protocol &quot;https&quot; {
  944. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  945. tls keypair &quot;example.com&quot;
  946. match header set &quot;X-Forwarded-For&quot; value &quot;$REMOTE_ADDR&quot;
  947. match header set &quot;X-Forwarded-Proto&quot; value &quot;https&quot;
  948. # set CORS header for .well-known/matrix/server, .well-known/matrix/client
  949. # httpd does not support setting headers, so do it here
  950. match request path &quot;/.well-known/matrix/*&quot; tag &quot;matrix-cors&quot;
  951. match response tagged &quot;matrix-cors&quot; header set &quot;Access-Control-Allow-Origin&quot; value &quot;*&quot;
  952. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  953. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  954. # pass on non-matrix traffic to webserver
  955. pass forward to &lt;webserver&gt;
  956. }
  957. relay &quot;https_traffic&quot; {
  958. listen on egress port 443 tls
  959. protocol &quot;https&quot;
  960. forward to &lt;matrixserver&gt; port 8008 check tcp
  961. forward to &lt;webserver&gt; port 8080 check tcp
  962. }
  963. http protocol &quot;matrix&quot; {
  964. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  965. tls keypair &quot;example.com&quot;
  966. block
  967. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  968. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  969. }
  970. relay &quot;matrix_federation&quot; {
  971. listen on egress port 8448 tls
  972. protocol &quot;matrix&quot;
  973. forward to &lt;matrixserver&gt; port 8008 check tcp
  974. }
  975. </code></pre>
  976. <h2 id="health-check-endpoint"><a class="header" href="#health-check-endpoint">Health check endpoint</a></h2>
  977. <p>Synapse exposes a health check endpoint for use by reverse proxies.
  978. Each configured HTTP listener has a <code>/health</code> endpoint which always returns
  979. 200 OK (and doesn't get logged).</p>
  980. <h2 id="synapse-administration-endpoints"><a class="header" href="#synapse-administration-endpoints">Synapse administration endpoints</a></h2>
  981. <p>Endpoints for administering your Synapse instance are placed under
  982. <code>/_synapse/admin</code>. These require authentication through an access token of an
  983. admin user. However as access to these endpoints grants the caller a lot of power,
  984. we do not recommend exposing them to the public internet without good reason.</p>
  985. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="using-a-forward-proxy-with-synapse"><a class="header" href="#using-a-forward-proxy-with-synapse">Using a forward proxy with Synapse</a></h1>
  986. <p>You can use Synapse with a forward or outbound proxy. An example of when
  987. this is necessary is in corporate environments behind a DMZ (demilitarized zone).
  988. Synapse supports routing outbound HTTP(S) requests via a proxy. Only HTTP(S)
  989. proxy is supported, not SOCKS proxy or anything else.</p>
  990. <h2 id="configure"><a class="header" href="#configure">Configure</a></h2>
  991. <p>The <code>http_proxy</code>, <code>https_proxy</code>, <code>no_proxy</code> environment variables are used to
  992. specify proxy settings. The environment variable is not case sensitive.</p>
  993. <ul>
  994. <li><code>http_proxy</code>: Proxy server to use for HTTP requests.</li>
  995. <li><code>https_proxy</code>: Proxy server to use for HTTPS requests.</li>
  996. <li><code>no_proxy</code>: Comma-separated list of hosts, IP addresses, or IP ranges in CIDR
  997. format which should not use the proxy. Synapse will directly connect to these hosts.</li>
  998. </ul>
  999. <p>The <code>http_proxy</code> and <code>https_proxy</code> environment variables have the form: <code>[scheme://][&lt;username&gt;:&lt;password&gt;@]&lt;host&gt;[:&lt;port&gt;]</code></p>
  1000. <ul>
  1001. <li>
  1002. <p>Supported schemes are <code>http://</code> and <code>https://</code>. The default scheme is <code>http://</code>
  1003. for compatibility reasons; it is recommended to set a scheme. If scheme is set
  1004. to <code>https://</code> the connection uses TLS between Synapse and the proxy.</p>
  1005. <p><strong>NOTE</strong>: Synapse validates the certificates. If the certificate is not
  1006. valid, then the connection is dropped.</p>
  1007. </li>
  1008. <li>
  1009. <p>Default port if not given is <code>1080</code>.</p>
  1010. </li>
  1011. <li>
  1012. <p>Username and password are optional and will be used to authenticate against
  1013. the proxy.</p>
  1014. </li>
  1015. </ul>
  1016. <p><strong>Examples</strong></p>
  1017. <ul>
  1018. <li>HTTP_PROXY=http://USERNAME:PASSWORD@10.0.1.1:8080/</li>
  1019. <li>HTTPS_PROXY=http://USERNAME:PASSWORD@proxy.example.com:8080/</li>
  1020. <li>NO_PROXY=master.hostname.example.com,10.1.0.0/16,172.30.0.0/16</li>
  1021. </ul>
  1022. <p><strong>NOTE</strong>:
  1023. Synapse does not apply the IP blacklist to connections through the proxy (since
  1024. the DNS resolution is done by the proxy). It is expected that the proxy or firewall
  1025. will apply blacklisting of IP addresses.</p>
  1026. <h2 id="connection-types"><a class="header" href="#connection-types">Connection types</a></h2>
  1027. <p>The proxy will be <strong>used</strong> for:</p>
  1028. <ul>
  1029. <li>push</li>
  1030. <li>url previews</li>
  1031. <li>phone-home stats</li>
  1032. <li>recaptcha validation</li>
  1033. <li>CAS auth validation</li>
  1034. <li>OpenID Connect</li>
  1035. <li>Outbound federation</li>
  1036. <li>Federation (checking public key revocation)</li>
  1037. <li>Fetching public keys of other servers</li>
  1038. <li>Downloading remote media</li>
  1039. </ul>
  1040. <p>It will <strong>not be used</strong> for:</p>
  1041. <ul>
  1042. <li>Application Services</li>
  1043. <li>Identity servers</li>
  1044. <li>In worker configurations
  1045. <ul>
  1046. <li>connections between workers</li>
  1047. <li>connections from workers to Redis</li>
  1048. </ul>
  1049. </li>
  1050. </ul>
  1051. <h2 id="troubleshooting-1"><a class="header" href="#troubleshooting-1">Troubleshooting</a></h2>
  1052. <p>If a proxy server is used with TLS (HTTPS) and no connections are established,
  1053. it is most likely due to the proxy's certificates. To test this, the validation
  1054. in Synapse can be deactivated.</p>
  1055. <p><strong>NOTE</strong>: This has an impact on security and is for testing purposes only!</p>
  1056. <p>To deactivate the certificate validation, the following setting must be made in
  1057. <a href="setup/../usage/configuration/homeserver_sample_config.html">homserver.yaml</a>.</p>
  1058. <pre><code class="language-yaml">use_insecure_ssl_client_just_for_testing_do_not_use: true
  1059. </code></pre>
  1060. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="overview-1"><a class="header" href="#overview-1">Overview</a></h1>
  1061. <p>This document explains how to enable VoIP relaying on your Home Server with
  1062. TURN.</p>
  1063. <p>The synapse Matrix Home Server supports integration with TURN server via the
  1064. <a href="https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00">TURN server REST API</a>. This
  1065. allows the Home Server to generate credentials that are valid for use on the
  1066. TURN server through the use of a secret shared between the Home Server and the
  1067. TURN server.</p>
  1068. <p>The following sections describe how to install <a href="https://github.com/coturn/coturn">coturn</a> (which implements the TURN REST API) and integrate it with synapse.</p>
  1069. <h2 id="requirements"><a class="header" href="#requirements">Requirements</a></h2>
  1070. <p>For TURN relaying with <code>coturn</code> to work, it must be hosted on a server/endpoint with a public IP.</p>
  1071. <p>Hosting TURN behind a NAT (even with appropriate port forwarding) is known to cause issues
  1072. and to often not work.</p>
  1073. <h2 id="coturn-setup"><a class="header" href="#coturn-setup"><code>coturn</code> setup</a></h2>
  1074. <h3 id="initial-installation"><a class="header" href="#initial-installation">Initial installation</a></h3>
  1075. <p>The TURN daemon <code>coturn</code> is available from a variety of sources such as native package managers, or installation from source.</p>
  1076. <h4 id="debian-installation"><a class="header" href="#debian-installation">Debian installation</a></h4>
  1077. <p>Just install the debian package:</p>
  1078. <pre><code class="language-sh">apt install coturn
  1079. </code></pre>
  1080. <p>This will install and start a systemd service called <code>coturn</code>.</p>
  1081. <h4 id="source-installation"><a class="header" href="#source-installation">Source installation</a></h4>
  1082. <ol>
  1083. <li>
  1084. <p>Download the <a href="https://github.com/coturn/coturn/releases/latest">latest release</a> from github. Unpack it and <code>cd</code> into the directory.</p>
  1085. </li>
  1086. <li>
  1087. <p>Configure it:</p>
  1088. <pre><code>./configure
  1089. </code></pre>
  1090. <p>You may need to install <code>libevent2</code>: if so, you should do so in
  1091. the way recommended by your operating system. You can ignore
  1092. warnings about lack of database support: a database is unnecessary
  1093. for this purpose.</p>
  1094. </li>
  1095. <li>
  1096. <p>Build and install it:</p>
  1097. <pre><code>make
  1098. make install
  1099. </code></pre>
  1100. </li>
  1101. </ol>
  1102. <h3 id="configuration"><a class="header" href="#configuration">Configuration</a></h3>
  1103. <ol>
  1104. <li>
  1105. <p>Create or edit the config file in <code>/etc/turnserver.conf</code>. The relevant
  1106. lines, with example values, are:</p>
  1107. <pre><code>use-auth-secret
  1108. static-auth-secret=[your secret key here]
  1109. realm=turn.myserver.org
  1110. </code></pre>
  1111. <p>See <code>turnserver.conf</code> for explanations of the options. One way to generate
  1112. the <code>static-auth-secret</code> is with <code>pwgen</code>:</p>
  1113. <pre><code>pwgen -s 64 1
  1114. </code></pre>
  1115. <p>A <code>realm</code> must be specified, but its value is somewhat arbitrary. (It is
  1116. sent to clients as part of the authentication flow.) It is conventional to
  1117. set it to be your server name.</p>
  1118. </li>
  1119. <li>
  1120. <p>You will most likely want to configure coturn to write logs somewhere. The
  1121. easiest way is normally to send them to the syslog:</p>
  1122. <pre><code>syslog
  1123. </code></pre>
  1124. <p>(in which case, the logs will be available via <code>journalctl -u coturn</code> on a
  1125. systemd system). Alternatively, coturn can be configured to write to a
  1126. logfile - check the example config file supplied with coturn.</p>
  1127. </li>
  1128. <li>
  1129. <p>Consider your security settings. TURN lets users request a relay which will
  1130. connect to arbitrary IP addresses and ports. The following configuration is
  1131. suggested as a minimum starting point:</p>
  1132. <pre><code># VoIP traffic is all UDP. There is no reason to let users connect to arbitrary TCP endpoints via the relay.
  1133. no-tcp-relay
  1134. # don't let the relay ever try to connect to private IP address ranges within your network (if any)
  1135. # given the turn server is likely behind your firewall, remember to include any privileged public IPs too.
  1136. denied-peer-ip=10.0.0.0-10.255.255.255
  1137. denied-peer-ip=192.168.0.0-192.168.255.255
  1138. denied-peer-ip=172.16.0.0-172.31.255.255
  1139. # special case the turn server itself so that client-&gt;TURN-&gt;TURN-&gt;client flows work
  1140. allowed-peer-ip=10.0.0.1
  1141. # consider whether you want to limit the quota of relayed streams per user (or total) to avoid risk of DoS.
  1142. user-quota=12 # 4 streams per video call, so 12 streams = 3 simultaneous relayed calls per user.
  1143. total-quota=1200
  1144. </code></pre>
  1145. </li>
  1146. <li>
  1147. <p>Also consider supporting TLS/DTLS. To do this, add the following settings
  1148. to <code>turnserver.conf</code>:</p>
  1149. <pre><code># TLS certificates, including intermediate certs.
  1150. # For Let's Encrypt certificates, use `fullchain.pem` here.
  1151. cert=/path/to/fullchain.pem
  1152. # TLS private key file
  1153. pkey=/path/to/privkey.pem
  1154. </code></pre>
  1155. <p>In this case, replace the <code>turn:</code> schemes in the <code>turn_uri</code> settings below
  1156. with <code>turns:</code>.</p>
  1157. <p>We recommend that you only try to set up TLS/DTLS once you have set up a
  1158. basic installation and got it working.</p>
  1159. </li>
  1160. <li>
  1161. <p>Ensure your firewall allows traffic into the TURN server on the ports
  1162. you've configured it to listen on (By default: 3478 and 5349 for TURN
  1163. traffic (remember to allow both TCP and UDP traffic), and ports 49152-65535
  1164. for the UDP relay.)</p>
  1165. </li>
  1166. <li>
  1167. <p>We do not recommend running a TURN server behind NAT, and are not aware of
  1168. anyone doing so successfully.</p>
  1169. <p>If you want to try it anyway, you will at least need to tell coturn its
  1170. external IP address:</p>
  1171. <pre><code>external-ip=192.88.99.1
  1172. </code></pre>
  1173. <p>... and your NAT gateway must forward all of the relayed ports directly
  1174. (eg, port 56789 on the external IP must be always be forwarded to port
  1175. 56789 on the internal IP).</p>
  1176. <p>If you get this working, let us know!</p>
  1177. </li>
  1178. <li>
  1179. <p>(Re)start the turn server:</p>
  1180. <ul>
  1181. <li>
  1182. <p>If you used the Debian package (or have set up a systemd unit yourself):</p>
  1183. <pre><code class="language-sh">systemctl restart coturn
  1184. </code></pre>
  1185. </li>
  1186. <li>
  1187. <p>If you installed from source:</p>
  1188. <pre><code class="language-sh">bin/turnserver -o
  1189. </code></pre>
  1190. </li>
  1191. </ul>
  1192. </li>
  1193. </ol>
  1194. <h2 id="synapse-setup"><a class="header" href="#synapse-setup">Synapse setup</a></h2>
  1195. <p>Your home server configuration file needs the following extra keys:</p>
  1196. <ol>
  1197. <li>&quot;<code>turn_uris</code>&quot;: This needs to be a yaml list of public-facing URIs
  1198. for your TURN server to be given out to your clients. Add separate
  1199. entries for each transport your TURN server supports.</li>
  1200. <li>&quot;<code>turn_shared_secret</code>&quot;: This is the secret shared between your
  1201. Home server and your TURN server, so you should set it to the same
  1202. string you used in turnserver.conf.</li>
  1203. <li>&quot;<code>turn_user_lifetime</code>&quot;: This is the amount of time credentials
  1204. generated by your Home Server are valid for (in milliseconds).
  1205. Shorter times offer less potential for abuse at the expense of
  1206. increased traffic between web clients and your home server to
  1207. refresh credentials. The TURN REST API specification recommends
  1208. one day (86400000).</li>
  1209. <li>&quot;<code>turn_allow_guests</code>&quot;: Whether to allow guest users to use the
  1210. TURN server. This is enabled by default, as otherwise VoIP will
  1211. not work reliably for guests. However, it does introduce a
  1212. security risk as it lets guests connect to arbitrary endpoints
  1213. without having gone through a CAPTCHA or similar to register a
  1214. real account.</li>
  1215. </ol>
  1216. <p>As an example, here is the relevant section of the config file for <code>matrix.org</code>. The
  1217. <code>turn_uris</code> are appropriate for TURN servers listening on the default ports, with no TLS.</p>
  1218. <pre><code>turn_uris: [ &quot;turn:turn.matrix.org?transport=udp&quot;, &quot;turn:turn.matrix.org?transport=tcp&quot; ]
  1219. turn_shared_secret: &quot;n0t4ctuAllymatr1Xd0TorgSshar3d5ecret4obvIousreAsons&quot;
  1220. turn_user_lifetime: 86400000
  1221. turn_allow_guests: True
  1222. </code></pre>
  1223. <p>After updating the homeserver configuration, you must restart synapse:</p>
  1224. <ul>
  1225. <li>If you use synctl:
  1226. <pre><code class="language-sh">cd /where/you/run/synapse
  1227. ./synctl restart
  1228. </code></pre>
  1229. </li>
  1230. <li>If you use systemd:
  1231. <pre><code>systemctl restart matrix-synapse.service
  1232. </code></pre>
  1233. </li>
  1234. </ul>
  1235. <p>... and then reload any clients (or wait an hour for them to refresh their
  1236. settings).</p>
  1237. <h2 id="troubleshooting-2"><a class="header" href="#troubleshooting-2">Troubleshooting</a></h2>
  1238. <p>The normal symptoms of a misconfigured TURN server are that calls between
  1239. devices on different networks ring, but get stuck at &quot;call
  1240. connecting&quot;. Unfortunately, troubleshooting this can be tricky.</p>
  1241. <p>Here are a few things to try:</p>
  1242. <ul>
  1243. <li>
  1244. <p>Check that your TURN server is not behind NAT. As above, we're not aware of
  1245. anyone who has successfully set this up.</p>
  1246. </li>
  1247. <li>
  1248. <p>Check that you have opened your firewall to allow TCP and UDP traffic to the
  1249. TURN ports (normally 3478 and 5479).</p>
  1250. </li>
  1251. <li>
  1252. <p>Check that you have opened your firewall to allow UDP traffic to the UDP
  1253. relay ports (49152-65535 by default).</p>
  1254. </li>
  1255. <li>
  1256. <p>Some WebRTC implementations (notably, that of Google Chrome) appear to get
  1257. confused by TURN servers which are reachable over IPv6 (this appears to be
  1258. an unexpected side-effect of its handling of multiple IP addresses as
  1259. defined by
  1260. <a href="https://tools.ietf.org/html/draft-ietf-rtcweb-ip-handling-12"><code>draft-ietf-rtcweb-ip-handling</code></a>).</p>
  1261. <p>Try removing any AAAA records for your TURN server, so that it is only
  1262. reachable over IPv4.</p>
  1263. </li>
  1264. <li>
  1265. <p>Enable more verbose logging in coturn via the <code>verbose</code> setting:</p>
  1266. <pre><code>verbose
  1267. </code></pre>
  1268. <p>... and then see if there are any clues in its logs.</p>
  1269. </li>
  1270. <li>
  1271. <p>If you are using a browser-based client under Chrome, check
  1272. <code>chrome://webrtc-internals/</code> for insights into the internals of the
  1273. negotiation. On Firefox, check the &quot;Connection Log&quot; on <code>about:webrtc</code>.</p>
  1274. <p>(Understanding the output is beyond the scope of this document!)</p>
  1275. </li>
  1276. <li>
  1277. <p>You can test your Matrix homeserver TURN setup with https://test.voip.librepush.net/.
  1278. Note that this test is not fully reliable yet, so don't be discouraged if
  1279. the test fails.
  1280. <a href="https://github.com/matrix-org/voip-tester">Here</a> is the github repo of the
  1281. source of the tester, where you can file bug reports.</p>
  1282. </li>
  1283. <li>
  1284. <p>There is a WebRTC test tool at
  1285. https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/. To
  1286. use it, you will need a username/password for your TURN server. You can
  1287. either:</p>
  1288. <ul>
  1289. <li>
  1290. <p>look for the <code>GET /_matrix/client/r0/voip/turnServer</code> request made by a
  1291. matrix client to your homeserver in your browser's network inspector. In
  1292. the response you should see <code>username</code> and <code>password</code>. Or:</p>
  1293. </li>
  1294. <li>
  1295. <p>Use the following shell commands:</p>
  1296. <pre><code class="language-sh">secret=staticAuthSecretHere
  1297. u=$((`date +%s` + 3600)):test
  1298. p=$(echo -n $u | openssl dgst -hmac $secret -sha1 -binary | base64)
  1299. echo -e &quot;username: $u\npassword: $p&quot;
  1300. </code></pre>
  1301. <p>Or:</p>
  1302. </li>
  1303. <li>
  1304. <p>Temporarily configure coturn to accept a static username/password. To do
  1305. this, comment out <code>use-auth-secret</code> and <code>static-auth-secret</code> and add the
  1306. following:</p>
  1307. <pre><code>lt-cred-mech
  1308. user=username:password
  1309. </code></pre>
  1310. <p><strong>Note</strong>: these settings will not take effect unless <code>use-auth-secret</code>
  1311. and <code>static-auth-secret</code> are disabled.</p>
  1312. <p>Restart coturn after changing the configuration file.</p>
  1313. <p>Remember to restore the original settings to go back to testing with
  1314. Matrix clients!</p>
  1315. </li>
  1316. </ul>
  1317. <p>If the TURN server is working correctly, you should see at least one <code>relay</code>
  1318. entry in the results.</p>
  1319. </li>
  1320. </ul>
  1321. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="delegation"><a class="header" href="#delegation">Delegation</a></h1>
  1322. <p>By default, other homeservers will expect to be able to reach yours via
  1323. your <code>server_name</code>, on port 8448. For example, if you set your <code>server_name</code>
  1324. to <code>example.com</code> (so that your user names look like <code>@user:example.com</code>),
  1325. other servers will try to connect to yours at <code>https://example.com:8448/</code>.</p>
  1326. <p>Delegation is a Matrix feature allowing a homeserver admin to retain a
  1327. <code>server_name</code> of <code>example.com</code> so that user IDs, room aliases, etc continue
  1328. to look like <code>*:example.com</code>, whilst having federation traffic routed
  1329. to a different server and/or port (e.g. <code>synapse.example.com:443</code>).</p>
  1330. <h2 id="well-known-delegation"><a class="header" href="#well-known-delegation">.well-known delegation</a></h2>
  1331. <p>To use this method, you need to be able to alter the
  1332. <code>server_name</code> 's https server to serve the <code>/.well-known/matrix/server</code>
  1333. URL. Having an active server (with a valid TLS certificate) serving your
  1334. <code>server_name</code> domain is out of the scope of this documentation.</p>
  1335. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> should
  1336. return a JSON structure containing the key <code>m.server</code> like so:</p>
  1337. <pre><code class="language-json">{
  1338. &quot;m.server&quot;: &quot;&lt;synapse.server.name&gt;[:&lt;yourport&gt;]&quot;
  1339. }
  1340. </code></pre>
  1341. <p>In our example, this would mean that URL <code>https://example.com/.well-known/matrix/server</code>
  1342. should return:</p>
  1343. <pre><code class="language-json">{
  1344. &quot;m.server&quot;: &quot;synapse.example.com:443&quot;
  1345. }
  1346. </code></pre>
  1347. <p>Note, specifying a port is optional. If no port is specified, then it defaults
  1348. to 8448.</p>
  1349. <p>With .well-known delegation, federating servers will check for a valid TLS
  1350. certificate for the delegated hostname (in our example: <code>synapse.example.com</code>).</p>
  1351. <h2 id="srv-dns-record-delegation"><a class="header" href="#srv-dns-record-delegation">SRV DNS record delegation</a></h2>
  1352. <p>It is also possible to do delegation using a SRV DNS record. However, that is
  1353. considered an advanced topic since it's a bit complex to set up, and <code>.well-known</code>
  1354. delegation is already enough in most cases.</p>
  1355. <p>However, if you really need it, you can find some documentation on how such a
  1356. record should look like and how Synapse will use it in <a href="https://matrix.org/docs/spec/server_server/latest#resolving-server-names">the Matrix
  1357. specification</a>.</p>
  1358. <h2 id="delegation-faq"><a class="header" href="#delegation-faq">Delegation FAQ</a></h2>
  1359. <h3 id="when-do-i-need-delegation"><a class="header" href="#when-do-i-need-delegation">When do I need delegation?</a></h3>
  1360. <p>If your homeserver's APIs are accessible on the default federation port (8448)
  1361. and the domain your <code>server_name</code> points to, you do not need any delegation.</p>
  1362. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  1363. fresh server, you could install Synapse on that host, giving it a <code>server_name</code>
  1364. of <code>example.com</code>, and once a reverse proxy has been set up to proxy all requests
  1365. sent to the port <code>8448</code> and serve TLS certificates for <code>example.com</code>, you
  1366. wouldn't need any delegation set up.</p>
  1367. <p><strong>However</strong>, if your homeserver's APIs aren't accessible on port 8448 and on the
  1368. domain <code>server_name</code> points to, you will need to let other servers know how to
  1369. find it using delegation.</p>
  1370. <h3 id="do-you-still-recommend-against-using-a-reverse-proxy-on-the-federation-port"><a class="header" href="#do-you-still-recommend-against-using-a-reverse-proxy-on-the-federation-port">Do you still recommend against using a reverse proxy on the federation port?</a></h3>
  1371. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  1372. find it easier to direct federation traffic to a reverse proxy and manage their
  1373. own TLS certificates, and this is a supported configuration.</p>
  1374. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  1375. reverse proxy.</p>
  1376. <h3 id="do-i-still-need-to-give-my-tls-certificates-to-synapse-if-i-am-using-a-reverse-proxy"><a class="header" href="#do-i-still-need-to-give-my-tls-certificates-to-synapse-if-i-am-using-a-reverse-proxy">Do I still need to give my TLS certificates to Synapse if I am using a reverse proxy?</a></h3>
  1377. <p>This is no longer necessary. If you are using a reverse proxy for all of your
  1378. TLS traffic, then you can set <code>no_tls: True</code> in the Synapse config.</p>
  1379. <p>In that case, the only reason Synapse needs the certificate is to populate a legacy
  1380. <code>tls_fingerprints</code> field in the federation API. This is ignored by Synapse 0.99.0
  1381. and later, and the only time pre-0.99 Synapses will check it is when attempting to
  1382. fetch the server keys - and generally this is delegated via <code>matrix.org</code>, which
  1383. is running a modern version of Synapse.</p>
  1384. <h3 id="do-i-need-the-same-certificate-for-the-client-and-federation-port"><a class="header" href="#do-i-need-the-same-certificate-for-the-client-and-federation-port">Do I need the same certificate for the client and federation port?</a></h3>
  1385. <p>No. There is nothing stopping you from using different certificates,
  1386. particularly if you are using a reverse proxy.</p>
  1387. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="upgrading-synapse"><a class="header" href="#upgrading-synapse">Upgrading Synapse</a></h1>
  1388. <p>Before upgrading check if any special steps are required to upgrade from
  1389. the version you currently have installed to the current version of
  1390. Synapse. The extra instructions that may be required are listed later in
  1391. this document.</p>
  1392. <ul>
  1393. <li>
  1394. <p>Check that your versions of Python and PostgreSQL are still
  1395. supported.</p>
  1396. <p>Synapse follows upstream lifecycles for <a href="https://endoflife.date/python">Python</a> and
  1397. <a href="https://endoflife.date/postgresql">PostgreSQL</a>, and removes support for versions
  1398. which are no longer maintained.</p>
  1399. <p>The website <a href="https://endoflife.date">https://endoflife.date</a> also offers convenient
  1400. summaries.</p>
  1401. </li>
  1402. <li>
  1403. <p>If Synapse was installed using <a href="setup/installation.html#prebuilt-packages">prebuilt
  1404. packages</a>, you will need to follow the
  1405. normal process for upgrading those packages.</p>
  1406. </li>
  1407. <li>
  1408. <p>If Synapse was installed from source, then:</p>
  1409. <ol>
  1410. <li>
  1411. <p>Activate the virtualenv before upgrading. For example, if
  1412. Synapse is installed in a virtualenv in <code>~/synapse/env</code> then
  1413. run:</p>
  1414. <pre><code class="language-bash">source ~/synapse/env/bin/activate
  1415. </code></pre>
  1416. </li>
  1417. <li>
  1418. <p>If Synapse was installed using pip then upgrade to the latest
  1419. version by running:</p>
  1420. <pre><code class="language-bash">pip install --upgrade matrix-synapse
  1421. </code></pre>
  1422. <p>If Synapse was installed using git then upgrade to the latest
  1423. version by running:</p>
  1424. <pre><code class="language-bash">git pull
  1425. pip install --upgrade .
  1426. </code></pre>
  1427. </li>
  1428. <li>
  1429. <p>Restart Synapse:</p>
  1430. <pre><code class="language-bash">./synctl restart
  1431. </code></pre>
  1432. </li>
  1433. </ol>
  1434. </li>
  1435. </ul>
  1436. <p>To check whether your update was successful, you can check the running
  1437. server version with:</p>
  1438. <pre><code class="language-bash"># you may need to replace 'localhost:8008' if synapse is not configured
  1439. # to listen on port 8008.
  1440. curl http://localhost:8008/_synapse/admin/v1/server_version
  1441. </code></pre>
  1442. <h2 id="rolling-back-to-older-versions"><a class="header" href="#rolling-back-to-older-versions">Rolling back to older versions</a></h2>
  1443. <p>Rolling back to previous releases can be difficult, due to database
  1444. schema changes between releases. Where we have been able to test the
  1445. rollback process, this will be noted below.</p>
  1446. <p>In general, you will need to undo any changes made during the upgrade
  1447. process, for example:</p>
  1448. <ul>
  1449. <li>
  1450. <p>pip:</p>
  1451. <pre><code class="language-bash">source env/bin/activate
  1452. # replace `1.3.0` accordingly:
  1453. pip install matrix-synapse==1.3.0
  1454. </code></pre>
  1455. </li>
  1456. <li>
  1457. <p>Debian:</p>
  1458. <pre><code class="language-bash"># replace `1.3.0` and `stretch` accordingly:
  1459. wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1460. dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1461. </code></pre>
  1462. </li>
  1463. </ul>
  1464. <h1 id="upgrading-to-v1410"><a class="header" href="#upgrading-to-v1410">Upgrading to v1.41.0</a></h1>
  1465. <h2 id="add-support-for-routing-outbound-http-requests-via-a-proxy-for-federation"><a class="header" href="#add-support-for-routing-outbound-http-requests-via-a-proxy-for-federation">Add support for routing outbound HTTP requests via a proxy for federation</a></h2>
  1466. <p>Since Synapse 1.6.0 (2019-11-26) you can set a proxy for outbound HTTP requests via
  1467. http_proxy/https_proxy environment variables. This proxy was set for:</p>
  1468. <ul>
  1469. <li>push</li>
  1470. <li>url previews</li>
  1471. <li>phone-home stats</li>
  1472. <li>recaptcha validation</li>
  1473. <li>CAS auth validation</li>
  1474. <li>OpenID Connect</li>
  1475. <li>Federation (checking public key revocation)</li>
  1476. </ul>
  1477. <p>In this version we have added support for outbound requests for:</p>
  1478. <ul>
  1479. <li>Outbound federation</li>
  1480. <li>Downloading remote media</li>
  1481. <li>Fetching public keys of other servers</li>
  1482. </ul>
  1483. <p>These requests use the same proxy configuration. If you have a proxy configuration we
  1484. recommend to verify the configuration. It may be necessary to adjust the <code>no_proxy</code>
  1485. environment variable.</p>
  1486. <p>See <a href="setup/forward_proxy.html">using a forward proxy with Synapse documentation</a> for
  1487. details.</p>
  1488. <h2 id="deprecation-of-template_dir"><a class="header" href="#deprecation-of-template_dir">Deprecation of <code>template_dir</code></a></h2>
  1489. <p>The <code>template_dir</code> settings in the <code>sso</code>, <code>account_validity</code> and <code>email</code> sections of the
  1490. configuration file are now deprecated. Server admins should use the new
  1491. <code>templates.custom_template_directory</code> setting in the configuration file and use one single
  1492. custom template directory for all aforementioned features. Template file names remain
  1493. unchanged. See <a href="https://matrix-org.github.io/synapse/latest/templates.html">the related documentation</a>
  1494. for more information and examples.</p>
  1495. <p>We plan to remove support for these settings in October 2021.</p>
  1496. <h2 id="_synapseadminv1usersuseridmedia-must-be-handled-by-media-workers"><a class="header" href="#_synapseadminv1usersuseridmedia-must-be-handled-by-media-workers"><code>/_synapse/admin/v1/users/{userId}/media</code> must be handled by media workers</a></h2>
  1497. <p>The <a href="https://matrix-org.github.io/synapse/latest/workers.html#synapseappmedia_repository">media repository worker documentation</a>
  1498. has been updated to reflect that calls to <code>/_synapse/admin/v1/users/{userId}/media</code>
  1499. must now be handled by media repository workers. This is due to the new <code>DELETE</code> method
  1500. of this endpoint modifying the media store.</p>
  1501. <h1 id="upgrading-to-v1390"><a class="header" href="#upgrading-to-v1390">Upgrading to v1.39.0</a></h1>
  1502. <h2 id="deprecation-of-the-current-third-party-rules-module-interface"><a class="header" href="#deprecation-of-the-current-third-party-rules-module-interface">Deprecation of the current third-party rules module interface</a></h2>
  1503. <p>The current third-party rules module interface is deprecated in favour of the new generic
  1504. modules system introduced in Synapse v1.37.0. Authors of third-party rules modules can refer
  1505. to <a href="modules.html#porting-an-existing-module-that-uses-the-old-interface">this documentation</a>
  1506. to update their modules. Synapse administrators can refer to <a href="modules.html#using-modules">this documentation</a>
  1507. to update their configuration once the modules they are using have been updated.</p>
  1508. <p>We plan to remove support for the current third-party rules interface in September 2021.</p>
  1509. <h1 id="upgrading-to-v1380"><a class="header" href="#upgrading-to-v1380">Upgrading to v1.38.0</a></h1>
  1510. <h2 id="re-indexing-of-events-table-on-postgres-databases"><a class="header" href="#re-indexing-of-events-table-on-postgres-databases">Re-indexing of <code>events</code> table on Postgres databases</a></h2>
  1511. <p>This release includes a database schema update which requires re-indexing one of
  1512. the larger tables in the database, <code>events</code>. This could result in increased
  1513. disk I/O for several hours or days after upgrading while the migration
  1514. completes. Furthermore, because we have to keep the old indexes until the new
  1515. indexes are ready, it could result in a significant, temporary, increase in
  1516. disk space.</p>
  1517. <p>To get a rough idea of the disk space required, check the current size of one
  1518. of the indexes. For example, from a <code>psql</code> shell, run the following sql:</p>
  1519. <pre><code class="language-sql">SELECT pg_size_pretty(pg_relation_size('events_order_room'));
  1520. </code></pre>
  1521. <p>We need to rebuild <strong>four</strong> indexes, so you will need to multiply this result
  1522. by four to give an estimate of the disk space required. For example, on one
  1523. particular server:</p>
  1524. <pre><code>synapse=# select pg_size_pretty(pg_relation_size('events_order_room'));
  1525. pg_size_pretty
  1526. ----------------
  1527. 288 MB
  1528. (1 row)
  1529. </code></pre>
  1530. <p>On this server, it would be wise to ensure that at least 1152MB are free.</p>
  1531. <p>The additional disk space will be freed once the migration completes.</p>
  1532. <p>SQLite databases are unaffected by this change.</p>
  1533. <h1 id="upgrading-to-v1370"><a class="header" href="#upgrading-to-v1370">Upgrading to v1.37.0</a></h1>
  1534. <h2 id="deprecation-of-the-current-spam-checker-interface"><a class="header" href="#deprecation-of-the-current-spam-checker-interface">Deprecation of the current spam checker interface</a></h2>
  1535. <p>The current spam checker interface is deprecated in favour of a new generic modules system.
  1536. Authors of spam checker modules can refer to <a href="modules.html#porting-an-existing-module-that-uses-the-old-interface">this
  1537. documentation</a>
  1538. to update their modules. Synapse administrators can refer to <a href="modules.html#using-modules">this
  1539. documentation</a>
  1540. to update their configuration once the modules they are using have been updated.</p>
  1541. <p>We plan to remove support for the current spam checker interface in August 2021.</p>
  1542. <p>More module interfaces will be ported over to this new generic system in future versions
  1543. of Synapse.</p>
  1544. <h1 id="upgrading-to-v1340"><a class="header" href="#upgrading-to-v1340">Upgrading to v1.34.0</a></h1>
  1545. <h2 id="room_invite_state_types-configuration-setting"><a class="header" href="#room_invite_state_types-configuration-setting"><code>room_invite_state_types</code> configuration setting</a></h2>
  1546. <p>The <code>room_invite_state_types</code> configuration setting has been deprecated
  1547. and replaced with <code>room_prejoin_state</code>. See the <a href="https://github.com/matrix-org/synapse/blob/v1.34.0/docs/sample_config.yaml#L1515">sample configuration
  1548. file</a>.</p>
  1549. <p>If you have set <code>room_invite_state_types</code> to the default value you
  1550. should simply remove it from your configuration file. The default value
  1551. used to be:</p>
  1552. <pre><code class="language-yaml">room_invite_state_types:
  1553. - &quot;m.room.join_rules&quot;
  1554. - &quot;m.room.canonical_alias&quot;
  1555. - &quot;m.room.avatar&quot;
  1556. - &quot;m.room.encryption&quot;
  1557. - &quot;m.room.name&quot;
  1558. </code></pre>
  1559. <p>If you have customised this value, you should remove
  1560. <code>room_invite_state_types</code> and configure <code>room_prejoin_state</code> instead.</p>
  1561. <h1 id="upgrading-to-v1330"><a class="header" href="#upgrading-to-v1330">Upgrading to v1.33.0</a></h1>
  1562. <h2 id="account-validity-html-templates-can-now-display-a-users-expiration-date"><a class="header" href="#account-validity-html-templates-can-now-display-a-users-expiration-date">Account Validity HTML templates can now display a user's expiration date</a></h2>
  1563. <p>This may affect you if you have enabled the account validity feature,
  1564. and have made use of a custom HTML template specified by the
  1565. <code>account_validity.template_dir</code> or
  1566. <code>account_validity.account_renewed_html_path</code> Synapse config options.</p>
  1567. <p>The template can now accept an <code>expiration_ts</code> variable, which
  1568. represents the unix timestamp in milliseconds for the future date of
  1569. which their account has been renewed until. See the <a href="https://github.com/matrix-org/synapse/blob/release-v1.33.0/synapse/res/templates/account_renewed.html">default
  1570. template</a>
  1571. for an example of usage.</p>
  1572. <p>ALso note that a new HTML template, <code>account_previously_renewed.html</code>,
  1573. has been added. This is is shown to users when they attempt to renew
  1574. their account with a valid renewal token that has already been used
  1575. before. The default template contents can been found
  1576. <a href="https://github.com/matrix-org/synapse/blob/release-v1.33.0/synapse/res/templates/account_previously_renewed.html">here</a>,
  1577. and can also accept an <code>expiration_ts</code> variable. This template replaces
  1578. the error message users would previously see upon attempting to use a
  1579. valid renewal token more than once.</p>
  1580. <h1 id="upgrading-to-v1320"><a class="header" href="#upgrading-to-v1320">Upgrading to v1.32.0</a></h1>
  1581. <h2 id="regression-causing-connected-prometheus-instances-to-become-overwhelmed"><a class="header" href="#regression-causing-connected-prometheus-instances-to-become-overwhelmed">Regression causing connected Prometheus instances to become overwhelmed</a></h2>
  1582. <p>This release introduces <a href="https://github.com/matrix-org/synapse/issues/9853">a
  1583. regression</a> that can
  1584. overwhelm connected Prometheus instances. This issue is not present in
  1585. Synapse v1.32.0rc1.</p>
  1586. <p>If you have been affected, please downgrade to 1.31.0. You then may need
  1587. to remove excess writeahead logs in order for Prometheus to recover.
  1588. Instructions for doing so are provided
  1589. <a href="https://github.com/matrix-org/synapse/pull/9854#issuecomment-823472183">here</a>.</p>
  1590. <h2 id="dropping-support-for-old-python-postgres-and-sqlite-versions"><a class="header" href="#dropping-support-for-old-python-postgres-and-sqlite-versions">Dropping support for old Python, Postgres and SQLite versions</a></h2>
  1591. <p>In line with our <a href="deprecation_policy.html">deprecation policy</a>,
  1592. we've dropped support for Python 3.5 and PostgreSQL 9.5, as they are no
  1593. longer supported upstream.</p>
  1594. <p>This release of Synapse requires Python 3.6+ and PostgresSQL 9.6+ or
  1595. SQLite 3.22+.</p>
  1596. <h2 id="removal-of-old-list-accounts-admin-api"><a class="header" href="#removal-of-old-list-accounts-admin-api">Removal of old List Accounts Admin API</a></h2>
  1597. <p>The deprecated v1 &quot;list accounts&quot; admin API
  1598. (<code>GET /_synapse/admin/v1/users/&lt;user_id&gt;</code>) has been removed in this
  1599. version.</p>
  1600. <p>The <a href="admin_api/user_admin_api.html#list-accounts">v2 list accounts API</a>
  1601. has been available since Synapse 1.7.0 (2019-12-13), and is accessible
  1602. under <code>GET /_synapse/admin/v2/users</code>.</p>
  1603. <p>The deprecation of the old endpoint was announced with Synapse 1.28.0
  1604. (released on 2021-02-25).</p>
  1605. <h2 id="application-services-must-use-type-mloginapplication_service-when-registering-users"><a class="header" href="#application-services-must-use-type-mloginapplication_service-when-registering-users">Application Services must use type <code>m.login.application_service</code> when registering users</a></h2>
  1606. <p>In compliance with the <a href="https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions">Application Service
  1607. spec</a>,
  1608. Application Services are now required to use the
  1609. <code>m.login.application_service</code> type when registering users via the
  1610. <code>/_matrix/client/r0/register</code> endpoint. This behaviour was deprecated in
  1611. Synapse v1.30.0.</p>
  1612. <p>Please ensure your Application Services are up to date.</p>
  1613. <h1 id="upgrading-to-v1290"><a class="header" href="#upgrading-to-v1290">Upgrading to v1.29.0</a></h1>
  1614. <h2 id="requirement-for-x-forwarded-proto-header"><a class="header" href="#requirement-for-x-forwarded-proto-header">Requirement for X-Forwarded-Proto header</a></h2>
  1615. <p>When using Synapse with a reverse proxy (in particular, when using the
  1616. [x_forwarded]{.title-ref} option on an HTTP listener), Synapse now
  1617. expects to receive an [X-Forwarded-Proto]{.title-ref} header on incoming
  1618. HTTP requests. If it is not set, Synapse will log a warning on each
  1619. received request.</p>
  1620. <p>To avoid the warning, administrators using a reverse proxy should ensure
  1621. that the reverse proxy sets [X-Forwarded-Proto]{.title-ref} header to
  1622. [https]{.title-ref} or [http]{.title-ref} to indicate the protocol used
  1623. by the client.</p>
  1624. <p>Synapse also requires the [Host]{.title-ref} header to be preserved.</p>
  1625. <p>See the <a href="reverse_proxy.html">reverse proxy documentation</a>, where the
  1626. example configurations have been updated to show how to set these
  1627. headers.</p>
  1628. <p>(Users of <a href="https://caddyserver.com/">Caddy</a> are unaffected, since we
  1629. believe it sets [X-Forwarded-Proto]{.title-ref} by default.)</p>
  1630. <h1 id="upgrading-to-v1270"><a class="header" href="#upgrading-to-v1270">Upgrading to v1.27.0</a></h1>
  1631. <h2 id="changes-to-callback-uri-for-oauth2--openid-connect-and-saml2"><a class="header" href="#changes-to-callback-uri-for-oauth2--openid-connect-and-saml2">Changes to callback URI for OAuth2 / OpenID Connect and SAML2</a></h2>
  1632. <p>This version changes the URI used for callbacks from OAuth2 and SAML2
  1633. identity providers:</p>
  1634. <ul>
  1635. <li>
  1636. <p>If your server is configured for single sign-on via an OpenID
  1637. Connect or OAuth2 identity provider, you will need to add
  1638. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> to the list
  1639. of permitted &quot;redirect URIs&quot; at the identity provider.</p>
  1640. <p>See the <a href="openid.html">OpenID docs</a> for more information on setting
  1641. up OpenID Connect.</p>
  1642. </li>
  1643. <li>
  1644. <p>If your server is configured for single sign-on via a SAML2 identity
  1645. provider, you will need to add
  1646. <code>[synapse public baseurl]/_synapse/client/saml2/authn_response</code> as a
  1647. permitted &quot;ACS location&quot; (also known as &quot;allowed callback URLs&quot;)
  1648. at the identity provider.</p>
  1649. <p>The &quot;Issuer&quot; in the &quot;AuthnRequest&quot; to the SAML2 identity
  1650. provider is also updated to
  1651. <code>[synapse public baseurl]/_synapse/client/saml2/metadata.xml</code>. If
  1652. your SAML2 identity provider uses this property to validate or
  1653. otherwise identify Synapse, its configuration will need to be
  1654. updated to use the new URL. Alternatively you could create a new,
  1655. separate &quot;EntityDescriptor&quot; in your SAML2 identity provider with
  1656. the new URLs and leave the URLs in the existing &quot;EntityDescriptor&quot;
  1657. as they were.</p>
  1658. </li>
  1659. </ul>
  1660. <h2 id="changes-to-html-templates"><a class="header" href="#changes-to-html-templates">Changes to HTML templates</a></h2>
  1661. <p>The HTML templates for SSO and email notifications now have <a href="https://jinja.palletsprojects.com/en/2.11.x/api/#autoescaping">Jinja2's
  1662. autoescape</a>
  1663. enabled for files ending in <code>.html</code>, <code>.htm</code>, and <code>.xml</code>. If you have
  1664. customised these templates and see issues when viewing them you might
  1665. need to update them. It is expected that most configurations will need
  1666. no changes.</p>
  1667. <p>If you have customised the templates <em>names</em> for these templates, it is
  1668. recommended to verify they end in <code>.html</code> to ensure autoescape is
  1669. enabled.</p>
  1670. <p>The above applies to the following templates:</p>
  1671. <ul>
  1672. <li><code>add_threepid.html</code></li>
  1673. <li><code>add_threepid_failure.html</code></li>
  1674. <li><code>add_threepid_success.html</code></li>
  1675. <li><code>notice_expiry.html</code></li>
  1676. <li><code>notice_expiry.html</code></li>
  1677. <li><code>notif_mail.html</code> (which, by default, includes <code>room.html</code> and
  1678. <code>notif.html</code>)</li>
  1679. <li><code>password_reset.html</code></li>
  1680. <li><code>password_reset_confirmation.html</code></li>
  1681. <li><code>password_reset_failure.html</code></li>
  1682. <li><code>password_reset_success.html</code></li>
  1683. <li><code>registration.html</code></li>
  1684. <li><code>registration_failure.html</code></li>
  1685. <li><code>registration_success.html</code></li>
  1686. <li><code>sso_account_deactivated.html</code></li>
  1687. <li><code>sso_auth_bad_user.html</code></li>
  1688. <li><code>sso_auth_confirm.html</code></li>
  1689. <li><code>sso_auth_success.html</code></li>
  1690. <li><code>sso_error.html</code></li>
  1691. <li><code>sso_login_idp_picker.html</code></li>
  1692. <li><code>sso_redirect_confirm.html</code></li>
  1693. </ul>
  1694. <h1 id="upgrading-to-v1260"><a class="header" href="#upgrading-to-v1260">Upgrading to v1.26.0</a></h1>
  1695. <h2 id="rolling-back-to-v1250-after-a-failed-upgrade"><a class="header" href="#rolling-back-to-v1250-after-a-failed-upgrade">Rolling back to v1.25.0 after a failed upgrade</a></h2>
  1696. <p>v1.26.0 includes a lot of large changes. If something problematic
  1697. occurs, you may want to roll-back to a previous version of Synapse.
  1698. Because v1.26.0 also includes a new database schema version, reverting
  1699. that version is also required alongside the generic rollback
  1700. instructions mentioned above. In short, to roll back to v1.25.0 you need
  1701. to:</p>
  1702. <ol>
  1703. <li>
  1704. <p>Stop the server</p>
  1705. </li>
  1706. <li>
  1707. <p>Decrease the schema version in the database:</p>
  1708. <pre><code class="language-sql">UPDATE schema_version SET version = 58;
  1709. </code></pre>
  1710. </li>
  1711. <li>
  1712. <p>Delete the ignored users &amp; chain cover data:</p>
  1713. <pre><code class="language-sql">DROP TABLE IF EXISTS ignored_users;
  1714. UPDATE rooms SET has_auth_chain_index = false;
  1715. </code></pre>
  1716. <p>For PostgreSQL run:</p>
  1717. <pre><code class="language-sql">TRUNCATE event_auth_chain_links;
  1718. TRUNCATE event_auth_chains;
  1719. </code></pre>
  1720. <p>For SQLite run:</p>
  1721. <pre><code class="language-sql">DELETE FROM event_auth_chain_links;
  1722. DELETE FROM event_auth_chains;
  1723. </code></pre>
  1724. </li>
  1725. <li>
  1726. <p>Mark the deltas as not run (so they will re-run on upgrade).</p>
  1727. <pre><code class="language-sql">DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/01ignored_user.py&quot;;
  1728. DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/06chain_cover_index.sql&quot;;
  1729. </code></pre>
  1730. </li>
  1731. <li>
  1732. <p>Downgrade Synapse by following the instructions for your
  1733. installation method in the &quot;Rolling back to older versions&quot;
  1734. section above.</p>
  1735. </li>
  1736. </ol>
  1737. <h1 id="upgrading-to-v1250"><a class="header" href="#upgrading-to-v1250">Upgrading to v1.25.0</a></h1>
  1738. <h2 id="last-release-supporting-python-35"><a class="header" href="#last-release-supporting-python-35">Last release supporting Python 3.5</a></h2>
  1739. <p>This is the last release of Synapse which guarantees support with Python
  1740. 3.5, which passed its upstream End of Life date several months ago.</p>
  1741. <p>We will attempt to maintain support through March 2021, but without
  1742. guarantees.</p>
  1743. <p>In the future, Synapse will follow upstream schedules for ending support
  1744. of older versions of Python and PostgreSQL. Please upgrade to at least
  1745. Python 3.6 and PostgreSQL 9.6 as soon as possible.</p>
  1746. <h2 id="blacklisting-ip-ranges"><a class="header" href="#blacklisting-ip-ranges">Blacklisting IP ranges</a></h2>
  1747. <p>Synapse v1.25.0 includes new settings, <code>ip_range_blacklist</code> and
  1748. <code>ip_range_whitelist</code>, for controlling outgoing requests from Synapse for
  1749. federation, identity servers, push, and for checking key validity for
  1750. third-party invite events. The previous setting,
  1751. <code>federation_ip_range_blacklist</code>, is deprecated. The new
  1752. <code>ip_range_blacklist</code> defaults to private IP ranges if it is not defined.</p>
  1753. <p>If you have never customised <code>federation_ip_range_blacklist</code> it is
  1754. recommended that you remove that setting.</p>
  1755. <p>If you have customised <code>federation_ip_range_blacklist</code> you should update
  1756. the setting name to <code>ip_range_blacklist</code>.</p>
  1757. <p>If you have a custom push server that is reached via private IP space
  1758. you may need to customise <code>ip_range_blacklist</code> or <code>ip_range_whitelist</code>.</p>
  1759. <h1 id="upgrading-to-v1240"><a class="header" href="#upgrading-to-v1240">Upgrading to v1.24.0</a></h1>
  1760. <h2 id="custom-openid-connect-mapping-provider-breaking-change"><a class="header" href="#custom-openid-connect-mapping-provider-breaking-change">Custom OpenID Connect mapping provider breaking change</a></h2>
  1761. <p>This release allows the OpenID Connect mapping provider to perform
  1762. normalisation of the localpart of the Matrix ID. This allows for the
  1763. mapping provider to specify different algorithms, instead of the
  1764. <a href="https://matrix.org/docs/spec/appendices#mapping-from-other-character-sets">default
  1765. way</a>.</p>
  1766. <p>If your Synapse configuration uses a custom mapping provider
  1767. ([oidc_config.user_mapping_provider.module]{.title-ref} is specified and
  1768. not equal to
  1769. [synapse.handlers.oidc_handler.JinjaOidcMappingProvider]{.title-ref})
  1770. then you <em>must</em> ensure that [map_user_attributes]{.title-ref} of the
  1771. mapping provider performs some normalisation of the
  1772. [localpart]{.title-ref} returned. To match previous behaviour you can
  1773. use the [map_username_to_mxid_localpart]{.title-ref} function provided
  1774. by Synapse. An example is shown below:</p>
  1775. <pre><code class="language-python">from synapse.types import map_username_to_mxid_localpart
  1776. class MyMappingProvider:
  1777. def map_user_attributes(self, userinfo, token):
  1778. # ... your custom logic ...
  1779. sso_user_id = ...
  1780. localpart = map_username_to_mxid_localpart(sso_user_id)
  1781. return {&quot;localpart&quot;: localpart}
  1782. </code></pre>
  1783. <h2 id="removal-historical-synapse-admin-api"><a class="header" href="#removal-historical-synapse-admin-api">Removal historical Synapse Admin API</a></h2>
  1784. <p>Historically, the Synapse Admin API has been accessible under:</p>
  1785. <ul>
  1786. <li><code>/_matrix/client/api/v1/admin</code></li>
  1787. <li><code>/_matrix/client/unstable/admin</code></li>
  1788. <li><code>/_matrix/client/r0/admin</code></li>
  1789. <li><code>/_synapse/admin/v1</code></li>
  1790. </ul>
  1791. <p>The endpoints with <code>/_matrix/client/*</code> prefixes have been removed as of
  1792. v1.24.0. The Admin API is now only accessible under:</p>
  1793. <ul>
  1794. <li><code>/_synapse/admin/v1</code></li>
  1795. </ul>
  1796. <p>The only exception is the [/admin/whois]{.title-ref} endpoint, which is
  1797. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid">also available via the client-server
  1798. API</a>.</p>
  1799. <p>The deprecation of the old endpoints was announced with Synapse 1.20.0
  1800. (released on 2020-09-22) and makes it easier for homeserver admins to
  1801. lock down external access to the Admin API endpoints.</p>
  1802. <h1 id="upgrading-to-v1230"><a class="header" href="#upgrading-to-v1230">Upgrading to v1.23.0</a></h1>
  1803. <h2 id="structured-logging-configuration-breaking-changes"><a class="header" href="#structured-logging-configuration-breaking-changes">Structured logging configuration breaking changes</a></h2>
  1804. <p>This release deprecates use of the <code>structured: true</code> logging
  1805. configuration for structured logging. If your logging configuration
  1806. contains <code>structured: true</code> then it should be modified based on the
  1807. <a href="structured_logging.html">structured logging documentation</a>.</p>
  1808. <p>The <code>structured</code> and <code>drains</code> logging options are now deprecated and
  1809. should be replaced by standard logging configuration of <code>handlers</code> and
  1810. <code>formatters</code>.</p>
  1811. <p>A future will release of Synapse will make using <code>structured: true</code> an
  1812. error.</p>
  1813. <h1 id="upgrading-to-v1220"><a class="header" href="#upgrading-to-v1220">Upgrading to v1.22.0</a></h1>
  1814. <h2 id="thirdpartyeventrules-breaking-changes"><a class="header" href="#thirdpartyeventrules-breaking-changes">ThirdPartyEventRules breaking changes</a></h2>
  1815. <p>This release introduces a backwards-incompatible change to modules
  1816. making use of <code>ThirdPartyEventRules</code> in Synapse. If you make use of a
  1817. module defined under the <code>third_party_event_rules</code> config option, please
  1818. make sure it is updated to handle the below change:</p>
  1819. <p>The <code>http_client</code> argument is no longer passed to modules as they are
  1820. initialised. Instead, modules are expected to make use of the
  1821. <code>http_client</code> property on the <code>ModuleApi</code> class. Modules are now passed
  1822. a <code>module_api</code> argument during initialisation, which is an instance of
  1823. <code>ModuleApi</code>. <code>ModuleApi</code> instances have a <code>http_client</code> property which
  1824. acts the same as the <code>http_client</code> argument previously passed to
  1825. <code>ThirdPartyEventRules</code> modules.</p>
  1826. <h1 id="upgrading-to-v1210"><a class="header" href="#upgrading-to-v1210">Upgrading to v1.21.0</a></h1>
  1827. <h2 id="forwarding-_synapseclient-through-your-reverse-proxy"><a class="header" href="#forwarding-_synapseclient-through-your-reverse-proxy">Forwarding <code>/_synapse/client</code> through your reverse proxy</a></h2>
  1828. <p>The <a href="reverse_proxy.html">reverse proxy documentation</a>
  1829. has been updated to include reverse proxy directives for
  1830. <code>/_synapse/client/*</code> endpoints. As the user password reset flow now uses
  1831. endpoints under this prefix, <strong>you must update your reverse proxy
  1832. configurations for user password reset to work</strong>.</p>
  1833. <p>Additionally, note that the <a href="workers.html">Synapse worker documentation</a> has been updated to</p>
  1834. <p>: state that the <code>/_synapse/client/password_reset/email/submit_token</code>
  1835. endpoint can be handled</p>
  1836. <p>by all workers. If you make use of Synapse's worker feature, please
  1837. update your reverse proxy configuration to reflect this change.</p>
  1838. <h2 id="new-html-templates"><a class="header" href="#new-html-templates">New HTML templates</a></h2>
  1839. <p>A new HTML template,
  1840. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/res/templates/password_reset_confirmation.html">password_reset_confirmation.html</a>,
  1841. has been added to the <code>synapse/res/templates</code> directory. If you are
  1842. using a custom template directory, you may want to copy the template
  1843. over and modify it.</p>
  1844. <p>Note that as of v1.20.0, templates do not need to be included in custom
  1845. template directories for Synapse to start. The default templates will be
  1846. used if a custom template cannot be found.</p>
  1847. <p>This page will appear to the user after clicking a password reset link
  1848. that has been emailed to them.</p>
  1849. <p>To complete password reset, the page must include a way to make a
  1850. [POST]{.title-ref} request to
  1851. <code>/_synapse/client/password_reset/{medium}/submit_token</code> with the query
  1852. parameters from the original link, presented as a URL-encoded form. See
  1853. the file itself for more details.</p>
  1854. <h2 id="updated-single-sign-on-html-templates"><a class="header" href="#updated-single-sign-on-html-templates">Updated Single Sign-on HTML Templates</a></h2>
  1855. <p>The <code>saml_error.html</code> template was removed from Synapse and replaced
  1856. with the <code>sso_error.html</code> template. If your Synapse is configured to use
  1857. SAML and a custom <code>sso_redirect_confirm_template_dir</code> configuration then
  1858. any customisations of the <code>saml_error.html</code> template will need to be
  1859. merged into the <code>sso_error.html</code> template. These templates are similar,
  1860. but the parameters are slightly different:</p>
  1861. <ul>
  1862. <li>The <code>msg</code> parameter should be renamed to <code>error_description</code>.</li>
  1863. <li>There is no longer a <code>code</code> parameter for the response code.</li>
  1864. <li>A string <code>error</code> parameter is available that includes a short hint
  1865. of why a user is seeing the error page.</li>
  1866. </ul>
  1867. <h1 id="upgrading-to-v1180"><a class="header" href="#upgrading-to-v1180">Upgrading to v1.18.0</a></h1>
  1868. <h2 id="docker--py3title-ref-suffix-will-be-removed-in-future-versions"><a class="header" href="#docker--py3title-ref-suffix-will-be-removed-in-future-versions">Docker [-py3]{.title-ref} suffix will be removed in future versions</a></h2>
  1869. <p>From 10th August 2020, we will no longer publish Docker images with the
  1870. [-py3]{.title-ref} tag suffix. The images tagged with the
  1871. [-py3]{.title-ref} suffix have been identical to the non-suffixed tags
  1872. since release 0.99.0, and the suffix is obsolete.</p>
  1873. <p>On 10th August, we will remove the [latest-py3]{.title-ref} tag.
  1874. Existing per-release tags (such as [v1.18.0-py3]{.title-ref}) will not
  1875. be removed, but no new [-py3]{.title-ref} tags will be added.</p>
  1876. <p>Scripts relying on the [-py3]{.title-ref} suffix will need to be
  1877. updated.</p>
  1878. <h2 id="redis-replication-is-now-recommended-in-lieu-of-tcp-replication"><a class="header" href="#redis-replication-is-now-recommended-in-lieu-of-tcp-replication">Redis replication is now recommended in lieu of TCP replication</a></h2>
  1879. <p>When setting up worker processes, we now recommend the use of a Redis
  1880. server for replication. <strong>The old direct TCP connection method is
  1881. deprecated and will be removed in a future release.</strong> See
  1882. <a href="workers.html">workers</a> for more details.</p>
  1883. <h1 id="upgrading-to-v1140"><a class="header" href="#upgrading-to-v1140">Upgrading to v1.14.0</a></h1>
  1884. <p>This version includes a database update which is run as part of the
  1885. upgrade, and which may take a couple of minutes in the case of a large
  1886. server. Synapse will not respond to HTTP requests while this update is
  1887. taking place.</p>
  1888. <h1 id="upgrading-to-v1130"><a class="header" href="#upgrading-to-v1130">Upgrading to v1.13.0</a></h1>
  1889. <h2 id="incorrect-database-migration-in-old-synapse-versions"><a class="header" href="#incorrect-database-migration-in-old-synapse-versions">Incorrect database migration in old synapse versions</a></h2>
  1890. <p>A bug was introduced in Synapse 1.4.0 which could cause the room
  1891. directory to be incomplete or empty if Synapse was upgraded directly
  1892. from v1.2.1 or earlier, to versions between v1.4.0 and v1.12.x.</p>
  1893. <p>This will <em>not</em> be a problem for Synapse installations which were:</p>
  1894. <p>: - created at v1.4.0 or later,
  1895. - upgraded via v1.3.x, or
  1896. - upgraded straight from v1.2.1 or earlier to v1.13.0 or later.</p>
  1897. <p>If completeness of the room directory is a concern, installations which
  1898. are affected can be repaired as follows:</p>
  1899. <ol>
  1900. <li>
  1901. <p>Run the following sql from a [psql]{.title-ref} or
  1902. [sqlite3]{.title-ref} console:</p>
  1903. <pre><code class="language-sql">INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1904. ('populate_stats_process_rooms', '{}', 'current_state_events_membership');
  1905. INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1906. ('populate_stats_process_users', '{}', 'populate_stats_process_rooms');
  1907. </code></pre>
  1908. </li>
  1909. <li>
  1910. <p>Restart synapse.</p>
  1911. </li>
  1912. </ol>
  1913. <h2 id="new-single-sign-on-html-templates"><a class="header" href="#new-single-sign-on-html-templates">New Single Sign-on HTML Templates</a></h2>
  1914. <p>New templates (<code>sso_auth_confirm.html</code>, <code>sso_auth_success.html</code>, and
  1915. <code>sso_account_deactivated.html</code>) were added to Synapse. If your Synapse
  1916. is configured to use SSO and a custom
  1917. <code>sso_redirect_confirm_template_dir</code> configuration then these templates
  1918. will need to be copied from
  1919. <a href="synapse/res/templates">synapse/res/templates</a> into that directory.</p>
  1920. <h2 id="synapse-sso-plugins-method-deprecation"><a class="header" href="#synapse-sso-plugins-method-deprecation">Synapse SSO Plugins Method Deprecation</a></h2>
  1921. <p>Plugins using the <code>complete_sso_login</code> method of
  1922. <code>synapse.module_api.ModuleApi</code> should update to using the async/await
  1923. version <code>complete_sso_login_async</code> which includes additional checks. The
  1924. non-async version is considered deprecated.</p>
  1925. <h2 id="rolling-back-to-v1124-after-a-failed-upgrade"><a class="header" href="#rolling-back-to-v1124-after-a-failed-upgrade">Rolling back to v1.12.4 after a failed upgrade</a></h2>
  1926. <p>v1.13.0 includes a lot of large changes. If something problematic
  1927. occurs, you may want to roll-back to a previous version of Synapse.
  1928. Because v1.13.0 also includes a new database schema version, reverting
  1929. that version is also required alongside the generic rollback
  1930. instructions mentioned above. In short, to roll back to v1.12.4 you need
  1931. to:</p>
  1932. <ol>
  1933. <li>
  1934. <p>Stop the server</p>
  1935. </li>
  1936. <li>
  1937. <p>Decrease the schema version in the database:</p>
  1938. <pre><code class="language-sql">UPDATE schema_version SET version = 57;
  1939. </code></pre>
  1940. </li>
  1941. <li>
  1942. <p>Downgrade Synapse by following the instructions for your
  1943. installation method in the &quot;Rolling back to older versions&quot;
  1944. section above.</p>
  1945. </li>
  1946. </ol>
  1947. <h1 id="upgrading-to-v1120"><a class="header" href="#upgrading-to-v1120">Upgrading to v1.12.0</a></h1>
  1948. <p>This version includes a database update which is run as part of the
  1949. upgrade, and which may take some time (several hours in the case of a
  1950. large server). Synapse will not respond to HTTP requests while this
  1951. update is taking place.</p>
  1952. <p>This is only likely to be a problem in the case of a server which is
  1953. participating in many rooms.</p>
  1954. <ol start="0">
  1955. <li>
  1956. <p>As with all upgrades, it is recommended that you have a recent
  1957. backup of your database which can be used for recovery in the event
  1958. of any problems.</p>
  1959. </li>
  1960. <li>
  1961. <p>As an initial check to see if you will be affected, you can try
  1962. running the following query from the [psql]{.title-ref} or
  1963. [sqlite3]{.title-ref} console. It is safe to run it while Synapse is
  1964. still running.</p>
  1965. <pre><code class="language-sql">SELECT MAX(q.v) FROM (
  1966. SELECT (
  1967. SELECT ej.json AS v
  1968. FROM state_events se INNER JOIN event_json ej USING (event_id)
  1969. WHERE se.room_id=rooms.room_id AND se.type='m.room.create' AND se.state_key=''
  1970. LIMIT 1
  1971. ) FROM rooms WHERE rooms.room_version IS NULL
  1972. ) q;
  1973. </code></pre>
  1974. <p>This query will take about the same amount of time as the upgrade
  1975. process: ie, if it takes 5 minutes, then it is likely that Synapse
  1976. will be unresponsive for 5 minutes during the upgrade.</p>
  1977. <p>If you consider an outage of this duration to be acceptable, no
  1978. further action is necessary and you can simply start Synapse 1.12.0.</p>
  1979. <p>If you would prefer to reduce the downtime, continue with the steps
  1980. below.</p>
  1981. </li>
  1982. <li>
  1983. <p>The easiest workaround for this issue is to manually create a new
  1984. index before upgrading. On PostgreSQL, his can be done as follows:</p>
  1985. <pre><code class="language-sql">CREATE INDEX CONCURRENTLY tmp_upgrade_1_12_0_index
  1986. ON state_events(room_id) WHERE type = 'm.room.create';
  1987. </code></pre>
  1988. <p>The above query may take some time, but is also safe to run while
  1989. Synapse is running.</p>
  1990. <p>We assume that no SQLite users have databases large enough to be
  1991. affected. If you <em>are</em> affected, you can run a similar query,
  1992. omitting the <code>CONCURRENTLY</code> keyword. Note however that this
  1993. operation may in itself cause Synapse to stop running for some time.
  1994. Synapse admins are reminded that <a href="postgres.html">SQLite is not recommended for use
  1995. outside a test environment</a>.</p>
  1996. </li>
  1997. <li>
  1998. <p>Once the index has been created, the <code>SELECT</code> query in step 1 above
  1999. should complete quickly. It is therefore safe to upgrade to Synapse
  2000. 1.12.0.</p>
  2001. </li>
  2002. <li>
  2003. <p>Once Synapse 1.12.0 has successfully started and is responding to
  2004. HTTP requests, the temporary index can be removed:</p>
  2005. <pre><code class="language-sql">DROP INDEX tmp_upgrade_1_12_0_index;
  2006. </code></pre>
  2007. </li>
  2008. </ol>
  2009. <h1 id="upgrading-to-v1100"><a class="header" href="#upgrading-to-v1100">Upgrading to v1.10.0</a></h1>
  2010. <p>Synapse will now log a warning on start up if used with a PostgreSQL
  2011. database that has a non-recommended locale set.</p>
  2012. <p>See <a href="postgres.html">Postgres</a> for details.</p>
  2013. <h1 id="upgrading-to-v180"><a class="header" href="#upgrading-to-v180">Upgrading to v1.8.0</a></h1>
  2014. <p>Specifying a <code>log_file</code> config option will now cause Synapse to refuse
  2015. to start, and should be replaced by with the <code>log_config</code> option.
  2016. Support for the <code>log_file</code> option was removed in v1.3.0 and has since
  2017. had no effect.</p>
  2018. <h1 id="upgrading-to-v170"><a class="header" href="#upgrading-to-v170">Upgrading to v1.7.0</a></h1>
  2019. <p>In an attempt to configure Synapse in a privacy preserving way, the
  2020. default behaviours of <code>allow_public_rooms_without_auth</code> and
  2021. <code>allow_public_rooms_over_federation</code> have been inverted. This means that
  2022. by default, only authenticated users querying the Client/Server API will
  2023. be able to query the room directory, and relatedly that the server will
  2024. not share room directory information with other servers over federation.</p>
  2025. <p>If your installation does not explicitly set these settings one way or
  2026. the other and you want either setting to be <code>true</code> then it will
  2027. necessary to update your homeserver configuration file accordingly.</p>
  2028. <p>For more details on the surrounding context see our
  2029. <a href="https://matrix.org/blog/2019/11/09/avoiding-unwelcome-visitors-on-private-matrix-servers">explainer</a>.</p>
  2030. <h1 id="upgrading-to-v150"><a class="header" href="#upgrading-to-v150">Upgrading to v1.5.0</a></h1>
  2031. <p>This release includes a database migration which may take several
  2032. minutes to complete if there are a large number (more than a million or
  2033. so) of entries in the <code>devices</code> table. This is only likely to a be a
  2034. problem on very large installations.</p>
  2035. <h1 id="upgrading-to-v140"><a class="header" href="#upgrading-to-v140">Upgrading to v1.4.0</a></h1>
  2036. <h2 id="new-custom-templates"><a class="header" href="#new-custom-templates">New custom templates</a></h2>
  2037. <p>If you have configured a custom template directory with the
  2038. <code>email.template_dir</code> option, be aware that there are new templates
  2039. regarding registration and threepid management (see below) that must be
  2040. included.</p>
  2041. <ul>
  2042. <li><code>registration.html</code> and <code>registration.txt</code></li>
  2043. <li><code>registration_success.html</code> and <code>registration_failure.html</code></li>
  2044. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code></li>
  2045. <li><code>add_threepid_failure.html</code> and <code>add_threepid_success.html</code></li>
  2046. </ul>
  2047. <p>Synapse will expect these files to exist inside the configured template
  2048. directory, and <strong>will fail to start</strong> if they are absent. To view the
  2049. default templates, see
  2050. <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">synapse/res/templates</a>.</p>
  2051. <h2 id="3pid-verification-changes"><a class="header" href="#3pid-verification-changes">3pid verification changes</a></h2>
  2052. <p><strong>Note: As of this release, users will be unable to add phone numbers or
  2053. email addresses to their accounts, without changes to the Synapse
  2054. configuration. This includes adding an email address during
  2055. registration.</strong></p>
  2056. <p>It is possible for a user to associate an email address or phone number
  2057. with their account, for a number of reasons:</p>
  2058. <ul>
  2059. <li>for use when logging in, as an alternative to the user id.</li>
  2060. <li>in the case of email, as an alternative contact to help with account
  2061. recovery.</li>
  2062. <li>in the case of email, to receive notifications of missed messages.</li>
  2063. </ul>
  2064. <p>Before an email address or phone number can be added to a user's
  2065. account, or before such an address is used to carry out a
  2066. password-reset, Synapse must confirm the operation with the owner of the
  2067. email address or phone number. It does this by sending an email or text
  2068. giving the user a link or token to confirm receipt. This process is
  2069. known as '3pid verification'. ('3pid', or 'threepid', stands for
  2070. third-party identifier, and we use it to refer to external identifiers
  2071. such as email addresses and phone numbers.)</p>
  2072. <p>Previous versions of Synapse delegated the task of 3pid verification to
  2073. an identity server by default. In most cases this server is <code>vector.im</code>
  2074. or <code>matrix.org</code>.</p>
  2075. <p>In Synapse 1.4.0, for security and privacy reasons, the homeserver will
  2076. no longer delegate this task to an identity server by default. Instead,
  2077. the server administrator will need to explicitly decide how they would
  2078. like the verification messages to be sent.</p>
  2079. <p>In the medium term, the <code>vector.im</code> and <code>matrix.org</code> identity servers
  2080. will disable support for delegated 3pid verification entirely. However,
  2081. in order to ease the transition, they will retain the capability for a
  2082. limited period. Delegated email verification will be disabled on Monday
  2083. 2nd December 2019 (giving roughly 2 months notice). Disabling delegated
  2084. SMS verification will follow some time after that once SMS verification
  2085. support lands in Synapse.</p>
  2086. <p>Once delegated 3pid verification support has been disabled in the
  2087. <code>vector.im</code> and <code>matrix.org</code> identity servers, all Synapse versions that
  2088. depend on those instances will be unable to verify email and phone
  2089. numbers through them. There are no imminent plans to remove delegated
  2090. 3pid verification from Sydent generally. (Sydent is the identity server
  2091. project that backs the <code>vector.im</code> and <code>matrix.org</code> instances).</p>
  2092. <h3 id="email-1"><a class="header" href="#email-1">Email</a></h3>
  2093. <p>Following upgrade, to continue verifying email (e.g. as part of the
  2094. registration process), admins can either:-</p>
  2095. <ul>
  2096. <li>Configure Synapse to use an email server.</li>
  2097. <li>Run or choose an identity server which allows delegated email
  2098. verification and delegate to it.</li>
  2099. </ul>
  2100. <h4 id="configure-smtp-in-synapse"><a class="header" href="#configure-smtp-in-synapse">Configure SMTP in Synapse</a></h4>
  2101. <p>To configure an SMTP server for Synapse, modify the configuration
  2102. section headed <code>email</code>, and be sure to have at least the
  2103. <code>smtp_host, smtp_port</code> and <code>notif_from</code> fields filled out.</p>
  2104. <p>You may also need to set <code>smtp_user</code>, <code>smtp_pass</code>, and
  2105. <code>require_transport_security</code>.</p>
  2106. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2107. for more details on these settings.</p>
  2108. <h4 id="delegate-email-to-an-identity-server"><a class="header" href="#delegate-email-to-an-identity-server">Delegate email to an identity server</a></h4>
  2109. <p>Some admins will wish to continue using email verification as part of
  2110. the registration process, but will not immediately have an appropriate
  2111. SMTP server at hand.</p>
  2112. <p>To this end, we will continue to support email verification delegation
  2113. via the <code>vector.im</code> and <code>matrix.org</code> identity servers for two months.
  2114. Support for delegated email verification will be disabled on Monday 2nd
  2115. December.</p>
  2116. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2117. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2118. server</a>) to handle
  2119. sending confirmation messages via email and SMS.</p>
  2120. <p>So to delegate email verification, in <code>homeserver.yaml</code>, set
  2121. <code>account_threepid_delegates.email</code> to the base URL of an identity
  2122. server. For example:</p>
  2123. <pre><code class="language-yaml">account_threepid_delegates:
  2124. email: https://example.com # Delegate email sending to example.com
  2125. </code></pre>
  2126. <p>Note that <code>account_threepid_delegates.email</code> replaces the deprecated
  2127. <code>email.trust_identity_server_for_password_resets</code>: if
  2128. <code>email.trust_identity_server_for_password_resets</code> is set to <code>true</code>, and
  2129. <code>account_threepid_delegates.email</code> is not set, then the first entry in
  2130. <code>trusted_third_party_id_servers</code> will be used as the
  2131. <code>account_threepid_delegate</code> for email. This is to ensure compatibility
  2132. with existing Synapse installs that set up external server handling for
  2133. these tasks before v1.4.0. If
  2134. <code>email.trust_identity_server_for_password_resets</code> is <code>true</code> and no
  2135. trusted identity server domains are configured, Synapse will report an
  2136. error and refuse to start.</p>
  2137. <p>If <code>email.trust_identity_server_for_password_resets</code> is <code>false</code> or
  2138. absent and no <code>email</code> delegate is configured in
  2139. <code>account_threepid_delegates</code>, then Synapse will send email verification
  2140. messages itself, using the configured SMTP server (see above). that
  2141. type.</p>
  2142. <h3 id="phone-numbers"><a class="header" href="#phone-numbers">Phone numbers</a></h3>
  2143. <p>Synapse does not support phone-number verification itself, so the only
  2144. way to maintain the ability for users to add phone numbers to their
  2145. accounts will be by continuing to delegate phone number verification to
  2146. the <code>matrix.org</code> and <code>vector.im</code> identity servers (or another identity
  2147. server that supports SMS sending).</p>
  2148. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2149. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2150. server</a>) to handle
  2151. sending confirmation messages via email and SMS.</p>
  2152. <p>So to delegate phone number verification, in <code>homeserver.yaml</code>, set
  2153. <code>account_threepid_delegates.msisdn</code> to the base URL of an identity
  2154. server. For example:</p>
  2155. <pre><code class="language-yaml">account_threepid_delegates:
  2156. msisdn: https://example.com # Delegate sms sending to example.com
  2157. </code></pre>
  2158. <p>The <code>matrix.org</code> and <code>vector.im</code> identity servers will continue to
  2159. support delegated phone number verification via SMS until such time as
  2160. it is possible for admins to configure their servers to perform phone
  2161. number verification directly. More details will follow in a future
  2162. release.</p>
  2163. <h2 id="rolling-back-to-v131"><a class="header" href="#rolling-back-to-v131">Rolling back to v1.3.1</a></h2>
  2164. <p>If you encounter problems with v1.4.0, it should be possible to roll
  2165. back to v1.3.1, subject to the following:</p>
  2166. <ul>
  2167. <li>
  2168. <p>The 'room statistics' engine was heavily reworked in this release
  2169. (see <a href="https://github.com/matrix-org/synapse/pull/5971">#5971</a>),
  2170. including significant changes to the database schema, which are not
  2171. easily reverted. This will cause the room statistics engine to stop
  2172. updating when you downgrade.</p>
  2173. <p>The room statistics are essentially unused in v1.3.1 (in future
  2174. versions of Synapse, they will be used to populate the room
  2175. directory), so there should be no loss of functionality. However,
  2176. the statistics engine will write errors to the logs, which can be
  2177. avoided by setting the following in <code>homeserver.yaml</code>:</p>
  2178. <pre><code class="language-yaml">stats:
  2179. enabled: false
  2180. </code></pre>
  2181. <p>Don't forget to re-enable it when you upgrade again, in preparation
  2182. for its use in the room directory!</p>
  2183. </li>
  2184. </ul>
  2185. <h1 id="upgrading-to-v120"><a class="header" href="#upgrading-to-v120">Upgrading to v1.2.0</a></h1>
  2186. <p>Some counter metrics have been renamed, with the old names deprecated.
  2187. See <a href="metrics-howto.html#renaming-of-metrics--deprecation-of-old-names-in-12">the metrics
  2188. documentation</a>
  2189. for details.</p>
  2190. <h1 id="upgrading-to-v110"><a class="header" href="#upgrading-to-v110">Upgrading to v1.1.0</a></h1>
  2191. <p>Synapse v1.1.0 removes support for older Python and PostgreSQL versions,
  2192. as outlined in <a href="https://matrix.org/blog/2019/04/08/synapse-deprecating-postgres-9-4-and-python-2-x">our deprecation
  2193. notice</a>.</p>
  2194. <h2 id="minimum-python-version"><a class="header" href="#minimum-python-version">Minimum Python Version</a></h2>
  2195. <p>Synapse v1.1.0 has a minimum Python requirement of Python 3.5. Python
  2196. 3.6 or Python 3.7 are recommended as they have improved internal string
  2197. handling, significantly reducing memory usage.</p>
  2198. <p>If you use current versions of the Matrix.org-distributed Debian
  2199. packages or Docker images, action is not required.</p>
  2200. <p>If you install Synapse in a Python virtual environment, please see
  2201. &quot;Upgrading to v0.34.0&quot; for notes on setting up a new virtualenv under
  2202. Python 3.</p>
  2203. <h2 id="minimum-postgresql-version"><a class="header" href="#minimum-postgresql-version">Minimum PostgreSQL Version</a></h2>
  2204. <p>If using PostgreSQL under Synapse, you will need to use PostgreSQL 9.5
  2205. or above. Please see the <a href="https://www.postgresql.org/docs/11/upgrading.html">PostgreSQL
  2206. documentation</a> for
  2207. more details on upgrading your database.</p>
  2208. <h1 id="upgrading-to-v10"><a class="header" href="#upgrading-to-v10">Upgrading to v1.0</a></h1>
  2209. <h2 id="validation-of-tls-certificates"><a class="header" href="#validation-of-tls-certificates">Validation of TLS certificates</a></h2>
  2210. <p>Synapse v1.0 is the first release to enforce validation of TLS
  2211. certificates for the federation API. It is therefore essential that your
  2212. certificates are correctly configured. See the
  2213. <a href="MSC1711_certificates_FAQ.html">FAQ</a> for more information.</p>
  2214. <p>Note, v1.0 installations will also no longer be able to federate with
  2215. servers that have not correctly configured their certificates.</p>
  2216. <p>In rare cases, it may be desirable to disable certificate checking: for
  2217. example, it might be essential to be able to federate with a given
  2218. legacy server in a closed federation. This can be done in one of two
  2219. ways:-</p>
  2220. <ul>
  2221. <li>Configure the global switch <code>federation_verify_certificates</code> to
  2222. <code>false</code>.</li>
  2223. <li>Configure a whitelist of server domains to trust via
  2224. <code>federation_certificate_verification_whitelist</code>.</li>
  2225. </ul>
  2226. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2227. for more details on these settings.</p>
  2228. <h2 id="email-2"><a class="header" href="#email-2">Email</a></h2>
  2229. <p>When a user requests a password reset, Synapse will send an email to the
  2230. user to confirm the request.</p>
  2231. <p>Previous versions of Synapse delegated the job of sending this email to
  2232. an identity server. If the identity server was somehow malicious or
  2233. became compromised, it would be theoretically possible to hijack an
  2234. account through this means.</p>
  2235. <p>Therefore, by default, Synapse v1.0 will send the confirmation email
  2236. itself. If Synapse is not configured with an SMTP server, password reset
  2237. via email will be disabled.</p>
  2238. <p>To configure an SMTP server for Synapse, modify the configuration
  2239. section headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>,
  2240. <code>smtp_port</code> and <code>notif_from</code> fields filled out. You may also need to set
  2241. <code>smtp_user</code>, <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  2242. <p>If you are absolutely certain that you wish to continue using an
  2243. identity server for password resets, set
  2244. <code>trust_identity_server_for_password_resets</code> to <code>true</code>.</p>
  2245. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2246. for more details on these settings.</p>
  2247. <h2 id="new-email-templates"><a class="header" href="#new-email-templates">New email templates</a></h2>
  2248. <p>Some new templates have been added to the default template directory for the purpose of
  2249. the homeserver sending its own password reset emails. If you have configured a
  2250. custom <code>template_dir</code> in your Synapse config, these files will need to be added.</p>
  2251. <p><code>password_reset.html</code> and <code>password_reset.txt</code> are HTML and plain text
  2252. templates respectively that contain the contents of what will be emailed
  2253. to the user upon attempting to reset their password via email.
  2254. <code>password_reset_success.html</code> and <code>password_reset_failure.html</code> are HTML
  2255. files that the content of which (assuming no redirect URL is set) will
  2256. be shown to the user after they attempt to click the link in the email
  2257. sent to them.</p>
  2258. <h1 id="upgrading-to-v0990"><a class="header" href="#upgrading-to-v0990">Upgrading to v0.99.0</a></h1>
  2259. <p>Please be aware that, before Synapse v1.0 is released around March 2019,
  2260. you will need to replace any self-signed certificates with those
  2261. verified by a root CA. Information on how to do so can be found at the
  2262. ACME docs.</p>
  2263. <p>For more information on configuring TLS certificates see the
  2264. <a href="MSC1711_certificates_FAQ.html">FAQ</a>.</p>
  2265. <h1 id="upgrading-to-v0340"><a class="header" href="#upgrading-to-v0340">Upgrading to v0.34.0</a></h1>
  2266. <ol>
  2267. <li>
  2268. <p>This release is the first to fully support Python 3. Synapse will
  2269. now run on Python versions 3.5, or 3.6 (as well as 2.7). We
  2270. recommend switching to Python 3, as it has been shown to give
  2271. performance improvements.</p>
  2272. <p>For users who have installed Synapse into a virtualenv, we recommend
  2273. doing this by creating a new virtualenv. For example:</p>
  2274. <pre><code>virtualenv -p python3 ~/synapse/env3
  2275. source ~/synapse/env3/bin/activate
  2276. pip install matrix-synapse
  2277. </code></pre>
  2278. <p>You can then start synapse as normal, having activated the new
  2279. virtualenv:</p>
  2280. <pre><code>cd ~/synapse
  2281. source env3/bin/activate
  2282. synctl start
  2283. </code></pre>
  2284. <p>Users who have installed from distribution packages should see the
  2285. relevant package documentation. See below for notes on Debian
  2286. packages.</p>
  2287. <ul>
  2288. <li>
  2289. <p>When upgrading to Python 3, you <strong>must</strong> make sure that your log
  2290. files are configured as UTF-8, by adding <code>encoding: utf8</code> to the
  2291. <code>RotatingFileHandler</code> configuration (if you have one) in your
  2292. <code>&lt;server&gt;.log.config</code> file. For example, if your <code>log.config</code>
  2293. file contains:</p>
  2294. <pre><code>handlers:
  2295. file:
  2296. class: logging.handlers.RotatingFileHandler
  2297. formatter: precise
  2298. filename: homeserver.log
  2299. maxBytes: 104857600
  2300. backupCount: 10
  2301. filters: [context]
  2302. console:
  2303. class: logging.StreamHandler
  2304. formatter: precise
  2305. filters: [context]
  2306. </code></pre>
  2307. <p>Then you should update this to be:</p>
  2308. <pre><code>handlers:
  2309. file:
  2310. class: logging.handlers.RotatingFileHandler
  2311. formatter: precise
  2312. filename: homeserver.log
  2313. maxBytes: 104857600
  2314. backupCount: 10
  2315. filters: [context]
  2316. encoding: utf8
  2317. console:
  2318. class: logging.StreamHandler
  2319. formatter: precise
  2320. filters: [context]
  2321. </code></pre>
  2322. <p>There is no need to revert this change if downgrading to
  2323. Python 2.</p>
  2324. </li>
  2325. </ul>
  2326. <p>We are also making available Debian packages which will run Synapse
  2327. on Python 3. You can switch to these packages with
  2328. <code>apt-get install matrix-synapse-py3</code>, however, please read
  2329. <a href="https://github.com/matrix-org/synapse/blob/release-v0.34.0/debian/NEWS">debian/NEWS</a>
  2330. before doing so. The existing <code>matrix-synapse</code> packages will
  2331. continue to use Python 2 for the time being.</p>
  2332. </li>
  2333. <li>
  2334. <p>This release removes the <code>riot.im</code> from the default list of trusted
  2335. identity servers.</p>
  2336. <p>If <code>riot.im</code> is in your homeserver's list of
  2337. <code>trusted_third_party_id_servers</code>, you should remove it. It was added
  2338. in case a hypothetical future identity server was put there. If you
  2339. don't remove it, users may be unable to deactivate their accounts.</p>
  2340. </li>
  2341. <li>
  2342. <p>This release no longer installs the (unmaintained) Matrix Console
  2343. web client as part of the default installation. It is possible to
  2344. re-enable it by installing it separately and setting the
  2345. <code>web_client_location</code> config option, but please consider switching
  2346. to another client.</p>
  2347. </li>
  2348. </ol>
  2349. <h1 id="upgrading-to-v0337"><a class="header" href="#upgrading-to-v0337">Upgrading to v0.33.7</a></h1>
  2350. <p>This release removes the example email notification templates from
  2351. <code>res/templates</code> (they are now internal to the python package). This
  2352. should only affect you if you (a) deploy your Synapse instance from a
  2353. git checkout or a github snapshot URL, and (b) have email notifications
  2354. enabled.</p>
  2355. <p>If you have email notifications enabled, you should ensure that
  2356. <code>email.template_dir</code> is either configured to point at a directory where
  2357. you have installed customised templates, or leave it unset to use the
  2358. default templates.</p>
  2359. <h1 id="upgrading-to-v0273"><a class="header" href="#upgrading-to-v0273">Upgrading to v0.27.3</a></h1>
  2360. <p>This release expands the anonymous usage stats sent if the opt-in
  2361. <code>report_stats</code> configuration is set to <code>true</code>. We now capture RSS memory
  2362. and cpu use at a very coarse level. This requires administrators to
  2363. install the optional <code>psutil</code> python module.</p>
  2364. <p>We would appreciate it if you could assist by ensuring this module is
  2365. available and <code>report_stats</code> is enabled. This will let us see if
  2366. performance changes to synapse are having an impact to the general
  2367. community.</p>
  2368. <h1 id="upgrading-to-v0150"><a class="header" href="#upgrading-to-v0150">Upgrading to v0.15.0</a></h1>
  2369. <p>If you want to use the new URL previewing API
  2370. (<code>/_matrix/media/r0/preview_url</code>) then you have to explicitly enable it
  2371. in the config and update your dependencies dependencies. See README.rst
  2372. for details.</p>
  2373. <h1 id="upgrading-to-v0110"><a class="header" href="#upgrading-to-v0110">Upgrading to v0.11.0</a></h1>
  2374. <p>This release includes the option to send anonymous usage stats to
  2375. matrix.org, and requires that administrators explictly opt in or out by
  2376. setting the <code>report_stats</code> option to either <code>true</code> or <code>false</code>.</p>
  2377. <p>We would really appreciate it if you could help our project out by
  2378. reporting anonymized usage statistics from your homeserver. Only very
  2379. basic aggregate data (e.g. number of users) will be reported, but it
  2380. helps us to track the growth of the Matrix community, and helps us to
  2381. make Matrix a success, as well as to convince other networks that they
  2382. should peer with us.</p>
  2383. <h1 id="upgrading-to-v090"><a class="header" href="#upgrading-to-v090">Upgrading to v0.9.0</a></h1>
  2384. <p>Application services have had a breaking API change in this version.</p>
  2385. <p>They can no longer register themselves with a home server using the AS
  2386. HTTP API. This decision was made because a compromised application
  2387. service with free reign to register any regex in effect grants full
  2388. read/write access to the home server if a regex of <code>.*</code> is used. An
  2389. attack where a compromised AS re-registers itself with <code>.*</code> was deemed
  2390. too big of a security risk to ignore, and so the ability to register
  2391. with the HS remotely has been removed.</p>
  2392. <p>It has been replaced by specifying a list of application service
  2393. registrations in <code>homeserver.yaml</code>:</p>
  2394. <pre><code>app_service_config_files: [&quot;registration-01.yaml&quot;, &quot;registration-02.yaml&quot;]
  2395. </code></pre>
  2396. <p>Where <code>registration-01.yaml</code> looks like:</p>
  2397. <pre><code>url: &lt;String&gt; # e.g. &quot;https://my.application.service.com&quot;
  2398. as_token: &lt;String&gt;
  2399. hs_token: &lt;String&gt;
  2400. sender_localpart: &lt;String&gt; # This is a new field which denotes the user_id localpart when using the AS token
  2401. namespaces:
  2402. users:
  2403. - exclusive: &lt;Boolean&gt;
  2404. regex: &lt;String&gt; # e.g. &quot;@prefix_.*&quot;
  2405. aliases:
  2406. - exclusive: &lt;Boolean&gt;
  2407. regex: &lt;String&gt;
  2408. rooms:
  2409. - exclusive: &lt;Boolean&gt;
  2410. regex: &lt;String&gt;
  2411. </code></pre>
  2412. <h1 id="upgrading-to-v080"><a class="header" href="#upgrading-to-v080">Upgrading to v0.8.0</a></h1>
  2413. <p>Servers which use captchas will need to add their public key to:</p>
  2414. <pre><code>static/client/register/register_config.js
  2415. window.matrixRegistrationConfig = {
  2416. recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  2417. };
  2418. </code></pre>
  2419. <p>This is required in order to support registration fallback (typically
  2420. used on mobile devices).</p>
  2421. <h1 id="upgrading-to-v070"><a class="header" href="#upgrading-to-v070">Upgrading to v0.7.0</a></h1>
  2422. <p>New dependencies are:</p>
  2423. <ul>
  2424. <li>pydenticon</li>
  2425. <li>simplejson</li>
  2426. <li>syutil</li>
  2427. <li>matrix-angular-sdk</li>
  2428. </ul>
  2429. <p>To pull in these dependencies in a virtual env, run:</p>
  2430. <pre><code>python synapse/python_dependencies.py | xargs -n 1 pip install
  2431. </code></pre>
  2432. <h1 id="upgrading-to-v060"><a class="header" href="#upgrading-to-v060">Upgrading to v0.6.0</a></h1>
  2433. <p>To pull in new dependencies, run:</p>
  2434. <pre><code>python setup.py develop --user
  2435. </code></pre>
  2436. <p>This update includes a change to the database schema. To upgrade you
  2437. first need to upgrade the database by running:</p>
  2438. <pre><code>python scripts/upgrade_db_to_v0.6.0.py &lt;db&gt; &lt;server_name&gt; &lt;signing_key&gt;
  2439. </code></pre>
  2440. <p>Where [<db>]{.title-ref} is the location of the database,
  2441. [&lt;server_name&gt;]{.title-ref} is the server name as specified in the
  2442. synapse configuration, and [&lt;signing_key&gt;]{.title-ref} is the location
  2443. of the signing key as specified in the synapse configuration.</p>
  2444. <p>This may take some time to complete. Failures of signatures and content
  2445. hashes can safely be ignored.</p>
  2446. <h1 id="upgrading-to-v051"><a class="header" href="#upgrading-to-v051">Upgrading to v0.5.1</a></h1>
  2447. <p>Depending on precisely when you installed v0.5.0 you may have ended up
  2448. with a stale release of the reference matrix webclient installed as a
  2449. python module. To uninstall it and ensure you are depending on the
  2450. latest module, please run:</p>
  2451. <pre><code>$ pip uninstall syweb
  2452. </code></pre>
  2453. <h1 id="upgrading-to-v050"><a class="header" href="#upgrading-to-v050">Upgrading to v0.5.0</a></h1>
  2454. <p>The webclient has been split out into a seperate repository/pacakage in
  2455. this release. Before you restart your homeserver you will need to pull
  2456. in the webclient package by running:</p>
  2457. <pre><code>python setup.py develop --user
  2458. </code></pre>
  2459. <p>This release completely changes the database schema and so requires
  2460. upgrading it before starting the new version of the homeserver.</p>
  2461. <p>The script &quot;database-prepare-for-0.5.0.sh&quot; should be used to upgrade
  2462. the database. This will save all user information, such as logins and
  2463. profiles, but will otherwise purge the database. This includes messages,
  2464. which rooms the home server was a member of and room alias mappings.</p>
  2465. <p>If you would like to keep your history, please take a copy of your
  2466. database file and ask for help in #matrix:matrix.org. The upgrade
  2467. process is, unfortunately, non trivial and requires human intervention
  2468. to resolve any resulting conflicts during the upgrade process.</p>
  2469. <p>Before running the command the homeserver should be first completely
  2470. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2471. <blockquote>
  2472. <p>./scripts/database-prepare-for-0.5.0.sh &quot;homeserver.db&quot;</p>
  2473. </blockquote>
  2474. <p>Once this has successfully completed it will be safe to restart the
  2475. homeserver. You may notice that the homeserver takes a few seconds
  2476. longer to restart than usual as it reinitializes the database.</p>
  2477. <p>On startup of the new version, users can either rejoin remote rooms
  2478. using room aliases or by being reinvited. Alternatively, if any other
  2479. homeserver sends a message to a room that the homeserver was previously
  2480. in the local HS will automatically rejoin the room.</p>
  2481. <h1 id="upgrading-to-v040"><a class="header" href="#upgrading-to-v040">Upgrading to v0.4.0</a></h1>
  2482. <p>This release needs an updated syutil version. Run:</p>
  2483. <pre><code>python setup.py develop
  2484. </code></pre>
  2485. <p>You will also need to upgrade your configuration as the signing key
  2486. format has changed. Run:</p>
  2487. <pre><code>python -m synapse.app.homeserver --config-path &lt;CONFIG&gt; --generate-config
  2488. </code></pre>
  2489. <h1 id="upgrading-to-v030"><a class="header" href="#upgrading-to-v030">Upgrading to v0.3.0</a></h1>
  2490. <p>This registration API now closely matches the login API. This introduces
  2491. a bit more backwards and forwards between the HS and the client, but
  2492. this improves the overall flexibility of the API. You can now GET on
  2493. /register to retrieve a list of valid registration flows. Upon choosing
  2494. one, they are submitted in the same way as login, e.g:</p>
  2495. <pre><code>{
  2496. type: m.login.password,
  2497. user: foo,
  2498. password: bar
  2499. }
  2500. </code></pre>
  2501. <p>The default HS supports 2 flows, with and without Identity Server email
  2502. authentication. Enabling captcha on the HS will add in an extra step to
  2503. all flows: <code>m.login.recaptcha</code> which must be completed before you can
  2504. transition to the next stage. There is a new login type:
  2505. <code>m.login.email.identity</code> which contains the <code>threepidCreds</code> key which
  2506. were previously sent in the original register request. For more
  2507. information on this, see the specification.</p>
  2508. <h2 id="web-client"><a class="header" href="#web-client">Web Client</a></h2>
  2509. <p>The VoIP specification has changed between v0.2.0 and v0.3.0. Users
  2510. should refresh any browser tabs to get the latest web client code. Users
  2511. on v0.2.0 of the web client will not be able to call those on v0.3.0 and
  2512. vice versa.</p>
  2513. <h1 id="upgrading-to-v020"><a class="header" href="#upgrading-to-v020">Upgrading to v0.2.0</a></h1>
  2514. <p>The home server now requires setting up of SSL config before it can run.
  2515. To automatically generate default config use:</p>
  2516. <pre><code>$ python synapse/app/homeserver.py \
  2517. --server-name machine.my.domain.name \
  2518. --bind-port 8448 \
  2519. --config-path homeserver.config \
  2520. --generate-config
  2521. </code></pre>
  2522. <p>This config can be edited if desired, for example to specify a different
  2523. SSL certificate to use. Once done you can run the home server using:</p>
  2524. <pre><code>$ python synapse/app/homeserver.py --config-path homeserver.config
  2525. </code></pre>
  2526. <p>See the README.rst for more information.</p>
  2527. <p>Also note that some config options have been renamed, including:</p>
  2528. <ul>
  2529. <li>&quot;host&quot; to &quot;server-name&quot;</li>
  2530. <li>&quot;database&quot; to &quot;database-path&quot;</li>
  2531. <li>&quot;port&quot; to &quot;bind-port&quot; and &quot;unsecure-port&quot;</li>
  2532. </ul>
  2533. <h1 id="upgrading-to-v001"><a class="header" href="#upgrading-to-v001">Upgrading to v0.0.1</a></h1>
  2534. <p>This release completely changes the database schema and so requires
  2535. upgrading it before starting the new version of the homeserver.</p>
  2536. <p>The script &quot;database-prepare-for-0.0.1.sh&quot; should be used to upgrade
  2537. the database. This will save all user information, such as logins and
  2538. profiles, but will otherwise purge the database. This includes messages,
  2539. which rooms the home server was a member of and room alias mappings.</p>
  2540. <p>Before running the command the homeserver should be first completely
  2541. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2542. <blockquote>
  2543. <p>./scripts/database-prepare-for-0.0.1.sh &quot;homeserver.db&quot;</p>
  2544. </blockquote>
  2545. <p>Once this has successfully completed it will be safe to restart the
  2546. homeserver. You may notice that the homeserver takes a few seconds
  2547. longer to restart than usual as it reinitializes the database.</p>
  2548. <p>On startup of the new version, users can either rejoin remote rooms
  2549. using room aliases or by being reinvited. Alternatively, if any other
  2550. homeserver sends a message to a room that the homeserver was previously
  2551. in the local HS will automatically rejoin the room.</p>
  2552. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="msc1711-certificates-faq"><a class="header" href="#msc1711-certificates-faq">MSC1711 Certificates FAQ</a></h1>
  2553. <h2 id="historical-note"><a class="header" href="#historical-note">Historical Note</a></h2>
  2554. <p>This document was originally written to guide server admins through the upgrade
  2555. path towards Synapse 1.0. Specifically,
  2556. <a href="https://github.com/matrix-org/matrix-doc/blob/master/proposals/1711-x509-for-federation.md">MSC1711</a>
  2557. required that all servers present valid TLS certificates on their federation
  2558. API. Admins were encouraged to achieve compliance from version 0.99.0 (released
  2559. in February 2019) ahead of version 1.0 (released June 2019) enforcing the
  2560. certificate checks.</p>
  2561. <p>Much of what follows is now outdated since most admins will have already
  2562. upgraded, however it may be of use to those with old installs returning to the
  2563. project.</p>
  2564. <p>If you are setting up a server from scratch you almost certainly should look at
  2565. the <a href="setup/installation.html">installation guide</a> instead.</p>
  2566. <h2 id="introduction-1"><a class="header" href="#introduction-1">Introduction</a></h2>
  2567. <p>The goal of Synapse 0.99.0 is to act as a stepping stone to Synapse 1.0.0. It
  2568. supports the r0.1 release of the server to server specification, but is
  2569. compatible with both the legacy Matrix federation behaviour (pre-r0.1) as well
  2570. as post-r0.1 behaviour, in order to allow for a smooth upgrade across the
  2571. federation.</p>
  2572. <p>The most important thing to know is that Synapse 1.0.0 will require a valid TLS
  2573. certificate on federation endpoints. Self signed certificates will not be
  2574. sufficient.</p>
  2575. <p>Synapse 0.99.0 makes it easy to configure TLS certificates and will
  2576. interoperate with both &gt;= 1.0.0 servers as well as existing servers yet to
  2577. upgrade.</p>
  2578. <p><strong>It is critical that all admins upgrade to 0.99.0 and configure a valid TLS
  2579. certificate.</strong> Admins will have 1 month to do so, after which 1.0.0 will be
  2580. released and those servers without a valid certificate will not longer be able
  2581. to federate with &gt;= 1.0.0 servers.</p>
  2582. <p>Full details on how to carry out this configuration change is given
  2583. <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">below</a>. A
  2584. timeline and some frequently asked questions are also given below.</p>
  2585. <p>For more details and context on the release of the r0.1 Server/Server API and
  2586. imminent Matrix 1.0 release, you can also see our
  2587. <a href="https://matrix.org/blog/2019/02/04/matrix-at-fosdem-2019/">main talk from FOSDEM 2019</a>.</p>
  2588. <h2 id="contents"><a class="header" href="#contents">Contents</a></h2>
  2589. <ul>
  2590. <li>Timeline</li>
  2591. <li>Configuring certificates for compatibility with Synapse 1.0</li>
  2592. <li>FAQ
  2593. <ul>
  2594. <li>Synapse 0.99.0 has just been released, what do I need to do right now?</li>
  2595. <li>How do I upgrade?</li>
  2596. <li>What will happen if I do not set up a valid federation certificate
  2597. immediately?</li>
  2598. <li>What will happen if I do nothing at all?</li>
  2599. <li>When do I need a SRV record or .well-known URI?</li>
  2600. <li>Can I still use an SRV record?</li>
  2601. <li>I have created a .well-known URI. Do I still need an SRV record?</li>
  2602. <li>It used to work just fine, why are you breaking everything?</li>
  2603. <li>Can I manage my own certificates rather than having Synapse renew
  2604. certificates itself?</li>
  2605. <li>Do you still recommend against using a reverse proxy on the federation port?</li>
  2606. <li>Do I still need to give my TLS certificates to Synapse if I am using a
  2607. reverse proxy?</li>
  2608. <li>Do I need the same certificate for the client and federation port?</li>
  2609. <li>How do I tell Synapse to reload my keys/certificates after I replace them?</li>
  2610. </ul>
  2611. </li>
  2612. </ul>
  2613. <h2 id="timeline"><a class="header" href="#timeline">Timeline</a></h2>
  2614. <p><strong>5th Feb 2019 - Synapse 0.99.0 is released.</strong></p>
  2615. <p>All server admins are encouraged to upgrade.</p>
  2616. <p>0.99.0:</p>
  2617. <ul>
  2618. <li>
  2619. <p>provides support for ACME to make setting up Let's Encrypt certs easy, as
  2620. well as .well-known support.</p>
  2621. </li>
  2622. <li>
  2623. <p>does not enforce that a valid CA cert is present on the federation API, but
  2624. rather makes it easy to set one up.</p>
  2625. </li>
  2626. <li>
  2627. <p>provides support for .well-known</p>
  2628. </li>
  2629. </ul>
  2630. <p>Admins should upgrade and configure a valid CA cert. Homeservers that require a
  2631. .well-known entry (see below), should retain their SRV record and use it
  2632. alongside their .well-known record.</p>
  2633. <p><strong>10th June 2019 - Synapse 1.0.0 is released</strong></p>
  2634. <p>1.0.0 is scheduled for release on 10th June. In
  2635. accordance with the the <a href="https://matrix.org/docs/spec/server_server/r0.1.0.html">S2S spec</a>
  2636. 1.0.0 will enforce certificate validity. This means that any homeserver without a
  2637. valid certificate after this point will no longer be able to federate with
  2638. 1.0.0 servers.</p>
  2639. <h2 id="configuring-certificates-for-compatibility-with-synapse-100"><a class="header" href="#configuring-certificates-for-compatibility-with-synapse-100">Configuring certificates for compatibility with Synapse 1.0.0</a></h2>
  2640. <h3 id="if-you-do-not-currently-have-an-srv-record"><a class="header" href="#if-you-do-not-currently-have-an-srv-record">If you do not currently have an SRV record</a></h3>
  2641. <p>In this case, your <code>server_name</code> points to the host where your Synapse is
  2642. running. There is no need to create a <code>.well-known</code> URI or an SRV record, but
  2643. you will need to give Synapse a valid, signed, certificate.</p>
  2644. <h3 id="if-you-do-have-an-srv-record-currently"><a class="header" href="#if-you-do-have-an-srv-record-currently">If you do have an SRV record currently</a></h3>
  2645. <p>If you are using an SRV record, your matrix domain (<code>server_name</code>) may not
  2646. point to the same host that your Synapse is running on (the 'target
  2647. domain'). (If it does, you can follow the recommendation above; otherwise, read
  2648. on.)</p>
  2649. <p>Let's assume that your <code>server_name</code> is <code>example.com</code>, and your Synapse is
  2650. hosted at a target domain of <code>customer.example.net</code>. Currently you should have
  2651. an SRV record which looks like:</p>
  2652. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 8000 customer.example.net.
  2653. </code></pre>
  2654. <p>In this situation, you have three choices for how to proceed:</p>
  2655. <h4 id="option-1-give-synapse-a-certificate-for-your-matrix-domain"><a class="header" href="#option-1-give-synapse-a-certificate-for-your-matrix-domain">Option 1: give Synapse a certificate for your matrix domain</a></h4>
  2656. <p>Synapse 1.0 will expect your server to present a TLS certificate for your
  2657. <code>server_name</code> (<code>example.com</code> in the above example). You can achieve this by acquiring a
  2658. certificate for the <code>server_name</code> yourself (for example, using <code>certbot</code>), and giving it
  2659. and the key to Synapse via <code>tls_certificate_path</code> and <code>tls_private_key_path</code>.</p>
  2660. <h4 id="option-2-run-synapse-behind-a-reverse-proxy"><a class="header" href="#option-2-run-synapse-behind-a-reverse-proxy">Option 2: run Synapse behind a reverse proxy</a></h4>
  2661. <p>If you have an existing reverse proxy set up with correct TLS certificates for
  2662. your domain, you can simply route all traffic through the reverse proxy by
  2663. updating the SRV record appropriately (or removing it, if the proxy listens on
  2664. 8448).</p>
  2665. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2666. reverse proxy.</p>
  2667. <h4 id="option-3-add-a-well-known-file-to-delegate-your-matrix-traffic"><a class="header" href="#option-3-add-a-well-known-file-to-delegate-your-matrix-traffic">Option 3: add a .well-known file to delegate your matrix traffic</a></h4>
  2668. <p>This will allow you to keep Synapse on a separate domain, without having to
  2669. give it a certificate for the matrix domain.</p>
  2670. <p>You can do this with a <code>.well-known</code> file as follows:</p>
  2671. <ol>
  2672. <li>
  2673. <p>Keep the SRV record in place - it is needed for backwards compatibility
  2674. with Synapse 0.34 and earlier.</p>
  2675. </li>
  2676. <li>
  2677. <p>Give Synapse a certificate corresponding to the target domain
  2678. (<code>customer.example.net</code> in the above example). You can do this by acquire a
  2679. certificate for the target domain and giving it to Synapse via <code>tls_certificate_path</code>
  2680. and <code>tls_private_key_path</code>.</p>
  2681. </li>
  2682. <li>
  2683. <p>Restart Synapse to ensure the new certificate is loaded.</p>
  2684. </li>
  2685. <li>
  2686. <p>Arrange for a <code>.well-known</code> file at
  2687. <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> with contents:</p>
  2688. <pre><code class="language-json">{&quot;m.server&quot;: &quot;&lt;target server name&gt;&quot;}
  2689. </code></pre>
  2690. <p>where the target server name is resolved as usual (i.e. SRV lookup, falling
  2691. back to talking to port 8448).</p>
  2692. <p>In the above example, where synapse is listening on port 8000,
  2693. <code>https://example.com/.well-known/matrix/server</code> should have <code>m.server</code> set to one of:</p>
  2694. <ol>
  2695. <li>
  2696. <p><code>customer.example.net</code> ─ with a SRV record on
  2697. <code>_matrix._tcp.customer.example.com</code> pointing to port 8000, or:</p>
  2698. </li>
  2699. <li>
  2700. <p><code>customer.example.net</code> ─ updating synapse to listen on the default port
  2701. 8448, or:</p>
  2702. </li>
  2703. <li>
  2704. <p><code>customer.example.net:8000</code> ─ ensuring that if there is a reverse proxy
  2705. on <code>customer.example.net:8000</code> it correctly handles HTTP requests with
  2706. Host header set to <code>customer.example.net:8000</code>.</p>
  2707. </li>
  2708. </ol>
  2709. </li>
  2710. </ol>
  2711. <h2 id="faq"><a class="header" href="#faq">FAQ</a></h2>
  2712. <h3 id="synapse-0990-has-just-been-released-what-do-i-need-to-do-right-now"><a class="header" href="#synapse-0990-has-just-been-released-what-do-i-need-to-do-right-now">Synapse 0.99.0 has just been released, what do I need to do right now?</a></h3>
  2713. <p>Upgrade as soon as you can in preparation for Synapse 1.0.0, and update your
  2714. TLS certificates as <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">above</a>.</p>
  2715. <h3 id="what-will-happen-if-i-do-not-set-up-a-valid-federation-certificate-immediately"><a class="header" href="#what-will-happen-if-i-do-not-set-up-a-valid-federation-certificate-immediately">What will happen if I do not set up a valid federation certificate immediately?</a></h3>
  2716. <p>Nothing initially, but once 1.0.0 is in the wild it will not be possible to
  2717. federate with 1.0.0 servers.</p>
  2718. <h3 id="what-will-happen-if-i-do-nothing-at-all"><a class="header" href="#what-will-happen-if-i-do-nothing-at-all">What will happen if I do nothing at all?</a></h3>
  2719. <p>If the admin takes no action at all, and remains on a Synapse &lt; 0.99.0 then the
  2720. homeserver will be unable to federate with those who have implemented
  2721. .well-known. Then, as above, once the month upgrade window has expired the
  2722. homeserver will not be able to federate with any Synapse &gt;= 1.0.0</p>
  2723. <h3 id="when-do-i-need-a-srv-record-or-well-known-uri"><a class="header" href="#when-do-i-need-a-srv-record-or-well-known-uri">When do I need a SRV record or .well-known URI?</a></h3>
  2724. <p>If your homeserver listens on the default federation port (8448), and your
  2725. <code>server_name</code> points to the host that your homeserver runs on, you do not need an
  2726. SRV record or <code>.well-known/matrix/server</code> URI.</p>
  2727. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  2728. fresh Upcloud VPS or similar, you could install Synapse 0.99 on that host,
  2729. giving it a server_name of <code>example.com</code>, and it would automatically generate a
  2730. valid TLS certificate for you via Let's Encrypt and no SRV record or
  2731. <code>.well-known</code> URI would be needed.</p>
  2732. <p>This is the common case, although you can add an SRV record or
  2733. <code>.well-known/matrix/server</code> URI for completeness if you wish.</p>
  2734. <p><strong>However</strong>, if your server does not listen on port 8448, or if your <code>server_name</code>
  2735. does not point to the host that your homeserver runs on, you will need to let
  2736. other servers know how to find it.</p>
  2737. <p>In this case, you should see <a href="MSC1711_certificates_FAQ.html#if-you-do-have-an-srv-record-currently">&quot;If you do have an SRV record
  2738. currently&quot;</a> above.</p>
  2739. <h3 id="can-i-still-use-an-srv-record"><a class="header" href="#can-i-still-use-an-srv-record">Can I still use an SRV record?</a></h3>
  2740. <p>Firstly, if you didn't need an SRV record before (because your server is
  2741. listening on port 8448 of your server_name), you certainly don't need one now:
  2742. the defaults are still the same.</p>
  2743. <p>If you previously had an SRV record, you can keep using it provided you are
  2744. able to give Synapse a TLS certificate corresponding to your server name. For
  2745. example, suppose you had the following SRV record, which directs matrix traffic
  2746. for example.com to matrix.example.com:443:</p>
  2747. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 443 matrix.example.com
  2748. </code></pre>
  2749. <p>In this case, Synapse must be given a certificate for example.com - or be
  2750. configured to acquire one from Let's Encrypt.</p>
  2751. <p>If you are unable to give Synapse a certificate for your server_name, you will
  2752. also need to use a .well-known URI instead. However, see also &quot;I have created a
  2753. .well-known URI. Do I still need an SRV record?&quot;.</p>
  2754. <h3 id="i-have-created-a-well-known-uri-do-i-still-need-an-srv-record"><a class="header" href="#i-have-created-a-well-known-uri-do-i-still-need-an-srv-record">I have created a .well-known URI. Do I still need an SRV record?</a></h3>
  2755. <p>As of Synapse 0.99, Synapse will first check for the existence of a <code>.well-known</code>
  2756. URI and follow any delegation it suggests. It will only then check for the
  2757. existence of an SRV record.</p>
  2758. <p>That means that the SRV record will often be redundant. However, you should
  2759. remember that there may still be older versions of Synapse in the federation
  2760. which do not understand <code>.well-known</code> URIs, so if you removed your SRV record you
  2761. would no longer be able to federate with them.</p>
  2762. <p>It is therefore best to leave the SRV record in place for now. Synapse 0.34 and
  2763. earlier will follow the SRV record (and not care about the invalid
  2764. certificate). Synapse 0.99 and later will follow the .well-known URI, with the
  2765. correct certificate chain.</p>
  2766. <h3 id="it-used-to-work-just-fine-why-are-you-breaking-everything"><a class="header" href="#it-used-to-work-just-fine-why-are-you-breaking-everything">It used to work just fine, why are you breaking everything?</a></h3>
  2767. <p>We have always wanted Matrix servers to be as easy to set up as possible, and
  2768. so back when we started federation in 2014 we didn't want admins to have to go
  2769. through the cumbersome process of buying a valid TLS certificate to run a
  2770. server. This was before Let's Encrypt came along and made getting a free and
  2771. valid TLS certificate straightforward. So instead, we adopted a system based on
  2772. <a href="https://en.wikipedia.org/wiki/Convergence_(SSL)">Perspectives</a>: an approach
  2773. where you check a set of &quot;notary servers&quot; (in practice, homeservers) to vouch
  2774. for the validity of a certificate rather than having it signed by a CA. As long
  2775. as enough different notaries agree on the certificate's validity, then it is
  2776. trusted.</p>
  2777. <p>However, in practice this has never worked properly. Most people only use the
  2778. default notary server (matrix.org), leading to inadvertent centralisation which
  2779. we want to eliminate. Meanwhile, we never implemented the full consensus
  2780. algorithm to query the servers participating in a room to determine consensus
  2781. on whether a given certificate is valid. This is fiddly to get right
  2782. (especially in face of sybil attacks), and we found ourselves questioning
  2783. whether it was worth the effort to finish the work and commit to maintaining a
  2784. secure certificate validation system as opposed to focusing on core Matrix
  2785. development.</p>
  2786. <p>Meanwhile, Let's Encrypt came along in 2016, and put the final nail in the
  2787. coffin of the Perspectives project (which was already pretty dead). So, the
  2788. Spec Core Team decided that a better approach would be to mandate valid TLS
  2789. certificates for federation alongside the rest of the Web. More details can be
  2790. found in
  2791. <a href="https://github.com/matrix-org/matrix-doc/blob/master/proposals/1711-x509-for-federation.md#background-the-failure-of-the-perspectives-approach">MSC1711</a>.</p>
  2792. <p>This results in a breaking change, which is disruptive, but absolutely critical
  2793. for the security model. However, the existence of Let's Encrypt as a trivial
  2794. way to replace the old self-signed certificates with valid CA-signed ones helps
  2795. smooth things over massively, especially as Synapse can now automate Let's
  2796. Encrypt certificate generation if needed.</p>
  2797. <h3 id="can-i-manage-my-own-certificates-rather-than-having-synapse-renew-certificates-itself"><a class="header" href="#can-i-manage-my-own-certificates-rather-than-having-synapse-renew-certificates-itself">Can I manage my own certificates rather than having Synapse renew certificates itself?</a></h3>
  2798. <p>Yes, you are welcome to manage your certificates yourself. Synapse will only
  2799. attempt to obtain certificates from Let's Encrypt if you configure it to do
  2800. so.The only requirement is that there is a valid TLS cert present for
  2801. federation end points.</p>
  2802. <h3 id="do-you-still-recommend-against-using-a-reverse-proxy-on-the-federation-port-1"><a class="header" href="#do-you-still-recommend-against-using-a-reverse-proxy-on-the-federation-port-1">Do you still recommend against using a reverse proxy on the federation port?</a></h3>
  2803. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  2804. find it easier to direct federation traffic to a reverse proxy and manage their
  2805. own TLS certificates, and this is a supported configuration.</p>
  2806. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2807. reverse proxy.</p>
  2808. <h3 id="do-i-still-need-to-give-my-tls-certificates-to-synapse-if-i-am-using-a-reverse-proxy-1"><a class="header" href="#do-i-still-need-to-give-my-tls-certificates-to-synapse-if-i-am-using-a-reverse-proxy-1">Do I still need to give my TLS certificates to Synapse if I am using a reverse proxy?</a></h3>
  2809. <p>Practically speaking, this is no longer necessary.</p>
  2810. <p>If you are using a reverse proxy for all of your TLS traffic, then you can set
  2811. <code>no_tls: True</code>. In that case, the only reason Synapse needs the certificate is
  2812. to populate a legacy 'tls_fingerprints' field in the federation API. This is
  2813. ignored by Synapse 0.99.0 and later, and the only time pre-0.99 Synapses will
  2814. check it is when attempting to fetch the server keys - and generally this is
  2815. delegated via <code>matrix.org</code>, which is on 0.99.0.</p>
  2816. <p>However, there is a bug in Synapse 0.99.0
  2817. <a href="https://github.com/matrix-org/synapse/issues/4554">4554</a> which prevents
  2818. Synapse from starting if you do not give it a TLS certificate. To work around
  2819. this, you can give it any TLS certificate at all. This will be fixed soon.</p>
  2820. <h3 id="do-i-need-the-same-certificate-for-the-client-and-federation-port-1"><a class="header" href="#do-i-need-the-same-certificate-for-the-client-and-federation-port-1">Do I need the same certificate for the client and federation port?</a></h3>
  2821. <p>No. There is nothing stopping you from using different certificates,
  2822. particularly if you are using a reverse proxy. However, Synapse will use the
  2823. same certificate on any ports where TLS is configured.</p>
  2824. <h3 id="how-do-i-tell-synapse-to-reload-my-keyscertificates-after-i-replace-them"><a class="header" href="#how-do-i-tell-synapse-to-reload-my-keyscertificates-after-i-replace-them">How do I tell Synapse to reload my keys/certificates after I replace them?</a></h3>
  2825. <p>Synapse will reload the keys and certificates when it receives a SIGHUP - for
  2826. example <code>kill -HUP $(cat homeserver.pid)</code>. Alternatively, simply restart
  2827. Synapse, though this will result in downtime while it restarts.</p>
  2828. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="setting-up-federation"><a class="header" href="#setting-up-federation">Setting up federation</a></h1>
  2829. <p>Federation is the process by which users on different servers can participate
  2830. in the same room. For this to work, those other servers must be able to contact
  2831. yours to send messages.</p>
  2832. <p>The <code>server_name</code> configured in the Synapse configuration file (often
  2833. <code>homeserver.yaml</code>) defines how resources (users, rooms, etc.) will be
  2834. identified (eg: <code>@user:example.com</code>, <code>#room:example.com</code>). By default,
  2835. it is also the domain that other servers will use to try to reach your
  2836. server (via port 8448). This is easy to set up and will work provided
  2837. you set the <code>server_name</code> to match your machine's public DNS hostname.</p>
  2838. <p>For this default configuration to work, you will need to listen for TLS
  2839. connections on port 8448. The preferred way to do that is by using a
  2840. reverse proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions
  2841. on how to correctly set one up.</p>
  2842. <p>In some cases you might not want to run Synapse on the machine that has
  2843. the <code>server_name</code> as its public DNS hostname, or you might want federation
  2844. traffic to use a different port than 8448. For example, you might want to
  2845. have your user names look like <code>@user:example.com</code>, but you want to run
  2846. Synapse on <code>synapse.example.com</code> on port 443. This can be done using
  2847. delegation, which allows an admin to control where federation traffic should
  2848. be sent. See <a href="delegate.html">the delegation documentation</a> for instructions on how to set this up.</p>
  2849. <p>Once federation has been configured, you should be able to join a room over
  2850. federation. A good place to start is <code>#synapse:matrix.org</code> - a room for
  2851. Synapse admins.</p>
  2852. <h2 id="troubleshooting-3"><a class="header" href="#troubleshooting-3">Troubleshooting</a></h2>
  2853. <p>You can use the <a href="https://matrix.org/federationtester">federation tester</a>
  2854. to check if your homeserver is configured correctly. Alternatively try the
  2855. <a href="https://matrix.org/federationtester/api/report?server_name=DOMAIN">JSON API used by the federation tester</a>.
  2856. Note that you'll have to modify this URL to replace <code>DOMAIN</code> with your
  2857. <code>server_name</code>. Hitting the API directly provides extra detail.</p>
  2858. <p>The typical failure mode for federation is that when the server tries to join
  2859. a room, it is rejected with &quot;401: Unauthorized&quot;. Generally this means that other
  2860. servers in the room could not access yours. (Joining a room over federation is
  2861. a complicated dance which requires connections in both directions).</p>
  2862. <p>Another common problem is that people on other servers can't join rooms that
  2863. you invite them to. This can be caused by an incorrectly-configured reverse
  2864. proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions on how
  2865. to correctly configure a reverse proxy.</p>
  2866. <h3 id="known-issues"><a class="header" href="#known-issues">Known issues</a></h3>
  2867. <p><strong>HTTP <code>308 Permanent Redirect</code> redirects are not followed</strong>: Due to missing features
  2868. in the HTTP library used by Synapse, 308 redirects are currently not followed by
  2869. federating servers, which can cause <code>M_UNKNOWN</code> or <code>401 Unauthorized</code> errors. This
  2870. may affect users who are redirecting apex-to-www (e.g. <code>example.com</code> -&gt; <code>www.example.com</code>),
  2871. and especially users of the Kubernetes <em>Nginx Ingress</em> module, which uses 308 redirect
  2872. codes by default. For those Kubernetes users, <a href="https://stackoverflow.com/a/52617528/5096871">this Stackoverflow post</a>
  2873. might be helpful. For other users, switching to a <code>301 Moved Permanently</code> code may be
  2874. an option. 308 redirect codes will be supported properly in a future
  2875. release of Synapse.</p>
  2876. <h2 id="running-a-demo-federation-of-synapses"><a class="header" href="#running-a-demo-federation-of-synapses">Running a demo federation of Synapses</a></h2>
  2877. <p>If you want to get up and running quickly with a trio of homeservers in a
  2878. private federation, there is a script in the <code>demo</code> directory. This is mainly
  2879. useful just for development purposes. See <a href="https://github.com/matrix-org/synapse/tree/develop/demo/">demo/README</a>.</p>
  2880. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="configuration-1"><a class="header" href="#configuration-1">Configuration</a></h1>
  2881. <p>This section contains information on tweaking Synapse via the various options in the configuration file. A configuration
  2882. file should have been generated when you <a href="usage/configuration/../../setup/installation.html">installed Synapse</a>.</p>
  2883. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="homeserver-sample-configuration-file"><a class="header" href="#homeserver-sample-configuration-file">Homeserver Sample Configuration File</a></h1>
  2884. <p>Below is a sample homeserver configuration file. The homeserver configuration file
  2885. can be tweaked to change the behaviour of your homeserver. A restart of the server is
  2886. generally required to apply any changes made to this file.</p>
  2887. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  2888. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  2889. a fresh config using Synapse by following the instructions in
  2890. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  2891. <pre><code class="language-yaml"># This file is maintained as an up-to-date snapshot of the default
  2892. # homeserver.yaml configuration generated by Synapse.
  2893. #
  2894. # It is intended to act as a reference for the default configuration,
  2895. # helping admins keep track of new options and other changes, and compare
  2896. # their configs with the current default. As such, many of the actual
  2897. # config values shown are placeholders.
  2898. #
  2899. # It is *not* intended to be copied and used as the basis for a real
  2900. # homeserver.yaml. Instead, if you are starting from scratch, please generate
  2901. # a fresh config using Synapse by following the instructions in
  2902. # https://matrix-org.github.io/synapse/latest/setup/installation.html.
  2903. # Configuration options that take a time period can be set using a number
  2904. # followed by a letter. Letters have the following meanings:
  2905. # s = second
  2906. # m = minute
  2907. # h = hour
  2908. # d = day
  2909. # w = week
  2910. # y = year
  2911. # For example, setting redaction_retention_period: 5m would remove redacted
  2912. # messages from the database after 5 minutes, rather than 5 months.
  2913. ################################################################################
  2914. # Configuration file for Synapse.
  2915. #
  2916. # This is a YAML file: see [1] for a quick introduction. Note in particular
  2917. # that *indentation is important*: all the elements of a list or dictionary
  2918. # should have the same indentation.
  2919. #
  2920. # [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  2921. ## Modules ##
  2922. # Server admins can expand Synapse's functionality with external modules.
  2923. #
  2924. # See https://matrix-org.github.io/synapse/latest/modules.html for more
  2925. # documentation on how to configure or create custom modules for Synapse.
  2926. #
  2927. modules:
  2928. # - module: my_super_module.MySuperClass
  2929. # config:
  2930. # do_thing: true
  2931. # - module: my_other_super_module.SomeClass
  2932. # config: {}
  2933. ## Server ##
  2934. # The public-facing domain of the server
  2935. #
  2936. # The server_name name will appear at the end of usernames and room addresses
  2937. # created on this server. For example if the server_name was example.com,
  2938. # usernames on this server would be in the format @user:example.com
  2939. #
  2940. # In most cases you should avoid using a matrix specific subdomain such as
  2941. # matrix.example.com or synapse.example.com as the server_name for the same
  2942. # reasons you wouldn't use user@email.example.com as your email address.
  2943. # See https://matrix-org.github.io/synapse/latest/delegate.html
  2944. # for information on how to host Synapse on a subdomain while preserving
  2945. # a clean server_name.
  2946. #
  2947. # The server_name cannot be changed later so it is important to
  2948. # configure this correctly before you start Synapse. It should be all
  2949. # lowercase and may contain an explicit port.
  2950. # Examples: matrix.org, localhost:8080
  2951. #
  2952. server_name: &quot;SERVERNAME&quot;
  2953. # When running as a daemon, the file to store the pid in
  2954. #
  2955. pid_file: DATADIR/homeserver.pid
  2956. # The absolute URL to the web client which /_matrix/client will redirect
  2957. # to if 'webclient' is configured under the 'listeners' configuration.
  2958. #
  2959. # This option can be also set to the filesystem path to the web client
  2960. # which will be served at /_matrix/client/ if 'webclient' is configured
  2961. # under the 'listeners' configuration, however this is a security risk:
  2962. # https://github.com/matrix-org/synapse#security-note
  2963. #
  2964. #web_client_location: https://riot.example.com/
  2965. # The public-facing base URL that clients use to access this Homeserver (not
  2966. # including _matrix/...). This is the same URL a user might enter into the
  2967. # 'Custom Homeserver URL' field on their client. If you use Synapse with a
  2968. # reverse proxy, this should be the URL to reach Synapse via the proxy.
  2969. # Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
  2970. # 'listeners' below).
  2971. #
  2972. #public_baseurl: https://example.com/
  2973. # Set the soft limit on the number of file descriptors synapse can use
  2974. # Zero is used to indicate synapse should set the soft limit to the
  2975. # hard limit.
  2976. #
  2977. #soft_file_limit: 0
  2978. # Presence tracking allows users to see the state (e.g online/offline)
  2979. # of other local and remote users.
  2980. #
  2981. presence:
  2982. # Uncomment to disable presence tracking on this homeserver. This option
  2983. # replaces the previous top-level 'use_presence' option.
  2984. #
  2985. #enabled: false
  2986. # Presence routers are third-party modules that can specify additional logic
  2987. # to where presence updates from users are routed.
  2988. #
  2989. presence_router:
  2990. # The custom module's class. Uncomment to use a custom presence router module.
  2991. #
  2992. #module: &quot;my_custom_router.PresenceRouter&quot;
  2993. # Configuration options of the custom module. Refer to your module's
  2994. # documentation for available options.
  2995. #
  2996. #config:
  2997. # example_option: 'something'
  2998. # Whether to require authentication to retrieve profile data (avatars,
  2999. # display names) of other users through the client API. Defaults to
  3000. # 'false'. Note that profile data is also available via the federation
  3001. # API, unless allow_profile_lookup_over_federation is set to false.
  3002. #
  3003. #require_auth_for_profile_requests: true
  3004. # Uncomment to require a user to share a room with another user in order
  3005. # to retrieve their profile information. Only checked on Client-Server
  3006. # requests. Profile requests from other servers should be checked by the
  3007. # requesting server. Defaults to 'false'.
  3008. #
  3009. #limit_profile_requests_to_users_who_share_rooms: true
  3010. # Uncomment to prevent a user's profile data from being retrieved and
  3011. # displayed in a room until they have joined it. By default, a user's
  3012. # profile data is included in an invite event, regardless of the values
  3013. # of the above two settings, and whether or not the users share a server.
  3014. # Defaults to 'true'.
  3015. #
  3016. #include_profile_data_on_invite: false
  3017. # If set to 'true', removes the need for authentication to access the server's
  3018. # public rooms directory through the client API, meaning that anyone can
  3019. # query the room directory. Defaults to 'false'.
  3020. #
  3021. #allow_public_rooms_without_auth: true
  3022. # If set to 'true', allows any other homeserver to fetch the server's public
  3023. # rooms directory via federation. Defaults to 'false'.
  3024. #
  3025. #allow_public_rooms_over_federation: true
  3026. # The default room version for newly created rooms.
  3027. #
  3028. # Known room versions are listed here:
  3029. # https://matrix.org/docs/spec/#complete-list-of-room-versions
  3030. #
  3031. # For example, for room version 1, default_room_version should be set
  3032. # to &quot;1&quot;.
  3033. #
  3034. #default_room_version: &quot;6&quot;
  3035. # The GC threshold parameters to pass to `gc.set_threshold`, if defined
  3036. #
  3037. #gc_thresholds: [700, 10, 10]
  3038. # The minimum time in seconds between each GC for a generation, regardless of
  3039. # the GC thresholds. This ensures that we don't do GC too frequently.
  3040. #
  3041. # A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
  3042. # generation 0 GCs, etc.
  3043. #
  3044. # Defaults to `[1s, 10s, 30s]`.
  3045. #
  3046. #gc_min_interval: [0.5s, 30s, 1m]
  3047. # Set the limit on the returned events in the timeline in the get
  3048. # and sync operations. The default value is 100. -1 means no upper limit.
  3049. #
  3050. # Uncomment the following to increase the limit to 5000.
  3051. #
  3052. #filter_timeline_limit: 5000
  3053. # Whether room invites to users on this server should be blocked
  3054. # (except those sent by local server admins). The default is False.
  3055. #
  3056. #block_non_admin_invites: true
  3057. # Room searching
  3058. #
  3059. # If disabled, new messages will not be indexed for searching and users
  3060. # will receive errors when searching for messages. Defaults to enabled.
  3061. #
  3062. #enable_search: false
  3063. # Prevent outgoing requests from being sent to the following blacklisted IP address
  3064. # CIDR ranges. If this option is not specified then it defaults to private IP
  3065. # address ranges (see the example below).
  3066. #
  3067. # The blacklist applies to the outbound requests for federation, identity servers,
  3068. # push servers, and for checking key validity for third-party invite events.
  3069. #
  3070. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3071. # listed here, since they correspond to unroutable addresses.)
  3072. #
  3073. # This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
  3074. #
  3075. # Note: The value is ignored when an HTTP proxy is in use
  3076. #
  3077. #ip_range_blacklist:
  3078. # - '127.0.0.0/8'
  3079. # - '10.0.0.0/8'
  3080. # - '172.16.0.0/12'
  3081. # - '192.168.0.0/16'
  3082. # - '100.64.0.0/10'
  3083. # - '192.0.0.0/24'
  3084. # - '169.254.0.0/16'
  3085. # - '192.88.99.0/24'
  3086. # - '198.18.0.0/15'
  3087. # - '192.0.2.0/24'
  3088. # - '198.51.100.0/24'
  3089. # - '203.0.113.0/24'
  3090. # - '224.0.0.0/4'
  3091. # - '::1/128'
  3092. # - 'fe80::/10'
  3093. # - 'fc00::/7'
  3094. # - '2001:db8::/32'
  3095. # - 'ff00::/8'
  3096. # - 'fec0::/10'
  3097. # List of IP address CIDR ranges that should be allowed for federation,
  3098. # identity servers, push servers, and for checking key validity for
  3099. # third-party invite events. This is useful for specifying exceptions to
  3100. # wide-ranging blacklisted target IP ranges - e.g. for communication with
  3101. # a push server only visible in your network.
  3102. #
  3103. # This whitelist overrides ip_range_blacklist and defaults to an empty
  3104. # list.
  3105. #
  3106. #ip_range_whitelist:
  3107. # - '192.168.1.1'
  3108. # List of ports that Synapse should listen on, their purpose and their
  3109. # configuration.
  3110. #
  3111. # Options for each listener include:
  3112. #
  3113. # port: the TCP port to bind to
  3114. #
  3115. # bind_addresses: a list of local addresses to listen on. The default is
  3116. # 'all local interfaces'.
  3117. #
  3118. # type: the type of listener. Normally 'http', but other valid options are:
  3119. # 'manhole' (see https://matrix-org.github.io/synapse/latest/manhole.html),
  3120. # 'metrics' (see https://matrix-org.github.io/synapse/latest/metrics-howto.html),
  3121. # 'replication' (see https://matrix-org.github.io/synapse/latest/workers.html).
  3122. #
  3123. # tls: set to true to enable TLS for this listener. Will use the TLS
  3124. # key/cert specified in tls_private_key_path / tls_certificate_path.
  3125. #
  3126. # x_forwarded: Only valid for an 'http' listener. Set to true to use the
  3127. # X-Forwarded-For header as the client IP. Useful when Synapse is
  3128. # behind a reverse-proxy.
  3129. #
  3130. # resources: Only valid for an 'http' listener. A list of resources to host
  3131. # on this port. Options for each resource are:
  3132. #
  3133. # names: a list of names of HTTP resources. See below for a list of
  3134. # valid resource names.
  3135. #
  3136. # compress: set to true to enable HTTP compression for this resource.
  3137. #
  3138. # additional_resources: Only valid for an 'http' listener. A map of
  3139. # additional endpoints which should be loaded via dynamic modules.
  3140. #
  3141. # Valid resource names are:
  3142. #
  3143. # client: the client-server API (/_matrix/client), and the synapse admin
  3144. # API (/_synapse/admin). Also implies 'media' and 'static'.
  3145. #
  3146. # consent: user consent forms (/_matrix/consent).
  3147. # See https://matrix-org.github.io/synapse/latest/consent_tracking.html.
  3148. #
  3149. # federation: the server-server API (/_matrix/federation). Also implies
  3150. # 'media', 'keys', 'openid'
  3151. #
  3152. # keys: the key discovery API (/_matrix/keys).
  3153. #
  3154. # media: the media API (/_matrix/media).
  3155. #
  3156. # metrics: the metrics interface.
  3157. # See https://matrix-org.github.io/synapse/latest/metrics-howto.html.
  3158. #
  3159. # openid: OpenID authentication.
  3160. #
  3161. # replication: the HTTP replication API (/_synapse/replication).
  3162. # See https://matrix-org.github.io/synapse/latest/workers.html.
  3163. #
  3164. # static: static resources under synapse/static (/_matrix/static). (Mostly
  3165. # useful for 'fallback authentication'.)
  3166. #
  3167. # webclient: A web client. Requires web_client_location to be set.
  3168. #
  3169. listeners:
  3170. # TLS-enabled listener: for when matrix traffic is sent directly to synapse.
  3171. #
  3172. # Disabled by default. To enable it, uncomment the following. (Note that you
  3173. # will also need to give Synapse a TLS key and certificate: see the TLS section
  3174. # below.)
  3175. #
  3176. #- port: 8448
  3177. # type: http
  3178. # tls: true
  3179. # resources:
  3180. # - names: [client, federation]
  3181. # Unsecure HTTP listener: for when matrix traffic passes through a reverse proxy
  3182. # that unwraps TLS.
  3183. #
  3184. # If you plan to use a reverse proxy, please see
  3185. # https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3186. #
  3187. - port: 8008
  3188. tls: false
  3189. type: http
  3190. x_forwarded: true
  3191. bind_addresses: ['::1', '127.0.0.1']
  3192. resources:
  3193. - names: [client, federation]
  3194. compress: false
  3195. # example additional_resources:
  3196. #
  3197. #additional_resources:
  3198. # &quot;/_matrix/my/custom/endpoint&quot;:
  3199. # module: my_module.CustomRequestHandler
  3200. # config: {}
  3201. # Turn on the twisted ssh manhole service on localhost on the given
  3202. # port.
  3203. #
  3204. #- port: 9000
  3205. # bind_addresses: ['::1', '127.0.0.1']
  3206. # type: manhole
  3207. # Forward extremities can build up in a room due to networking delays between
  3208. # homeservers. Once this happens in a large room, calculation of the state of
  3209. # that room can become quite expensive. To mitigate this, once the number of
  3210. # forward extremities reaches a given threshold, Synapse will send an
  3211. # org.matrix.dummy_event event, which will reduce the forward extremities
  3212. # in the room.
  3213. #
  3214. # This setting defines the threshold (i.e. number of forward extremities in the
  3215. # room) at which dummy events are sent. The default value is 10.
  3216. #
  3217. #dummy_events_threshold: 5
  3218. ## Homeserver blocking ##
  3219. # How to reach the server admin, used in ResourceLimitError
  3220. #
  3221. #admin_contact: 'mailto:admin@server.com'
  3222. # Global blocking
  3223. #
  3224. #hs_disabled: false
  3225. #hs_disabled_message: 'Human readable reason for why the HS is blocked'
  3226. # Monthly Active User Blocking
  3227. #
  3228. # Used in cases where the admin or server owner wants to limit to the
  3229. # number of monthly active users.
  3230. #
  3231. # 'limit_usage_by_mau' disables/enables monthly active user blocking. When
  3232. # enabled and a limit is reached the server returns a 'ResourceLimitError'
  3233. # with error type Codes.RESOURCE_LIMIT_EXCEEDED
  3234. #
  3235. # 'max_mau_value' is the hard limit of monthly active users above which
  3236. # the server will start blocking user actions.
  3237. #
  3238. # 'mau_trial_days' is a means to add a grace period for active users. It
  3239. # means that users must be active for this number of days before they
  3240. # can be considered active and guards against the case where lots of users
  3241. # sign up in a short space of time never to return after their initial
  3242. # session.
  3243. #
  3244. # 'mau_limit_alerting' is a means of limiting client side alerting
  3245. # should the mau limit be reached. This is useful for small instances
  3246. # where the admin has 5 mau seats (say) for 5 specific people and no
  3247. # interest increasing the mau limit further. Defaults to True, which
  3248. # means that alerting is enabled
  3249. #
  3250. #limit_usage_by_mau: false
  3251. #max_mau_value: 50
  3252. #mau_trial_days: 2
  3253. #mau_limit_alerting: false
  3254. # If enabled, the metrics for the number of monthly active users will
  3255. # be populated, however no one will be limited. If limit_usage_by_mau
  3256. # is true, this is implied to be true.
  3257. #
  3258. #mau_stats_only: false
  3259. # Sometimes the server admin will want to ensure certain accounts are
  3260. # never blocked by mau checking. These accounts are specified here.
  3261. #
  3262. #mau_limit_reserved_threepids:
  3263. # - medium: 'email'
  3264. # address: 'reserved_user@example.com'
  3265. # Used by phonehome stats to group together related servers.
  3266. #server_context: context
  3267. # Resource-constrained homeserver settings
  3268. #
  3269. # When this is enabled, the room &quot;complexity&quot; will be checked before a user
  3270. # joins a new remote room. If it is above the complexity limit, the server will
  3271. # disallow joining, or will instantly leave.
  3272. #
  3273. # Room complexity is an arbitrary measure based on factors such as the number of
  3274. # users in the room.
  3275. #
  3276. limit_remote_rooms:
  3277. # Uncomment to enable room complexity checking.
  3278. #
  3279. #enabled: true
  3280. # the limit above which rooms cannot be joined. The default is 1.0.
  3281. #
  3282. #complexity: 0.5
  3283. # override the error which is returned when the room is too complex.
  3284. #
  3285. #complexity_error: &quot;This room is too complex.&quot;
  3286. # allow server admins to join complex rooms. Default is false.
  3287. #
  3288. #admins_can_join: true
  3289. # Whether to require a user to be in the room to add an alias to it.
  3290. # Defaults to 'true'.
  3291. #
  3292. #require_membership_for_aliases: false
  3293. # Whether to allow per-room membership profiles through the send of membership
  3294. # events with profile information that differ from the target's global profile.
  3295. # Defaults to 'true'.
  3296. #
  3297. #allow_per_room_profiles: false
  3298. # How long to keep redacted events in unredacted form in the database. After
  3299. # this period redacted events get replaced with their redacted form in the DB.
  3300. #
  3301. # Defaults to `7d`. Set to `null` to disable.
  3302. #
  3303. #redaction_retention_period: 28d
  3304. # How long to track users' last seen time and IPs in the database.
  3305. #
  3306. # Defaults to `28d`. Set to `null` to disable clearing out of old rows.
  3307. #
  3308. #user_ips_max_age: 14d
  3309. # Message retention policy at the server level.
  3310. #
  3311. # Room admins and mods can define a retention period for their rooms using the
  3312. # 'm.room.retention' state event, and server admins can cap this period by setting
  3313. # the 'allowed_lifetime_min' and 'allowed_lifetime_max' config options.
  3314. #
  3315. # If this feature is enabled, Synapse will regularly look for and purge events
  3316. # which are older than the room's maximum retention period. Synapse will also
  3317. # filter events received over federation so that events that should have been
  3318. # purged are ignored and not stored again.
  3319. #
  3320. retention:
  3321. # The message retention policies feature is disabled by default. Uncomment the
  3322. # following line to enable it.
  3323. #
  3324. #enabled: true
  3325. # Default retention policy. If set, Synapse will apply it to rooms that lack the
  3326. # 'm.room.retention' state event. Currently, the value of 'min_lifetime' doesn't
  3327. # matter much because Synapse doesn't take it into account yet.
  3328. #
  3329. #default_policy:
  3330. # min_lifetime: 1d
  3331. # max_lifetime: 1y
  3332. # Retention policy limits. If set, and the state of a room contains a
  3333. # 'm.room.retention' event in its state which contains a 'min_lifetime' or a
  3334. # 'max_lifetime' that's out of these bounds, Synapse will cap the room's policy
  3335. # to these limits when running purge jobs.
  3336. #
  3337. #allowed_lifetime_min: 1d
  3338. #allowed_lifetime_max: 1y
  3339. # Server admins can define the settings of the background jobs purging the
  3340. # events which lifetime has expired under the 'purge_jobs' section.
  3341. #
  3342. # If no configuration is provided, a single job will be set up to delete expired
  3343. # events in every room daily.
  3344. #
  3345. # Each job's configuration defines which range of message lifetimes the job
  3346. # takes care of. For example, if 'shortest_max_lifetime' is '2d' and
  3347. # 'longest_max_lifetime' is '3d', the job will handle purging expired events in
  3348. # rooms whose state defines a 'max_lifetime' that's both higher than 2 days, and
  3349. # lower than or equal to 3 days. Both the minimum and the maximum value of a
  3350. # range are optional, e.g. a job with no 'shortest_max_lifetime' and a
  3351. # 'longest_max_lifetime' of '3d' will handle every room with a retention policy
  3352. # which 'max_lifetime' is lower than or equal to three days.
  3353. #
  3354. # The rationale for this per-job configuration is that some rooms might have a
  3355. # retention policy with a low 'max_lifetime', where history needs to be purged
  3356. # of outdated messages on a more frequent basis than for the rest of the rooms
  3357. # (e.g. every 12h), but not want that purge to be performed by a job that's
  3358. # iterating over every room it knows, which could be heavy on the server.
  3359. #
  3360. # If any purge job is configured, it is strongly recommended to have at least
  3361. # a single job with neither 'shortest_max_lifetime' nor 'longest_max_lifetime'
  3362. # set, or one job without 'shortest_max_lifetime' and one job without
  3363. # 'longest_max_lifetime' set. Otherwise some rooms might be ignored, even if
  3364. # 'allowed_lifetime_min' and 'allowed_lifetime_max' are set, because capping a
  3365. # room's policy to these values is done after the policies are retrieved from
  3366. # Synapse's database (which is done using the range specified in a purge job's
  3367. # configuration).
  3368. #
  3369. #purge_jobs:
  3370. # - longest_max_lifetime: 3d
  3371. # interval: 12h
  3372. # - shortest_max_lifetime: 3d
  3373. # interval: 1d
  3374. # Inhibits the /requestToken endpoints from returning an error that might leak
  3375. # information about whether an e-mail address is in use or not on this
  3376. # homeserver.
  3377. # Note that for some endpoints the error situation is the e-mail already being
  3378. # used, and for others the error is entering the e-mail being unused.
  3379. # If this option is enabled, instead of returning an error, these endpoints will
  3380. # act as if no error happened and return a fake session ID ('sid') to clients.
  3381. #
  3382. #request_token_inhibit_3pid_errors: true
  3383. # A list of domains that the domain portion of 'next_link' parameters
  3384. # must match.
  3385. #
  3386. # This parameter is optionally provided by clients while requesting
  3387. # validation of an email or phone number, and maps to a link that
  3388. # users will be automatically redirected to after validation
  3389. # succeeds. Clients can make use this parameter to aid the validation
  3390. # process.
  3391. #
  3392. # The whitelist is applied whether the homeserver or an
  3393. # identity server is handling validation.
  3394. #
  3395. # The default value is no whitelist functionality; all domains are
  3396. # allowed. Setting this value to an empty list will instead disallow
  3397. # all domains.
  3398. #
  3399. #next_link_domain_whitelist: [&quot;matrix.org&quot;]
  3400. # Templates to use when generating email or HTML page contents.
  3401. #
  3402. templates:
  3403. # Directory in which Synapse will try to find template files to use to generate
  3404. # email or HTML page contents.
  3405. # If not set, or a file is not found within the template directory, a default
  3406. # template from within the Synapse package will be used.
  3407. #
  3408. # See https://matrix-org.github.io/synapse/latest/templates.html for more
  3409. # information about using custom templates.
  3410. #
  3411. #custom_template_directory: /path/to/custom/templates/
  3412. ## TLS ##
  3413. # PEM-encoded X509 certificate for TLS.
  3414. # This certificate, as of Synapse 1.0, will need to be a valid and verifiable
  3415. # certificate, signed by a recognised Certificate Authority.
  3416. #
  3417. # Be sure to use a `.pem` file that includes the full certificate chain including
  3418. # any intermediate certificates (for instance, if using certbot, use
  3419. # `fullchain.pem` as your certificate, not `cert.pem`).
  3420. #
  3421. #tls_certificate_path: &quot;CONFDIR/SERVERNAME.tls.crt&quot;
  3422. # PEM-encoded private key for TLS
  3423. #
  3424. #tls_private_key_path: &quot;CONFDIR/SERVERNAME.tls.key&quot;
  3425. # Whether to verify TLS server certificates for outbound federation requests.
  3426. #
  3427. # Defaults to `true`. To disable certificate verification, uncomment the
  3428. # following line.
  3429. #
  3430. #federation_verify_certificates: false
  3431. # The minimum TLS version that will be used for outbound federation requests.
  3432. #
  3433. # Defaults to `1`. Configurable to `1`, `1.1`, `1.2`, or `1.3`. Note
  3434. # that setting this value higher than `1.2` will prevent federation to most
  3435. # of the public Matrix network: only configure it to `1.3` if you have an
  3436. # entirely private federation setup and you can ensure TLS 1.3 support.
  3437. #
  3438. #federation_client_minimum_tls_version: 1.2
  3439. # Skip federation certificate verification on the following whitelist
  3440. # of domains.
  3441. #
  3442. # This setting should only be used in very specific cases, such as
  3443. # federation over Tor hidden services and similar. For private networks
  3444. # of homeservers, you likely want to use a private CA instead.
  3445. #
  3446. # Only effective if federation_verify_certicates is `true`.
  3447. #
  3448. #federation_certificate_verification_whitelist:
  3449. # - lon.example.com
  3450. # - *.domain.com
  3451. # - *.onion
  3452. # List of custom certificate authorities for federation traffic.
  3453. #
  3454. # This setting should only normally be used within a private network of
  3455. # homeservers.
  3456. #
  3457. # Note that this list will replace those that are provided by your
  3458. # operating environment. Certificates must be in PEM format.
  3459. #
  3460. #federation_custom_ca_list:
  3461. # - myCA1.pem
  3462. # - myCA2.pem
  3463. # - myCA3.pem
  3464. ## Federation ##
  3465. # Restrict federation to the following whitelist of domains.
  3466. # N.B. we recommend also firewalling your federation listener to limit
  3467. # inbound federation traffic as early as possible, rather than relying
  3468. # purely on this application-layer restriction. If not specified, the
  3469. # default is to whitelist everything.
  3470. #
  3471. #federation_domain_whitelist:
  3472. # - lon.example.com
  3473. # - nyc.example.com
  3474. # - syd.example.com
  3475. # Report prometheus metrics on the age of PDUs being sent to and received from
  3476. # the following domains. This can be used to give an idea of &quot;delay&quot; on inbound
  3477. # and outbound federation, though be aware that any delay can be due to problems
  3478. # at either end or with the intermediate network.
  3479. #
  3480. # By default, no domains are monitored in this way.
  3481. #
  3482. #federation_metrics_domains:
  3483. # - matrix.org
  3484. # - example.com
  3485. # Uncomment to disable profile lookup over federation. By default, the
  3486. # Federation API allows other homeservers to obtain profile data of any user
  3487. # on this homeserver. Defaults to 'true'.
  3488. #
  3489. #allow_profile_lookup_over_federation: false
  3490. # Uncomment to disable device display name lookup over federation. By default, the
  3491. # Federation API allows other homeservers to obtain device display names of any user
  3492. # on this homeserver. Defaults to 'true'.
  3493. #
  3494. #allow_device_name_lookup_over_federation: false
  3495. ## Caching ##
  3496. # Caching can be configured through the following options.
  3497. #
  3498. # A cache 'factor' is a multiplier that can be applied to each of
  3499. # Synapse's caches in order to increase or decrease the maximum
  3500. # number of entries that can be stored.
  3501. # The number of events to cache in memory. Not affected by
  3502. # caches.global_factor.
  3503. #
  3504. #event_cache_size: 10K
  3505. caches:
  3506. # Controls the global cache factor, which is the default cache factor
  3507. # for all caches if a specific factor for that cache is not otherwise
  3508. # set.
  3509. #
  3510. # This can also be set by the &quot;SYNAPSE_CACHE_FACTOR&quot; environment
  3511. # variable. Setting by environment variable takes priority over
  3512. # setting through the config file.
  3513. #
  3514. # Defaults to 0.5, which will half the size of all caches.
  3515. #
  3516. #global_factor: 1.0
  3517. # A dictionary of cache name to cache factor for that individual
  3518. # cache. Overrides the global cache factor for a given cache.
  3519. #
  3520. # These can also be set through environment variables comprised
  3521. # of &quot;SYNAPSE_CACHE_FACTOR_&quot; + the name of the cache in capital
  3522. # letters and underscores. Setting by environment variable
  3523. # takes priority over setting through the config file.
  3524. # Ex. SYNAPSE_CACHE_FACTOR_GET_USERS_WHO_SHARE_ROOM_WITH_USER=2.0
  3525. #
  3526. # Some caches have '*' and other characters that are not
  3527. # alphanumeric or underscores. These caches can be named with or
  3528. # without the special characters stripped. For example, to specify
  3529. # the cache factor for `*stateGroupCache*` via an environment
  3530. # variable would be `SYNAPSE_CACHE_FACTOR_STATEGROUPCACHE=2.0`.
  3531. #
  3532. per_cache_factors:
  3533. #get_users_who_share_room_with_user: 2.0
  3534. # Controls how long an entry can be in a cache without having been
  3535. # accessed before being evicted. Defaults to None, which means
  3536. # entries are never evicted based on time.
  3537. #
  3538. #expiry_time: 30m
  3539. # Controls how long the results of a /sync request are cached for after
  3540. # a successful response is returned. A higher duration can help clients with
  3541. # intermittent connections, at the cost of higher memory usage.
  3542. #
  3543. # By default, this is zero, which means that sync responses are not cached
  3544. # at all.
  3545. #
  3546. #sync_response_cache_duration: 2m
  3547. ## Database ##
  3548. # The 'database' setting defines the database that synapse uses to store all of
  3549. # its data.
  3550. #
  3551. # 'name' gives the database engine to use: either 'sqlite3' (for SQLite) or
  3552. # 'psycopg2' (for PostgreSQL).
  3553. #
  3554. # 'txn_limit' gives the maximum number of transactions to run per connection
  3555. # before reconnecting. Defaults to 0, which means no limit.
  3556. #
  3557. # 'args' gives options which are passed through to the database engine,
  3558. # except for options starting 'cp_', which are used to configure the Twisted
  3559. # connection pool. For a reference to valid arguments, see:
  3560. # * for sqlite: https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
  3561. # * for postgres: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
  3562. # * for the connection pool: https://twistedmatrix.com/documents/current/api/twisted.enterprise.adbapi.ConnectionPool.html#__init__
  3563. #
  3564. #
  3565. # Example SQLite configuration:
  3566. #
  3567. #database:
  3568. # name: sqlite3
  3569. # args:
  3570. # database: /path/to/homeserver.db
  3571. #
  3572. #
  3573. # Example Postgres configuration:
  3574. #
  3575. #database:
  3576. # name: psycopg2
  3577. # txn_limit: 10000
  3578. # args:
  3579. # user: synapse_user
  3580. # password: secretpassword
  3581. # database: synapse
  3582. # host: localhost
  3583. # port: 5432
  3584. # cp_min: 5
  3585. # cp_max: 10
  3586. #
  3587. # For more information on using Synapse with Postgres,
  3588. # see https://matrix-org.github.io/synapse/latest/postgres.html.
  3589. #
  3590. database:
  3591. name: sqlite3
  3592. args:
  3593. database: DATADIR/homeserver.db
  3594. ## Logging ##
  3595. # A yaml python logging config file as described by
  3596. # https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  3597. #
  3598. log_config: &quot;CONFDIR/SERVERNAME.log.config&quot;
  3599. ## Ratelimiting ##
  3600. # Ratelimiting settings for client actions (registration, login, messaging).
  3601. #
  3602. # Each ratelimiting configuration is made of two parameters:
  3603. # - per_second: number of requests a client can send per second.
  3604. # - burst_count: number of requests a client can send before being throttled.
  3605. #
  3606. # Synapse currently uses the following configurations:
  3607. # - one for messages that ratelimits sending based on the account the client
  3608. # is using
  3609. # - one for registration that ratelimits registration requests based on the
  3610. # client's IP address.
  3611. # - one for login that ratelimits login requests based on the client's IP
  3612. # address.
  3613. # - one for login that ratelimits login requests based on the account the
  3614. # client is attempting to log into.
  3615. # - one for login that ratelimits login requests based on the account the
  3616. # client is attempting to log into, based on the amount of failed login
  3617. # attempts for this account.
  3618. # - one for ratelimiting redactions by room admins. If this is not explicitly
  3619. # set then it uses the same ratelimiting as per rc_message. This is useful
  3620. # to allow room admins to deal with abuse quickly.
  3621. # - two for ratelimiting number of rooms a user can join, &quot;local&quot; for when
  3622. # users are joining rooms the server is already in (this is cheap) vs
  3623. # &quot;remote&quot; for when users are trying to join rooms not on the server (which
  3624. # can be more expensive)
  3625. # - one for ratelimiting how often a user or IP can attempt to validate a 3PID.
  3626. # - two for ratelimiting how often invites can be sent in a room or to a
  3627. # specific user.
  3628. #
  3629. # The defaults are as shown below.
  3630. #
  3631. #rc_message:
  3632. # per_second: 0.2
  3633. # burst_count: 10
  3634. #
  3635. #rc_registration:
  3636. # per_second: 0.17
  3637. # burst_count: 3
  3638. #
  3639. #rc_login:
  3640. # address:
  3641. # per_second: 0.17
  3642. # burst_count: 3
  3643. # account:
  3644. # per_second: 0.17
  3645. # burst_count: 3
  3646. # failed_attempts:
  3647. # per_second: 0.17
  3648. # burst_count: 3
  3649. #
  3650. #rc_admin_redaction:
  3651. # per_second: 1
  3652. # burst_count: 50
  3653. #
  3654. #rc_joins:
  3655. # local:
  3656. # per_second: 0.1
  3657. # burst_count: 10
  3658. # remote:
  3659. # per_second: 0.01
  3660. # burst_count: 10
  3661. #
  3662. #rc_3pid_validation:
  3663. # per_second: 0.003
  3664. # burst_count: 5
  3665. #
  3666. #rc_invites:
  3667. # per_room:
  3668. # per_second: 0.3
  3669. # burst_count: 10
  3670. # per_user:
  3671. # per_second: 0.003
  3672. # burst_count: 5
  3673. # Ratelimiting settings for incoming federation
  3674. #
  3675. # The rc_federation configuration is made up of the following settings:
  3676. # - window_size: window size in milliseconds
  3677. # - sleep_limit: number of federation requests from a single server in
  3678. # a window before the server will delay processing the request.
  3679. # - sleep_delay: duration in milliseconds to delay processing events
  3680. # from remote servers by if they go over the sleep limit.
  3681. # - reject_limit: maximum number of concurrent federation requests
  3682. # allowed from a single server
  3683. # - concurrent: number of federation requests to concurrently process
  3684. # from a single server
  3685. #
  3686. # The defaults are as shown below.
  3687. #
  3688. #rc_federation:
  3689. # window_size: 1000
  3690. # sleep_limit: 10
  3691. # sleep_delay: 500
  3692. # reject_limit: 50
  3693. # concurrent: 3
  3694. # Target outgoing federation transaction frequency for sending read-receipts,
  3695. # per-room.
  3696. #
  3697. # If we end up trying to send out more read-receipts, they will get buffered up
  3698. # into fewer transactions.
  3699. #
  3700. #federation_rr_transactions_per_room_per_second: 50
  3701. ## Media Store ##
  3702. # Enable the media store service in the Synapse master. Uncomment the
  3703. # following if you are using a separate media store worker.
  3704. #
  3705. #enable_media_repo: false
  3706. # Directory where uploaded images and attachments are stored.
  3707. #
  3708. media_store_path: &quot;DATADIR/media_store&quot;
  3709. # Media storage providers allow media to be stored in different
  3710. # locations.
  3711. #
  3712. #media_storage_providers:
  3713. # - module: file_system
  3714. # # Whether to store newly uploaded local files
  3715. # store_local: false
  3716. # # Whether to store newly downloaded remote files
  3717. # store_remote: false
  3718. # # Whether to wait for successful storage for local uploads
  3719. # store_synchronous: false
  3720. # config:
  3721. # directory: /mnt/some/other/directory
  3722. # The largest allowed upload size in bytes
  3723. #
  3724. # If you are using a reverse proxy you may also need to set this value in
  3725. # your reverse proxy's config. Notably Nginx has a small max body size by default.
  3726. # See https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3727. #
  3728. #max_upload_size: 50M
  3729. # Maximum number of pixels that will be thumbnailed
  3730. #
  3731. #max_image_pixels: 32M
  3732. # Whether to generate new thumbnails on the fly to precisely match
  3733. # the resolution requested by the client. If true then whenever
  3734. # a new resolution is requested by the client the server will
  3735. # generate a new thumbnail. If false the server will pick a thumbnail
  3736. # from a precalculated list.
  3737. #
  3738. #dynamic_thumbnails: false
  3739. # List of thumbnails to precalculate when an image is uploaded.
  3740. #
  3741. #thumbnail_sizes:
  3742. # - width: 32
  3743. # height: 32
  3744. # method: crop
  3745. # - width: 96
  3746. # height: 96
  3747. # method: crop
  3748. # - width: 320
  3749. # height: 240
  3750. # method: scale
  3751. # - width: 640
  3752. # height: 480
  3753. # method: scale
  3754. # - width: 800
  3755. # height: 600
  3756. # method: scale
  3757. # Is the preview URL API enabled?
  3758. #
  3759. # 'false' by default: uncomment the following to enable it (and specify a
  3760. # url_preview_ip_range_blacklist blacklist).
  3761. #
  3762. #url_preview_enabled: true
  3763. # List of IP address CIDR ranges that the URL preview spider is denied
  3764. # from accessing. There are no defaults: you must explicitly
  3765. # specify a list for URL previewing to work. You should specify any
  3766. # internal services in your network that you do not want synapse to try
  3767. # to connect to, otherwise anyone in any Matrix room could cause your
  3768. # synapse to issue arbitrary GET requests to your internal services,
  3769. # causing serious security issues.
  3770. #
  3771. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3772. # listed here, since they correspond to unroutable addresses.)
  3773. #
  3774. # This must be specified if url_preview_enabled is set. It is recommended that
  3775. # you uncomment the following list as a starting point.
  3776. #
  3777. # Note: The value is ignored when an HTTP proxy is in use
  3778. #
  3779. #url_preview_ip_range_blacklist:
  3780. # - '127.0.0.0/8'
  3781. # - '10.0.0.0/8'
  3782. # - '172.16.0.0/12'
  3783. # - '192.168.0.0/16'
  3784. # - '100.64.0.0/10'
  3785. # - '192.0.0.0/24'
  3786. # - '169.254.0.0/16'
  3787. # - '192.88.99.0/24'
  3788. # - '198.18.0.0/15'
  3789. # - '192.0.2.0/24'
  3790. # - '198.51.100.0/24'
  3791. # - '203.0.113.0/24'
  3792. # - '224.0.0.0/4'
  3793. # - '::1/128'
  3794. # - 'fe80::/10'
  3795. # - 'fc00::/7'
  3796. # - '2001:db8::/32'
  3797. # - 'ff00::/8'
  3798. # - 'fec0::/10'
  3799. # List of IP address CIDR ranges that the URL preview spider is allowed
  3800. # to access even if they are specified in url_preview_ip_range_blacklist.
  3801. # This is useful for specifying exceptions to wide-ranging blacklisted
  3802. # target IP ranges - e.g. for enabling URL previews for a specific private
  3803. # website only visible in your network.
  3804. #
  3805. #url_preview_ip_range_whitelist:
  3806. # - '192.168.1.1'
  3807. # Optional list of URL matches that the URL preview spider is
  3808. # denied from accessing. You should use url_preview_ip_range_blacklist
  3809. # in preference to this, otherwise someone could define a public DNS
  3810. # entry that points to a private IP address and circumvent the blacklist.
  3811. # This is more useful if you know there is an entire shape of URL that
  3812. # you know that will never want synapse to try to spider.
  3813. #
  3814. # Each list entry is a dictionary of url component attributes as returned
  3815. # by urlparse.urlsplit as applied to the absolute form of the URL. See
  3816. # https://docs.python.org/2/library/urlparse.html#urlparse.urlsplit
  3817. # The values of the dictionary are treated as an filename match pattern
  3818. # applied to that component of URLs, unless they start with a ^ in which
  3819. # case they are treated as a regular expression match. If all the
  3820. # specified component matches for a given list item succeed, the URL is
  3821. # blacklisted.
  3822. #
  3823. #url_preview_url_blacklist:
  3824. # # blacklist any URL with a username in its URI
  3825. # - username: '*'
  3826. #
  3827. # # blacklist all *.google.com URLs
  3828. # - netloc: 'google.com'
  3829. # - netloc: '*.google.com'
  3830. #
  3831. # # blacklist all plain HTTP URLs
  3832. # - scheme: 'http'
  3833. #
  3834. # # blacklist http(s)://www.acme.com/foo
  3835. # - netloc: 'www.acme.com'
  3836. # path: '/foo'
  3837. #
  3838. # # blacklist any URL with a literal IPv4 address
  3839. # - netloc: '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  3840. # The largest allowed URL preview spidering size in bytes
  3841. #
  3842. #max_spider_size: 10M
  3843. # A list of values for the Accept-Language HTTP header used when
  3844. # downloading webpages during URL preview generation. This allows
  3845. # Synapse to specify the preferred languages that URL previews should
  3846. # be in when communicating with remote servers.
  3847. #
  3848. # Each value is a IETF language tag; a 2-3 letter identifier for a
  3849. # language, optionally followed by subtags separated by '-', specifying
  3850. # a country or region variant.
  3851. #
  3852. # Multiple values can be provided, and a weight can be added to each by
  3853. # using quality value syntax (;q=). '*' translates to any language.
  3854. #
  3855. # Defaults to &quot;en&quot;.
  3856. #
  3857. # Example:
  3858. #
  3859. # url_preview_accept_language:
  3860. # - en-UK
  3861. # - en-US;q=0.9
  3862. # - fr;q=0.8
  3863. # - *;q=0.7
  3864. #
  3865. url_preview_accept_language:
  3866. # - en
  3867. ## Captcha ##
  3868. # See docs/CAPTCHA_SETUP.md for full details of configuring this.
  3869. # This homeserver's ReCAPTCHA public key. Must be specified if
  3870. # enable_registration_captcha is enabled.
  3871. #
  3872. #recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  3873. # This homeserver's ReCAPTCHA private key. Must be specified if
  3874. # enable_registration_captcha is enabled.
  3875. #
  3876. #recaptcha_private_key: &quot;YOUR_PRIVATE_KEY&quot;
  3877. # Uncomment to enable ReCaptcha checks when registering, preventing signup
  3878. # unless a captcha is answered. Requires a valid ReCaptcha
  3879. # public/private key. Defaults to 'false'.
  3880. #
  3881. #enable_registration_captcha: true
  3882. # The API endpoint to use for verifying m.login.recaptcha responses.
  3883. # Defaults to &quot;https://www.recaptcha.net/recaptcha/api/siteverify&quot;.
  3884. #
  3885. #recaptcha_siteverify_api: &quot;https://my.recaptcha.site&quot;
  3886. ## TURN ##
  3887. # The public URIs of the TURN server to give to clients
  3888. #
  3889. #turn_uris: []
  3890. # The shared secret used to compute passwords for the TURN server
  3891. #
  3892. #turn_shared_secret: &quot;YOUR_SHARED_SECRET&quot;
  3893. # The Username and password if the TURN server needs them and
  3894. # does not use a token
  3895. #
  3896. #turn_username: &quot;TURNSERVER_USERNAME&quot;
  3897. #turn_password: &quot;TURNSERVER_PASSWORD&quot;
  3898. # How long generated TURN credentials last
  3899. #
  3900. #turn_user_lifetime: 1h
  3901. # Whether guests should be allowed to use the TURN server.
  3902. # This defaults to True, otherwise VoIP will be unreliable for guests.
  3903. # However, it does introduce a slight security risk as it allows users to
  3904. # connect to arbitrary endpoints without having first signed up for a
  3905. # valid account (e.g. by passing a CAPTCHA).
  3906. #
  3907. #turn_allow_guests: true
  3908. ## Registration ##
  3909. #
  3910. # Registration can be rate-limited using the parameters in the &quot;Ratelimiting&quot;
  3911. # section of this file.
  3912. # Enable registration for new users.
  3913. #
  3914. #enable_registration: false
  3915. # Time that a user's session remains valid for, after they log in.
  3916. #
  3917. # Note that this is not currently compatible with guest logins.
  3918. #
  3919. # Note also that this is calculated at login time: changes are not applied
  3920. # retrospectively to users who have already logged in.
  3921. #
  3922. # By default, this is infinite.
  3923. #
  3924. #session_lifetime: 24h
  3925. # The user must provide all of the below types of 3PID when registering.
  3926. #
  3927. #registrations_require_3pid:
  3928. # - email
  3929. # - msisdn
  3930. # Explicitly disable asking for MSISDNs from the registration
  3931. # flow (overrides registrations_require_3pid if MSISDNs are set as required)
  3932. #
  3933. #disable_msisdn_registration: true
  3934. # Mandate that users are only allowed to associate certain formats of
  3935. # 3PIDs with accounts on this server.
  3936. #
  3937. #allowed_local_3pids:
  3938. # - medium: email
  3939. # pattern: '^[^@]+@matrix\.org$'
  3940. # - medium: email
  3941. # pattern: '^[^@]+@vector\.im$'
  3942. # - medium: msisdn
  3943. # pattern: '\+44'
  3944. # Enable 3PIDs lookup requests to identity servers from this server.
  3945. #
  3946. #enable_3pid_lookup: true
  3947. # If set, allows registration of standard or admin accounts by anyone who
  3948. # has the shared secret, even if registration is otherwise disabled.
  3949. #
  3950. #registration_shared_secret: &lt;PRIVATE STRING&gt;
  3951. # Set the number of bcrypt rounds used to generate password hash.
  3952. # Larger numbers increase the work factor needed to generate the hash.
  3953. # The default number is 12 (which equates to 2^12 rounds).
  3954. # N.B. that increasing this will exponentially increase the time required
  3955. # to register or login - e.g. 24 =&gt; 2^24 rounds which will take &gt;20 mins.
  3956. #
  3957. #bcrypt_rounds: 12
  3958. # Allows users to register as guests without a password/email/etc, and
  3959. # participate in rooms hosted on this server which have been made
  3960. # accessible to anonymous users.
  3961. #
  3962. #allow_guest_access: false
  3963. # The identity server which we suggest that clients should use when users log
  3964. # in on this server.
  3965. #
  3966. # (By default, no suggestion is made, so it is left up to the client.
  3967. # This setting is ignored unless public_baseurl is also set.)
  3968. #
  3969. #default_identity_server: https://matrix.org
  3970. # Handle threepid (email/phone etc) registration and password resets through a set of
  3971. # *trusted* identity servers. Note that this allows the configured identity server to
  3972. # reset passwords for accounts!
  3973. #
  3974. # Be aware that if `email` is not set, and SMTP options have not been
  3975. # configured in the email config block, registration and user password resets via
  3976. # email will be globally disabled.
  3977. #
  3978. # Additionally, if `msisdn` is not set, registration and password resets via msisdn
  3979. # will be disabled regardless, and users will not be able to associate an msisdn
  3980. # identifier to their account. This is due to Synapse currently not supporting
  3981. # any method of sending SMS messages on its own.
  3982. #
  3983. # To enable using an identity server for operations regarding a particular third-party
  3984. # identifier type, set the value to the URL of that identity server as shown in the
  3985. # examples below.
  3986. #
  3987. # Servers handling the these requests must answer the `/requestToken` endpoints defined
  3988. # by the Matrix Identity Service API specification:
  3989. # https://matrix.org/docs/spec/identity_service/latest
  3990. #
  3991. # If a delegate is specified, the config option public_baseurl must also be filled out.
  3992. #
  3993. account_threepid_delegates:
  3994. #email: https://example.com # Delegate email sending to example.com
  3995. #msisdn: http://localhost:8090 # Delegate SMS sending to this local process
  3996. # Whether users are allowed to change their displayname after it has
  3997. # been initially set. Useful when provisioning users based on the
  3998. # contents of a third-party directory.
  3999. #
  4000. # Does not apply to server administrators. Defaults to 'true'
  4001. #
  4002. #enable_set_displayname: false
  4003. # Whether users are allowed to change their avatar after it has been
  4004. # initially set. Useful when provisioning users based on the contents
  4005. # of a third-party directory.
  4006. #
  4007. # Does not apply to server administrators. Defaults to 'true'
  4008. #
  4009. #enable_set_avatar_url: false
  4010. # Whether users can change the 3PIDs associated with their accounts
  4011. # (email address and msisdn).
  4012. #
  4013. # Defaults to 'true'
  4014. #
  4015. #enable_3pid_changes: false
  4016. # Users who register on this homeserver will automatically be joined
  4017. # to these rooms.
  4018. #
  4019. # By default, any room aliases included in this list will be created
  4020. # as a publicly joinable room when the first user registers for the
  4021. # homeserver. This behaviour can be customised with the settings below.
  4022. # If the room already exists, make certain it is a publicly joinable
  4023. # room. The join rule of the room must be set to 'public'.
  4024. #
  4025. #auto_join_rooms:
  4026. # - &quot;#example:example.com&quot;
  4027. # Where auto_join_rooms are specified, setting this flag ensures that the
  4028. # the rooms exist by creating them when the first user on the
  4029. # homeserver registers.
  4030. #
  4031. # By default the auto-created rooms are publicly joinable from any federated
  4032. # server. Use the autocreate_auto_join_rooms_federated and
  4033. # autocreate_auto_join_room_preset settings below to customise this behaviour.
  4034. #
  4035. # Setting to false means that if the rooms are not manually created,
  4036. # users cannot be auto-joined since they do not exist.
  4037. #
  4038. # Defaults to true. Uncomment the following line to disable automatically
  4039. # creating auto-join rooms.
  4040. #
  4041. #autocreate_auto_join_rooms: false
  4042. # Whether the auto_join_rooms that are auto-created are available via
  4043. # federation. Only has an effect if autocreate_auto_join_rooms is true.
  4044. #
  4045. # Note that whether a room is federated cannot be modified after
  4046. # creation.
  4047. #
  4048. # Defaults to true: the room will be joinable from other servers.
  4049. # Uncomment the following to prevent users from other homeservers from
  4050. # joining these rooms.
  4051. #
  4052. #autocreate_auto_join_rooms_federated: false
  4053. # The room preset to use when auto-creating one of auto_join_rooms. Only has an
  4054. # effect if autocreate_auto_join_rooms is true.
  4055. #
  4056. # This can be one of &quot;public_chat&quot;, &quot;private_chat&quot;, or &quot;trusted_private_chat&quot;.
  4057. # If a value of &quot;private_chat&quot; or &quot;trusted_private_chat&quot; is used then
  4058. # auto_join_mxid_localpart must also be configured.
  4059. #
  4060. # Defaults to &quot;public_chat&quot;, meaning that the room is joinable by anyone, including
  4061. # federated servers if autocreate_auto_join_rooms_federated is true (the default).
  4062. # Uncomment the following to require an invitation to join these rooms.
  4063. #
  4064. #autocreate_auto_join_room_preset: private_chat
  4065. # The local part of the user id which is used to create auto_join_rooms if
  4066. # autocreate_auto_join_rooms is true. If this is not provided then the
  4067. # initial user account that registers will be used to create the rooms.
  4068. #
  4069. # The user id is also used to invite new users to any auto-join rooms which
  4070. # are set to invite-only.
  4071. #
  4072. # It *must* be configured if autocreate_auto_join_room_preset is set to
  4073. # &quot;private_chat&quot; or &quot;trusted_private_chat&quot;.
  4074. #
  4075. # Note that this must be specified in order for new users to be correctly
  4076. # invited to any auto-join rooms which have been set to invite-only (either
  4077. # at the time of creation or subsequently).
  4078. #
  4079. # Note that, if the room already exists, this user must be joined and
  4080. # have the appropriate permissions to invite new members.
  4081. #
  4082. #auto_join_mxid_localpart: system
  4083. # When auto_join_rooms is specified, setting this flag to false prevents
  4084. # guest accounts from being automatically joined to the rooms.
  4085. #
  4086. # Defaults to true.
  4087. #
  4088. #auto_join_rooms_for_guests: false
  4089. ## Metrics ###
  4090. # Enable collection and rendering of performance metrics
  4091. #
  4092. #enable_metrics: false
  4093. # Enable sentry integration
  4094. # NOTE: While attempts are made to ensure that the logs don't contain
  4095. # any sensitive information, this cannot be guaranteed. By enabling
  4096. # this option the sentry server may therefore receive sensitive
  4097. # information, and it in turn may then diseminate sensitive information
  4098. # through insecure notification channels if so configured.
  4099. #
  4100. #sentry:
  4101. # dsn: &quot;...&quot;
  4102. # Flags to enable Prometheus metrics which are not suitable to be
  4103. # enabled by default, either for performance reasons or limited use.
  4104. #
  4105. metrics_flags:
  4106. # Publish synapse_federation_known_servers, a gauge of the number of
  4107. # servers this homeserver knows about, including itself. May cause
  4108. # performance problems on large homeservers.
  4109. #
  4110. #known_servers: true
  4111. # Whether or not to report anonymized homeserver usage statistics.
  4112. #
  4113. #report_stats: true|false
  4114. # The endpoint to report the anonymized homeserver usage statistics to.
  4115. # Defaults to https://matrix.org/report-usage-stats/push
  4116. #
  4117. #report_stats_endpoint: https://example.com/report-usage-stats/push
  4118. ## API Configuration ##
  4119. # Controls for the state that is shared with users who receive an invite
  4120. # to a room
  4121. #
  4122. room_prejoin_state:
  4123. # By default, the following state event types are shared with users who
  4124. # receive invites to the room:
  4125. #
  4126. # - m.room.join_rules
  4127. # - m.room.canonical_alias
  4128. # - m.room.avatar
  4129. # - m.room.encryption
  4130. # - m.room.name
  4131. # - m.room.create
  4132. #
  4133. # Uncomment the following to disable these defaults (so that only the event
  4134. # types listed in 'additional_event_types' are shared). Defaults to 'false'.
  4135. #
  4136. #disable_default_event_types: true
  4137. # Additional state event types to share with users when they are invited
  4138. # to a room.
  4139. #
  4140. # By default, this list is empty (so only the default event types are shared).
  4141. #
  4142. #additional_event_types:
  4143. # - org.example.custom.event.type
  4144. # A list of application service config files to use
  4145. #
  4146. #app_service_config_files:
  4147. # - app_service_1.yaml
  4148. # - app_service_2.yaml
  4149. # Uncomment to enable tracking of application service IP addresses. Implicitly
  4150. # enables MAU tracking for application service users.
  4151. #
  4152. #track_appservice_user_ips: true
  4153. # a secret which is used to sign access tokens. If none is specified,
  4154. # the registration_shared_secret is used, if one is given; otherwise,
  4155. # a secret key is derived from the signing key.
  4156. #
  4157. #macaroon_secret_key: &lt;PRIVATE STRING&gt;
  4158. # a secret which is used to calculate HMACs for form values, to stop
  4159. # falsification of values. Must be specified for the User Consent
  4160. # forms to work.
  4161. #
  4162. #form_secret: &lt;PRIVATE STRING&gt;
  4163. ## Signing Keys ##
  4164. # Path to the signing key to sign messages with
  4165. #
  4166. signing_key_path: &quot;CONFDIR/SERVERNAME.signing.key&quot;
  4167. # The keys that the server used to sign messages with but won't use
  4168. # to sign new messages.
  4169. #
  4170. old_signing_keys:
  4171. # For each key, `key` should be the base64-encoded public key, and
  4172. # `expired_ts`should be the time (in milliseconds since the unix epoch) that
  4173. # it was last used.
  4174. #
  4175. # It is possible to build an entry from an old signing.key file using the
  4176. # `export_signing_key` script which is provided with synapse.
  4177. #
  4178. # For example:
  4179. #
  4180. #&quot;ed25519:id&quot;: { key: &quot;base64string&quot;, expired_ts: 123456789123 }
  4181. # How long key response published by this server is valid for.
  4182. # Used to set the valid_until_ts in /key/v2 APIs.
  4183. # Determines how quickly servers will query to check which keys
  4184. # are still valid.
  4185. #
  4186. #key_refresh_interval: 1d
  4187. # The trusted servers to download signing keys from.
  4188. #
  4189. # When we need to fetch a signing key, each server is tried in parallel.
  4190. #
  4191. # Normally, the connection to the key server is validated via TLS certificates.
  4192. # Additional security can be provided by configuring a `verify key`, which
  4193. # will make synapse check that the response is signed by that key.
  4194. #
  4195. # This setting supercedes an older setting named `perspectives`. The old format
  4196. # is still supported for backwards-compatibility, but it is deprecated.
  4197. #
  4198. # 'trusted_key_servers' defaults to matrix.org, but using it will generate a
  4199. # warning on start-up. To suppress this warning, set
  4200. # 'suppress_key_server_warning' to true.
  4201. #
  4202. # Options for each entry in the list include:
  4203. #
  4204. # server_name: the name of the server. required.
  4205. #
  4206. # verify_keys: an optional map from key id to base64-encoded public key.
  4207. # If specified, we will check that the response is signed by at least
  4208. # one of the given keys.
  4209. #
  4210. # accept_keys_insecurely: a boolean. Normally, if `verify_keys` is unset,
  4211. # and federation_verify_certificates is not `true`, synapse will refuse
  4212. # to start, because this would allow anyone who can spoof DNS responses
  4213. # to masquerade as the trusted key server. If you know what you are doing
  4214. # and are sure that your network environment provides a secure connection
  4215. # to the key server, you can set this to `true` to override this
  4216. # behaviour.
  4217. #
  4218. # An example configuration might look like:
  4219. #
  4220. #trusted_key_servers:
  4221. # - server_name: &quot;my_trusted_server.example.com&quot;
  4222. # verify_keys:
  4223. # &quot;ed25519:auto&quot;: &quot;abcdefghijklmnopqrstuvwxyzabcdefghijklmopqr&quot;
  4224. # - server_name: &quot;my_other_trusted_server.example.com&quot;
  4225. #
  4226. trusted_key_servers:
  4227. - server_name: &quot;matrix.org&quot;
  4228. # Uncomment the following to disable the warning that is emitted when the
  4229. # trusted_key_servers include 'matrix.org'. See above.
  4230. #
  4231. #suppress_key_server_warning: true
  4232. # The signing keys to use when acting as a trusted key server. If not specified
  4233. # defaults to the server signing key.
  4234. #
  4235. # Can contain multiple keys, one per line.
  4236. #
  4237. #key_server_signing_keys_path: &quot;key_server_signing_keys.key&quot;
  4238. ## Single sign-on integration ##
  4239. # The following settings can be used to make Synapse use a single sign-on
  4240. # provider for authentication, instead of its internal password database.
  4241. #
  4242. # You will probably also want to set the following options to `false` to
  4243. # disable the regular login/registration flows:
  4244. # * enable_registration
  4245. # * password_config.enabled
  4246. #
  4247. # You will also want to investigate the settings under the &quot;sso&quot; configuration
  4248. # section below.
  4249. # Enable SAML2 for registration and login. Uses pysaml2.
  4250. #
  4251. # At least one of `sp_config` or `config_path` must be set in this section to
  4252. # enable SAML login.
  4253. #
  4254. # Once SAML support is enabled, a metadata file will be exposed at
  4255. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/metadata.xml, which you may be able to
  4256. # use to configure your SAML IdP with. Alternatively, you can manually configure
  4257. # the IdP to use an ACS location of
  4258. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/authn_response.
  4259. #
  4260. saml2_config:
  4261. # `sp_config` is the configuration for the pysaml2 Service Provider.
  4262. # See pysaml2 docs for format of config.
  4263. #
  4264. # Default values will be used for the 'entityid' and 'service' settings,
  4265. # so it is not normally necessary to specify them unless you need to
  4266. # override them.
  4267. #
  4268. sp_config:
  4269. # Point this to the IdP's metadata. You must provide either a local
  4270. # file via the `local` attribute or (preferably) a URL via the
  4271. # `remote` attribute.
  4272. #
  4273. #metadata:
  4274. # local: [&quot;saml2/idp.xml&quot;]
  4275. # remote:
  4276. # - url: https://our_idp/metadata.xml
  4277. # Allowed clock difference in seconds between the homeserver and IdP.
  4278. #
  4279. # Uncomment the below to increase the accepted time difference from 0 to 3 seconds.
  4280. #
  4281. #accepted_time_diff: 3
  4282. # By default, the user has to go to our login page first. If you'd like
  4283. # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
  4284. # 'service.sp' section:
  4285. #
  4286. #service:
  4287. # sp:
  4288. # allow_unsolicited: true
  4289. # The examples below are just used to generate our metadata xml, and you
  4290. # may well not need them, depending on your setup. Alternatively you
  4291. # may need a whole lot more detail - see the pysaml2 docs!
  4292. #description: [&quot;My awesome SP&quot;, &quot;en&quot;]
  4293. #name: [&quot;Test SP&quot;, &quot;en&quot;]
  4294. #ui_info:
  4295. # display_name:
  4296. # - lang: en
  4297. # text: &quot;Display Name is the descriptive name of your service.&quot;
  4298. # description:
  4299. # - lang: en
  4300. # text: &quot;Description should be a short paragraph explaining the purpose of the service.&quot;
  4301. # information_url:
  4302. # - lang: en
  4303. # text: &quot;https://example.com/terms-of-service&quot;
  4304. # privacy_statement_url:
  4305. # - lang: en
  4306. # text: &quot;https://example.com/privacy-policy&quot;
  4307. # keywords:
  4308. # - lang: en
  4309. # text: [&quot;Matrix&quot;, &quot;Element&quot;]
  4310. # logo:
  4311. # - lang: en
  4312. # text: &quot;https://example.com/logo.svg&quot;
  4313. # width: &quot;200&quot;
  4314. # height: &quot;80&quot;
  4315. #organization:
  4316. # name: Example com
  4317. # display_name:
  4318. # - [&quot;Example co&quot;, &quot;en&quot;]
  4319. # url: &quot;http://example.com&quot;
  4320. #contact_person:
  4321. # - given_name: Bob
  4322. # sur_name: &quot;the Sysadmin&quot;
  4323. # email_address&quot;: [&quot;admin@example.com&quot;]
  4324. # contact_type&quot;: technical
  4325. # Instead of putting the config inline as above, you can specify a
  4326. # separate pysaml2 configuration file:
  4327. #
  4328. #config_path: &quot;CONFDIR/sp_conf.py&quot;
  4329. # The lifetime of a SAML session. This defines how long a user has to
  4330. # complete the authentication process, if allow_unsolicited is unset.
  4331. # The default is 15 minutes.
  4332. #
  4333. #saml_session_lifetime: 5m
  4334. # An external module can be provided here as a custom solution to
  4335. # mapping attributes returned from a saml provider onto a matrix user.
  4336. #
  4337. user_mapping_provider:
  4338. # The custom module's class. Uncomment to use a custom module.
  4339. #
  4340. #module: mapping_provider.SamlMappingProvider
  4341. # Custom configuration values for the module. Below options are
  4342. # intended for the built-in provider, they should be changed if
  4343. # using a custom module. This section will be passed as a Python
  4344. # dictionary to the module's `parse_config` method.
  4345. #
  4346. config:
  4347. # The SAML attribute (after mapping via the attribute maps) to use
  4348. # to derive the Matrix ID from. 'uid' by default.
  4349. #
  4350. # Note: This used to be configured by the
  4351. # saml2_config.mxid_source_attribute option. If that is still
  4352. # defined, its value will be used instead.
  4353. #
  4354. #mxid_source_attribute: displayName
  4355. # The mapping system to use for mapping the saml attribute onto a
  4356. # matrix ID.
  4357. #
  4358. # Options include:
  4359. # * 'hexencode' (which maps unpermitted characters to '=xx')
  4360. # * 'dotreplace' (which replaces unpermitted characters with
  4361. # '.').
  4362. # The default is 'hexencode'.
  4363. #
  4364. # Note: This used to be configured by the
  4365. # saml2_config.mxid_mapping option. If that is still defined, its
  4366. # value will be used instead.
  4367. #
  4368. #mxid_mapping: dotreplace
  4369. # In previous versions of synapse, the mapping from SAML attribute to
  4370. # MXID was always calculated dynamically rather than stored in a
  4371. # table. For backwards- compatibility, we will look for user_ids
  4372. # matching such a pattern before creating a new account.
  4373. #
  4374. # This setting controls the SAML attribute which will be used for this
  4375. # backwards-compatibility lookup. Typically it should be 'uid', but if
  4376. # the attribute maps are changed, it may be necessary to change it.
  4377. #
  4378. # The default is 'uid'.
  4379. #
  4380. #grandfathered_mxid_source_attribute: upn
  4381. # It is possible to configure Synapse to only allow logins if SAML attributes
  4382. # match particular values. The requirements can be listed under
  4383. # `attribute_requirements` as shown below. All of the listed attributes must
  4384. # match for the login to be permitted.
  4385. #
  4386. #attribute_requirements:
  4387. # - attribute: userGroup
  4388. # value: &quot;staff&quot;
  4389. # - attribute: department
  4390. # value: &quot;sales&quot;
  4391. # If the metadata XML contains multiple IdP entities then the `idp_entityid`
  4392. # option must be set to the entity to redirect users to.
  4393. #
  4394. # Most deployments only have a single IdP entity and so should omit this
  4395. # option.
  4396. #
  4397. #idp_entityid: 'https://our_idp/entityid'
  4398. # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration
  4399. # and login.
  4400. #
  4401. # Options for each entry include:
  4402. #
  4403. # idp_id: a unique identifier for this identity provider. Used internally
  4404. # by Synapse; should be a single word such as 'github'.
  4405. #
  4406. # Note that, if this is changed, users authenticating via that provider
  4407. # will no longer be recognised as the same user!
  4408. #
  4409. # (Use &quot;oidc&quot; here if you are migrating from an old &quot;oidc_config&quot;
  4410. # configuration.)
  4411. #
  4412. # idp_name: A user-facing name for this identity provider, which is used to
  4413. # offer the user a choice of login mechanisms.
  4414. #
  4415. # idp_icon: An optional icon for this identity provider, which is presented
  4416. # by clients and Synapse's own IdP picker page. If given, must be an
  4417. # MXC URI of the format mxc://&lt;server-name&gt;/&lt;media-id&gt;. (An easy way to
  4418. # obtain such an MXC URI is to upload an image to an (unencrypted) room
  4419. # and then copy the &quot;url&quot; from the source of the event.)
  4420. #
  4421. # idp_brand: An optional brand for this identity provider, allowing clients
  4422. # to style the login flow according to the identity provider in question.
  4423. # See the spec for possible options here.
  4424. #
  4425. # discover: set to 'false' to disable the use of the OIDC discovery mechanism
  4426. # to discover endpoints. Defaults to true.
  4427. #
  4428. # issuer: Required. The OIDC issuer. Used to validate tokens and (if discovery
  4429. # is enabled) to discover the provider's endpoints.
  4430. #
  4431. # client_id: Required. oauth2 client id to use.
  4432. #
  4433. # client_secret: oauth2 client secret to use. May be omitted if
  4434. # client_secret_jwt_key is given, or if client_auth_method is 'none'.
  4435. #
  4436. # client_secret_jwt_key: Alternative to client_secret: details of a key used
  4437. # to create a JSON Web Token to be used as an OAuth2 client secret. If
  4438. # given, must be a dictionary with the following properties:
  4439. #
  4440. # key: a pem-encoded signing key. Must be a suitable key for the
  4441. # algorithm specified. Required unless 'key_file' is given.
  4442. #
  4443. # key_file: the path to file containing a pem-encoded signing key file.
  4444. # Required unless 'key' is given.
  4445. #
  4446. # jwt_header: a dictionary giving properties to include in the JWT
  4447. # header. Must include the key 'alg', giving the algorithm used to
  4448. # sign the JWT, such as &quot;ES256&quot;, using the JWA identifiers in
  4449. # RFC7518.
  4450. #
  4451. # jwt_payload: an optional dictionary giving properties to include in
  4452. # the JWT payload. Normally this should include an 'iss' key.
  4453. #
  4454. # client_auth_method: auth method to use when exchanging the token. Valid
  4455. # values are 'client_secret_basic' (default), 'client_secret_post' and
  4456. # 'none'.
  4457. #
  4458. # scopes: list of scopes to request. This should normally include the &quot;openid&quot;
  4459. # scope. Defaults to [&quot;openid&quot;].
  4460. #
  4461. # authorization_endpoint: the oauth2 authorization endpoint. Required if
  4462. # provider discovery is disabled.
  4463. #
  4464. # token_endpoint: the oauth2 token endpoint. Required if provider discovery is
  4465. # disabled.
  4466. #
  4467. # userinfo_endpoint: the OIDC userinfo endpoint. Required if discovery is
  4468. # disabled and the 'openid' scope is not requested.
  4469. #
  4470. # jwks_uri: URI where to fetch the JWKS. Required if discovery is disabled and
  4471. # the 'openid' scope is used.
  4472. #
  4473. # skip_verification: set to 'true' to skip metadata verification. Use this if
  4474. # you are connecting to a provider that is not OpenID Connect compliant.
  4475. # Defaults to false. Avoid this in production.
  4476. #
  4477. # user_profile_method: Whether to fetch the user profile from the userinfo
  4478. # endpoint. Valid values are: 'auto' or 'userinfo_endpoint'.
  4479. #
  4480. # Defaults to 'auto', which fetches the userinfo endpoint if 'openid' is
  4481. # included in 'scopes'. Set to 'userinfo_endpoint' to always fetch the
  4482. # userinfo endpoint.
  4483. #
  4484. # allow_existing_users: set to 'true' to allow a user logging in via OIDC to
  4485. # match a pre-existing account instead of failing. This could be used if
  4486. # switching from password logins to OIDC. Defaults to false.
  4487. #
  4488. # user_mapping_provider: Configuration for how attributes returned from a OIDC
  4489. # provider are mapped onto a matrix user. This setting has the following
  4490. # sub-properties:
  4491. #
  4492. # module: The class name of a custom mapping module. Default is
  4493. # 'synapse.handlers.oidc.JinjaOidcMappingProvider'.
  4494. # See https://matrix-org.github.io/synapse/latest/sso_mapping_providers.html#openid-mapping-providers
  4495. # for information on implementing a custom mapping provider.
  4496. #
  4497. # config: Configuration for the mapping provider module. This section will
  4498. # be passed as a Python dictionary to the user mapping provider
  4499. # module's `parse_config` method.
  4500. #
  4501. # For the default provider, the following settings are available:
  4502. #
  4503. # subject_claim: name of the claim containing a unique identifier
  4504. # for the user. Defaults to 'sub', which OpenID Connect
  4505. # compliant providers should provide.
  4506. #
  4507. # localpart_template: Jinja2 template for the localpart of the MXID.
  4508. # If this is not set, the user will be prompted to choose their
  4509. # own username (see 'sso_auth_account_details.html' in the 'sso'
  4510. # section of this file).
  4511. #
  4512. # display_name_template: Jinja2 template for the display name to set
  4513. # on first login. If unset, no displayname will be set.
  4514. #
  4515. # email_template: Jinja2 template for the email address of the user.
  4516. # If unset, no email address will be added to the account.
  4517. #
  4518. # extra_attributes: a map of Jinja2 templates for extra attributes
  4519. # to send back to the client during login.
  4520. # Note that these are non-standard and clients will ignore them
  4521. # without modifications.
  4522. #
  4523. # When rendering, the Jinja2 templates are given a 'user' variable,
  4524. # which is set to the claims returned by the UserInfo Endpoint and/or
  4525. # in the ID Token.
  4526. #
  4527. # It is possible to configure Synapse to only allow logins if certain attributes
  4528. # match particular values in the OIDC userinfo. The requirements can be listed under
  4529. # `attribute_requirements` as shown below. All of the listed attributes must
  4530. # match for the login to be permitted. Additional attributes can be added to
  4531. # userinfo by expanding the `scopes` section of the OIDC config to retrieve
  4532. # additional information from the OIDC provider.
  4533. #
  4534. # If the OIDC claim is a list, then the attribute must match any value in the list.
  4535. # Otherwise, it must exactly match the value of the claim. Using the example
  4536. # below, the `family_name` claim MUST be &quot;Stephensson&quot;, but the `groups`
  4537. # claim MUST contain &quot;admin&quot;.
  4538. #
  4539. # attribute_requirements:
  4540. # - attribute: family_name
  4541. # value: &quot;Stephensson&quot;
  4542. # - attribute: groups
  4543. # value: &quot;admin&quot;
  4544. #
  4545. # See https://matrix-org.github.io/synapse/latest/openid.html
  4546. # for information on how to configure these options.
  4547. #
  4548. # For backwards compatibility, it is also possible to configure a single OIDC
  4549. # provider via an 'oidc_config' setting. This is now deprecated and admins are
  4550. # advised to migrate to the 'oidc_providers' format. (When doing that migration,
  4551. # use 'oidc' for the idp_id to ensure that existing users continue to be
  4552. # recognised.)
  4553. #
  4554. oidc_providers:
  4555. # Generic example
  4556. #
  4557. #- idp_id: my_idp
  4558. # idp_name: &quot;My OpenID provider&quot;
  4559. # idp_icon: &quot;mxc://example.com/mediaid&quot;
  4560. # discover: false
  4561. # issuer: &quot;https://accounts.example.com/&quot;
  4562. # client_id: &quot;provided-by-your-issuer&quot;
  4563. # client_secret: &quot;provided-by-your-issuer&quot;
  4564. # client_auth_method: client_secret_post
  4565. # scopes: [&quot;openid&quot;, &quot;profile&quot;]
  4566. # authorization_endpoint: &quot;https://accounts.example.com/oauth2/auth&quot;
  4567. # token_endpoint: &quot;https://accounts.example.com/oauth2/token&quot;
  4568. # userinfo_endpoint: &quot;https://accounts.example.com/userinfo&quot;
  4569. # jwks_uri: &quot;https://accounts.example.com/.well-known/jwks.json&quot;
  4570. # skip_verification: true
  4571. # user_mapping_provider:
  4572. # config:
  4573. # subject_claim: &quot;id&quot;
  4574. # localpart_template: &quot;{{ user.login }}&quot;
  4575. # display_name_template: &quot;{{ user.name }}&quot;
  4576. # email_template: &quot;{{ user.email }}&quot;
  4577. # attribute_requirements:
  4578. # - attribute: userGroup
  4579. # value: &quot;synapseUsers&quot;
  4580. # Enable Central Authentication Service (CAS) for registration and login.
  4581. #
  4582. cas_config:
  4583. # Uncomment the following to enable authorization against a CAS server.
  4584. # Defaults to false.
  4585. #
  4586. #enabled: true
  4587. # The URL of the CAS authorization endpoint.
  4588. #
  4589. #server_url: &quot;https://cas-server.com&quot;
  4590. # The attribute of the CAS response to use as the display name.
  4591. #
  4592. # If unset, no displayname will be set.
  4593. #
  4594. #displayname_attribute: name
  4595. # It is possible to configure Synapse to only allow logins if CAS attributes
  4596. # match particular values. All of the keys in the mapping below must exist
  4597. # and the values must match the given value. Alternately if the given value
  4598. # is None then any value is allowed (the attribute just must exist).
  4599. # All of the listed attributes must match for the login to be permitted.
  4600. #
  4601. #required_attributes:
  4602. # userGroup: &quot;staff&quot;
  4603. # department: None
  4604. # Additional settings to use with single-sign on systems such as OpenID Connect,
  4605. # SAML2 and CAS.
  4606. #
  4607. # Server admins can configure custom templates for pages related to SSO. See
  4608. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4609. #
  4610. sso:
  4611. # A list of client URLs which are whitelisted so that the user does not
  4612. # have to confirm giving access to their account to the URL. Any client
  4613. # whose URL starts with an entry in the following list will not be subject
  4614. # to an additional confirmation step after the SSO login is completed.
  4615. #
  4616. # WARNING: An entry such as &quot;https://my.client&quot; is insecure, because it
  4617. # will also match &quot;https://my.client.evil.site&quot;, exposing your users to
  4618. # phishing attacks from evil.site. To avoid this, include a slash after the
  4619. # hostname: &quot;https://my.client/&quot;.
  4620. #
  4621. # If public_baseurl is set, then the login fallback page (used by clients
  4622. # that don't natively support the required login flows) is whitelisted in
  4623. # addition to any URLs in this list.
  4624. #
  4625. # By default, this list is empty.
  4626. #
  4627. #client_whitelist:
  4628. # - https://riot.im/develop
  4629. # - https://my.custom.client/
  4630. # Uncomment to keep a user's profile fields in sync with information from
  4631. # the identity provider. Currently only syncing the displayname is
  4632. # supported. Fields are checked on every SSO login, and are updated
  4633. # if necessary.
  4634. #
  4635. # Note that enabling this option will override user profile information,
  4636. # regardless of whether users have opted-out of syncing that
  4637. # information when first signing in. Defaults to false.
  4638. #
  4639. #update_profile_information: true
  4640. # JSON web token integration. The following settings can be used to make
  4641. # Synapse JSON web tokens for authentication, instead of its internal
  4642. # password database.
  4643. #
  4644. # Each JSON Web Token needs to contain a &quot;sub&quot; (subject) claim, which is
  4645. # used as the localpart of the mxid.
  4646. #
  4647. # Additionally, the expiration time (&quot;exp&quot;), not before time (&quot;nbf&quot;),
  4648. # and issued at (&quot;iat&quot;) claims are validated if present.
  4649. #
  4650. # Note that this is a non-standard login type and client support is
  4651. # expected to be non-existent.
  4652. #
  4653. # See https://matrix-org.github.io/synapse/latest/jwt.html.
  4654. #
  4655. #jwt_config:
  4656. # Uncomment the following to enable authorization using JSON web
  4657. # tokens. Defaults to false.
  4658. #
  4659. #enabled: true
  4660. # This is either the private shared secret or the public key used to
  4661. # decode the contents of the JSON web token.
  4662. #
  4663. # Required if 'enabled' is true.
  4664. #
  4665. #secret: &quot;provided-by-your-issuer&quot;
  4666. # The algorithm used to sign the JSON web token.
  4667. #
  4668. # Supported algorithms are listed at
  4669. # https://pyjwt.readthedocs.io/en/latest/algorithms.html
  4670. #
  4671. # Required if 'enabled' is true.
  4672. #
  4673. #algorithm: &quot;provided-by-your-issuer&quot;
  4674. # The issuer to validate the &quot;iss&quot; claim against.
  4675. #
  4676. # Optional, if provided the &quot;iss&quot; claim will be required and
  4677. # validated for all JSON web tokens.
  4678. #
  4679. #issuer: &quot;provided-by-your-issuer&quot;
  4680. # A list of audiences to validate the &quot;aud&quot; claim against.
  4681. #
  4682. # Optional, if provided the &quot;aud&quot; claim will be required and
  4683. # validated for all JSON web tokens.
  4684. #
  4685. # Note that if the &quot;aud&quot; claim is included in a JSON web token then
  4686. # validation will fail without configuring audiences.
  4687. #
  4688. #audiences:
  4689. # - &quot;provided-by-your-issuer&quot;
  4690. password_config:
  4691. # Uncomment to disable password login
  4692. #
  4693. #enabled: false
  4694. # Uncomment to disable authentication against the local password
  4695. # database. This is ignored if `enabled` is false, and is only useful
  4696. # if you have other password_providers.
  4697. #
  4698. #localdb_enabled: false
  4699. # Uncomment and change to a secret random string for extra security.
  4700. # DO NOT CHANGE THIS AFTER INITIAL SETUP!
  4701. #
  4702. #pepper: &quot;EVEN_MORE_SECRET&quot;
  4703. # Define and enforce a password policy. Each parameter is optional.
  4704. # This is an implementation of MSC2000.
  4705. #
  4706. policy:
  4707. # Whether to enforce the password policy.
  4708. # Defaults to 'false'.
  4709. #
  4710. #enabled: true
  4711. # Minimum accepted length for a password.
  4712. # Defaults to 0.
  4713. #
  4714. #minimum_length: 15
  4715. # Whether a password must contain at least one digit.
  4716. # Defaults to 'false'.
  4717. #
  4718. #require_digit: true
  4719. # Whether a password must contain at least one symbol.
  4720. # A symbol is any character that's not a number or a letter.
  4721. # Defaults to 'false'.
  4722. #
  4723. #require_symbol: true
  4724. # Whether a password must contain at least one lowercase letter.
  4725. # Defaults to 'false'.
  4726. #
  4727. #require_lowercase: true
  4728. # Whether a password must contain at least one lowercase letter.
  4729. # Defaults to 'false'.
  4730. #
  4731. #require_uppercase: true
  4732. ui_auth:
  4733. # The amount of time to allow a user-interactive authentication session
  4734. # to be active.
  4735. #
  4736. # This defaults to 0, meaning the user is queried for their credentials
  4737. # before every action, but this can be overridden to allow a single
  4738. # validation to be re-used. This weakens the protections afforded by
  4739. # the user-interactive authentication process, by allowing for multiple
  4740. # (and potentially different) operations to use the same validation session.
  4741. #
  4742. # This is ignored for potentially &quot;dangerous&quot; operations (including
  4743. # deactivating an account, modifying an account password, and
  4744. # adding a 3PID).
  4745. #
  4746. # Uncomment below to allow for credential validation to last for 15
  4747. # seconds.
  4748. #
  4749. #session_timeout: &quot;15s&quot;
  4750. # Configuration for sending emails from Synapse.
  4751. #
  4752. # Server admins can configure custom templates for email content. See
  4753. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4754. #
  4755. email:
  4756. # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'.
  4757. #
  4758. #smtp_host: mail.server
  4759. # The port on the mail server for outgoing SMTP. Defaults to 25.
  4760. #
  4761. #smtp_port: 587
  4762. # Username/password for authentication to the SMTP server. By default, no
  4763. # authentication is attempted.
  4764. #
  4765. #smtp_user: &quot;exampleusername&quot;
  4766. #smtp_pass: &quot;examplepassword&quot;
  4767. # Uncomment the following to require TLS transport security for SMTP.
  4768. # By default, Synapse will connect over plain text, and will then switch to
  4769. # TLS via STARTTLS *if the SMTP server supports it*. If this option is set,
  4770. # Synapse will refuse to connect unless the server supports STARTTLS.
  4771. #
  4772. #require_transport_security: true
  4773. # Uncomment the following to disable TLS for SMTP.
  4774. #
  4775. # By default, if the server supports TLS, it will be used, and the server
  4776. # must present a certificate that is valid for 'smtp_host'. If this option
  4777. # is set to false, TLS will not be used.
  4778. #
  4779. #enable_tls: false
  4780. # notif_from defines the &quot;From&quot; address to use when sending emails.
  4781. # It must be set if email sending is enabled.
  4782. #
  4783. # The placeholder '%(app)s' will be replaced by the application name,
  4784. # which is normally 'app_name' (below), but may be overridden by the
  4785. # Matrix client application.
  4786. #
  4787. # Note that the placeholder must be written '%(app)s', including the
  4788. # trailing 's'.
  4789. #
  4790. #notif_from: &quot;Your Friendly %(app)s homeserver &lt;noreply@example.com&gt;&quot;
  4791. # app_name defines the default value for '%(app)s' in notif_from and email
  4792. # subjects. It defaults to 'Matrix'.
  4793. #
  4794. #app_name: my_branded_matrix_server
  4795. # Uncomment the following to enable sending emails for messages that the user
  4796. # has missed. Disabled by default.
  4797. #
  4798. #enable_notifs: true
  4799. # Uncomment the following to disable automatic subscription to email
  4800. # notifications for new users. Enabled by default.
  4801. #
  4802. #notif_for_new_users: false
  4803. # Custom URL for client links within the email notifications. By default
  4804. # links will be based on &quot;https://matrix.to&quot;.
  4805. #
  4806. # (This setting used to be called riot_base_url; the old name is still
  4807. # supported for backwards-compatibility but is now deprecated.)
  4808. #
  4809. #client_base_url: &quot;http://localhost/riot&quot;
  4810. # Configure the time that a validation email will expire after sending.
  4811. # Defaults to 1h.
  4812. #
  4813. #validation_token_lifetime: 15m
  4814. # The web client location to direct users to during an invite. This is passed
  4815. # to the identity server as the org.matrix.web_client_location key. Defaults
  4816. # to unset, giving no guidance to the identity server.
  4817. #
  4818. #invite_client_location: https://app.element.io
  4819. # Subjects to use when sending emails from Synapse.
  4820. #
  4821. # The placeholder '%(app)s' will be replaced with the value of the 'app_name'
  4822. # setting above, or by a value dictated by the Matrix client application.
  4823. #
  4824. # If a subject isn't overridden in this configuration file, the value used as
  4825. # its example will be used.
  4826. #
  4827. #subjects:
  4828. # Subjects for notification emails.
  4829. #
  4830. # On top of the '%(app)s' placeholder, these can use the following
  4831. # placeholders:
  4832. #
  4833. # * '%(person)s', which will be replaced by the display name of the user(s)
  4834. # that sent the message(s), e.g. &quot;Alice and Bob&quot;.
  4835. # * '%(room)s', which will be replaced by the name of the room the
  4836. # message(s) have been sent to, e.g. &quot;My super room&quot;.
  4837. #
  4838. # See the example provided for each setting to see which placeholder can be
  4839. # used and how to use them.
  4840. #
  4841. # Subject to use to notify about one message from one or more user(s) in a
  4842. # room which has a name.
  4843. #message_from_person_in_room: &quot;[%(app)s] You have a message on %(app)s from %(person)s in the %(room)s room...&quot;
  4844. #
  4845. # Subject to use to notify about one message from one or more user(s) in a
  4846. # room which doesn't have a name.
  4847. #message_from_person: &quot;[%(app)s] You have a message on %(app)s from %(person)s...&quot;
  4848. #
  4849. # Subject to use to notify about multiple messages from one or more users in
  4850. # a room which doesn't have a name.
  4851. #messages_from_person: &quot;[%(app)s] You have messages on %(app)s from %(person)s...&quot;
  4852. #
  4853. # Subject to use to notify about multiple messages in a room which has a
  4854. # name.
  4855. #messages_in_room: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room...&quot;
  4856. #
  4857. # Subject to use to notify about multiple messages in multiple rooms.
  4858. #messages_in_room_and_others: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room and others...&quot;
  4859. #
  4860. # Subject to use to notify about multiple messages from multiple persons in
  4861. # multiple rooms. This is similar to the setting above except it's used when
  4862. # the room in which the notification was triggered has no name.
  4863. #messages_from_person_and_others: &quot;[%(app)s] You have messages on %(app)s from %(person)s and others...&quot;
  4864. #
  4865. # Subject to use to notify about an invite to a room which has a name.
  4866. #invite_from_person_to_room: &quot;[%(app)s] %(person)s has invited you to join the %(room)s room on %(app)s...&quot;
  4867. #
  4868. # Subject to use to notify about an invite to a room which doesn't have a
  4869. # name.
  4870. #invite_from_person: &quot;[%(app)s] %(person)s has invited you to chat on %(app)s...&quot;
  4871. # Subject for emails related to account administration.
  4872. #
  4873. # On top of the '%(app)s' placeholder, these one can use the
  4874. # '%(server_name)s' placeholder, which will be replaced by the value of the
  4875. # 'server_name' setting in your Synapse configuration.
  4876. #
  4877. # Subject to use when sending a password reset email.
  4878. #password_reset: &quot;[%(server_name)s] Password reset&quot;
  4879. #
  4880. # Subject to use when sending a verification email to assert an address's
  4881. # ownership.
  4882. #email_validation: &quot;[%(server_name)s] Validate your email&quot;
  4883. # Password providers allow homeserver administrators to integrate
  4884. # their Synapse installation with existing authentication methods
  4885. # ex. LDAP, external tokens, etc.
  4886. #
  4887. # For more information and known implementations, please see
  4888. # https://matrix-org.github.io/synapse/latest/password_auth_providers.html
  4889. #
  4890. # Note: instances wishing to use SAML or CAS authentication should
  4891. # instead use the `saml2_config` or `cas_config` options,
  4892. # respectively.
  4893. #
  4894. password_providers:
  4895. # # Example config for an LDAP auth provider
  4896. # - module: &quot;ldap_auth_provider.LdapAuthProvider&quot;
  4897. # config:
  4898. # enabled: true
  4899. # uri: &quot;ldap://ldap.example.com:389&quot;
  4900. # start_tls: true
  4901. # base: &quot;ou=users,dc=example,dc=com&quot;
  4902. # attributes:
  4903. # uid: &quot;cn&quot;
  4904. # mail: &quot;email&quot;
  4905. # name: &quot;givenName&quot;
  4906. # #bind_dn:
  4907. # #bind_password:
  4908. # #filter: &quot;(objectClass=posixAccount)&quot;
  4909. ## Push ##
  4910. push:
  4911. # Clients requesting push notifications can either have the body of
  4912. # the message sent in the notification poke along with other details
  4913. # like the sender, or just the event ID and room ID (`event_id_only`).
  4914. # If clients choose the former, this option controls whether the
  4915. # notification request includes the content of the event (other details
  4916. # like the sender are still included). For `event_id_only` push, it
  4917. # has no effect.
  4918. #
  4919. # For modern android devices the notification content will still appear
  4920. # because it is loaded by the app. iPhone, however will send a
  4921. # notification saying only that a message arrived and who it came from.
  4922. #
  4923. # The default value is &quot;true&quot; to include message details. Uncomment to only
  4924. # include the event ID and room ID in push notification payloads.
  4925. #
  4926. #include_content: false
  4927. # When a push notification is received, an unread count is also sent.
  4928. # This number can either be calculated as the number of unread messages
  4929. # for the user, or the number of *rooms* the user has unread messages in.
  4930. #
  4931. # The default value is &quot;true&quot;, meaning push clients will see the number of
  4932. # rooms with unread messages in them. Uncomment to instead send the number
  4933. # of unread messages.
  4934. #
  4935. #group_unread_count_by_room: false
  4936. ## Rooms ##
  4937. # Controls whether locally-created rooms should be end-to-end encrypted by
  4938. # default.
  4939. #
  4940. # Possible options are &quot;all&quot;, &quot;invite&quot;, and &quot;off&quot;. They are defined as:
  4941. #
  4942. # * &quot;all&quot;: any locally-created room
  4943. # * &quot;invite&quot;: any room created with the &quot;private_chat&quot; or &quot;trusted_private_chat&quot;
  4944. # room creation presets
  4945. # * &quot;off&quot;: this option will take no effect
  4946. #
  4947. # The default value is &quot;off&quot;.
  4948. #
  4949. # Note that this option will only affect rooms created after it is set. It
  4950. # will also not affect rooms created by other servers.
  4951. #
  4952. #encryption_enabled_by_default_for_room_type: invite
  4953. # Uncomment to allow non-server-admin users to create groups on this server
  4954. #
  4955. #enable_group_creation: true
  4956. # If enabled, non server admins can only create groups with local parts
  4957. # starting with this prefix
  4958. #
  4959. #group_creation_prefix: &quot;unofficial_&quot;
  4960. # User Directory configuration
  4961. #
  4962. user_directory:
  4963. # Defines whether users can search the user directory. If false then
  4964. # empty responses are returned to all queries. Defaults to true.
  4965. #
  4966. # Uncomment to disable the user directory.
  4967. #
  4968. #enabled: false
  4969. # Defines whether to search all users visible to your HS when searching
  4970. # the user directory, rather than limiting to users visible in public
  4971. # rooms. Defaults to false.
  4972. #
  4973. # If you set it true, you'll have to rebuild the user_directory search
  4974. # indexes, see:
  4975. # https://matrix-org.github.io/synapse/latest/user_directory.html
  4976. #
  4977. # Uncomment to return search results containing all known users, even if that
  4978. # user does not share a room with the requester.
  4979. #
  4980. #search_all_users: true
  4981. # Defines whether to prefer local users in search query results.
  4982. # If True, local users are more likely to appear above remote users
  4983. # when searching the user directory. Defaults to false.
  4984. #
  4985. # Uncomment to prefer local over remote users in user directory search
  4986. # results.
  4987. #
  4988. #prefer_local_users: true
  4989. # User Consent configuration
  4990. #
  4991. # for detailed instructions, see
  4992. # https://matrix-org.github.io/synapse/latest/consent_tracking.html
  4993. #
  4994. # Parts of this section are required if enabling the 'consent' resource under
  4995. # 'listeners', in particular 'template_dir' and 'version'.
  4996. #
  4997. # 'template_dir' gives the location of the templates for the HTML forms.
  4998. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  4999. # and each language directory should contain the policy document (named as
  5000. # '&lt;version&gt;.html') and a success page (success.html).
  5001. #
  5002. # 'version' specifies the 'current' version of the policy document. It defines
  5003. # the version to be served by the consent resource if there is no 'v'
  5004. # parameter.
  5005. #
  5006. # 'server_notice_content', if enabled, will send a user a &quot;Server Notice&quot;
  5007. # asking them to consent to the privacy policy. The 'server_notices' section
  5008. # must also be configured for this to work. Notices will *not* be sent to
  5009. # guest users unless 'send_server_notice_to_guests' is set to true.
  5010. #
  5011. # 'block_events_error', if set, will block any attempts to send events
  5012. # until the user consents to the privacy policy. The value of the setting is
  5013. # used as the text of the error.
  5014. #
  5015. # 'require_at_registration', if enabled, will add a step to the registration
  5016. # process, similar to how captcha works. Users will be required to accept the
  5017. # policy before their account is created.
  5018. #
  5019. # 'policy_name' is the display name of the policy users will see when registering
  5020. # for an account. Has no effect unless `require_at_registration` is enabled.
  5021. # Defaults to &quot;Privacy Policy&quot;.
  5022. #
  5023. #user_consent:
  5024. # template_dir: res/templates/privacy
  5025. # version: 1.0
  5026. # server_notice_content:
  5027. # msgtype: m.text
  5028. # body: &gt;-
  5029. # To continue using this homeserver you must review and agree to the
  5030. # terms and conditions at %(consent_uri)s
  5031. # send_server_notice_to_guests: true
  5032. # block_events_error: &gt;-
  5033. # To continue using this homeserver you must review and agree to the
  5034. # terms and conditions at %(consent_uri)s
  5035. # require_at_registration: false
  5036. # policy_name: Privacy Policy
  5037. #
  5038. # Settings for local room and user statistics collection. See
  5039. # https://matrix-org.github.io/synapse/latest/room_and_user_statistics.html.
  5040. #
  5041. stats:
  5042. # Uncomment the following to disable room and user statistics. Note that doing
  5043. # so may cause certain features (such as the room directory) not to work
  5044. # correctly.
  5045. #
  5046. #enabled: false
  5047. # Server Notices room configuration
  5048. #
  5049. # Uncomment this section to enable a room which can be used to send notices
  5050. # from the server to users. It is a special room which cannot be left; notices
  5051. # come from a special &quot;notices&quot; user id.
  5052. #
  5053. # If you uncomment this section, you *must* define the system_mxid_localpart
  5054. # setting, which defines the id of the user which will be used to send the
  5055. # notices.
  5056. #
  5057. # It's also possible to override the room name, the display name of the
  5058. # &quot;notices&quot; user, and the avatar for the user.
  5059. #
  5060. #server_notices:
  5061. # system_mxid_localpart: notices
  5062. # system_mxid_display_name: &quot;Server Notices&quot;
  5063. # system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  5064. # room_name: &quot;Server Notices&quot;
  5065. # Uncomment to disable searching the public room list. When disabled
  5066. # blocks searching local and remote room lists for local and remote
  5067. # users by always returning an empty list for all queries.
  5068. #
  5069. #enable_room_list_search: false
  5070. # The `alias_creation` option controls who's allowed to create aliases
  5071. # on this server.
  5072. #
  5073. # The format of this option is a list of rules that contain globs that
  5074. # match against user_id, room_id and the new alias (fully qualified with
  5075. # server name). The action in the first rule that matches is taken,
  5076. # which can currently either be &quot;allow&quot; or &quot;deny&quot;.
  5077. #
  5078. # Missing user_id/room_id/alias fields default to &quot;*&quot;.
  5079. #
  5080. # If no rules match the request is denied. An empty list means no one
  5081. # can create aliases.
  5082. #
  5083. # Options for the rules include:
  5084. #
  5085. # user_id: Matches against the creator of the alias
  5086. # alias: Matches against the alias being created
  5087. # room_id: Matches against the room ID the alias is being pointed at
  5088. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5089. #
  5090. # The default is:
  5091. #
  5092. #alias_creation_rules:
  5093. # - user_id: &quot;*&quot;
  5094. # alias: &quot;*&quot;
  5095. # room_id: &quot;*&quot;
  5096. # action: allow
  5097. # The `room_list_publication_rules` option controls who can publish and
  5098. # which rooms can be published in the public room list.
  5099. #
  5100. # The format of this option is the same as that for
  5101. # `alias_creation_rules`.
  5102. #
  5103. # If the room has one or more aliases associated with it, only one of
  5104. # the aliases needs to match the alias rule. If there are no aliases
  5105. # then only rules with `alias: *` match.
  5106. #
  5107. # If no rules match the request is denied. An empty list means no one
  5108. # can publish rooms.
  5109. #
  5110. # Options for the rules include:
  5111. #
  5112. # user_id: Matches against the creator of the alias
  5113. # room_id: Matches against the room ID being published
  5114. # alias: Matches against any current local or canonical aliases
  5115. # associated with the room
  5116. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5117. #
  5118. # The default is:
  5119. #
  5120. #room_list_publication_rules:
  5121. # - user_id: &quot;*&quot;
  5122. # alias: &quot;*&quot;
  5123. # room_id: &quot;*&quot;
  5124. # action: allow
  5125. ## Opentracing ##
  5126. # These settings enable opentracing, which implements distributed tracing.
  5127. # This allows you to observe the causal chains of events across servers
  5128. # including requests, key lookups etc., across any server running
  5129. # synapse or any other other services which supports opentracing
  5130. # (specifically those implemented with Jaeger).
  5131. #
  5132. opentracing:
  5133. # tracing is disabled by default. Uncomment the following line to enable it.
  5134. #
  5135. #enabled: true
  5136. # The list of homeservers we wish to send and receive span contexts and span baggage.
  5137. # See https://matrix-org.github.io/synapse/latest/opentracing.html.
  5138. #
  5139. # This is a list of regexes which are matched against the server_name of the
  5140. # homeserver.
  5141. #
  5142. # By default, it is empty, so no servers are matched.
  5143. #
  5144. #homeserver_whitelist:
  5145. # - &quot;.*&quot;
  5146. # A list of the matrix IDs of users whose requests will always be traced,
  5147. # even if the tracing system would otherwise drop the traces due to
  5148. # probabilistic sampling.
  5149. #
  5150. # By default, the list is empty.
  5151. #
  5152. #force_tracing_for_users:
  5153. # - &quot;@user1:server_name&quot;
  5154. # - &quot;@user2:server_name&quot;
  5155. # Jaeger can be configured to sample traces at different rates.
  5156. # All configuration options provided by Jaeger can be set here.
  5157. # Jaeger's configuration is mostly related to trace sampling which
  5158. # is documented here:
  5159. # https://www.jaegertracing.io/docs/latest/sampling/.
  5160. #
  5161. #jaeger_config:
  5162. # sampler:
  5163. # type: const
  5164. # param: 1
  5165. # logging:
  5166. # false
  5167. ## Workers ##
  5168. # Disables sending of outbound federation transactions on the main process.
  5169. # Uncomment if using a federation sender worker.
  5170. #
  5171. #send_federation: false
  5172. # It is possible to run multiple federation sender workers, in which case the
  5173. # work is balanced across them.
  5174. #
  5175. # This configuration must be shared between all federation sender workers, and if
  5176. # changed all federation sender workers must be stopped at the same time and then
  5177. # started, to ensure that all instances are running with the same config (otherwise
  5178. # events may be dropped).
  5179. #
  5180. #federation_sender_instances:
  5181. # - federation_sender1
  5182. # When using workers this should be a map from `worker_name` to the
  5183. # HTTP replication listener of the worker, if configured.
  5184. #
  5185. #instance_map:
  5186. # worker1:
  5187. # host: localhost
  5188. # port: 8034
  5189. # Experimental: When using workers you can define which workers should
  5190. # handle event persistence and typing notifications. Any worker
  5191. # specified here must also be in the `instance_map`.
  5192. #
  5193. #stream_writers:
  5194. # events: worker1
  5195. # typing: worker1
  5196. # The worker that is used to run background tasks (e.g. cleaning up expired
  5197. # data). If not provided this defaults to the main process.
  5198. #
  5199. #run_background_tasks_on: worker1
  5200. # A shared secret used by the replication APIs to authenticate HTTP requests
  5201. # from workers.
  5202. #
  5203. # By default this is unused and traffic is not authenticated.
  5204. #
  5205. #worker_replication_secret: &quot;&quot;
  5206. # Configuration for Redis when using workers. This *must* be enabled when
  5207. # using workers (unless using old style direct TCP configuration).
  5208. #
  5209. redis:
  5210. # Uncomment the below to enable Redis support.
  5211. #
  5212. #enabled: true
  5213. # Optional host and port to use to connect to redis. Defaults to
  5214. # localhost and 6379
  5215. #
  5216. #host: localhost
  5217. #port: 6379
  5218. # Optional password if configured on the Redis instance
  5219. #
  5220. #password: &lt;secret_password&gt;
  5221. </code></pre>
  5222. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="logging-sample-configuration-file"><a class="header" href="#logging-sample-configuration-file">Logging Sample Configuration File</a></h1>
  5223. <p>Below is a sample logging configuration file. This file can be tweaked to control how your
  5224. homeserver will output logs. A restart of the server is generally required to apply any
  5225. changes made to this file.</p>
  5226. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  5227. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  5228. a fresh config using Synapse by following the instructions in
  5229. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  5230. <pre><code class="language-yaml"># Log configuration for Synapse.
  5231. #
  5232. # This is a YAML file containing a standard Python logging configuration
  5233. # dictionary. See [1] for details on the valid settings.
  5234. #
  5235. # Synapse also supports structured logging for machine readable logs which can
  5236. # be ingested by ELK stacks. See [2] for details.
  5237. #
  5238. # [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  5239. # [2]: https://matrix-org.github.io/synapse/latest/structured_logging.html
  5240. version: 1
  5241. formatters:
  5242. precise:
  5243. format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
  5244. handlers:
  5245. file:
  5246. class: logging.handlers.TimedRotatingFileHandler
  5247. formatter: precise
  5248. filename: /var/log/matrix-synapse/homeserver.log
  5249. when: midnight
  5250. backupCount: 3 # Does not include the current log file.
  5251. encoding: utf8
  5252. # Default to buffering writes to log file for efficiency.
  5253. # WARNING/ERROR logs will still be flushed immediately, but there will be a
  5254. # delay (of up to `period` seconds, or until the buffer is full with
  5255. # `capacity` messages) before INFO/DEBUG logs get written.
  5256. buffer:
  5257. class: synapse.logging.handlers.PeriodicallyFlushingMemoryHandler
  5258. target: file
  5259. # The capacity is the maximum number of log lines that are buffered
  5260. # before being written to disk. Increasing this will lead to better
  5261. # performance, at the expensive of it taking longer for log lines to
  5262. # be written to disk.
  5263. # This parameter is required.
  5264. capacity: 10
  5265. # Logs with a level at or above the flush level will cause the buffer to
  5266. # be flushed immediately.
  5267. # Default value: 40 (ERROR)
  5268. # Other values: 50 (CRITICAL), 30 (WARNING), 20 (INFO), 10 (DEBUG)
  5269. flushLevel: 30 # Flush immediately for WARNING logs and higher
  5270. # The period of time, in seconds, between forced flushes.
  5271. # Messages will not be delayed for longer than this time.
  5272. # Default value: 5 seconds
  5273. period: 5
  5274. # A handler that writes logs to stderr. Unused by default, but can be used
  5275. # instead of &quot;buffer&quot; and &quot;file&quot; in the logger handlers.
  5276. console:
  5277. class: logging.StreamHandler
  5278. formatter: precise
  5279. loggers:
  5280. synapse.storage.SQL:
  5281. # beware: increasing this to DEBUG will make synapse log sensitive
  5282. # information such as access tokens.
  5283. level: INFO
  5284. twisted:
  5285. # We send the twisted logging directly to the file handler,
  5286. # to work around https://github.com/matrix-org/synapse/issues/3471
  5287. # when using &quot;buffer&quot; logger. Use &quot;console&quot; to log to stderr instead.
  5288. handlers: [file]
  5289. propagate: false
  5290. root:
  5291. level: INFO
  5292. # Write logs to the `buffer` handler, which will buffer them together in memory,
  5293. # then write them to a file.
  5294. #
  5295. # Replace &quot;buffer&quot; with &quot;console&quot; to log to stderr instead. (Note that you'll
  5296. # also need to update the configuration for the `twisted` logger above, in
  5297. # this case.)
  5298. #
  5299. handlers: [buffer]
  5300. disable_existing_loggers: false
  5301. </code></pre>
  5302. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="structured-logging"><a class="header" href="#structured-logging">Structured Logging</a></h1>
  5303. <p>A structured logging system can be useful when your logs are destined for a
  5304. machine to parse and process. By maintaining its machine-readable characteristics,
  5305. it enables more efficient searching and aggregations when consumed by software
  5306. such as the &quot;ELK stack&quot;.</p>
  5307. <p>Synapse's structured logging system is configured via the file that Synapse's
  5308. <code>log_config</code> config option points to. The file should include a formatter which
  5309. uses the <code>synapse.logging.TerseJsonFormatter</code> class included with Synapse and a
  5310. handler which uses the above formatter.</p>
  5311. <p>There is also a <code>synapse.logging.JsonFormatter</code> option which does not include
  5312. a timestamp in the resulting JSON. This is useful if the log ingester adds its
  5313. own timestamp.</p>
  5314. <p>A structured logging configuration looks similar to the following:</p>
  5315. <pre><code class="language-yaml">version: 1
  5316. formatters:
  5317. structured:
  5318. class: synapse.logging.TerseJsonFormatter
  5319. handlers:
  5320. file:
  5321. class: logging.handlers.TimedRotatingFileHandler
  5322. formatter: structured
  5323. filename: /path/to/my/logs/homeserver.log
  5324. when: midnight
  5325. backupCount: 3 # Does not include the current log file.
  5326. encoding: utf8
  5327. loggers:
  5328. synapse:
  5329. level: INFO
  5330. handlers: [remote]
  5331. synapse.storage.SQL:
  5332. level: WARNING
  5333. </code></pre>
  5334. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5335. with the SQL layer at 'WARNING', and will log to a file, stored as JSON.</p>
  5336. <p>It is also possible to figure Synapse to log to a remote endpoint by using the
  5337. <code>synapse.logging.RemoteHandler</code> class included with Synapse. It takes the
  5338. following arguments:</p>
  5339. <ul>
  5340. <li><code>host</code>: Hostname or IP address of the log aggregator.</li>
  5341. <li><code>port</code>: Numerical port to contact on the host.</li>
  5342. <li><code>maximum_buffer</code>: (Optional, defaults to 1000) The maximum buffer size to allow.</li>
  5343. </ul>
  5344. <p>A remote structured logging configuration looks similar to the following:</p>
  5345. <pre><code class="language-yaml">version: 1
  5346. formatters:
  5347. structured:
  5348. class: synapse.logging.TerseJsonFormatter
  5349. handlers:
  5350. remote:
  5351. class: synapse.logging.RemoteHandler
  5352. formatter: structured
  5353. host: 10.1.2.3
  5354. port: 9999
  5355. loggers:
  5356. synapse:
  5357. level: INFO
  5358. handlers: [remote]
  5359. synapse.storage.SQL:
  5360. level: WARNING
  5361. </code></pre>
  5362. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5363. with the SQL layer at 'WARNING', and will log JSON formatted messages to a
  5364. remote endpoint at 10.1.2.3:9999.</p>
  5365. <h2 id="upgrading-from-legacy-structured-logging-configuration"><a class="header" href="#upgrading-from-legacy-structured-logging-configuration">Upgrading from legacy structured logging configuration</a></h2>
  5366. <p>Versions of Synapse prior to v1.23.0 included a custom structured logging
  5367. configuration which is deprecated. It used a <code>structured: true</code> flag and
  5368. configured <code>drains</code> instead of <code>handlers</code> and <code>formatters</code>.</p>
  5369. <p>Synapse currently automatically converts the old configuration to the new
  5370. configuration, but this will be removed in a future version of Synapse. The
  5371. following reference can be used to update your configuration. Based on the drain
  5372. <code>type</code>, we can pick a new handler:</p>
  5373. <ol>
  5374. <li>For a type of <code>console</code>, <code>console_json</code>, or <code>console_json_terse</code>: a handler
  5375. with a class of <code>logging.StreamHandler</code> and a <code>stream</code> of <code>ext://sys.stdout</code>
  5376. or <code>ext://sys.stderr</code> should be used.</li>
  5377. <li>For a type of <code>file</code> or <code>file_json</code>: a handler of <code>logging.FileHandler</code> with
  5378. a location of the file path should be used.</li>
  5379. <li>For a type of <code>network_json_terse</code>: a handler of <code>synapse.logging.RemoteHandler</code>
  5380. with the host and port should be used.</li>
  5381. </ol>
  5382. <p>Then based on the drain <code>type</code> we can pick a new formatter:</p>
  5383. <ol>
  5384. <li>For a type of <code>console</code> or <code>file</code> no formatter is necessary.</li>
  5385. <li>For a type of <code>console_json</code> or <code>file_json</code>: a formatter of
  5386. <code>synapse.logging.JsonFormatter</code> should be used.</li>
  5387. <li>For a type of <code>console_json_terse</code> or <code>network_json_terse</code>: a formatter of
  5388. <code>synapse.logging.TerseJsonFormatter</code> should be used.</li>
  5389. </ol>
  5390. <p>For each new handler and formatter they should be added to the logging configuration
  5391. and then assigned to either a logger or the root logger.</p>
  5392. <p>An example legacy configuration:</p>
  5393. <pre><code class="language-yaml">structured: true
  5394. loggers:
  5395. synapse:
  5396. level: INFO
  5397. synapse.storage.SQL:
  5398. level: WARNING
  5399. drains:
  5400. console:
  5401. type: console
  5402. location: stdout
  5403. file:
  5404. type: file_json
  5405. location: homeserver.log
  5406. </code></pre>
  5407. <p>Would be converted into a new configuration:</p>
  5408. <pre><code class="language-yaml">version: 1
  5409. formatters:
  5410. json:
  5411. class: synapse.logging.JsonFormatter
  5412. handlers:
  5413. console:
  5414. class: logging.StreamHandler
  5415. location: ext://sys.stdout
  5416. file:
  5417. class: logging.FileHandler
  5418. formatter: json
  5419. filename: homeserver.log
  5420. loggers:
  5421. synapse:
  5422. level: INFO
  5423. handlers: [console, file]
  5424. synapse.storage.SQL:
  5425. level: WARNING
  5426. </code></pre>
  5427. <p>The new logging configuration is a bit more verbose, but significantly more
  5428. flexible. It allows for configuration that were not previously possible, such as
  5429. sending plain logs over the network, or using different handlers for different
  5430. modules.</p>
  5431. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="templates"><a class="header" href="#templates">Templates</a></h1>
  5432. <p>Synapse uses parametrised templates to generate the content of emails it sends and
  5433. webpages it shows to users.</p>
  5434. <p>By default, Synapse will use the templates listed <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">here</a>.
  5435. Server admins can configure an additional directory for Synapse to look for templates
  5436. in, allowing them to specify custom templates:</p>
  5437. <pre><code class="language-yaml">templates:
  5438. custom_templates_directory: /path/to/custom/templates/
  5439. </code></pre>
  5440. <p>If this setting is not set, or the files named below are not found within the directory,
  5441. default templates from within the Synapse package will be used.</p>
  5442. <p>Templates that are given variables when being rendered are rendered using <a href="https://jinja.palletsprojects.com/en/2.11.x/">Jinja 2</a>.
  5443. Templates rendered by Jinja 2 can also access two functions on top of the functions
  5444. already available as part of Jinja 2:</p>
  5445. <pre><code class="language-python">format_ts(value: int, format: str) -&gt; str
  5446. </code></pre>
  5447. <p>Formats a timestamp in milliseconds.</p>
  5448. <p>Example: <code>reason.last_sent_ts|format_ts(&quot;%c&quot;)</code></p>
  5449. <pre><code class="language-python">mxc_to_http(value: str, width: int, height: int, resize_method: str = &quot;crop&quot;) -&gt; str
  5450. </code></pre>
  5451. <p>Turns a <code>mxc://</code> URL for media content into an HTTP(S) one using the homeserver's
  5452. <code>public_baseurl</code> configuration setting as the URL's base.</p>
  5453. <p>Example: <code>message.sender_avatar_url|mxc_to_http(32,32)</code></p>
  5454. <h2 id="email-templates"><a class="header" href="#email-templates">Email templates</a></h2>
  5455. <p>Below are the templates Synapse will look for when generating the content of an email:</p>
  5456. <ul>
  5457. <li><code>notif_mail.html</code> and <code>notif_mail.txt</code>: The contents of email notifications of missed
  5458. events.
  5459. When rendering, this template is given the following variables:
  5460. <ul>
  5461. <li><code>user_display_name</code>: the display name for the user receiving the notification</li>
  5462. <li><code>unsubscribe_link</code>: the link users can click to unsubscribe from email notifications</li>
  5463. <li><code>summary_text</code>: a summary of the notification(s). The text used can be customised
  5464. by configuring the various settings in the <code>email.subjects</code> section of the
  5465. configuration file.</li>
  5466. <li><code>rooms</code>: a list of rooms containing events to include in the email. Each element is
  5467. an object with the following attributes:
  5468. <ul>
  5469. <li><code>title</code>: a human-readable name for the room</li>
  5470. <li><code>hash</code>: a hash of the ID of the room</li>
  5471. <li><code>invite</code>: a boolean, which is <code>True</code> if the room is an invite the user hasn't
  5472. accepted yet, <code>False</code> otherwise</li>
  5473. <li><code>notifs</code>: a list of events, or an empty list if <code>invite</code> is <code>True</code>. Each element
  5474. is an object with the following attributes:
  5475. <ul>
  5476. <li><code>link</code>: a <code>matrix.to</code> link to the event</li>
  5477. <li><code>ts</code>: the time in milliseconds at which the event was received</li>
  5478. <li><code>messages</code>: a list of messages containing one message before the event, the
  5479. message in the event, and one message after the event. Each element is an
  5480. object with the following attributes:
  5481. <ul>
  5482. <li><code>event_type</code>: the type of the event</li>
  5483. <li><code>is_historical</code>: a boolean, which is <code>False</code> if the message is the one
  5484. that triggered the notification, <code>True</code> otherwise</li>
  5485. <li><code>id</code>: the ID of the event</li>
  5486. <li><code>ts</code>: the time in milliseconds at which the event was sent</li>
  5487. <li><code>sender_name</code>: the display name for the event's sender</li>
  5488. <li><code>sender_avatar_url</code>: the avatar URL (as a <code>mxc://</code> URL) for the event's
  5489. sender</li>
  5490. <li><code>sender_hash</code>: a hash of the user ID of the sender</li>
  5491. </ul>
  5492. </li>
  5493. </ul>
  5494. </li>
  5495. <li><code>link</code>: a <code>matrix.to</code> link to the room</li>
  5496. </ul>
  5497. </li>
  5498. <li><code>reason</code>: information on the event that triggered the email to be sent. It's an
  5499. object with the following attributes:
  5500. <ul>
  5501. <li><code>room_id</code>: the ID of the room the event was sent in</li>
  5502. <li><code>room_name</code>: a human-readable name for the room the event was sent in</li>
  5503. <li><code>now</code>: the current time in milliseconds</li>
  5504. <li><code>received_at</code>: the time in milliseconds at which the event was received</li>
  5505. <li><code>delay_before_mail_ms</code>: the amount of time in milliseconds Synapse always waits
  5506. before ever emailing about a notification (to give the user a chance to respond
  5507. to other push or notice the window)</li>
  5508. <li><code>last_sent_ts</code>: the time in milliseconds at which a notification was last sent
  5509. for an event in this room</li>
  5510. <li><code>throttle_ms</code>: the minimum amount of time in milliseconds between two
  5511. notifications can be sent for this room</li>
  5512. </ul>
  5513. </li>
  5514. </ul>
  5515. </li>
  5516. <li><code>password_reset.html</code> and <code>password_reset.txt</code>: The contents of password reset emails
  5517. sent by the homeserver.
  5518. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5519. user must click in order to reset their password.</li>
  5520. <li><code>registration.html</code> and <code>registration.txt</code>: The contents of address verification emails
  5521. sent during registration.
  5522. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5523. user must click in order to validate their email address.</li>
  5524. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code>: The contents of address verification emails
  5525. sent when an address is added to a Matrix account.
  5526. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5527. user must click in order to validate their email address.</li>
  5528. </ul>
  5529. <h2 id="html-page-templates-for-registration-and-password-reset"><a class="header" href="#html-page-templates-for-registration-and-password-reset">HTML page templates for registration and password reset</a></h2>
  5530. <p>Below are the templates Synapse will look for when generating pages related to
  5531. registration and password reset:</p>
  5532. <ul>
  5533. <li><code>password_reset_confirmation.html</code>: An HTML page that a user will see when they follow
  5534. the link in the password reset email. The user will be asked to confirm the action
  5535. before their password is reset.
  5536. When rendering, this template is given the following variables:
  5537. <ul>
  5538. <li><code>sid</code>: the session ID for the password reset</li>
  5539. <li><code>token</code>: the token for the password reset</li>
  5540. <li><code>client_secret</code>: the client secret for the password reset</li>
  5541. </ul>
  5542. </li>
  5543. <li><code>password_reset_success.html</code> and <code>password_reset_failure.html</code>: HTML pages for success
  5544. and failure that a user will see when they confirm the password reset flow using the
  5545. page above.
  5546. When rendering, <code>password_reset_success.html</code> is given no variable, and
  5547. <code>password_reset_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5548. for the password reset failure. </li>
  5549. <li><code>registration_success.html</code> and <code>registration_failure.html</code>: HTML pages for success and
  5550. failure that a user will see when they follow the link in an address verification email
  5551. sent during registration.
  5552. When rendering, <code>registration_success.html</code> is given no variable, and
  5553. <code>registration_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5554. for the registration failure.</li>
  5555. <li><code>add_threepid_success.html</code> and <code>add_threepid_failure.html</code>: HTML pages for success and
  5556. failure that a user will see when they follow the link in an address verification email
  5557. sent when an address is added to a Matrix account.
  5558. When rendering, <code>add_threepid_success.html</code> is given no variable, and
  5559. <code>add_threepid_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5560. for the registration failure.</li>
  5561. </ul>
  5562. <h2 id="html-page-templates-for-single-sign-on-sso"><a class="header" href="#html-page-templates-for-single-sign-on-sso">HTML page templates for Single Sign-On (SSO)</a></h2>
  5563. <p>Below are the templates Synapse will look for when generating pages related to SSO:</p>
  5564. <ul>
  5565. <li><code>sso_login_idp_picker.html</code>: HTML page to prompt the user to choose an
  5566. Identity Provider during login.
  5567. This is only used if multiple SSO Identity Providers are configured.
  5568. When rendering, this template is given the following variables:
  5569. <ul>
  5570. <li><code>redirect_url</code>: the URL that the user will be redirected to after
  5571. login.</li>
  5572. <li><code>server_name</code>: the homeserver's name.</li>
  5573. <li><code>providers</code>: a list of available Identity Providers. Each element is
  5574. an object with the following attributes:
  5575. <ul>
  5576. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5577. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5578. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5579. for the IdP</li>
  5580. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5581. for the brand of the IdP
  5582. The rendered HTML page should contain a form which submits its results
  5583. back as a GET request, with the following query parameters:</li>
  5584. </ul>
  5585. </li>
  5586. <li><code>redirectUrl</code>: the client redirect URI (ie, the <code>redirect_url</code> passed
  5587. to the template)</li>
  5588. <li><code>idp</code>: the 'idp_id' of the chosen IDP.</li>
  5589. </ul>
  5590. </li>
  5591. <li><code>sso_auth_account_details.html</code>: HTML page to prompt new users to enter a
  5592. userid and confirm other details. This is only shown if the
  5593. SSO implementation (with any <code>user_mapping_provider</code>) does not return
  5594. a localpart.
  5595. When rendering, this template is given the following variables:
  5596. <ul>
  5597. <li><code>server_name</code>: the homeserver's name.</li>
  5598. <li><code>idp</code>: details of the SSO Identity Provider that the user logged in
  5599. with: an object with the following attributes:
  5600. <ul>
  5601. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5602. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5603. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5604. for the IdP</li>
  5605. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5606. for the brand of the IdP</li>
  5607. </ul>
  5608. </li>
  5609. <li><code>user_attributes</code>: an object containing details about the user that
  5610. we received from the IdP. May have the following attributes:
  5611. <ul>
  5612. <li>display_name: the user's display_name</li>
  5613. <li>emails: a list of email addresses
  5614. The template should render a form which submits the following fields:</li>
  5615. </ul>
  5616. </li>
  5617. <li><code>username</code>: the localpart of the user's chosen user id</li>
  5618. </ul>
  5619. </li>
  5620. <li><code>sso_new_user_consent.html</code>: HTML page allowing the user to consent to the
  5621. server's terms and conditions. This is only shown for new users, and only if
  5622. <code>user_consent.require_at_registration</code> is set.
  5623. When rendering, this template is given the following variables:
  5624. <ul>
  5625. <li><code>server_name</code>: the homeserver's name.</li>
  5626. <li><code>user_id</code>: the user's matrix proposed ID.</li>
  5627. <li><code>user_profile.display_name</code>: the user's proposed display name, if any.</li>
  5628. <li>consent_version: the version of the terms that the user will be
  5629. shown</li>
  5630. <li><code>terms_url</code>: a link to the page showing the terms.
  5631. The template should render a form which submits the following fields:</li>
  5632. <li><code>accepted_version</code>: the version of the terms accepted by the user
  5633. (ie, 'consent_version' from the input variables).</li>
  5634. </ul>
  5635. </li>
  5636. <li><code>sso_redirect_confirm.html</code>: HTML page for a confirmation step before redirecting back
  5637. to the client with the login token.
  5638. When rendering, this template is given the following variables:
  5639. <ul>
  5640. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5641. <li><code>display_url</code>: the same as <code>redirect_url</code>, but with the query
  5642. parameters stripped. The intention is to have a
  5643. human-readable URL to show to users, not to use it as
  5644. the final address to redirect to.</li>
  5645. <li><code>server_name</code>: the homeserver's name.</li>
  5646. <li><code>new_user</code>: a boolean indicating whether this is the user's first time
  5647. logging in.</li>
  5648. <li><code>user_id</code>: the user's matrix ID.</li>
  5649. <li><code>user_profile.avatar_url</code>: an MXC URI for the user's avatar, if any.
  5650. <code>None</code> if the user has not set an avatar.</li>
  5651. <li><code>user_profile.display_name</code>: the user's display name. <code>None</code> if the user
  5652. has not set a display name.</li>
  5653. </ul>
  5654. </li>
  5655. <li><code>sso_auth_confirm.html</code>: HTML page which notifies the user that they are authenticating
  5656. to confirm an operation on their account during the user interactive authentication
  5657. process.
  5658. When rendering, this template is given the following variables:
  5659. <ul>
  5660. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5661. <li><code>description</code>: the operation which the user is being asked to confirm</li>
  5662. <li><code>idp</code>: details of the Identity Provider that we will use to confirm
  5663. the user's identity: an object with the following attributes:
  5664. <ul>
  5665. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5666. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5667. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5668. for the IdP</li>
  5669. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5670. for the brand of the IdP</li>
  5671. </ul>
  5672. </li>
  5673. </ul>
  5674. </li>
  5675. <li><code>sso_auth_success.html</code>: HTML page shown after a successful user interactive
  5676. authentication session.
  5677. Note that this page must include the JavaScript which notifies of a successful
  5678. authentication (see https://matrix.org/docs/spec/client_server/r0.6.0#fallback).
  5679. This template has no additional variables.</li>
  5680. <li><code>sso_auth_bad_user.html</code>: HTML page shown after a user-interactive authentication
  5681. session which does not map correctly onto the expected user.
  5682. When rendering, this template is given the following variables:
  5683. <ul>
  5684. <li><code>server_name</code>: the homeserver's name.</li>
  5685. <li><code>user_id_to_verify</code>: the MXID of the user that we are trying to
  5686. validate.</li>
  5687. </ul>
  5688. </li>
  5689. <li><code>sso_account_deactivated.html</code>: HTML page shown during single sign-on if a deactivated
  5690. user (according to Synapse's database) attempts to login.
  5691. This template has no additional variables.</li>
  5692. <li><code>sso_error.html</code>: HTML page to display to users if something goes wrong during the
  5693. OpenID Connect authentication process.
  5694. When rendering, this template is given two variables:
  5695. <ul>
  5696. <li><code>error</code>: the technical name of the error</li>
  5697. <li><code>error_description</code>: a human-readable message for the error</li>
  5698. </ul>
  5699. </li>
  5700. </ul>
  5701. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="user-authentication"><a class="header" href="#user-authentication">User Authentication</a></h1>
  5702. <p>Synapse supports multiple methods of authenticating users, either out-of-the-box or through custom pluggable
  5703. authentication modules.</p>
  5704. <p>Included in Synapse is support for authenticating users via:</p>
  5705. <ul>
  5706. <li>A username and password.</li>
  5707. <li>An email address and password.</li>
  5708. <li>Single Sign-On through the SAML, Open ID Connect or CAS protocols.</li>
  5709. <li>JSON Web Tokens.</li>
  5710. <li>An administrator's shared secret.</li>
  5711. </ul>
  5712. <p>Synapse can additionally be extended to support custom authentication schemes through optional &quot;password auth provider&quot;
  5713. modules.</p>
  5714. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="configuring-synapse-to-authenticate-against-an-openid-connect-provider"><a class="header" href="#configuring-synapse-to-authenticate-against-an-openid-connect-provider">Configuring Synapse to authenticate against an OpenID Connect provider</a></h1>
  5715. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  5716. authentication, instead of its own local password database.</p>
  5717. <p>Any OP should work with Synapse, as long as it supports the authorization code
  5718. flow. There are a few options for that:</p>
  5719. <ul>
  5720. <li>
  5721. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  5722. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  5723. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  5724. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  5725. environment variable set to the path of the CA.</p>
  5726. </li>
  5727. <li>
  5728. <p>set up a SaaS OP, like <a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a>, <a href="https://auth0.com/">Auth0</a> or
  5729. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  5730. </li>
  5731. </ul>
  5732. <p>It may also be possible to use other OAuth2 providers which provide the
  5733. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  5734. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  5735. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  5736. <p>The OpenID integration in Synapse uses the
  5737. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  5738. as follows:</p>
  5739. <ul>
  5740. <li>
  5741. <p>The relevant libraries are included in the Docker images and Debian packages
  5742. provided by <code>matrix.org</code> so no further action is needed.</p>
  5743. </li>
  5744. <li>
  5745. <p>If you installed Synapse into a virtualenv, run <code>/path/to/env/bin/pip install matrix-synapse[oidc]</code> to install the necessary dependencies.</p>
  5746. </li>
  5747. <li>
  5748. <p>For other installation mechanisms, see the documentation provided by the
  5749. maintainer.</p>
  5750. </li>
  5751. </ul>
  5752. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  5753. setting in your configuration file (or uncomment one of the existing examples).
  5754. See <a href="./sample_config.yaml">sample_config.yaml</a> for some sample settings, as well as
  5755. the text below for example configurations for specific providers.</p>
  5756. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  5757. <p>Here are a few configs for providers that should work with Synapse.</p>
  5758. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  5759. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  5760. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  5761. application should point to your matrix server:
  5762. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5763. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  5764. Directory (tenant) ID as it will be used in the Azure links.
  5765. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  5766. <pre><code class="language-yaml">oidc_providers:
  5767. - idp_id: microsoft
  5768. idp_name: Microsoft
  5769. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  5770. client_id: &quot;&lt;client id&gt;&quot;
  5771. client_secret: &quot;&lt;client secret&gt;&quot;
  5772. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5773. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  5774. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  5775. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  5776. user_mapping_provider:
  5777. config:
  5778. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  5779. display_name_template: &quot;{{ user.name }}&quot;
  5780. </code></pre>
  5781. <h3 id="a-hrefhttpsgithubcomdexidpdexdexa"><a class="header" href="#a-hrefhttpsgithubcomdexidpdexdexa"><a href="https://github.com/dexidp/dex">Dex</a></a></h3>
  5782. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source, certified OpenID Connect Provider.
  5783. Although it is designed to help building a full-blown provider with an
  5784. external database, it can be configured with static passwords in a config file.</p>
  5785. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  5786. to install Dex.</p>
  5787. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  5788. <pre><code class="language-yaml">staticClients:
  5789. - id: synapse
  5790. secret: secret
  5791. redirectURIs:
  5792. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  5793. name: 'Synapse'
  5794. </code></pre>
  5795. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  5796. <p>Synapse config:</p>
  5797. <pre><code class="language-yaml">oidc_providers:
  5798. - idp_id: dex
  5799. idp_name: &quot;My Dex server&quot;
  5800. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  5801. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  5802. client_id: &quot;synapse&quot;
  5803. client_secret: &quot;secret&quot;
  5804. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5805. user_mapping_provider:
  5806. config:
  5807. localpart_template: &quot;{{ user.name }}&quot;
  5808. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  5809. </code></pre>
  5810. <h3 id="a-hrefhttpswwwkeycloakorgdocslatestserver_adminsso-protocolskeycloaka"><a class="header" href="#a-hrefhttpswwwkeycloakorgdocslatestserver_adminsso-protocolskeycloaka"><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a></a></h3>
  5811. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  5812. <p>Follow the <a href="https://www.keycloak.org/getting-started">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  5813. <ol>
  5814. <li>
  5815. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  5816. </li>
  5817. <li>
  5818. <p>Fill in the fields as below:</p>
  5819. </li>
  5820. </ol>
  5821. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5822. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5823. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5824. </tbody></table>
  5825. <ol start="3">
  5826. <li>Click <code>Save</code></li>
  5827. <li>Fill in the fields as below:</li>
  5828. </ol>
  5829. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5830. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5831. <tr><td>Enabled</td><td><code>On</code></td></tr>
  5832. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5833. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  5834. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  5835. </tbody></table>
  5836. <ol start="5">
  5837. <li>Click <code>Save</code></li>
  5838. <li>On the Credentials tab, update the fields:</li>
  5839. </ol>
  5840. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5841. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  5842. </tbody></table>
  5843. <ol start="7">
  5844. <li>Click <code>Regenerate Secret</code></li>
  5845. <li>Copy Secret</li>
  5846. </ol>
  5847. <pre><code class="language-yaml">oidc_providers:
  5848. - idp_id: keycloak
  5849. idp_name: &quot;My KeyCloak server&quot;
  5850. issuer: &quot;https://127.0.0.1:8443/auth/realms/{realm_name}&quot;
  5851. client_id: &quot;synapse&quot;
  5852. client_secret: &quot;copy secret generated from above&quot;
  5853. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5854. user_mapping_provider:
  5855. config:
  5856. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5857. display_name_template: &quot;{{ user.name }}&quot;
  5858. </code></pre>
  5859. <h3 id="a-hrefhttpsauth0comauth0a"><a class="header" href="#a-hrefhttpsauth0comauth0a"><a href="https://auth0.com/">Auth0</a></a></h3>
  5860. <ol>
  5861. <li>
  5862. <p>Create a regular web application for Synapse</p>
  5863. </li>
  5864. <li>
  5865. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5866. </li>
  5867. <li>
  5868. <p>Add a rule to add the <code>preferred_username</code> claim.</p>
  5869. <details>
  5870. <summary>Code sample</summary>
  5871. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  5872. user.user_metadata = user.user_metadata || {};
  5873. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  5874. context.idToken.preferred_username = user.user_metadata.preferred_username;
  5875. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  5876. .then(function(){
  5877. callback(null, user, context);
  5878. })
  5879. .catch(function(err){
  5880. callback(err);
  5881. });
  5882. }
  5883. </code></pre>
  5884. </li>
  5885. </ol>
  5886. </details>
  5887. <p>Synapse config:</p>
  5888. <pre><code class="language-yaml">oidc_providers:
  5889. - idp_id: auth0
  5890. idp_name: Auth0
  5891. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  5892. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5893. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5894. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5895. user_mapping_provider:
  5896. config:
  5897. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5898. display_name_template: &quot;{{ user.name }}&quot;
  5899. </code></pre>
  5900. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  5901. <p>GitHub is a bit special as it is not an OpenID Connect compliant provider, but
  5902. just a regular OAuth2 provider.</p>
  5903. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  5904. can be used to retrieve information on the authenticated user. As the Synapse
  5905. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5906. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5907. <ol>
  5908. <li>Create a new OAuth application: https://github.com/settings/applications/new.</li>
  5909. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5910. </ol>
  5911. <p>Synapse config:</p>
  5912. <pre><code class="language-yaml">oidc_providers:
  5913. - idp_id: github
  5914. idp_name: Github
  5915. idp_brand: &quot;github&quot; # optional: styling hint for clients
  5916. discover: false
  5917. issuer: &quot;https://github.com/&quot;
  5918. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5919. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5920. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  5921. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  5922. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  5923. scopes: [&quot;read:user&quot;]
  5924. user_mapping_provider:
  5925. config:
  5926. subject_claim: &quot;id&quot;
  5927. localpart_template: &quot;{{ user.login }}&quot;
  5928. display_name_template: &quot;{{ user.name }}&quot;
  5929. </code></pre>
  5930. <h3 id="a-hrefhttpsdevelopersgooglecomidentityprotocolsoauth2openid-connectgooglea"><a class="header" href="#a-hrefhttpsdevelopersgooglecomidentityprotocolsoauth2openid-connectgooglea"><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a></a></h3>
  5931. <ol>
  5932. <li>Set up a project in the Google API Console (see
  5933. https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup).</li>
  5934. <li>add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  5935. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  5936. <pre><code class="language-yaml">oidc_providers:
  5937. - idp_id: google
  5938. idp_name: Google
  5939. idp_brand: &quot;google&quot; # optional: styling hint for clients
  5940. issuer: &quot;https://accounts.google.com/&quot;
  5941. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5942. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5943. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5944. user_mapping_provider:
  5945. config:
  5946. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  5947. display_name_template: &quot;{{ user.name }}&quot;
  5948. </code></pre>
  5949. </li>
  5950. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5951. </ol>
  5952. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  5953. <ol>
  5954. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  5955. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  5956. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5957. </ol>
  5958. <p>Synapse config:</p>
  5959. <pre><code class="language-yaml">oidc_providers:
  5960. - idp_id: twitch
  5961. idp_name: Twitch
  5962. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  5963. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5964. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5965. client_auth_method: &quot;client_secret_post&quot;
  5966. user_mapping_provider:
  5967. config:
  5968. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5969. display_name_template: &quot;{{ user.name }}&quot;
  5970. </code></pre>
  5971. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  5972. <ol>
  5973. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  5974. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  5975. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5976. </ol>
  5977. <p>Synapse config:</p>
  5978. <pre><code class="language-yaml">oidc_providers:
  5979. - idp_id: gitlab
  5980. idp_name: Gitlab
  5981. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  5982. issuer: &quot;https://gitlab.com/&quot;
  5983. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5984. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5985. client_auth_method: &quot;client_secret_post&quot;
  5986. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  5987. user_profile_method: &quot;userinfo_endpoint&quot;
  5988. user_mapping_provider:
  5989. config:
  5990. localpart_template: '{{ user.nickname }}'
  5991. display_name_template: '{{ user.name }}'
  5992. </code></pre>
  5993. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  5994. <p>Like Github, Facebook provide a custom OAuth2 API rather than an OIDC-compliant
  5995. one so requires a little more configuration.</p>
  5996. <ol start="0">
  5997. <li>You will need a Facebook developer account. You can register for one
  5998. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  5999. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  6000. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  6001. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  6002. need to go through the whole form here.</li>
  6003. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  6004. <ul>
  6005. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  6006. URL.</li>
  6007. </ul>
  6008. </li>
  6009. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  6010. and &quot;App Secret&quot; for use below.</li>
  6011. </ol>
  6012. <p>Synapse config:</p>
  6013. <pre><code class="language-yaml"> - idp_id: facebook
  6014. idp_name: Facebook
  6015. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  6016. discover: false
  6017. issuer: &quot;https://facebook.com&quot;
  6018. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6019. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6020. scopes: [&quot;openid&quot;, &quot;email&quot;]
  6021. authorization_endpoint: https://facebook.com/dialog/oauth
  6022. token_endpoint: https://graph.facebook.com/v9.0/oauth/access_token
  6023. user_profile_method: &quot;userinfo_endpoint&quot;
  6024. userinfo_endpoint: &quot;https://graph.facebook.com/v9.0/me?fields=id,name,email,picture&quot;
  6025. user_mapping_provider:
  6026. config:
  6027. subject_claim: &quot;id&quot;
  6028. display_name_template: &quot;{{ user.name }}&quot;
  6029. </code></pre>
  6030. <p>Relevant documents:</p>
  6031. <ul>
  6032. <li>https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow</li>
  6033. <li>Using Facebook's Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/</li>
  6034. <li>Reference to the User endpoint: https://developers.facebook.com/docs/graph-api/reference/user</li>
  6035. </ul>
  6036. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  6037. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  6038. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  6039. can be used to retrieve information on the authenticated user. As the Synapse
  6040. login mechanism needs an attribute to uniquely identify users, and that endpoint
  6041. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  6042. <ol>
  6043. <li>Create a new application.</li>
  6044. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  6045. </ol>
  6046. <p>Synapse config:</p>
  6047. <pre><code class="language-yaml">oidc_providers:
  6048. - idp_id: gitea
  6049. idp_name: Gitea
  6050. discover: false
  6051. issuer: &quot;https://your-gitea.com/&quot;
  6052. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6053. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6054. client_auth_method: client_secret_post
  6055. scopes: [] # Gitea doesn't support Scopes
  6056. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  6057. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  6058. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  6059. user_mapping_provider:
  6060. config:
  6061. subject_claim: &quot;id&quot;
  6062. localpart_template: &quot;{{ user.login }}&quot;
  6063. display_name_template: &quot;{{ user.full_name }}&quot;
  6064. </code></pre>
  6065. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  6066. <p>Install <a href="https://extensions.xwiki.org/xwiki/bin/view/Extension/OpenID%20Connect/OpenID%20Connect%20Provider/">OpenID Connect Provider</a> extension in your <a href="https://www.xwiki.org">XWiki</a> instance.</p>
  6067. <p>Synapse config:</p>
  6068. <pre><code class="language-yaml">oidc_providers:
  6069. - idp_id: xwiki
  6070. idp_name: &quot;XWiki&quot;
  6071. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  6072. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6073. client_auth_method: none
  6074. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  6075. user_profile_method: &quot;userinfo_endpoint&quot;
  6076. user_mapping_provider:
  6077. config:
  6078. localpart_template: &quot;{{ user.preferred_username }}&quot;
  6079. display_name_template: &quot;{{ user.name }}&quot;
  6080. </code></pre>
  6081. <h3 id="apple"><a class="header" href="#apple">Apple</a></h3>
  6082. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  6083. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  6084. private key with &quot;SiWA&quot; enabled.</p>
  6085. <p>As well as the private key file, you will need:</p>
  6086. <ul>
  6087. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  6088. <li>Team ID: a 10-character ID associated with your developer account.</li>
  6089. <li>Key ID: the 10-character identifier for the key.</li>
  6090. </ul>
  6091. <p>https://help.apple.com/developer-account/?lang=en#/dev77c875b7e has more
  6092. documentation on setting up SiWA.</p>
  6093. <p>The synapse config will look like this:</p>
  6094. <pre><code class="language-yaml"> - idp_id: apple
  6095. idp_name: Apple
  6096. issuer: &quot;https://appleid.apple.com&quot;
  6097. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  6098. client_auth_method: &quot;client_secret_post&quot;
  6099. client_secret_jwt_key:
  6100. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  6101. jwt_header:
  6102. alg: ES256
  6103. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  6104. jwt_payload:
  6105. iss: TEAMIDCODE # Set to the 10-char Team ID
  6106. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  6107. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  6108. user_mapping_provider:
  6109. config:
  6110. email_template: &quot;{{ user.email }}&quot;
  6111. </code></pre>
  6112. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="sso-mapping-providers"><a class="header" href="#sso-mapping-providers">SSO Mapping Providers</a></h1>
  6113. <p>A mapping provider is a Python class (loaded via a Python module) that
  6114. works out how to map attributes of a SSO response to Matrix-specific
  6115. user attributes. Details such as user ID localpart, displayname, and even avatar
  6116. URLs are all things that can be mapped from talking to a SSO service.</p>
  6117. <p>As an example, a SSO service may return the email address
  6118. &quot;john.smith@example.com&quot; for a user, whereas Synapse will need to figure out how
  6119. to turn that into a displayname when creating a Matrix user for this individual.
  6120. It may choose <code>John Smith</code>, or <code>Smith, John [Example.com]</code> or any number of
  6121. variations. As each Synapse configuration may want something different, this is
  6122. where SAML mapping providers come into play.</p>
  6123. <p>SSO mapping providers are currently supported for OpenID and SAML SSO
  6124. configurations. Please see the details below for how to implement your own.</p>
  6125. <p>It is up to the mapping provider whether the user should be assigned a predefined
  6126. Matrix ID based on the SSO attributes, or if the user should be allowed to
  6127. choose their own username.</p>
  6128. <p>In the first case - where users are automatically allocated a Matrix ID - it is
  6129. the responsibility of the mapping provider to normalise the SSO attributes and
  6130. map them to a valid Matrix ID. The <a href="https://matrix.org/docs/spec/appendices#user-identifiers">specification for Matrix
  6131. IDs</a> has some
  6132. information about what is considered valid.</p>
  6133. <p>If the mapping provider does not assign a Matrix ID, then Synapse will
  6134. automatically serve an HTML page allowing the user to pick their own username.</p>
  6135. <p>External mapping providers are provided to Synapse in the form of an external
  6136. Python module. You can retrieve this module from <a href="https://pypi.org">PyPI</a> or elsewhere,
  6137. but it must be importable via Synapse (e.g. it must be in the same virtualenv
  6138. as Synapse). The Synapse config is then modified to point to the mapping provider
  6139. (and optionally provide additional configuration for it).</p>
  6140. <h2 id="openid-mapping-providers"><a class="header" href="#openid-mapping-providers">OpenID Mapping Providers</a></h2>
  6141. <p>The OpenID mapping provider can be customized by editing the
  6142. <code>oidc_config.user_mapping_provider.module</code> config option.</p>
  6143. <p><code>oidc_config.user_mapping_provider.config</code> allows you to provide custom
  6144. configuration options to the module. Check with the module's documentation for
  6145. what options it provides (if any). The options listed by default are for the
  6146. user mapping provider built in to Synapse. If using a custom module, you should
  6147. comment these options out and use those specified by the module instead.</p>
  6148. <h3 id="building-a-custom-openid-mapping-provider"><a class="header" href="#building-a-custom-openid-mapping-provider">Building a Custom OpenID Mapping Provider</a></h3>
  6149. <p>A custom mapping provider must specify the following methods:</p>
  6150. <ul>
  6151. <li><code>__init__(self, parsed_config)</code>
  6152. <ul>
  6153. <li>Arguments:
  6154. <ul>
  6155. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6156. <code>parse_config</code> method. You should set any configuration options needed by
  6157. the module here.</li>
  6158. </ul>
  6159. </li>
  6160. </ul>
  6161. </li>
  6162. <li><code>parse_config(config)</code>
  6163. <ul>
  6164. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6165. <li>Arguments:
  6166. <ul>
  6167. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6168. <code>oidc_config.user_mapping_provider.config</code> homeserver config option.
  6169. Runs on homeserver startup. Providers should extract and validate
  6170. any option values they need here.</li>
  6171. </ul>
  6172. </li>
  6173. <li>Whatever is returned will be passed back to the user mapping provider module's
  6174. <code>__init__</code> method during construction.</li>
  6175. </ul>
  6176. </li>
  6177. <li><code>get_remote_user_id(self, userinfo)</code>
  6178. <ul>
  6179. <li>Arguments:
  6180. <ul>
  6181. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6182. information from.</li>
  6183. </ul>
  6184. </li>
  6185. <li>This method must return a string, which is the unique, immutable identifier
  6186. for the user. Commonly the <code>sub</code> claim of the response.</li>
  6187. </ul>
  6188. </li>
  6189. <li><code>map_user_attributes(self, userinfo, token, failures)</code>
  6190. <ul>
  6191. <li>This method must be async.</li>
  6192. <li>Arguments:
  6193. <ul>
  6194. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6195. information from.</li>
  6196. <li><code>token</code> - A dictionary which includes information necessary to make
  6197. further requests to the OpenID provider.</li>
  6198. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6199. mxid localpart mapping has failed. This should be used
  6200. to create a deduplicated mxid localpart which should be
  6201. returned instead. For example, if this method returns
  6202. <code>john.doe</code> as the value of <code>localpart</code> in the returned
  6203. dict, and that is already taken on the homeserver, this
  6204. method will be called again with the same parameters but
  6205. with failures=1. The method should then return a different
  6206. <code>localpart</code> value, such as <code>john.doe1</code>.</li>
  6207. </ul>
  6208. </li>
  6209. <li>Returns a dictionary with two keys:
  6210. <ul>
  6211. <li><code>localpart</code>: A string, used to generate the Matrix ID. If this is
  6212. <code>None</code>, the user is prompted to pick their own username. This is only used
  6213. during a user's first login. Once a localpart has been associated with a
  6214. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6215. <li><code>displayname</code>: An optional string, the display name for the user.</li>
  6216. </ul>
  6217. </li>
  6218. </ul>
  6219. </li>
  6220. <li><code>get_extra_attributes(self, userinfo, token)</code>
  6221. <ul>
  6222. <li>
  6223. <p>This method must be async.</p>
  6224. </li>
  6225. <li>
  6226. <p>Arguments:</p>
  6227. <ul>
  6228. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6229. information from.</li>
  6230. <li><code>token</code> - A dictionary which includes information necessary to make
  6231. further requests to the OpenID provider.</li>
  6232. </ul>
  6233. </li>
  6234. <li>
  6235. <p>Returns a dictionary that is suitable to be serialized to JSON. This
  6236. will be returned as part of the response during a successful login.</p>
  6237. <p>Note that care should be taken to not overwrite any of the parameters
  6238. usually returned as part of the <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login">login response</a>.</p>
  6239. </li>
  6240. </ul>
  6241. </li>
  6242. </ul>
  6243. <h3 id="default-openid-mapping-provider"><a class="header" href="#default-openid-mapping-provider">Default OpenID Mapping Provider</a></h3>
  6244. <p>Synapse has a built-in OpenID mapping provider if a custom provider isn't
  6245. specified in the config. It is located at
  6246. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/oidc.py"><code>synapse.handlers.oidc.JinjaOidcMappingProvider</code></a>.</p>
  6247. <h2 id="saml-mapping-providers"><a class="header" href="#saml-mapping-providers">SAML Mapping Providers</a></h2>
  6248. <p>The SAML mapping provider can be customized by editing the
  6249. <code>saml2_config.user_mapping_provider.module</code> config option.</p>
  6250. <p><code>saml2_config.user_mapping_provider.config</code> allows you to provide custom
  6251. configuration options to the module. Check with the module's documentation for
  6252. what options it provides (if any). The options listed by default are for the
  6253. user mapping provider built in to Synapse. If using a custom module, you should
  6254. comment these options out and use those specified by the module instead.</p>
  6255. <h3 id="building-a-custom-saml-mapping-provider"><a class="header" href="#building-a-custom-saml-mapping-provider">Building a Custom SAML Mapping Provider</a></h3>
  6256. <p>A custom mapping provider must specify the following methods:</p>
  6257. <ul>
  6258. <li><code>__init__(self, parsed_config, module_api)</code>
  6259. <ul>
  6260. <li>Arguments:
  6261. <ul>
  6262. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6263. <code>parse_config</code> method. You should set any configuration options needed by
  6264. the module here.</li>
  6265. <li><code>module_api</code> - a <code>synapse.module_api.ModuleApi</code> object which provides the
  6266. stable API available for extension modules.</li>
  6267. </ul>
  6268. </li>
  6269. </ul>
  6270. </li>
  6271. <li><code>parse_config(config)</code>
  6272. <ul>
  6273. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6274. <li>Arguments:
  6275. <ul>
  6276. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6277. <code>saml_config.user_mapping_provider.config</code> homeserver config option.
  6278. Runs on homeserver startup. Providers should extract and validate
  6279. any option values they need here.</li>
  6280. </ul>
  6281. </li>
  6282. <li>Whatever is returned will be passed back to the user mapping provider module's
  6283. <code>__init__</code> method during construction.</li>
  6284. </ul>
  6285. </li>
  6286. <li><code>get_saml_attributes(config)</code>
  6287. <ul>
  6288. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6289. <li>Arguments:
  6290. <ul>
  6291. <li><code>config</code> - A object resulting from a call to <code>parse_config</code>.</li>
  6292. </ul>
  6293. </li>
  6294. <li>Returns a tuple of two sets. The first set equates to the SAML auth
  6295. response attributes that are required for the module to function, whereas
  6296. the second set consists of those attributes which can be used if available,
  6297. but are not necessary.</li>
  6298. </ul>
  6299. </li>
  6300. <li><code>get_remote_user_id(self, saml_response, client_redirect_url)</code>
  6301. <ul>
  6302. <li>Arguments:
  6303. <ul>
  6304. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6305. information from.</li>
  6306. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6307. redirected to.</li>
  6308. </ul>
  6309. </li>
  6310. <li>This method must return a string, which is the unique, immutable identifier
  6311. for the user. Commonly the <code>uid</code> claim of the response.</li>
  6312. </ul>
  6313. </li>
  6314. <li><code>saml_response_to_user_attributes(self, saml_response, failures, client_redirect_url)</code>
  6315. <ul>
  6316. <li>
  6317. <p>Arguments:</p>
  6318. <ul>
  6319. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6320. information from.</li>
  6321. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6322. mxid localpart mapping has failed. This should be used
  6323. to create a deduplicated mxid localpart which should be
  6324. returned instead. For example, if this method returns
  6325. <code>john.doe</code> as the value of <code>mxid_localpart</code> in the returned
  6326. dict, and that is already taken on the homeserver, this
  6327. method will be called again with the same parameters but
  6328. with failures=1. The method should then return a different
  6329. <code>mxid_localpart</code> value, such as <code>john.doe1</code>.</li>
  6330. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6331. redirected to.</li>
  6332. </ul>
  6333. </li>
  6334. <li>
  6335. <p>This method must return a dictionary, which will then be used by Synapse
  6336. to build a new user. The following keys are allowed:</p>
  6337. <ul>
  6338. <li><code>mxid_localpart</code> - A string, the mxid localpart of the new user. If this is
  6339. <code>None</code>, the user is prompted to pick their own username. This is only used
  6340. during a user's first login. Once a localpart has been associated with a
  6341. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6342. <li><code>displayname</code> - The displayname of the new user. If not provided, will default to
  6343. the value of <code>mxid_localpart</code>.</li>
  6344. <li><code>emails</code> - A list of emails for the new user. If not provided, will
  6345. default to an empty list.</li>
  6346. </ul>
  6347. <p>Alternatively it can raise a <code>synapse.api.errors.RedirectException</code> to
  6348. redirect the user to another page. This is useful to prompt the user for
  6349. additional information, e.g. if you want them to provide their own username.
  6350. It is the responsibility of the mapping provider to either redirect back
  6351. to <code>client_redirect_url</code> (including any additional information) or to
  6352. complete registration using methods from the <code>ModuleApi</code>.</p>
  6353. </li>
  6354. </ul>
  6355. </li>
  6356. </ul>
  6357. <h3 id="default-saml-mapping-provider"><a class="header" href="#default-saml-mapping-provider">Default SAML Mapping Provider</a></h3>
  6358. <p>Synapse has a built-in SAML mapping provider if a custom provider isn't
  6359. specified in the config. It is located at
  6360. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/saml.py"><code>synapse.handlers.saml.DefaultSamlMappingProvider</code></a>.</p>
  6361. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="password-auth-provider-modules"><a class="header" href="#password-auth-provider-modules">Password auth provider modules</a></h1>
  6362. <p>Password auth providers offer a way for server administrators to
  6363. integrate their Synapse installation with an existing authentication
  6364. system.</p>
  6365. <p>A password auth provider is a Python class which is dynamically loaded
  6366. into Synapse, and provides a number of methods by which it can integrate
  6367. with the authentication system.</p>
  6368. <p>This document serves as a reference for those looking to implement their
  6369. own password auth providers. Additionally, here is a list of known
  6370. password auth provider module implementations:</p>
  6371. <ul>
  6372. <li><a href="https://github.com/matrix-org/matrix-synapse-ldap3/">matrix-synapse-ldap3</a></li>
  6373. <li><a href="https://github.com/devture/matrix-synapse-shared-secret-auth">matrix-synapse-shared-secret-auth</a></li>
  6374. <li><a href="https://github.com/ma1uta/matrix-synapse-rest-password-provider">matrix-synapse-rest-password-provider</a></li>
  6375. </ul>
  6376. <h2 id="required-methods"><a class="header" href="#required-methods">Required methods</a></h2>
  6377. <p>Password auth provider classes must provide the following methods:</p>
  6378. <ul>
  6379. <li>
  6380. <p><code>parse_config(config)</code>
  6381. This method is passed the <code>config</code> object for this module from the
  6382. homeserver configuration file.</p>
  6383. <p>It should perform any appropriate sanity checks on the provided
  6384. configuration, and return an object which is then passed into
  6385. <code>__init__</code>.</p>
  6386. <p>This method should have the <code>@staticmethod</code> decoration.</p>
  6387. </li>
  6388. <li>
  6389. <p><code>__init__(self, config, account_handler)</code></p>
  6390. <p>The constructor is passed the config object returned by
  6391. <code>parse_config</code>, and a <code>synapse.module_api.ModuleApi</code> object which
  6392. allows the password provider to check if accounts exist and/or create
  6393. new ones.</p>
  6394. </li>
  6395. </ul>
  6396. <h2 id="optional-methods"><a class="header" href="#optional-methods">Optional methods</a></h2>
  6397. <p>Password auth provider classes may optionally provide the following methods:</p>
  6398. <ul>
  6399. <li>
  6400. <p><code>get_db_schema_files(self)</code></p>
  6401. <p>This method, if implemented, should return an Iterable of
  6402. <code>(name, stream)</code> pairs of database schema files. Each file is applied
  6403. in turn at initialisation, and a record is then made in the database
  6404. so that it is not re-applied on the next start.</p>
  6405. </li>
  6406. <li>
  6407. <p><code>get_supported_login_types(self)</code></p>
  6408. <p>This method, if implemented, should return a <code>dict</code> mapping from a
  6409. login type identifier (such as <code>m.login.password</code>) to an iterable
  6410. giving the fields which must be provided by the user in the submission
  6411. to <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login">the <code>/login</code> API</a>.
  6412. These fields are passed in the <code>login_dict</code> dictionary to <code>check_auth</code>.</p>
  6413. <p>For example, if a password auth provider wants to implement a custom
  6414. login type of <code>com.example.custom_login</code>, where the client is expected
  6415. to pass the fields <code>secret1</code> and <code>secret2</code>, the provider should
  6416. implement this method and return the following dict:</p>
  6417. <pre><code class="language-python">{&quot;com.example.custom_login&quot;: (&quot;secret1&quot;, &quot;secret2&quot;)}
  6418. </code></pre>
  6419. </li>
  6420. <li>
  6421. <p><code>check_auth(self, username, login_type, login_dict)</code></p>
  6422. <p>This method does the real work. If implemented, it
  6423. will be called for each login attempt where the login type matches one
  6424. of the keys returned by <code>get_supported_login_types</code>.</p>
  6425. <p>It is passed the (possibly unqualified) <code>user</code> field provided by the client,
  6426. the login type, and a dictionary of login secrets passed by the
  6427. client.</p>
  6428. <p>The method should return an <code>Awaitable</code> object, which resolves
  6429. to the canonical <code>@localpart:domain</code> user ID if authentication is
  6430. successful, and <code>None</code> if not.</p>
  6431. <p>Alternatively, the <code>Awaitable</code> can resolve to a <code>(str, func)</code> tuple, in
  6432. which case the second field is a callback which will be called with
  6433. the result from the <code>/login</code> call (including <code>access_token</code>,
  6434. <code>device_id</code>, etc.)</p>
  6435. </li>
  6436. <li>
  6437. <p><code>check_3pid_auth(self, medium, address, password)</code></p>
  6438. <p>This method, if implemented, is called when a user attempts to
  6439. register or log in with a third party identifier, such as email. It is
  6440. passed the medium (ex. &quot;email&quot;), an address (ex.
  6441. &quot;<a href="mailto:jdoe@example.com">jdoe@example.com</a>&quot;) and the user's password.</p>
  6442. <p>The method should return an <code>Awaitable</code> object, which resolves
  6443. to a <code>str</code> containing the user's (canonical) User id if
  6444. authentication was successful, and <code>None</code> if not.</p>
  6445. <p>As with <code>check_auth</code>, the <code>Awaitable</code> may alternatively resolve to a
  6446. <code>(user_id, callback)</code> tuple.</p>
  6447. </li>
  6448. <li>
  6449. <p><code>check_password(self, user_id, password)</code></p>
  6450. <p>This method provides a simpler interface than
  6451. <code>get_supported_login_types</code> and <code>check_auth</code> for password auth
  6452. providers that just want to provide a mechanism for validating
  6453. <code>m.login.password</code> logins.</p>
  6454. <p>If implemented, it will be called to check logins with an
  6455. <code>m.login.password</code> login type. It is passed a qualified
  6456. <code>@localpart:domain</code> user id, and the password provided by the user.</p>
  6457. <p>The method should return an <code>Awaitable</code> object, which resolves
  6458. to <code>True</code> if authentication is successful, and <code>False</code> if not.</p>
  6459. </li>
  6460. <li>
  6461. <p><code>on_logged_out(self, user_id, device_id, access_token)</code></p>
  6462. <p>This method, if implemented, is called when a user logs out. It is
  6463. passed the qualified user ID, the ID of the deactivated device (if
  6464. any: access tokens are occasionally created without an associated
  6465. device ID), and the (now deactivated) access token.</p>
  6466. <p>It may return an <code>Awaitable</code> object; the logout request will
  6467. wait for the <code>Awaitable</code> to complete, but the result is ignored.</p>
  6468. </li>
  6469. </ul>
  6470. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="jwt-login-type"><a class="header" href="#jwt-login-type">JWT Login Type</a></h1>
  6471. <p>Synapse comes with a non-standard login type to support
  6472. <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">JSON Web Tokens</a>. In general the
  6473. documentation for
  6474. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#login">the login endpoint</a>
  6475. is still valid (and the mechanism works similarly to the
  6476. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#token-based">token based login</a>).</p>
  6477. <p>To log in using a JSON Web Token, clients should submit a <code>/login</code> request as
  6478. follows:</p>
  6479. <pre><code class="language-json">{
  6480. &quot;type&quot;: &quot;org.matrix.login.jwt&quot;,
  6481. &quot;token&quot;: &quot;&lt;jwt&gt;&quot;
  6482. }
  6483. </code></pre>
  6484. <p>Note that the login type of <code>m.login.jwt</code> is supported, but is deprecated. This
  6485. will be removed in a future version of Synapse.</p>
  6486. <p>The <code>token</code> field should include the JSON web token with the following claims:</p>
  6487. <ul>
  6488. <li>The <code>sub</code> (subject) claim is required and should encode the local part of the
  6489. user ID.</li>
  6490. <li>The expiration time (<code>exp</code>), not before time (<code>nbf</code>), and issued at (<code>iat</code>)
  6491. claims are optional, but validated if present.</li>
  6492. <li>The issuer (<code>iss</code>) claim is optional, but required and validated if configured.</li>
  6493. <li>The audience (<code>aud</code>) claim is optional, but required and validated if configured.
  6494. Providing the audience claim when not configured will cause validation to fail.</li>
  6495. </ul>
  6496. <p>In the case that the token is not valid, the homeserver must respond with
  6497. <code>403 Forbidden</code> and an error code of <code>M_FORBIDDEN</code>.</p>
  6498. <p>As with other login types, there are additional fields (e.g. <code>device_id</code> and
  6499. <code>initial_device_display_name</code>) which can be included in the above request.</p>
  6500. <h2 id="preparing-synapse-1"><a class="header" href="#preparing-synapse-1">Preparing Synapse</a></h2>
  6501. <p>The JSON Web Token integration in Synapse uses the
  6502. <a href="https://pypi.org/project/pyjwt/"><code>PyJWT</code></a> library, which must be installed
  6503. as follows:</p>
  6504. <ul>
  6505. <li>
  6506. <p>The relevant libraries are included in the Docker images and Debian packages
  6507. provided by <code>matrix.org</code> so no further action is needed.</p>
  6508. </li>
  6509. <li>
  6510. <p>If you installed Synapse into a virtualenv, run <code>/path/to/env/bin/pip install synapse[pyjwt]</code> to install the necessary dependencies.</p>
  6511. </li>
  6512. <li>
  6513. <p>For other installation mechanisms, see the documentation provided by the
  6514. maintainer.</p>
  6515. </li>
  6516. </ul>
  6517. <p>To enable the JSON web token integration, you should then add an <code>jwt_config</code> section
  6518. to your configuration file (or uncomment the <code>enabled: true</code> line in the
  6519. existing section). See <a href="./sample_config.yaml">sample_config.yaml</a> for some
  6520. sample settings.</p>
  6521. <h2 id="how-to-test-jwt-as-a-developer"><a class="header" href="#how-to-test-jwt-as-a-developer">How to test JWT as a developer</a></h2>
  6522. <p>Although JSON Web Tokens are typically generated from an external server, the
  6523. examples below use <a href="https://pyjwt.readthedocs.io/en/latest/">PyJWT</a> directly.</p>
  6524. <ol>
  6525. <li>
  6526. <p>Configure Synapse with JWT logins, note that this example uses a pre-shared
  6527. secret and an algorithm of HS256:</p>
  6528. <pre><code class="language-yaml">jwt_config:
  6529. enabled: true
  6530. secret: &quot;my-secret-token&quot;
  6531. algorithm: &quot;HS256&quot;
  6532. </code></pre>
  6533. </li>
  6534. <li>
  6535. <p>Generate a JSON web token:</p>
  6536. <pre><code class="language-bash">$ pyjwt --key=my-secret-token --alg=HS256 encode sub=test-user
  6537. eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc
  6538. </code></pre>
  6539. </li>
  6540. <li>
  6541. <p>Query for the login types and ensure <code>org.matrix.login.jwt</code> is there:</p>
  6542. <pre><code class="language-bash">curl http://localhost:8080/_matrix/client/r0/login
  6543. </code></pre>
  6544. </li>
  6545. <li>
  6546. <p>Login used the generated JSON web token from above:</p>
  6547. <pre><code class="language-bash">$ curl http://localhost:8082/_matrix/client/r0/login -X POST \
  6548. --data '{&quot;type&quot;:&quot;org.matrix.login.jwt&quot;,&quot;token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc&quot;}'
  6549. {
  6550. &quot;access_token&quot;: &quot;&lt;access token&gt;&quot;,
  6551. &quot;device_id&quot;: &quot;ACBDEFGHI&quot;,
  6552. &quot;home_server&quot;: &quot;localhost:8080&quot;,
  6553. &quot;user_id&quot;: &quot;@test-user:localhost:8480&quot;
  6554. }
  6555. </code></pre>
  6556. </li>
  6557. </ol>
  6558. <p>You should now be able to use the returned access token to query the client API.</p>
  6559. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="overview-2"><a class="header" href="#overview-2">Overview</a></h1>
  6560. <p>A captcha can be enabled on your homeserver to help prevent bots from registering
  6561. accounts. Synapse currently uses Google's reCAPTCHA service which requires API keys
  6562. from Google.</p>
  6563. <h2 id="getting-api-keys"><a class="header" href="#getting-api-keys">Getting API keys</a></h2>
  6564. <ol>
  6565. <li>Create a new site at <a href="https://www.google.com/recaptcha/admin/create">https://www.google.com/recaptcha/admin/create</a></li>
  6566. <li>Set the label to anything you want</li>
  6567. <li>Set the type to reCAPTCHA v2 using the &quot;I'm not a robot&quot; Checkbox option.
  6568. This is the only type of captcha that works with Synapse.</li>
  6569. <li>Add the public hostname for your server, as set in <code>public_baseurl</code>
  6570. in <code>homeserver.yaml</code>, to the list of authorized domains. If you have not set
  6571. <code>public_baseurl</code>, use <code>server_name</code>.</li>
  6572. <li>Agree to the terms of service and submit.</li>
  6573. <li>Copy your site key and secret key and add them to your <code>homeserver.yaml</code>
  6574. configuration file
  6575. <pre><code>recaptcha_public_key: YOUR_SITE_KEY
  6576. recaptcha_private_key: YOUR_SECRET_KEY
  6577. </code></pre>
  6578. </li>
  6579. <li>Enable the CAPTCHA for new registrations
  6580. <pre><code>enable_registration_captcha: true
  6581. </code></pre>
  6582. </li>
  6583. <li>Go to the settings page for the CAPTCHA you just created</li>
  6584. <li>Uncheck the &quot;Verify the origin of reCAPTCHA solutions&quot; checkbox so that the
  6585. captcha can be displayed in any client. If you do not disable this option then you
  6586. must specify the domains of every client that is allowed to display the CAPTCHA.</li>
  6587. </ol>
  6588. <h2 id="configuring-ip-used-for-auth"><a class="header" href="#configuring-ip-used-for-auth">Configuring IP used for auth</a></h2>
  6589. <p>The reCAPTCHA API requires that the IP address of the user who solved the
  6590. CAPTCHA is sent. If the client is connecting through a proxy or load balancer,
  6591. it may be required to use the <code>X-Forwarded-For</code> (XFF) header instead of the origin
  6592. IP address. This can be configured using the <code>x_forwarded</code> directive in the
  6593. listeners section of the <code>homeserver.yaml</code> configuration file.</p>
  6594. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="registering-an-application-service"><a class="header" href="#registering-an-application-service">Registering an Application Service</a></h1>
  6595. <p>The registration of new application services depends on the homeserver used.
  6596. In synapse, you need to create a new configuration file for your AS and add it
  6597. to the list specified under the <code>app_service_config_files</code> config
  6598. option in your synapse config.</p>
  6599. <p>For example:</p>
  6600. <pre><code class="language-yaml">app_service_config_files:
  6601. - /home/matrix/.synapse/&lt;your-AS&gt;.yaml
  6602. </code></pre>
  6603. <p>The format of the AS configuration file is as follows:</p>
  6604. <pre><code class="language-yaml">url: &lt;base url of AS&gt;
  6605. as_token: &lt;token AS will add to requests to HS&gt;
  6606. hs_token: &lt;token HS will add to requests to AS&gt;
  6607. sender_localpart: &lt;localpart of AS user&gt;
  6608. namespaces:
  6609. users: # List of users we're interested in
  6610. - exclusive: &lt;bool&gt;
  6611. regex: &lt;regex&gt;
  6612. group_id: &lt;group&gt;
  6613. - ...
  6614. aliases: [] # List of aliases we're interested in
  6615. rooms: [] # List of room ids we're interested in
  6616. </code></pre>
  6617. <p><code>exclusive</code>: If enabled, only this application service is allowed to register users in its namespace(s).
  6618. <code>group_id</code>: All users of this application service are dynamically joined to this group. This is useful for e.g user organisation or flairs.</p>
  6619. <p>See the <a href="https://matrix.org/docs/spec/application_service/unstable.html">spec</a> for further details on how application services work.</p>
  6620. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="server-notices"><a class="header" href="#server-notices">Server Notices</a></h1>
  6621. <p>'Server Notices' are a new feature introduced in Synapse 0.30. They provide a
  6622. channel whereby server administrators can send messages to users on the server.</p>
  6623. <p>They are used as part of communication of the server polices (see
  6624. <a href="consent_tracking.html">Consent Tracking</a>), however the intention is that
  6625. they may also find a use for features such as &quot;Message of the day&quot;.</p>
  6626. <p>This is a feature specific to Synapse, but it uses standard Matrix
  6627. communication mechanisms, so should work with any Matrix client.</p>
  6628. <h2 id="user-experience"><a class="header" href="#user-experience">User experience</a></h2>
  6629. <p>When the user is first sent a server notice, they will get an invitation to a
  6630. room (typically called 'Server Notices', though this is configurable in
  6631. <code>homeserver.yaml</code>). They will be <strong>unable to reject</strong> this invitation -
  6632. attempts to do so will receive an error.</p>
  6633. <p>Once they accept the invitation, they will see the notice message in the room
  6634. history; it will appear to have come from the 'server notices user' (see
  6635. below).</p>
  6636. <p>The user is prevented from sending any messages in this room by the power
  6637. levels.</p>
  6638. <p>Having joined the room, the user can leave the room if they want. Subsequent
  6639. server notices will then cause a new room to be created.</p>
  6640. <h2 id="synapse-configuration"><a class="header" href="#synapse-configuration">Synapse configuration</a></h2>
  6641. <p>Server notices come from a specific user id on the server. Server
  6642. administrators are free to choose the user id - something like <code>server</code> is
  6643. suggested, meaning the notices will come from
  6644. <code>@server:&lt;your_server_name&gt;</code>. Once the Server Notices user is configured, that
  6645. user id becomes a special, privileged user, so administrators should ensure
  6646. that <strong>it is not already allocated</strong>.</p>
  6647. <p>In order to support server notices, it is necessary to add some configuration
  6648. to the <code>homeserver.yaml</code> file. In particular, you should add a <code>server_notices</code>
  6649. section, which should look like this:</p>
  6650. <pre><code class="language-yaml">server_notices:
  6651. system_mxid_localpart: server
  6652. system_mxid_display_name: &quot;Server Notices&quot;
  6653. system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  6654. room_name: &quot;Server Notices&quot;
  6655. </code></pre>
  6656. <p>The only compulsory setting is <code>system_mxid_localpart</code>, which defines the user
  6657. id of the Server Notices user, as above. <code>room_name</code> defines the name of the
  6658. room which will be created.</p>
  6659. <p><code>system_mxid_display_name</code> and <code>system_mxid_avatar_url</code> can be used to set the
  6660. displayname and avatar of the Server Notices user.</p>
  6661. <h2 id="sending-notices"><a class="header" href="#sending-notices">Sending notices</a></h2>
  6662. <p>To send server notices to users you can use the
  6663. <a href="admin_api/server_notices.html">admin_api</a>.</p>
  6664. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions"><a class="header" href="#support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions">Support in Synapse for tracking agreement to server terms and conditions</a></h1>
  6665. <p>Synapse 0.30 introduces support for tracking whether users have agreed to the
  6666. terms and conditions set by the administrator of a server - and blocking access
  6667. to the server until they have.</p>
  6668. <p>There are several parts to this functionality; each requires some specific
  6669. configuration in <code>homeserver.yaml</code> to be enabled.</p>
  6670. <p>Note that various parts of the configuation and this document refer to the
  6671. &quot;privacy policy&quot;: agreement with a privacy policy is one particular use of this
  6672. feature, but of course adminstrators can specify other terms and conditions
  6673. unrelated to &quot;privacy&quot; per se.</p>
  6674. <h2 id="collecting-policy-agreement-from-a-user"><a class="header" href="#collecting-policy-agreement-from-a-user">Collecting policy agreement from a user</a></h2>
  6675. <p>Synapse can be configured to serve the user a simple policy form with an
  6676. &quot;accept&quot; button. Clicking &quot;Accept&quot; records the user's acceptance in the
  6677. database and shows a success page.</p>
  6678. <p>To enable this, first create templates for the policy and success pages.
  6679. These should be stored on the local filesystem.</p>
  6680. <p>These templates use the <a href="http://jinja.pocoo.org">Jinja2</a> templating language,
  6681. and <a href="https://github.com/matrix-org/synapse/tree/develop/docs/privacy_policy_templates/">docs/privacy_policy_templates</a>
  6682. gives examples of the sort of thing that can be done.</p>
  6683. <p>Note that the templates must be stored under a name giving the language of the
  6684. template - currently this must always be <code>en</code> (for &quot;English&quot;);
  6685. internationalisation support is intended for the future.</p>
  6686. <p>The template for the policy itself should be versioned and named according to
  6687. the version: for example <code>1.0.html</code>. The version of the policy which the user
  6688. has agreed to is stored in the database.</p>
  6689. <p>Once the templates are in place, make the following changes to <code>homeserver.yaml</code>:</p>
  6690. <ol>
  6691. <li>
  6692. <p>Add a <code>user_consent</code> section, which should look like:</p>
  6693. <pre><code class="language-yaml">user_consent:
  6694. template_dir: privacy_policy_templates
  6695. version: 1.0
  6696. </code></pre>
  6697. <p><code>template_dir</code> points to the directory containing the policy
  6698. templates. <code>version</code> defines the version of the policy which will be served
  6699. to the user. In the example above, Synapse will serve
  6700. <code>privacy_policy_templates/en/1.0.html</code>.</p>
  6701. </li>
  6702. <li>
  6703. <p>Add a <code>form_secret</code> setting at the top level:</p>
  6704. <pre><code class="language-yaml">form_secret: &quot;&lt;unique secret&gt;&quot;
  6705. </code></pre>
  6706. <p>This should be set to an arbitrary secret string (try <code>pwgen -y 30</code> to
  6707. generate suitable secrets).</p>
  6708. <p>More on what this is used for below.</p>
  6709. </li>
  6710. <li>
  6711. <p>Add <code>consent</code> wherever the <code>client</code> resource is currently enabled in the
  6712. <code>listeners</code> configuration. For example:</p>
  6713. <pre><code class="language-yaml">listeners:
  6714. - port: 8008
  6715. resources:
  6716. - names:
  6717. - client
  6718. - consent
  6719. </code></pre>
  6720. </li>
  6721. </ol>
  6722. <p>Finally, ensure that <code>jinja2</code> is installed. If you are using a virtualenv, this
  6723. should be a matter of <code>pip install Jinja2</code>. On debian, try <code>apt-get install python-jinja2</code>.</p>
  6724. <p>Once this is complete, and the server has been restarted, try visiting
  6725. <code>https://&lt;server&gt;/_matrix/consent</code>. If correctly configured, this should give
  6726. an error &quot;Missing string query parameter 'u'&quot;. It is now possible to manually
  6727. construct URIs where users can give their consent.</p>
  6728. <h3 id="enabling-consent-tracking-at-registration"><a class="header" href="#enabling-consent-tracking-at-registration">Enabling consent tracking at registration</a></h3>
  6729. <ol>
  6730. <li>
  6731. <p>Add the following to your configuration:</p>
  6732. <pre><code class="language-yaml">user_consent:
  6733. require_at_registration: true
  6734. policy_name: &quot;Privacy Policy&quot; # or whatever you'd like to call the policy
  6735. </code></pre>
  6736. </li>
  6737. <li>
  6738. <p>In your consent templates, make use of the <code>public_version</code> variable to
  6739. see if an unauthenticated user is viewing the page. This is typically
  6740. wrapped around the form that would be used to actually agree to the document:</p>
  6741. <pre><code>{% if not public_version %}
  6742. &lt;!-- The variables used here are only provided when the 'u' param is given to the homeserver --&gt;
  6743. &lt;form method=&quot;post&quot; action=&quot;consent&quot;&gt;
  6744. &lt;input type=&quot;hidden&quot; name=&quot;v&quot; value=&quot;{{version}}&quot;/&gt;
  6745. &lt;input type=&quot;hidden&quot; name=&quot;u&quot; value=&quot;{{user}}&quot;/&gt;
  6746. &lt;input type=&quot;hidden&quot; name=&quot;h&quot; value=&quot;{{userhmac}}&quot;/&gt;
  6747. &lt;input type=&quot;submit&quot; value=&quot;Sure thing!&quot;/&gt;
  6748. &lt;/form&gt;
  6749. {% endif %}
  6750. </code></pre>
  6751. </li>
  6752. <li>
  6753. <p>Restart Synapse to apply the changes.</p>
  6754. </li>
  6755. </ol>
  6756. <p>Visiting <code>https://&lt;server&gt;/_matrix/consent</code> should now give you a view of the privacy
  6757. document. This is what users will be able to see when registering for accounts.</p>
  6758. <h3 id="constructing-the-consent-uri"><a class="header" href="#constructing-the-consent-uri">Constructing the consent URI</a></h3>
  6759. <p>It may be useful to manually construct the &quot;consent URI&quot; for a given user - for
  6760. instance, in order to send them an email asking them to consent. To do this,
  6761. take the base <code>https://&lt;server&gt;/_matrix/consent</code> URL and add the following
  6762. query parameters:</p>
  6763. <ul>
  6764. <li>
  6765. <p><code>u</code>: the user id of the user. This can either be a full MXID
  6766. (<code>@user:server.com</code>) or just the localpart (<code>user</code>).</p>
  6767. </li>
  6768. <li>
  6769. <p><code>h</code>: hex-encoded HMAC-SHA256 of <code>u</code> using the <code>form_secret</code> as a key. It is
  6770. possible to calculate this on the commandline with something like:</p>
  6771. <pre><code class="language-bash">echo -n '&lt;user&gt;' | openssl sha256 -hmac '&lt;form_secret&gt;'
  6772. </code></pre>
  6773. <p>This should result in a URI which looks something like:
  6774. <code>https://&lt;server&gt;/_matrix/consent?u=&lt;user&gt;&amp;h=68a152465a4d...</code>.</p>
  6775. </li>
  6776. </ul>
  6777. <p>Note that not providing a <code>u</code> parameter will be interpreted as wanting to view
  6778. the document from an unauthenticated perspective, such as prior to registration.
  6779. Therefore, the <code>h</code> parameter is not required in this scenario. To enable this
  6780. behaviour, set <code>require_at_registration</code> to <code>true</code> in your <code>user_consent</code> config.</p>
  6781. <h2 id="sending-users-a-server-notice-asking-them-to-agree-to-the-policy"><a class="header" href="#sending-users-a-server-notice-asking-them-to-agree-to-the-policy">Sending users a server notice asking them to agree to the policy</a></h2>
  6782. <p>It is possible to configure Synapse to send a <a href="server_notices.html">server
  6783. notice</a> to anybody who has not yet agreed to the current
  6784. version of the policy. To do so:</p>
  6785. <ul>
  6786. <li>
  6787. <p>ensure that the consent resource is configured, as in the previous section</p>
  6788. </li>
  6789. <li>
  6790. <p>ensure that server notices are configured, as in <a href="server_notices.html">the server notice documentation</a>.</p>
  6791. </li>
  6792. <li>
  6793. <p>Add <code>server_notice_content</code> under <code>user_consent</code> in <code>homeserver.yaml</code>. For
  6794. example:</p>
  6795. <pre><code class="language-yaml">user_consent:
  6796. server_notice_content:
  6797. msgtype: m.text
  6798. body: &gt;-
  6799. Please give your consent to the privacy policy at %(consent_uri)s.
  6800. </code></pre>
  6801. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6802. consent uri for that user.</p>
  6803. </li>
  6804. <li>
  6805. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6806. URI that clients use to connect to the server. (It is used to construct
  6807. <code>consent_uri</code> in the server notice.)</p>
  6808. </li>
  6809. </ul>
  6810. <h2 id="blocking-users-from-using-the-server-until-they-agree-to-the-policy"><a class="header" href="#blocking-users-from-using-the-server-until-they-agree-to-the-policy">Blocking users from using the server until they agree to the policy</a></h2>
  6811. <p>Synapse can be configured to block any attempts to join rooms or send messages
  6812. until the user has given their agreement to the policy. (Joining the server
  6813. notices room is exempted from this).</p>
  6814. <p>To enable this, add <code>block_events_error</code> under <code>user_consent</code>. For example:</p>
  6815. <pre><code class="language-yaml">user_consent:
  6816. block_events_error: &gt;-
  6817. You can't send any messages until you consent to the privacy policy at
  6818. %(consent_uri)s.
  6819. </code></pre>
  6820. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6821. consent uri for that user.</p>
  6822. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6823. URI that clients use to connect to the server. (It is used to construct
  6824. <code>consent_uri</code> in the error.)</p>
  6825. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="url-previews-1"><a class="header" href="#url-previews-1">URL Previews</a></h1>
  6826. <p>Design notes on a URL previewing service for Matrix:</p>
  6827. <p>Options are:</p>
  6828. <ol>
  6829. <li>Have an AS which listens for URLs, downloads them, and inserts an event that describes their metadata.</li>
  6830. </ol>
  6831. <ul>
  6832. <li>Pros:
  6833. <ul>
  6834. <li>Decouples the implementation entirely from Synapse.</li>
  6835. <li>Uses existing Matrix events &amp; content repo to store the metadata.</li>
  6836. </ul>
  6837. </li>
  6838. <li>Cons:
  6839. <ul>
  6840. <li>Which AS should provide this service for a room, and why should you trust it?</li>
  6841. <li>Doesn't work well with E2E; you'd have to cut the AS into every room</li>
  6842. <li>the AS would end up subscribing to every room anyway.</li>
  6843. </ul>
  6844. </li>
  6845. </ul>
  6846. <ol start="2">
  6847. <li>Have a generic preview API (nothing to do with Matrix) that provides a previewing service:</li>
  6848. </ol>
  6849. <ul>
  6850. <li>Pros:
  6851. <ul>
  6852. <li>Simple and flexible; can be used by any clients at any point</li>
  6853. </ul>
  6854. </li>
  6855. <li>Cons:
  6856. <ul>
  6857. <li>If each HS provides one of these independently, all the HSes in a room may needlessly DoS the target URI</li>
  6858. <li>We need somewhere to store the URL metadata rather than just using Matrix itself</li>
  6859. <li>We can't piggyback on matrix to distribute the metadata between HSes.</li>
  6860. </ul>
  6861. </li>
  6862. </ul>
  6863. <ol start="3">
  6864. <li>Make the synapse of the sending user responsible for spidering the URL and inserting an event asynchronously which describes the metadata.</li>
  6865. </ol>
  6866. <ul>
  6867. <li>Pros:
  6868. <ul>
  6869. <li>Works transparently for all clients</li>
  6870. <li>Piggy-backs nicely on using Matrix for distributing the metadata.</li>
  6871. <li>No confusion as to which AS</li>
  6872. </ul>
  6873. </li>
  6874. <li>Cons:
  6875. <ul>
  6876. <li>Doesn't work with E2E</li>
  6877. <li>We might want to decouple the implementation of the spider from the HS, given spider behaviour can be quite complicated and evolve much more rapidly than the HS. It's more like a bot than a core part of the server.</li>
  6878. </ul>
  6879. </li>
  6880. </ul>
  6881. <ol start="4">
  6882. <li>Make the sending client use the preview API and insert the event itself when successful.</li>
  6883. </ol>
  6884. <ul>
  6885. <li>Pros:
  6886. <ul>
  6887. <li>Works well with E2E</li>
  6888. <li>No custom server functionality</li>
  6889. <li>Lets the client customise the preview that they send (like on FB)</li>
  6890. </ul>
  6891. </li>
  6892. <li>Cons:
  6893. <ul>
  6894. <li>Entirely specific to the sending client, whereas it'd be nice if /any/ URL was correctly previewed if clients support it.</li>
  6895. </ul>
  6896. </li>
  6897. </ul>
  6898. <ol start="5">
  6899. <li>Have the option of specifying a shared (centralised) previewing service used by a room, to avoid all the different HSes in the room DoSing the target.</li>
  6900. </ol>
  6901. <p>Best solution is probably a combination of both 2 and 4.</p>
  6902. <ul>
  6903. <li>Sending clients do their best to create and send a preview at the point of sending the message, perhaps delaying the message until the preview is computed? (This also lets the user validate the preview before sending)</li>
  6904. <li>Receiving clients have the option of going and creating their own preview if one doesn't arrive soon enough (or if the original sender didn't create one)</li>
  6905. </ul>
  6906. <p>This is a bit magical though in that the preview could come from two entirely different sources - the sending HS or your local one. However, this can always be exposed to users: &quot;Generate your own URL previews if none are available?&quot;</p>
  6907. <p>This is tantamount also to senders calculating their own thumbnails for sending in advance of the main content - we are trusting the sender not to lie about the content in the thumbnail. Whereas currently thumbnails are calculated by the receiving homeserver to avoid this attack.</p>
  6908. <p>However, this kind of phishing attack does exist whether we let senders pick their thumbnails or not, in that a malicious sender can send normal text messages around the attachment claiming it to be legitimate. We could rely on (future) reputation/abuse management to punish users who phish (be it with bogus metadata or bogus descriptions). Bogus metadata is particularly bad though, especially if it's avoidable.</p>
  6909. <p>As a first cut, let's do #2 and have the receiver hit the API to calculate its own previews (as it does currently for image thumbnails). We can then extend/optimise this to option 4 as a special extra if needed.</p>
  6910. <h2 id="api"><a class="header" href="#api">API</a></h2>
  6911. <pre><code>GET /_matrix/media/r0/preview_url?url=http://wherever.com
  6912. 200 OK
  6913. {
  6914. &quot;og:type&quot; : &quot;article&quot;
  6915. &quot;og:url&quot; : &quot;https://twitter.com/matrixdotorg/status/684074366691356672&quot;
  6916. &quot;og:title&quot; : &quot;Matrix on Twitter&quot;
  6917. &quot;og:image&quot; : &quot;https://pbs.twimg.com/profile_images/500400952029888512/yI0qtFi7_400x400.png&quot;
  6918. &quot;og:description&quot; : &quot;“Synapse 0.12 is out! Lots of polishing, performance &amp;amp;amp; bugfixes: /sync API, /r0 prefix, fulltext search, 3PID invites https://t.co/5alhXLLEGP”&quot;
  6919. &quot;og:site_name&quot; : &quot;Twitter&quot;
  6920. }
  6921. </code></pre>
  6922. <ul>
  6923. <li>Downloads the URL
  6924. <ul>
  6925. <li>If HTML, just stores it in RAM and parses it for OG meta tags
  6926. <ul>
  6927. <li>Download any media OG meta tags to the media repo, and refer to them in the OG via mxc:// URIs.</li>
  6928. </ul>
  6929. </li>
  6930. <li>If a media filetype we know we can thumbnail: store it on disk, and hand it to the thumbnailer. Generate OG meta tags from the thumbnailer contents.</li>
  6931. <li>Otherwise, don't bother downloading further.</li>
  6932. </ul>
  6933. </li>
  6934. </ul>
  6935. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="user-directory-api-implementation"><a class="header" href="#user-directory-api-implementation">User Directory API Implementation</a></h1>
  6936. <p>The user directory is currently maintained based on the 'visible' users
  6937. on this particular server - i.e. ones which your account shares a room with, or
  6938. who are present in a publicly viewable room present on the server.</p>
  6939. <p>The directory info is stored in various tables, which can (typically after
  6940. DB corruption) get stale or out of sync. If this happens, for now the
  6941. solution to fix it is to execute the SQL <a href="https://github.com/matrix-org/synapse/blob/master/synapse/storage/schema/main/delta/53/user_dir_populate.sql">here</a>
  6942. and then restart synapse. This should then start a background task to
  6943. flush the current tables and regenerate the directory.</p>
  6944. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="message-retention-policies"><a class="header" href="#message-retention-policies">Message retention policies</a></h1>
  6945. <p>Synapse admins can enable support for message retention policies on
  6946. their homeserver. Message retention policies exist at a room level,
  6947. follow the semantics described in
  6948. <a href="https://github.com/matrix-org/matrix-doc/blob/matthew/msc1763/proposals/1763-configurable-retention-periods.md">MSC1763</a>,
  6949. and allow server and room admins to configure how long messages should
  6950. be kept in a homeserver's database before being purged from it.
  6951. <strong>Please note that, as this feature isn't part of the Matrix
  6952. specification yet, this implementation is to be considered as
  6953. experimental.</strong> </p>
  6954. <p>A message retention policy is mainly defined by its <code>max_lifetime</code>
  6955. parameter, which defines how long a message can be kept around after
  6956. it was sent to the room. If a room doesn't have a message retention
  6957. policy, and there's no default one for a given server, then no message
  6958. sent in that room is ever purged on that server.</p>
  6959. <p>MSC1763 also specifies semantics for a <code>min_lifetime</code> parameter which
  6960. defines the amount of time after which an event <em>can</em> get purged (after
  6961. it was sent to the room), but Synapse doesn't currently support it
  6962. beyond registering it.</p>
  6963. <p>Both <code>max_lifetime</code> and <code>min_lifetime</code> are optional parameters.</p>
  6964. <p>Note that message retention policies don't apply to state events.</p>
  6965. <p>Once an event reaches its expiry date (defined as the time it was sent
  6966. plus the value for <code>max_lifetime</code> in the room), two things happen:</p>
  6967. <ul>
  6968. <li>Synapse stops serving the event to clients via any endpoint.</li>
  6969. <li>The message gets picked up by the next purge job (see the &quot;Purge jobs&quot;
  6970. section) and is removed from Synapse's database.</li>
  6971. </ul>
  6972. <p>Since purge jobs don't run continuously, this means that an event might
  6973. stay in a server's database for longer than the value for <code>max_lifetime</code>
  6974. in the room would allow, though hidden from clients.</p>
  6975. <p>Similarly, if a server (with support for message retention policies
  6976. enabled) receives from another server an event that should have been
  6977. purged according to its room's policy, then the receiving server will
  6978. process and store that event until it's picked up by the next purge job,
  6979. though it will always hide it from clients.</p>
  6980. <p>Synapse requires at least one message in each room, so it will never
  6981. delete the last message in a room. It will, however, hide it from
  6982. clients.</p>
  6983. <h2 id="server-configuration"><a class="header" href="#server-configuration">Server configuration</a></h2>
  6984. <p>Support for this feature can be enabled and configured in the
  6985. <code>retention</code> section of the Synapse configuration file (see the
  6986. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample file</a>).</p>
  6987. <p>To enable support for message retention policies, set the setting
  6988. <code>enabled</code> in this section to <code>true</code>.</p>
  6989. <h3 id="default-policy"><a class="header" href="#default-policy">Default policy</a></h3>
  6990. <p>A default message retention policy is a policy defined in Synapse's
  6991. configuration that is used by Synapse for every room that doesn't have a
  6992. message retention policy configured in its state. This allows server
  6993. admins to ensure that messages are never kept indefinitely in a server's
  6994. database. </p>
  6995. <p>A default policy can be defined as such, in the <code>retention</code> section of
  6996. the configuration file:</p>
  6997. <pre><code class="language-yaml"> default_policy:
  6998. min_lifetime: 1d
  6999. max_lifetime: 1y
  7000. </code></pre>
  7001. <p>Here, <code>min_lifetime</code> and <code>max_lifetime</code> have the same meaning and level
  7002. of support as previously described. They can be expressed either as a
  7003. duration (using the units <code>s</code> (seconds), <code>m</code> (minutes), <code>h</code> (hours),
  7004. <code>d</code> (days), <code>w</code> (weeks) and <code>y</code> (years)) or as a number of milliseconds.</p>
  7005. <h3 id="purge-jobs"><a class="header" href="#purge-jobs">Purge jobs</a></h3>
  7006. <p>Purge jobs are the jobs that Synapse runs in the background to purge
  7007. expired events from the database. They are only run if support for
  7008. message retention policies is enabled in the server's configuration. If
  7009. no configuration for purge jobs is configured by the server admin,
  7010. Synapse will use a default configuration, which is described in the
  7011. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample configuration file</a>.</p>
  7012. <p>Some server admins might want a finer control on when events are removed
  7013. depending on an event's room's policy. This can be done by setting the
  7014. <code>purge_jobs</code> sub-section in the <code>retention</code> section of the configuration
  7015. file. An example of such configuration could be:</p>
  7016. <pre><code class="language-yaml"> purge_jobs:
  7017. - longest_max_lifetime: 3d
  7018. interval: 12h
  7019. - shortest_max_lifetime: 3d
  7020. longest_max_lifetime: 1w
  7021. interval: 1d
  7022. - shortest_max_lifetime: 1w
  7023. interval: 2d
  7024. </code></pre>
  7025. <p>In this example, we define three jobs:</p>
  7026. <ul>
  7027. <li>one that runs twice a day (every 12 hours) and purges events in rooms
  7028. which policy's <code>max_lifetime</code> is lower or equal to 3 days.</li>
  7029. <li>one that runs once a day and purges events in rooms which policy's
  7030. <code>max_lifetime</code> is between 3 days and a week.</li>
  7031. <li>one that runs once every 2 days and purges events in rooms which
  7032. policy's <code>max_lifetime</code> is greater than a week.</li>
  7033. </ul>
  7034. <p>Note that this example is tailored to show different configurations and
  7035. features slightly more jobs than it's probably necessary (in practice, a
  7036. server admin would probably consider it better to replace the two last
  7037. jobs with one that runs once a day and handles rooms which which
  7038. policy's <code>max_lifetime</code> is greater than 3 days).</p>
  7039. <p>Keep in mind, when configuring these jobs, that a purge job can become
  7040. quite heavy on the server if it targets many rooms, therefore prefer
  7041. having jobs with a low interval that target a limited set of rooms. Also
  7042. make sure to include a job with no minimum and one with no maximum to
  7043. make sure your configuration handles every policy.</p>
  7044. <p>As previously mentioned in this documentation, while a purge job that
  7045. runs e.g. every day means that an expired event might stay in the
  7046. database for up to a day after its expiry, Synapse hides expired events
  7047. from clients as soon as they expire, so the event is not visible to
  7048. local users between its expiry date and the moment it gets purged from
  7049. the server's database.</p>
  7050. <h3 id="lifetime-limits"><a class="header" href="#lifetime-limits">Lifetime limits</a></h3>
  7051. <p>Server admins can set limits on the values of <code>max_lifetime</code> to use when
  7052. purging old events in a room. These limits can be defined as such in the
  7053. <code>retention</code> section of the configuration file:</p>
  7054. <pre><code class="language-yaml"> allowed_lifetime_min: 1d
  7055. allowed_lifetime_max: 1y
  7056. </code></pre>
  7057. <p>The limits are considered when running purge jobs. If necessary, the
  7058. effective value of <code>max_lifetime</code> will be brought between
  7059. <code>allowed_lifetime_min</code> and <code>allowed_lifetime_max</code> (inclusive).
  7060. This means that, if the value of <code>max_lifetime</code> defined in the room's state
  7061. is lower than <code>allowed_lifetime_min</code>, the value of <code>allowed_lifetime_min</code>
  7062. will be used instead. Likewise, if the value of <code>max_lifetime</code> is higher
  7063. than <code>allowed_lifetime_max</code>, the value of <code>allowed_lifetime_max</code> will be
  7064. used instead.</p>
  7065. <p>In the example above, we ensure Synapse never deletes events that are less
  7066. than one day old, and that it always deletes events that are over a year
  7067. old.</p>
  7068. <p>If a default policy is set, and its <code>max_lifetime</code> value is lower than
  7069. <code>allowed_lifetime_min</code> or higher than <code>allowed_lifetime_max</code>, the same
  7070. process applies.</p>
  7071. <p>Both parameters are optional; if one is omitted Synapse won't use it to
  7072. adjust the effective value of <code>max_lifetime</code>.</p>
  7073. <p>Like other settings in this section, these parameters can be expressed
  7074. either as a duration or as a number of milliseconds.</p>
  7075. <h2 id="room-configuration"><a class="header" href="#room-configuration">Room configuration</a></h2>
  7076. <p>To configure a room's message retention policy, a room's admin or
  7077. moderator needs to send a state event in that room with the type
  7078. <code>m.room.retention</code> and the following content:</p>
  7079. <pre><code class="language-json">{
  7080. &quot;max_lifetime&quot;: ...
  7081. }
  7082. </code></pre>
  7083. <p>In this event's content, the <code>max_lifetime</code> parameter has the same
  7084. meaning as previously described, and needs to be expressed in
  7085. milliseconds. The event's content can also include a <code>min_lifetime</code>
  7086. parameter, which has the same meaning and limited support as previously
  7087. described.</p>
  7088. <p>Note that over every server in the room, only the ones with support for
  7089. message retention policies will actually remove expired events. This
  7090. support is currently not enabled by default in Synapse.</p>
  7091. <h2 id="note-on-reclaiming-disk-space"><a class="header" href="#note-on-reclaiming-disk-space">Note on reclaiming disk space</a></h2>
  7092. <p>While purge jobs actually delete data from the database, the disk space
  7093. used by the database might not decrease immediately on the database's
  7094. host. However, even though the database engine won't free up the disk
  7095. space, it will start writing new data into where the purged data was.</p>
  7096. <p>If you want to reclaim the freed disk space anyway and return it to the
  7097. operating system, the server admin needs to run <code>VACUUM FULL;</code> (or
  7098. <code>VACUUM;</code> for SQLite databases) on Synapse's database (see the related
  7099. <a href="https://www.postgresql.org/docs/current/sql-vacuum.html">PostgreSQL documentation</a>).</p>
  7100. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="modules"><a class="header" href="#modules">Modules</a></h1>
  7101. <p>Synapse supports extending its functionality by configuring external modules.</p>
  7102. <h2 id="using-modules"><a class="header" href="#using-modules">Using modules</a></h2>
  7103. <p>To use a module on Synapse, add it to the <code>modules</code> section of the configuration file:</p>
  7104. <pre><code class="language-yaml">modules:
  7105. - module: my_super_module.MySuperClass
  7106. config:
  7107. do_thing: true
  7108. - module: my_other_super_module.SomeClass
  7109. config: {}
  7110. </code></pre>
  7111. <p>Each module is defined by a path to a Python class as well as a configuration. This
  7112. information for a given module should be available in the module's own documentation.</p>
  7113. <p><strong>Note</strong>: When using third-party modules, you effectively allow someone else to run
  7114. custom code on your Synapse homeserver. Server admins are encouraged to verify the
  7115. provenance of the modules they use on their homeserver and make sure the modules aren't
  7116. running malicious code on their instance.</p>
  7117. <p>Also note that we are currently in the process of migrating module interfaces to this
  7118. system. While some interfaces might be compatible with it, others still require
  7119. configuring modules in another part of Synapse's configuration file. Currently, only the
  7120. spam checker interface is compatible with this new system.</p>
  7121. <h2 id="writing-a-module"><a class="header" href="#writing-a-module">Writing a module</a></h2>
  7122. <p>A module is a Python class that uses Synapse's module API to interact with the
  7123. homeserver. It can register callbacks that Synapse will call on specific operations, as
  7124. well as web resources to attach to Synapse's web server.</p>
  7125. <p>When instantiated, a module is given its parsed configuration as well as an instance of
  7126. the <code>synapse.module_api.ModuleApi</code> class. The configuration is a dictionary, and is
  7127. either the output of the module's <code>parse_config</code> static method (see below), or the
  7128. configuration associated with the module in Synapse's configuration file.</p>
  7129. <p>See the documentation for the <code>ModuleApi</code> class
  7130. <a href="https://github.com/matrix-org/synapse/blob/master/synapse/module_api/__init__.py">here</a>.</p>
  7131. <h3 id="handling-the-modules-configuration"><a class="header" href="#handling-the-modules-configuration">Handling the module's configuration</a></h3>
  7132. <p>A module can implement the following static method:</p>
  7133. <pre><code class="language-python">@staticmethod
  7134. def parse_config(config: dict) -&gt; dict
  7135. </code></pre>
  7136. <p>This method is given a dictionary resulting from parsing the YAML configuration for the
  7137. module. It may modify it (for example by parsing durations expressed as strings (e.g.
  7138. &quot;5d&quot;) into milliseconds, etc.), and return the modified dictionary. It may also verify
  7139. that the configuration is correct, and raise an instance of
  7140. <code>synapse.module_api.errors.ConfigError</code> if not.</p>
  7141. <h3 id="registering-a-web-resource"><a class="header" href="#registering-a-web-resource">Registering a web resource</a></h3>
  7142. <p>Modules can register web resources onto Synapse's web server using the following module
  7143. API method:</p>
  7144. <pre><code class="language-python">def ModuleApi.register_web_resource(path: str, resource: IResource) -&gt; None
  7145. </code></pre>
  7146. <p>The path is the full absolute path to register the resource at. For example, if you
  7147. register a resource for the path <code>/_synapse/client/my_super_module/say_hello</code>, Synapse
  7148. will serve it at <code>http(s)://[HS_URL]/_synapse/client/my_super_module/say_hello</code>. Note
  7149. that Synapse does not allow registering resources for several sub-paths in the <code>/_matrix</code>
  7150. namespace (such as anything under <code>/_matrix/client</code> for example). It is strongly
  7151. recommended that modules register their web resources under the <code>/_synapse/client</code>
  7152. namespace.</p>
  7153. <p>The provided resource is a Python class that implements Twisted's <a href="https://twistedmatrix.com/documents/current/api/twisted.web.resource.IResource.html">IResource</a>
  7154. interface (such as <a href="https://twistedmatrix.com/documents/current/api/twisted.web.resource.Resource.html">Resource</a>).</p>
  7155. <p>Only one resource can be registered for a given path. If several modules attempt to
  7156. register a resource for the same path, the module that appears first in Synapse's
  7157. configuration file takes priority.</p>
  7158. <p>Modules <strong>must</strong> register their web resources in their <code>__init__</code> method.</p>
  7159. <h3 id="registering-a-callback"><a class="header" href="#registering-a-callback">Registering a callback</a></h3>
  7160. <p>Modules can use Synapse's module API to register callbacks. Callbacks are functions that
  7161. Synapse will call when performing specific actions. Callbacks must be asynchronous, and
  7162. are split in categories. A single module may implement callbacks from multiple categories,
  7163. and is under no obligation to implement all callbacks from the categories it registers
  7164. callbacks for.</p>
  7165. <p>Modules can register callbacks using one of the module API's <code>register_[...]_callbacks</code>
  7166. methods. The callback functions are passed to these methods as keyword arguments, with
  7167. the callback name as the argument name and the function as its value. This is demonstrated
  7168. in the example below. A <code>register_[...]_callbacks</code> method exists for each module type
  7169. documented in this section.</p>
  7170. <h4 id="spam-checker-callbacks"><a class="header" href="#spam-checker-callbacks">Spam checker callbacks</a></h4>
  7171. <p>Spam checker callbacks allow module developers to implement spam mitigation actions for
  7172. Synapse instances. Spam checker callbacks can be registered using the module API's
  7173. <code>register_spam_checker_callbacks</code> method.</p>
  7174. <p>The available spam checker callbacks are:</p>
  7175. <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]
  7176. </code></pre>
  7177. <p>Called when receiving an event from a client or via federation. The module can return
  7178. either a <code>bool</code> to indicate whether the event must be rejected because of spam, or a <code>str</code>
  7179. to indicate the event must be rejected because of spam and to give a rejection reason to
  7180. forward to clients.</p>
  7181. <pre><code class="language-python">async def user_may_invite(inviter: str, invitee: str, room_id: str) -&gt; bool
  7182. </code></pre>
  7183. <p>Called when processing an invitation. The module must return a <code>bool</code> indicating whether
  7184. the inviter can invite the invitee to the given room. Both inviter and invitee are
  7185. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7186. <pre><code class="language-python">async def user_may_create_room(user: str) -&gt; bool
  7187. </code></pre>
  7188. <p>Called when processing a room creation request. The module must return a <code>bool</code> indicating
  7189. whether the given user (represented by their Matrix user ID) is allowed to create a room.</p>
  7190. <pre><code class="language-python">async def user_may_create_room_alias(user: str, room_alias: &quot;synapse.types.RoomAlias&quot;) -&gt; bool
  7191. </code></pre>
  7192. <p>Called when trying to associate an alias with an existing room. The module must return a
  7193. <code>bool</code> indicating whether the given user (represented by their Matrix user ID) is allowed
  7194. to set the given alias.</p>
  7195. <pre><code class="language-python">async def user_may_publish_room(user: str, room_id: str) -&gt; bool
  7196. </code></pre>
  7197. <p>Called when trying to publish a room to the homeserver's public rooms directory. The
  7198. module must return a <code>bool</code> indicating whether the given user (represented by their
  7199. Matrix user ID) is allowed to publish the given room.</p>
  7200. <pre><code class="language-python">async def check_username_for_spam(user_profile: Dict[str, str]) -&gt; bool
  7201. </code></pre>
  7202. <p>Called when computing search results in the user directory. The module must return a
  7203. <code>bool</code> indicating whether the given user profile can appear in search results. The profile
  7204. is represented as a dictionary with the following keys:</p>
  7205. <ul>
  7206. <li><code>user_id</code>: The Matrix ID for this user.</li>
  7207. <li><code>display_name</code>: The user's display name.</li>
  7208. <li><code>avatar_url</code>: The <code>mxc://</code> URL to the user's avatar.</li>
  7209. </ul>
  7210. <p>The module is given a copy of the original dictionary, so modifying it from within the
  7211. module cannot modify a user's profile when included in user directory search results.</p>
  7212. <pre><code class="language-python">async def check_registration_for_spam(
  7213. email_threepid: Optional[dict],
  7214. username: Optional[str],
  7215. request_info: Collection[Tuple[str, str]],
  7216. auth_provider_id: Optional[str] = None,
  7217. ) -&gt; &quot;synapse.spam_checker_api.RegistrationBehaviour&quot;
  7218. </code></pre>
  7219. <p>Called when registering a new user. The module must return a <code>RegistrationBehaviour</code>
  7220. indicating whether the registration can go through or must be denied, or whether the user
  7221. may be allowed to register but will be shadow banned.</p>
  7222. <p>The arguments passed to this callback are:</p>
  7223. <ul>
  7224. <li><code>email_threepid</code>: The email address used for registering, if any.</li>
  7225. <li><code>username</code>: The username the user would like to register. Can be <code>None</code>, meaning that
  7226. Synapse will generate one later.</li>
  7227. <li><code>request_info</code>: A collection of tuples, which first item is a user agent, and which
  7228. second item is an IP address. These user agents and IP addresses are the ones that were
  7229. used during the registration process.</li>
  7230. <li><code>auth_provider_id</code>: The identifier of the SSO authentication provider, if any.</li>
  7231. </ul>
  7232. <pre><code class="language-python">async def check_media_file_for_spam(
  7233. file_wrapper: &quot;synapse.rest.media.v1.media_storage.ReadableFileWrapper&quot;,
  7234. file_info: &quot;synapse.rest.media.v1._base.FileInfo&quot;,
  7235. ) -&gt; bool
  7236. </code></pre>
  7237. <p>Called when storing a local or remote file. The module must return a boolean indicating
  7238. whether the given file can be stored in the homeserver's media store.</p>
  7239. <h4 id="account-validity-callbacks"><a class="header" href="#account-validity-callbacks">Account validity callbacks</a></h4>
  7240. <p>Account validity callbacks allow module developers to add extra steps to verify the
  7241. validity on an account, i.e. see if a user can be granted access to their account on the
  7242. Synapse instance. Account validity callbacks can be registered using the module API's
  7243. <code>register_account_validity_callbacks</code> method.</p>
  7244. <p>The available account validity callbacks are:</p>
  7245. <pre><code class="language-python">async def is_user_expired(user: str) -&gt; Optional[bool]
  7246. </code></pre>
  7247. <p>Called when processing any authenticated request (except for logout requests). The module
  7248. can return a <code>bool</code> to indicate whether the user has expired and should be locked out of
  7249. their account, or <code>None</code> if the module wasn't able to figure it out. The user is
  7250. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7251. <p>If the module returns <code>True</code>, the current request will be denied with the error code
  7252. <code>ORG_MATRIX_EXPIRED_ACCOUNT</code> and the HTTP status code 403. Note that this doesn't
  7253. invalidate the user's access token.</p>
  7254. <pre><code class="language-python">async def on_user_registration(user: str) -&gt; None
  7255. </code></pre>
  7256. <p>Called after successfully registering a user, in case the module needs to perform extra
  7257. operations to keep track of them. (e.g. add them to a database table). The user is
  7258. represented by their Matrix user ID.</p>
  7259. <h4 id="third-party-rules-callbacks"><a class="header" href="#third-party-rules-callbacks">Third party rules callbacks</a></h4>
  7260. <p>Third party rules callbacks allow module developers to add extra checks to verify the
  7261. validity of incoming events. Third party event rules callbacks can be registered using
  7262. the module API's <code>register_third_party_rules_callbacks</code> method.</p>
  7263. <p>The available third party rules callbacks are:</p>
  7264. <pre><code class="language-python">async def check_event_allowed(
  7265. event: &quot;synapse.events.EventBase&quot;,
  7266. state_events: &quot;synapse.types.StateMap&quot;,
  7267. ) -&gt; Tuple[bool, Optional[dict]]
  7268. </code></pre>
  7269. <p><strong><span style="color:red">
  7270. This callback is very experimental and can and will break without notice. Module developers
  7271. are encouraged to implement <code>check_event_for_spam</code> from the spam checker category instead.
  7272. </span></strong></p>
  7273. <p>Called when processing any incoming event, with the event and a <code>StateMap</code>
  7274. representing the current state of the room the event is being sent into. A <code>StateMap</code> is
  7275. a dictionary that maps tuples containing an event type and a state key to the
  7276. corresponding state event. For example retrieving the room's <code>m.room.create</code> event from
  7277. the <code>state_events</code> argument would look like this: <code>state_events.get((&quot;m.room.create&quot;, &quot;&quot;))</code>.
  7278. The module must return a boolean indicating whether the event can be allowed.</p>
  7279. <p>Note that this callback function processes incoming events coming via federation
  7280. traffic (on top of client traffic). This means denying an event might cause the local
  7281. copy of the room's history to diverge from that of remote servers. This may cause
  7282. federation issues in the room. It is strongly recommended to only deny events using this
  7283. callback function if the sender is a local user, or in a private federation in which all
  7284. servers are using the same module, with the same configuration.</p>
  7285. <p>If the boolean returned by the module is <code>True</code>, it may also tell Synapse to replace the
  7286. event with new data by returning the new event's data as a dictionary. In order to do
  7287. that, it is recommended the module calls <code>event.get_dict()</code> to get the current event as a
  7288. dictionary, and modify the returned dictionary accordingly.</p>
  7289. <p>Note that replacing the event only works for events sent by local users, not for events
  7290. received over federation.</p>
  7291. <pre><code class="language-python">async def on_create_room(
  7292. requester: &quot;synapse.types.Requester&quot;,
  7293. request_content: dict,
  7294. is_requester_admin: bool,
  7295. ) -&gt; None
  7296. </code></pre>
  7297. <p>Called when processing a room creation request, with the <code>Requester</code> object for the user
  7298. performing the request, a dictionary representing the room creation request's JSON body
  7299. (see <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom">the spec</a>
  7300. for a list of possible parameters), and a boolean indicating whether the user performing
  7301. the request is a server admin.</p>
  7302. <p>Modules can modify the <code>request_content</code> (by e.g. adding events to its <code>initial_state</code>),
  7303. or deny the room's creation by raising a <code>module_api.errors.SynapseError</code>.</p>
  7304. <h3 id="porting-an-existing-module-that-uses-the-old-interface"><a class="header" href="#porting-an-existing-module-that-uses-the-old-interface">Porting an existing module that uses the old interface</a></h3>
  7305. <p>In order to port a module that uses Synapse's old module interface, its author needs to:</p>
  7306. <ul>
  7307. <li>ensure the module's callbacks are all asynchronous.</li>
  7308. <li>register their callbacks using one or more of the <code>register_[...]_callbacks</code> methods
  7309. from the <code>ModuleApi</code> class in the module's <code>__init__</code> method (see <a href="modules.html#registering-a-callback">this section</a>
  7310. for more info).</li>
  7311. </ul>
  7312. <p>Additionally, if the module is packaged with an additional web resource, the module
  7313. should register this resource in its <code>__init__</code> method using the <code>register_web_resource</code>
  7314. method from the <code>ModuleApi</code> class (see <a href="modules.html#registering-a-web-resource">this section</a> for
  7315. more info).</p>
  7316. <p>The module's author should also update any example in the module's configuration to only
  7317. use the new <code>modules</code> section in Synapse's configuration file (see <a href="modules.html#using-modules">this section</a>
  7318. for more info).</p>
  7319. <h3 id="example"><a class="header" href="#example">Example</a></h3>
  7320. <p>The example below is a module that implements the spam checker callback
  7321. <code>user_may_create_room</code> to deny room creation to user <code>@evilguy:example.com</code>, and registers
  7322. a web resource to the path <code>/_synapse/client/demo/hello</code> that returns a JSON object.</p>
  7323. <pre><code class="language-python">import json
  7324. from twisted.web.resource import Resource
  7325. from twisted.web.server import Request
  7326. from synapse.module_api import ModuleApi
  7327. class DemoResource(Resource):
  7328. def __init__(self, config):
  7329. super(DemoResource, self).__init__()
  7330. self.config = config
  7331. def render_GET(self, request: Request):
  7332. name = request.args.get(b&quot;name&quot;)[0]
  7333. request.setHeader(b&quot;Content-Type&quot;, b&quot;application/json&quot;)
  7334. return json.dumps({&quot;hello&quot;: name})
  7335. class DemoModule:
  7336. def __init__(self, config: dict, api: ModuleApi):
  7337. self.config = config
  7338. self.api = api
  7339. self.api.register_web_resource(
  7340. path=&quot;/_synapse/client/demo/hello&quot;,
  7341. resource=DemoResource(self.config),
  7342. )
  7343. self.api.register_spam_checker_callbacks(
  7344. user_may_create_room=self.user_may_create_room,
  7345. )
  7346. @staticmethod
  7347. def parse_config(config):
  7348. return config
  7349. async def user_may_create_room(self, user: str) -&gt; bool:
  7350. if user == &quot;@evilguy:example.com&quot;:
  7351. return False
  7352. return True
  7353. </code></pre>
  7354. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h2 style="color:red">
  7355. This page of the Synapse documentation is now deprecated. For up to date
  7356. documentation on setting up or writing a spam checker module, please see
  7357. <a href="modules.html">this page</a>.
  7358. </h2>
  7359. <h1 id="handling-spam-in-synapse"><a class="header" href="#handling-spam-in-synapse">Handling spam in Synapse</a></h1>
  7360. <p>Synapse has support to customize spam checking behavior. It can plug into a
  7361. variety of events and affect how they are presented to users on your homeserver.</p>
  7362. <p>The spam checking behavior is implemented as a Python class, which must be
  7363. able to be imported by the running Synapse.</p>
  7364. <h2 id="python-spam-checker-class"><a class="header" href="#python-spam-checker-class">Python spam checker class</a></h2>
  7365. <p>The Python class is instantiated with two objects:</p>
  7366. <ul>
  7367. <li>Any configuration (see below).</li>
  7368. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7369. </ul>
  7370. <p>It then implements methods which return a boolean to alter behavior in Synapse.
  7371. All the methods must be defined.</p>
  7372. <p>There's a generic method for checking every event (<code>check_event_for_spam</code>), as
  7373. well as some specific methods:</p>
  7374. <ul>
  7375. <li><code>user_may_invite</code></li>
  7376. <li><code>user_may_create_room</code></li>
  7377. <li><code>user_may_create_room_alias</code></li>
  7378. <li><code>user_may_publish_room</code></li>
  7379. <li><code>check_username_for_spam</code></li>
  7380. <li><code>check_registration_for_spam</code></li>
  7381. <li><code>check_media_file_for_spam</code></li>
  7382. </ul>
  7383. <p>The details of each of these methods (as well as their inputs and outputs)
  7384. are documented in the <code>synapse.events.spamcheck.SpamChecker</code> class.</p>
  7385. <p>The <code>ModuleApi</code> class provides a way for the custom spam checker class to
  7386. call back into the homeserver internals.</p>
  7387. <p>Additionally, a <code>parse_config</code> method is mandatory and receives the plugin config
  7388. dictionary. After parsing, It must return an object which will be
  7389. passed to <code>__init__</code> later.</p>
  7390. <h3 id="example-1"><a class="header" href="#example-1">Example</a></h3>
  7391. <pre><code class="language-python">from synapse.spam_checker_api import RegistrationBehaviour
  7392. class ExampleSpamChecker:
  7393. def __init__(self, config, api):
  7394. self.config = config
  7395. self.api = api
  7396. @staticmethod
  7397. def parse_config(config):
  7398. return config
  7399. async def check_event_for_spam(self, foo):
  7400. return False # allow all events
  7401. async def user_may_invite(self, inviter_userid, invitee_userid, room_id):
  7402. return True # allow all invites
  7403. async def user_may_create_room(self, userid):
  7404. return True # allow all room creations
  7405. async def user_may_create_room_alias(self, userid, room_alias):
  7406. return True # allow all room aliases
  7407. async def user_may_publish_room(self, userid, room_id):
  7408. return True # allow publishing of all rooms
  7409. async def check_username_for_spam(self, user_profile):
  7410. return False # allow all usernames
  7411. async def check_registration_for_spam(
  7412. self,
  7413. email_threepid,
  7414. username,
  7415. request_info,
  7416. auth_provider_id,
  7417. ):
  7418. return RegistrationBehaviour.ALLOW # allow all registrations
  7419. async def check_media_file_for_spam(self, file_wrapper, file_info):
  7420. return False # allow all media
  7421. </code></pre>
  7422. <h2 id="configuration-2"><a class="header" href="#configuration-2">Configuration</a></h2>
  7423. <p>Modify the <code>spam_checker</code> section of your <code>homeserver.yaml</code> in the following
  7424. manner:</p>
  7425. <p>Create a list entry with the keys <code>module</code> and <code>config</code>.</p>
  7426. <ul>
  7427. <li>
  7428. <p><code>module</code> should point to the fully qualified Python class that implements your
  7429. custom logic, e.g. <code>my_module.ExampleSpamChecker</code>.</p>
  7430. </li>
  7431. <li>
  7432. <p><code>config</code> is a dictionary that gets passed to the spam checker class.</p>
  7433. </li>
  7434. </ul>
  7435. <h3 id="example-2"><a class="header" href="#example-2">Example</a></h3>
  7436. <p>This section might look like:</p>
  7437. <pre><code class="language-yaml">spam_checker:
  7438. - module: my_module.ExampleSpamChecker
  7439. config:
  7440. # Enable or disable a specific option in ExampleSpamChecker.
  7441. my_custom_option: true
  7442. </code></pre>
  7443. <p>More spam checkers can be added in tandem by appending more items to the list. An
  7444. action is blocked when at least one of the configured spam checkers flags it.</p>
  7445. <h2 id="examples"><a class="header" href="#examples">Examples</a></h2>
  7446. <p>The <a href="https://github.com/matrix-org/mjolnir">Mjolnir</a> project is a full fledged
  7447. example using the Synapse spam checking API, including a bot for dynamic
  7448. configuration.</p>
  7449. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="presence-router-module"><a class="header" href="#presence-router-module">Presence Router Module</a></h1>
  7450. <p>Synapse supports configuring a module that can specify additional users
  7451. (local or remote) to should receive certain presence updates from local
  7452. users.</p>
  7453. <p>Note that routing presence via Application Service transactions is not
  7454. currently supported.</p>
  7455. <p>The presence routing module is implemented as a Python class, which will
  7456. be imported by the running Synapse.</p>
  7457. <h2 id="python-presence-router-class"><a class="header" href="#python-presence-router-class">Python Presence Router Class</a></h2>
  7458. <p>The Python class is instantiated with two objects:</p>
  7459. <ul>
  7460. <li>A configuration object of some type (see below).</li>
  7461. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7462. </ul>
  7463. <p>It then implements methods related to presence routing.</p>
  7464. <p>Note that one method of <code>ModuleApi</code> that may be useful is:</p>
  7465. <pre><code class="language-python">async def ModuleApi.send_local_online_presence_to(users: Iterable[str]) -&gt; None
  7466. </code></pre>
  7467. <p>which can be given a list of local or remote MXIDs to broadcast known, online user
  7468. presence to (for those users that the receiving user is considered interested in).
  7469. It does not include state for users who are currently offline, and it can only be
  7470. called on workers that support sending federation. Additionally, this method must
  7471. only be called from the process that has been configured to write to the
  7472. the <a href="workers.html#stream-writers">presence stream</a>.
  7473. By default, this is the main process, but another worker can be configured to do
  7474. so.</p>
  7475. <h3 id="module-structure"><a class="header" href="#module-structure">Module structure</a></h3>
  7476. <p>Below is a list of possible methods that can be implemented, and whether they are
  7477. required.</p>
  7478. <h4 id="parse_config"><a class="header" href="#parse_config"><code>parse_config</code></a></h4>
  7479. <pre><code class="language-python">def parse_config(config_dict: dict) -&gt; Any
  7480. </code></pre>
  7481. <p><strong>Required.</strong> A static method that is passed a dictionary of config options, and
  7482. should return a validated config object. This method is described further in
  7483. <a href="presence_router_module.html#configuration">Configuration</a>.</p>
  7484. <h4 id="get_users_for_states"><a class="header" href="#get_users_for_states"><code>get_users_for_states</code></a></h4>
  7485. <pre><code class="language-python">async def get_users_for_states(
  7486. self,
  7487. state_updates: Iterable[UserPresenceState],
  7488. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7489. </code></pre>
  7490. <p><strong>Required.</strong> An asynchronous method that is passed an iterable of user presence
  7491. state. This method can determine whether a given presence update should be sent to certain
  7492. users. It does this by returning a dictionary with keys representing local or remote
  7493. Matrix User IDs, and values being a python set
  7494. of <code>synapse.handlers.presence.UserPresenceState</code> instances.</p>
  7495. <p>Synapse will then attempt to send the specified presence updates to each user when
  7496. possible.</p>
  7497. <h4 id="get_interested_users"><a class="header" href="#get_interested_users"><code>get_interested_users</code></a></h4>
  7498. <pre><code class="language-python">async def get_interested_users(self, user_id: str) -&gt; Union[Set[str], str]
  7499. </code></pre>
  7500. <p><strong>Required.</strong> An asynchronous method that is passed a single Matrix User ID. This
  7501. method is expected to return the users that the passed in user may be interested in the
  7502. presence of. Returned users may be local or remote. The presence routed as a result of
  7503. what this method returns is sent in addition to the updates already sent between users
  7504. that share a room together. Presence updates are deduplicated.</p>
  7505. <p>This method should return a python set of Matrix User IDs, or the object
  7506. <code>synapse.events.presence_router.PresenceRouter.ALL_USERS</code> to indicate that the passed
  7507. user should receive presence information for <em>all</em> known users.</p>
  7508. <p>For clarity, if the user <code>@alice:example.org</code> is passed to this method, and the Set
  7509. <code>{&quot;@bob:example.com&quot;, &quot;@charlie:somewhere.org&quot;}</code> is returned, this signifies that Alice
  7510. should receive presence updates sent by Bob and Charlie, regardless of whether these
  7511. users share a room.</p>
  7512. <h3 id="example-3"><a class="header" href="#example-3">Example</a></h3>
  7513. <p>Below is an example implementation of a presence router class.</p>
  7514. <pre><code class="language-python">from typing import Dict, Iterable, Set, Union
  7515. from synapse.events.presence_router import PresenceRouter
  7516. from synapse.handlers.presence import UserPresenceState
  7517. from synapse.module_api import ModuleApi
  7518. class PresenceRouterConfig:
  7519. def __init__(self):
  7520. # Config options with their defaults
  7521. # A list of users to always send all user presence updates to
  7522. self.always_send_to_users = [] # type: List[str]
  7523. # A list of users to ignore presence updates for. Does not affect
  7524. # shared-room presence relationships
  7525. self.blacklisted_users = [] # type: List[str]
  7526. class ExamplePresenceRouter:
  7527. &quot;&quot;&quot;An example implementation of synapse.presence_router.PresenceRouter.
  7528. Supports routing all presence to a configured set of users, or a subset
  7529. of presence from certain users to members of certain rooms.
  7530. Args:
  7531. config: A configuration object.
  7532. module_api: An instance of Synapse's ModuleApi.
  7533. &quot;&quot;&quot;
  7534. def __init__(self, config: PresenceRouterConfig, module_api: ModuleApi):
  7535. self._config = config
  7536. self._module_api = module_api
  7537. @staticmethod
  7538. def parse_config(config_dict: dict) -&gt; PresenceRouterConfig:
  7539. &quot;&quot;&quot;Parse a configuration dictionary from the homeserver config, do
  7540. some validation and return a typed PresenceRouterConfig.
  7541. Args:
  7542. config_dict: The configuration dictionary.
  7543. Returns:
  7544. A validated config object.
  7545. &quot;&quot;&quot;
  7546. # Initialise a typed config object
  7547. config = PresenceRouterConfig()
  7548. always_send_to_users = config_dict.get(&quot;always_send_to_users&quot;)
  7549. blacklisted_users = config_dict.get(&quot;blacklisted_users&quot;)
  7550. # Do some validation of config options... otherwise raise a
  7551. # synapse.config.ConfigError.
  7552. config.always_send_to_users = always_send_to_users
  7553. config.blacklisted_users = blacklisted_users
  7554. return config
  7555. async def get_users_for_states(
  7556. self,
  7557. state_updates: Iterable[UserPresenceState],
  7558. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7559. &quot;&quot;&quot;Given an iterable of user presence updates, determine where each one
  7560. needs to go. Returned results will not affect presence updates that are
  7561. sent between users who share a room.
  7562. Args:
  7563. state_updates: An iterable of user presence state updates.
  7564. Returns:
  7565. A dictionary of user_id -&gt; set of UserPresenceState that the user should
  7566. receive.
  7567. &quot;&quot;&quot;
  7568. destination_users = {} # type: Dict[str, Set[UserPresenceState]
  7569. # Ignore any updates for blacklisted users
  7570. desired_updates = set()
  7571. for update in state_updates:
  7572. if update.state_key not in self._config.blacklisted_users:
  7573. desired_updates.add(update)
  7574. # Send all presence updates to specific users
  7575. for user_id in self._config.always_send_to_users:
  7576. destination_users[user_id] = desired_updates
  7577. return destination_users
  7578. async def get_interested_users(
  7579. self,
  7580. user_id: str,
  7581. ) -&gt; Union[Set[str], PresenceRouter.ALL_USERS]:
  7582. &quot;&quot;&quot;
  7583. Retrieve a list of users that `user_id` is interested in receiving the
  7584. presence of. This will be in addition to those they share a room with.
  7585. Optionally, the object PresenceRouter.ALL_USERS can be returned to indicate
  7586. that this user should receive all incoming local and remote presence updates.
  7587. Note that this method will only be called for local users.
  7588. Args:
  7589. user_id: A user requesting presence updates.
  7590. Returns:
  7591. A set of user IDs to return additional presence updates for, or
  7592. PresenceRouter.ALL_USERS to return presence updates for all other users.
  7593. &quot;&quot;&quot;
  7594. if user_id in self._config.always_send_to_users:
  7595. return PresenceRouter.ALL_USERS
  7596. return set()
  7597. </code></pre>
  7598. <h4 id="a-note-on-get_users_for_states-and-get_interested_users"><a class="header" href="#a-note-on-get_users_for_states-and-get_interested_users">A note on <code>get_users_for_states</code> and <code>get_interested_users</code></a></h4>
  7599. <p>Both of these methods are effectively two different sides of the same coin. The logic
  7600. regarding which users should receive updates for other users should be the same
  7601. between them.</p>
  7602. <p><code>get_users_for_states</code> is called when presence updates come in from either federation
  7603. or local users, and is used to either direct local presence to remote users, or to
  7604. wake up the sync streams of local users to collect remote presence.</p>
  7605. <p>In contrast, <code>get_interested_users</code> is used to determine the users that presence should
  7606. be fetched for when a local user is syncing. This presence is then retrieved, before
  7607. being fed through <code>get_users_for_states</code> once again, with only the syncing user's
  7608. routing information pulled from the resulting dictionary.</p>
  7609. <p>Their routing logic should thus line up, else you may run into unintended behaviour.</p>
  7610. <h2 id="configuration-3"><a class="header" href="#configuration-3">Configuration</a></h2>
  7611. <p>Once you've crafted your module and installed it into the same Python environment as
  7612. Synapse, amend your homeserver config file with the following.</p>
  7613. <pre><code class="language-yaml">presence:
  7614. enabled: true
  7615. presence_router:
  7616. module: my_module.ExamplePresenceRouter
  7617. config:
  7618. # Any configuration options for your module. The below is an example.
  7619. # of setting options for ExamplePresenceRouter.
  7620. always_send_to_users: [&quot;@presence_gobbler:example.org&quot;]
  7621. blacklisted_users:
  7622. - &quot;@alice:example.com&quot;
  7623. - &quot;@bob:example.com&quot;
  7624. ...
  7625. </code></pre>
  7626. <p>The contents of <code>config</code> will be passed as a Python dictionary to the static
  7627. <code>parse_config</code> method of your class. The object returned by this method will
  7628. then be passed to the <code>__init__</code> method of your module as <code>config</code>.</p>
  7629. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="scaling-synapse-via-workers"><a class="header" href="#scaling-synapse-via-workers">Scaling synapse via workers</a></h1>
  7630. <p>For small instances it recommended to run Synapse in the default monolith mode.
  7631. For larger instances where performance is a concern it can be helpful to split
  7632. out functionality into multiple separate python processes. These processes are
  7633. called 'workers', and are (eventually) intended to scale horizontally
  7634. independently.</p>
  7635. <p>Synapse's worker support is under active development and subject to change as
  7636. we attempt to rapidly scale ever larger Synapse instances. However we are
  7637. documenting it here to help admins needing a highly scalable Synapse instance
  7638. similar to the one running <code>matrix.org</code>.</p>
  7639. <p>All processes continue to share the same database instance, and as such,
  7640. workers only work with PostgreSQL-based Synapse deployments. SQLite should only
  7641. be used for demo purposes and any admin considering workers should already be
  7642. running PostgreSQL.</p>
  7643. <p>See also <a href="https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability">Matrix.org blog post</a>
  7644. for a higher level overview.</p>
  7645. <h2 id="main-processworker-communication"><a class="header" href="#main-processworker-communication">Main process/worker communication</a></h2>
  7646. <p>The processes communicate with each other via a Synapse-specific protocol called
  7647. 'replication' (analogous to MySQL- or Postgres-style database replication) which
  7648. feeds streams of newly written data between processes so they can be kept in
  7649. sync with the database state.</p>
  7650. <p>When configured to do so, Synapse uses a
  7651. <a href="https://redis.io/topics/pubsub">Redis pub/sub channel</a> to send the replication
  7652. stream between all configured Synapse processes. Additionally, processes may
  7653. make HTTP requests to each other, primarily for operations which need to wait
  7654. for a reply ─ such as sending an event.</p>
  7655. <p>Redis support was added in v1.13.0 with it becoming the recommended method in
  7656. v1.18.0. It replaced the old direct TCP connections (which is deprecated as of
  7657. v1.18.0) to the main process. With Redis, rather than all the workers connecting
  7658. to the main process, all the workers and the main process connect to Redis,
  7659. which relays replication commands between processes. This can give a significant
  7660. cpu saving on the main process and will be a prerequisite for upcoming
  7661. performance improvements.</p>
  7662. <p>If Redis support is enabled Synapse will use it as a shared cache, as well as a
  7663. pub/sub mechanism.</p>
  7664. <p>See the <a href="workers.html#architectural-diagram">Architectural diagram</a> section at the end for
  7665. a visualisation of what this looks like.</p>
  7666. <h2 id="setting-up-workers"><a class="header" href="#setting-up-workers">Setting up workers</a></h2>
  7667. <p>A Redis server is required to manage the communication between the processes.
  7668. The Redis server should be installed following the normal procedure for your
  7669. distribution (e.g. <code>apt install redis-server</code> on Debian). It is safe to use an
  7670. existing Redis deployment if you have one.</p>
  7671. <p>Once installed, check that Redis is running and accessible from the host running
  7672. Synapse, for example by executing <code>echo PING | nc -q1 localhost 6379</code> and seeing
  7673. a response of <code>+PONG</code>.</p>
  7674. <p>The appropriate dependencies must also be installed for Synapse. If using a
  7675. virtualenv, these can be installed with:</p>
  7676. <pre><code class="language-sh">pip install &quot;matrix-synapse[redis]&quot;
  7677. </code></pre>
  7678. <p>Note that these dependencies are included when synapse is installed with <code>pip install matrix-synapse[all]</code>. They are also included in the debian packages from
  7679. <code>matrix.org</code> and in the docker images at
  7680. https://hub.docker.com/r/matrixdotorg/synapse/.</p>
  7681. <p>To make effective use of the workers, you will need to configure an HTTP
  7682. reverse-proxy such as nginx or haproxy, which will direct incoming requests to
  7683. the correct worker, or to the main synapse instance. See
  7684. <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a reverse
  7685. proxy.</p>
  7686. <p>When using workers, each worker process has its own configuration file which
  7687. contains settings specific to that worker, such as the HTTP listener that it
  7688. provides (if any), logging configuration, etc.</p>
  7689. <p>Normally, the worker processes are configured to read from a shared
  7690. configuration file as well as the worker-specific configuration files. This
  7691. makes it easier to keep common configuration settings synchronised across all
  7692. the processes.</p>
  7693. <p>The main process is somewhat special in this respect: it does not normally
  7694. need its own configuration file and can take all of its configuration from the
  7695. shared configuration file.</p>
  7696. <h3 id="shared-configuration"><a class="header" href="#shared-configuration">Shared configuration</a></h3>
  7697. <p>Normally, only a couple of changes are needed to make an existing configuration
  7698. file suitable for use with workers. First, you need to enable an &quot;HTTP replication
  7699. listener&quot; for the main process; and secondly, you need to enable redis-based
  7700. replication. Optionally, a shared secret can be used to authenticate HTTP
  7701. traffic between workers. For example:</p>
  7702. <pre><code class="language-yaml"># extend the existing `listeners` section. This defines the ports that the
  7703. # main process will listen on.
  7704. listeners:
  7705. # The HTTP replication port
  7706. - port: 9093
  7707. bind_address: '127.0.0.1'
  7708. type: http
  7709. resources:
  7710. - names: [replication]
  7711. # Add a random shared secret to authenticate traffic.
  7712. worker_replication_secret: &quot;&quot;
  7713. redis:
  7714. enabled: true
  7715. </code></pre>
  7716. <p>See the sample config for the full documentation of each option.</p>
  7717. <p>Under <strong>no circumstances</strong> should the replication listener be exposed to the
  7718. public internet; it has no authentication and is unencrypted.</p>
  7719. <h3 id="worker-configuration"><a class="header" href="#worker-configuration">Worker configuration</a></h3>
  7720. <p>In the config file for each worker, you must specify the type of worker
  7721. application (<code>worker_app</code>), and you should specify a unique name for the worker
  7722. (<code>worker_name</code>). The currently available worker applications are listed below.
  7723. You must also specify the HTTP replication endpoint that it should talk to on
  7724. the main synapse process. <code>worker_replication_host</code> should specify the host of
  7725. the main synapse and <code>worker_replication_http_port</code> should point to the HTTP
  7726. replication port. If the worker will handle HTTP requests then the
  7727. <code>worker_listeners</code> option should be set with a <code>http</code> listener, in the same way
  7728. as the <code>listeners</code> option in the shared config.</p>
  7729. <p>For example:</p>
  7730. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  7731. worker_name: worker1
  7732. # The replication listener on the main synapse process.
  7733. worker_replication_host: 127.0.0.1
  7734. worker_replication_http_port: 9093
  7735. worker_listeners:
  7736. - type: http
  7737. port: 8083
  7738. resources:
  7739. - names:
  7740. - client
  7741. - federation
  7742. worker_log_config: /home/matrix/synapse/config/worker1_log_config.yaml
  7743. </code></pre>
  7744. <p>...is a full configuration for a generic worker instance, which will expose a
  7745. plain HTTP endpoint on port 8083 separately serving various endpoints, e.g.
  7746. <code>/sync</code>, which are listed below.</p>
  7747. <p>Obviously you should configure your reverse-proxy to route the relevant
  7748. endpoints to the worker (<code>localhost:8083</code> in the above example).</p>
  7749. <h3 id="running-synapse-with-workers"><a class="header" href="#running-synapse-with-workers">Running Synapse with workers</a></h3>
  7750. <p>Finally, you need to start your worker processes. This can be done with either
  7751. <code>synctl</code> or your distribution's preferred service manager such as <code>systemd</code>. We
  7752. recommend the use of <code>systemd</code> where available: for information on setting up
  7753. <code>systemd</code> to start synapse workers, see
  7754. <a href="systemd-with-workers">Systemd with Workers</a>. To use <code>synctl</code>, see
  7755. <a href="synctl_workers.html">Using synctl with Workers</a>.</p>
  7756. <h2 id="available-worker-applications"><a class="header" href="#available-worker-applications">Available worker applications</a></h2>
  7757. <h3 id="synapseappgeneric_worker"><a class="header" href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a></h3>
  7758. <p>This worker can handle API requests matching the following regular
  7759. expressions:</p>
  7760. <pre><code># Sync requests
  7761. ^/_matrix/client/(v2_alpha|r0)/sync$
  7762. ^/_matrix/client/(api/v1|v2_alpha|r0)/events$
  7763. ^/_matrix/client/(api/v1|r0)/initialSync$
  7764. ^/_matrix/client/(api/v1|r0)/rooms/[^/]+/initialSync$
  7765. # Federation requests
  7766. ^/_matrix/federation/v1/event/
  7767. ^/_matrix/federation/v1/state/
  7768. ^/_matrix/federation/v1/state_ids/
  7769. ^/_matrix/federation/v1/backfill/
  7770. ^/_matrix/federation/v1/get_missing_events/
  7771. ^/_matrix/federation/v1/publicRooms
  7772. ^/_matrix/federation/v1/query/
  7773. ^/_matrix/federation/v1/make_join/
  7774. ^/_matrix/federation/v1/make_leave/
  7775. ^/_matrix/federation/v1/send_join/
  7776. ^/_matrix/federation/v2/send_join/
  7777. ^/_matrix/federation/v1/send_leave/
  7778. ^/_matrix/federation/v2/send_leave/
  7779. ^/_matrix/federation/v1/invite/
  7780. ^/_matrix/federation/v2/invite/
  7781. ^/_matrix/federation/v1/query_auth/
  7782. ^/_matrix/federation/v1/event_auth/
  7783. ^/_matrix/federation/v1/exchange_third_party_invite/
  7784. ^/_matrix/federation/v1/user/devices/
  7785. ^/_matrix/federation/v1/get_groups_publicised$
  7786. ^/_matrix/key/v2/query
  7787. # Inbound federation transaction request
  7788. ^/_matrix/federation/v1/send/
  7789. # Client API requests
  7790. ^/_matrix/client/(api/v1|r0|unstable)/createRoom$
  7791. ^/_matrix/client/(api/v1|r0|unstable)/publicRooms$
  7792. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/joined_members$
  7793. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/context/.*$
  7794. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/members$
  7795. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state$
  7796. ^/_matrix/client/(api/v1|r0|unstable)/account/3pid$
  7797. ^/_matrix/client/(api/v1|r0|unstable)/devices$
  7798. ^/_matrix/client/(api/v1|r0|unstable)/keys/query$
  7799. ^/_matrix/client/(api/v1|r0|unstable)/keys/changes$
  7800. ^/_matrix/client/versions$
  7801. ^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$
  7802. ^/_matrix/client/(api/v1|r0|unstable)/joined_groups$
  7803. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups$
  7804. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups/
  7805. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/event/
  7806. ^/_matrix/client/(api/v1|r0|unstable)/joined_rooms$
  7807. ^/_matrix/client/(api/v1|r0|unstable)/search$
  7808. # Registration/login requests
  7809. ^/_matrix/client/(api/v1|r0|unstable)/login$
  7810. ^/_matrix/client/(r0|unstable)/register$
  7811. # Event sending requests
  7812. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/redact
  7813. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/send
  7814. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state/
  7815. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
  7816. ^/_matrix/client/(api/v1|r0|unstable)/join/
  7817. ^/_matrix/client/(api/v1|r0|unstable)/profile/
  7818. </code></pre>
  7819. <p>Additionally, the following REST endpoints can be handled for GET requests:</p>
  7820. <pre><code>^/_matrix/federation/v1/groups/
  7821. </code></pre>
  7822. <p>Pagination requests can also be handled, but all requests for a given
  7823. room must be routed to the same instance. Additionally, care must be taken to
  7824. ensure that the purge history admin API is not used while pagination requests
  7825. for the room are in flight:</p>
  7826. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/messages$
  7827. </code></pre>
  7828. <p>Additionally, the following endpoints should be included if Synapse is configured
  7829. to use SSO (you only need to include the ones for whichever SSO provider you're
  7830. using):</p>
  7831. <pre><code># for all SSO providers
  7832. ^/_matrix/client/(api/v1|r0|unstable)/login/sso/redirect
  7833. ^/_synapse/client/pick_idp$
  7834. ^/_synapse/client/pick_username
  7835. ^/_synapse/client/new_user_consent$
  7836. ^/_synapse/client/sso_register$
  7837. # OpenID Connect requests.
  7838. ^/_synapse/client/oidc/callback$
  7839. # SAML requests.
  7840. ^/_synapse/client/saml2/authn_response$
  7841. # CAS requests.
  7842. ^/_matrix/client/(api/v1|r0|unstable)/login/cas/ticket$
  7843. </code></pre>
  7844. <p>Ensure that all SSO logins go to a single process.
  7845. For multiple workers not handling the SSO endpoints properly, see
  7846. <a href="https://github.com/matrix-org/synapse/issues/7530">#7530</a> and
  7847. <a href="https://github.com/matrix-org/synapse/issues/9427">#9427</a>.</p>
  7848. <p>Note that a HTTP listener with <code>client</code> and <code>federation</code> resources must be
  7849. configured in the <code>worker_listeners</code> option in the worker config.</p>
  7850. <h4 id="load-balancing"><a class="header" href="#load-balancing">Load balancing</a></h4>
  7851. <p>It is possible to run multiple instances of this worker app, with incoming requests
  7852. being load-balanced between them by the reverse-proxy. However, different endpoints
  7853. have different characteristics and so admins
  7854. may wish to run multiple groups of workers handling different endpoints so that
  7855. load balancing can be done in different ways.</p>
  7856. <p>For <code>/sync</code> and <code>/initialSync</code> requests it will be more efficient if all
  7857. requests from a particular user are routed to a single instance. Extracting a
  7858. user ID from the access token or <code>Authorization</code> header is currently left as an
  7859. exercise for the reader. Admins may additionally wish to separate out <code>/sync</code>
  7860. requests that have a <code>since</code> query parameter from those that don't (and
  7861. <code>/initialSync</code>), as requests that don't are known as &quot;initial sync&quot; that happens
  7862. when a user logs in on a new device and can be <em>very</em> resource intensive, so
  7863. isolating these requests will stop them from interfering with other users ongoing
  7864. syncs.</p>
  7865. <p>Federation and client requests can be balanced via simple round robin.</p>
  7866. <p>The inbound federation transaction request <code>^/_matrix/federation/v1/send/</code>
  7867. should be balanced by source IP so that transactions from the same remote server
  7868. go to the same process.</p>
  7869. <p>Registration/login requests can be handled separately purely to help ensure that
  7870. unexpected load doesn't affect new logins and sign ups.</p>
  7871. <p>Finally, event sending requests can be balanced by the room ID in the URI (or
  7872. the full URI, or even just round robin), the room ID is the path component after
  7873. <code>/rooms/</code>. If there is a large bridge connected that is sending or may send lots
  7874. of events, then a dedicated set of workers can be provisioned to limit the
  7875. effects of bursts of events from that bridge on events sent by normal users.</p>
  7876. <h4 id="stream-writers"><a class="header" href="#stream-writers">Stream writers</a></h4>
  7877. <p>Additionally, there is <em>experimental</em> support for moving writing of specific
  7878. streams (such as events) off of the main process to a particular worker. (This
  7879. is only supported with Redis-based replication.)</p>
  7880. <p>Currently supported streams are <code>events</code> and <code>typing</code>.</p>
  7881. <p>To enable this, the worker must have a HTTP replication listener configured,
  7882. have a <code>worker_name</code> and be listed in the <code>instance_map</code> config. For example to
  7883. move event persistence off to a dedicated worker, the shared configuration would
  7884. include:</p>
  7885. <pre><code class="language-yaml">instance_map:
  7886. event_persister1:
  7887. host: localhost
  7888. port: 8034
  7889. stream_writers:
  7890. events: event_persister1
  7891. </code></pre>
  7892. <p>The <code>events</code> stream also experimentally supports having multiple writers, where
  7893. work is sharded between them by room ID. Note that you <em>must</em> restart all worker
  7894. instances when adding or removing event persisters. An example <code>stream_writers</code>
  7895. configuration with multiple writers:</p>
  7896. <pre><code class="language-yaml">stream_writers:
  7897. events:
  7898. - event_persister1
  7899. - event_persister2
  7900. </code></pre>
  7901. <h4 id="background-tasks"><a class="header" href="#background-tasks">Background tasks</a></h4>
  7902. <p>There is also <em>experimental</em> support for moving background tasks to a separate
  7903. worker. Background tasks are run periodically or started via replication. Exactly
  7904. which tasks are configured to run depends on your Synapse configuration (e.g. if
  7905. stats is enabled).</p>
  7906. <p>To enable this, the worker must have a <code>worker_name</code> and can be configured to run
  7907. background tasks. For example, to move background tasks to a dedicated worker,
  7908. the shared configuration would include:</p>
  7909. <pre><code class="language-yaml">run_background_tasks_on: background_worker
  7910. </code></pre>
  7911. <p>You might also wish to investigate the <code>update_user_directory</code> and
  7912. <code>media_instance_running_background_jobs</code> settings.</p>
  7913. <h3 id="synapseapppusher"><a class="header" href="#synapseapppusher"><code>synapse.app.pusher</code></a></h3>
  7914. <p>Handles sending push notifications to sygnal and email. Doesn't handle any
  7915. REST endpoints itself, but you should set <code>start_pushers: False</code> in the
  7916. shared configuration file to stop the main synapse sending push notifications.</p>
  7917. <p>To run multiple instances at once the <code>pusher_instances</code> option should list all
  7918. pusher instances by their worker name, e.g.:</p>
  7919. <pre><code class="language-yaml">pusher_instances:
  7920. - pusher_worker1
  7921. - pusher_worker2
  7922. </code></pre>
  7923. <h3 id="synapseappappservice"><a class="header" href="#synapseappappservice"><code>synapse.app.appservice</code></a></h3>
  7924. <p>Handles sending output traffic to Application Services. Doesn't handle any
  7925. REST endpoints itself, but you should set <code>notify_appservices: False</code> in the
  7926. shared configuration file to stop the main synapse sending appservice notifications.</p>
  7927. <p>Note this worker cannot be load-balanced: only one instance should be active.</p>
  7928. <h3 id="synapseappfederation_sender"><a class="header" href="#synapseappfederation_sender"><code>synapse.app.federation_sender</code></a></h3>
  7929. <p>Handles sending federation traffic to other servers. Doesn't handle any
  7930. REST endpoints itself, but you should set <code>send_federation: False</code> in the
  7931. shared configuration file to stop the main synapse sending this traffic.</p>
  7932. <p>If running multiple federation senders then you must list each
  7933. instance in the <code>federation_sender_instances</code> option by their <code>worker_name</code>.
  7934. All instances must be stopped and started when adding or removing instances.
  7935. For example:</p>
  7936. <pre><code class="language-yaml">federation_sender_instances:
  7937. - federation_sender1
  7938. - federation_sender2
  7939. </code></pre>
  7940. <h3 id="synapseappmedia_repository"><a class="header" href="#synapseappmedia_repository"><code>synapse.app.media_repository</code></a></h3>
  7941. <p>Handles the media repository. It can handle all endpoints starting with:</p>
  7942. <pre><code>/_matrix/media/
  7943. </code></pre>
  7944. <p>... and the following regular expressions matching media-specific administration APIs:</p>
  7945. <pre><code>^/_synapse/admin/v1/purge_media_cache$
  7946. ^/_synapse/admin/v1/room/.*/media.*$
  7947. ^/_synapse/admin/v1/user/.*/media.*$
  7948. ^/_synapse/admin/v1/media/.*$
  7949. ^/_synapse/admin/v1/quarantine_media/.*$
  7950. ^/_synapse/admin/v1/users/.*/media$
  7951. </code></pre>
  7952. <p>You should also set <code>enable_media_repo: False</code> in the shared configuration
  7953. file to stop the main synapse running background jobs related to managing the
  7954. media repository. Note that doing so will prevent the main process from being
  7955. able to handle the above endpoints.</p>
  7956. <p>In the <code>media_repository</code> worker configuration file, configure the http listener to
  7957. expose the <code>media</code> resource. For example:</p>
  7958. <pre><code class="language-yaml"> worker_listeners:
  7959. - type: http
  7960. port: 8085
  7961. resources:
  7962. - names:
  7963. - media
  7964. </code></pre>
  7965. <p>Note that if running multiple media repositories they must be on the same server
  7966. and you must configure a single instance to run the background tasks, e.g.:</p>
  7967. <pre><code class="language-yaml"> media_instance_running_background_jobs: &quot;media-repository-1&quot;
  7968. </code></pre>
  7969. <p>Note that if a reverse proxy is used , then <code>/_matrix/media/</code> must be routed for both inbound client and federation requests (if they are handled separately).</p>
  7970. <h3 id="synapseappuser_dir"><a class="header" href="#synapseappuser_dir"><code>synapse.app.user_dir</code></a></h3>
  7971. <p>Handles searches in the user directory. It can handle REST endpoints matching
  7972. the following regular expressions:</p>
  7973. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$
  7974. </code></pre>
  7975. <p>When using this worker you must also set <code>update_user_directory: False</code> in the
  7976. shared configuration file to stop the main synapse running background
  7977. jobs related to updating the user directory.</p>
  7978. <h3 id="synapseappfrontend_proxy"><a class="header" href="#synapseappfrontend_proxy"><code>synapse.app.frontend_proxy</code></a></h3>
  7979. <p>Proxies some frequently-requested client endpoints to add caching and remove
  7980. load from the main synapse. It can handle REST endpoints matching the following
  7981. regular expressions:</p>
  7982. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/keys/upload
  7983. </code></pre>
  7984. <p>If <code>use_presence</code> is False in the homeserver config, it can also handle REST
  7985. endpoints matching the following regular expressions:</p>
  7986. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/presence/[^/]+/status
  7987. </code></pre>
  7988. <p>This &quot;stub&quot; presence handler will pass through <code>GET</code> request but make the
  7989. <code>PUT</code> effectively a no-op.</p>
  7990. <p>It will proxy any requests it cannot handle to the main synapse instance. It
  7991. must therefore be configured with the location of the main instance, via
  7992. the <code>worker_main_http_uri</code> setting in the <code>frontend_proxy</code> worker configuration
  7993. file. For example:</p>
  7994. <pre><code>worker_main_http_uri: http://127.0.0.1:8008
  7995. </code></pre>
  7996. <h3 id="historical-apps"><a class="header" href="#historical-apps">Historical apps</a></h3>
  7997. <p><em>Note:</em> Historically there used to be more apps, however they have been
  7998. amalgamated into a single <code>synapse.app.generic_worker</code> app. The remaining apps
  7999. are ones that do specific processing unrelated to requests, e.g. the <code>pusher</code>
  8000. that handles sending out push notifications for new events. The intention is for
  8001. all these to be folded into the <code>generic_worker</code> app and to use config to define
  8002. which processes handle the various proccessing such as push notifications.</p>
  8003. <h2 id="migration-from-old-config"><a class="header" href="#migration-from-old-config">Migration from old config</a></h2>
  8004. <p>There are two main independent changes that have been made: introducing Redis
  8005. support and merging apps into <code>synapse.app.generic_worker</code>. Both these changes
  8006. are backwards compatible and so no changes to the config are required, however
  8007. server admins are encouraged to plan to migrate to Redis as the old style direct
  8008. TCP replication config is deprecated.</p>
  8009. <p>To migrate to Redis add the <code>redis</code> config as above, and optionally remove the
  8010. TCP <code>replication</code> listener from master and <code>worker_replication_port</code> from worker
  8011. config.</p>
  8012. <p>To migrate apps to use <code>synapse.app.generic_worker</code> simply update the
  8013. <code>worker_app</code> option in the worker configs, and where worker are started (e.g.
  8014. in systemd service files, but not required for synctl).</p>
  8015. <h2 id="architectural-diagram"><a class="header" href="#architectural-diagram">Architectural diagram</a></h2>
  8016. <p>The following shows an example setup using Redis and a reverse proxy:</p>
  8017. <pre><code> Clients &amp; Federation
  8018. |
  8019. v
  8020. +-----------+
  8021. | |
  8022. | Reverse |
  8023. | Proxy |
  8024. | |
  8025. +-----------+
  8026. | | |
  8027. | | | HTTP requests
  8028. +-------------------+ | +-----------+
  8029. | +---+ |
  8030. | | |
  8031. v v v
  8032. +--------------+ +--------------+ +--------------+ +--------------+
  8033. | Main | | Generic | | Generic | | Event |
  8034. | Process | | Worker 1 | | Worker 2 | | Persister |
  8035. +--------------+ +--------------+ +--------------+ +--------------+
  8036. ^ ^ | ^ | | ^ | ^ ^
  8037. | | | | | | | | | |
  8038. | | | | | HTTP | | | | |
  8039. | +----------+&lt;--|---|---------+ | | | |
  8040. | | +-------------|--&gt;+----------+ |
  8041. | | | |
  8042. | | | |
  8043. v v v v
  8044. ====================================================================
  8045. Redis pub/sub channel
  8046. </code></pre>
  8047. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h3 id="using-synctl-with-workers"><a class="header" href="#using-synctl-with-workers">Using synctl with workers</a></h3>
  8048. <p>If you want to use <code>synctl</code> to manage your synapse processes, you will need to
  8049. create an an additional configuration file for the main synapse process. That
  8050. configuration should look like this:</p>
  8051. <pre><code class="language-yaml">worker_app: synapse.app.homeserver
  8052. </code></pre>
  8053. <p>Additionally, each worker app must be configured with the name of a &quot;pid file&quot;,
  8054. to which it will write its process ID when it starts. For example, for a
  8055. synchrotron, you might write:</p>
  8056. <pre><code class="language-yaml">worker_pid_file: /home/matrix/synapse/worker1.pid
  8057. </code></pre>
  8058. <p>Finally, to actually run your worker-based synapse, you must pass synctl the <code>-a</code>
  8059. commandline option to tell it to operate on all the worker configurations found
  8060. in the given directory, e.g.:</p>
  8061. <pre><code>synctl -a $CONFIG/workers start
  8062. </code></pre>
  8063. <p>Currently one should always restart all workers when restarting or upgrading
  8064. synapse, unless you explicitly know it's safe not to. For instance, restarting
  8065. synapse without restarting all the synchrotrons may result in broken typing
  8066. notifications.</p>
  8067. <p>To manipulate a specific worker, you pass the -w option to synctl:</p>
  8068. <pre><code>synctl -w $CONFIG/workers/worker1.yaml restart
  8069. </code></pre>
  8070. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="setting-up-synapse-with-workers-and-systemd"><a class="header" href="#setting-up-synapse-with-workers-and-systemd">Setting up Synapse with Workers and Systemd</a></h1>
  8071. <p>This is a setup for managing synapse with systemd, including support for
  8072. managing workers. It provides a <code>matrix-synapse</code> service for the master, as
  8073. well as a <code>matrix-synapse-worker@</code> service template for any workers you
  8074. require. Additionally, to group the required services, it sets up a
  8075. <code>matrix-synapse.target</code>.</p>
  8076. <p>See the folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/system/">system</a>
  8077. for the systemd unit files.</p>
  8078. <p>The folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/workers/">workers</a>
  8079. contains an example configuration for the <code>federation_reader</code> worker.</p>
  8080. <h2 id="synapse-configuration-files"><a class="header" href="#synapse-configuration-files">Synapse configuration files</a></h2>
  8081. <p>See <a href="systemd-with-workers/../workers.html">the worker documentation</a> for information on how to set up the
  8082. configuration files and reverse-proxy correctly.
  8083. Below is a sample <code>federation_reader</code> worker configuration file.</p>
  8084. <pre><code class="language-yaml">worker_app: synapse.app.federation_reader
  8085. worker_name: federation_reader1
  8086. worker_replication_host: 127.0.0.1
  8087. worker_replication_http_port: 9093
  8088. worker_listeners:
  8089. - type: http
  8090. port: 8011
  8091. resources:
  8092. - names: [federation]
  8093. worker_log_config: /etc/matrix-synapse/federation-reader-log.yaml
  8094. </code></pre>
  8095. <p>Systemd manages daemonization itself, so ensure that none of the configuration
  8096. files set either <code>daemonize</code> or <code>worker_daemonize</code>.</p>
  8097. <p>The config files of all workers are expected to be located in
  8098. <code>/etc/matrix-synapse/workers</code>. If you want to use a different location, edit
  8099. the provided <code>*.service</code> files accordingly.</p>
  8100. <p>There is no need for a separate configuration file for the master process.</p>
  8101. <h2 id="set-up"><a class="header" href="#set-up">Set up</a></h2>
  8102. <ol>
  8103. <li>Adjust synapse configuration files as above.</li>
  8104. <li>Copy the <code>*.service</code> and <code>*.target</code> files in <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/system/">system</a>
  8105. to <code>/etc/systemd/system</code>.</li>
  8106. <li>Run <code>systemctl daemon-reload</code> to tell systemd to load the new unit files.</li>
  8107. <li>Run <code>systemctl enable matrix-synapse.service</code>. This will configure the
  8108. synapse master process to be started as part of the <code>matrix-synapse.target</code>
  8109. target.</li>
  8110. <li>For each worker process to be enabled, run <code>systemctl enable matrix-synapse-worker@&lt;worker_name&gt;.service</code>. For each <code>&lt;worker_name&gt;</code>, there
  8111. should be a corresponding configuration file.
  8112. <code>/etc/matrix-synapse/workers/&lt;worker_name&gt;.yaml</code>.</li>
  8113. <li>Start all the synapse processes with <code>systemctl start matrix-synapse.target</code>.</li>
  8114. <li>Tell systemd to start synapse on boot with <code>systemctl enable matrix-synapse.target</code>.</li>
  8115. </ol>
  8116. <h2 id="usage"><a class="header" href="#usage">Usage</a></h2>
  8117. <p>Once the services are correctly set up, you can use the following commands
  8118. to manage your synapse installation:</p>
  8119. <pre><code class="language-sh"># Restart Synapse master and all workers
  8120. systemctl restart matrix-synapse.target
  8121. # Stop Synapse and all workers
  8122. systemctl stop matrix-synapse.target
  8123. # Restart the master alone
  8124. systemctl start matrix-synapse.service
  8125. # Restart a specific worker (eg. federation_reader); the master is
  8126. # unaffected by this.
  8127. systemctl restart matrix-synapse-worker@federation_reader.service
  8128. # Add a new worker (assuming all configs are set up already)
  8129. systemctl enable matrix-synapse-worker@federation_writer.service
  8130. systemctl restart matrix-synapse.target
  8131. </code></pre>
  8132. <h2 id="hardening"><a class="header" href="#hardening">Hardening</a></h2>
  8133. <p><strong>Optional:</strong> If further hardening is desired, the file
  8134. <code>override-hardened.conf</code> may be copied from
  8135. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/systemd/">contrib/systemd/override-hardened.conf</a>
  8136. in this repository to the location
  8137. <code>/etc/systemd/system/matrix-synapse.service.d/override-hardened.conf</code> (the
  8138. directory may have to be created). It enables certain sandboxing features in
  8139. systemd to further secure the synapse service. You may read the comments to
  8140. understand what the override file is doing. The same file will need to be copied to
  8141. <code>/etc/systemd/system/matrix-synapse-worker@.service.d/override-hardened-worker.conf</code>
  8142. (this directory may also have to be created) in order to apply the same
  8143. hardening options to any worker processes.</p>
  8144. <p>Once these files have been copied to their appropriate locations, simply reload
  8145. systemd's manager config files and restart all Synapse services to apply the hardening options. They will automatically
  8146. be applied at every restart as long as the override files are present at the
  8147. specified locations.</p>
  8148. <pre><code class="language-sh">systemctl daemon-reload
  8149. # Restart services
  8150. systemctl restart matrix-synapse.target
  8151. </code></pre>
  8152. <p>In order to see their effect, you may run <code>systemd-analyze security matrix-synapse.service</code> before and after applying the hardening options to see
  8153. the changes being applied at a glance.</p>
  8154. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="administration"><a class="header" href="#administration">Administration</a></h1>
  8155. <p>This section contains information on managing your Synapse homeserver. This includes:</p>
  8156. <ul>
  8157. <li>Managing users, rooms and media via the Admin API.</li>
  8158. <li>Setting up metrics and monitoring to give you insight into your homeserver's health.</li>
  8159. <li>Configuring structured logging.</li>
  8160. </ul>
  8161. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="the-admin-api"><a class="header" href="#the-admin-api">The Admin API</a></h1>
  8162. <h2 id="authenticate-as-a-server-admin"><a class="header" href="#authenticate-as-a-server-admin">Authenticate as a server admin</a></h2>
  8163. <p>Many of the API calls in the admin api will require an <code>access_token</code> for a
  8164. server admin. (Note that a server admin is distinct from a room admin.)</p>
  8165. <p>A user can be marked as a server admin by updating the database directly, e.g.:</p>
  8166. <pre><code class="language-sql">UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
  8167. </code></pre>
  8168. <p>A new server admin user can also be created using the <code>register_new_matrix_user</code>
  8169. command. This is a script that is located in the <code>scripts/</code> directory, or possibly
  8170. already on your <code>$PATH</code> depending on how Synapse was installed.</p>
  8171. <p>Finding your user's <code>access_token</code> is client-dependent, but will usually be shown in the client's settings.</p>
  8172. <h2 id="making-an-admin-api-request"><a class="header" href="#making-an-admin-api-request">Making an Admin API request</a></h2>
  8173. <p>Once you have your <code>access_token</code>, you will need to authenticate each request to an Admin API endpoint by
  8174. providing the token as either a query parameter or a request header. To add it as a request header in cURL:</p>
  8175. <pre><code class="language-sh">curl --header &quot;Authorization: Bearer &lt;access_token&gt;&quot; &lt;the_rest_of_your_API_request&gt;
  8176. </code></pre>
  8177. <p>For more details on access tokens in Matrix, please refer to the complete
  8178. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#using-access-tokens">matrix spec documentation</a>.</p>
  8179. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="account-validity-api"><a class="header" href="#account-validity-api">Account validity API</a></h1>
  8180. <p>This API allows a server administrator to manage the validity of an account. To
  8181. use it, you must enable the account validity feature (under
  8182. <code>account_validity</code>) in Synapse's configuration.</p>
  8183. <h2 id="renew-account"><a class="header" href="#renew-account">Renew account</a></h2>
  8184. <p>This API extends the validity of an account by as much time as configured in the
  8185. <code>period</code> parameter from the <code>account_validity</code> configuration.</p>
  8186. <p>The API is:</p>
  8187. <pre><code>POST /_synapse/admin/v1/account_validity/validity
  8188. </code></pre>
  8189. <p>with the following body:</p>
  8190. <pre><code class="language-json">{
  8191. &quot;user_id&quot;: &quot;&lt;user ID for the account to renew&gt;&quot;,
  8192. &quot;expiration_ts&quot;: 0,
  8193. &quot;enable_renewal_emails&quot;: true
  8194. }
  8195. </code></pre>
  8196. <p><code>expiration_ts</code> is an optional parameter and overrides the expiration date,
  8197. which otherwise defaults to now + validity period.</p>
  8198. <p><code>enable_renewal_emails</code> is also an optional parameter and enables/disables
  8199. sending renewal emails to the user. Defaults to true.</p>
  8200. <p>The API returns with the new expiration date for this account, as a timestamp in
  8201. milliseconds since epoch:</p>
  8202. <pre><code class="language-json">{
  8203. &quot;expiration_ts&quot;: 0
  8204. }
  8205. </code></pre>
  8206. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="delete-a-local-group"><a class="header" href="#delete-a-local-group">Delete a local group</a></h1>
  8207. <p>This API lets a server admin delete a local group. Doing so will kick all
  8208. users out of the group so that their clients will correctly handle the group
  8209. being deleted.</p>
  8210. <p>The API is:</p>
  8211. <pre><code>POST /_synapse/admin/v1/delete_group/&lt;group_id&gt;
  8212. </code></pre>
  8213. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8214. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8215. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="show-reported-events"><a class="header" href="#show-reported-events">Show reported events</a></h1>
  8216. <p>This API returns information about reported events.</p>
  8217. <p>The api is:</p>
  8218. <pre><code>GET /_synapse/admin/v1/event_reports?from=0&amp;limit=10
  8219. </code></pre>
  8220. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8221. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8222. <p>It returns a JSON body like the following:</p>
  8223. <pre><code class="language-json">{
  8224. &quot;event_reports&quot;: [
  8225. {
  8226. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8227. &quot;id&quot;: 2,
  8228. &quot;reason&quot;: &quot;foo&quot;,
  8229. &quot;score&quot;: -100,
  8230. &quot;received_ts&quot;: 1570897107409,
  8231. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8232. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8233. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8234. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8235. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8236. },
  8237. {
  8238. &quot;event_id&quot;: &quot;$3IcdZsDaN_En-S1DF4EMCy3v4gNRKeOJs8W5qTOKj4I&quot;,
  8239. &quot;id&quot;: 3,
  8240. &quot;reason&quot;: &quot;bar&quot;,
  8241. &quot;score&quot;: -100,
  8242. &quot;received_ts&quot;: 1598889612059,
  8243. &quot;canonical_alias&quot;: &quot;#alias2:matrix.org&quot;,
  8244. &quot;room_id&quot;: &quot;!eGvUQuTCkHGVwNMOjv:matrix.org&quot;,
  8245. &quot;name&quot;: &quot;Your room name here&quot;,
  8246. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8247. &quot;user_id&quot;: &quot;@bar:matrix.org&quot;
  8248. }
  8249. ],
  8250. &quot;next_token&quot;: 2,
  8251. &quot;total&quot;: 4
  8252. }
  8253. </code></pre>
  8254. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again with <code>from</code>
  8255. set to the value of <code>next_token</code>. This will return a new page.</p>
  8256. <p>If the endpoint does not return a <code>next_token</code> then there are no more reports to
  8257. paginate through.</p>
  8258. <p><strong>URL parameters:</strong></p>
  8259. <ul>
  8260. <li><code>limit</code>: integer - Is optional but is used for pagination, denoting the maximum number
  8261. of items to return in this call. Defaults to <code>100</code>.</li>
  8262. <li><code>from</code>: integer - Is optional but used for pagination, denoting the offset in the
  8263. returned results. This should be treated as an opaque value and not explicitly set to
  8264. anything other than the return value of <code>next_token</code> from a previous call. Defaults to <code>0</code>.</li>
  8265. <li><code>dir</code>: string - Direction of event report order. Whether to fetch the most recent
  8266. first (<code>b</code>) or the oldest first (<code>f</code>). Defaults to <code>b</code>.</li>
  8267. <li><code>user_id</code>: string - Is optional and filters to only return users with user IDs that
  8268. contain this value. This is the user who reported the event and wrote the reason.</li>
  8269. <li><code>room_id</code>: string - Is optional and filters to only return rooms with room IDs that
  8270. contain this value.</li>
  8271. </ul>
  8272. <p><strong>Response</strong></p>
  8273. <p>The following fields are returned in the JSON response body:</p>
  8274. <ul>
  8275. <li><code>id</code>: integer - ID of event report.</li>
  8276. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8277. report was sent.</li>
  8278. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8279. <li><code>name</code>: string - The name of the room.</li>
  8280. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8281. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8282. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank or <code>null</code>.</li>
  8283. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8284. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;. May be <code>null</code>.</li>
  8285. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8286. was reported.</li>
  8287. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8288. have a canonical alias set.</li>
  8289. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  8290. <li><code>total</code>: integer - Total number of event reports related to the query
  8291. (<code>user_id</code> and <code>room_id</code>).</li>
  8292. </ul>
  8293. <h1 id="show-details-of-a-specific-event-report"><a class="header" href="#show-details-of-a-specific-event-report">Show details of a specific event report</a></h1>
  8294. <p>This API returns information about a specific event report.</p>
  8295. <p>The api is:</p>
  8296. <pre><code>GET /_synapse/admin/v1/event_reports/&lt;report_id&gt;
  8297. </code></pre>
  8298. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8299. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8300. <p>It returns a JSON body like the following:</p>
  8301. <pre><code class="language-jsonc">{
  8302. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8303. &quot;event_json&quot;: {
  8304. &quot;auth_events&quot;: [
  8305. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;,
  8306. &quot;$oggsNXxzPFRE3y53SUNd7nsj69-QzKv03a1RucHu-ws&quot;
  8307. ],
  8308. &quot;content&quot;: {
  8309. &quot;body&quot;: &quot;matrix.org: This Week in Matrix&quot;,
  8310. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  8311. &quot;formatted_body&quot;: &quot;&lt;strong&gt;matrix.org&lt;/strong&gt;:&lt;br&gt;&lt;a href=\&quot;https://matrix.org/blog/\&quot;&gt;&lt;strong&gt;This Week in Matrix&lt;/strong&gt;&lt;/a&gt;&quot;,
  8312. &quot;msgtype&quot;: &quot;m.notice&quot;
  8313. },
  8314. &quot;depth&quot;: 546,
  8315. &quot;hashes&quot;: {
  8316. &quot;sha256&quot;: &quot;xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw&quot;
  8317. },
  8318. &quot;origin&quot;: &quot;matrix.org&quot;,
  8319. &quot;origin_server_ts&quot;: 1592291711430,
  8320. &quot;prev_events&quot;: [
  8321. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;
  8322. ],
  8323. &quot;prev_state&quot;: [],
  8324. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8325. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8326. &quot;signatures&quot;: {
  8327. &quot;matrix.org&quot;: {
  8328. &quot;ed25519:a_JaEG&quot;: &quot;cs+OUKW/iHx5pEidbWxh0UiNNHwe46Ai9LwNz+Ah16aWDNszVIe2gaAcVZfvNsBhakQTew51tlKmL2kspXk/Dg&quot;
  8329. }
  8330. },
  8331. &quot;type&quot;: &quot;m.room.message&quot;,
  8332. &quot;unsigned&quot;: {
  8333. &quot;age_ts&quot;: 1592291711430,
  8334. }
  8335. },
  8336. &quot;id&quot;: &lt;report_id&gt;,
  8337. &quot;reason&quot;: &quot;foo&quot;,
  8338. &quot;score&quot;: -100,
  8339. &quot;received_ts&quot;: 1570897107409,
  8340. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8341. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8342. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8343. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8344. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8345. }
  8346. </code></pre>
  8347. <p><strong>URL parameters:</strong></p>
  8348. <ul>
  8349. <li><code>report_id</code>: string - The ID of the event report.</li>
  8350. </ul>
  8351. <p><strong>Response</strong></p>
  8352. <p>The following fields are returned in the JSON response body:</p>
  8353. <ul>
  8354. <li><code>id</code>: integer - ID of event report.</li>
  8355. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8356. report was sent.</li>
  8357. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8358. <li><code>name</code>: string - The name of the room.</li>
  8359. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8360. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8361. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank.</li>
  8362. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8363. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;.</li>
  8364. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8365. was reported.</li>
  8366. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8367. have a canonical alias set.</li>
  8368. <li><code>event_json</code>: object - Details of the original event that was reported.</li>
  8369. </ul>
  8370. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="contents-1"><a class="header" href="#contents-1">Contents</a></h1>
  8371. <ul>
  8372. <li><a href="admin_api/media_admin_api.html#querying-media">Querying media</a>
  8373. <ul>
  8374. <li><a href="admin_api/media_admin_api.html#list-all-media-in-a-room">List all media in a room</a></li>
  8375. <li><a href="admin_api/media_admin_api.html#list-all-media-uploaded-by-a-user">List all media uploaded by a user</a></li>
  8376. </ul>
  8377. </li>
  8378. <li><a href="admin_api/media_admin_api.html#quarantine-media">Quarantine media</a>
  8379. <ul>
  8380. <li><a href="admin_api/media_admin_api.html#quarantining-media-by-id">Quarantining media by ID</a></li>
  8381. <li><a href="admin_api/media_admin_api.html#remove-media-from-quarantine-by-id">Remove media from quarantine by ID</a></li>
  8382. <li><a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">Quarantining media in a room</a></li>
  8383. <li><a href="admin_api/media_admin_api.html#quarantining-all-media-of-a-user">Quarantining all media of a user</a></li>
  8384. <li><a href="admin_api/media_admin_api.html#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></li>
  8385. <li><a href="admin_api/media_admin_api.html#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></li>
  8386. </ul>
  8387. </li>
  8388. <li><a href="admin_api/media_admin_api.html#delete-local-media">Delete local media</a>
  8389. <ul>
  8390. <li><a href="admin_api/media_admin_api.html#delete-a-specific-local-media">Delete a specific local media</a></li>
  8391. <li><a href="admin_api/media_admin_api.html#delete-local-media-by-date-or-size">Delete local media by date or size</a></li>
  8392. <li><a href="admin_api/media_admin_api.html#delete-media-uploaded-by-a-user">Delete media uploaded by a user</a></li>
  8393. </ul>
  8394. </li>
  8395. <li><a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a></li>
  8396. </ul>
  8397. <h1 id="querying-media"><a class="header" href="#querying-media">Querying media</a></h1>
  8398. <p>These APIs allow extracting media information from the homeserver.</p>
  8399. <h2 id="list-all-media-in-a-room"><a class="header" href="#list-all-media-in-a-room">List all media in a room</a></h2>
  8400. <p>This API gets a list of known media in a room.
  8401. However, it only shows media from unencrypted events or rooms.</p>
  8402. <p>The API is:</p>
  8403. <pre><code>GET /_synapse/admin/v1/room/&lt;room_id&gt;/media
  8404. </code></pre>
  8405. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8406. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8407. <p>The API returns a JSON body like the following:</p>
  8408. <pre><code class="language-json">{
  8409. &quot;local&quot;: [
  8410. &quot;mxc://localhost/xwvutsrqponmlkjihgfedcba&quot;,
  8411. &quot;mxc://localhost/abcdefghijklmnopqrstuvwx&quot;
  8412. ],
  8413. &quot;remote&quot;: [
  8414. &quot;mxc://matrix.org/xwvutsrqponmlkjihgfedcba&quot;,
  8415. &quot;mxc://matrix.org/abcdefghijklmnopqrstuvwx&quot;
  8416. ]
  8417. }
  8418. </code></pre>
  8419. <h2 id="list-all-media-uploaded-by-a-user"><a class="header" href="#list-all-media-uploaded-by-a-user">List all media uploaded by a user</a></h2>
  8420. <p>Listing all media that has been uploaded by a local user can be achieved through
  8421. the use of the
  8422. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>
  8423. Admin API.</p>
  8424. <h1 id="quarantine-media"><a class="header" href="#quarantine-media">Quarantine media</a></h1>
  8425. <p>Quarantining media means that it is marked as inaccessible by users. It applies
  8426. to any local media, and any locally-cached copies of remote media.</p>
  8427. <p>The media file itself (and any thumbnails) is not deleted from the server.</p>
  8428. <h2 id="quarantining-media-by-id"><a class="header" href="#quarantining-media-by-id">Quarantining media by ID</a></h2>
  8429. <p>This API quarantines a single piece of local or remote media.</p>
  8430. <p>Request:</p>
  8431. <pre><code>POST /_synapse/admin/v1/media/quarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8432. {}
  8433. </code></pre>
  8434. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8435. form of <code>abcdefg12345...</code>.</p>
  8436. <p>Response:</p>
  8437. <pre><code class="language-json">{}
  8438. </code></pre>
  8439. <h2 id="remove-media-from-quarantine-by-id"><a class="header" href="#remove-media-from-quarantine-by-id">Remove media from quarantine by ID</a></h2>
  8440. <p>This API removes a single piece of local or remote media from quarantine.</p>
  8441. <p>Request:</p>
  8442. <pre><code>POST /_synapse/admin/v1/media/unquarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8443. {}
  8444. </code></pre>
  8445. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8446. form of <code>abcdefg12345...</code>.</p>
  8447. <p>Response:</p>
  8448. <pre><code class="language-json">{}
  8449. </code></pre>
  8450. <h2 id="quarantining-media-in-a-room"><a class="header" href="#quarantining-media-in-a-room">Quarantining media in a room</a></h2>
  8451. <p>This API quarantines all local and remote media in a room.</p>
  8452. <p>Request:</p>
  8453. <pre><code>POST /_synapse/admin/v1/room/&lt;room_id&gt;/media/quarantine
  8454. {}
  8455. </code></pre>
  8456. <p>Where <code>room_id</code> is in the form of <code>!roomid12345:example.org</code>.</p>
  8457. <p>Response:</p>
  8458. <pre><code class="language-json">{
  8459. &quot;num_quarantined&quot;: 10
  8460. }
  8461. </code></pre>
  8462. <p>The following fields are returned in the JSON response body:</p>
  8463. <ul>
  8464. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8465. </ul>
  8466. <p>Note that there is a legacy endpoint, <code>POST /_synapse/admin/v1/quarantine_media/&lt;room_id&gt;</code>, that operates the same.
  8467. However, it is deprecated and may be removed in a future release.</p>
  8468. <h2 id="quarantining-all-media-of-a-user"><a class="header" href="#quarantining-all-media-of-a-user">Quarantining all media of a user</a></h2>
  8469. <p>This API quarantines all <em>local</em> media that a <em>local</em> user has uploaded. That is to say, if
  8470. you would like to quarantine media uploaded by a user on a remote homeserver, you should
  8471. instead use one of the other APIs.</p>
  8472. <p>Request:</p>
  8473. <pre><code>POST /_synapse/admin/v1/user/&lt;user_id&gt;/media/quarantine
  8474. {}
  8475. </code></pre>
  8476. <p>URL Parameters</p>
  8477. <ul>
  8478. <li><code>user_id</code>: string - User ID in the form of <code>@bob:example.org</code></li>
  8479. </ul>
  8480. <p>Response:</p>
  8481. <pre><code class="language-json">{
  8482. &quot;num_quarantined&quot;: 10
  8483. }
  8484. </code></pre>
  8485. <p>The following fields are returned in the JSON response body:</p>
  8486. <ul>
  8487. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8488. </ul>
  8489. <h2 id="protecting-media-from-being-quarantined"><a class="header" href="#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></h2>
  8490. <p>This API protects a single piece of local media from being quarantined using the
  8491. above APIs. This is useful for sticker packs and other shared media which you do
  8492. not want to get quarantined, especially when
  8493. <a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">quarantining media in a room</a>.</p>
  8494. <p>Request:</p>
  8495. <pre><code>POST /_synapse/admin/v1/media/protect/&lt;media_id&gt;
  8496. {}
  8497. </code></pre>
  8498. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8499. <p>Response:</p>
  8500. <pre><code class="language-json">{}
  8501. </code></pre>
  8502. <h2 id="unprotecting-media-from-being-quarantined"><a class="header" href="#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></h2>
  8503. <p>This API reverts the protection of a media.</p>
  8504. <p>Request:</p>
  8505. <pre><code>POST /_synapse/admin/v1/media/unprotect/&lt;media_id&gt;
  8506. {}
  8507. </code></pre>
  8508. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8509. <p>Response:</p>
  8510. <pre><code class="language-json">{}
  8511. </code></pre>
  8512. <h1 id="delete-local-media"><a class="header" href="#delete-local-media">Delete local media</a></h1>
  8513. <p>This API deletes the <em>local</em> media from the disk of your own server.
  8514. This includes any local thumbnails and copies of media downloaded from
  8515. remote homeservers.
  8516. This API will not affect media that has been uploaded to external
  8517. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
  8518. See also <a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a>.</p>
  8519. <h2 id="delete-a-specific-local-media"><a class="header" href="#delete-a-specific-local-media">Delete a specific local media</a></h2>
  8520. <p>Delete a specific <code>media_id</code>.</p>
  8521. <p>Request:</p>
  8522. <pre><code>DELETE /_synapse/admin/v1/media/&lt;server_name&gt;/&lt;media_id&gt;
  8523. {}
  8524. </code></pre>
  8525. <p>URL Parameters</p>
  8526. <ul>
  8527. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>)</li>
  8528. <li><code>media_id</code>: string - The ID of the media (e.g <code>abcdefghijklmnopqrstuvwx</code>)</li>
  8529. </ul>
  8530. <p>Response:</p>
  8531. <pre><code class="language-json">{
  8532. &quot;deleted_media&quot;: [
  8533. &quot;abcdefghijklmnopqrstuvwx&quot;
  8534. ],
  8535. &quot;total&quot;: 1
  8536. }
  8537. </code></pre>
  8538. <p>The following fields are returned in the JSON response body:</p>
  8539. <ul>
  8540. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8541. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8542. </ul>
  8543. <h2 id="delete-local-media-by-date-or-size"><a class="header" href="#delete-local-media-by-date-or-size">Delete local media by date or size</a></h2>
  8544. <p>Request:</p>
  8545. <pre><code>POST /_synapse/admin/v1/media/&lt;server_name&gt;/delete?before_ts=&lt;before_ts&gt;
  8546. {}
  8547. </code></pre>
  8548. <p>URL Parameters</p>
  8549. <ul>
  8550. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>).</li>
  8551. <li><code>before_ts</code>: string representing a positive integer - Unix timestamp in ms.
  8552. Files that were last used before this timestamp will be deleted. It is the timestamp of
  8553. last access and not the timestamp creation.</li>
  8554. <li><code>size_gt</code>: Optional - string representing a positive integer - Size of the media in bytes.
  8555. Files that are larger will be deleted. Defaults to <code>0</code>.</li>
  8556. <li><code>keep_profiles</code>: Optional - string representing a boolean - Switch to also delete files
  8557. that are still used in image data (e.g user profile, room avatar).
  8558. If <code>false</code> these files will be deleted. Defaults to <code>true</code>.</li>
  8559. </ul>
  8560. <p>Response:</p>
  8561. <pre><code class="language-json">{
  8562. &quot;deleted_media&quot;: [
  8563. &quot;abcdefghijklmnopqrstuvwx&quot;,
  8564. &quot;abcdefghijklmnopqrstuvwz&quot;
  8565. ],
  8566. &quot;total&quot;: 2
  8567. }
  8568. </code></pre>
  8569. <p>The following fields are returned in the JSON response body:</p>
  8570. <ul>
  8571. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8572. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8573. </ul>
  8574. <h2 id="delete-media-uploaded-by-a-user"><a class="header" href="#delete-media-uploaded-by-a-user">Delete media uploaded by a user</a></h2>
  8575. <p>You can find details of how to delete multiple media uploaded by a user in
  8576. <a href="admin_api/user_admin_api.html#delete-media-uploaded-by-a-user">User Admin API</a>.</p>
  8577. <h1 id="purge-remote-media-api"><a class="header" href="#purge-remote-media-api">Purge Remote Media API</a></h1>
  8578. <p>The purge remote media API allows server admins to purge old cached remote media.</p>
  8579. <p>The API is:</p>
  8580. <pre><code>POST /_synapse/admin/v1/purge_media_cache?before_ts=&lt;unix_timestamp_in_ms&gt;
  8581. {}
  8582. </code></pre>
  8583. <p>URL Parameters</p>
  8584. <ul>
  8585. <li><code>unix_timestamp_in_ms</code>: string representing a positive integer - Unix timestamp in ms.
  8586. All cached media that was last accessed before this timestamp will be removed.</li>
  8587. </ul>
  8588. <p>Response:</p>
  8589. <pre><code class="language-json">{
  8590. &quot;deleted&quot;: 10
  8591. }
  8592. </code></pre>
  8593. <p>The following fields are returned in the JSON response body:</p>
  8594. <ul>
  8595. <li><code>deleted</code>: integer - The number of media items successfully deleted</li>
  8596. </ul>
  8597. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8598. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8599. <p>If the user re-requests purged remote media, synapse will re-request the media
  8600. from the originating server.</p>
  8601. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="purge-history-api"><a class="header" href="#purge-history-api">Purge History API</a></h1>
  8602. <p>The purge history API allows server admins to purge historic events from their
  8603. database, reclaiming disk space.</p>
  8604. <p>Depending on the amount of history being purged a call to the API may take
  8605. several minutes or longer. During this period users will not be able to
  8606. paginate further back in the room from the point being purged from.</p>
  8607. <p>Note that Synapse requires at least one message in each room, so it will never
  8608. delete the last message in a room.</p>
  8609. <p>The API is:</p>
  8610. <pre><code>POST /_synapse/admin/v1/purge_history/&lt;room_id&gt;[/&lt;event_id&gt;]
  8611. </code></pre>
  8612. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8613. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  8614. <p>By default, events sent by local users are not deleted, as they may represent
  8615. the only copies of this content in existence. (Events sent by remote users are
  8616. deleted.)</p>
  8617. <p>Room state data (such as joins, leaves, topic) is always preserved.</p>
  8618. <p>To delete local message events as well, set <code>delete_local_events</code> in the body:</p>
  8619. <pre><code>{
  8620. &quot;delete_local_events&quot;: true
  8621. }
  8622. </code></pre>
  8623. <p>The caller must specify the point in the room to purge up to. This can be
  8624. specified by including an event_id in the URI, or by setting a
  8625. <code>purge_up_to_event_id</code> or <code>purge_up_to_ts</code> in the request body. If an event
  8626. id is given, that event (and others at the same graph depth) will be retained.
  8627. If <code>purge_up_to_ts</code> is given, it should be a timestamp since the unix epoch,
  8628. in milliseconds.</p>
  8629. <p>The API starts the purge running, and returns immediately with a JSON body with
  8630. a purge id:</p>
  8631. <pre><code class="language-json">{
  8632. &quot;purge_id&quot;: &quot;&lt;opaque id&gt;&quot;
  8633. }
  8634. </code></pre>
  8635. <h2 id="purge-status-query"><a class="header" href="#purge-status-query">Purge status query</a></h2>
  8636. <p>It is possible to poll for updates on recent purges with a second API;</p>
  8637. <pre><code>GET /_synapse/admin/v1/purge_history_status/&lt;purge_id&gt;
  8638. </code></pre>
  8639. <p>Again, you will need to authenticate by providing an <code>access_token</code> for a
  8640. server admin.</p>
  8641. <p>This API returns a JSON body like the following:</p>
  8642. <pre><code class="language-json">{
  8643. &quot;status&quot;: &quot;active&quot;
  8644. }
  8645. </code></pre>
  8646. <p>The status will be one of <code>active</code>, <code>complete</code>, or <code>failed</code>.</p>
  8647. <h2 id="reclaim-disk-space-postgres"><a class="header" href="#reclaim-disk-space-postgres">Reclaim disk space (Postgres)</a></h2>
  8648. <p>To reclaim the disk space and return it to the operating system, you need to run
  8649. <code>VACUUM FULL;</code> on the database.</p>
  8650. <p><a href="https://www.postgresql.org/docs/current/sql-vacuum.html">https://www.postgresql.org/docs/current/sql-vacuum.html</a></p>
  8651. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="deprecated-purge-room-api"><a class="header" href="#deprecated-purge-room-api">Deprecated: Purge room API</a></h1>
  8652. <p><strong>The old Purge room API is deprecated and will be removed in a future release.
  8653. See the new <a href="admin_api/rooms.html#delete-room-api">Delete Room API</a> for more details.</strong></p>
  8654. <p>This API will remove all trace of a room from your database.</p>
  8655. <p>All local users must have left the room before it can be removed.</p>
  8656. <p>The API is:</p>
  8657. <pre><code>POST /_synapse/admin/v1/purge_room
  8658. {
  8659. &quot;room_id&quot;: &quot;!room:id&quot;
  8660. }
  8661. </code></pre>
  8662. <p>You must authenticate using the access token of an admin user.</p>
  8663. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="shared-secret-registration"><a class="header" href="#shared-secret-registration">Shared-Secret Registration</a></h1>
  8664. <p>This API allows for the creation of users in an administrative and
  8665. non-interactive way. This is generally used for bootstrapping a Synapse
  8666. instance with administrator accounts.</p>
  8667. <p>To authenticate yourself to the server, you will need both the shared secret
  8668. (<code>registration_shared_secret</code> in the homeserver configuration), and a
  8669. one-time nonce. If the registration shared secret is not configured, this API
  8670. is not enabled.</p>
  8671. <p>To fetch the nonce, you need to request one from the API:</p>
  8672. <pre><code>&gt; GET /_synapse/admin/v1/register
  8673. &lt; {&quot;nonce&quot;: &quot;thisisanonce&quot;}
  8674. </code></pre>
  8675. <p>Once you have the nonce, you can make a <code>POST</code> to the same URL with a JSON
  8676. body containing the nonce, username, password, whether they are an admin
  8677. (optional, False by default), and a HMAC digest of the content. Also you can
  8678. set the displayname (optional, <code>username</code> by default).</p>
  8679. <p>As an example:</p>
  8680. <pre><code>&gt; POST /_synapse/admin/v1/register
  8681. &gt; {
  8682. &quot;nonce&quot;: &quot;thisisanonce&quot;,
  8683. &quot;username&quot;: &quot;pepper_roni&quot;,
  8684. &quot;displayname&quot;: &quot;Pepper Roni&quot;,
  8685. &quot;password&quot;: &quot;pizza&quot;,
  8686. &quot;admin&quot;: true,
  8687. &quot;mac&quot;: &quot;mac_digest_here&quot;
  8688. }
  8689. &lt; {
  8690. &quot;access_token&quot;: &quot;token_here&quot;,
  8691. &quot;user_id&quot;: &quot;@pepper_roni:localhost&quot;,
  8692. &quot;home_server&quot;: &quot;test&quot;,
  8693. &quot;device_id&quot;: &quot;device_id_here&quot;
  8694. }
  8695. </code></pre>
  8696. <p>The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
  8697. the shared secret and the content being the nonce, user, password, either the
  8698. string &quot;admin&quot; or &quot;notadmin&quot;, and optionally the user_type
  8699. each separated by NULs. For an example of generation in Python:</p>
  8700. <pre><code class="language-python">import hmac, hashlib
  8701. def generate_mac(nonce, user, password, admin=False, user_type=None):
  8702. mac = hmac.new(
  8703. key=shared_secret,
  8704. digestmod=hashlib.sha1,
  8705. )
  8706. mac.update(nonce.encode('utf8'))
  8707. mac.update(b&quot;\x00&quot;)
  8708. mac.update(user.encode('utf8'))
  8709. mac.update(b&quot;\x00&quot;)
  8710. mac.update(password.encode('utf8'))
  8711. mac.update(b&quot;\x00&quot;)
  8712. mac.update(b&quot;admin&quot; if admin else b&quot;notadmin&quot;)
  8713. if user_type:
  8714. mac.update(b&quot;\x00&quot;)
  8715. mac.update(user_type.encode('utf8'))
  8716. return mac.hexdigest()
  8717. </code></pre>
  8718. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="edit-room-membership-api"><a class="header" href="#edit-room-membership-api">Edit Room Membership API</a></h1>
  8719. <p>This API allows an administrator to join an user account with a given <code>user_id</code>
  8720. to a room with a given <code>room_id_or_alias</code>. You can only modify the membership of
  8721. local users. The server administrator must be in the room and have permission to
  8722. invite users.</p>
  8723. <h2 id="parameters"><a class="header" href="#parameters">Parameters</a></h2>
  8724. <p>The following parameters are available:</p>
  8725. <ul>
  8726. <li><code>user_id</code> - Fully qualified user: for example, <code>@user:server.com</code>.</li>
  8727. <li><code>room_id_or_alias</code> - The room identifier or alias to join: for example,
  8728. <code>!636q39766251:server.com</code>.</li>
  8729. </ul>
  8730. <h2 id="usage-1"><a class="header" href="#usage-1">Usage</a></h2>
  8731. <pre><code>POST /_synapse/admin/v1/join/&lt;room_id_or_alias&gt;
  8732. {
  8733. &quot;user_id&quot;: &quot;@user:server.com&quot;
  8734. }
  8735. </code></pre>
  8736. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8737. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8738. <p>Response:</p>
  8739. <pre><code>{
  8740. &quot;room_id&quot;: &quot;!636q39766251:server.com&quot;
  8741. }
  8742. </code></pre>
  8743. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="contents-2"><a class="header" href="#contents-2">Contents</a></h1>
  8744. <ul>
  8745. <li><a href="admin_api/rooms.html#list-room-api">List Room API</a></li>
  8746. <li><a href="admin_api/rooms.html#room-details-api">Room Details API</a></li>
  8747. <li><a href="admin_api/rooms.html#room-members-api">Room Members API</a></li>
  8748. <li><a href="admin_api/rooms.html#room-state-api">Room State API</a></li>
  8749. <li><a href="admin_api/rooms.html#delete-room-api">Delete Room API</a>
  8750. <ul>
  8751. <li><a href="admin_api/rooms.html#undoing-room-shutdowns">Undoing room shutdowns</a></li>
  8752. </ul>
  8753. </li>
  8754. <li><a href="admin_api/rooms.html#make-room-admin-api">Make Room Admin API</a></li>
  8755. <li><a href="admin_api/rooms.html#forward-extremities-admin-api">Forward Extremities Admin API</a></li>
  8756. <li><a href="admin_api/rooms.html#event-context-api">Event Context API</a></li>
  8757. </ul>
  8758. <h1 id="list-room-api"><a class="header" href="#list-room-api">List Room API</a></h1>
  8759. <p>The List Room admin API allows server admins to get a list of rooms on their
  8760. server. There are various parameters available that allow for filtering and
  8761. sorting the returned list. This API supports pagination.</p>
  8762. <p><strong>Parameters</strong></p>
  8763. <p>The following query parameters are available:</p>
  8764. <ul>
  8765. <li><code>from</code> - Offset in the returned list. Defaults to <code>0</code>.</li>
  8766. <li><code>limit</code> - Maximum amount of rooms to return. Defaults to <code>100</code>.</li>
  8767. <li><code>order_by</code> - The method in which to sort the returned list of rooms. Valid values are:
  8768. <ul>
  8769. <li><code>alphabetical</code> - Same as <code>name</code>. This is deprecated.</li>
  8770. <li><code>size</code> - Same as <code>joined_members</code>. This is deprecated.</li>
  8771. <li><code>name</code> - Rooms are ordered alphabetically by room name. This is the default.</li>
  8772. <li><code>canonical_alias</code> - Rooms are ordered alphabetically by main alias address of the room.</li>
  8773. <li><code>joined_members</code> - Rooms are ordered by the number of members. Largest to smallest.</li>
  8774. <li><code>joined_local_members</code> - Rooms are ordered by the number of local members. Largest to smallest.</li>
  8775. <li><code>version</code> - Rooms are ordered by room version. Largest to smallest.</li>
  8776. <li><code>creator</code> - Rooms are ordered alphabetically by creator of the room.</li>
  8777. <li><code>encryption</code> - Rooms are ordered alphabetically by the end-to-end encryption algorithm.</li>
  8778. <li><code>federatable</code> - Rooms are ordered by whether the room is federatable.</li>
  8779. <li><code>public</code> - Rooms are ordered by visibility in room list.</li>
  8780. <li><code>join_rules</code> - Rooms are ordered alphabetically by join rules of the room.</li>
  8781. <li><code>guest_access</code> - Rooms are ordered alphabetically by guest access option of the room.</li>
  8782. <li><code>history_visibility</code> - Rooms are ordered alphabetically by visibility of history of the room.</li>
  8783. <li><code>state_events</code> - Rooms are ordered by number of state events. Largest to smallest.</li>
  8784. </ul>
  8785. </li>
  8786. <li><code>dir</code> - Direction of room order. Either <code>f</code> for forwards or <code>b</code> for backwards. Setting
  8787. this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  8788. <li><code>search_term</code> - Filter rooms by their room name. Search term can be contained in any
  8789. part of the room name. Defaults to no filtering.</li>
  8790. </ul>
  8791. <p><strong>Response</strong></p>
  8792. <p>The following fields are possible in the JSON response body:</p>
  8793. <ul>
  8794. <li><code>rooms</code> - An array of objects, each containing information about a room.
  8795. <ul>
  8796. <li>Room objects contain the following fields:
  8797. <ul>
  8798. <li><code>room_id</code> - The ID of the room.</li>
  8799. <li><code>name</code> - The name of the room.</li>
  8800. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  8801. <li><code>joined_members</code> - How many users are currently in the room.</li>
  8802. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  8803. <li><code>version</code> - The version of the room as a string.</li>
  8804. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  8805. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  8806. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  8807. <li><code>public</code> - Whether the room is visible in room directory.</li>
  8808. <li><code>join_rules</code> - The type of rules used for users wishing to join this room. One of: [&quot;public&quot;, &quot;knock&quot;, &quot;invite&quot;, &quot;private&quot;].</li>
  8809. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  8810. <li><code>history_visibility</code> - Who can see the room history. One of: [&quot;invited&quot;, &quot;joined&quot;, &quot;shared&quot;, &quot;world_readable&quot;].</li>
  8811. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  8812. </ul>
  8813. </li>
  8814. </ul>
  8815. </li>
  8816. <li><code>offset</code> - The current pagination offset in rooms. This parameter should be
  8817. used instead of <code>next_token</code> for room offset as <code>next_token</code> is
  8818. not intended to be parsed.</li>
  8819. <li><code>total_rooms</code> - The total number of rooms this query can return. Using this
  8820. and <code>offset</code>, you have enough information to know the current
  8821. progression through the list.</li>
  8822. <li><code>next_batch</code> - If this field is present, we know that there are potentially
  8823. more rooms on the server that did not all fit into this response.
  8824. We can use <code>next_batch</code> to get the &quot;next page&quot; of results. To do
  8825. so, simply repeat your request, setting the <code>from</code> parameter to
  8826. the value of <code>next_batch</code>.</li>
  8827. <li><code>prev_batch</code> - If this field is present, it is possible to paginate backwards.
  8828. Use <code>prev_batch</code> for the <code>from</code> value in the next request to
  8829. get the &quot;previous page&quot; of results.</li>
  8830. </ul>
  8831. <p>The API is:</p>
  8832. <p>A standard request with no filtering:</p>
  8833. <pre><code>GET /_synapse/admin/v1/rooms
  8834. </code></pre>
  8835. <p>A response body like the following is returned:</p>
  8836. <pre><code class="language-jsonc">{
  8837. &quot;rooms&quot;: [
  8838. {
  8839. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  8840. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8841. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  8842. &quot;joined_members&quot;: 8326,
  8843. &quot;joined_local_members&quot;: 2,
  8844. &quot;version&quot;: &quot;1&quot;,
  8845. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8846. &quot;encryption&quot;: null,
  8847. &quot;federatable&quot;: true,
  8848. &quot;public&quot;: true,
  8849. &quot;join_rules&quot;: &quot;invite&quot;,
  8850. &quot;guest_access&quot;: null,
  8851. &quot;history_visibility&quot;: &quot;shared&quot;,
  8852. &quot;state_events&quot;: 93534
  8853. },
  8854. ... (8 hidden items) ...
  8855. {
  8856. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8857. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8858. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8859. &quot;joined_members&quot;: 314,
  8860. &quot;joined_local_members&quot;: 20,
  8861. &quot;version&quot;: &quot;4&quot;,
  8862. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8863. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8864. &quot;federatable&quot;: true,
  8865. &quot;public&quot;: false,
  8866. &quot;join_rules&quot;: &quot;invite&quot;,
  8867. &quot;guest_access&quot;: null,
  8868. &quot;history_visibility&quot;: &quot;shared&quot;,
  8869. &quot;state_events&quot;: 8345
  8870. }
  8871. ],
  8872. &quot;offset&quot;: 0,
  8873. &quot;total_rooms&quot;: 10
  8874. }
  8875. </code></pre>
  8876. <p>Filtering by room name:</p>
  8877. <pre><code>GET /_synapse/admin/v1/rooms?search_term=TWIM
  8878. </code></pre>
  8879. <p>A response body like the following is returned:</p>
  8880. <pre><code class="language-json">{
  8881. &quot;rooms&quot;: [
  8882. {
  8883. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8884. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8885. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8886. &quot;joined_members&quot;: 314,
  8887. &quot;joined_local_members&quot;: 20,
  8888. &quot;version&quot;: &quot;4&quot;,
  8889. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8890. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8891. &quot;federatable&quot;: true,
  8892. &quot;public&quot;: false,
  8893. &quot;join_rules&quot;: &quot;invite&quot;,
  8894. &quot;guest_access&quot;: null,
  8895. &quot;history_visibility&quot;: &quot;shared&quot;,
  8896. &quot;state_events&quot;: 8
  8897. }
  8898. ],
  8899. &quot;offset&quot;: 0,
  8900. &quot;total_rooms&quot;: 1
  8901. }
  8902. </code></pre>
  8903. <p>Paginating through a list of rooms:</p>
  8904. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size
  8905. </code></pre>
  8906. <p>A response body like the following is returned:</p>
  8907. <pre><code class="language-jsonc">{
  8908. &quot;rooms&quot;: [
  8909. {
  8910. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  8911. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8912. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  8913. &quot;joined_members&quot;: 8326,
  8914. &quot;joined_local_members&quot;: 2,
  8915. &quot;version&quot;: &quot;1&quot;,
  8916. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8917. &quot;encryption&quot;: null,
  8918. &quot;federatable&quot;: true,
  8919. &quot;public&quot;: true,
  8920. &quot;join_rules&quot;: &quot;invite&quot;,
  8921. &quot;guest_access&quot;: null,
  8922. &quot;history_visibility&quot;: &quot;shared&quot;,
  8923. &quot;state_events&quot;: 93534
  8924. },
  8925. ... (98 hidden items) ...
  8926. {
  8927. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8928. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8929. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8930. &quot;joined_members&quot;: 314,
  8931. &quot;joined_local_members&quot;: 20,
  8932. &quot;version&quot;: &quot;4&quot;,
  8933. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8934. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8935. &quot;federatable&quot;: true,
  8936. &quot;public&quot;: false,
  8937. &quot;join_rules&quot;: &quot;invite&quot;,
  8938. &quot;guest_access&quot;: null,
  8939. &quot;history_visibility&quot;: &quot;shared&quot;,
  8940. &quot;state_events&quot;: 8345
  8941. }
  8942. ],
  8943. &quot;offset&quot;: 0,
  8944. &quot;total_rooms&quot;: 150
  8945. &quot;next_token&quot;: 100
  8946. }
  8947. </code></pre>
  8948. <p>The presence of the <code>next_token</code> parameter tells us that there are more rooms
  8949. than returned in this request, and we need to make another request to get them.
  8950. To get the next batch of room results, we repeat our request, setting the <code>from</code>
  8951. parameter to the value of <code>next_token</code>.</p>
  8952. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size&amp;from=100
  8953. </code></pre>
  8954. <p>A response body like the following is returned:</p>
  8955. <pre><code class="language-jsonc">{
  8956. &quot;rooms&quot;: [
  8957. {
  8958. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  8959. &quot;name&quot;: &quot;Music Theory&quot;,
  8960. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  8961. &quot;joined_members&quot;: 127,
  8962. &quot;joined_local_members&quot;: 2,
  8963. &quot;version&quot;: &quot;1&quot;,
  8964. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8965. &quot;encryption&quot;: null,
  8966. &quot;federatable&quot;: true,
  8967. &quot;public&quot;: true,
  8968. &quot;join_rules&quot;: &quot;invite&quot;,
  8969. &quot;guest_access&quot;: null,
  8970. &quot;history_visibility&quot;: &quot;shared&quot;,
  8971. &quot;state_events&quot;: 93534
  8972. },
  8973. ... (48 hidden items) ...
  8974. {
  8975. &quot;room_id&quot;: &quot;!twcBhHVdZlQWuuxBhN:termina.org.uk&quot;,
  8976. &quot;name&quot;: &quot;weechat-matrix&quot;,
  8977. &quot;canonical_alias&quot;: &quot;#weechat-matrix:termina.org.uk&quot;,
  8978. &quot;joined_members&quot;: 137,
  8979. &quot;joined_local_members&quot;: 20,
  8980. &quot;version&quot;: &quot;4&quot;,
  8981. &quot;creator&quot;: &quot;@foo:termina.org.uk&quot;,
  8982. &quot;encryption&quot;: null,
  8983. &quot;federatable&quot;: true,
  8984. &quot;public&quot;: true,
  8985. &quot;join_rules&quot;: &quot;invite&quot;,
  8986. &quot;guest_access&quot;: null,
  8987. &quot;history_visibility&quot;: &quot;shared&quot;,
  8988. &quot;state_events&quot;: 8345
  8989. }
  8990. ],
  8991. &quot;offset&quot;: 100,
  8992. &quot;prev_batch&quot;: 0,
  8993. &quot;total_rooms&quot;: 150
  8994. }
  8995. </code></pre>
  8996. <p>Once the <code>next_token</code> parameter is no longer present, we know we've reached the
  8997. end of the list.</p>
  8998. <h1 id="room-details-api"><a class="header" href="#room-details-api">Room Details API</a></h1>
  8999. <p>The Room Details admin API allows server admins to get all details of a room.</p>
  9000. <p>The following fields are possible in the JSON response body:</p>
  9001. <ul>
  9002. <li><code>room_id</code> - The ID of the room.</li>
  9003. <li><code>name</code> - The name of the room.</li>
  9004. <li><code>topic</code> - The topic of the room.</li>
  9005. <li><code>avatar</code> - The <code>mxc</code> URI to the avatar of the room.</li>
  9006. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  9007. <li><code>joined_members</code> - How many users are currently in the room.</li>
  9008. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  9009. <li><code>joined_local_devices</code> - How many local devices are currently in the room.</li>
  9010. <li><code>version</code> - The version of the room as a string.</li>
  9011. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  9012. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  9013. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  9014. <li><code>public</code> - Whether the room is visible in room directory.</li>
  9015. <li><code>join_rules</code> - The type of rules used for users wishing to join this room. One of: [&quot;public&quot;, &quot;knock&quot;, &quot;invite&quot;, &quot;private&quot;].</li>
  9016. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  9017. <li><code>history_visibility</code> - Who can see the room history. One of: [&quot;invited&quot;, &quot;joined&quot;, &quot;shared&quot;, &quot;world_readable&quot;].</li>
  9018. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  9019. </ul>
  9020. <p>The API is:</p>
  9021. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9022. </code></pre>
  9023. <p>A response body like the following is returned:</p>
  9024. <pre><code class="language-json">{
  9025. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  9026. &quot;name&quot;: &quot;Music Theory&quot;,
  9027. &quot;avatar&quot;: &quot;mxc://matrix.org/AQDaVFlbkQoErdOgqWRgiGSV&quot;,
  9028. &quot;topic&quot;: &quot;Theory, Composition, Notation, Analysis&quot;,
  9029. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  9030. &quot;joined_members&quot;: 127,
  9031. &quot;joined_local_members&quot;: 2,
  9032. &quot;joined_local_devices&quot;: 2,
  9033. &quot;version&quot;: &quot;1&quot;,
  9034. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9035. &quot;encryption&quot;: null,
  9036. &quot;federatable&quot;: true,
  9037. &quot;public&quot;: true,
  9038. &quot;join_rules&quot;: &quot;invite&quot;,
  9039. &quot;guest_access&quot;: null,
  9040. &quot;history_visibility&quot;: &quot;shared&quot;,
  9041. &quot;state_events&quot;: 93534
  9042. }
  9043. </code></pre>
  9044. <h1 id="room-members-api"><a class="header" href="#room-members-api">Room Members API</a></h1>
  9045. <p>The Room Members admin API allows server admins to get a list of all members of a room.</p>
  9046. <p>The response includes the following fields:</p>
  9047. <ul>
  9048. <li><code>members</code> - A list of all the members that are present in the room, represented by their ids.</li>
  9049. <li><code>total</code> - Total number of members in the room.</li>
  9050. </ul>
  9051. <p>The API is:</p>
  9052. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/members
  9053. </code></pre>
  9054. <p>A response body like the following is returned:</p>
  9055. <pre><code class="language-json">{
  9056. &quot;members&quot;: [
  9057. &quot;@foo:matrix.org&quot;,
  9058. &quot;@bar:matrix.org&quot;,
  9059. &quot;@foobar:matrix.org&quot;
  9060. ],
  9061. &quot;total&quot;: 3
  9062. }
  9063. </code></pre>
  9064. <h1 id="room-state-api"><a class="header" href="#room-state-api">Room State API</a></h1>
  9065. <p>The Room State admin API allows server admins to get a list of all state events in a room.</p>
  9066. <p>The response includes the following fields:</p>
  9067. <ul>
  9068. <li><code>state</code> - The current state of the room at the time of request.</li>
  9069. </ul>
  9070. <p>The API is:</p>
  9071. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/state
  9072. </code></pre>
  9073. <p>A response body like the following is returned:</p>
  9074. <pre><code class="language-json">{
  9075. &quot;state&quot;: [
  9076. {&quot;type&quot;: &quot;m.room.create&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9077. {&quot;type&quot;: &quot;m.room.power_levels&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9078. {&quot;type&quot;: &quot;m.room.name&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true}
  9079. ]
  9080. }
  9081. </code></pre>
  9082. <h1 id="delete-room-api"><a class="header" href="#delete-room-api">Delete Room API</a></h1>
  9083. <p>The Delete Room admin API allows server admins to remove rooms from server
  9084. and block these rooms.</p>
  9085. <p>Shuts down a room. Moves all local users and room aliases automatically to a
  9086. new room if <code>new_room_user_id</code> is set. Otherwise local users only
  9087. leave the room without any information.</p>
  9088. <p>The new room will be created with the user specified by the <code>new_room_user_id</code> parameter
  9089. as room administrator and will contain a message explaining what happened. Users invited
  9090. to the new room will have power level <code>-10</code> by default, and thus be unable to speak.</p>
  9091. <p>If <code>block</code> is <code>True</code> it prevents new joins to the old room.</p>
  9092. <p>This API will remove all trace of the old room from your database after removing
  9093. all local users. If <code>purge</code> is <code>true</code> (the default), all traces of the old room will
  9094. be removed from your database after removing all local users. If you do not want
  9095. this to happen, set <code>purge</code> to <code>false</code>.
  9096. Depending on the amount of history being purged a call to the API may take
  9097. several minutes or longer.</p>
  9098. <p>The local server will only have the power to move local user and room aliases to
  9099. the new room. Users on other servers will be unaffected.</p>
  9100. <p>The API is:</p>
  9101. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9102. </code></pre>
  9103. <p>with a body of:</p>
  9104. <pre><code class="language-json">{
  9105. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  9106. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  9107. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;,
  9108. &quot;block&quot;: true,
  9109. &quot;purge&quot;: true
  9110. }
  9111. </code></pre>
  9112. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9113. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9114. <p>A response body like the following is returned:</p>
  9115. <pre><code class="language-json">{
  9116. &quot;kicked_users&quot;: [
  9117. &quot;@foobar:example.com&quot;
  9118. ],
  9119. &quot;failed_to_kick_users&quot;: [],
  9120. &quot;local_aliases&quot;: [
  9121. &quot;#badroom:example.com&quot;,
  9122. &quot;#evilsaloon:example.com&quot;
  9123. ],
  9124. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;
  9125. }
  9126. </code></pre>
  9127. <p><strong>Parameters</strong></p>
  9128. <p>The following parameters should be set in the URL:</p>
  9129. <ul>
  9130. <li><code>room_id</code> - The ID of the room.</li>
  9131. </ul>
  9132. <p>The following JSON body parameters are available:</p>
  9133. <ul>
  9134. <li><code>new_room_user_id</code> - Optional. If set, a new room will be created with this user ID
  9135. as the creator and admin, and all users in the old room will be moved into that
  9136. room. If not set, no new room will be created and the users will just be removed
  9137. from the old room. The user ID must be on the local server, but does not necessarily
  9138. have to belong to a registered user.</li>
  9139. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  9140. invited to. Defaults to <code>Content Violation Notification</code></li>
  9141. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  9142. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  9143. original room was shut down. Defaults to <code>Sharing illegal content on this server is not permitted and rooms in violation will be blocked.</code></li>
  9144. <li><code>block</code> - Optional. If set to <code>true</code>, this room will be added to a blocking list, preventing
  9145. future attempts to join the room. Defaults to <code>false</code>.</li>
  9146. <li><code>purge</code> - Optional. If set to <code>true</code>, it will remove all traces of the room from your database.
  9147. Defaults to <code>true</code>.</li>
  9148. <li><code>force_purge</code> - Optional, and ignored unless <code>purge</code> is <code>true</code>. If set to <code>true</code>, it
  9149. will force a purge to go ahead even if there are local users still in the room. Do not
  9150. use this unless a regular <code>purge</code> operation fails, as it could leave those users'
  9151. clients in a confused state.</li>
  9152. </ul>
  9153. <p>The JSON body must not be empty. The body must be at least <code>{}</code>.</p>
  9154. <p><strong>Response</strong></p>
  9155. <p>The following fields are returned in the JSON response body:</p>
  9156. <ul>
  9157. <li><code>kicked_users</code> - An array of users (<code>user_id</code>) that were kicked.</li>
  9158. <li><code>failed_to_kick_users</code> - An array of users (<code>user_id</code>) that that were not kicked.</li>
  9159. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  9160. the old room to the new.</li>
  9161. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  9162. </ul>
  9163. <h2 id="undoing-room-shutdowns"><a class="header" href="#undoing-room-shutdowns">Undoing room shutdowns</a></h2>
  9164. <p><em>Note</em>: This guide may be outdated by the time you read it. By nature of room shutdowns being performed at the database level,
  9165. the structure can and does change without notice.</p>
  9166. <p>First, it's important to understand that a room shutdown is very destructive. Undoing a shutdown is not as simple as pretending it
  9167. never happened - work has to be done to move forward instead of resetting the past. In fact, in some cases it might not be possible
  9168. to recover at all:</p>
  9169. <ul>
  9170. <li>If the room was invite-only, your users will need to be re-invited.</li>
  9171. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  9172. <li>The first user to rejoin will have to do so via an alias on a different server.</li>
  9173. </ul>
  9174. <p>With all that being said, if you still want to try and recover the room:</p>
  9175. <ol>
  9176. <li>For safety reasons, shut down Synapse.</li>
  9177. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  9178. <ul>
  9179. <li>For caution: it's recommended to run this in a transaction: <code>BEGIN; DELETE ...;</code>, verify you got 1 result, then <code>COMMIT;</code>.</li>
  9180. <li>The room ID is the same one supplied to the shutdown room API, not the Content Violation room.</li>
  9181. </ul>
  9182. </li>
  9183. <li>Restart Synapse.</li>
  9184. </ol>
  9185. <p>You will have to manually handle, if you so choose, the following:</p>
  9186. <ul>
  9187. <li>Aliases that would have been redirected to the Content Violation room.</li>
  9188. <li>Users that would have been booted from the room (and will have been force-joined to the Content Violation room).</li>
  9189. <li>Removal of the Content Violation room if desired.</li>
  9190. </ul>
  9191. <h2 id="deprecated-endpoint"><a class="header" href="#deprecated-endpoint">Deprecated endpoint</a></h2>
  9192. <p>The previous deprecated API will be removed in a future release, it was:</p>
  9193. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id&gt;/delete
  9194. </code></pre>
  9195. <p>It behaves the same way than the current endpoint except the path and the method.</p>
  9196. <h1 id="make-room-admin-api"><a class="header" href="#make-room-admin-api">Make Room Admin API</a></h1>
  9197. <p>Grants another user the highest power available to a local user who is in the room.
  9198. If the user is not in the room, and it is not publicly joinable, then invite the user.</p>
  9199. <p>By default the server admin (the caller) is granted power, but another user can
  9200. optionally be specified, e.g.:</p>
  9201. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/make_room_admin
  9202. {
  9203. &quot;user_id&quot;: &quot;@foo:example.com&quot;
  9204. }
  9205. </code></pre>
  9206. <h1 id="forward-extremities-admin-api"><a class="header" href="#forward-extremities-admin-api">Forward Extremities Admin API</a></h1>
  9207. <p>Enables querying and deleting forward extremities from rooms. When a lot of forward
  9208. extremities accumulate in a room, performance can become degraded. For details, see
  9209. <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.</p>
  9210. <h2 id="check-for-forward-extremities"><a class="header" href="#check-for-forward-extremities">Check for forward extremities</a></h2>
  9211. <p>To check the status of forward extremities for a room:</p>
  9212. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9213. </code></pre>
  9214. <p>A response as follows will be returned:</p>
  9215. <pre><code class="language-json">{
  9216. &quot;count&quot;: 1,
  9217. &quot;results&quot;: [
  9218. {
  9219. &quot;event_id&quot;: &quot;$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdefgh&quot;,
  9220. &quot;state_group&quot;: 439,
  9221. &quot;depth&quot;: 123,
  9222. &quot;received_ts&quot;: 1611263016761
  9223. }
  9224. ]
  9225. }
  9226. </code></pre>
  9227. <h2 id="deleting-forward-extremities"><a class="header" href="#deleting-forward-extremities">Deleting forward extremities</a></h2>
  9228. <p><strong>WARNING</strong>: Please ensure you know what you're doing and have read
  9229. the related issue <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.
  9230. Under no situations should this API be executed as an automated maintenance task!</p>
  9231. <p>If a room has lots of forward extremities, the extra can be
  9232. deleted as follows:</p>
  9233. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9234. </code></pre>
  9235. <p>A response as follows will be returned, indicating the amount of forward extremities
  9236. that were deleted.</p>
  9237. <pre><code class="language-json">{
  9238. &quot;deleted&quot;: 1
  9239. }
  9240. </code></pre>
  9241. <h1 id="event-context-api"><a class="header" href="#event-context-api">Event Context API</a></h1>
  9242. <p>This API lets a client find the context of an event. This is designed primarily to investigate abuse reports.</p>
  9243. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/context/&lt;event_id&gt;
  9244. </code></pre>
  9245. <p>This API mimmicks <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-context-eventid">GET /_matrix/client/r0/rooms/{roomId}/context/{eventId}</a>. Please refer to the link for all details on parameters and reseponse.</p>
  9246. <p>Example response:</p>
  9247. <pre><code class="language-json">{
  9248. &quot;end&quot;: &quot;t29-57_2_0_2&quot;,
  9249. &quot;events_after&quot;: [
  9250. {
  9251. &quot;content&quot;: {
  9252. &quot;body&quot;: &quot;This is an example text message&quot;,
  9253. &quot;msgtype&quot;: &quot;m.text&quot;,
  9254. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  9255. &quot;formatted_body&quot;: &quot;&lt;b&gt;This is an example text message&lt;/b&gt;&quot;
  9256. },
  9257. &quot;type&quot;: &quot;m.room.message&quot;,
  9258. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9259. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9260. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9261. &quot;origin_server_ts&quot;: 1432735824653,
  9262. &quot;unsigned&quot;: {
  9263. &quot;age&quot;: 1234
  9264. }
  9265. }
  9266. ],
  9267. &quot;event&quot;: {
  9268. &quot;content&quot;: {
  9269. &quot;body&quot;: &quot;filename.jpg&quot;,
  9270. &quot;info&quot;: {
  9271. &quot;h&quot;: 398,
  9272. &quot;w&quot;: 394,
  9273. &quot;mimetype&quot;: &quot;image/jpeg&quot;,
  9274. &quot;size&quot;: 31037
  9275. },
  9276. &quot;url&quot;: &quot;mxc://example.org/JWEIFJgwEIhweiWJE&quot;,
  9277. &quot;msgtype&quot;: &quot;m.image&quot;
  9278. },
  9279. &quot;type&quot;: &quot;m.room.message&quot;,
  9280. &quot;event_id&quot;: &quot;$f3h4d129462ha:example.com&quot;,
  9281. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9282. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9283. &quot;origin_server_ts&quot;: 1432735824653,
  9284. &quot;unsigned&quot;: {
  9285. &quot;age&quot;: 1234
  9286. }
  9287. },
  9288. &quot;events_before&quot;: [
  9289. {
  9290. &quot;content&quot;: {
  9291. &quot;body&quot;: &quot;something-important.doc&quot;,
  9292. &quot;filename&quot;: &quot;something-important.doc&quot;,
  9293. &quot;info&quot;: {
  9294. &quot;mimetype&quot;: &quot;application/msword&quot;,
  9295. &quot;size&quot;: 46144
  9296. },
  9297. &quot;msgtype&quot;: &quot;m.file&quot;,
  9298. &quot;url&quot;: &quot;mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe&quot;
  9299. },
  9300. &quot;type&quot;: &quot;m.room.message&quot;,
  9301. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9302. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9303. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9304. &quot;origin_server_ts&quot;: 1432735824653,
  9305. &quot;unsigned&quot;: {
  9306. &quot;age&quot;: 1234
  9307. }
  9308. }
  9309. ],
  9310. &quot;start&quot;: &quot;t27-54_2_0_2&quot;,
  9311. &quot;state&quot;: [
  9312. {
  9313. &quot;content&quot;: {
  9314. &quot;creator&quot;: &quot;@example:example.org&quot;,
  9315. &quot;room_version&quot;: &quot;1&quot;,
  9316. &quot;m.federate&quot;: true,
  9317. &quot;predecessor&quot;: {
  9318. &quot;event_id&quot;: &quot;$something:example.org&quot;,
  9319. &quot;room_id&quot;: &quot;!oldroom:example.org&quot;
  9320. }
  9321. },
  9322. &quot;type&quot;: &quot;m.room.create&quot;,
  9323. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9324. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9325. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9326. &quot;origin_server_ts&quot;: 1432735824653,
  9327. &quot;unsigned&quot;: {
  9328. &quot;age&quot;: 1234
  9329. },
  9330. &quot;state_key&quot;: &quot;&quot;
  9331. },
  9332. {
  9333. &quot;content&quot;: {
  9334. &quot;membership&quot;: &quot;join&quot;,
  9335. &quot;avatar_url&quot;: &quot;mxc://example.org/SEsfnsuifSDFSSEF&quot;,
  9336. &quot;displayname&quot;: &quot;Alice Margatroid&quot;
  9337. },
  9338. &quot;type&quot;: &quot;m.room.member&quot;,
  9339. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9340. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9341. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9342. &quot;origin_server_ts&quot;: 1432735824653,
  9343. &quot;unsigned&quot;: {
  9344. &quot;age&quot;: 1234
  9345. },
  9346. &quot;state_key&quot;: &quot;@alice:example.org&quot;
  9347. }
  9348. ]
  9349. }
  9350. </code></pre>
  9351. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="server-notices-1"><a class="header" href="#server-notices-1">Server Notices</a></h1>
  9352. <p>The API to send notices is as follows:</p>
  9353. <pre><code>POST /_synapse/admin/v1/send_server_notice
  9354. </code></pre>
  9355. <p>or:</p>
  9356. <pre><code>PUT /_synapse/admin/v1/send_server_notice/{txnId}
  9357. </code></pre>
  9358. <p>You will need to authenticate with an access token for an admin user.</p>
  9359. <p>When using the <code>PUT</code> form, retransmissions with the same transaction ID will be
  9360. ignored in the same way as with <code>PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}</code>.</p>
  9361. <p>The request body should look something like the following:</p>
  9362. <pre><code class="language-json">{
  9363. &quot;user_id&quot;: &quot;@target_user:server_name&quot;,
  9364. &quot;content&quot;: {
  9365. &quot;msgtype&quot;: &quot;m.text&quot;,
  9366. &quot;body&quot;: &quot;This is my message&quot;
  9367. }
  9368. }
  9369. </code></pre>
  9370. <p>You can optionally include the following additional parameters:</p>
  9371. <ul>
  9372. <li><code>type</code>: the type of event. Defaults to <code>m.room.message</code>.</li>
  9373. <li><code>state_key</code>: Setting this will result in a state event being sent.</li>
  9374. </ul>
  9375. <p>Once the notice has been sent, the API will return the following response:</p>
  9376. <pre><code class="language-json">{
  9377. &quot;event_id&quot;: &quot;&lt;event_id&gt;&quot;
  9378. }
  9379. </code></pre>
  9380. <p>Note that server notices must be enabled in <code>homeserver.yaml</code> before this API
  9381. can be used. See <a href="admin_api/../server_notices.html">the server notices documentation</a> for more information.</p>
  9382. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="deprecated-shutdown-room-api"><a class="header" href="#deprecated-shutdown-room-api">Deprecated: Shutdown room API</a></h1>
  9383. <p><strong>The old Shutdown room API is deprecated and will be removed in a future release.
  9384. See the new <a href="admin_api/rooms.html#delete-room-api">Delete Room API</a> for more details.</strong></p>
  9385. <p>Shuts down a room, preventing new joins and moves local users and room aliases automatically
  9386. to a new room. The new room will be created with the user specified by the
  9387. <code>new_room_user_id</code> parameter as room administrator and will contain a message
  9388. explaining what happened. Users invited to the new room will have power level
  9389. -10 by default, and thus be unable to speak. The old room's power levels will be changed to
  9390. disallow any further invites or joins.</p>
  9391. <p>The local server will only have the power to move local user and room aliases to
  9392. the new room. Users on other servers will be unaffected.</p>
  9393. <h2 id="api-1"><a class="header" href="#api-1">API</a></h2>
  9394. <p>You will need to authenticate with an access token for an admin user.</p>
  9395. <h3 id="url"><a class="header" href="#url">URL</a></h3>
  9396. <p><code>POST /_synapse/admin/v1/shutdown_room/{room_id}</code></p>
  9397. <h3 id="url-parameters"><a class="header" href="#url-parameters">URL Parameters</a></h3>
  9398. <ul>
  9399. <li><code>room_id</code> - The ID of the room (e.g <code>!someroom:example.com</code>)</li>
  9400. </ul>
  9401. <h3 id="json-body-parameters"><a class="header" href="#json-body-parameters">JSON Body Parameters</a></h3>
  9402. <ul>
  9403. <li><code>new_room_user_id</code> - Required. A string representing the user ID of the user that will admin
  9404. the new room that all users in the old room will be moved to.</li>
  9405. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  9406. invited to.</li>
  9407. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  9408. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  9409. original room was shut down.</li>
  9410. </ul>
  9411. <p>If not specified, the default value of <code>room_name</code> is &quot;Content Violation
  9412. Notification&quot;. The default value of <code>message</code> is &quot;Sharing illegal content on
  9413. othis server is not permitted and rooms in violation will be blocked.&quot;</p>
  9414. <h3 id="response-parameters"><a class="header" href="#response-parameters">Response Parameters</a></h3>
  9415. <ul>
  9416. <li><code>kicked_users</code> - An integer number representing the number of users that
  9417. were kicked.</li>
  9418. <li><code>failed_to_kick_users</code> - An integer number representing the number of users
  9419. that were not kicked.</li>
  9420. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  9421. the old room to the new.</li>
  9422. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  9423. </ul>
  9424. <h2 id="example-4"><a class="header" href="#example-4">Example</a></h2>
  9425. <p>Request:</p>
  9426. <pre><code>POST /_synapse/admin/v1/shutdown_room/!somebadroom%3Aexample.com
  9427. {
  9428. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  9429. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  9430. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;
  9431. }
  9432. </code></pre>
  9433. <p>Response:</p>
  9434. <pre><code>{
  9435. &quot;kicked_users&quot;: 5,
  9436. &quot;failed_to_kick_users&quot;: 0,
  9437. &quot;local_aliases&quot;: [&quot;#badroom:example.com&quot;, &quot;#evilsaloon:example.com],
  9438. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;,
  9439. },
  9440. </code></pre>
  9441. <h2 id="undoing-room-shutdowns-1"><a class="header" href="#undoing-room-shutdowns-1">Undoing room shutdowns</a></h2>
  9442. <p><em>Note</em>: This guide may be outdated by the time you read it. By nature of room shutdowns being performed at the database level,
  9443. the structure can and does change without notice.</p>
  9444. <p>First, it's important to understand that a room shutdown is very destructive. Undoing a shutdown is not as simple as pretending it
  9445. never happened - work has to be done to move forward instead of resetting the past. In fact, in some cases it might not be possible
  9446. to recover at all:</p>
  9447. <ul>
  9448. <li>If the room was invite-only, your users will need to be re-invited.</li>
  9449. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  9450. <li>The first user to rejoin will have to do so via an alias on a different server.</li>
  9451. </ul>
  9452. <p>With all that being said, if you still want to try and recover the room:</p>
  9453. <ol>
  9454. <li>For safety reasons, shut down Synapse.</li>
  9455. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  9456. <ul>
  9457. <li>For caution: it's recommended to run this in a transaction: <code>BEGIN; DELETE ...;</code>, verify you got 1 result, then <code>COMMIT;</code>.</li>
  9458. <li>The room ID is the same one supplied to the shutdown room API, not the Content Violation room.</li>
  9459. </ul>
  9460. </li>
  9461. <li>Restart Synapse.</li>
  9462. </ol>
  9463. <p>You will have to manually handle, if you so choose, the following:</p>
  9464. <ul>
  9465. <li>Aliases that would have been redirected to the Content Violation room.</li>
  9466. <li>Users that would have been booted from the room (and will have been force-joined to the Content Violation room).</li>
  9467. <li>Removal of the Content Violation room if desired.</li>
  9468. </ul>
  9469. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="users-media-usage-statistics"><a class="header" href="#users-media-usage-statistics">Users' media usage statistics</a></h1>
  9470. <p>Returns information about all local media usage of users. Gives the
  9471. possibility to filter them by time and user.</p>
  9472. <p>The API is:</p>
  9473. <pre><code>GET /_synapse/admin/v1/statistics/users/media
  9474. </code></pre>
  9475. <p>To use it, you will need to authenticate by providing an <code>access_token</code>
  9476. for a server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9477. <p>A response body like the following is returned:</p>
  9478. <pre><code class="language-json">{
  9479. &quot;users&quot;: [
  9480. {
  9481. &quot;displayname&quot;: &quot;foo_user_0&quot;,
  9482. &quot;media_count&quot;: 2,
  9483. &quot;media_length&quot;: 134,
  9484. &quot;user_id&quot;: &quot;@foo_user_0:test&quot;
  9485. },
  9486. {
  9487. &quot;displayname&quot;: &quot;foo_user_1&quot;,
  9488. &quot;media_count&quot;: 2,
  9489. &quot;media_length&quot;: 134,
  9490. &quot;user_id&quot;: &quot;@foo_user_1:test&quot;
  9491. }
  9492. ],
  9493. &quot;next_token&quot;: 3,
  9494. &quot;total&quot;: 10
  9495. }
  9496. </code></pre>
  9497. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint
  9498. again with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9499. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9500. reports to paginate through.</p>
  9501. <p><strong>Parameters</strong></p>
  9502. <p>The following parameters should be set in the URL:</p>
  9503. <ul>
  9504. <li><code>limit</code>: string representing a positive integer - Is optional but is
  9505. used for pagination, denoting the maximum number of items to return
  9506. in this call. Defaults to <code>100</code>.</li>
  9507. <li><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9508. denoting the offset in the returned results. This should be treated as an opaque value
  9509. and not explicitly set to anything other than the return value of <code>next_token</code> from a
  9510. previous call. Defaults to <code>0</code>.</li>
  9511. <li><code>order_by</code> - string - The method in which to sort the returned list of users. Valid values are:
  9512. <ul>
  9513. <li><code>user_id</code> - Users are ordered alphabetically by <code>user_id</code>. This is the default.</li>
  9514. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9515. <li><code>media_length</code> - Users are ordered by the total size of uploaded media in bytes.
  9516. Smallest to largest.</li>
  9517. <li><code>media_count</code> - Users are ordered by number of uploaded media. Smallest to largest.</li>
  9518. </ul>
  9519. </li>
  9520. <li><code>from_ts</code> - string representing a positive integer - Considers only
  9521. files created at this timestamp or later. Unix timestamp in ms.</li>
  9522. <li><code>until_ts</code> - string representing a positive integer - Considers only
  9523. files created at this timestamp or earlier. Unix timestamp in ms.</li>
  9524. <li><code>search_term</code> - string - Filter users by their user ID localpart <strong>or</strong> displayname.
  9525. The search term can be found in any part of the string.
  9526. Defaults to no filtering.</li>
  9527. <li><code>dir</code> - string - Direction of order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9528. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  9529. </ul>
  9530. <p><strong>Response</strong></p>
  9531. <p>The following fields are returned in the JSON response body:</p>
  9532. <ul>
  9533. <li><code>users</code> - An array of objects, each containing information
  9534. about the user and their local media. Objects contain the following fields:
  9535. <ul>
  9536. <li><code>displayname</code> - string - Displayname of this user.</li>
  9537. <li><code>media_count</code> - integer - Number of uploaded media by this user.</li>
  9538. <li><code>media_length</code> - integer - Size of uploaded media in bytes by this user.</li>
  9539. <li><code>user_id</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9540. </ul>
  9541. </li>
  9542. <li><code>next_token</code> - integer - Opaque value used for pagination. See above.</li>
  9543. <li><code>total</code> - integer - Total number of users after filtering.</li>
  9544. </ul>
  9545. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="user-admin-api"><a class="header" href="#user-admin-api">User Admin API</a></h1>
  9546. <h2 id="query-user-account"><a class="header" href="#query-user-account">Query User Account</a></h2>
  9547. <p>This API returns information about a specific user account.</p>
  9548. <p>The api is:</p>
  9549. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;
  9550. </code></pre>
  9551. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9552. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9553. <p>It returns a JSON body like the following:</p>
  9554. <pre><code class="language-json">{
  9555. &quot;displayname&quot;: &quot;User&quot;,
  9556. &quot;threepids&quot;: [
  9557. {
  9558. &quot;medium&quot;: &quot;email&quot;,
  9559. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9560. },
  9561. {
  9562. &quot;medium&quot;: &quot;email&quot;,
  9563. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9564. }
  9565. ],
  9566. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9567. &quot;admin&quot;: 0,
  9568. &quot;deactivated&quot;: 0,
  9569. &quot;shadow_banned&quot;: 0,
  9570. &quot;password_hash&quot;: &quot;$2b$12$p9B4GkqYdRTPGD&quot;,
  9571. &quot;creation_ts&quot;: 1560432506,
  9572. &quot;appservice_id&quot;: null,
  9573. &quot;consent_server_notice_sent&quot;: null,
  9574. &quot;consent_version&quot;: null,
  9575. &quot;external_ids&quot;: [
  9576. {
  9577. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9578. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9579. },
  9580. {
  9581. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9582. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9583. }
  9584. ]
  9585. }
  9586. </code></pre>
  9587. <p>URL parameters:</p>
  9588. <ul>
  9589. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9590. </ul>
  9591. <h2 id="create-or-modify-account"><a class="header" href="#create-or-modify-account">Create or modify Account</a></h2>
  9592. <p>This API allows an administrator to create or modify a user account with a
  9593. specific <code>user_id</code>.</p>
  9594. <p>This api is:</p>
  9595. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;
  9596. </code></pre>
  9597. <p>with a body of:</p>
  9598. <pre><code class="language-json">{
  9599. &quot;password&quot;: &quot;user_password&quot;,
  9600. &quot;displayname&quot;: &quot;User&quot;,
  9601. &quot;threepids&quot;: [
  9602. {
  9603. &quot;medium&quot;: &quot;email&quot;,
  9604. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9605. },
  9606. {
  9607. &quot;medium&quot;: &quot;email&quot;,
  9608. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9609. }
  9610. ],
  9611. &quot;external_ids&quot;: [
  9612. {
  9613. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9614. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9615. },
  9616. {
  9617. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9618. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9619. }
  9620. ],
  9621. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9622. &quot;admin&quot;: false,
  9623. &quot;deactivated&quot;: false
  9624. }
  9625. </code></pre>
  9626. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9627. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9628. <p>Returns HTTP status code:</p>
  9629. <ul>
  9630. <li><code>201</code> - When a new user object was created.</li>
  9631. <li><code>200</code> - When a user was modified.</li>
  9632. </ul>
  9633. <p>URL parameters:</p>
  9634. <ul>
  9635. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9636. </ul>
  9637. <p>Body parameters:</p>
  9638. <ul>
  9639. <li><code>password</code> - string, optional. If provided, the user's password is updated and all
  9640. devices are logged out.</li>
  9641. <li><code>displayname</code> - string, optional, defaults to the value of <code>user_id</code>.</li>
  9642. <li><code>threepids</code> - array, optional, allows setting the third-party IDs (email, msisdn)
  9643. <ul>
  9644. <li><code>medium</code> - string. Kind of third-party ID, either <code>email</code> or <code>msisdn</code>.</li>
  9645. <li><code>address</code> - string. Value of third-party ID.
  9646. belonging to a user.</li>
  9647. </ul>
  9648. </li>
  9649. <li><code>external_ids</code> - array, optional. Allow setting the identifier of the external identity
  9650. provider for SSO (Single sign-on). Details in
  9651. <a href="admin_api/../usage/configuration/homeserver_sample_config.html">Sample Configuration File</a>
  9652. section <code>sso</code> and <code>oidc_providers</code>.
  9653. <ul>
  9654. <li><code>auth_provider</code> - string. ID of the external identity provider. Value of <code>idp_id</code>
  9655. in homeserver configuration.</li>
  9656. <li><code>external_id</code> - string, user ID in the external identity provider.</li>
  9657. </ul>
  9658. </li>
  9659. <li><code>avatar_url</code> - string, optional, must be a
  9660. <a href="https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris">MXC URI</a>.</li>
  9661. <li><code>admin</code> - bool, optional, defaults to <code>false</code>.</li>
  9662. <li><code>deactivated</code> - bool, optional. If unspecified, deactivation state will be left
  9663. unchanged on existing accounts and set to <code>false</code> for new accounts.
  9664. A user cannot be erased by deactivating with this API. For details on
  9665. deactivating users see <a href="admin_api/user_admin_api.html#deactivate-account">Deactivate Account</a>.</li>
  9666. </ul>
  9667. <p>If the user already exists then optional parameters default to the current value.</p>
  9668. <p>In order to re-activate an account <code>deactivated</code> must be set to <code>false</code>. If
  9669. users do not login via single-sign-on, a new <code>password</code> must be provided.</p>
  9670. <h2 id="list-accounts"><a class="header" href="#list-accounts">List Accounts</a></h2>
  9671. <p>This API returns all local user accounts.
  9672. By default, the response is ordered by ascending user ID.</p>
  9673. <pre><code>GET /_synapse/admin/v2/users?from=0&amp;limit=10&amp;guests=false
  9674. </code></pre>
  9675. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9676. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9677. <p>A response body like the following is returned:</p>
  9678. <pre><code class="language-json">{
  9679. &quot;users&quot;: [
  9680. {
  9681. &quot;name&quot;: &quot;&lt;user_id1&gt;&quot;,
  9682. &quot;is_guest&quot;: 0,
  9683. &quot;admin&quot;: 0,
  9684. &quot;user_type&quot;: null,
  9685. &quot;deactivated&quot;: 0,
  9686. &quot;shadow_banned&quot;: 0,
  9687. &quot;displayname&quot;: &quot;&lt;User One&gt;&quot;,
  9688. &quot;avatar_url&quot;: null,
  9689. &quot;creation_ts&quot;: 1560432668000
  9690. }, {
  9691. &quot;name&quot;: &quot;&lt;user_id2&gt;&quot;,
  9692. &quot;is_guest&quot;: 0,
  9693. &quot;admin&quot;: 1,
  9694. &quot;user_type&quot;: null,
  9695. &quot;deactivated&quot;: 0,
  9696. &quot;shadow_banned&quot;: 0,
  9697. &quot;displayname&quot;: &quot;&lt;User Two&gt;&quot;,
  9698. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9699. &quot;creation_ts&quot;: 1561550621000
  9700. }
  9701. ],
  9702. &quot;next_token&quot;: &quot;100&quot;,
  9703. &quot;total&quot;: 200
  9704. }
  9705. </code></pre>
  9706. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9707. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9708. <p>If the endpoint does not return a <code>next_token</code> then there are no more users
  9709. to paginate through.</p>
  9710. <p><strong>Parameters</strong></p>
  9711. <p>The following parameters should be set in the URL:</p>
  9712. <ul>
  9713. <li>
  9714. <p><code>user_id</code> - Is optional and filters to only return users with user IDs
  9715. that contain this value. This parameter is ignored when using the <code>name</code> parameter.</p>
  9716. </li>
  9717. <li>
  9718. <p><code>name</code> - Is optional and filters to only return users with user ID localparts
  9719. <strong>or</strong> displaynames that contain this value.</p>
  9720. </li>
  9721. <li>
  9722. <p><code>guests</code> - string representing a bool - Is optional and if <code>false</code> will <strong>exclude</strong> guest users.
  9723. Defaults to <code>true</code> to include guest users.</p>
  9724. </li>
  9725. <li>
  9726. <p><code>deactivated</code> - string representing a bool - Is optional and if <code>true</code> will <strong>include</strong> deactivated users.
  9727. Defaults to <code>false</code> to exclude deactivated users.</p>
  9728. </li>
  9729. <li>
  9730. <p><code>limit</code> - string representing a positive integer - Is optional but is used for pagination,
  9731. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9732. </li>
  9733. <li>
  9734. <p><code>from</code> - string representing a positive integer - Is optional but used for pagination,
  9735. denoting the offset in the returned results. This should be treated as an opaque value and
  9736. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9737. Defaults to <code>0</code>.</p>
  9738. </li>
  9739. <li>
  9740. <p><code>order_by</code> - The method by which to sort the returned list of users.
  9741. If the ordered field has duplicates, the second order is always by ascending <code>name</code>,
  9742. which guarantees a stable ordering. Valid values are:</p>
  9743. <ul>
  9744. <li><code>name</code> - Users are ordered alphabetically by <code>name</code>. This is the default.</li>
  9745. <li><code>is_guest</code> - Users are ordered by <code>is_guest</code> status.</li>
  9746. <li><code>admin</code> - Users are ordered by <code>admin</code> status.</li>
  9747. <li><code>user_type</code> - Users are ordered alphabetically by <code>user_type</code>.</li>
  9748. <li><code>deactivated</code> - Users are ordered by <code>deactivated</code> status.</li>
  9749. <li><code>shadow_banned</code> - Users are ordered by <code>shadow_banned</code> status.</li>
  9750. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9751. <li><code>avatar_url</code> - Users are ordered alphabetically by avatar URL.</li>
  9752. <li><code>creation_ts</code> - Users are ordered by when the users was created in ms.</li>
  9753. </ul>
  9754. </li>
  9755. <li>
  9756. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9757. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  9758. </li>
  9759. </ul>
  9760. <p>Caution. The database only has indexes on the columns <code>name</code> and <code>creation_ts</code>.
  9761. This means that if a different sort order is used (<code>is_guest</code>, <code>admin</code>,
  9762. <code>user_type</code>, <code>deactivated</code>, <code>shadow_banned</code>, <code>avatar_url</code> or <code>displayname</code>),
  9763. this can cause a large load on the database, especially for large environments.</p>
  9764. <p><strong>Response</strong></p>
  9765. <p>The following fields are returned in the JSON response body:</p>
  9766. <ul>
  9767. <li>
  9768. <p><code>users</code> - An array of objects, each containing information about an user.
  9769. User objects contain the following fields:</p>
  9770. <ul>
  9771. <li><code>name</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9772. <li><code>is_guest</code> - bool - Status if that user is a guest account.</li>
  9773. <li><code>admin</code> - bool - Status if that user is a server administrator.</li>
  9774. <li><code>user_type</code> - string - Type of the user. Normal users are type <code>None</code>.
  9775. This allows user type specific behaviour. There are also types <code>support</code> and <code>bot</code>. </li>
  9776. <li><code>deactivated</code> - bool - Status if that user has been marked as deactivated.</li>
  9777. <li><code>shadow_banned</code> - bool - Status if that user has been marked as shadow banned.</li>
  9778. <li><code>displayname</code> - string - The user's display name if they have set one.</li>
  9779. <li><code>avatar_url</code> - string - The user's avatar URL if they have set one.</li>
  9780. <li><code>creation_ts</code> - integer - The user's creation timestamp in ms.</li>
  9781. </ul>
  9782. </li>
  9783. <li>
  9784. <p><code>next_token</code>: string representing a positive integer - Indication for pagination. See above.</p>
  9785. </li>
  9786. <li>
  9787. <p><code>total</code> - integer - Total number of media.</p>
  9788. </li>
  9789. </ul>
  9790. <h2 id="query-current-sessions-for-a-user"><a class="header" href="#query-current-sessions-for-a-user">Query current sessions for a user</a></h2>
  9791. <p>This API returns information about the active sessions for a specific user.</p>
  9792. <p>The endpoints are:</p>
  9793. <pre><code>GET /_synapse/admin/v1/whois/&lt;user_id&gt;
  9794. </code></pre>
  9795. <p>and:</p>
  9796. <pre><code>GET /_matrix/client/r0/admin/whois/&lt;userId&gt;
  9797. </code></pre>
  9798. <p>See also: <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid">Client Server
  9799. API Whois</a>.</p>
  9800. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9801. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9802. <p>It returns a JSON body like the following:</p>
  9803. <pre><code class="language-json">{
  9804. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;,
  9805. &quot;devices&quot;: {
  9806. &quot;&quot;: {
  9807. &quot;sessions&quot;: [
  9808. {
  9809. &quot;connections&quot;: [
  9810. {
  9811. &quot;ip&quot;: &quot;1.2.3.4&quot;,
  9812. &quot;last_seen&quot;: 1417222374433,
  9813. &quot;user_agent&quot;: &quot;Mozilla/5.0 ...&quot;
  9814. },
  9815. {
  9816. &quot;ip&quot;: &quot;1.2.3.10&quot;,
  9817. &quot;last_seen&quot;: 1417222374500,
  9818. &quot;user_agent&quot;: &quot;Dalvik/2.1.0 ...&quot;
  9819. }
  9820. ]
  9821. }
  9822. ]
  9823. }
  9824. }
  9825. }
  9826. </code></pre>
  9827. <p><code>last_seen</code> is measured in milliseconds since the Unix epoch.</p>
  9828. <h2 id="deactivate-account"><a class="header" href="#deactivate-account">Deactivate Account</a></h2>
  9829. <p>This API deactivates an account. It removes active access tokens, resets the
  9830. password, and deletes third-party IDs (to prevent the user requesting a
  9831. password reset).</p>
  9832. <p>It can also mark the user as GDPR-erased. This means messages sent by the
  9833. user will still be visible by anyone that was in the room when these messages
  9834. were sent, but hidden from users joining the room afterwards.</p>
  9835. <p>The api is:</p>
  9836. <pre><code>POST /_synapse/admin/v1/deactivate/&lt;user_id&gt;
  9837. </code></pre>
  9838. <p>with a body of:</p>
  9839. <pre><code class="language-json">{
  9840. &quot;erase&quot;: true
  9841. }
  9842. </code></pre>
  9843. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9844. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9845. <p>The erase parameter is optional and defaults to <code>false</code>.
  9846. An empty body may be passed for backwards compatibility.</p>
  9847. <p>The following actions are performed when deactivating an user:</p>
  9848. <ul>
  9849. <li>Try to unpind 3PIDs from the identity server</li>
  9850. <li>Remove all 3PIDs from the homeserver</li>
  9851. <li>Delete all devices and E2EE keys</li>
  9852. <li>Delete all access tokens</li>
  9853. <li>Delete the password hash</li>
  9854. <li>Removal from all rooms the user is a member of</li>
  9855. <li>Remove the user from the user directory</li>
  9856. <li>Reject all pending invites</li>
  9857. <li>Remove all account validity information related to the user</li>
  9858. </ul>
  9859. <p>The following additional actions are performed during deactivation if <code>erase</code>
  9860. is set to <code>true</code>:</p>
  9861. <ul>
  9862. <li>Remove the user's display name</li>
  9863. <li>Remove the user's avatar URL</li>
  9864. <li>Mark the user as erased</li>
  9865. </ul>
  9866. <h2 id="reset-password"><a class="header" href="#reset-password">Reset password</a></h2>
  9867. <p>Changes the password of another user. This will automatically log the user out of all their devices.</p>
  9868. <p>The api is:</p>
  9869. <pre><code>POST /_synapse/admin/v1/reset_password/&lt;user_id&gt;
  9870. </code></pre>
  9871. <p>with a body of:</p>
  9872. <pre><code class="language-json">{
  9873. &quot;new_password&quot;: &quot;&lt;secret&gt;&quot;,
  9874. &quot;logout_devices&quot;: true
  9875. }
  9876. </code></pre>
  9877. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9878. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9879. <p>The parameter <code>new_password</code> is required.
  9880. The parameter <code>logout_devices</code> is optional and defaults to <code>true</code>.</p>
  9881. <h2 id="get-whether-a-user-is-a-server-administrator-or-not"><a class="header" href="#get-whether-a-user-is-a-server-administrator-or-not">Get whether a user is a server administrator or not</a></h2>
  9882. <p>The api is:</p>
  9883. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  9884. </code></pre>
  9885. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9886. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9887. <p>A response body like the following is returned:</p>
  9888. <pre><code class="language-json">{
  9889. &quot;admin&quot;: true
  9890. }
  9891. </code></pre>
  9892. <h2 id="change-whether-a-user-is-a-server-administrator-or-not"><a class="header" href="#change-whether-a-user-is-a-server-administrator-or-not">Change whether a user is a server administrator or not</a></h2>
  9893. <p>Note that you cannot demote yourself.</p>
  9894. <p>The api is:</p>
  9895. <pre><code>PUT /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  9896. </code></pre>
  9897. <p>with a body of:</p>
  9898. <pre><code class="language-json">{
  9899. &quot;admin&quot;: true
  9900. }
  9901. </code></pre>
  9902. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9903. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9904. <h2 id="list-room-memberships-of-a-user"><a class="header" href="#list-room-memberships-of-a-user">List room memberships of a user</a></h2>
  9905. <p>Gets a list of all <code>room_id</code> that a specific <code>user_id</code> is member.</p>
  9906. <p>The API is:</p>
  9907. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/joined_rooms
  9908. </code></pre>
  9909. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9910. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9911. <p>A response body like the following is returned:</p>
  9912. <pre><code class="language-json"> {
  9913. &quot;joined_rooms&quot;: [
  9914. &quot;!DuGcnbhHGaSZQoNQR:matrix.org&quot;,
  9915. &quot;!ZtSaPCawyWtxfWiIy:matrix.org&quot;
  9916. ],
  9917. &quot;total&quot;: 2
  9918. }
  9919. </code></pre>
  9920. <p>The server returns the list of rooms of which the user and the server
  9921. are member. If the user is local, all the rooms of which the user is
  9922. member are returned.</p>
  9923. <p><strong>Parameters</strong></p>
  9924. <p>The following parameters should be set in the URL:</p>
  9925. <ul>
  9926. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9927. </ul>
  9928. <p><strong>Response</strong></p>
  9929. <p>The following fields are returned in the JSON response body:</p>
  9930. <ul>
  9931. <li><code>joined_rooms</code> - An array of <code>room_id</code>.</li>
  9932. <li><code>total</code> - Number of rooms.</li>
  9933. </ul>
  9934. <h2 id="user-media"><a class="header" href="#user-media">User media</a></h2>
  9935. <h3 id="list-media-uploaded-by-a-user"><a class="header" href="#list-media-uploaded-by-a-user">List media uploaded by a user</a></h3>
  9936. <p>Gets a list of all local media that a specific <code>user_id</code> has created.
  9937. By default, the response is ordered by descending creation date and ascending media ID.
  9938. The newest media is on top. You can change the order with parameters
  9939. <code>order_by</code> and <code>dir</code>.</p>
  9940. <p>The API is:</p>
  9941. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/media
  9942. </code></pre>
  9943. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9944. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9945. <p>A response body like the following is returned:</p>
  9946. <pre><code class="language-json">{
  9947. &quot;media&quot;: [
  9948. {
  9949. &quot;created_ts&quot;: 100400,
  9950. &quot;last_access_ts&quot;: null,
  9951. &quot;media_id&quot;: &quot;qXhyRzulkwLsNHTbpHreuEgo&quot;,
  9952. &quot;media_length&quot;: 67,
  9953. &quot;media_type&quot;: &quot;image/png&quot;,
  9954. &quot;quarantined_by&quot;: null,
  9955. &quot;safe_from_quarantine&quot;: false,
  9956. &quot;upload_name&quot;: &quot;test1.png&quot;
  9957. },
  9958. {
  9959. &quot;created_ts&quot;: 200400,
  9960. &quot;last_access_ts&quot;: null,
  9961. &quot;media_id&quot;: &quot;FHfiSnzoINDatrXHQIXBtahw&quot;,
  9962. &quot;media_length&quot;: 67,
  9963. &quot;media_type&quot;: &quot;image/png&quot;,
  9964. &quot;quarantined_by&quot;: null,
  9965. &quot;safe_from_quarantine&quot;: false,
  9966. &quot;upload_name&quot;: &quot;test2.png&quot;
  9967. }
  9968. ],
  9969. &quot;next_token&quot;: 3,
  9970. &quot;total&quot;: 2
  9971. }
  9972. </code></pre>
  9973. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9974. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9975. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9976. reports to paginate through.</p>
  9977. <p><strong>Parameters</strong></p>
  9978. <p>The following parameters should be set in the URL:</p>
  9979. <ul>
  9980. <li>
  9981. <p><code>user_id</code> - string - fully qualified: for example, <code>@user:server.com</code>.</p>
  9982. </li>
  9983. <li>
  9984. <p><code>limit</code>: string representing a positive integer - Is optional but is used for pagination,
  9985. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9986. </li>
  9987. <li>
  9988. <p><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9989. denoting the offset in the returned results. This should be treated as an opaque value and
  9990. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9991. Defaults to <code>0</code>.</p>
  9992. </li>
  9993. <li>
  9994. <p><code>order_by</code> - The method by which to sort the returned list of media.
  9995. If the ordered field has duplicates, the second order is always by ascending <code>media_id</code>,
  9996. which guarantees a stable ordering. Valid values are:</p>
  9997. <ul>
  9998. <li><code>media_id</code> - Media are ordered alphabetically by <code>media_id</code>.</li>
  9999. <li><code>upload_name</code> - Media are ordered alphabetically by name the media was uploaded with.</li>
  10000. <li><code>created_ts</code> - Media are ordered by when the content was uploaded in ms.
  10001. Smallest to largest. This is the default.</li>
  10002. <li><code>last_access_ts</code> - Media are ordered by when the content was last accessed in ms.
  10003. Smallest to largest.</li>
  10004. <li><code>media_length</code> - Media are ordered by length of the media in bytes.
  10005. Smallest to largest.</li>
  10006. <li><code>media_type</code> - Media are ordered alphabetically by MIME-type.</li>
  10007. <li><code>quarantined_by</code> - Media are ordered alphabetically by the user ID that
  10008. initiated the quarantine request for this media.</li>
  10009. <li><code>safe_from_quarantine</code> - Media are ordered by the status if this media is safe
  10010. from quarantining.</li>
  10011. </ul>
  10012. </li>
  10013. <li>
  10014. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  10015. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  10016. </li>
  10017. </ul>
  10018. <p>If neither <code>order_by</code> nor <code>dir</code> is set, the default order is newest media on top
  10019. (corresponds to <code>order_by</code> = <code>created_ts</code> and <code>dir</code> = <code>b</code>).</p>
  10020. <p>Caution. The database only has indexes on the columns <code>media_id</code>,
  10021. <code>user_id</code> and <code>created_ts</code>. This means that if a different sort order is used
  10022. (<code>upload_name</code>, <code>last_access_ts</code>, <code>media_length</code>, <code>media_type</code>,
  10023. <code>quarantined_by</code> or <code>safe_from_quarantine</code>), this can cause a large load on the
  10024. database, especially for large environments.</p>
  10025. <p><strong>Response</strong></p>
  10026. <p>The following fields are returned in the JSON response body:</p>
  10027. <ul>
  10028. <li><code>media</code> - An array of objects, each containing information about a media.
  10029. Media objects contain the following fields:
  10030. <ul>
  10031. <li><code>created_ts</code> - integer - Timestamp when the content was uploaded in ms.</li>
  10032. <li><code>last_access_ts</code> - integer - Timestamp when the content was last accessed in ms.</li>
  10033. <li><code>media_id</code> - string - The id used to refer to the media.</li>
  10034. <li><code>media_length</code> - integer - Length of the media in bytes.</li>
  10035. <li><code>media_type</code> - string - The MIME-type of the media.</li>
  10036. <li><code>quarantined_by</code> - string - The user ID that initiated the quarantine request
  10037. for this media.</li>
  10038. <li><code>safe_from_quarantine</code> - bool - Status if this media is safe from quarantining.</li>
  10039. <li><code>upload_name</code> - string - The name the media was uploaded with.</li>
  10040. </ul>
  10041. </li>
  10042. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  10043. <li><code>total</code> - integer - Total number of media.</li>
  10044. </ul>
  10045. <h3 id="delete-media-uploaded-by-a-user-1"><a class="header" href="#delete-media-uploaded-by-a-user-1">Delete media uploaded by a user</a></h3>
  10046. <p>This API deletes the <em>local</em> media from the disk of your own server
  10047. that a specific <code>user_id</code> has created. This includes any local thumbnails.</p>
  10048. <p>This API will not affect media that has been uploaded to external
  10049. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).</p>
  10050. <p>By default, the API deletes media ordered by descending creation date and ascending media ID.
  10051. The newest media is deleted first. You can change the order with parameters
  10052. <code>order_by</code> and <code>dir</code>. If no <code>limit</code> is set the API deletes <code>100</code> files per request.</p>
  10053. <p>The API is:</p>
  10054. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/media
  10055. </code></pre>
  10056. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10057. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10058. <p>A response body like the following is returned:</p>
  10059. <pre><code class="language-json">{
  10060. &quot;deleted_media&quot;: [
  10061. &quot;abcdefghijklmnopqrstuvwx&quot;
  10062. ],
  10063. &quot;total&quot;: 1
  10064. }
  10065. </code></pre>
  10066. <p>The following fields are returned in the JSON response body:</p>
  10067. <ul>
  10068. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  10069. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  10070. </ul>
  10071. <p><strong>Note</strong>: There is no <code>next_token</code>. This is not useful for deleting media, because
  10072. after deleting media the remaining media have a new order.</p>
  10073. <p><strong>Parameters</strong></p>
  10074. <p>This API has the same parameters as
  10075. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>.
  10076. With the parameters you can for example limit the number of files to delete at once or
  10077. delete largest/smallest or newest/oldest files first.</p>
  10078. <h2 id="login-as-a-user"><a class="header" href="#login-as-a-user">Login as a user</a></h2>
  10079. <p>Get an access token that can be used to authenticate as that user. Useful for
  10080. when admins wish to do actions on behalf of a user.</p>
  10081. <p>The API is:</p>
  10082. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/login
  10083. {}
  10084. </code></pre>
  10085. <p>An optional <code>valid_until_ms</code> field can be specified in the request body as an
  10086. integer timestamp that specifies when the token should expire. By default tokens
  10087. do not expire.</p>
  10088. <p>A response body like the following is returned:</p>
  10089. <pre><code class="language-json">{
  10090. &quot;access_token&quot;: &quot;&lt;opaque_access_token_string&gt;&quot;
  10091. }
  10092. </code></pre>
  10093. <p>This API does <em>not</em> generate a new device for the user, and so will not appear
  10094. their <code>/devices</code> list, and in general the target user should not be able to
  10095. tell they have been logged in as.</p>
  10096. <p>To expire the token call the standard <code>/logout</code> API with the token.</p>
  10097. <p>Note: The token will expire if the <em>admin</em> user calls <code>/logout/all</code> from any
  10098. of their devices, but the token will <em>not</em> expire if the target user does the
  10099. same.</p>
  10100. <h2 id="user-devices"><a class="header" href="#user-devices">User devices</a></h2>
  10101. <h3 id="list-all-devices"><a class="header" href="#list-all-devices">List all devices</a></h3>
  10102. <p>Gets information about all devices for a specific <code>user_id</code>.</p>
  10103. <p>The API is:</p>
  10104. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices
  10105. </code></pre>
  10106. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10107. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10108. <p>A response body like the following is returned:</p>
  10109. <pre><code class="language-json">{
  10110. &quot;devices&quot;: [
  10111. {
  10112. &quot;device_id&quot;: &quot;QBUAZIFURK&quot;,
  10113. &quot;display_name&quot;: &quot;android&quot;,
  10114. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10115. &quot;last_seen_ts&quot;: 1474491775024,
  10116. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10117. },
  10118. {
  10119. &quot;device_id&quot;: &quot;AUIECTSRND&quot;,
  10120. &quot;display_name&quot;: &quot;ios&quot;,
  10121. &quot;last_seen_ip&quot;: &quot;1.2.3.5&quot;,
  10122. &quot;last_seen_ts&quot;: 1474491775025,
  10123. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10124. }
  10125. ],
  10126. &quot;total&quot;: 2
  10127. }
  10128. </code></pre>
  10129. <p><strong>Parameters</strong></p>
  10130. <p>The following parameters should be set in the URL:</p>
  10131. <ul>
  10132. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10133. </ul>
  10134. <p><strong>Response</strong></p>
  10135. <p>The following fields are returned in the JSON response body:</p>
  10136. <ul>
  10137. <li>
  10138. <p><code>devices</code> - An array of objects, each containing information about a device.
  10139. Device objects contain the following fields:</p>
  10140. <ul>
  10141. <li><code>device_id</code> - Identifier of device.</li>
  10142. <li><code>display_name</code> - Display name set by the user for this device.
  10143. Absent if no name has been set.</li>
  10144. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10145. (May be a few minutes out of date, for efficiency reasons).</li>
  10146. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10147. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10148. <li><code>user_id</code> - Owner of device.</li>
  10149. </ul>
  10150. </li>
  10151. <li>
  10152. <p><code>total</code> - Total number of user's devices.</p>
  10153. </li>
  10154. </ul>
  10155. <h3 id="delete-multiple-devices"><a class="header" href="#delete-multiple-devices">Delete multiple devices</a></h3>
  10156. <p>Deletes the given devices for a specific <code>user_id</code>, and invalidates
  10157. any access token associated with them.</p>
  10158. <p>The API is:</p>
  10159. <pre><code>POST /_synapse/admin/v2/users/&lt;user_id&gt;/delete_devices
  10160. {
  10161. &quot;devices&quot;: [
  10162. &quot;QBUAZIFURK&quot;,
  10163. &quot;AUIECTSRND&quot;
  10164. ],
  10165. }
  10166. </code></pre>
  10167. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10168. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10169. <p>An empty JSON dict is returned.</p>
  10170. <p><strong>Parameters</strong></p>
  10171. <p>The following parameters should be set in the URL:</p>
  10172. <ul>
  10173. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10174. </ul>
  10175. <p>The following fields are required in the JSON request body:</p>
  10176. <ul>
  10177. <li><code>devices</code> - The list of device IDs to delete.</li>
  10178. </ul>
  10179. <h3 id="show-a-device"><a class="header" href="#show-a-device">Show a device</a></h3>
  10180. <p>Gets information on a single device, by <code>device_id</code> for a specific <code>user_id</code>.</p>
  10181. <p>The API is:</p>
  10182. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10183. </code></pre>
  10184. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10185. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10186. <p>A response body like the following is returned:</p>
  10187. <pre><code class="language-json">{
  10188. &quot;device_id&quot;: &quot;&lt;device_id&gt;&quot;,
  10189. &quot;display_name&quot;: &quot;android&quot;,
  10190. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10191. &quot;last_seen_ts&quot;: 1474491775024,
  10192. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10193. }
  10194. </code></pre>
  10195. <p><strong>Parameters</strong></p>
  10196. <p>The following parameters should be set in the URL:</p>
  10197. <ul>
  10198. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10199. <li><code>device_id</code> - The device to retrieve.</li>
  10200. </ul>
  10201. <p><strong>Response</strong></p>
  10202. <p>The following fields are returned in the JSON response body:</p>
  10203. <ul>
  10204. <li><code>device_id</code> - Identifier of device.</li>
  10205. <li><code>display_name</code> - Display name set by the user for this device.
  10206. Absent if no name has been set.</li>
  10207. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10208. (May be a few minutes out of date, for efficiency reasons).</li>
  10209. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10210. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10211. <li><code>user_id</code> - Owner of device.</li>
  10212. </ul>
  10213. <h3 id="update-a-device"><a class="header" href="#update-a-device">Update a device</a></h3>
  10214. <p>Updates the metadata on the given <code>device_id</code> for a specific <code>user_id</code>.</p>
  10215. <p>The API is:</p>
  10216. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10217. {
  10218. &quot;display_name&quot;: &quot;My other phone&quot;
  10219. }
  10220. </code></pre>
  10221. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10222. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10223. <p>An empty JSON dict is returned.</p>
  10224. <p><strong>Parameters</strong></p>
  10225. <p>The following parameters should be set in the URL:</p>
  10226. <ul>
  10227. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10228. <li><code>device_id</code> - The device to update.</li>
  10229. </ul>
  10230. <p>The following fields are required in the JSON request body:</p>
  10231. <ul>
  10232. <li><code>display_name</code> - The new display name for this device. If not given,
  10233. the display name is unchanged.</li>
  10234. </ul>
  10235. <h3 id="delete-a-device"><a class="header" href="#delete-a-device">Delete a device</a></h3>
  10236. <p>Deletes the given <code>device_id</code> for a specific <code>user_id</code>,
  10237. and invalidates any access token associated with it.</p>
  10238. <p>The API is:</p>
  10239. <pre><code>DELETE /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10240. {}
  10241. </code></pre>
  10242. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10243. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10244. <p>An empty JSON dict is returned.</p>
  10245. <p><strong>Parameters</strong></p>
  10246. <p>The following parameters should be set in the URL:</p>
  10247. <ul>
  10248. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10249. <li><code>device_id</code> - The device to delete.</li>
  10250. </ul>
  10251. <h2 id="list-all-pushers"><a class="header" href="#list-all-pushers">List all pushers</a></h2>
  10252. <p>Gets information about all pushers for a specific <code>user_id</code>.</p>
  10253. <p>The API is:</p>
  10254. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/pushers
  10255. </code></pre>
  10256. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10257. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10258. <p>A response body like the following is returned:</p>
  10259. <pre><code class="language-json">{
  10260. &quot;pushers&quot;: [
  10261. {
  10262. &quot;app_display_name&quot;:&quot;HTTP Push Notifications&quot;,
  10263. &quot;app_id&quot;:&quot;m.http&quot;,
  10264. &quot;data&quot;: {
  10265. &quot;url&quot;:&quot;example.com&quot;
  10266. },
  10267. &quot;device_display_name&quot;:&quot;pushy push&quot;,
  10268. &quot;kind&quot;:&quot;http&quot;,
  10269. &quot;lang&quot;:&quot;None&quot;,
  10270. &quot;profile_tag&quot;:&quot;&quot;,
  10271. &quot;pushkey&quot;:&quot;a@example.com&quot;
  10272. }
  10273. ],
  10274. &quot;total&quot;: 1
  10275. }
  10276. </code></pre>
  10277. <p><strong>Parameters</strong></p>
  10278. <p>The following parameters should be set in the URL:</p>
  10279. <ul>
  10280. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10281. </ul>
  10282. <p><strong>Response</strong></p>
  10283. <p>The following fields are returned in the JSON response body:</p>
  10284. <ul>
  10285. <li>
  10286. <p><code>pushers</code> - An array containing the current pushers for the user</p>
  10287. <ul>
  10288. <li>
  10289. <p><code>app_display_name</code> - string - A string that will allow the user to identify
  10290. what application owns this pusher.</p>
  10291. </li>
  10292. <li>
  10293. <p><code>app_id</code> - string - This is a reverse-DNS style identifier for the application.
  10294. Max length, 64 chars.</p>
  10295. </li>
  10296. <li>
  10297. <p><code>data</code> - A dictionary of information for the pusher implementation itself.</p>
  10298. <ul>
  10299. <li>
  10300. <p><code>url</code> - string - Required if <code>kind</code> is <code>http</code>. The URL to use to send
  10301. notifications to.</p>
  10302. </li>
  10303. <li>
  10304. <p><code>format</code> - string - The format to use when sending notifications to the
  10305. Push Gateway.</p>
  10306. </li>
  10307. </ul>
  10308. </li>
  10309. <li>
  10310. <p><code>device_display_name</code> - string - A string that will allow the user to identify
  10311. what device owns this pusher.</p>
  10312. </li>
  10313. <li>
  10314. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10315. this pusher executes.</p>
  10316. </li>
  10317. <li>
  10318. <p><code>kind</code> - string - The kind of pusher. &quot;http&quot; is a pusher that sends HTTP pokes.</p>
  10319. </li>
  10320. <li>
  10321. <p><code>lang</code> - string - The preferred language for receiving notifications
  10322. (e.g. 'en' or 'en-US')</p>
  10323. </li>
  10324. <li>
  10325. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10326. this pusher executes.</p>
  10327. </li>
  10328. <li>
  10329. <p><code>pushkey</code> - string - This is a unique identifier for this pusher.
  10330. Max length, 512 bytes.</p>
  10331. </li>
  10332. </ul>
  10333. </li>
  10334. <li>
  10335. <p><code>total</code> - integer - Number of pushers.</p>
  10336. </li>
  10337. </ul>
  10338. <p>See also the
  10339. <a href="https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers">Client-Server API Spec on pushers</a>.</p>
  10340. <h2 id="shadow-banning-users"><a class="header" href="#shadow-banning-users">Shadow-banning users</a></h2>
  10341. <p>Shadow-banning is a useful tool for moderating malicious or egregiously abusive users.
  10342. A shadow-banned users receives successful responses to their client-server API requests,
  10343. but the events are not propagated into rooms. This can be an effective tool as it
  10344. (hopefully) takes longer for the user to realise they are being moderated before
  10345. pivoting to another account.</p>
  10346. <p>Shadow-banning a user should be used as a tool of last resort and may lead to confusing
  10347. or broken behaviour for the client. A shadow-banned user will not receive any
  10348. notification and it is generally more appropriate to ban or kick abusive users.
  10349. A shadow-banned user will be unable to contact anyone on the server.</p>
  10350. <p>The API is:</p>
  10351. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/shadow_ban
  10352. </code></pre>
  10353. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10354. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10355. <p>An empty JSON dict is returned.</p>
  10356. <p><strong>Parameters</strong></p>
  10357. <p>The following parameters should be set in the URL:</p>
  10358. <ul>
  10359. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10360. be local.</li>
  10361. </ul>
  10362. <h2 id="override-ratelimiting-for-users"><a class="header" href="#override-ratelimiting-for-users">Override ratelimiting for users</a></h2>
  10363. <p>This API allows to override or disable ratelimiting for a specific user.
  10364. There are specific APIs to set, get and delete a ratelimit.</p>
  10365. <h3 id="get-status-of-ratelimit"><a class="header" href="#get-status-of-ratelimit">Get status of ratelimit</a></h3>
  10366. <p>The API is:</p>
  10367. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10368. </code></pre>
  10369. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10370. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10371. <p>A response body like the following is returned:</p>
  10372. <pre><code class="language-json">{
  10373. &quot;messages_per_second&quot;: 0,
  10374. &quot;burst_count&quot;: 0
  10375. }
  10376. </code></pre>
  10377. <p><strong>Parameters</strong></p>
  10378. <p>The following parameters should be set in the URL:</p>
  10379. <ul>
  10380. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10381. be local.</li>
  10382. </ul>
  10383. <p><strong>Response</strong></p>
  10384. <p>The following fields are returned in the JSON response body:</p>
  10385. <ul>
  10386. <li><code>messages_per_second</code> - integer - The number of actions that can
  10387. be performed in a second. <code>0</code> mean that ratelimiting is disabled for this user.</li>
  10388. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10389. being limited.</li>
  10390. </ul>
  10391. <p>If <strong>no</strong> custom ratelimit is set, an empty JSON dict is returned.</p>
  10392. <pre><code class="language-json">{}
  10393. </code></pre>
  10394. <h3 id="set-ratelimit"><a class="header" href="#set-ratelimit">Set ratelimit</a></h3>
  10395. <p>The API is:</p>
  10396. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10397. </code></pre>
  10398. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10399. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10400. <p>A response body like the following is returned:</p>
  10401. <pre><code class="language-json">{
  10402. &quot;messages_per_second&quot;: 0,
  10403. &quot;burst_count&quot;: 0
  10404. }
  10405. </code></pre>
  10406. <p><strong>Parameters</strong></p>
  10407. <p>The following parameters should be set in the URL:</p>
  10408. <ul>
  10409. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10410. be local.</li>
  10411. </ul>
  10412. <p>Body parameters:</p>
  10413. <ul>
  10414. <li><code>messages_per_second</code> - positive integer, optional. The number of actions that can
  10415. be performed in a second. Defaults to <code>0</code>.</li>
  10416. <li><code>burst_count</code> - positive integer, optional. How many actions that can be performed
  10417. before being limited. Defaults to <code>0</code>.</li>
  10418. </ul>
  10419. <p>To disable users' ratelimit set both values to <code>0</code>.</p>
  10420. <p><strong>Response</strong></p>
  10421. <p>The following fields are returned in the JSON response body:</p>
  10422. <ul>
  10423. <li><code>messages_per_second</code> - integer - The number of actions that can
  10424. be performed in a second.</li>
  10425. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10426. being limited.</li>
  10427. </ul>
  10428. <h3 id="delete-ratelimit"><a class="header" href="#delete-ratelimit">Delete ratelimit</a></h3>
  10429. <p>The API is:</p>
  10430. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10431. </code></pre>
  10432. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10433. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10434. <p>An empty JSON dict is returned.</p>
  10435. <pre><code class="language-json">{}
  10436. </code></pre>
  10437. <p><strong>Parameters</strong></p>
  10438. <p>The following parameters should be set in the URL:</p>
  10439. <ul>
  10440. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10441. be local.</li>
  10442. </ul>
  10443. <h3 id="check-username-availability"><a class="header" href="#check-username-availability">Check username availability</a></h3>
  10444. <p>Checks to see if a username is available, and valid, for the server. See <a href="https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available">the client-server
  10445. API</a>
  10446. for more information.</p>
  10447. <p>This endpoint will work even if registration is disabled on the server, unlike
  10448. <code>/_matrix/client/r0/register/available</code>.</p>
  10449. <p>The API is:</p>
  10450. <pre><code>POST /_synapse/admin/v1/username_availabile?username=$localpart
  10451. </code></pre>
  10452. <p>The request and response format is the same as the <a href="https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available">/_matrix/client/r0/register/available</a> API.</p>
  10453. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10454. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10455. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="version-api"><a class="header" href="#version-api">Version API</a></h1>
  10456. <p>This API returns the running Synapse version and the Python version
  10457. on which Synapse is being run. This is useful when a Synapse instance
  10458. is behind a proxy that does not forward the 'Server' header (which also
  10459. contains Synapse version information).</p>
  10460. <p>The api is:</p>
  10461. <pre><code>GET /_synapse/admin/v1/server_version
  10462. </code></pre>
  10463. <p>It returns a JSON body like the following:</p>
  10464. <pre><code class="language-json">{
  10465. &quot;server_version&quot;: &quot;0.99.2rc1 (b=develop, abcdef123)&quot;,
  10466. &quot;python_version&quot;: &quot;3.6.8&quot;
  10467. }
  10468. </code></pre>
  10469. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="using-the-synapse-manhole"><a class="header" href="#using-the-synapse-manhole">Using the synapse manhole</a></h1>
  10470. <p>The &quot;manhole&quot; allows server administrators to access a Python shell on a running
  10471. Synapse installation. This is a very powerful mechanism for administration and
  10472. debugging.</p>
  10473. <p><strong><em>Security Warning</em></strong></p>
  10474. <p>Note that this will give administrative access to synapse to <strong>all users</strong> with
  10475. shell access to the server. It should therefore <strong>not</strong> be enabled in
  10476. environments where untrusted users have shell access.</p>
  10477. <hr />
  10478. <p>To enable it, first uncomment the <code>manhole</code> listener configuration in
  10479. <code>homeserver.yaml</code>. The configuration is slightly different if you're using docker.</p>
  10480. <h4 id="docker-config"><a class="header" href="#docker-config">Docker config</a></h4>
  10481. <p>If you are using Docker, set <code>bind_addresses</code> to <code>['0.0.0.0']</code> as shown:</p>
  10482. <pre><code class="language-yaml">listeners:
  10483. - port: 9000
  10484. bind_addresses: ['0.0.0.0']
  10485. type: manhole
  10486. </code></pre>
  10487. <p>When using <code>docker run</code> to start the server, you will then need to change the command to the following to include the
  10488. <code>manhole</code> port forwarding. The <code>-p 127.0.0.1:9000:9000</code> below is important: it
  10489. ensures that access to the <code>manhole</code> is only possible for local users.</p>
  10490. <pre><code class="language-bash">docker run -d --name synapse \
  10491. --mount type=volume,src=synapse-data,dst=/data \
  10492. -p 8008:8008 \
  10493. -p 127.0.0.1:9000:9000 \
  10494. matrixdotorg/synapse:latest
  10495. </code></pre>
  10496. <h4 id="native-config"><a class="header" href="#native-config">Native config</a></h4>
  10497. <p>If you are not using docker, set <code>bind_addresses</code> to <code>['::1', '127.0.0.1']</code> as shown.
  10498. The <code>bind_addresses</code> in the example below is important: it ensures that access to the
  10499. <code>manhole</code> is only possible for local users).</p>
  10500. <pre><code class="language-yaml">listeners:
  10501. - port: 9000
  10502. bind_addresses: ['::1', '127.0.0.1']
  10503. type: manhole
  10504. </code></pre>
  10505. <h4 id="accessing-synapse-manhole"><a class="header" href="#accessing-synapse-manhole">Accessing synapse manhole</a></h4>
  10506. <p>Then restart synapse, and point an ssh client at port 9000 on localhost, using
  10507. the username <code>matrix</code>:</p>
  10508. <pre><code class="language-bash">ssh -p9000 matrix@localhost
  10509. </code></pre>
  10510. <p>The password is <code>rabbithole</code>.</p>
  10511. <p>This gives a Python REPL in which <code>hs</code> gives access to the
  10512. <code>synapse.server.HomeServer</code> object - which in turn gives access to many other
  10513. parts of the process.</p>
  10514. <p>Note that, prior to Synapse 1.41, any call which returns a coroutine will need to be wrapped in <code>ensureDeferred</code>.</p>
  10515. <p>As a simple example, retrieving an event from the database:</p>
  10516. <pre><code class="language-pycon">&gt;&gt;&gt; from twisted.internet import defer
  10517. &gt;&gt;&gt; defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
  10518. &lt;Deferred at 0x7ff253fc6998 current result: &lt;FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''&gt;&gt;
  10519. </code></pre>
  10520. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="how-to-monitor-synapse-metrics-using-prometheus"><a class="header" href="#how-to-monitor-synapse-metrics-using-prometheus">How to monitor Synapse metrics using Prometheus</a></h1>
  10521. <ol>
  10522. <li>
  10523. <p>Install Prometheus:</p>
  10524. <p>Follow instructions at
  10525. <a href="http://prometheus.io/docs/introduction/install/">http://prometheus.io/docs/introduction/install/</a></p>
  10526. </li>
  10527. <li>
  10528. <p>Enable Synapse metrics:</p>
  10529. <p>There are two methods of enabling metrics in Synapse.</p>
  10530. <p>The first serves the metrics as a part of the usual web server and
  10531. can be enabled by adding the &quot;metrics&quot; resource to the existing
  10532. listener as such:</p>
  10533. <pre><code class="language-yaml"> resources:
  10534. - names:
  10535. - client
  10536. - metrics
  10537. </code></pre>
  10538. <p>This provides a simple way of adding metrics to your Synapse
  10539. installation, and serves under <code>/_synapse/metrics</code>. If you do not
  10540. wish your metrics be publicly exposed, you will need to either
  10541. filter it out at your load balancer, or use the second method.</p>
  10542. <p>The second method runs the metrics server on a different port, in a
  10543. different thread to Synapse. This can make it more resilient to
  10544. heavy load meaning metrics cannot be retrieved, and can be exposed
  10545. to just internal networks easier. The served metrics are available
  10546. over HTTP only, and will be available at <code>/_synapse/metrics</code>.</p>
  10547. <p>Add a new listener to homeserver.yaml:</p>
  10548. <pre><code class="language-yaml"> listeners:
  10549. - type: metrics
  10550. port: 9000
  10551. bind_addresses:
  10552. - '0.0.0.0'
  10553. </code></pre>
  10554. <p>For both options, you will need to ensure that <code>enable_metrics</code> is
  10555. set to <code>True</code>.</p>
  10556. </li>
  10557. <li>
  10558. <p>Restart Synapse.</p>
  10559. </li>
  10560. <li>
  10561. <p>Add a Prometheus target for Synapse.</p>
  10562. <p>It needs to set the <code>metrics_path</code> to a non-default value (under
  10563. <code>scrape_configs</code>):</p>
  10564. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10565. scrape_interval: 15s
  10566. metrics_path: &quot;/_synapse/metrics&quot;
  10567. static_configs:
  10568. - targets: [&quot;my.server.here:port&quot;]
  10569. </code></pre>
  10570. <p>where <code>my.server.here</code> is the IP address of Synapse, and <code>port</code> is
  10571. the listener port configured with the <code>metrics</code> resource.</p>
  10572. <p>If your prometheus is older than 1.5.2, you will need to replace
  10573. <code>static_configs</code> in the above with <code>target_groups</code>.</p>
  10574. </li>
  10575. <li>
  10576. <p>Restart Prometheus.</p>
  10577. </li>
  10578. <li>
  10579. <p>Consider using the <a href="https://github.com/matrix-org/synapse/tree/master/contrib/grafana/">grafana dashboard</a>
  10580. and required <a href="https://github.com/matrix-org/synapse/tree/master/contrib/prometheus/">recording rules</a> </p>
  10581. </li>
  10582. </ol>
  10583. <h2 id="monitoring-workers"><a class="header" href="#monitoring-workers">Monitoring workers</a></h2>
  10584. <p>To monitor a Synapse installation using <a href="workers.html">workers</a>,
  10585. every worker needs to be monitored independently, in addition to
  10586. the main homeserver process. This is because workers don't send
  10587. their metrics to the main homeserver process, but expose them
  10588. directly (if they are configured to do so).</p>
  10589. <p>To allow collecting metrics from a worker, you need to add a
  10590. <code>metrics</code> listener to its configuration, by adding the following
  10591. under <code>worker_listeners</code>:</p>
  10592. <pre><code class="language-yaml"> - type: metrics
  10593. bind_address: ''
  10594. port: 9101
  10595. </code></pre>
  10596. <p>The <code>bind_address</code> and <code>port</code> parameters should be set so that
  10597. the resulting listener can be reached by prometheus, and they
  10598. don't clash with an existing worker.
  10599. With this example, the worker's metrics would then be available
  10600. on <code>http://127.0.0.1:9101</code>.</p>
  10601. <p>Example Prometheus target for Synapse with workers:</p>
  10602. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10603. scrape_interval: 15s
  10604. metrics_path: &quot;/_synapse/metrics&quot;
  10605. static_configs:
  10606. - targets: [&quot;my.server.here:port&quot;]
  10607. labels:
  10608. instance: &quot;my.server&quot;
  10609. job: &quot;master&quot;
  10610. index: 1
  10611. - targets: [&quot;my.workerserver.here:port&quot;]
  10612. labels:
  10613. instance: &quot;my.server&quot;
  10614. job: &quot;generic_worker&quot;
  10615. index: 1
  10616. - targets: [&quot;my.workerserver.here:port&quot;]
  10617. labels:
  10618. instance: &quot;my.server&quot;
  10619. job: &quot;generic_worker&quot;
  10620. index: 2
  10621. - targets: [&quot;my.workerserver.here:port&quot;]
  10622. labels:
  10623. instance: &quot;my.server&quot;
  10624. job: &quot;media_repository&quot;
  10625. index: 1
  10626. </code></pre>
  10627. <p>Labels (<code>instance</code>, <code>job</code>, <code>index</code>) can be defined as anything.
  10628. The labels are used to group graphs in grafana.</p>
  10629. <h2 id="renaming-of-metrics--deprecation-of-old-names-in-12"><a class="header" href="#renaming-of-metrics--deprecation-of-old-names-in-12">Renaming of metrics &amp; deprecation of old names in 1.2</a></h2>
  10630. <p>Synapse 1.2 updates the Prometheus metrics to match the naming
  10631. convention of the upstream <code>prometheus_client</code>. The old names are
  10632. considered deprecated and will be removed in a future version of
  10633. Synapse.</p>
  10634. <table><thead><tr><th>New Name</th><th>Old Name</th></tr></thead><tbody>
  10635. <tr><td>python_gc_objects_collected_total</td><td>python_gc_objects_collected</td></tr>
  10636. <tr><td>python_gc_objects_uncollectable_total</td><td>python_gc_objects_uncollectable</td></tr>
  10637. <tr><td>python_gc_collections_total</td><td>python_gc_collections</td></tr>
  10638. <tr><td>process_cpu_seconds_total</td><td>process_cpu_seconds</td></tr>
  10639. <tr><td>synapse_federation_client_sent_transactions_total</td><td>synapse_federation_client_sent_transactions</td></tr>
  10640. <tr><td>synapse_federation_client_events_processed_total</td><td>synapse_federation_client_events_processed</td></tr>
  10641. <tr><td>synapse_event_processing_loop_count_total</td><td>synapse_event_processing_loop_count</td></tr>
  10642. <tr><td>synapse_event_processing_loop_room_count_total</td><td>synapse_event_processing_loop_room_count</td></tr>
  10643. <tr><td>synapse_util_metrics_block_count_total</td><td>synapse_util_metrics_block_count</td></tr>
  10644. <tr><td>synapse_util_metrics_block_time_seconds_total</td><td>synapse_util_metrics_block_time_seconds</td></tr>
  10645. <tr><td>synapse_util_metrics_block_ru_utime_seconds_total</td><td>synapse_util_metrics_block_ru_utime_seconds</td></tr>
  10646. <tr><td>synapse_util_metrics_block_ru_stime_seconds_total</td><td>synapse_util_metrics_block_ru_stime_seconds</td></tr>
  10647. <tr><td>synapse_util_metrics_block_db_txn_count_total</td><td>synapse_util_metrics_block_db_txn_count</td></tr>
  10648. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds_total</td><td>synapse_util_metrics_block_db_txn_duration_seconds</td></tr>
  10649. <tr><td>synapse_util_metrics_block_db_sched_duration_seconds_total</td><td>synapse_util_metrics_block_db_sched_duration_seconds</td></tr>
  10650. <tr><td>synapse_background_process_start_count_total</td><td>synapse_background_process_start_count</td></tr>
  10651. <tr><td>synapse_background_process_ru_utime_seconds_total</td><td>synapse_background_process_ru_utime_seconds</td></tr>
  10652. <tr><td>synapse_background_process_ru_stime_seconds_total</td><td>synapse_background_process_ru_stime_seconds</td></tr>
  10653. <tr><td>synapse_background_process_db_txn_count_total</td><td>synapse_background_process_db_txn_count</td></tr>
  10654. <tr><td>synapse_background_process_db_txn_duration_seconds_total</td><td>synapse_background_process_db_txn_duration_seconds</td></tr>
  10655. <tr><td>synapse_background_process_db_sched_duration_seconds_total</td><td>synapse_background_process_db_sched_duration_seconds</td></tr>
  10656. <tr><td>synapse_storage_events_persisted_events_total</td><td>synapse_storage_events_persisted_events</td></tr>
  10657. <tr><td>synapse_storage_events_persisted_events_sep_total</td><td>synapse_storage_events_persisted_events_sep</td></tr>
  10658. <tr><td>synapse_storage_events_state_delta_total</td><td>synapse_storage_events_state_delta</td></tr>
  10659. <tr><td>synapse_storage_events_state_delta_single_event_total</td><td>synapse_storage_events_state_delta_single_event</td></tr>
  10660. <tr><td>synapse_storage_events_state_delta_reuse_delta_total</td><td>synapse_storage_events_state_delta_reuse_delta</td></tr>
  10661. <tr><td>synapse_federation_server_received_pdus_total</td><td>synapse_federation_server_received_pdus</td></tr>
  10662. <tr><td>synapse_federation_server_received_edus_total</td><td>synapse_federation_server_received_edus</td></tr>
  10663. <tr><td>synapse_handler_presence_notified_presence_total</td><td>synapse_handler_presence_notified_presence</td></tr>
  10664. <tr><td>synapse_handler_presence_federation_presence_out_total</td><td>synapse_handler_presence_federation_presence_out</td></tr>
  10665. <tr><td>synapse_handler_presence_presence_updates_total</td><td>synapse_handler_presence_presence_updates</td></tr>
  10666. <tr><td>synapse_handler_presence_timers_fired_total</td><td>synapse_handler_presence_timers_fired</td></tr>
  10667. <tr><td>synapse_handler_presence_federation_presence_total</td><td>synapse_handler_presence_federation_presence</td></tr>
  10668. <tr><td>synapse_handler_presence_bump_active_time_total</td><td>synapse_handler_presence_bump_active_time</td></tr>
  10669. <tr><td>synapse_federation_client_sent_edus_total</td><td>synapse_federation_client_sent_edus</td></tr>
  10670. <tr><td>synapse_federation_client_sent_pdu_destinations_count_total</td><td>synapse_federation_client_sent_pdu_destinations:count</td></tr>
  10671. <tr><td>synapse_federation_client_sent_pdu_destinations_total</td><td>synapse_federation_client_sent_pdu_destinations:total</td></tr>
  10672. <tr><td>synapse_handlers_appservice_events_processed_total</td><td>synapse_handlers_appservice_events_processed</td></tr>
  10673. <tr><td>synapse_notifier_notified_events_total</td><td>synapse_notifier_notified_events</td></tr>
  10674. <tr><td>synapse_push_bulk_push_rule_evaluator_push_rules_invalidation_counter_total</td><td>synapse_push_bulk_push_rule_evaluator_push_rules_invalidation_counter</td></tr>
  10675. <tr><td>synapse_push_bulk_push_rule_evaluator_push_rules_state_size_counter_total</td><td>synapse_push_bulk_push_rule_evaluator_push_rules_state_size_counter</td></tr>
  10676. <tr><td>synapse_http_httppusher_http_pushes_processed_total</td><td>synapse_http_httppusher_http_pushes_processed</td></tr>
  10677. <tr><td>synapse_http_httppusher_http_pushes_failed_total</td><td>synapse_http_httppusher_http_pushes_failed</td></tr>
  10678. <tr><td>synapse_http_httppusher_badge_updates_processed_total</td><td>synapse_http_httppusher_badge_updates_processed</td></tr>
  10679. <tr><td>synapse_http_httppusher_badge_updates_failed_total</td><td>synapse_http_httppusher_badge_updates_failed</td></tr>
  10680. </tbody></table>
  10681. <h2 id="removal-of-deprecated-metrics--time-based-counters-becoming-histograms-in-0310"><a class="header" href="#removal-of-deprecated-metrics--time-based-counters-becoming-histograms-in-0310">Removal of deprecated metrics &amp; time based counters becoming histograms in 0.31.0</a></h2>
  10682. <p>The duplicated metrics deprecated in Synapse 0.27.0 have been removed.</p>
  10683. <p>All time duration-based metrics have been changed to be seconds. This
  10684. affects:</p>
  10685. <table><thead><tr><th>msec -&gt; sec metrics</th></tr></thead><tbody>
  10686. <tr><td>python_gc_time</td></tr>
  10687. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10688. <tr><td>synapse_storage_query_time</td></tr>
  10689. <tr><td>synapse_storage_schedule_time</td></tr>
  10690. <tr><td>synapse_storage_transaction_time</td></tr>
  10691. </tbody></table>
  10692. <p>Several metrics have been changed to be histograms, which sort entries
  10693. into buckets and allow better analysis. The following metrics are now
  10694. histograms:</p>
  10695. <table><thead><tr><th>Altered metrics</th></tr></thead><tbody>
  10696. <tr><td>python_gc_time</td></tr>
  10697. <tr><td>python_twisted_reactor_pending_calls</td></tr>
  10698. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10699. <tr><td>synapse_http_server_response_time_seconds</td></tr>
  10700. <tr><td>synapse_storage_query_time</td></tr>
  10701. <tr><td>synapse_storage_schedule_time</td></tr>
  10702. <tr><td>synapse_storage_transaction_time</td></tr>
  10703. </tbody></table>
  10704. <h2 id="block-and-response-metrics-renamed-for-0270"><a class="header" href="#block-and-response-metrics-renamed-for-0270">Block and response metrics renamed for 0.27.0</a></h2>
  10705. <p>Synapse 0.27.0 begins the process of rationalising the duplicate
  10706. <code>*:count</code> metrics reported for the resource tracking for code blocks and
  10707. HTTP requests.</p>
  10708. <p>At the same time, the corresponding <code>*:total</code> metrics are being renamed,
  10709. as the <code>:total</code> suffix no longer makes sense in the absence of a
  10710. corresponding <code>:count</code> metric.</p>
  10711. <p>To enable a graceful migration path, this release just adds new names
  10712. for the metrics being renamed. A future release will remove the old
  10713. ones.</p>
  10714. <p>The following table shows the new metrics, and the old metrics which
  10715. they are replacing.</p>
  10716. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10717. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_timer:count</td></tr>
  10718. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_utime:count</td></tr>
  10719. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_stime:count</td></tr>
  10720. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_count:count</td></tr>
  10721. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_duration:count</td></tr>
  10722. <tr><td>synapse_util_metrics_block_time_seconds</td><td>synapse_util_metrics_block_timer:total</td></tr>
  10723. <tr><td>synapse_util_metrics_block_ru_utime_seconds</td><td>synapse_util_metrics_block_ru_utime:total</td></tr>
  10724. <tr><td>synapse_util_metrics_block_ru_stime_seconds</td><td>synapse_util_metrics_block_ru_stime:total</td></tr>
  10725. <tr><td>synapse_util_metrics_block_db_txn_count</td><td>synapse_util_metrics_block_db_txn_count:total</td></tr>
  10726. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds</td><td>synapse_util_metrics_block_db_txn_duration:total</td></tr>
  10727. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_requests</td></tr>
  10728. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_time:count</td></tr>
  10729. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_utime:count</td></tr>
  10730. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_stime:count</td></tr>
  10731. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_count:count</td></tr>
  10732. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_duration:count</td></tr>
  10733. <tr><td>synapse_http_server_response_time_seconds</td><td>synapse_http_server_response_time:total</td></tr>
  10734. <tr><td>synapse_http_server_response_ru_utime_seconds</td><td>synapse_http_server_response_ru_utime:total</td></tr>
  10735. <tr><td>synapse_http_server_response_ru_stime_seconds</td><td>synapse_http_server_response_ru_stime:total</td></tr>
  10736. <tr><td>synapse_http_server_response_db_txn_count</td><td>synapse_http_server_response_db_txn_count:total</td></tr>
  10737. <tr><td>synapse_http_server_response_db_txn_duration_seconds</td><td>synapse_http_server_response_db_txn_duration:total</td></tr>
  10738. </tbody></table>
  10739. <h2 id="standard-metric-names"><a class="header" href="#standard-metric-names">Standard Metric Names</a></h2>
  10740. <p>As of synapse version 0.18.2, the format of the process-wide metrics has
  10741. been changed to fit prometheus standard naming conventions. Additionally
  10742. the units have been changed to seconds, from miliseconds.</p>
  10743. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10744. <tr><td>process_cpu_user_seconds_total</td><td>process_resource_utime / 1000</td></tr>
  10745. <tr><td>process_cpu_system_seconds_total</td><td>process_resource_stime / 1000</td></tr>
  10746. <tr><td>process_open_fds (no 'type' label)</td><td>process_fds</td></tr>
  10747. </tbody></table>
  10748. <p>The python-specific counts of garbage collector performance have been
  10749. renamed.</p>
  10750. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10751. <tr><td>python_gc_time</td><td>reactor_gc_time</td></tr>
  10752. <tr><td>python_gc_unreachable_total</td><td>reactor_gc_unreachable</td></tr>
  10753. <tr><td>python_gc_counts</td><td>reactor_gc_counts</td></tr>
  10754. </tbody></table>
  10755. <p>The twisted-specific reactor metrics have been renamed.</p>
  10756. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10757. <tr><td>python_twisted_reactor_pending_calls</td><td>reactor_pending_calls</td></tr>
  10758. <tr><td>python_twisted_reactor_tick_time</td><td>reactor_tick_time</td></tr>
  10759. </tbody></table>
  10760. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="request-log-format"><a class="header" href="#request-log-format">Request log format</a></h1>
  10761. <p>HTTP request logs are written by synapse (see <a href="usage/administration/../synapse/http/site.py"><code>site.py</code></a> for details).</p>
  10762. <p>See the following for how to decode the dense data available from the default logging configuration.</p>
  10763. <pre><code>2020-10-01 12:00:00,000 - synapse.access.http.8008 - 311 - INFO - PUT-1000- 192.168.0.1 - 8008 - {another-matrix-server.com} Processed request: 0.100sec/-0.000sec (0.000sec, 0.000sec) (0.001sec/0.090sec/3) 11B !200 &quot;PUT /_matrix/federation/v1/send/1600000000000 HTTP/1.1&quot; &quot;Synapse/1.20.1&quot; [0 dbevts]
  10764. -AAAAAAAAAAAAAAAAAAAAA- -BBBBBBBBBBBBBBBBBBBBBB- -C- -DD- -EEEEEE- -FFFFFFFFF- -GG- -HHHHHHHHHHHHHHHHHHHHHHH- -IIIIII- -JJJJJJJ- -KKKKKK-, -LLLLLL- -MMMMMMM- -NNNNNN- O -P- -QQ- -RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR- -SSSSSSSSSSSS- -TTTTTT-
  10765. </code></pre>
  10766. <table><thead><tr><th>Part</th><th>Explanation</th></tr></thead><tbody>
  10767. <tr><td>AAAA</td><td>Timestamp request was logged (not recieved)</td></tr>
  10768. <tr><td>BBBB</td><td>Logger name (<code>synapse.access.(http\|https).&lt;tag&gt;</code>, where 'tag' is defined in the <code>listeners</code> config section, normally the port)</td></tr>
  10769. <tr><td>CCCC</td><td>Line number in code</td></tr>
  10770. <tr><td>DDDD</td><td>Log Level</td></tr>
  10771. <tr><td>EEEE</td><td>Request Identifier (This identifier is shared by related log lines)</td></tr>
  10772. <tr><td>FFFF</td><td>Source IP (Or X-Forwarded-For if enabled)</td></tr>
  10773. <tr><td>GGGG</td><td>Server Port</td></tr>
  10774. <tr><td>HHHH</td><td>Federated Server or Local User making request (blank if unauthenticated or not supplied)</td></tr>
  10775. <tr><td>IIII</td><td>Total Time to process the request</td></tr>
  10776. <tr><td>JJJJ</td><td>Time to send response over network once generated (this may be negative if the socket is closed before the response is generated)</td></tr>
  10777. <tr><td>KKKK</td><td>Userland CPU time</td></tr>
  10778. <tr><td>LLLL</td><td>System CPU time</td></tr>
  10779. <tr><td>MMMM</td><td>Total time waiting for a free DB connection from the pool across all parallel DB work from this request</td></tr>
  10780. <tr><td>NNNN</td><td>Total time waiting for response to DB queries across all parallel DB work from this request</td></tr>
  10781. <tr><td>OOOO</td><td>Count of DB transactions performed</td></tr>
  10782. <tr><td>PPPP</td><td>Response body size</td></tr>
  10783. <tr><td>QQQQ</td><td>Response status code (prefixed with ! if the socket was closed before the response was generated)</td></tr>
  10784. <tr><td>RRRR</td><td>Request</td></tr>
  10785. <tr><td>SSSS</td><td>User-agent</td></tr>
  10786. <tr><td>TTTT</td><td>Events fetched from DB to service this request (note that this does not include events fetched from the cache)</td></tr>
  10787. </tbody></table>
  10788. <p>MMMM / NNNN can be greater than IIII if there are multiple slow database queries
  10789. running in parallel.</p>
  10790. <p>Some actions can result in multiple identical http requests, which will return
  10791. the same data, but only the first request will report time/transactions in
  10792. <code>KKKK</code>/<code>LLLL</code>/<code>MMMM</code>/<code>NNNN</code>/<code>OOOO</code> - the others will be awaiting the first query to return a
  10793. response and will simultaneously return with the first request, but with very
  10794. small processing times.</p>
  10795. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><!--
  10796. Include the contents of CONTRIBUTING.md from the project root (where GitHub likes it
  10797. to be)
  10798. -->
  10799. <h1 id="contributing"><a class="header" href="#contributing">Contributing</a></h1>
  10800. <p>Welcome to Synapse</p>
  10801. <p>This document aims to get you started with contributing to this repo! </p>
  10802. <ul>
  10803. <li><a href="development/contributing_guide.html#1-who-can-contribute-to-synapse">1. Who can contribute to Synapse?</a></li>
  10804. <li><a href="development/contributing_guide.html#2-what-do-i-need">2. What do I need?</a></li>
  10805. <li><a href="development/contributing_guide.html#3-get-the-source">3. Get the source.</a></li>
  10806. <li><a href="development/contributing_guide.html#4-install-the-dependencies">4. Install the dependencies</a>
  10807. <ul>
  10808. <li><a href="development/contributing_guide.html#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></li>
  10809. <li><a href="development/contributing_guide.html#under-windows">Under Windows</a></li>
  10810. </ul>
  10811. </li>
  10812. <li><a href="development/contributing_guide.html#5-get-in-touch">5. Get in touch.</a></li>
  10813. <li><a href="development/contributing_guide.html#6-pick-an-issue">6. Pick an issue.</a></li>
  10814. <li><a href="development/contributing_guide.html#7-turn-coffee-and-documentation-into-code-and-documentation">7. Turn coffee and documentation into code and documentation!</a></li>
  10815. <li><a href="development/contributing_guide.html#8-test-test-test">8. Test, test, test!</a>
  10816. <ul>
  10817. <li><a href="development/contributing_guide.html#run-the-linters">Run the linters.</a></li>
  10818. <li><a href="development/contributing_guide.html#run-the-unit-tests-twisted-trial">Run the unit tests.</a></li>
  10819. <li><a href="development/contributing_guide.html#run-the-integration-tests-sytest">Run the integration tests (SyTest).</a></li>
  10820. <li><a href="development/contributing_guide.html#run-the-integration-tests-complement">Run the integration tests (Complement).</a></li>
  10821. </ul>
  10822. </li>
  10823. <li><a href="development/contributing_guide.html#9-submit-your-patch">9. Submit your patch.</a>
  10824. <ul>
  10825. <li><a href="development/contributing_guide.html#changelog">Changelog</a>
  10826. <ul>
  10827. <li><a href="development/contributing_guide.html#how-do-i-know-what-to-call-the-changelog-file-before-i-create-the-pr">How do I know what to call the changelog file before I create the PR?</a></li>
  10828. <li><a href="development/contributing_guide.html#debian-changelog">Debian changelog</a></li>
  10829. </ul>
  10830. </li>
  10831. <li><a href="development/contributing_guide.html#sign-off">Sign off</a></li>
  10832. </ul>
  10833. </li>
  10834. <li><a href="development/contributing_guide.html#10-turn-feedback-into-better-code">10. Turn feedback into better code.</a></li>
  10835. <li><a href="development/contributing_guide.html#11-find-a-new-issue">11. Find a new issue.</a></li>
  10836. <li><a href="development/contributing_guide.html#notes-for-maintainers-on-merging-prs-etc">Notes for maintainers on merging PRs etc</a></li>
  10837. <li><a href="development/contributing_guide.html#conclusion">Conclusion</a></li>
  10838. </ul>
  10839. <h1 id="1-who-can-contribute-to-synapse"><a class="header" href="#1-who-can-contribute-to-synapse">1. Who can contribute to Synapse?</a></h1>
  10840. <p>Everyone is welcome to contribute code to <a href="https://github.com/matrix-org">matrix.org
  10841. projects</a>, provided that they are willing to
  10842. license their contributions under the same license as the project itself. We
  10843. follow a simple 'inbound=outbound' model for contributions: the act of
  10844. submitting an 'inbound' contribution means that the contributor agrees to
  10845. license the code under the same terms as the project's overall 'outbound'
  10846. license - in our case, this is almost always Apache Software License v2 (see
  10847. <a href="development/LICENSE">LICENSE</a>).</p>
  10848. <h1 id="2-what-do-i-need"><a class="header" href="#2-what-do-i-need">2. What do I need?</a></h1>
  10849. <p>The code of Synapse is written in Python 3. To do pretty much anything, you'll need <a href="https://wiki.python.org/moin/BeginnersGuide/Download">a recent version of Python 3</a>.</p>
  10850. <p>The source code of Synapse is hosted on GitHub. You will also need <a href="https://github.com/git-guides/install-git">a recent version of git</a>.</p>
  10851. <p>For some tests, you will need <a href="https://docs.docker.com/get-docker/">a recent version of Docker</a>.</p>
  10852. <h1 id="3-get-the-source"><a class="header" href="#3-get-the-source">3. Get the source.</a></h1>
  10853. <p>The preferred and easiest way to contribute changes is to fork the relevant
  10854. project on GitHub, and then <a href="https://help.github.com/articles/using-pull-requests/">create a pull request</a> to ask us to pull your
  10855. changes into our repo.</p>
  10856. <p>Please base your changes on the <code>develop</code> branch.</p>
  10857. <pre><code class="language-sh">git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git
  10858. git checkout develop
  10859. </code></pre>
  10860. <p>If you need help getting started with git, this is beyond the scope of the document, but you
  10861. can find many good git tutorials on the web.</p>
  10862. <h1 id="4-install-the-dependencies"><a class="header" href="#4-install-the-dependencies">4. Install the dependencies</a></h1>
  10863. <h2 id="under-unix-macos-linux-bsd-"><a class="header" href="#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></h2>
  10864. <p>Once you have installed Python 3 and added the source, please open a terminal and
  10865. setup a <em>virtualenv</em>, as follows:</p>
  10866. <pre><code class="language-sh">cd path/where/you/have/cloned/the/repository
  10867. python3 -m venv ./env
  10868. source ./env/bin/activate
  10869. pip install -e &quot;.[all,lint,mypy,test]&quot;
  10870. pip install tox
  10871. </code></pre>
  10872. <p>This will install the developer dependencies for the project.</p>
  10873. <h2 id="under-windows"><a class="header" href="#under-windows">Under Windows</a></h2>
  10874. <p>TBD</p>
  10875. <h1 id="5-get-in-touch"><a class="header" href="#5-get-in-touch">5. Get in touch.</a></h1>
  10876. <p>Join our developer community on Matrix: #synapse-dev:matrix.org !</p>
  10877. <h1 id="6-pick-an-issue"><a class="header" href="#6-pick-an-issue">6. Pick an issue.</a></h1>
  10878. <p>Fix your favorite problem or perhaps find a <a href="https://github.com/matrix-org/synapse/issues?q=is%3Aopen+is%3Aissue+label%3A%22Good+First+Issue%22">Good First Issue</a>
  10879. to work on.</p>
  10880. <h1 id="7-turn-coffee-and-documentation-into-code-and-documentation"><a class="header" href="#7-turn-coffee-and-documentation-into-code-and-documentation">7. Turn coffee and documentation into code and documentation!</a></h1>
  10881. <p>Synapse's code style is documented <a href="development/docs/code_style.html">here</a>. Please follow
  10882. it, including the conventions for the <a href="development/docs/code_style.html#configuration-file-format">sample configuration
  10883. file</a>.</p>
  10884. <p>There is a growing amount of documentation located in the <a href="development/docs">docs</a>
  10885. directory. This documentation is intended primarily for sysadmins running their
  10886. own Synapse instance, as well as developers interacting externally with
  10887. Synapse. <a href="development/docs/dev">docs/dev</a> exists primarily to house documentation for
  10888. Synapse developers. <a href="development/docs/admin_api">docs/admin_api</a> houses documentation
  10889. regarding Synapse's Admin API, which is used mostly by sysadmins and external
  10890. service developers.</p>
  10891. <p>If you add new files added to either of these folders, please use <a href="https://guides.github.com/features/mastering-markdown/">GitHub-Flavoured
  10892. Markdown</a>.</p>
  10893. <p>Some documentation also exists in <a href="https://github.com/matrix-org/synapse/wiki">Synapse's GitHub
  10894. Wiki</a>, although this is primarily
  10895. contributed to by community authors.</p>
  10896. <h1 id="8-test-test-test"><a class="header" href="#8-test-test-test">8. Test, test, test!</a></h1>
  10897. <p><a name="test-test-test"></a></p>
  10898. <p>While you're developing and before submitting a patch, you'll
  10899. want to test your code.</p>
  10900. <h2 id="run-the-linters"><a class="header" href="#run-the-linters">Run the linters.</a></h2>
  10901. <p>The linters look at your code and do two things:</p>
  10902. <ul>
  10903. <li>ensure that your code follows the coding style adopted by the project;</li>
  10904. <li>catch a number of errors in your code.</li>
  10905. </ul>
  10906. <p>They're pretty fast, don't hesitate!</p>
  10907. <pre><code class="language-sh">source ./env/bin/activate
  10908. ./scripts-dev/lint.sh
  10909. </code></pre>
  10910. <p>Note that this script <em>will modify your files</em> to fix styling errors.
  10911. Make sure that you have saved all your files.</p>
  10912. <p>If you wish to restrict the linters to only the files changed since the last commit
  10913. (much faster!), you can instead run:</p>
  10914. <pre><code class="language-sh">source ./env/bin/activate
  10915. ./scripts-dev/lint.sh -d
  10916. </code></pre>
  10917. <p>Or if you know exactly which files you wish to lint, you can instead run:</p>
  10918. <pre><code class="language-sh">source ./env/bin/activate
  10919. ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
  10920. </code></pre>
  10921. <h2 id="run-the-unit-tests-twisted-trial"><a class="header" href="#run-the-unit-tests-twisted-trial">Run the unit tests (Twisted trial).</a></h2>
  10922. <p>The unit tests run parts of Synapse, including your changes, to see if anything
  10923. was broken. They are slower than the linters but will typically catch more errors.</p>
  10924. <pre><code class="language-sh">source ./env/bin/activate
  10925. trial tests
  10926. </code></pre>
  10927. <p>If you wish to only run <em>some</em> unit tests, you may specify
  10928. another module instead of <code>tests</code> - or a test class or a method:</p>
  10929. <pre><code class="language-sh">source ./env/bin/activate
  10930. trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
  10931. </code></pre>
  10932. <p>If your tests fail, you may wish to look at the logs (the default log level is <code>ERROR</code>):</p>
  10933. <pre><code class="language-sh">less _trial_temp/test.log
  10934. </code></pre>
  10935. <p>To increase the log level for the tests, set <code>SYNAPSE_TEST_LOG_LEVEL</code>:</p>
  10936. <pre><code class="language-sh">SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
  10937. </code></pre>
  10938. <h2 id="run-the-integration-tests-a-hrefhttpsgithubcommatrix-orgsytestsytesta"><a class="header" href="#run-the-integration-tests-a-hrefhttpsgithubcommatrix-orgsytestsytesta">Run the integration tests (<a href="https://github.com/matrix-org/sytest">Sytest</a>).</a></h2>
  10939. <p>The integration tests are a more comprehensive suite of tests. They
  10940. run a full version of Synapse, including your changes, to check if
  10941. anything was broken. They are slower than the unit tests but will
  10942. typically catch more errors.</p>
  10943. <p>The following command will let you run the integration test with the most common
  10944. configuration:</p>
  10945. <pre><code class="language-sh">$ docker run --rm -it -v /path/where/you/have/cloned/the/repository\:/src:ro -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapse:buster
  10946. </code></pre>
  10947. <p>This configuration should generally cover your needs. For more details about other configurations, see <a href="https://github.com/matrix-org/sytest/blob/develop/docker/README.md">documentation in the SyTest repo</a>.</p>
  10948. <h2 id="run-the-integration-tests-a-hrefhttpsgithubcommatrix-orgcomplementcomplementa"><a class="header" href="#run-the-integration-tests-a-hrefhttpsgithubcommatrix-orgcomplementcomplementa">Run the integration tests (<a href="https://github.com/matrix-org/complement">Complement</a>).</a></h2>
  10949. <p><a href="https://github.com/matrix-org/complement">Complement</a> is a suite of black box tests that can be run on any homeserver implementation. It can also be thought of as end-to-end (e2e) tests.</p>
  10950. <p>It's often nice to develop on Synapse and write Complement tests at the same time.
  10951. Here is how to run your local Synapse checkout against your local Complement checkout.</p>
  10952. <p>(checkout <a href="https://github.com/matrix-org/complement"><code>complement</code></a> alongside your <code>synapse</code> checkout)</p>
  10953. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh
  10954. </code></pre>
  10955. <p>To run a specific test file, you can pass the test name at the end of the command. The name passed comes from the naming structure in your Complement tests. If you're unsure of the name, you can do a full run and copy it from the test output:</p>
  10956. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory
  10957. </code></pre>
  10958. <p>To run a specific test, you can specify the whole name structure:</p>
  10959. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory/parallel/Backfilled_historical_events_resolve_with_proper_state_in_correct_order
  10960. </code></pre>
  10961. <h3 id="access-database-for-homeserver-after-complement-test-runs"><a class="header" href="#access-database-for-homeserver-after-complement-test-runs">Access database for homeserver after Complement test runs.</a></h3>
  10962. <p>If you're curious what the database looks like after you run some tests, here are some steps to get you going in Synapse:</p>
  10963. <ol>
  10964. <li>In your Complement test comment out <code>defer deployment.Destroy(t)</code> and replace with <code>defer time.Sleep(2 * time.Hour)</code> to keep the homeserver running after the tests complete</li>
  10965. <li>Start the Complement tests</li>
  10966. <li>Find the name of the container, <code>docker ps -f name=complement_</code> (this will filter for just the Compelement related Docker containers)</li>
  10967. <li>Access the container replacing the name with what you found in the previous step: <code>docker exec -it complement_1_hs_with_application_service.hs1_2 /bin/bash</code></li>
  10968. <li>Install sqlite (database driver), <code>apt-get update &amp;&amp; apt-get install -y sqlite3</code></li>
  10969. <li>Then run <code>sqlite3</code> and open the database <code>.open /conf/homeserver.db</code> (this db path comes from the Synapse homeserver.yaml)</li>
  10970. </ol>
  10971. <h1 id="9-submit-your-patch"><a class="header" href="#9-submit-your-patch">9. Submit your patch.</a></h1>
  10972. <p>Once you're happy with your patch, it's time to prepare a Pull Request.</p>
  10973. <p>To prepare a Pull Request, please:</p>
  10974. <ol>
  10975. <li>verify that <a href="development/contributing_guide.html#test-test-test">all the tests pass</a>, including the coding style;</li>
  10976. <li><a href="development/contributing_guide.html#sign-off">sign off</a> your contribution;</li>
  10977. <li><code>git push</code> your commit to your fork of Synapse;</li>
  10978. <li>on GitHub, <a href="https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request">create the Pull Request</a>;</li>
  10979. <li>add a <a href="development/contributing_guide.html#changelog">changelog entry</a> and push it to your Pull Request;</li>
  10980. <li>for most contributors, that's all - however, if you are a member of the organization <code>matrix-org</code>, on GitHub, please request a review from <code>matrix.org / Synapse Core</code>.</li>
  10981. <li>if you need to update your PR, please avoid rebasing and just add new commits to your branch.</li>
  10982. </ol>
  10983. <h2 id="changelog"><a class="header" href="#changelog">Changelog</a></h2>
  10984. <p>All changes, even minor ones, need a corresponding changelog / newsfragment
  10985. entry. These are managed by <a href="https://github.com/hawkowl/towncrier">Towncrier</a>.</p>
  10986. <p>To create a changelog entry, make a new file in the <code>changelog.d</code> directory named
  10987. in the format of <code>PRnumber.type</code>. The type can be one of the following:</p>
  10988. <ul>
  10989. <li><code>feature</code></li>
  10990. <li><code>bugfix</code></li>
  10991. <li><code>docker</code> (for updates to the Docker image)</li>
  10992. <li><code>doc</code> (for updates to the documentation)</li>
  10993. <li><code>removal</code> (also used for deprecations)</li>
  10994. <li><code>misc</code> (for internal-only changes)</li>
  10995. </ul>
  10996. <p>This file will become part of our <a href="https://github.com/matrix-org/synapse/blob/master/CHANGES.md">changelog</a> at the next
  10997. release, so the content of the file should be a short description of your
  10998. change in the same style as the rest of the changelog. The file can contain Markdown
  10999. formatting, and should end with a full stop (.) or an exclamation mark (!) for
  11000. consistency.</p>
  11001. <p>Adding credits to the changelog is encouraged, we value your
  11002. contributions and would like to have you shouted out in the release notes!</p>
  11003. <p>For example, a fix in PR #1234 would have its changelog entry in
  11004. <code>changelog.d/1234.bugfix</code>, and contain content like:</p>
  11005. <blockquote>
  11006. <p>The security levels of Florbs are now validated when received
  11007. via the <code>/federation/florb</code> endpoint. Contributed by Jane Matrix.</p>
  11008. </blockquote>
  11009. <p>If there are multiple pull requests involved in a single bugfix/feature/etc,
  11010. then the content for each <code>changelog.d</code> file should be the same. Towncrier will
  11011. merge the matching files together into a single changelog entry when we come to
  11012. release.</p>
  11013. <h3 id="how-do-i-know-what-to-call-the-changelog-file-before-i-create-the-pr"><a class="header" href="#how-do-i-know-what-to-call-the-changelog-file-before-i-create-the-pr">How do I know what to call the changelog file before I create the PR?</a></h3>
  11014. <p>Obviously, you don't know if you should call your newsfile
  11015. <code>1234.bugfix</code> or <code>5678.bugfix</code> until you create the PR, which leads to a
  11016. chicken-and-egg problem.</p>
  11017. <p>There are two options for solving this:</p>
  11018. <ol>
  11019. <li>
  11020. <p>Open the PR without a changelog file, see what number you got, and <em>then</em>
  11021. add the changelog file to your branch (see <a href="development/contributing_guide.html#updating-your-pull-request">Updating your pull
  11022. request</a>), or:</p>
  11023. </li>
  11024. <li>
  11025. <p>Look at the <a href="https://github.com/matrix-org/synapse/issues?q=">list of all
  11026. issues/PRs</a>, add one to the
  11027. highest number you see, and quickly open the PR before somebody else claims
  11028. your number.</p>
  11029. <p><a href="https://github.com/richvdh/scripts/blob/master/next_github_number.sh">This
  11030. script</a>
  11031. might be helpful if you find yourself doing this a lot.</p>
  11032. </li>
  11033. </ol>
  11034. <p>Sorry, we know it's a bit fiddly, but it's <em>really</em> helpful for us when we come
  11035. to put together a release!</p>
  11036. <h3 id="debian-changelog"><a class="header" href="#debian-changelog">Debian changelog</a></h3>
  11037. <p>Changes which affect the debian packaging files (in <code>debian</code>) are an
  11038. exception to the rule that all changes require a <code>changelog.d</code> file.</p>
  11039. <p>In this case, you will need to add an entry to the debian changelog for the
  11040. next release. For this, run the following command:</p>
  11041. <pre><code>dch
  11042. </code></pre>
  11043. <p>This will make up a new version number (if there isn't already an unreleased
  11044. version in flight), and open an editor where you can add a new changelog entry.
  11045. (Our release process will ensure that the version number and maintainer name is
  11046. corrected for the release.)</p>
  11047. <p>If your change affects both the debian packaging <em>and</em> files outside the debian
  11048. directory, you will need both a regular newsfragment <em>and</em> an entry in the
  11049. debian changelog. (Though typically such changes should be submitted as two
  11050. separate pull requests.)</p>
  11051. <h2 id="sign-off"><a class="header" href="#sign-off">Sign off</a></h2>
  11052. <p>In order to have a concrete record that your contribution is intentional
  11053. and you agree to license it under the same terms as the project's license, we've adopted the
  11054. same lightweight approach that the Linux Kernel
  11055. <a href="https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin%3E">submitting patches process</a>,
  11056. <a href="https://github.com/docker/docker/blob/master/CONTRIBUTING.md">Docker</a>, and many other
  11057. projects use: the DCO (Developer Certificate of Origin:
  11058. http://developercertificate.org/). This is a simple declaration that you wrote
  11059. the contribution or otherwise have the right to contribute it to Matrix:</p>
  11060. <pre><code>Developer Certificate of Origin
  11061. Version 1.1
  11062. Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
  11063. 660 York Street, Suite 102,
  11064. San Francisco, CA 94110 USA
  11065. Everyone is permitted to copy and distribute verbatim copies of this
  11066. license document, but changing it is not allowed.
  11067. Developer's Certificate of Origin 1.1
  11068. By making a contribution to this project, I certify that:
  11069. (a) The contribution was created in whole or in part by me and I
  11070. have the right to submit it under the open source license
  11071. indicated in the file; or
  11072. (b) The contribution is based upon previous work that, to the best
  11073. of my knowledge, is covered under an appropriate open source
  11074. license and I have the right under that license to submit that
  11075. work with modifications, whether created in whole or in part
  11076. by me, under the same open source license (unless I am
  11077. permitted to submit under a different license), as indicated
  11078. in the file; or
  11079. (c) The contribution was provided directly to me by some other
  11080. person who certified (a), (b) or (c) and I have not modified
  11081. it.
  11082. (d) I understand and agree that this project and the contribution
  11083. are public and that a record of the contribution (including all
  11084. personal information I submit with it, including my sign-off) is
  11085. maintained indefinitely and may be redistributed consistent with
  11086. this project or the open source license(s) involved.
  11087. </code></pre>
  11088. <p>If you agree to this for your contribution, then all that's needed is to
  11089. include the line in your commit or pull request comment:</p>
  11090. <pre><code>Signed-off-by: Your Name &lt;your@email.example.org&gt;
  11091. </code></pre>
  11092. <p>We accept contributions under a legally identifiable name, such as
  11093. your name on government documentation or common-law names (names
  11094. claimed by legitimate usage or repute). Unfortunately, we cannot
  11095. accept anonymous contributions at this time.</p>
  11096. <p>Git allows you to add this signoff automatically when using the <code>-s</code>
  11097. flag to <code>git commit</code>, which uses the name and email set in your
  11098. <code>user.name</code> and <code>user.email</code> git configs.</p>
  11099. <h1 id="10-turn-feedback-into-better-code"><a class="header" href="#10-turn-feedback-into-better-code">10. Turn feedback into better code.</a></h1>
  11100. <p>Once the Pull Request is opened, you will see a few things:</p>
  11101. <ol>
  11102. <li>our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;</li>
  11103. <li>one or more of the developers will take a look at your Pull Request and offer feedback.</li>
  11104. </ol>
  11105. <p>From this point, you should:</p>
  11106. <ol>
  11107. <li>Look at the results of the CI pipeline.
  11108. <ul>
  11109. <li>If there is any error, fix the error.</li>
  11110. </ul>
  11111. </li>
  11112. <li>If a developer has requested changes, make these changes and let us know if it is ready for a developer to review again.</li>
  11113. <li>Create a new commit with the changes.
  11114. <ul>
  11115. <li>Please do NOT overwrite the history. New commits make the reviewer's life easier.</li>
  11116. <li>Push this commits to your Pull Request.</li>
  11117. </ul>
  11118. </li>
  11119. <li>Back to 1.</li>
  11120. </ol>
  11121. <p>Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!</p>
  11122. <h1 id="11-find-a-new-issue"><a class="header" href="#11-find-a-new-issue">11. Find a new issue.</a></h1>
  11123. <p>By now, you know the drill!</p>
  11124. <h1 id="notes-for-maintainers-on-merging-prs-etc"><a class="header" href="#notes-for-maintainers-on-merging-prs-etc">Notes for maintainers on merging PRs etc</a></h1>
  11125. <p>There are some notes for those with commit access to the project on how we
  11126. manage git <a href="development/docs/development/git.html">here</a>.</p>
  11127. <h1 id="conclusion"><a class="header" href="#conclusion">Conclusion</a></h1>
  11128. <p>That's it! Matrix is a very open and collaborative project as you might expect
  11129. given our obsession with open communication. If we're going to successfully
  11130. matrix together all the fragmented communication technologies out there we are
  11131. reliant on contributions and collaboration from the community to do so. So
  11132. please get involved - and we hope you have as much fun hacking on Matrix as we
  11133. do!</p>
  11134. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="code-style"><a class="header" href="#code-style">Code Style</a></h1>
  11135. <h2 id="formatting-tools"><a class="header" href="#formatting-tools">Formatting tools</a></h2>
  11136. <p>The Synapse codebase uses a number of code formatting tools in order to
  11137. quickly and automatically check for formatting (and sometimes logical)
  11138. errors in code.</p>
  11139. <p>The necessary tools are detailed below.</p>
  11140. <p>First install them with:</p>
  11141. <pre><code>pip install -e &quot;.[lint,mypy]&quot;
  11142. </code></pre>
  11143. <ul>
  11144. <li>
  11145. <p><strong>black</strong></p>
  11146. <p>The Synapse codebase uses <a href="https://pypi.org/project/black/">black</a>
  11147. as an opinionated code formatter, ensuring all comitted code is
  11148. properly formatted.</p>
  11149. <p>Have <code>black</code> auto-format your code (it shouldn't change any
  11150. functionality) with:</p>
  11151. <pre><code>black . --exclude=&quot;\.tox|build|env&quot;
  11152. </code></pre>
  11153. </li>
  11154. <li>
  11155. <p><strong>flake8</strong></p>
  11156. <p><code>flake8</code> is a code checking tool. We require code to pass <code>flake8</code>
  11157. before being merged into the codebase.</p>
  11158. <p>Check all application and test code with:</p>
  11159. <pre><code>flake8 synapse tests
  11160. </code></pre>
  11161. </li>
  11162. <li>
  11163. <p><strong>isort</strong></p>
  11164. <p><code>isort</code> ensures imports are nicely formatted, and can suggest and
  11165. auto-fix issues such as double-importing.</p>
  11166. <p>Auto-fix imports with:</p>
  11167. <pre><code>isort -rc synapse tests
  11168. </code></pre>
  11169. <p><code>-rc</code> means to recursively search the given directories.</p>
  11170. </li>
  11171. </ul>
  11172. <p>It's worth noting that modern IDEs and text editors can run these tools
  11173. automatically on save. It may be worth looking into whether this
  11174. functionality is supported in your editor for a more convenient
  11175. development workflow. It is not, however, recommended to run <code>flake8</code> on
  11176. save as it takes a while and is very resource intensive.</p>
  11177. <h2 id="general-rules"><a class="header" href="#general-rules">General rules</a></h2>
  11178. <ul>
  11179. <li><strong>Naming</strong>:
  11180. <ul>
  11181. <li>Use camel case for class and type names</li>
  11182. <li>Use underscores for functions and variables.</li>
  11183. </ul>
  11184. </li>
  11185. <li><strong>Docstrings</strong>: should follow the <a href="https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings">google code
  11186. style</a>.
  11187. See the
  11188. <a href="http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html">examples</a>
  11189. in the sphinx documentation.</li>
  11190. <li><strong>Imports</strong>:
  11191. <ul>
  11192. <li>
  11193. <p>Imports should be sorted by <code>isort</code> as described above.</p>
  11194. </li>
  11195. <li>
  11196. <p>Prefer to import classes and functions rather than packages or
  11197. modules.</p>
  11198. <p>Example:</p>
  11199. <pre><code>from synapse.types import UserID
  11200. ...
  11201. user_id = UserID(local, server)
  11202. </code></pre>
  11203. <p>is preferred over:</p>
  11204. <pre><code>from synapse import types
  11205. ...
  11206. user_id = types.UserID(local, server)
  11207. </code></pre>
  11208. <p>(or any other variant).</p>
  11209. <p>This goes against the advice in the Google style guide, but it
  11210. means that errors in the name are caught early (at import time).</p>
  11211. </li>
  11212. <li>
  11213. <p>Avoid wildcard imports (<code>from synapse.types import *</code>) and
  11214. relative imports (<code>from .types import UserID</code>).</p>
  11215. </li>
  11216. </ul>
  11217. </li>
  11218. </ul>
  11219. <h2 id="configuration-file-format"><a class="header" href="#configuration-file-format">Configuration file format</a></h2>
  11220. <p>The <a href="./sample_config.yaml">sample configuration file</a> acts as a
  11221. reference to Synapse's configuration options for server administrators.
  11222. Remember that many readers will be unfamiliar with YAML and server
  11223. administration in general, so that it is important that the file be as
  11224. easy to understand as possible, which includes following a consistent
  11225. format.</p>
  11226. <p>Some guidelines follow:</p>
  11227. <ul>
  11228. <li>
  11229. <p>Sections should be separated with a heading consisting of a single
  11230. line prefixed and suffixed with <code>##</code>. There should be <strong>two</strong> blank
  11231. lines before the section header, and <strong>one</strong> after.</p>
  11232. </li>
  11233. <li>
  11234. <p>Each option should be listed in the file with the following format:</p>
  11235. <ul>
  11236. <li>
  11237. <p>A comment describing the setting. Each line of this comment
  11238. should be prefixed with a hash (<code>#</code>) and a space.</p>
  11239. <p>The comment should describe the default behaviour (ie, what
  11240. happens if the setting is omitted), as well as what the effect
  11241. will be if the setting is changed.</p>
  11242. <p>Often, the comment end with something like &quot;uncomment the
  11243. following to <do action>&quot;.</p>
  11244. </li>
  11245. <li>
  11246. <p>A line consisting of only <code>#</code>.</p>
  11247. </li>
  11248. <li>
  11249. <p>A commented-out example setting, prefixed with only <code>#</code>.</p>
  11250. <p>For boolean (on/off) options, convention is that this example
  11251. should be the <em>opposite</em> to the default (so the comment will end
  11252. with &quot;Uncomment the following to enable [or disable]
  11253. <feature>.&quot; For other options, the example should give some
  11254. non-default value which is likely to be useful to the reader.</p>
  11255. </li>
  11256. </ul>
  11257. </li>
  11258. <li>
  11259. <p>There should be a blank line between each option.</p>
  11260. </li>
  11261. <li>
  11262. <p>Where several settings are grouped into a single dict, <em>avoid</em> the
  11263. convention where the whole block is commented out, resulting in
  11264. comment lines starting <code># #</code>, as this is hard to read and confusing
  11265. to edit. Instead, leave the top-level config option uncommented, and
  11266. follow the conventions above for sub-options. Ensure that your code
  11267. correctly handles the top-level option being set to <code>None</code> (as it
  11268. will be if no sub-options are enabled).</p>
  11269. </li>
  11270. <li>
  11271. <p>Lines should be wrapped at 80 characters.</p>
  11272. </li>
  11273. <li>
  11274. <p>Use two-space indents.</p>
  11275. </li>
  11276. <li>
  11277. <p><code>true</code> and <code>false</code> are spelt thus (as opposed to <code>True</code>, etc.)</p>
  11278. </li>
  11279. <li>
  11280. <p>Use single quotes (<code>'</code>) rather than double-quotes (<code>&quot;</code>) or backticks
  11281. (<code>`</code>) to refer to configuration options.</p>
  11282. </li>
  11283. </ul>
  11284. <p>Example:</p>
  11285. <pre><code>## Frobnication ##
  11286. # The frobnicator will ensure that all requests are fully frobnicated.
  11287. # To enable it, uncomment the following.
  11288. #
  11289. #frobnicator_enabled: true
  11290. # By default, the frobnicator will frobnicate with the default frobber.
  11291. # The following will make it use an alternative frobber.
  11292. #
  11293. #frobincator_frobber: special_frobber
  11294. # Settings for the frobber
  11295. #
  11296. frobber:
  11297. # frobbing speed. Defaults to 1.
  11298. #
  11299. #speed: 10
  11300. # frobbing distance. Defaults to 1000.
  11301. #
  11302. #distance: 100
  11303. </code></pre>
  11304. <p>Note that the sample configuration is generated from the synapse code
  11305. and is maintained by a script, <code>scripts-dev/generate_sample_config</code>.
  11306. Making sure that the output from this script matches the desired format
  11307. is left as an exercise for the reader!</p>
  11308. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="some-notes-on-how-we-use-git"><a class="header" href="#some-notes-on-how-we-use-git">Some notes on how we use git</a></h1>
  11309. <h2 id="on-keeping-the-commit-history-clean"><a class="header" href="#on-keeping-the-commit-history-clean">On keeping the commit history clean</a></h2>
  11310. <p>In an ideal world, our git commit history would be a linear progression of
  11311. commits each of which contains a single change building on what came
  11312. before. Here, by way of an arbitrary example, is the top of <code>git log --graph b2dba0607</code>:</p>
  11313. <img src="development/img/git/clean.png" alt="clean git graph" width="500px">
  11314. <p>Note how the commit comment explains clearly what is changing and why. Also
  11315. note the <em>absence</em> of merge commits, as well as the absence of commits called
  11316. things like (to pick a few culprits):
  11317. <a href="https://github.com/matrix-org/synapse/commit/84691da6c">“pep8”</a>, <a href="https://github.com/matrix-org/synapse/commit/474810d9d">“fix broken
  11318. test”</a>,
  11319. <a href="https://github.com/matrix-org/synapse/commit/c9d72e457">“oops”</a>,
  11320. <a href="https://github.com/matrix-org/synapse/commit/836358823">“typo”</a>, or <a href="https://github.com/matrix-org/synapse/commit/707374d5d">“Who's
  11321. the president?”</a>.</p>
  11322. <p>There are a number of reasons why keeping a clean commit history is a good
  11323. thing:</p>
  11324. <ul>
  11325. <li>
  11326. <p>From time to time, after a change lands, it turns out to be necessary to
  11327. revert it, or to backport it to a release branch. Those operations are
  11328. <em>much</em> easier when the change is contained in a single commit.</p>
  11329. </li>
  11330. <li>
  11331. <p>Similarly, it's much easier to answer questions like “is the fix for
  11332. <code>/publicRooms</code> on the release branch?” if that change consists of a single
  11333. commit.</p>
  11334. </li>
  11335. <li>
  11336. <p>Likewise: “what has changed on this branch in the last week?” is much
  11337. clearer without merges and “pep8” commits everywhere.</p>
  11338. </li>
  11339. <li>
  11340. <p>Sometimes we need to figure out where a bug got introduced, or some
  11341. behaviour changed. One way of doing that is with <code>git bisect</code>: pick an
  11342. arbitrary commit between the known good point and the known bad point, and
  11343. see how the code behaves. However, that strategy fails if the commit you
  11344. chose is the middle of someone's epic branch in which they broke the world
  11345. before putting it back together again.</p>
  11346. </li>
  11347. </ul>
  11348. <p>One counterargument is that it is sometimes useful to see how a PR evolved as
  11349. it went through review cycles. This is true, but that information is always
  11350. available via the GitHub UI (or via the little-known <a href="https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally">refs/pull
  11351. namespace</a>).</p>
  11352. <p>Of course, in reality, things are more complicated than that. We have release
  11353. branches as well as <code>develop</code> and <code>master</code>, and we deliberately merge changes
  11354. between them. Bugs often slip through and have to be fixed later. That's all
  11355. fine: this not a cast-iron rule which must be obeyed, but an ideal to aim
  11356. towards.</p>
  11357. <h2 id="merges-squashes-rebases-wtf"><a class="header" href="#merges-squashes-rebases-wtf">Merges, squashes, rebases: wtf?</a></h2>
  11358. <p>Ok, so that's what we'd like to achieve. How do we achieve it?</p>
  11359. <p>The TL;DR is: when you come to merge a pull request, you <em>probably</em> want to
  11360. “squash and merge”:</p>
  11361. <p><img src="development/img/git/squash.png" alt="squash and merge" />.</p>
  11362. <p>(This applies whether you are merging your own PR, or that of another
  11363. contributor.)</p>
  11364. <p>“Squash and merge”<sup id="a1"><a href="development/git.html#f1">1</a></sup> takes all of the changes in the
  11365. PR, and bundles them into a single commit. GitHub gives you the opportunity to
  11366. edit the commit message before you confirm, and normally you should do so,
  11367. because the default will be useless (again: <code>* woops typo</code> is not a useful
  11368. thing to keep in the historical record).</p>
  11369. <p>The main problem with this approach comes when you have a series of pull
  11370. requests which build on top of one another: as soon as you squash-merge the
  11371. first PR, you'll end up with a stack of conflicts to resolve in all of the
  11372. others. In general, it's best to avoid this situation in the first place by
  11373. trying not to have multiple related PRs in flight at the same time. Still,
  11374. sometimes that's not possible and doing a regular merge is the lesser evil.</p>
  11375. <p>Another occasion in which a regular merge makes more sense is a PR where you've
  11376. deliberately created a series of commits each of which makes sense in its own
  11377. right. For example: <a href="https://github.com/matrix-org/synapse/pull/6837">a PR which gradually propagates a refactoring operation
  11378. through the codebase</a>, or <a href="https://github.com/matrix-org/synapse/pull/5987">a
  11379. PR which is the culmination of several other
  11380. PRs</a>. In this case the ability
  11381. to figure out when a particular change/bug was introduced could be very useful.</p>
  11382. <p>Ultimately: <strong>this is not a hard-and-fast-rule</strong>. If in doubt, ask yourself “do
  11383. each of the commits I am about to merge make sense in their own right”, but
  11384. remember that we're just doing our best to balance “keeping the commit history
  11385. clean” with other factors.</p>
  11386. <h2 id="git-branching-model"><a class="header" href="#git-branching-model">Git branching model</a></h2>
  11387. <p>A <a href="https://nvie.com/posts/a-successful-git-branching-model/">lot</a>
  11388. <a href="http://scottchacon.com/2011/08/31/github-flow.html">of</a>
  11389. <a href="https://www.endoflineblog.com/gitflow-considered-harmful">words</a> have been
  11390. written in the past about git branching models (no really, <a href="https://martinfowler.com/articles/branching-patterns.html">a
  11391. lot</a>). I tend to
  11392. think the whole thing is overblown. Fundamentally, it's not that
  11393. complicated. Here's how we do it.</p>
  11394. <p>Let's start with a picture:</p>
  11395. <p><img src="development/img/git/branches.jpg" alt="branching model" /></p>
  11396. <p>It looks complicated, but it's really not. There's one basic rule: <em>anyone</em> is
  11397. free to merge from <em>any</em> more-stable branch to <em>any</em> less-stable branch at
  11398. <em>any</em> time<sup id="a2"><a href="development/git.html#f2">2</a></sup>. (The principle behind this is that if a
  11399. change is good enough for the more-stable branch, then it's also good enough go
  11400. put in a less-stable branch.)</p>
  11401. <p>Meanwhile, merging (or squashing, as per the above) from a less-stable to a
  11402. more-stable branch is a deliberate action in which you want to publish a change
  11403. or a set of changes to (some subset of) the world: for example, this happens
  11404. when a PR is landed, or as part of our release process.</p>
  11405. <p>So, what counts as a more- or less-stable branch? A little reflection will show
  11406. that our active branches are ordered thus, from more-stable to less-stable:</p>
  11407. <ul>
  11408. <li><code>master</code> (tracks our last release).</li>
  11409. <li><code>release-vX.Y</code> (the branch where we prepare the next release)<sup
  11410. id="a3"><a href="development/git.html#f3">3</a></sup>.</li>
  11411. <li>PR branches which are targeting the release.</li>
  11412. <li><code>develop</code> (our &quot;mainline&quot; branch containing our bleeding-edge).</li>
  11413. <li>regular PR branches.</li>
  11414. </ul>
  11415. <p>The corollary is: if you have a bugfix that needs to land in both
  11416. <code>release-vX.Y</code> <em>and</em> <code>develop</code>, then you should base your PR on
  11417. <code>release-vX.Y</code>, get it merged there, and then merge from <code>release-vX.Y</code> to
  11418. <code>develop</code>. (If a fix lands in <code>develop</code> and we later need it in a
  11419. release-branch, we can of course cherry-pick it, but landing it in the release
  11420. branch first helps reduce the chance of annoying conflicts.)</p>
  11421. <hr />
  11422. <p><b id="f1">[1]</b>: “Squash and merge” is GitHub's term for this
  11423. operation. Given that there is no merge involved, I'm not convinced it's the
  11424. most intuitive name. <a href="development/git.html#a1">^</a></p>
  11425. <p><b id="f2">[2]</b>: Well, anyone with commit access.<a href="development/git.html#a2">^</a></p>
  11426. <p><b id="f3">[3]</b>: Very, very occasionally (I think this has happened once in
  11427. the history of Synapse), we've had two releases in flight at once. Obviously,
  11428. <code>release-v1.2</code> is more-stable than <code>release-v1.3</code>. <a href="development/git.html#a3">^</a></p>
  11429. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="opentracing"><a class="header" href="#opentracing">OpenTracing</a></h1>
  11430. <h2 id="background"><a class="header" href="#background">Background</a></h2>
  11431. <p>OpenTracing is a semi-standard being adopted by a number of distributed
  11432. tracing platforms. It is a common api for facilitating vendor-agnostic
  11433. tracing instrumentation. That is, we can use the OpenTracing api and
  11434. select one of a number of tracer implementations to do the heavy lifting
  11435. in the background. Our current selected implementation is Jaeger.</p>
  11436. <p>OpenTracing is a tool which gives an insight into the causal
  11437. relationship of work done in and between servers. The servers each track
  11438. events and report them to a centralised server - in Synapse's case:
  11439. Jaeger. The basic unit used to represent events is the span. The span
  11440. roughly represents a single piece of work that was done and the time at
  11441. which it occurred. A span can have child spans, meaning that the work of
  11442. the child had to be completed for the parent span to complete, or it can
  11443. have follow-on spans which represent work that is undertaken as a result
  11444. of the parent but is not depended on by the parent to in order to
  11445. finish.</p>
  11446. <p>Since this is undertaken in a distributed environment a request to
  11447. another server, such as an RPC or a simple GET, can be considered a span
  11448. (a unit or work) for the local server. This causal link is what
  11449. OpenTracing aims to capture and visualise. In order to do this metadata
  11450. about the local server's span, i.e the 'span context', needs to be
  11451. included with the request to the remote.</p>
  11452. <p>It is up to the remote server to decide what it does with the spans it
  11453. creates. This is called the sampling policy and it can be configured
  11454. through Jaeger's settings.</p>
  11455. <p>For OpenTracing concepts see
  11456. <a href="https://opentracing.io/docs/overview/what-is-tracing/">https://opentracing.io/docs/overview/what-is-tracing/</a>.</p>
  11457. <p>For more information about Jaeger's implementation see
  11458. <a href="https://www.jaegertracing.io/docs/">https://www.jaegertracing.io/docs/</a></p>
  11459. <h2 id="setting-up-opentracing"><a class="header" href="#setting-up-opentracing">Setting up OpenTracing</a></h2>
  11460. <p>To receive OpenTracing spans, start up a Jaeger server. This can be done
  11461. using docker like so:</p>
  11462. <pre><code class="language-sh">docker run -d --name jaeger \
  11463. -p 6831:6831/udp \
  11464. -p 6832:6832/udp \
  11465. -p 5778:5778 \
  11466. -p 16686:16686 \
  11467. -p 14268:14268 \
  11468. jaegertracing/all-in-one:1
  11469. </code></pre>
  11470. <p>Latest documentation is probably at
  11471. https://www.jaegertracing.io/docs/latest/getting-started.</p>
  11472. <h2 id="enable-opentracing-in-synapse"><a class="header" href="#enable-opentracing-in-synapse">Enable OpenTracing in Synapse</a></h2>
  11473. <p>OpenTracing is not enabled by default. It must be enabled in the
  11474. homeserver config by uncommenting the config options under <code>opentracing</code>
  11475. as shown in the <a href="./sample_config.yaml">sample config</a>. For example:</p>
  11476. <pre><code class="language-yaml">opentracing:
  11477. enabled: true
  11478. homeserver_whitelist:
  11479. - &quot;mytrustedhomeserver.org&quot;
  11480. - &quot;*.myotherhomeservers.com&quot;
  11481. </code></pre>
  11482. <h2 id="homeserver-whitelisting"><a class="header" href="#homeserver-whitelisting">Homeserver whitelisting</a></h2>
  11483. <p>The homeserver whitelist is configured using regular expressions. A list
  11484. of regular expressions can be given and their union will be compared
  11485. when propagating any spans contexts to another homeserver.</p>
  11486. <p>Though it's mostly safe to send and receive span contexts to and from
  11487. untrusted users since span contexts are usually opaque ids it can lead
  11488. to two problems, namely:</p>
  11489. <ul>
  11490. <li>If the span context is marked as sampled by the sending homeserver
  11491. the receiver will sample it. Therefore two homeservers with wildly
  11492. different sampling policies could incur higher sampling counts than
  11493. intended.</li>
  11494. <li>Sending servers can attach arbitrary data to spans, known as
  11495. 'baggage'. For safety this has been disabled in Synapse but that
  11496. doesn't prevent another server sending you baggage which will be
  11497. logged to OpenTracing's logs.</li>
  11498. </ul>
  11499. <h2 id="configuring-jaeger"><a class="header" href="#configuring-jaeger">Configuring Jaeger</a></h2>
  11500. <p>Sampling strategies can be set as in this document:
  11501. <a href="https://www.jaegertracing.io/docs/latest/sampling/">https://www.jaegertracing.io/docs/latest/sampling/</a>.</p>
  11502. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="synapse-database-schema-files"><a class="header" href="#synapse-database-schema-files">Synapse database schema files</a></h1>
  11503. <p>Synapse's database schema is stored in the <code>synapse.storage.schema</code> module.</p>
  11504. <h2 id="logical-databases"><a class="header" href="#logical-databases">Logical databases</a></h2>
  11505. <p>Synapse supports splitting its datastore across multiple physical databases (which can
  11506. be useful for large installations), and the schema files are therefore split according
  11507. to the logical database they apply to.</p>
  11508. <p>At the time of writing, the following &quot;logical&quot; databases are supported:</p>
  11509. <ul>
  11510. <li><code>state</code> - used to store Matrix room state (more specifically, <code>state_groups</code>,
  11511. their relationships and contents).</li>
  11512. <li><code>main</code> - stores everything else.</li>
  11513. </ul>
  11514. <p>Additionally, the <code>common</code> directory contains schema files for tables which must be
  11515. present on <em>all</em> physical databases.</p>
  11516. <h2 id="synapse-schema-versions"><a class="header" href="#synapse-schema-versions">Synapse schema versions</a></h2>
  11517. <p>Synapse manages its database schema via &quot;schema versions&quot;. These are mainly used to
  11518. help avoid confusion if the Synapse codebase is rolled back after the database is
  11519. updated. They work as follows:</p>
  11520. <ul>
  11521. <li>
  11522. <p>The Synapse codebase defines a constant <code>synapse.storage.schema.SCHEMA_VERSION</code>
  11523. which represents the expectations made about the database by that version. For
  11524. example, as of Synapse v1.36, this is <code>59</code>.</p>
  11525. </li>
  11526. <li>
  11527. <p>The database stores a &quot;compatibility version&quot; in
  11528. <code>schema_compat_version.compat_version</code> which defines the <code>SCHEMA_VERSION</code> of the
  11529. oldest version of Synapse which will work with the database. On startup, if
  11530. <code>compat_version</code> is found to be newer than <code>SCHEMA_VERSION</code>, Synapse will refuse to
  11531. start.</p>
  11532. <p>Synapse automatically updates this field from
  11533. <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code>.</p>
  11534. </li>
  11535. <li>
  11536. <p>Whenever a backwards-incompatible change is made to the database format (normally
  11537. via a <code>delta</code> file), <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code> is also updated
  11538. so that administrators can not accidentally roll back to a too-old version of Synapse.</p>
  11539. </li>
  11540. </ul>
  11541. <p>Generally, the goal is to maintain compatibility with at least one or two previous
  11542. releases of Synapse, so any substantial change tends to require multiple releases and a
  11543. bit of forward-planning to get right.</p>
  11544. <p>As a worked example: we want to remove the <code>room_stats_historical</code> table. Here is how it
  11545. might pan out.</p>
  11546. <ol>
  11547. <li>
  11548. <p>Replace any code that <em>reads</em> from <code>room_stats_historical</code> with alternative
  11549. implementations, but keep writing to it in case of rollback to an earlier version.
  11550. Also, increase <code>synapse.storage.schema.SCHEMA_VERSION</code>. In this
  11551. instance, there is no existing code which reads from <code>room_stats_historical</code>, so
  11552. our starting point is:</p>
  11553. <p>v1.36.0: <code>SCHEMA_VERSION=59</code>, <code>SCHEMA_COMPAT_VERSION=59</code></p>
  11554. </li>
  11555. <li>
  11556. <p>Next (say in Synapse v1.37.0): remove the code that <em>writes</em> to
  11557. <code>room_stats_historical</code>, but don’t yet remove the table in case of rollback to
  11558. v1.36.0. Again, we increase <code>synapse.storage.schema.SCHEMA_VERSION</code>, but
  11559. because we have not broken compatibility with v1.36, we do not yet update
  11560. <code>SCHEMA_COMPAT_VERSION</code>. We now have:</p>
  11561. <p>v1.37.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=59</code>.</p>
  11562. </li>
  11563. <li>
  11564. <p>Later (say in Synapse v1.38.0): we can remove the table altogether. This will
  11565. break compatibility with v1.36.0, so we must update <code>SCHEMA_COMPAT_VERSION</code> accordingly.
  11566. There is no need to update <code>synapse.storage.schema.SCHEMA_VERSION</code>, since there is no
  11567. change to the Synapse codebase here. So we end up with:</p>
  11568. <p>v1.38.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=60</code>.</p>
  11569. </li>
  11570. </ol>
  11571. <p>If in doubt about whether to update <code>SCHEMA_VERSION</code> or not, it is generally best to
  11572. lean towards doing so.</p>
  11573. <h2 id="full-schema-dumps"><a class="header" href="#full-schema-dumps">Full schema dumps</a></h2>
  11574. <p>In the <code>full_schemas</code> directories, only the most recently-numbered snapshot is used
  11575. (<code>54</code> at the time of writing). Older snapshots (eg, <code>16</code>) are present for historical
  11576. reference only.</p>
  11577. <h3 id="building-full-schema-dumps"><a class="header" href="#building-full-schema-dumps">Building full schema dumps</a></h3>
  11578. <p>If you want to recreate these schemas, they need to be made from a database that
  11579. has had all background updates run.</p>
  11580. <p>To do so, use <code>scripts-dev/make_full_schema.sh</code>. This will produce new
  11581. <code>full.sql.postgres</code> and <code>full.sql.sqlite</code> files.</p>
  11582. <p>Ensure postgres is installed, then run:</p>
  11583. <pre><code>./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
  11584. </code></pre>
  11585. <p>NB at the time of writing, this script predates the split into separate <code>state</code>/<code>main</code>
  11586. databases so will require updates to handle that correctly.</p>
  11587. <h2 id="boolean-columns"><a class="header" href="#boolean-columns">Boolean columns</a></h2>
  11588. <p>Boolean columns require special treatment, since SQLite treats booleans the
  11589. same as integers.</p>
  11590. <p>There are three separate aspects to this:</p>
  11591. <ul>
  11592. <li>
  11593. <p>Any new boolean column must be added to the <code>BOOLEAN_COLUMNS</code> list in
  11594. <code>scripts/synapse_port_db</code>. This tells the port script to cast the integer
  11595. value from SQLite to a boolean before writing the value to the postgres
  11596. database.</p>
  11597. </li>
  11598. <li>
  11599. <p>Before SQLite 3.23, <code>TRUE</code> and <code>FALSE</code> were not recognised as constants by
  11600. SQLite, and the <code>IS [NOT] TRUE</code>/<code>IS [NOT] FALSE</code> operators were not
  11601. supported. This makes it necessary to avoid using <code>TRUE</code> and <code>FALSE</code>
  11602. constants in SQL commands.</p>
  11603. <p>For example, to insert a <code>TRUE</code> value into the database, write:</p>
  11604. <pre><code class="language-python">txn.execute(&quot;INSERT INTO tbl(col) VALUES (?)&quot;, (True, ))
  11605. </code></pre>
  11606. </li>
  11607. <li>
  11608. <p>Default values for new boolean columns present a particular
  11609. difficulty. Generally it is best to create separate schema files for
  11610. Postgres and SQLite. For example:</p>
  11611. <pre><code class="language-sql"># in 00delta.sql.postgres:
  11612. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT FALSE;
  11613. </code></pre>
  11614. <pre><code class="language-sql"># in 00delta.sql.sqlite:
  11615. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT 0;
  11616. </code></pre>
  11617. <p>Note that there is a particularly insidious failure mode here: the Postgres
  11618. flavour will be accepted by SQLite 3.22, but will give a column whose
  11619. default value is the <strong>string</strong> <code>&quot;FALSE&quot;</code> - which, when cast back to a boolean
  11620. in Python, evaluates to <code>True</code>.</p>
  11621. </li>
  11622. </ul>
  11623. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="log-contexts"><a class="header" href="#log-contexts">Log Contexts</a></h1>
  11624. <p>To help track the processing of individual requests, synapse uses a
  11625. '<code>log context</code>' to track which request it is handling at any given
  11626. moment. This is done via a thread-local variable; a <code>logging.Filter</code> is
  11627. then used to fish the information back out of the thread-local variable
  11628. and add it to each log record.</p>
  11629. <p>Logcontexts are also used for CPU and database accounting, so that we
  11630. can track which requests were responsible for high CPU use or database
  11631. activity.</p>
  11632. <p>The <code>synapse.logging.context</code> module provides a facilities for managing
  11633. the current log context (as well as providing the <code>LoggingContextFilter</code>
  11634. class).</p>
  11635. <p>Asynchronous functions make the whole thing complicated, so this document describes
  11636. how it all works, and how to write code which follows the rules.</p>
  11637. <p>In this document, &quot;awaitable&quot; refers to any object which can be <code>await</code>ed. In the context of
  11638. Synapse, that normally means either a coroutine or a Twisted
  11639. <a href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html"><code>Deferred</code></a>.</p>
  11640. <h2 id="logcontexts-without-asynchronous-code"><a class="header" href="#logcontexts-without-asynchronous-code">Logcontexts without asynchronous code</a></h2>
  11641. <p>In the absence of any asynchronous voodoo, things are simple enough. As with
  11642. any code of this nature, the rule is that our function should leave
  11643. things as it found them:</p>
  11644. <pre><code class="language-python">from synapse.logging import context # omitted from future snippets
  11645. def handle_request(request_id):
  11646. request_context = context.LoggingContext()
  11647. calling_context = context.set_current_context(request_context)
  11648. try:
  11649. request_context.request = request_id
  11650. do_request_handling()
  11651. logger.debug(&quot;finished&quot;)
  11652. finally:
  11653. context.set_current_context(calling_context)
  11654. def do_request_handling():
  11655. logger.debug(&quot;phew&quot;) # this will be logged against request_id
  11656. </code></pre>
  11657. <p>LoggingContext implements the context management methods, so the above
  11658. can be written much more succinctly as:</p>
  11659. <pre><code class="language-python">def handle_request(request_id):
  11660. with context.LoggingContext() as request_context:
  11661. request_context.request = request_id
  11662. do_request_handling()
  11663. logger.debug(&quot;finished&quot;)
  11664. def do_request_handling():
  11665. logger.debug(&quot;phew&quot;)
  11666. </code></pre>
  11667. <h2 id="using-logcontexts-with-awaitables"><a class="header" href="#using-logcontexts-with-awaitables">Using logcontexts with awaitables</a></h2>
  11668. <p>Awaitables break the linear flow of code so that there is no longer a single entry point
  11669. where we should set the logcontext and a single exit point where we should remove it.</p>
  11670. <p>Consider the example above, where <code>do_request_handling</code> needs to do some
  11671. blocking operation, and returns an awaitable:</p>
  11672. <pre><code class="language-python">async def handle_request(request_id):
  11673. with context.LoggingContext() as request_context:
  11674. request_context.request = request_id
  11675. await do_request_handling()
  11676. logger.debug(&quot;finished&quot;)
  11677. </code></pre>
  11678. <p>In the above flow:</p>
  11679. <ul>
  11680. <li>The logcontext is set</li>
  11681. <li><code>do_request_handling</code> is called, and returns an awaitable</li>
  11682. <li><code>handle_request</code> awaits the awaitable</li>
  11683. <li>Execution of <code>handle_request</code> is suspended</li>
  11684. </ul>
  11685. <p>So we have stopped processing the request (and will probably go on to
  11686. start processing the next), without clearing the logcontext.</p>
  11687. <p>To circumvent this problem, synapse code assumes that, wherever you have
  11688. an awaitable, you will want to <code>await</code> it. To that end, whereever
  11689. functions return awaitables, we adopt the following conventions:</p>
  11690. <p><strong>Rules for functions returning awaitables:</strong></p>
  11691. <blockquote>
  11692. <ul>
  11693. <li>If the awaitable is already complete, the function returns with the
  11694. same logcontext it started with.</li>
  11695. <li>If the awaitable is incomplete, the function clears the logcontext
  11696. before returning; when the awaitable completes, it restores the
  11697. logcontext before running any callbacks.</li>
  11698. </ul>
  11699. </blockquote>
  11700. <p>That sounds complicated, but actually it means a lot of code (including
  11701. the example above) &quot;just works&quot;. There are two cases:</p>
  11702. <ul>
  11703. <li>
  11704. <p>If <code>do_request_handling</code> returns a completed awaitable, then the
  11705. logcontext will still be in place. In this case, execution will
  11706. continue immediately after the <code>await</code>; the &quot;finished&quot; line will
  11707. be logged against the right context, and the <code>with</code> block restores
  11708. the original context before we return to the caller.</p>
  11709. </li>
  11710. <li>
  11711. <p>If the returned awaitable is incomplete, <code>do_request_handling</code> clears
  11712. the logcontext before returning. The logcontext is therefore clear
  11713. when <code>handle_request</code> <code>await</code>s the awaitable.</p>
  11714. <p>Once <code>do_request_handling</code>'s awaitable completes, it will reinstate
  11715. the logcontext, before running the second half of <code>handle_request</code>,
  11716. so again the &quot;finished&quot; line will be logged against the right context,
  11717. and the <code>with</code> block restores the original context.</p>
  11718. </li>
  11719. </ul>
  11720. <p>As an aside, it's worth noting that <code>handle_request</code> follows our rules</p>
  11721. <ul>
  11722. <li>though that only matters if the caller has its own logcontext which it
  11723. cares about.</li>
  11724. </ul>
  11725. <p>The following sections describe pitfalls and helpful patterns when
  11726. implementing these rules.</p>
  11727. <h2 id="always-await-your-awaitables"><a class="header" href="#always-await-your-awaitables">Always await your awaitables</a></h2>
  11728. <p>Whenever you get an awaitable back from a function, you should <code>await</code> on
  11729. it as soon as possible. Do not pass go; do not do any logging; do not
  11730. call any other functions.</p>
  11731. <pre><code class="language-python">async def fun():
  11732. logger.debug(&quot;starting&quot;)
  11733. await do_some_stuff() # just like this
  11734. coro = more_stuff()
  11735. result = await coro # also fine, of course
  11736. return result
  11737. </code></pre>
  11738. <p>Provided this pattern is followed all the way back up to the callchain
  11739. to where the logcontext was set, this will make things work out ok:
  11740. provided <code>do_some_stuff</code> and <code>more_stuff</code> follow the rules above, then
  11741. so will <code>fun</code>.</p>
  11742. <p>It's all too easy to forget to <code>await</code>: for instance if we forgot that
  11743. <code>do_some_stuff</code> returned an awaitable, we might plough on regardless. This
  11744. leads to a mess; it will probably work itself out eventually, but not
  11745. before a load of stuff has been logged against the wrong context.
  11746. (Normally, other things will break, more obviously, if you forget to
  11747. <code>await</code>, so this tends not to be a major problem in practice.)</p>
  11748. <p>Of course sometimes you need to do something a bit fancier with your
  11749. awaitable - not all code follows the linear A-then-B-then-C pattern.
  11750. Notes on implementing more complex patterns are in later sections.</p>
  11751. <h2 id="where-you-create-a-new-awaitable-make-it-follow-the-rules"><a class="header" href="#where-you-create-a-new-awaitable-make-it-follow-the-rules">Where you create a new awaitable, make it follow the rules</a></h2>
  11752. <p>Most of the time, an awaitable comes from another synapse function.
  11753. Sometimes, though, we need to make up a new awaitable, or we get an awaitable
  11754. back from external code. We need to make it follow our rules.</p>
  11755. <p>The easy way to do it is by using <code>context.make_deferred_yieldable</code>. Suppose we want to implement
  11756. <code>sleep</code>, which returns a deferred which will run its callbacks after a
  11757. given number of seconds. That might look like:</p>
  11758. <pre><code class="language-python"># not a logcontext-rules-compliant function
  11759. def get_sleep_deferred(seconds):
  11760. d = defer.Deferred()
  11761. reactor.callLater(seconds, d.callback, None)
  11762. return d
  11763. </code></pre>
  11764. <p>That doesn't follow the rules, but we can fix it by calling it through
  11765. <code>context.make_deferred_yieldable</code>:</p>
  11766. <pre><code class="language-python">async def sleep(seconds):
  11767. return await context.make_deferred_yieldable(get_sleep_deferred(seconds))
  11768. </code></pre>
  11769. <h2 id="fire-and-forget"><a class="header" href="#fire-and-forget">Fire-and-forget</a></h2>
  11770. <p>Sometimes you want to fire off a chain of execution, but not wait for
  11771. its result. That might look a bit like this:</p>
  11772. <pre><code class="language-python">async def do_request_handling():
  11773. await foreground_operation()
  11774. # *don't* do this
  11775. background_operation()
  11776. logger.debug(&quot;Request handling complete&quot;)
  11777. async def background_operation():
  11778. await first_background_step()
  11779. logger.debug(&quot;Completed first step&quot;)
  11780. await second_background_step()
  11781. logger.debug(&quot;Completed second step&quot;)
  11782. </code></pre>
  11783. <p>The above code does a couple of steps in the background after
  11784. <code>do_request_handling</code> has finished. The log lines are still logged
  11785. against the <code>request_context</code> logcontext, which may or may not be
  11786. desirable. There are two big problems with the above, however. The first
  11787. problem is that, if <code>background_operation</code> returns an incomplete
  11788. awaitable, it will expect its caller to <code>await</code> immediately, so will have
  11789. cleared the logcontext. In this example, that means that 'Request
  11790. handling complete' will be logged without any context.</p>
  11791. <p>The second problem, which is potentially even worse, is that when the
  11792. awaitable returned by <code>background_operation</code> completes, it will restore
  11793. the original logcontext. There is nothing waiting on that awaitable, so
  11794. the logcontext will leak into the reactor and possibly get attached to
  11795. some arbitrary future operation.</p>
  11796. <p>There are two potential solutions to this.</p>
  11797. <p>One option is to surround the call to <code>background_operation</code> with a
  11798. <code>PreserveLoggingContext</code> call. That will reset the logcontext before
  11799. starting <code>background_operation</code> (so the context restored when the
  11800. deferred completes will be the empty logcontext), and will restore the
  11801. current logcontext before continuing the foreground process:</p>
  11802. <pre><code class="language-python">async def do_request_handling():
  11803. await foreground_operation()
  11804. # start background_operation off in the empty logcontext, to
  11805. # avoid leaking the current context into the reactor.
  11806. with PreserveLoggingContext():
  11807. background_operation()
  11808. # this will now be logged against the request context
  11809. logger.debug(&quot;Request handling complete&quot;)
  11810. </code></pre>
  11811. <p>Obviously that option means that the operations done in
  11812. <code>background_operation</code> would be not be logged against a logcontext
  11813. (though that might be fixed by setting a different logcontext via a
  11814. <code>with LoggingContext(...)</code> in <code>background_operation</code>).</p>
  11815. <p>The second option is to use <code>context.run_in_background</code>, which wraps a
  11816. function so that it doesn't reset the logcontext even when it returns
  11817. an incomplete awaitable, and adds a callback to the returned awaitable to
  11818. reset the logcontext. In other words, it turns a function that follows
  11819. the Synapse rules about logcontexts and awaitables into one which behaves
  11820. more like an external function --- the opposite operation to that
  11821. described in the previous section. It can be used like this:</p>
  11822. <pre><code class="language-python">async def do_request_handling():
  11823. await foreground_operation()
  11824. context.run_in_background(background_operation)
  11825. # this will now be logged against the request context
  11826. logger.debug(&quot;Request handling complete&quot;)
  11827. </code></pre>
  11828. <h2 id="passing-synapse-deferreds-into-third-party-functions"><a class="header" href="#passing-synapse-deferreds-into-third-party-functions">Passing synapse deferreds into third-party functions</a></h2>
  11829. <p>A typical example of this is where we want to collect together two or
  11830. more awaitables via <code>defer.gatherResults</code>:</p>
  11831. <pre><code class="language-python">a1 = operation1()
  11832. a2 = operation2()
  11833. a3 = defer.gatherResults([a1, a2])
  11834. </code></pre>
  11835. <p>This is really a variation of the fire-and-forget problem above, in that
  11836. we are firing off <code>a1</code> and <code>a2</code> without awaiting on them. The difference
  11837. is that we now have third-party code attached to their callbacks. Anyway
  11838. either technique given in the <a href="log_contexts.html#fire-and-forget">Fire-and-forget</a>
  11839. section will work.</p>
  11840. <p>Of course, the new awaitable returned by <code>gather</code> needs to be
  11841. wrapped in order to make it follow the logcontext rules before we can
  11842. yield it, as described in <a href="log_contexts.html#where-you-create-a-new-awaitable-make-it-follow-the-rules">Where you create a new awaitable, make it
  11843. follow the
  11844. rules</a>.</p>
  11845. <p>So, option one: reset the logcontext before starting the operations to
  11846. be gathered:</p>
  11847. <pre><code class="language-python">async def do_request_handling():
  11848. with PreserveLoggingContext():
  11849. a1 = operation1()
  11850. a2 = operation2()
  11851. result = await defer.gatherResults([a1, a2])
  11852. </code></pre>
  11853. <p>In this case particularly, though, option two, of using
  11854. <code>context.run_in_background</code> almost certainly makes more sense, so that
  11855. <code>operation1</code> and <code>operation2</code> are both logged against the original
  11856. logcontext. This looks like:</p>
  11857. <pre><code class="language-python">async def do_request_handling():
  11858. a1 = context.run_in_background(operation1)
  11859. a2 = context.run_in_background(operation2)
  11860. result = await make_deferred_yieldable(defer.gatherResults([a1, a2]))
  11861. </code></pre>
  11862. <h2 id="a-note-on-garbage-collection-of-awaitable-chains"><a class="header" href="#a-note-on-garbage-collection-of-awaitable-chains">A note on garbage-collection of awaitable chains</a></h2>
  11863. <p>It turns out that our logcontext rules do not play nicely with awaitable
  11864. chains which get orphaned and garbage-collected.</p>
  11865. <p>Imagine we have some code that looks like this:</p>
  11866. <pre><code class="language-python">listener_queue = []
  11867. def on_something_interesting():
  11868. for d in listener_queue:
  11869. d.callback(&quot;foo&quot;)
  11870. async def await_something_interesting():
  11871. new_awaitable = defer.Deferred()
  11872. listener_queue.append(new_awaitable)
  11873. with PreserveLoggingContext():
  11874. await new_awaitable
  11875. </code></pre>
  11876. <p>Obviously, the idea here is that we have a bunch of things which are
  11877. waiting for an event. (It's just an example of the problem here, but a
  11878. relatively common one.)</p>
  11879. <p>Now let's imagine two further things happen. First of all, whatever was
  11880. waiting for the interesting thing goes away. (Perhaps the request times
  11881. out, or something <em>even more</em> interesting happens.)</p>
  11882. <p>Secondly, let's suppose that we decide that the interesting thing is
  11883. never going to happen, and we reset the listener queue:</p>
  11884. <pre><code class="language-python">def reset_listener_queue():
  11885. listener_queue.clear()
  11886. </code></pre>
  11887. <p>So, both ends of the awaitable chain have now dropped their references,
  11888. and the awaitable chain is now orphaned, and will be garbage-collected at
  11889. some point. Note that <code>await_something_interesting</code> is a coroutine,
  11890. which Python implements as a generator function. When Python
  11891. garbage-collects generator functions, it gives them a chance to
  11892. clean up by making the <code>async</code> (or <code>yield</code>) raise a <code>GeneratorExit</code>
  11893. exception. In our case, that means that the <code>__exit__</code> handler of
  11894. <code>PreserveLoggingContext</code> will carefully restore the request context, but
  11895. there is now nothing waiting for its return, so the request context is
  11896. never cleared.</p>
  11897. <p>To reiterate, this problem only arises when <em>both</em> ends of a awaitable
  11898. chain are dropped. Dropping the the reference to an awaitable you're
  11899. supposed to be awaiting is bad practice, so this doesn't
  11900. actually happen too much. Unfortunately, when it does happen, it will
  11901. lead to leaked logcontexts which are incredibly hard to track down.</p>
  11902. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="replication-architecture"><a class="header" href="#replication-architecture">Replication Architecture</a></h1>
  11903. <h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
  11904. <p>We'd like to be able to split some of the work that synapse does into
  11905. multiple python processes. In theory multiple synapse processes could
  11906. share a single postgresql database and we'd scale up by running more
  11907. synapse processes. However much of synapse assumes that only one process
  11908. is interacting with the database, both for assigning unique identifiers
  11909. when inserting into tables, notifying components about new updates, and
  11910. for invalidating its caches.</p>
  11911. <p>So running multiple copies of the current code isn't an option. One way
  11912. to run multiple processes would be to have a single writer process and
  11913. multiple reader processes connected to the same database. In order to do
  11914. this we'd need a way for the reader process to invalidate its in-memory
  11915. caches when an update happens on the writer. One way to do this is for
  11916. the writer to present an append-only log of updates which the readers
  11917. can consume to invalidate their caches and to push updates to listening
  11918. clients or pushers.</p>
  11919. <p>Synapse already stores much of its data as an append-only log so that it
  11920. can correctly respond to <code>/sync</code> requests so the amount of code changes
  11921. needed to expose the append-only log to the readers should be fairly
  11922. minimal.</p>
  11923. <h2 id="architecture"><a class="header" href="#architecture">Architecture</a></h2>
  11924. <h3 id="the-replication-protocol"><a class="header" href="#the-replication-protocol">The Replication Protocol</a></h3>
  11925. <p>See <a href="tcp_replication.html">the TCP replication documentation</a>.</p>
  11926. <h3 id="the-slaved-datastore"><a class="header" href="#the-slaved-datastore">The Slaved DataStore</a></h3>
  11927. <p>There are read-only version of the synapse storage layer in
  11928. <code>synapse/replication/slave/storage</code> that use the response of the
  11929. replication API to invalidate their caches.</p>
  11930. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="tcp-replication"><a class="header" href="#tcp-replication">TCP Replication</a></h1>
  11931. <h2 id="motivation-1"><a class="header" href="#motivation-1">Motivation</a></h2>
  11932. <p>Previously the workers used an HTTP long poll mechanism to get updates
  11933. from the master, which had the problem of causing a lot of duplicate
  11934. work on the server. This TCP protocol replaces those APIs with the aim
  11935. of increased efficiency.</p>
  11936. <h2 id="overview-3"><a class="header" href="#overview-3">Overview</a></h2>
  11937. <p>The protocol is based on fire and forget, line based commands. An
  11938. example flow would be (where '&gt;' indicates master to worker and
  11939. '&lt;' worker to master flows):</p>
  11940. <pre><code>&gt; SERVER example.com
  11941. &lt; REPLICATE
  11942. &gt; POSITION events master 53 53
  11943. &gt; RDATA events master 54 [&quot;$foo1:bar.com&quot;, ...]
  11944. &gt; RDATA events master 55 [&quot;$foo4:bar.com&quot;, ...]
  11945. </code></pre>
  11946. <p>The example shows the server accepting a new connection and sending its identity
  11947. with the <code>SERVER</code> command, followed by the client server to respond with the
  11948. position of all streams. The server then periodically sends <code>RDATA</code> commands
  11949. which have the format <code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row&gt;</code>, where
  11950. the format of <code>&lt;row&gt;</code> is defined by the individual streams. The
  11951. <code>&lt;instance_name&gt;</code> is the name of the Synapse process that generated the data
  11952. (usually &quot;master&quot;).</p>
  11953. <p>Error reporting happens by either the client or server sending an ERROR
  11954. command, and usually the connection will be closed.</p>
  11955. <p>Since the protocol is a simple line based, its possible to manually
  11956. connect to the server using a tool like netcat. A few things should be
  11957. noted when manually using the protocol:</p>
  11958. <ul>
  11959. <li>The federation stream is only available if federation sending has
  11960. been disabled on the main process.</li>
  11961. <li>The server will only time connections out that have sent a <code>PING</code>
  11962. command. If a ping is sent then the connection will be closed if no
  11963. further commands are receieved within 15s. Both the client and
  11964. server protocol implementations will send an initial PING on
  11965. connection and ensure at least one command every 5s is sent (not
  11966. necessarily <code>PING</code>).</li>
  11967. <li><code>RDATA</code> commands <em>usually</em> include a numeric token, however if the
  11968. stream has multiple rows to replicate per token the server will send
  11969. multiple <code>RDATA</code> commands, with all but the last having a token of
  11970. <code>batch</code>. See the documentation on <code>commands.RdataCommand</code> for
  11971. further details.</li>
  11972. </ul>
  11973. <h2 id="architecture-1"><a class="header" href="#architecture-1">Architecture</a></h2>
  11974. <p>The basic structure of the protocol is line based, where the initial
  11975. word of each line specifies the command. The rest of the line is parsed
  11976. based on the command. For example, the RDATA command is defined as:</p>
  11977. <pre><code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row_json&gt;
  11978. </code></pre>
  11979. <p>(Note that &lt;row_json&gt; may contains spaces, but cannot contain
  11980. newlines.)</p>
  11981. <p>Blank lines are ignored.</p>
  11982. <h3 id="keep-alives"><a class="header" href="#keep-alives">Keep alives</a></h3>
  11983. <p>Both sides are expected to send at least one command every 5s or so, and
  11984. should send a <code>PING</code> command if necessary. If either side do not receive
  11985. a command within e.g. 15s then the connection should be closed.</p>
  11986. <p>Because the server may be connected to manually using e.g. netcat, the
  11987. timeouts aren't enabled until an initial <code>PING</code> command is seen. Both
  11988. the client and server implementations below send a <code>PING</code> command
  11989. immediately on connection to ensure the timeouts are enabled.</p>
  11990. <p>This ensures that both sides can quickly realize if the tcp connection
  11991. has gone and handle the situation appropriately.</p>
  11992. <h3 id="start-up"><a class="header" href="#start-up">Start up</a></h3>
  11993. <p>When a new connection is made, the server:</p>
  11994. <ul>
  11995. <li>Sends a <code>SERVER</code> command, which includes the identity of the server,
  11996. allowing the client to detect if its connected to the expected
  11997. server</li>
  11998. <li>Sends a <code>PING</code> command as above, to enable the client to time out
  11999. connections promptly.</li>
  12000. </ul>
  12001. <p>The client:</p>
  12002. <ul>
  12003. <li>Sends a <code>NAME</code> command, allowing the server to associate a human
  12004. friendly name with the connection. This is optional.</li>
  12005. <li>Sends a <code>PING</code> as above</li>
  12006. <li>Sends a <code>REPLICATE</code> to get the current position of all streams.</li>
  12007. <li>On receipt of a <code>SERVER</code> command, checks that the server name
  12008. matches the expected server name.</li>
  12009. </ul>
  12010. <h3 id="error-handling"><a class="header" href="#error-handling">Error handling</a></h3>
  12011. <p>If either side detects an error it can send an <code>ERROR</code> command and close
  12012. the connection.</p>
  12013. <p>If the client side loses the connection to the server it should
  12014. reconnect, following the steps above.</p>
  12015. <h3 id="congestion"><a class="header" href="#congestion">Congestion</a></h3>
  12016. <p>If the server sends messages faster than the client can consume them the
  12017. server will first buffer a (fairly large) number of commands and then
  12018. disconnect the client. This ensures that we don't queue up an unbounded
  12019. number of commands in memory and gives us a potential oppurtunity to
  12020. squawk loudly. When/if the client recovers it can reconnect to the
  12021. server and ask for missed messages.</p>
  12022. <h3 id="reliability"><a class="header" href="#reliability">Reliability</a></h3>
  12023. <p>In general the replication stream should be considered an unreliable
  12024. transport since e.g. commands are not resent if the connection
  12025. disappears.</p>
  12026. <p>The exception to that are the replication streams, i.e. RDATA commands,
  12027. since these include tokens which can be used to restart the stream on
  12028. connection errors.</p>
  12029. <p>The client should keep track of the token in the last RDATA command
  12030. received for each stream so that on reconneciton it can start streaming
  12031. from the correct place. Note: not all RDATA have valid tokens due to
  12032. batching. See <code>RdataCommand</code> for more details.</p>
  12033. <h3 id="example-5"><a class="header" href="#example-5">Example</a></h3>
  12034. <p>An example iteraction is shown below. Each line is prefixed with '&gt;'
  12035. or '&lt;' to indicate which side is sending, these are <em>not</em> included on
  12036. the wire:</p>
  12037. <pre><code>* connection established *
  12038. &gt; SERVER localhost:8823
  12039. &gt; PING 1490197665618
  12040. &lt; NAME synapse.app.appservice
  12041. &lt; PING 1490197665618
  12042. &lt; REPLICATE
  12043. &gt; POSITION events master 1 1
  12044. &gt; POSITION backfill master 1 1
  12045. &gt; POSITION caches master 1 1
  12046. &gt; RDATA caches master 2 [&quot;get_user_by_id&quot;,[&quot;@01register-user:localhost:8823&quot;],1490197670513]
  12047. &gt; RDATA events master 14 [&quot;$149019767112vOHxz:localhost:8823&quot;,
  12048. &quot;!AFDCvgApUmpdfVjIXm:localhost:8823&quot;,&quot;m.room.guest_access&quot;,&quot;&quot;,null]
  12049. &lt; PING 1490197675618
  12050. &gt; ERROR server stopping
  12051. * connection closed by server *
  12052. </code></pre>
  12053. <p>The <code>POSITION</code> command sent by the server is used to set the clients
  12054. position without needing to send data with the <code>RDATA</code> command.</p>
  12055. <p>An example of a batched set of <code>RDATA</code> is:</p>
  12056. <pre><code>&gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test:localhost:8823&quot;],1490197670513]
  12057. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test2:localhost:8823&quot;],1490197670513]
  12058. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test3:localhost:8823&quot;],1490197670513]
  12059. &gt; RDATA caches master 54 [&quot;get_user_by_id&quot;,[&quot;@test4:localhost:8823&quot;],1490197670513]
  12060. </code></pre>
  12061. <p>In this case the client shouldn't advance their caches token until it
  12062. sees the the last <code>RDATA</code>.</p>
  12063. <h3 id="list-of-commands"><a class="header" href="#list-of-commands">List of commands</a></h3>
  12064. <p>The list of valid commands, with which side can send it: server (S) or
  12065. client (C):</p>
  12066. <h4 id="server-s"><a class="header" href="#server-s">SERVER (S)</a></h4>
  12067. <p>Sent at the start to identify which server the client is talking to</p>
  12068. <h4 id="rdata-s"><a class="header" href="#rdata-s">RDATA (S)</a></h4>
  12069. <p>A single update in a stream</p>
  12070. <h4 id="position-s"><a class="header" href="#position-s">POSITION (S)</a></h4>
  12071. <p>On receipt of a POSITION command clients should check if they have missed any
  12072. updates, and if so then fetch them out of band. Sent in response to a
  12073. REPLICATE command (but can happen at any time).</p>
  12074. <p>The POSITION command includes the source of the stream. Currently all streams
  12075. are written by a single process (usually &quot;master&quot;). If fetching missing
  12076. updates via HTTP API, rather than via the DB, then processes should make the
  12077. request to the appropriate process.</p>
  12078. <p>Two positions are included, the &quot;new&quot; position and the last position sent respectively.
  12079. This allows servers to tell instances that the positions have advanced but no
  12080. data has been written, without clients needlessly checking to see if they
  12081. have missed any updates.</p>
  12082. <h4 id="error-s-c"><a class="header" href="#error-s-c">ERROR (S, C)</a></h4>
  12083. <p>There was an error</p>
  12084. <h4 id="ping-s-c"><a class="header" href="#ping-s-c">PING (S, C)</a></h4>
  12085. <p>Sent periodically to ensure the connection is still alive</p>
  12086. <h4 id="name-c"><a class="header" href="#name-c">NAME (C)</a></h4>
  12087. <p>Sent at the start by client to inform the server who they are</p>
  12088. <h4 id="replicate-c"><a class="header" href="#replicate-c">REPLICATE (C)</a></h4>
  12089. <p>Asks the server for the current position of all streams.</p>
  12090. <h4 id="user_sync-c"><a class="header" href="#user_sync-c">USER_SYNC (C)</a></h4>
  12091. <p>A user has started or stopped syncing on this process.</p>
  12092. <h4 id="clear_user_sync-c"><a class="header" href="#clear_user_sync-c">CLEAR_USER_SYNC (C)</a></h4>
  12093. <p>The server should clear all associated user sync data from the worker.</p>
  12094. <p>This is used when a worker is shutting down.</p>
  12095. <h4 id="federation_ack-c"><a class="header" href="#federation_ack-c">FEDERATION_ACK (C)</a></h4>
  12096. <p>Acknowledge receipt of some federation data</p>
  12097. <h3 id="remote_server_up-s-c"><a class="header" href="#remote_server_up-s-c">REMOTE_SERVER_UP (S, C)</a></h3>
  12098. <p>Inform other processes that a remote server may have come back online.</p>
  12099. <p>See <code>synapse/replication/tcp/commands.py</code> for a detailed description and
  12100. the format of each command.</p>
  12101. <h3 id="cache-invalidation-stream"><a class="header" href="#cache-invalidation-stream">Cache Invalidation Stream</a></h3>
  12102. <p>The cache invalidation stream is used to inform workers when they need
  12103. to invalidate any of their caches in the data store. This is done by
  12104. streaming all cache invalidations done on master down to the workers,
  12105. assuming that any caches on the workers also exist on the master.</p>
  12106. <p>Each individual cache invalidation results in a row being sent down
  12107. replication, which includes the cache name (the name of the function)
  12108. and they key to invalidate. For example:</p>
  12109. <pre><code>&gt; RDATA caches master 550953771 [&quot;get_user_by_id&quot;, [&quot;@bob:example.com&quot;], 1550574873251]
  12110. </code></pre>
  12111. <p>Alternatively, an entire cache can be invalidated by sending down a <code>null</code>
  12112. instead of the key. For example:</p>
  12113. <pre><code>&gt; RDATA caches master 550953772 [&quot;get_user_by_id&quot;, null, 1550574873252]
  12114. </code></pre>
  12115. <p>However, there are times when a number of caches need to be invalidated
  12116. at the same time with the same key. To reduce traffic we batch those
  12117. invalidations into a single poke by defining a special cache name that
  12118. workers understand to mean to expand to invalidate the correct caches.</p>
  12119. <p>Currently the special cache names are declared in
  12120. <code>synapse/storage/_base.py</code> and are:</p>
  12121. <ol>
  12122. <li><code>cs_cache_fake</code> ─ invalidates caches that depend on the current
  12123. state</li>
  12124. </ol>
  12125. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="internal-documentation"><a class="header" href="#internal-documentation">Internal Documentation</a></h1>
  12126. <p>This section covers implementation documentation for various parts of Synapse.</p>
  12127. <p>If a developer is planning to make a change to a feature of Synapse, it can be useful for
  12128. general documentation of how that feature is implemented to be available. This saves the
  12129. developer time in place of needing to understand how the feature works by reading the
  12130. code.</p>
  12131. <p>Documentation that would be more useful for the perspective of a system administrator,
  12132. rather than a developer who's intending to change to code, should instead be placed
  12133. under the Usage section of the documentation.</p>
  12134. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-saml-as-a-developer-without-a-server"><a class="header" href="#how-to-test-saml-as-a-developer-without-a-server">How to test SAML as a developer without a server</a></h1>
  12135. <p>https://capriza.github.io/samling/samling.html (https://github.com/capriza/samling) is a great
  12136. resource for being able to tinker with the SAML options within Synapse without needing to
  12137. deploy and configure a complicated software stack.</p>
  12138. <p>To make Synapse (and therefore Riot) use it:</p>
  12139. <ol>
  12140. <li>Use the samling.html URL above or deploy your own and visit the IdP Metadata tab.</li>
  12141. <li>Copy the XML to your clipboard.</li>
  12142. <li>On your Synapse server, create a new file <code>samling.xml</code> next to your <code>homeserver.yaml</code> with
  12143. the XML from step 2 as the contents.</li>
  12144. <li>Edit your <code>homeserver.yaml</code> to include:
  12145. <pre><code class="language-yaml">saml2_config:
  12146. sp_config:
  12147. allow_unknown_attributes: true # Works around a bug with AVA Hashes: https://github.com/IdentityPython/pysaml2/issues/388
  12148. metadata:
  12149. local: [&quot;samling.xml&quot;]
  12150. </code></pre>
  12151. </li>
  12152. <li>Ensure that your <code>homeserver.yaml</code> has a setting for <code>public_baseurl</code>:
  12153. <pre><code class="language-yaml">public_baseurl: http://localhost:8080/
  12154. </code></pre>
  12155. </li>
  12156. <li>Run <code>apt-get install xmlsec1</code> and <code>pip install --upgrade --force 'pysaml2&gt;=4.5.0'</code> to ensure
  12157. the dependencies are installed and ready to go.</li>
  12158. <li>Restart Synapse.</li>
  12159. </ol>
  12160. <p>Then in Riot:</p>
  12161. <ol>
  12162. <li>Visit the login page with a Riot pointing at your homeserver.</li>
  12163. <li>Click the Single Sign-On button.</li>
  12164. <li>On the samling page, enter a Name Identifier and add a SAML Attribute for <code>uid=your_localpart</code>.
  12165. The response must also be signed.</li>
  12166. <li>Click &quot;Next&quot;.</li>
  12167. <li>Click &quot;Post Response&quot; (change nothing).</li>
  12168. <li>You should be logged in.</li>
  12169. </ol>
  12170. <p>If you try and repeat this process, you may be automatically logged in using the information you
  12171. gave previously. To fix this, open your developer console (<code>F12</code> or <code>Ctrl+Shift+I</code>) while on the
  12172. samling page and clear the site data. In Chrome, this will be a button on the Application tab.</p>
  12173. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-cas-as-a-developer-without-a-server"><a class="header" href="#how-to-test-cas-as-a-developer-without-a-server">How to test CAS as a developer without a server</a></h1>
  12174. <p>The <a href="https://github.com/jbittel/django-mama-cas">django-mama-cas</a> project is an
  12175. easy to run CAS implementation built on top of Django.</p>
  12176. <h2 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h2>
  12177. <ol>
  12178. <li>Create a new virtualenv: <code>python3 -m venv &lt;your virtualenv&gt;</code></li>
  12179. <li>Activate your virtualenv: <code>source /path/to/your/virtualenv/bin/activate</code></li>
  12180. <li>Install Django and django-mama-cas:
  12181. <pre><code>python -m pip install &quot;django&lt;3&quot; &quot;django-mama-cas==2.4.0&quot;
  12182. </code></pre>
  12183. </li>
  12184. <li>Create a Django project in the current directory:
  12185. <pre><code>django-admin startproject cas_test .
  12186. </code></pre>
  12187. </li>
  12188. <li>Follow the <a href="https://django-mama-cas.readthedocs.io/en/latest/installation.html#configuring">install directions</a> for django-mama-cas</li>
  12189. <li>Setup the SQLite database: <code>python manage.py migrate</code></li>
  12190. <li>Create a user:
  12191. <pre><code>python manage.py createsuperuser
  12192. </code></pre>
  12193. <ol>
  12194. <li>Use whatever you want as the username and password.</li>
  12195. <li>Leave the other fields blank.</li>
  12196. </ol>
  12197. </li>
  12198. <li>Use the built-in Django test server to serve the CAS endpoints on port 8000:
  12199. <pre><code>python manage.py runserver
  12200. </code></pre>
  12201. </li>
  12202. </ol>
  12203. <p>You should now have a Django project configured to serve CAS authentication with
  12204. a single user created.</p>
  12205. <h2 id="configure-synapse-and-element-to-use-cas"><a class="header" href="#configure-synapse-and-element-to-use-cas">Configure Synapse (and Element) to use CAS</a></h2>
  12206. <ol>
  12207. <li>Modify your <code>homeserver.yaml</code> to enable CAS and point it to your locally
  12208. running Django test server:
  12209. <pre><code class="language-yaml">cas_config:
  12210. enabled: true
  12211. server_url: &quot;http://localhost:8000&quot;
  12212. service_url: &quot;http://localhost:8081&quot;
  12213. #displayname_attribute: name
  12214. #required_attributes:
  12215. # name: value
  12216. </code></pre>
  12217. </li>
  12218. <li>Restart Synapse.</li>
  12219. </ol>
  12220. <p>Note that the above configuration assumes the homeserver is running on port 8081
  12221. and that the CAS server is on port 8000, both on localhost.</p>
  12222. <h2 id="testing-the-configuration"><a class="header" href="#testing-the-configuration">Testing the configuration</a></h2>
  12223. <p>Then in Element:</p>
  12224. <ol>
  12225. <li>Visit the login page with a Element pointing at your homeserver.</li>
  12226. <li>Click the Single Sign-On button.</li>
  12227. <li>Login using the credentials created with <code>createsuperuser</code>.</li>
  12228. <li>You should be logged in.</li>
  12229. </ol>
  12230. <p>If you want to repeat this process you'll need to manually logout first:</p>
  12231. <ol>
  12232. <li>http://localhost:8000/admin/</li>
  12233. <li>Click &quot;logout&quot; in the top right.</li>
  12234. </ol>
  12235. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="room-dag-concepts"><a class="header" href="#room-dag-concepts">Room DAG concepts</a></h1>
  12236. <h2 id="edges"><a class="header" href="#edges">Edges</a></h2>
  12237. <p>The word &quot;edge&quot; comes from graph theory lingo. An edge is just a connection
  12238. between two events. In Synapse, we connect events by specifying their
  12239. <code>prev_events</code>. A subsequent event points back at a previous event.</p>
  12240. <pre><code>A (oldest) &lt;---- B &lt;---- C (most recent)
  12241. </code></pre>
  12242. <h2 id="depth-and-stream-ordering"><a class="header" href="#depth-and-stream-ordering">Depth and stream ordering</a></h2>
  12243. <p>Events are normally sorted by <code>(topological_ordering, stream_ordering)</code> where
  12244. <code>topological_ordering</code> is just <code>depth</code>. In other words, we first sort by <code>depth</code>
  12245. and then tie-break based on <code>stream_ordering</code>. <code>depth</code> is incremented as new
  12246. messages are added to the DAG. Normally, <code>stream_ordering</code> is an auto
  12247. incrementing integer, but backfilled events start with <code>stream_ordering=-1</code> and decrement.</p>
  12248. <hr />
  12249. <ul>
  12250. <li><code>/sync</code> returns things in the order they arrive at the server (<code>stream_ordering</code>).</li>
  12251. <li><code>/messages</code> (and <code>/backfill</code> in the federation API) return them in the order determined by the event graph <code>(topological_ordering, stream_ordering)</code>.</li>
  12252. </ul>
  12253. <p>The general idea is that, if you're following a room in real-time (i.e.
  12254. <code>/sync</code>), you probably want to see the messages as they arrive at your server,
  12255. rather than skipping any that arrived late; whereas if you're looking at a
  12256. historical section of timeline (i.e. <code>/messages</code>), you want to see the best
  12257. representation of the state of the room as others were seeing it at the time.</p>
  12258. <h2 id="forward-extremity"><a class="header" href="#forward-extremity">Forward extremity</a></h2>
  12259. <p>Most-recent-in-time events in the DAG which are not referenced by any other events' <code>prev_events</code> yet.</p>
  12260. <p>The forward extremities of a room are used as the <code>prev_events</code> when the next event is sent.</p>
  12261. <h2 id="backwards-extremity"><a class="header" href="#backwards-extremity">Backwards extremity</a></h2>
  12262. <p>The current marker of where we have backfilled up to and will generally be the
  12263. oldest-in-time events we know of in the DAG.</p>
  12264. <p>This is an event where we haven't fetched all of the <code>prev_events</code> for.</p>
  12265. <p>Once we have fetched all of its <code>prev_events</code>, it's unmarked as a backwards
  12266. extremity (although we may have formed new backwards extremities from the prev
  12267. events during the backfilling process).</p>
  12268. <h2 id="outliers"><a class="header" href="#outliers">Outliers</a></h2>
  12269. <p>We mark an event as an <code>outlier</code> when we haven't figured out the state for the
  12270. room at that point in the DAG yet.</p>
  12271. <p>We won't <em>necessarily</em> have the <code>prev_events</code> of an <code>outlier</code> in the database,
  12272. but it's entirely possible that we <em>might</em>. The status of whether we have all of
  12273. the <code>prev_events</code> is marked as a <a href="development/room-dag-concepts.html#backwards-extremity">backwards extremity</a>.</p>
  12274. <p>For example, when we fetch the event auth chain or state for a given event, we
  12275. mark all of those claimed auth events as outliers because we haven't done the
  12276. state calculation ourself.</p>
  12277. <h2 id="state-groups"><a class="header" href="#state-groups">State groups</a></h2>
  12278. <p>For every non-outlier event we need to know the state at that event. Instead of
  12279. storing the full state for each event in the DB (i.e. a <code>event_id -&gt; state</code>
  12280. mapping), which is <em>very</em> space inefficient when state doesn't change, we
  12281. instead assign each different set of state a &quot;state group&quot; and then have
  12282. mappings of <code>event_id -&gt; state_group</code> and <code>state_group -&gt; state</code>.</p>
  12283. <h3 id="stage-group-edges"><a class="header" href="#stage-group-edges">Stage group edges</a></h3>
  12284. <p>TODO: <code>state_group_edges</code> is a further optimization...
  12285. notes from @Azrenbeth, https://pastebin.com/seUGVGeT</p>
  12286. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="auth-chain-difference-algorithm"><a class="header" href="#auth-chain-difference-algorithm">Auth Chain Difference Algorithm</a></h1>
  12287. <p>The auth chain difference algorithm is used by V2 state resolution, where a
  12288. naive implementation can be a significant source of CPU and DB usage.</p>
  12289. <h3 id="definitions"><a class="header" href="#definitions">Definitions</a></h3>
  12290. <p>A <em>state set</em> is a set of state events; e.g. the input of a state resolution
  12291. algorithm is a collection of state sets.</p>
  12292. <p>The <em>auth chain</em> of a set of events are all the events' auth events and <em>their</em>
  12293. auth events, recursively (i.e. the events reachable by walking the graph induced
  12294. by an event's auth events links).</p>
  12295. <p>The <em>auth chain difference</em> of a collection of state sets is the union minus the
  12296. intersection of the sets of auth chains corresponding to the state sets, i.e an
  12297. event is in the auth chain difference if it is reachable by walking the auth
  12298. event graph from at least one of the state sets but not from <em>all</em> of the state
  12299. sets.</p>
  12300. <h2 id="breadth-first-walk-algorithm"><a class="header" href="#breadth-first-walk-algorithm">Breadth First Walk Algorithm</a></h2>
  12301. <p>A way of calculating the auth chain difference without calculating the full auth
  12302. chains for each state set is to do a parallel breadth first walk (ordered by
  12303. depth) of each state set's auth chain. By tracking which events are reachable
  12304. from each state set we can finish early if every pending event is reachable from
  12305. every state set.</p>
  12306. <p>This can work well for state sets that have a small auth chain difference, but
  12307. can be very inefficient for larger differences. However, this algorithm is still
  12308. used if we don't have a chain cover index for the room (e.g. because we're in
  12309. the process of indexing it).</p>
  12310. <h2 id="chain-cover-index"><a class="header" href="#chain-cover-index">Chain Cover Index</a></h2>
  12311. <p>Synapse computes auth chain differences by pre-computing a &quot;chain cover&quot; index
  12312. for the auth chain in a room, allowing efficient reachability queries like &quot;is
  12313. event A in the auth chain of event B&quot;. This is done by assigning every event a
  12314. <em>chain ID</em> and <em>sequence number</em> (e.g. <code>(5,3)</code>), and having a map of <em>links</em>
  12315. between chains (e.g. <code>(5,3) -&gt; (2,4)</code>) such that A is reachable by B (i.e. <code>A</code>
  12316. is in the auth chain of <code>B</code>) if and only if either:</p>
  12317. <ol>
  12318. <li>A and B have the same chain ID and <code>A</code>'s sequence number is less than <code>B</code>'s
  12319. sequence number; or</li>
  12320. <li>there is a link <code>L</code> between <code>B</code>'s chain ID and <code>A</code>'s chain ID such that
  12321. <code>L.start_seq_no</code> &lt;= <code>B.seq_no</code> and <code>A.seq_no</code> &lt;= <code>L.end_seq_no</code>.</li>
  12322. </ol>
  12323. <p>There are actually two potential implementations, one where we store links from
  12324. each chain to every other reachable chain (the transitive closure of the links
  12325. graph), and one where we remove redundant links (the transitive reduction of the
  12326. links graph) e.g. if we have chains <code>C3 -&gt; C2 -&gt; C1</code> then the link <code>C3 -&gt; C1</code>
  12327. would not be stored. Synapse uses the former implementations so that it doesn't
  12328. need to recurse to test reachability between chains.</p>
  12329. <h3 id="example-6"><a class="header" href="#example-6">Example</a></h3>
  12330. <p>An example auth graph would look like the following, where chains have been
  12331. formed based on type/state_key and are denoted by colour and are labelled with
  12332. <code>(chain ID, sequence number)</code>. Links are denoted by the arrows (links in grey
  12333. are those that would be remove in the second implementation described above).</p>
  12334. <p><img src="auth_chain_diff.dot.png" alt="Example" /></p>
  12335. <p>Note that we don't include all links between events and their auth events, as
  12336. most of those links would be redundant. For example, all events point to the
  12337. create event, but each chain only needs the one link from it's base to the
  12338. create event.</p>
  12339. <h2 id="using-the-index"><a class="header" href="#using-the-index">Using the Index</a></h2>
  12340. <p>This index can be used to calculate the auth chain difference of the state sets
  12341. by looking at the chain ID and sequence numbers reachable from each state set:</p>
  12342. <ol>
  12343. <li>For every state set lookup the chain ID/sequence numbers of each state event</li>
  12344. <li>Use the index to find all chains and the maximum sequence number reachable
  12345. from each state set.</li>
  12346. <li>The auth chain difference is then all events in each chain that have sequence
  12347. numbers between the maximum sequence number reachable from <em>any</em> state set and
  12348. the minimum reachable by <em>all</em> state sets (if any).</li>
  12349. </ol>
  12350. <p>Note that steps 2 is effectively calculating the auth chain for each state set
  12351. (in terms of chain IDs and sequence numbers), and step 3 is calculating the
  12352. difference between the union and intersection of the auth chains.</p>
  12353. <h3 id="worked-example"><a class="header" href="#worked-example">Worked Example</a></h3>
  12354. <p>For example, given the above graph, we can calculate the difference between
  12355. state sets consisting of:</p>
  12356. <ol>
  12357. <li><code>S1</code>: Alice's invite <code>(4,1)</code> and Bob's second join <code>(2,2)</code>; and</li>
  12358. <li><code>S2</code>: Alice's second join <code>(4,3)</code> and Bob's first join <code>(2,1)</code>.</li>
  12359. </ol>
  12360. <p>Using the index we see that the following auth chains are reachable from each
  12361. state set:</p>
  12362. <ol>
  12363. <li><code>S1</code>: <code>(1,1)</code>, <code>(2,2)</code>, <code>(3,1)</code> &amp; <code>(4,1)</code></li>
  12364. <li><code>S2</code>: <code>(1,1)</code>, <code>(2,1)</code>, <code>(3,2)</code> &amp; <code>(4,3)</code></li>
  12365. </ol>
  12366. <p>And so, for each the ranges that are in the auth chain difference:</p>
  12367. <ol>
  12368. <li>Chain 1: None, (since everything can reach the create event).</li>
  12369. <li>Chain 2: The range <code>(1, 2]</code> (i.e. just <code>2</code>), as <code>1</code> is reachable by all state
  12370. sets and the maximum reachable is <code>2</code> (corresponding to Bob's second join).</li>
  12371. <li>Chain 3: Similarly the range <code>(1, 2]</code> (corresponding to the second power
  12372. level).</li>
  12373. <li>Chain 4: The range <code>(1, 3]</code> (corresponding to both of Alice's joins).</li>
  12374. </ol>
  12375. <p>So the final result is: Bob's second join <code>(2,2)</code>, the second power level
  12376. <code>(3,2)</code> and both of Alice's joins <code>(4,2)</code> &amp; <code>(4,3)</code>.</p>
  12377. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="media-repository"><a class="header" href="#media-repository">Media Repository</a></h1>
  12378. <p><em>Synapse implementation-specific details for the media repository</em></p>
  12379. <p>The media repository is where attachments and avatar photos are stored.
  12380. It stores attachment content and thumbnails for media uploaded by local users.
  12381. It caches attachment content and thumbnails for media uploaded by remote users.</p>
  12382. <h2 id="storage"><a class="header" href="#storage">Storage</a></h2>
  12383. <p>Each item of media is assigned a <code>media_id</code> when it is uploaded.
  12384. The <code>media_id</code> is a randomly chosen, URL safe 24 character string.</p>
  12385. <p>Metadata such as the MIME type, upload time and length are stored in the
  12386. sqlite3 database indexed by <code>media_id</code>.</p>
  12387. <p>Content is stored on the filesystem under a <code>&quot;local_content&quot;</code> directory.</p>
  12388. <p>Thumbnails are stored under a <code>&quot;local_thumbnails&quot;</code> directory.</p>
  12389. <p>The item with <code>media_id</code> <code>&quot;aabbccccccccdddddddddddd&quot;</code> is stored under
  12390. <code>&quot;local_content/aa/bb/ccccccccdddddddddddd&quot;</code>. Its thumbnail with width
  12391. <code>128</code> and height <code>96</code> and type <code>&quot;image/jpeg&quot;</code> is stored under
  12392. <code>&quot;local_thumbnails/aa/bb/ccccccccdddddddddddd/128-96-image-jpeg&quot;</code></p>
  12393. <p>Remote content is cached under <code>&quot;remote_content&quot;</code> directory. Each item of
  12394. remote content is assigned a local <code>&quot;filesystem_id&quot;</code> to ensure that the
  12395. directory structure <code>&quot;remote_content/server_name/aa/bb/ccccccccdddddddddddd&quot;</code>
  12396. is appropriate. Thumbnails for remote content are stored under
  12397. <code>&quot;remote_thumbnails/server_name/...&quot;</code></p>
  12398. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="room-and-user-statistics"><a class="header" href="#room-and-user-statistics">Room and User Statistics</a></h1>
  12399. <p>Synapse maintains room and user statistics in various tables. These can be used
  12400. for administrative purposes but are also used when generating the public room
  12401. directory.</p>
  12402. <h1 id="synapse-developer-documentation"><a class="header" href="#synapse-developer-documentation">Synapse Developer Documentation</a></h1>
  12403. <h2 id="high-level-concepts"><a class="header" href="#high-level-concepts">High-Level Concepts</a></h2>
  12404. <h3 id="definitions-1"><a class="header" href="#definitions-1">Definitions</a></h3>
  12405. <ul>
  12406. <li><strong>subject</strong>: Something we are tracking stats about – currently a room or user.</li>
  12407. <li><strong>current row</strong>: An entry for a subject in the appropriate current statistics
  12408. table. Each subject can have only one.</li>
  12409. </ul>
  12410. <h3 id="overview-4"><a class="header" href="#overview-4">Overview</a></h3>
  12411. <p>Stats correspond to the present values. Current rows contain the most up-to-date
  12412. statistics for a room. Each subject can only have one entry.</p>
  12413. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="deprecation-policy-for-platform-dependencies"><a class="header" href="#deprecation-policy-for-platform-dependencies">Deprecation Policy for Platform Dependencies</a></h1>
  12414. <p>Synapse has a number of platform dependencies, including Python and PostgreSQL.
  12415. This document outlines the policy towards which versions we support, and when we
  12416. drop support for versions in the future.</p>
  12417. <h2 id="policy"><a class="header" href="#policy">Policy</a></h2>
  12418. <p>Synapse follows the upstream support life cycles for Python and PostgreSQL,
  12419. i.e. when a version reaches End of Life Synapse will withdraw support for that
  12420. version in future releases.</p>
  12421. <p>Details on the upstream support life cycles for Python and PostgreSQL are
  12422. documented at https://endoflife.date/python and
  12423. https://endoflife.date/postgresql.</p>
  12424. <h2 id="context"><a class="header" href="#context">Context</a></h2>
  12425. <p>It is important for system admins to have a clear understanding of the platform
  12426. requirements of Synapse and its deprecation policies so that they can
  12427. effectively plan upgrading their infrastructure ahead of time. This is
  12428. especially important in contexts where upgrading the infrastructure requires
  12429. auditing and approval from a security team, or where otherwise upgrading is a
  12430. long process.</p>
  12431. <p>By following the upstream support life cycles Synapse can ensure that its
  12432. dependencies continue to get security patches, while not requiring system admins
  12433. to constantly update their platform dependencies to the latest versions.</p>
  12434. </main>
  12435. <nav class="nav-wrapper" aria-label="Page navigation">
  12436. <!-- Mobile navigation buttons -->
  12437. <div style="clear: both"></div>
  12438. </nav>
  12439. </div>
  12440. </div>
  12441. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  12442. </nav>
  12443. </div>
  12444. <script type="text/javascript">
  12445. window.playground_copyable = true;
  12446. </script>
  12447. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  12448. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  12449. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  12450. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  12451. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  12452. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  12453. <!-- Custom JS scripts -->
  12454. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  12455. <script type="text/javascript">
  12456. window.addEventListener('load', function() {
  12457. window.setTimeout(window.print, 100);
  12458. });
  12459. </script>
  12460. </body>
  12461. </html>