print.html 682 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095
  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. <link rel="stylesheet" href="docs/website_files/version-picker.css">
  31. </head>
  32. <body>
  33. <!-- Provide site root to javascript -->
  34. <script type="text/javascript">
  35. var path_to_root = "";
  36. var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
  37. </script>
  38. <!-- Work around some values being stored in localStorage wrapped in quotes -->
  39. <script type="text/javascript">
  40. try {
  41. var theme = localStorage.getItem('mdbook-theme');
  42. var sidebar = localStorage.getItem('mdbook-sidebar');
  43. if (theme.startsWith('"') && theme.endsWith('"')) {
  44. localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
  45. }
  46. if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
  47. localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
  48. }
  49. } catch (e) { }
  50. </script>
  51. <!-- Set the theme before any content is loaded, prevents flash -->
  52. <script type="text/javascript">
  53. var theme;
  54. try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
  55. if (theme === null || theme === undefined) { theme = default_theme; }
  56. var html = document.querySelector('html');
  57. html.classList.remove('no-js')
  58. html.classList.remove('light')
  59. html.classList.add(theme);
  60. html.classList.add('js');
  61. </script>
  62. <!-- Hide / unhide sidebar before it is displayed -->
  63. <script type="text/javascript">
  64. var html = document.querySelector('html');
  65. var sidebar = 'hidden';
  66. if (document.body.clientWidth >= 1080) {
  67. try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
  68. sidebar = sidebar || 'visible';
  69. }
  70. html.classList.remove('sidebar-visible');
  71. html.classList.add("sidebar-" + sidebar);
  72. </script>
  73. <nav id="sidebar" class="sidebar" aria-label="Table of contents">
  74. <div class="sidebar-scrollbox">
  75. <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="development/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/index.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/writing_a_module.html">Writing a module</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/spam_checker_callbacks.html">Spam checker callbacks</a></li><li class="chapter-item expanded "><a href="modules/third_party_rules_callbacks.html">Third-party rules callbacks</a></li><li class="chapter-item expanded "><a href="modules/presence_router_callbacks.html">Presence router callbacks</a></li><li class="chapter-item expanded "><a href="modules/account_validity_callbacks.html">Account validity callbacks</a></li><li class="chapter-item expanded "><a href="modules/porting_legacy_module.html">Porting a legacy module to the new interface</a></li></ol></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/register_api.html">Register Users</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/registration_tokens.html">Registration Tokens</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/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 "><a href="development/experimental_features.html">Experimental features</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>
  76. </div>
  77. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  78. </nav>
  79. <div id="page-wrapper" class="page-wrapper">
  80. <div class="page">
  81. <div id="menu-bar-hover-placeholder"></div>
  82. <div id="menu-bar" class="menu-bar sticky bordered">
  83. <div class="left-buttons">
  84. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  85. <i class="fa fa-bars"></i>
  86. </button>
  87. <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">
  88. <i class="fa fa-paint-brush"></i>
  89. </button>
  90. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  91. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  94. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  95. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  96. </ul>
  97. <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">
  98. <i class="fa fa-search"></i>
  99. </button>
  100. <div class="version-picker">
  101. <div class="dropdown">
  102. <div class="select">
  103. <span></span>
  104. <i class="fa fa-chevron-down"></i>
  105. </div>
  106. <input type="hidden" name="version">
  107. <ul class="dropdown-menu">
  108. <!-- Versions will be added dynamically in version-picker.js -->
  109. </ul>
  110. </div>
  111. </div>
  112. </div>
  113. <h1 class="menu-title">Synapse</h1>
  114. <div class="right-buttons">
  115. <a href="print.html" title="Print this book" aria-label="Print this book">
  116. <i id="print-button" class="fa fa-print"></i>
  117. </a>
  118. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  119. <i id="git-repository-button" class="fa fa-github"></i>
  120. </a>
  121. </div>
  122. </div>
  123. <div id="search-wrapper" class="hidden">
  124. <form id="searchbar-outer" class="searchbar-outer">
  125. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  126. </form>
  127. <div id="searchresults-outer" class="searchresults-outer hidden">
  128. <div id="searchresults-header" class="searchresults-header"></div>
  129. <ul id="searchresults">
  130. </ul>
  131. </div>
  132. </div>
  133. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  134. <script type="text/javascript">
  135. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  136. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  137. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  138. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  139. });
  140. </script>
  141. <div id="content" class="content">
  142. <main>
  143. <!-- Page table of contents -->
  144. <div class="sidetoc">
  145. <nav class="pagetoc"></nav>
  146. </div>
  147. <div style="break-before: page; page-break-before: always;"></div><h1 id="introduction"><a class="header" href="#introduction">Introduction</a></h1>
  148. <p>Welcome to the documentation repository for Synapse, the reference
  149. <a href="https://matrix.org">Matrix</a> homeserver implementation.</p>
  150. <div style="break-before: page; page-break-before: always;"></div><h1 id="installation-instructions"><a class="header" href="#installation-instructions">Installation Instructions</a></h1>
  151. <h2 id="choosing-your-server-name"><a class="header" href="#choosing-your-server-name">Choosing your server name</a></h2>
  152. <p>It is important to choose the name for your server before you install Synapse,
  153. because it cannot be changed later.</p>
  154. <p>The server name determines the &quot;domain&quot; part of user-ids for users on your
  155. server: these will all be of the format <code>@user:my.domain.name</code>. It also
  156. determines how other matrix servers will reach yours for federation.</p>
  157. <p>For a test configuration, set this to the hostname of your server. For a more
  158. production-ready setup, you will probably want to specify your domain
  159. (<code>example.com</code>) rather than a matrix-specific hostname here (in the same way
  160. that your email address is probably <code>user@example.com</code> rather than
  161. <code>user@email.example.com</code>) - but doing so may require more advanced setup: see
  162. <a href="setup/../federate.html">Setting up Federation</a>.</p>
  163. <h2 id="installing-synapse"><a class="header" href="#installing-synapse">Installing Synapse</a></h2>
  164. <h3 id="prebuilt-packages"><a class="header" href="#prebuilt-packages">Prebuilt packages</a></h3>
  165. <p>Prebuilt packages are available for a number of platforms. These are recommended
  166. for most users.</p>
  167. <h4 id="docker-images-and-ansible-playbooks"><a class="header" href="#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></h4>
  168. <p>There is an official synapse image available at
  169. <a href="https://hub.docker.com/r/matrixdotorg/synapse">https://hub.docker.com/r/matrixdotorg/synapse</a> which can be used with
  170. the docker-compose file available at
  171. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/docker">contrib/docker</a>.
  172. Further information on this including configuration options is available in the README
  173. on hub.docker.com.</p>
  174. <p>Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a
  175. Dockerfile to automate a synapse server in a single Docker image, at
  176. <a href="https://hub.docker.com/r/avhost/docker-matrix/tags/">https://hub.docker.com/r/avhost/docker-matrix/tags/</a></p>
  177. <p>Slavi Pantaleev has created an Ansible playbook,
  178. which installs the offical Docker image of Matrix Synapse
  179. along with many other Matrix-related services (Postgres database, Element, coturn,
  180. ma1sd, SSL support, etc.).
  181. For more details, see
  182. <a href="https://github.com/spantaleev/matrix-docker-ansible-deploy">https://github.com/spantaleev/matrix-docker-ansible-deploy</a></p>
  183. <h4 id="debianubuntu"><a class="header" href="#debianubuntu">Debian/Ubuntu</a></h4>
  184. <h5 id="matrixorg-packages"><a class="header" href="#matrixorg-packages">Matrix.org packages</a></h5>
  185. <p>Matrix.org provides Debian/Ubuntu packages of Synapse, for the amd64
  186. architecture via <a href="https://packages.matrix.org/debian/">https://packages.matrix.org/debian/</a>.</p>
  187. <p>To install the latest release:</p>
  188. <pre><code class="language-sh">sudo apt install -y lsb-release wget apt-transport-https
  189. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  190. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main&quot; |
  191. sudo tee /etc/apt/sources.list.d/matrix-org.list
  192. sudo apt update
  193. sudo apt install matrix-synapse-py3
  194. </code></pre>
  195. <p>Packages are also published for release candidates. To enable the prerelease
  196. channel, add <code>prerelease</code> to the <code>sources.list</code> line. For example:</p>
  197. <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
  198. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main prerelease&quot; |
  199. sudo tee /etc/apt/sources.list.d/matrix-org.list
  200. sudo apt update
  201. sudo apt install matrix-synapse-py3
  202. </code></pre>
  203. <p>The fingerprint of the repository signing key (as shown by <code>gpg /usr/share/keyrings/matrix-org-archive-keyring.gpg</code>) is
  204. <code>AAF9AE843A7584B5A3E4CD2BCF45A512DE2DA058</code>.</p>
  205. <h5 id="downstream-debian-packages"><a class="header" href="#downstream-debian-packages">Downstream Debian packages</a></h5>
  206. <p>We do not recommend using the packages from the default Debian <code>buster</code>
  207. repository at this time, as they are old and suffer from known security
  208. vulnerabilities. You can install the latest version of Synapse from
  209. <a href="setup/installation.html#matrixorg-packages">our repository</a> or from <code>buster-backports</code>. Please
  210. see the <a href="https://backports.debian.org/Instructions/">Debian documentation</a>
  211. for information on how to use backports.</p>
  212. <p>If you are using Debian <code>sid</code> or testing, Synapse is available in the default
  213. repositories and it should be possible to install it simply with:</p>
  214. <pre><code class="language-sh">sudo apt install matrix-synapse
  215. </code></pre>
  216. <h5 id="downstream-ubuntu-packages"><a class="header" href="#downstream-ubuntu-packages">Downstream Ubuntu packages</a></h5>
  217. <p>We do not recommend using the packages in the default Ubuntu repository
  218. at this time, as they are old and suffer from known security vulnerabilities.
  219. The latest version of Synapse can be installed from <a href="setup/installation.html#matrixorg-packages">our repository</a>.</p>
  220. <h4 id="fedora"><a class="header" href="#fedora">Fedora</a></h4>
  221. <p>Synapse is in the Fedora repositories as <code>matrix-synapse</code>:</p>
  222. <pre><code class="language-sh">sudo dnf install matrix-synapse
  223. </code></pre>
  224. <p>Oleg Girko provides Fedora RPMs at
  225. <a href="https://obs.infoserver.lv/project/monitor/matrix-synapse">https://obs.infoserver.lv/project/monitor/matrix-synapse</a></p>
  226. <h4 id="opensuse"><a class="header" href="#opensuse">OpenSUSE</a></h4>
  227. <p>Synapse is in the OpenSUSE repositories as <code>matrix-synapse</code>:</p>
  228. <pre><code class="language-sh">sudo zypper install matrix-synapse
  229. </code></pre>
  230. <h4 id="suse-linux-enterprise-server"><a class="header" href="#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></h4>
  231. <p>Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at
  232. <a href="https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/">https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/</a></p>
  233. <h4 id="archlinux"><a class="header" href="#archlinux">ArchLinux</a></h4>
  234. <p>The quickest way to get up and running with ArchLinux is probably with the community package
  235. <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
  236. the necessary dependencies.</p>
  237. <p>pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):</p>
  238. <pre><code class="language-sh">sudo pip install --upgrade pip
  239. </code></pre>
  240. <p>If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  241. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  242. compile it under the right architecture. (This should not be needed if
  243. installing under virtualenv):</p>
  244. <pre><code class="language-sh">sudo pip uninstall py-bcrypt
  245. sudo pip install py-bcrypt
  246. </code></pre>
  247. <h4 id="void-linux"><a class="header" href="#void-linux">Void Linux</a></h4>
  248. <p>Synapse can be found in the void repositories as 'synapse':</p>
  249. <pre><code class="language-sh">xbps-install -Su
  250. xbps-install -S synapse
  251. </code></pre>
  252. <h4 id="freebsd"><a class="header" href="#freebsd">FreeBSD</a></h4>
  253. <p>Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:</p>
  254. <ul>
  255. <li>Ports: <code>cd /usr/ports/net-im/py-matrix-synapse &amp;&amp; make install clean</code></li>
  256. <li>Packages: <code>pkg install py37-matrix-synapse</code></li>
  257. </ul>
  258. <h4 id="openbsd"><a class="header" href="#openbsd">OpenBSD</a></h4>
  259. <p>As of OpenBSD 6.7 Synapse is available as a pre-compiled binary. The filesystem
  260. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  261. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  262. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  263. <p>Installing Synapse:</p>
  264. <pre><code class="language-sh">doas pkg_add synapse
  265. </code></pre>
  266. <h4 id="nixos"><a class="header" href="#nixos">NixOS</a></h4>
  267. <p>Robin Lambertz has packaged Synapse for NixOS at:
  268. <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>
  269. <h3 id="installing-as-a-python-module-from-pypi"><a class="header" href="#installing-as-a-python-module-from-pypi">Installing as a Python module from PyPI</a></h3>
  270. <p>It's also possible to install Synapse as a Python module from PyPI.</p>
  271. <p>When following this route please make sure that the <a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a> are already installed.</p>
  272. <p>System requirements:</p>
  273. <ul>
  274. <li>POSIX-compliant system (tested on Linux &amp; OS X)</li>
  275. <li>Python 3.6 or later, up to Python 3.9.</li>
  276. <li>At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org</li>
  277. </ul>
  278. <p>To install the Synapse homeserver run:</p>
  279. <pre><code class="language-sh">mkdir -p ~/synapse
  280. virtualenv -p python3 ~/synapse/env
  281. source ~/synapse/env/bin/activate
  282. pip install --upgrade pip
  283. pip install --upgrade setuptools
  284. pip install matrix-synapse
  285. </code></pre>
  286. <p>This will download Synapse from <a href="https://pypi.org/project/matrix-synapse">PyPI</a>
  287. and install it, along with the python libraries it uses, into a virtual environment
  288. under <code>~/synapse/env</code>. Feel free to pick a different directory if you
  289. prefer.</p>
  290. <p>This Synapse installation can then be later upgraded by using pip again with the
  291. update flag:</p>
  292. <pre><code class="language-sh">source ~/synapse/env/bin/activate
  293. pip install -U matrix-synapse
  294. </code></pre>
  295. <p>Before you can start Synapse, you will need to generate a configuration
  296. file. To do this, run (in your virtualenv, as before):</p>
  297. <pre><code class="language-sh">cd ~/synapse
  298. python -m synapse.app.homeserver \
  299. --server-name my.domain.name \
  300. --config-path homeserver.yaml \
  301. --generate-config \
  302. --report-stats=[yes|no]
  303. </code></pre>
  304. <p>... substituting an appropriate value for <code>--server-name</code>.</p>
  305. <p>This command will generate you a config file that you can then customise, but it will
  306. also generate a set of keys for you. These keys will allow your homeserver to
  307. identify itself to other homeserver, so don't lose or delete them. It would be
  308. wise to back them up somewhere safe. (If, for whatever reason, you do need to
  309. change your homeserver's keys, you may find that other homeserver have the
  310. old key cached. If you update the signing key, you should change the name of the
  311. key in the <code>&lt;server name&gt;.signing.key</code> file (the second word) to something
  312. 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>
  313. <p>To actually run your new homeserver, pick a working directory for Synapse to
  314. run (e.g. <code>~/synapse</code>), and:</p>
  315. <pre><code class="language-sh">cd ~/synapse
  316. source env/bin/activate
  317. synctl start
  318. </code></pre>
  319. <h4 id="platform-specific-prerequisites"><a class="header" href="#platform-specific-prerequisites">Platform-specific prerequisites</a></h4>
  320. <p>Synapse is written in Python but some of the libraries it uses are written in
  321. C. So before we can install Synapse itself we need a working C compiler and the
  322. header files for Python C extensions.</p>
  323. <h5 id="debianubunturaspbian"><a class="header" href="#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></h5>
  324. <p>Installing prerequisites on Ubuntu or Debian:</p>
  325. <pre><code class="language-sh">sudo apt install build-essential python3-dev libffi-dev \
  326. python3-pip python3-setuptools sqlite3 \
  327. libssl-dev virtualenv libjpeg-dev libxslt1-dev
  328. </code></pre>
  329. <h5 id="archlinux-1"><a class="header" href="#archlinux-1">ArchLinux</a></h5>
  330. <p>Installing prerequisites on ArchLinux:</p>
  331. <pre><code class="language-sh">sudo pacman -S base-devel python python-pip \
  332. python-setuptools python-virtualenv sqlite3
  333. </code></pre>
  334. <h5 id="centosfedora"><a class="header" href="#centosfedora">CentOS/Fedora</a></h5>
  335. <p>Installing prerequisites on CentOS or Fedora Linux:</p>
  336. <pre><code class="language-sh">sudo dnf install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
  337. libwebp-devel libxml2-devel libxslt-devel libpq-devel \
  338. python3-virtualenv libffi-devel openssl-devel python3-devel
  339. sudo dnf groupinstall &quot;Development Tools&quot;
  340. </code></pre>
  341. <h5 id="macos"><a class="header" href="#macos">macOS</a></h5>
  342. <p>Installing prerequisites on macOS:</p>
  343. <p>You may need to install the latest Xcode developer tools:</p>
  344. <pre><code class="language-sh">xcode-select --install
  345. </code></pre>
  346. <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>
  347. <pre><code class="language-sh"> brew install jpeg
  348. </code></pre>
  349. <p>On macOS Catalina (10.15) you may need to explicitly install OpenSSL
  350. via brew and inform <code>pip</code> about it so that <code>psycopg2</code> builds:</p>
  351. <pre><code class="language-sh">brew install openssl@1.1
  352. export LDFLAGS=&quot;-L/usr/local/opt/openssl/lib&quot;
  353. export CPPFLAGS=&quot;-I/usr/local/opt/openssl/include&quot;
  354. </code></pre>
  355. <h5 id="opensuse-1"><a class="header" href="#opensuse-1">OpenSUSE</a></h5>
  356. <p>Installing prerequisites on openSUSE:</p>
  357. <pre><code class="language-sh">sudo zypper in -t pattern devel_basis
  358. sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
  359. python-devel libffi-devel libopenssl-devel libjpeg62-devel
  360. </code></pre>
  361. <h5 id="openbsd-1"><a class="header" href="#openbsd-1">OpenBSD</a></h5>
  362. <p>A port of Synapse is available under <code>net/synapse</code>. The filesystem
  363. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  364. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  365. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  366. <p>To be able to build Synapse's dependency on python the <code>WRKOBJDIR</code>
  367. (cf. <code>bsd.port.mk(5)</code>) for building python, too, needs to be on a filesystem
  368. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>).</p>
  369. <p>Creating a <code>WRKOBJDIR</code> for building python under <code>/usr/local</code> (which on a
  370. default OpenBSD installation is mounted with <code>wxallowed</code>):</p>
  371. <pre><code class="language-sh">doas mkdir /usr/local/pobj_wxallowed
  372. </code></pre>
  373. <p>Assuming <code>PORTS_PRIVSEP=Yes</code> (cf. <code>bsd.port.mk(5)</code>) and <code>SUDO=doas</code> are
  374. configured in <code>/etc/mk.conf</code>:</p>
  375. <pre><code class="language-sh">doas chown _pbuild:_pbuild /usr/local/pobj_wxallowed
  376. </code></pre>
  377. <p>Setting the <code>WRKOBJDIR</code> for building python:</p>
  378. <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
  379. </code></pre>
  380. <p>Building Synapse:</p>
  381. <pre><code class="language-sh">cd /usr/ports/net/synapse
  382. make install
  383. </code></pre>
  384. <h5 id="windows"><a class="header" href="#windows">Windows</a></h5>
  385. <p>If you wish to run or develop Synapse on Windows, the Windows Subsystem For
  386. Linux provides a Linux environment on Windows 10 which is capable of using the
  387. Debian, Fedora, or source installation methods. More information about WSL can
  388. 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
  389. 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>
  390. for Windows Server.</p>
  391. <h2 id="setting-up-synapse"><a class="header" href="#setting-up-synapse">Setting up Synapse</a></h2>
  392. <p>Once you have installed synapse as above, you will need to configure it.</p>
  393. <h3 id="using-postgresql"><a class="header" href="#using-postgresql">Using PostgreSQL</a></h3>
  394. <p>By default Synapse uses an <a href="https://sqlite.org/">SQLite</a> database and in doing so trades
  395. performance for convenience. Almost all installations should opt to use <a href="https://www.postgresql.org">PostgreSQL</a>
  396. instead. Advantages include:</p>
  397. <ul>
  398. <li>significant performance improvements due to the superior threading and
  399. caching model, smarter query optimiser</li>
  400. <li>allowing the DB to be run on separate hardware</li>
  401. </ul>
  402. <p>For information on how to install and use PostgreSQL in Synapse, please see
  403. <a href="setup/../postgres.html">Using Postgres</a></p>
  404. <p>SQLite is only acceptable for testing purposes. SQLite should not be used in
  405. a production server. Synapse will perform poorly when using
  406. SQLite, especially when participating in large rooms.</p>
  407. <h3 id="tls-certificates"><a class="header" href="#tls-certificates">TLS certificates</a></h3>
  408. <p>The default configuration exposes a single HTTP port on the local
  409. interface: <code>http://localhost:8008</code>. It is suitable for local testing,
  410. but for any practical use, you will need Synapse's APIs to be served
  411. over HTTPS.</p>
  412. <p>The recommended way to do so is to set up a reverse proxy on port
  413. <code>8448</code>. You can find documentation on doing so in
  414. <a href="setup/../reverse_proxy.html">the reverse proxy documentation</a>.</p>
  415. <p>Alternatively, you can configure Synapse to expose an HTTPS port. To do
  416. so, you will need to edit <code>homeserver.yaml</code>, as follows:</p>
  417. <ul>
  418. <li>First, under the <code>listeners</code> section, uncomment the configuration for the
  419. TLS-enabled listener. (Remove the hash sign (<code>#</code>) at the start of
  420. each line). The relevant lines are like this:</li>
  421. </ul>
  422. <pre><code class="language-yaml"> - port: 8448
  423. type: http
  424. tls: true
  425. resources:
  426. - names: [client, federation]
  427. </code></pre>
  428. <ul>
  429. <li>
  430. <p>You will also need to uncomment the <code>tls_certificate_path</code> and
  431. <code>tls_private_key_path</code> lines under the <code>TLS</code> section. You will need to manage
  432. provisioning of these certificates yourself.</p>
  433. <p>If you are using your own certificate, be sure to use a <code>.pem</code> file that
  434. includes the full certificate chain including any intermediate certificates
  435. (for instance, if using certbot, use <code>fullchain.pem</code> as your certificate, not
  436. <code>cert.pem</code>).</p>
  437. </li>
  438. </ul>
  439. <p>For a more detailed guide to configuring your server for federation, see
  440. <a href="setup/../federate.html">Federation</a>.</p>
  441. <h3 id="client-well-known-uri"><a class="header" href="#client-well-known-uri">Client Well-Known URI</a></h3>
  442. <p>Setting up the client Well-Known URI is optional but if you set it up, it will
  443. allow users to enter their full username (e.g. <code>@user:&lt;server_name&gt;</code>) into clients
  444. which support well-known lookup to automatically configure the homeserver and
  445. identity server URLs. This is useful so that users don't have to memorize or think
  446. about the actual homeserver URL you are using.</p>
  447. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/client</code> should return JSON in
  448. the following format.</p>
  449. <pre><code class="language-json">{
  450. &quot;m.homeserver&quot;: {
  451. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  452. }
  453. }
  454. </code></pre>
  455. <p>It can optionally contain identity server information as well.</p>
  456. <pre><code class="language-json">{
  457. &quot;m.homeserver&quot;: {
  458. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  459. },
  460. &quot;m.identity_server&quot;: {
  461. &quot;base_url&quot;: &quot;https://&lt;identity.example.com&gt;&quot;
  462. }
  463. }
  464. </code></pre>
  465. <p>To work in browser based clients, the file must be served with the appropriate
  466. Cross-Origin Resource Sharing (CORS) headers. A recommended value would be
  467. <code>Access-Control-Allow-Origin: *</code> which would allow all browser based clients to
  468. view it.</p>
  469. <p>In nginx this would be something like:</p>
  470. <pre><code class="language-nginx">location /.well-known/matrix/client {
  471. return 200 '{&quot;m.homeserver&quot;: {&quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;}}';
  472. default_type application/json;
  473. add_header Access-Control-Allow-Origin *;
  474. }
  475. </code></pre>
  476. <p>You should also ensure the <code>public_baseurl</code> option in <code>homeserver.yaml</code> is set
  477. correctly. <code>public_baseurl</code> should be set to the URL that clients will use to
  478. connect to your server. This is the same URL you put for the <code>m.homeserver</code>
  479. <code>base_url</code> above.</p>
  480. <pre><code class="language-yaml">public_baseurl: &quot;https://&lt;matrix.example.com&gt;&quot;
  481. </code></pre>
  482. <h3 id="email"><a class="header" href="#email">Email</a></h3>
  483. <p>It is desirable for Synapse to have the capability to send email. This allows
  484. Synapse to send password reset emails, send verifications when an email address
  485. is added to a user's account, and send email notifications to users when they
  486. receive new messages.</p>
  487. <p>To configure an SMTP server for Synapse, modify the configuration section
  488. headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>, <code>smtp_port</code>
  489. and <code>notif_from</code> fields filled out. You may also need to set <code>smtp_user</code>,
  490. <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  491. <p>If email is not configured, password reset, registration and notifications via
  492. email will be disabled.</p>
  493. <h3 id="registering-a-user"><a class="header" href="#registering-a-user">Registering a user</a></h3>
  494. <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>
  495. <p>Alternatively, you can do so from the command line. This can be done as follows:</p>
  496. <ol>
  497. <li>If synapse was installed via pip, activate the virtualenv as follows (if Synapse was
  498. installed via a prebuilt package, <code>register_new_matrix_user</code> should already be
  499. on the search path):
  500. <pre><code class="language-sh">cd ~/synapse
  501. source env/bin/activate
  502. synctl start # if not already running
  503. </code></pre>
  504. </li>
  505. <li>Run the following command:
  506. <pre><code class="language-sh">register_new_matrix_user -c homeserver.yaml http://localhost:8008
  507. </code></pre>
  508. </li>
  509. </ol>
  510. <p>This will prompt you to add details for the new user, and will then connect to
  511. the running Synapse to create the new user. For example:</p>
  512. <pre><code>New user localpart: erikj
  513. Password:
  514. Confirm password:
  515. Make admin [no]:
  516. Success!
  517. </code></pre>
  518. <p>This process uses a setting <code>registration_shared_secret</code> in
  519. <code>homeserver.yaml</code>, which is shared between Synapse itself and the
  520. <code>register_new_matrix_user</code> script. It doesn't matter what it is (a random
  521. value is generated by <code>--generate-config</code>), but it should be kept secret, as
  522. anyone with knowledge of it can register users, including admin accounts,
  523. on your server even if <code>enable_registration</code> is <code>false</code>.</p>
  524. <h3 id="setting-up-a-turn-server"><a class="header" href="#setting-up-a-turn-server">Setting up a TURN server</a></h3>
  525. <p>For reliable VoIP calls to be routed via this homeserver, you MUST configure
  526. a TURN server. See <a href="setup/../turn-howto.html">TURN setup</a> for details.</p>
  527. <h3 id="url-previews"><a class="header" href="#url-previews">URL previews</a></h3>
  528. <p>Synapse includes support for previewing URLs, which is disabled by default. To
  529. turn it on you must enable the <code>url_preview_enabled: True</code> config parameter
  530. and explicitly specify the IP ranges that Synapse is not allowed to spider for
  531. previewing in the <code>url_preview_ip_range_blacklist</code> configuration parameter.
  532. This is critical from a security perspective to stop arbitrary Matrix users
  533. spidering 'internal' URLs on your network. At the very least we recommend that
  534. your loopback and RFC1918 IP addresses are blacklisted.</p>
  535. <p>This also requires the optional <code>lxml</code> python dependency to be installed. This
  536. in turn requires the <code>libxml2</code> library to be available - on Debian/Ubuntu this
  537. means <code>apt-get install libxml2-dev</code>, or equivalent for your OS.</p>
  538. <h3 id="troubleshooting-installation"><a class="header" href="#troubleshooting-installation">Troubleshooting Installation</a></h3>
  539. <p><code>pip</code> seems to leak <em>lots</em> of memory during installation. For instance, a Linux
  540. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  541. happens, you will have to individually install the dependencies which are
  542. failing, e.g.:</p>
  543. <pre><code class="language-sh">pip install twisted
  544. </code></pre>
  545. <p>If you have any other problems, feel free to ask in
  546. <a href="https://matrix.to/#/#synapse:matrix.org">#synapse:matrix.org</a>.</p>
  547. <div style="break-before: page; page-break-before: always;"></div><h1 id="using-postgres"><a class="header" href="#using-postgres">Using Postgres</a></h1>
  548. <p>Synapse supports PostgreSQL versions 9.6 or later.</p>
  549. <h2 id="install-postgres-client-libraries"><a class="header" href="#install-postgres-client-libraries">Install postgres client libraries</a></h2>
  550. <p>Synapse will require the python postgres client library in order to
  551. connect to a postgres database.</p>
  552. <ul>
  553. <li>
  554. <p>If you are using the <a href="setup/installation.html#matrixorg-packages">matrix.org debian/ubuntu
  555. packages</a>, the necessary python
  556. library will already be installed, but you will need to ensure the
  557. low-level postgres library is installed, which you can do with
  558. <code>apt install libpq5</code>.</p>
  559. </li>
  560. <li>
  561. <p>For other pre-built packages, please consult the documentation from
  562. the relevant package.</p>
  563. </li>
  564. <li>
  565. <p>If you installed synapse <a href="setup/installation.html#installing-from-source">in a
  566. virtualenv</a>, you can install
  567. the library with:</p>
  568. <pre><code>~/synapse/env/bin/pip install &quot;matrix-synapse[postgres]&quot;
  569. </code></pre>
  570. <p>(substituting the path to your virtualenv for <code>~/synapse/env</code>, if
  571. you used a different path). You will require the postgres
  572. development files. These are in the <code>libpq-dev</code> package on
  573. Debian-derived distributions.</p>
  574. </li>
  575. </ul>
  576. <h2 id="set-up-database"><a class="header" href="#set-up-database">Set up database</a></h2>
  577. <p>Assuming your PostgreSQL database user is called <code>postgres</code>, first authenticate as the database user with:</p>
  578. <pre><code>su - postgres
  579. # Or, if your system uses sudo to get administrative rights
  580. sudo -u postgres bash
  581. </code></pre>
  582. <p>Then, create a postgres user and a database with:</p>
  583. <pre><code># this will prompt for a password for the new user
  584. createuser --pwprompt synapse_user
  585. createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse
  586. </code></pre>
  587. <p>The above will create a user called <code>synapse_user</code>, and a database called
  588. <code>synapse</code>.</p>
  589. <p>Note that the PostgreSQL database <em>must</em> have the correct encoding set
  590. (as shown above), otherwise it will not be able to store UTF8 strings.</p>
  591. <p>You may need to enable password authentication so <code>synapse_user</code> can
  592. connect to the database. See
  593. <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>
  594. <h2 id="synapse-config"><a class="header" href="#synapse-config">Synapse config</a></h2>
  595. <p>When you are ready to start using PostgreSQL, edit the <code>database</code>
  596. section in your config file to match the following lines:</p>
  597. <pre><code class="language-yaml">database:
  598. name: psycopg2
  599. args:
  600. user: &lt;user&gt;
  601. password: &lt;pass&gt;
  602. database: &lt;db&gt;
  603. host: &lt;host&gt;
  604. cp_min: 5
  605. cp_max: 10
  606. </code></pre>
  607. <p>All key, values in <code>args</code> are passed to the <code>psycopg2.connect(..)</code>
  608. function, except keys beginning with <code>cp_</code>, which are consumed by the
  609. twisted adbapi connection pool. See the <a href="https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS">libpq
  610. documentation</a>
  611. for a list of options which can be passed.</p>
  612. <p>You should consider tuning the <code>args.keepalives_*</code> options if there is any danger of
  613. the connection between your homeserver and database dropping, otherwise Synapse
  614. may block for an extended period while it waits for a response from the
  615. database server. Example values might be:</p>
  616. <pre><code class="language-yaml">database:
  617. args:
  618. # ... as above
  619. # seconds of inactivity after which TCP should send a keepalive message to the server
  620. keepalives_idle: 10
  621. # the number of seconds after which a TCP keepalive message that is not
  622. # acknowledged by the server should be retransmitted
  623. keepalives_interval: 10
  624. # the number of TCP keepalives that can be lost before the client's connection
  625. # to the server is considered dead
  626. keepalives_count: 3
  627. </code></pre>
  628. <h2 id="tuning-postgres"><a class="header" href="#tuning-postgres">Tuning Postgres</a></h2>
  629. <p>The default settings should be fine for most deployments. For larger
  630. scale deployments tuning some of the settings is recommended, details of
  631. which can be found at
  632. <a href="https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server">https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server</a>.</p>
  633. <p>In particular, we've found tuning the following values helpful for
  634. performance:</p>
  635. <ul>
  636. <li><code>shared_buffers</code></li>
  637. <li><code>effective_cache_size</code></li>
  638. <li><code>work_mem</code></li>
  639. <li><code>maintenance_work_mem</code></li>
  640. <li><code>autovacuum_work_mem</code></li>
  641. </ul>
  642. <p>Note that the appropriate values for those fields depend on the amount
  643. of free memory the database host has available.</p>
  644. <h2 id="porting-from-sqlite"><a class="header" href="#porting-from-sqlite">Porting from SQLite</a></h2>
  645. <h3 id="overview"><a class="header" href="#overview">Overview</a></h3>
  646. <p>The script <code>synapse_port_db</code> allows porting an existing synapse server
  647. backed by SQLite to using PostgreSQL. This is done in as a two phase
  648. process:</p>
  649. <ol>
  650. <li>Copy the existing SQLite database to a separate location and run
  651. the port script against that offline database.</li>
  652. <li>Shut down the server. Rerun the port script to port any data that
  653. has come in since taking the first snapshot. Restart server against
  654. the PostgreSQL database.</li>
  655. </ol>
  656. <p>The port script is designed to be run repeatedly against newer snapshots
  657. of the SQLite database file. This makes it safe to repeat step 1 if
  658. there was a delay between taking the previous snapshot and being ready
  659. to do step 2.</p>
  660. <p>It is safe to at any time kill the port script and restart it.</p>
  661. <p>Note that the database may take up significantly more (25% - 100% more)
  662. space on disk after porting to Postgres.</p>
  663. <h3 id="using-the-port-script"><a class="header" href="#using-the-port-script">Using the port script</a></h3>
  664. <p>Firstly, shut down the currently running synapse server and copy its
  665. database file (typically <code>homeserver.db</code>) to another location. Once the
  666. copy is complete, restart synapse. For instance:</p>
  667. <pre><code>./synctl stop
  668. cp homeserver.db homeserver.db.snapshot
  669. ./synctl start
  670. </code></pre>
  671. <p>Copy the old config file into a new config file:</p>
  672. <pre><code>cp homeserver.yaml homeserver-postgres.yaml
  673. </code></pre>
  674. <p>Edit the database section as described in the section <em>Synapse config</em>
  675. above and with the SQLite snapshot located at <code>homeserver.db.snapshot</code>
  676. simply run:</p>
  677. <pre><code>synapse_port_db --sqlite-database homeserver.db.snapshot \
  678. --postgres-config homeserver-postgres.yaml
  679. </code></pre>
  680. <p>The flag <code>--curses</code> displays a coloured curses progress UI.</p>
  681. <p>If the script took a long time to complete, or time has otherwise passed
  682. since the original snapshot was taken, repeat the previous steps with a
  683. newer snapshot.</p>
  684. <p>To complete the conversion shut down the synapse server and run the port
  685. script one last time, e.g. if the SQLite database is at <code>homeserver.db</code>
  686. run:</p>
  687. <pre><code>synapse_port_db --sqlite-database homeserver.db \
  688. --postgres-config homeserver-postgres.yaml
  689. </code></pre>
  690. <p>Once that has completed, change the synapse config to point at the
  691. PostgreSQL database configuration file <code>homeserver-postgres.yaml</code>:</p>
  692. <pre><code>./synctl stop
  693. mv homeserver.yaml homeserver-old-sqlite.yaml
  694. mv homeserver-postgres.yaml homeserver.yaml
  695. ./synctl start
  696. </code></pre>
  697. <p>Synapse should now be running against PostgreSQL.</p>
  698. <h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
  699. <h3 id="alternative-auth-methods"><a class="header" href="#alternative-auth-methods">Alternative auth methods</a></h3>
  700. <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
  701. <code>ident</code>:</p>
  702. <ul>
  703. <li>
  704. <p>If the <code>synapse_user</code> user has a password, add the password to the <code>database:</code>
  705. section of <code>homeserver.yaml</code>. Then add the following to <code>pg_hba.conf</code>:</p>
  706. <pre><code>host synapse synapse_user ::1/128 md5 # or `scram-sha-256` instead of `md5` if you use that
  707. </code></pre>
  708. </li>
  709. <li>
  710. <p>If the <code>synapse_user</code> user does not have a password, then a password doesn't
  711. have to be added to <code>homeserver.yaml</code>. But the following does need to be added
  712. to <code>pg_hba.conf</code>:</p>
  713. <pre><code>host synapse synapse_user ::1/128 trust
  714. </code></pre>
  715. </li>
  716. </ul>
  717. <p>Note that line order matters in <code>pg_hba.conf</code>, so make sure that if you do add a
  718. new line, it is inserted before:</p>
  719. <pre><code>host all all ::1/128 ident
  720. </code></pre>
  721. <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>
  722. <p>Synapse will refuse to set up a new database if it has the wrong values of
  723. <code>COLLATE</code> and <code>CTYPE</code> set, and will log warnings on existing databases. Using
  724. different locales can cause issues if the locale library is updated from
  725. underneath the database, or if a different version of the locale is used on any
  726. replicas.</p>
  727. <p>The safest way to fix the issue is to dump the database and recreate it with
  728. the correct locale parameter (as shown above). It is also possible to change the
  729. parameters on a live database and run a <code>REINDEX</code> on the entire database,
  730. however extreme care must be taken to avoid database corruption.</p>
  731. <p>Note that the above may fail with an error about duplicate rows if corruption
  732. has already occurred, and such duplicate rows will need to be manually removed.</p>
  733. <h3 id="fixing-inconsistent-sequences-error"><a class="header" href="#fixing-inconsistent-sequences-error">Fixing inconsistent sequences error</a></h3>
  734. <p>Synapse uses Postgres sequences to generate IDs for various tables. A sequence
  735. and associated table can get out of sync if, for example, Synapse has been
  736. downgraded and then upgraded again.</p>
  737. <p>To fix the issue shut down Synapse (including any and all workers) and run the
  738. SQL command included in the error message. Once done Synapse should start
  739. successfully.</p>
  740. <div 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>
  741. <p>It is recommended to put a reverse proxy such as
  742. <a href="https://nginx.org/en/docs/http/ngx_http_proxy_module.html">nginx</a>,
  743. <a href="https://httpd.apache.org/docs/current/mod/mod_proxy_http.html">Apache</a>,
  744. <a href="https://caddyserver.com/docs/quick-starts/reverse-proxy">Caddy</a>,
  745. <a href="https://www.haproxy.org/">HAProxy</a> or
  746. <a href="https://man.openbsd.org/relayd.8">relayd</a> in front of Synapse. One advantage
  747. of doing so is that it means that you can expose the default https port
  748. (443) to Matrix clients without needing to run Synapse with root
  749. privileges.</p>
  750. <p>You should configure your reverse proxy to forward requests to <code>/_matrix</code> or
  751. <code>/_synapse/client</code> to Synapse, and have it set the <code>X-Forwarded-For</code> and
  752. <code>X-Forwarded-Proto</code> request headers.</p>
  753. <p>You should remember that Matrix clients and other Matrix servers do not
  754. necessarily need to connect to your server via the same server name or
  755. port. Indeed, clients will use port 443 by default, whereas servers default to
  756. port 8448. Where these are different, we refer to the 'client port' and the
  757. 'federation port'. See <a href="https://matrix.org/docs/spec/server_server/latest#resolving-server-names">the Matrix
  758. specification</a>
  759. for more details of the algorithm used for federation connections, and
  760. <a href="delegate.html">Delegation</a> for instructions on setting up delegation.</p>
  761. <p><strong>NOTE</strong>: Your reverse proxy must not <code>canonicalise</code> or <code>normalise</code>
  762. the requested URI in any way (for example, by decoding <code>%xx</code> escapes).
  763. Beware that Apache <em>will</em> canonicalise URIs unless you specify
  764. <code>nocanon</code>.</p>
  765. <p>Let's assume that we expect clients to connect to our server at
  766. <code>https://matrix.example.com</code>, and other servers to connect at
  767. <code>https://example.com:8448</code>. The following sections detail the configuration of
  768. the reverse proxy and the homeserver.</p>
  769. <h2 id="homeserver-configuration"><a class="header" href="#homeserver-configuration">Homeserver Configuration</a></h2>
  770. <p>The HTTP configuration will need to be updated for Synapse to correctly record
  771. client IP addresses and generate redirect URLs while behind a reverse proxy. </p>
  772. <p>In <code>homeserver.yaml</code> set <code>x_forwarded: true</code> in the port 8008 section and
  773. consider setting <code>bind_addresses: ['127.0.0.1']</code> so that the server only
  774. listens to traffic on localhost. (Do not change <code>bind_addresses</code> to <code>127.0.0.1</code>
  775. when using a containerized Synapse, as that will prevent it from responding
  776. to proxied traffic.)</p>
  777. <h2 id="reverse-proxy-configuration-examples"><a class="header" href="#reverse-proxy-configuration-examples">Reverse-proxy configuration examples</a></h2>
  778. <p><strong>NOTE</strong>: You only need one of these.</p>
  779. <h3 id="nginx"><a class="header" href="#nginx">nginx</a></h3>
  780. <pre><code>server {
  781. listen 443 ssl http2;
  782. listen [::]:443 ssl http2;
  783. # For the federation port
  784. listen 8448 ssl http2 default_server;
  785. listen [::]:8448 ssl http2 default_server;
  786. server_name matrix.example.com;
  787. location ~* ^(\/_matrix|\/_synapse\/client) {
  788. # note: do not add a path (even a single /) after the port in `proxy_pass`,
  789. # otherwise nginx will canonicalise the URI and cause signature verification
  790. # errors.
  791. proxy_pass http://localhost:8008;
  792. proxy_set_header X-Forwarded-For $remote_addr;
  793. proxy_set_header X-Forwarded-Proto $scheme;
  794. proxy_set_header Host $host;
  795. # Nginx by default only allows file uploads up to 1M in size
  796. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  797. client_max_body_size 50M;
  798. }
  799. }
  800. </code></pre>
  801. <h3 id="caddy-v1"><a class="header" href="#caddy-v1">Caddy v1</a></h3>
  802. <pre><code>matrix.example.com {
  803. proxy /_matrix http://localhost:8008 {
  804. transparent
  805. }
  806. proxy /_synapse/client http://localhost:8008 {
  807. transparent
  808. }
  809. }
  810. example.com:8448 {
  811. proxy / http://localhost:8008 {
  812. transparent
  813. }
  814. }
  815. </code></pre>
  816. <h3 id="caddy-v2"><a class="header" href="#caddy-v2">Caddy v2</a></h3>
  817. <pre><code>matrix.example.com {
  818. reverse_proxy /_matrix/* http://localhost:8008
  819. reverse_proxy /_synapse/client/* http://localhost:8008
  820. }
  821. example.com:8448 {
  822. reverse_proxy http://localhost:8008
  823. }
  824. </code></pre>
  825. <p><a href="delegate.html">Delegation</a> example:</p>
  826. <pre><code>(matrix-well-known-header) {
  827. # Headers
  828. header Access-Control-Allow-Origin &quot;*&quot;
  829. header Access-Control-Allow-Methods &quot;GET, POST, PUT, DELETE, OPTIONS&quot;
  830. header Access-Control-Allow-Headers &quot;Origin, X-Requested-With, Content-Type, Accept, Authorization&quot;
  831. header Content-Type &quot;application/json&quot;
  832. }
  833. example.com {
  834. handle /.well-known/matrix/server {
  835. import matrix-well-known-header
  836. respond `{&quot;m.server&quot;:&quot;matrix.example.com:443&quot;}`
  837. }
  838. handle /.well-known/matrix/client {
  839. import matrix-well-known-header
  840. 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;}}`
  841. }
  842. }
  843. matrix.example.com {
  844. reverse_proxy /_matrix/* http://localhost:8008
  845. reverse_proxy /_synapse/client/* http://localhost:8008
  846. }
  847. </code></pre>
  848. <h3 id="apache"><a class="header" href="#apache">Apache</a></h3>
  849. <pre><code>&lt;VirtualHost *:443&gt;
  850. SSLEngine on
  851. ServerName matrix.example.com
  852. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  853. AllowEncodedSlashes NoDecode
  854. ProxyPreserveHost on
  855. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  856. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  857. ProxyPass /_synapse/client http://127.0.0.1:8008/_synapse/client nocanon
  858. ProxyPassReverse /_synapse/client http://127.0.0.1:8008/_synapse/client
  859. &lt;/VirtualHost&gt;
  860. &lt;VirtualHost *:8448&gt;
  861. SSLEngine on
  862. ServerName example.com
  863. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  864. AllowEncodedSlashes NoDecode
  865. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  866. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  867. &lt;/VirtualHost&gt;
  868. </code></pre>
  869. <p><strong>NOTE</strong>: ensure the <code>nocanon</code> options are included.</p>
  870. <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>
  871. <pre><code>&lt;IfModule security2_module&gt;
  872. SecRuleEngine off
  873. &lt;/IfModule&gt;
  874. </code></pre>
  875. <p><strong>NOTE 3</strong>: Missing <code>ProxyPreserveHost on</code> can lead to a redirect loop.</p>
  876. <h3 id="haproxy"><a class="header" href="#haproxy">HAProxy</a></h3>
  877. <pre><code>frontend https
  878. bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
  879. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  880. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  881. http-request set-header X-Forwarded-For %[src]
  882. # Matrix client traffic
  883. acl matrix-host hdr(host) -i matrix.example.com
  884. acl matrix-path path_beg /_matrix
  885. acl matrix-path path_beg /_synapse/client
  886. use_backend matrix if matrix-host matrix-path
  887. frontend matrix-federation
  888. bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
  889. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  890. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  891. http-request set-header X-Forwarded-For %[src]
  892. default_backend matrix
  893. backend matrix
  894. server matrix 127.0.0.1:8008
  895. </code></pre>
  896. <h3 id="relayd"><a class="header" href="#relayd">Relayd</a></h3>
  897. <pre><code>table &lt;webserver&gt; { 127.0.0.1 }
  898. table &lt;matrixserver&gt; { 127.0.0.1 }
  899. http protocol &quot;https&quot; {
  900. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  901. tls keypair &quot;example.com&quot;
  902. match header set &quot;X-Forwarded-For&quot; value &quot;$REMOTE_ADDR&quot;
  903. match header set &quot;X-Forwarded-Proto&quot; value &quot;https&quot;
  904. # set CORS header for .well-known/matrix/server, .well-known/matrix/client
  905. # httpd does not support setting headers, so do it here
  906. match request path &quot;/.well-known/matrix/*&quot; tag &quot;matrix-cors&quot;
  907. match response tagged &quot;matrix-cors&quot; header set &quot;Access-Control-Allow-Origin&quot; value &quot;*&quot;
  908. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  909. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  910. # pass on non-matrix traffic to webserver
  911. pass forward to &lt;webserver&gt;
  912. }
  913. relay &quot;https_traffic&quot; {
  914. listen on egress port 443 tls
  915. protocol &quot;https&quot;
  916. forward to &lt;matrixserver&gt; port 8008 check tcp
  917. forward to &lt;webserver&gt; port 8080 check tcp
  918. }
  919. http protocol &quot;matrix&quot; {
  920. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  921. tls keypair &quot;example.com&quot;
  922. block
  923. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  924. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  925. }
  926. relay &quot;matrix_federation&quot; {
  927. listen on egress port 8448 tls
  928. protocol &quot;matrix&quot;
  929. forward to &lt;matrixserver&gt; port 8008 check tcp
  930. }
  931. </code></pre>
  932. <h2 id="health-check-endpoint"><a class="header" href="#health-check-endpoint">Health check endpoint</a></h2>
  933. <p>Synapse exposes a health check endpoint for use by reverse proxies.
  934. Each configured HTTP listener has a <code>/health</code> endpoint which always returns
  935. 200 OK (and doesn't get logged).</p>
  936. <h2 id="synapse-administration-endpoints"><a class="header" href="#synapse-administration-endpoints">Synapse administration endpoints</a></h2>
  937. <p>Endpoints for administering your Synapse instance are placed under
  938. <code>/_synapse/admin</code>. These require authentication through an access token of an
  939. admin user. However as access to these endpoints grants the caller a lot of power,
  940. we do not recommend exposing them to the public internet without good reason.</p>
  941. <div 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>
  942. <p>You can use Synapse with a forward or outbound proxy. An example of when
  943. this is necessary is in corporate environments behind a DMZ (demilitarized zone).
  944. Synapse supports routing outbound HTTP(S) requests via a proxy. Only HTTP(S)
  945. proxy is supported, not SOCKS proxy or anything else.</p>
  946. <h2 id="configure"><a class="header" href="#configure">Configure</a></h2>
  947. <p>The <code>http_proxy</code>, <code>https_proxy</code>, <code>no_proxy</code> environment variables are used to
  948. specify proxy settings. The environment variable is not case sensitive.</p>
  949. <ul>
  950. <li><code>http_proxy</code>: Proxy server to use for HTTP requests.</li>
  951. <li><code>https_proxy</code>: Proxy server to use for HTTPS requests.</li>
  952. <li><code>no_proxy</code>: Comma-separated list of hosts, IP addresses, or IP ranges in CIDR
  953. format which should not use the proxy. Synapse will directly connect to these hosts.</li>
  954. </ul>
  955. <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>
  956. <ul>
  957. <li>
  958. <p>Supported schemes are <code>http://</code> and <code>https://</code>. The default scheme is <code>http://</code>
  959. for compatibility reasons; it is recommended to set a scheme. If scheme is set
  960. to <code>https://</code> the connection uses TLS between Synapse and the proxy.</p>
  961. <p><strong>NOTE</strong>: Synapse validates the certificates. If the certificate is not
  962. valid, then the connection is dropped.</p>
  963. </li>
  964. <li>
  965. <p>Default port if not given is <code>1080</code>.</p>
  966. </li>
  967. <li>
  968. <p>Username and password are optional and will be used to authenticate against
  969. the proxy.</p>
  970. </li>
  971. </ul>
  972. <p><strong>Examples</strong></p>
  973. <ul>
  974. <li>HTTP_PROXY=http://USERNAME:PASSWORD@10.0.1.1:8080/</li>
  975. <li>HTTPS_PROXY=http://USERNAME:PASSWORD@proxy.example.com:8080/</li>
  976. <li>NO_PROXY=master.hostname.example.com,10.1.0.0/16,172.30.0.0/16</li>
  977. </ul>
  978. <p><strong>NOTE</strong>:
  979. Synapse does not apply the IP blacklist to connections through the proxy (since
  980. the DNS resolution is done by the proxy). It is expected that the proxy or firewall
  981. will apply blacklisting of IP addresses.</p>
  982. <h2 id="connection-types"><a class="header" href="#connection-types">Connection types</a></h2>
  983. <p>The proxy will be <strong>used</strong> for:</p>
  984. <ul>
  985. <li>push</li>
  986. <li>url previews</li>
  987. <li>phone-home stats</li>
  988. <li>recaptcha validation</li>
  989. <li>CAS auth validation</li>
  990. <li>OpenID Connect</li>
  991. <li>Outbound federation</li>
  992. <li>Federation (checking public key revocation)</li>
  993. <li>Fetching public keys of other servers</li>
  994. <li>Downloading remote media</li>
  995. </ul>
  996. <p>It will <strong>not be used</strong> for:</p>
  997. <ul>
  998. <li>Application Services</li>
  999. <li>Identity servers</li>
  1000. <li>In worker configurations
  1001. <ul>
  1002. <li>connections between workers</li>
  1003. <li>connections from workers to Redis</li>
  1004. </ul>
  1005. </li>
  1006. </ul>
  1007. <h2 id="troubleshooting-1"><a class="header" href="#troubleshooting-1">Troubleshooting</a></h2>
  1008. <p>If a proxy server is used with TLS (HTTPS) and no connections are established,
  1009. it is most likely due to the proxy's certificates. To test this, the validation
  1010. in Synapse can be deactivated.</p>
  1011. <p><strong>NOTE</strong>: This has an impact on security and is for testing purposes only!</p>
  1012. <p>To deactivate the certificate validation, the following setting must be made in
  1013. <a href="setup/../usage/configuration/homeserver_sample_config.html">homserver.yaml</a>.</p>
  1014. <pre><code class="language-yaml">use_insecure_ssl_client_just_for_testing_do_not_use: true
  1015. </code></pre>
  1016. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-1"><a class="header" href="#overview-1">Overview</a></h1>
  1017. <p>This document explains how to enable VoIP relaying on your Home Server with
  1018. TURN.</p>
  1019. <p>The synapse Matrix Home Server supports integration with TURN server via the
  1020. <a href="https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00">TURN server REST API</a>. This
  1021. allows the Home Server to generate credentials that are valid for use on the
  1022. TURN server through the use of a secret shared between the Home Server and the
  1023. TURN server.</p>
  1024. <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>
  1025. <h2 id="requirements"><a class="header" href="#requirements">Requirements</a></h2>
  1026. <p>For TURN relaying with <code>coturn</code> to work, it must be hosted on a server/endpoint with a public IP.</p>
  1027. <p>Hosting TURN behind a NAT (even with appropriate port forwarding) is known to cause issues
  1028. and to often not work.</p>
  1029. <h2 id="coturn-setup"><a class="header" href="#coturn-setup"><code>coturn</code> setup</a></h2>
  1030. <h3 id="initial-installation"><a class="header" href="#initial-installation">Initial installation</a></h3>
  1031. <p>The TURN daemon <code>coturn</code> is available from a variety of sources such as native package managers, or installation from source.</p>
  1032. <h4 id="debian-installation"><a class="header" href="#debian-installation">Debian installation</a></h4>
  1033. <p>Just install the debian package:</p>
  1034. <pre><code class="language-sh">apt install coturn
  1035. </code></pre>
  1036. <p>This will install and start a systemd service called <code>coturn</code>.</p>
  1037. <h4 id="source-installation"><a class="header" href="#source-installation">Source installation</a></h4>
  1038. <ol>
  1039. <li>
  1040. <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>
  1041. </li>
  1042. <li>
  1043. <p>Configure it:</p>
  1044. <pre><code>./configure
  1045. </code></pre>
  1046. <p>You may need to install <code>libevent2</code>: if so, you should do so in
  1047. the way recommended by your operating system. You can ignore
  1048. warnings about lack of database support: a database is unnecessary
  1049. for this purpose.</p>
  1050. </li>
  1051. <li>
  1052. <p>Build and install it:</p>
  1053. <pre><code>make
  1054. make install
  1055. </code></pre>
  1056. </li>
  1057. </ol>
  1058. <h3 id="configuration"><a class="header" href="#configuration">Configuration</a></h3>
  1059. <ol>
  1060. <li>
  1061. <p>Create or edit the config file in <code>/etc/turnserver.conf</code>. The relevant
  1062. lines, with example values, are:</p>
  1063. <pre><code>use-auth-secret
  1064. static-auth-secret=[your secret key here]
  1065. realm=turn.myserver.org
  1066. </code></pre>
  1067. <p>See <code>turnserver.conf</code> for explanations of the options. One way to generate
  1068. the <code>static-auth-secret</code> is with <code>pwgen</code>:</p>
  1069. <pre><code>pwgen -s 64 1
  1070. </code></pre>
  1071. <p>A <code>realm</code> must be specified, but its value is somewhat arbitrary. (It is
  1072. sent to clients as part of the authentication flow.) It is conventional to
  1073. set it to be your server name.</p>
  1074. </li>
  1075. <li>
  1076. <p>You will most likely want to configure coturn to write logs somewhere. The
  1077. easiest way is normally to send them to the syslog:</p>
  1078. <pre><code>syslog
  1079. </code></pre>
  1080. <p>(in which case, the logs will be available via <code>journalctl -u coturn</code> on a
  1081. systemd system). Alternatively, coturn can be configured to write to a
  1082. logfile - check the example config file supplied with coturn.</p>
  1083. </li>
  1084. <li>
  1085. <p>Consider your security settings. TURN lets users request a relay which will
  1086. connect to arbitrary IP addresses and ports. The following configuration is
  1087. suggested as a minimum starting point:</p>
  1088. <pre><code># VoIP traffic is all UDP. There is no reason to let users connect to arbitrary TCP endpoints via the relay.
  1089. no-tcp-relay
  1090. # don't let the relay ever try to connect to private IP address ranges within your network (if any)
  1091. # given the turn server is likely behind your firewall, remember to include any privileged public IPs too.
  1092. denied-peer-ip=10.0.0.0-10.255.255.255
  1093. denied-peer-ip=192.168.0.0-192.168.255.255
  1094. denied-peer-ip=172.16.0.0-172.31.255.255
  1095. # special case the turn server itself so that client-&gt;TURN-&gt;TURN-&gt;client flows work
  1096. allowed-peer-ip=10.0.0.1
  1097. # consider whether you want to limit the quota of relayed streams per user (or total) to avoid risk of DoS.
  1098. user-quota=12 # 4 streams per video call, so 12 streams = 3 simultaneous relayed calls per user.
  1099. total-quota=1200
  1100. </code></pre>
  1101. </li>
  1102. <li>
  1103. <p>Also consider supporting TLS/DTLS. To do this, add the following settings
  1104. to <code>turnserver.conf</code>:</p>
  1105. <pre><code># TLS certificates, including intermediate certs.
  1106. # For Let's Encrypt certificates, use `fullchain.pem` here.
  1107. cert=/path/to/fullchain.pem
  1108. # TLS private key file
  1109. pkey=/path/to/privkey.pem
  1110. </code></pre>
  1111. <p>In this case, replace the <code>turn:</code> schemes in the <code>turn_uri</code> settings below
  1112. with <code>turns:</code>.</p>
  1113. <p>We recommend that you only try to set up TLS/DTLS once you have set up a
  1114. basic installation and got it working.</p>
  1115. </li>
  1116. <li>
  1117. <p>Ensure your firewall allows traffic into the TURN server on the ports
  1118. you've configured it to listen on (By default: 3478 and 5349 for TURN
  1119. traffic (remember to allow both TCP and UDP traffic), and ports 49152-65535
  1120. for the UDP relay.)</p>
  1121. </li>
  1122. <li>
  1123. <p>We do not recommend running a TURN server behind NAT, and are not aware of
  1124. anyone doing so successfully.</p>
  1125. <p>If you want to try it anyway, you will at least need to tell coturn its
  1126. external IP address:</p>
  1127. <pre><code>external-ip=192.88.99.1
  1128. </code></pre>
  1129. <p>... and your NAT gateway must forward all of the relayed ports directly
  1130. (eg, port 56789 on the external IP must be always be forwarded to port
  1131. 56789 on the internal IP).</p>
  1132. <p>If you get this working, let us know!</p>
  1133. </li>
  1134. <li>
  1135. <p>(Re)start the turn server:</p>
  1136. <ul>
  1137. <li>
  1138. <p>If you used the Debian package (or have set up a systemd unit yourself):</p>
  1139. <pre><code class="language-sh">systemctl restart coturn
  1140. </code></pre>
  1141. </li>
  1142. <li>
  1143. <p>If you installed from source:</p>
  1144. <pre><code class="language-sh">bin/turnserver -o
  1145. </code></pre>
  1146. </li>
  1147. </ul>
  1148. </li>
  1149. </ol>
  1150. <h2 id="synapse-setup"><a class="header" href="#synapse-setup">Synapse setup</a></h2>
  1151. <p>Your home server configuration file needs the following extra keys:</p>
  1152. <ol>
  1153. <li>&quot;<code>turn_uris</code>&quot;: This needs to be a yaml list of public-facing URIs
  1154. for your TURN server to be given out to your clients. Add separate
  1155. entries for each transport your TURN server supports.</li>
  1156. <li>&quot;<code>turn_shared_secret</code>&quot;: This is the secret shared between your
  1157. Home server and your TURN server, so you should set it to the same
  1158. string you used in turnserver.conf.</li>
  1159. <li>&quot;<code>turn_user_lifetime</code>&quot;: This is the amount of time credentials
  1160. generated by your Home Server are valid for (in milliseconds).
  1161. Shorter times offer less potential for abuse at the expense of
  1162. increased traffic between web clients and your home server to
  1163. refresh credentials. The TURN REST API specification recommends
  1164. one day (86400000).</li>
  1165. <li>&quot;<code>turn_allow_guests</code>&quot;: Whether to allow guest users to use the
  1166. TURN server. This is enabled by default, as otherwise VoIP will
  1167. not work reliably for guests. However, it does introduce a
  1168. security risk as it lets guests connect to arbitrary endpoints
  1169. without having gone through a CAPTCHA or similar to register a
  1170. real account.</li>
  1171. </ol>
  1172. <p>As an example, here is the relevant section of the config file for <code>matrix.org</code>. The
  1173. <code>turn_uris</code> are appropriate for TURN servers listening on the default ports, with no TLS.</p>
  1174. <pre><code>turn_uris: [ &quot;turn:turn.matrix.org?transport=udp&quot;, &quot;turn:turn.matrix.org?transport=tcp&quot; ]
  1175. turn_shared_secret: &quot;n0t4ctuAllymatr1Xd0TorgSshar3d5ecret4obvIousreAsons&quot;
  1176. turn_user_lifetime: 86400000
  1177. turn_allow_guests: True
  1178. </code></pre>
  1179. <p>After updating the homeserver configuration, you must restart synapse:</p>
  1180. <ul>
  1181. <li>If you use synctl:
  1182. <pre><code class="language-sh">cd /where/you/run/synapse
  1183. ./synctl restart
  1184. </code></pre>
  1185. </li>
  1186. <li>If you use systemd:
  1187. <pre><code>systemctl restart matrix-synapse.service
  1188. </code></pre>
  1189. </li>
  1190. </ul>
  1191. <p>... and then reload any clients (or wait an hour for them to refresh their
  1192. settings).</p>
  1193. <h2 id="troubleshooting-2"><a class="header" href="#troubleshooting-2">Troubleshooting</a></h2>
  1194. <p>The normal symptoms of a misconfigured TURN server are that calls between
  1195. devices on different networks ring, but get stuck at &quot;call
  1196. connecting&quot;. Unfortunately, troubleshooting this can be tricky.</p>
  1197. <p>Here are a few things to try:</p>
  1198. <ul>
  1199. <li>
  1200. <p>Check that your TURN server is not behind NAT. As above, we're not aware of
  1201. anyone who has successfully set this up.</p>
  1202. </li>
  1203. <li>
  1204. <p>Check that you have opened your firewall to allow TCP and UDP traffic to the
  1205. TURN ports (normally 3478 and 5479).</p>
  1206. </li>
  1207. <li>
  1208. <p>Check that you have opened your firewall to allow UDP traffic to the UDP
  1209. relay ports (49152-65535 by default).</p>
  1210. </li>
  1211. <li>
  1212. <p>Some WebRTC implementations (notably, that of Google Chrome) appear to get
  1213. confused by TURN servers which are reachable over IPv6 (this appears to be
  1214. an unexpected side-effect of its handling of multiple IP addresses as
  1215. defined by
  1216. <a href="https://tools.ietf.org/html/draft-ietf-rtcweb-ip-handling-12"><code>draft-ietf-rtcweb-ip-handling</code></a>).</p>
  1217. <p>Try removing any AAAA records for your TURN server, so that it is only
  1218. reachable over IPv4.</p>
  1219. </li>
  1220. <li>
  1221. <p>Enable more verbose logging in coturn via the <code>verbose</code> setting:</p>
  1222. <pre><code>verbose
  1223. </code></pre>
  1224. <p>... and then see if there are any clues in its logs.</p>
  1225. </li>
  1226. <li>
  1227. <p>If you are using a browser-based client under Chrome, check
  1228. <code>chrome://webrtc-internals/</code> for insights into the internals of the
  1229. negotiation. On Firefox, check the &quot;Connection Log&quot; on <code>about:webrtc</code>.</p>
  1230. <p>(Understanding the output is beyond the scope of this document!)</p>
  1231. </li>
  1232. <li>
  1233. <p>You can test your Matrix homeserver TURN setup with https://test.voip.librepush.net/.
  1234. Note that this test is not fully reliable yet, so don't be discouraged if
  1235. the test fails.
  1236. <a href="https://github.com/matrix-org/voip-tester">Here</a> is the github repo of the
  1237. source of the tester, where you can file bug reports.</p>
  1238. </li>
  1239. <li>
  1240. <p>There is a WebRTC test tool at
  1241. https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/. To
  1242. use it, you will need a username/password for your TURN server. You can
  1243. either:</p>
  1244. <ul>
  1245. <li>
  1246. <p>look for the <code>GET /_matrix/client/r0/voip/turnServer</code> request made by a
  1247. matrix client to your homeserver in your browser's network inspector. In
  1248. the response you should see <code>username</code> and <code>password</code>. Or:</p>
  1249. </li>
  1250. <li>
  1251. <p>Use the following shell commands:</p>
  1252. <pre><code class="language-sh">secret=staticAuthSecretHere
  1253. u=$((`date +%s` + 3600)):test
  1254. p=$(echo -n $u | openssl dgst -hmac $secret -sha1 -binary | base64)
  1255. echo -e &quot;username: $u\npassword: $p&quot;
  1256. </code></pre>
  1257. <p>Or:</p>
  1258. </li>
  1259. <li>
  1260. <p>Temporarily configure coturn to accept a static username/password. To do
  1261. this, comment out <code>use-auth-secret</code> and <code>static-auth-secret</code> and add the
  1262. following:</p>
  1263. <pre><code>lt-cred-mech
  1264. user=username:password
  1265. </code></pre>
  1266. <p><strong>Note</strong>: these settings will not take effect unless <code>use-auth-secret</code>
  1267. and <code>static-auth-secret</code> are disabled.</p>
  1268. <p>Restart coturn after changing the configuration file.</p>
  1269. <p>Remember to restore the original settings to go back to testing with
  1270. Matrix clients!</p>
  1271. </li>
  1272. </ul>
  1273. <p>If the TURN server is working correctly, you should see at least one <code>relay</code>
  1274. entry in the results.</p>
  1275. </li>
  1276. </ul>
  1277. <div style="break-before: page; page-break-before: always;"></div><h1 id="delegation"><a class="header" href="#delegation">Delegation</a></h1>
  1278. <p>By default, other homeservers will expect to be able to reach yours via
  1279. your <code>server_name</code>, on port 8448. For example, if you set your <code>server_name</code>
  1280. to <code>example.com</code> (so that your user names look like <code>@user:example.com</code>),
  1281. other servers will try to connect to yours at <code>https://example.com:8448/</code>.</p>
  1282. <p>Delegation is a Matrix feature allowing a homeserver admin to retain a
  1283. <code>server_name</code> of <code>example.com</code> so that user IDs, room aliases, etc continue
  1284. to look like <code>*:example.com</code>, whilst having federation traffic routed
  1285. to a different server and/or port (e.g. <code>synapse.example.com:443</code>).</p>
  1286. <h2 id="well-known-delegation"><a class="header" href="#well-known-delegation">.well-known delegation</a></h2>
  1287. <p>To use this method, you need to be able to alter the
  1288. <code>server_name</code> 's https server to serve the <code>/.well-known/matrix/server</code>
  1289. URL. Having an active server (with a valid TLS certificate) serving your
  1290. <code>server_name</code> domain is out of the scope of this documentation.</p>
  1291. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> should
  1292. return a JSON structure containing the key <code>m.server</code> like so:</p>
  1293. <pre><code class="language-json">{
  1294. &quot;m.server&quot;: &quot;&lt;synapse.server.name&gt;[:&lt;yourport&gt;]&quot;
  1295. }
  1296. </code></pre>
  1297. <p>In our example, this would mean that URL <code>https://example.com/.well-known/matrix/server</code>
  1298. should return:</p>
  1299. <pre><code class="language-json">{
  1300. &quot;m.server&quot;: &quot;synapse.example.com:443&quot;
  1301. }
  1302. </code></pre>
  1303. <p>Note, specifying a port is optional. If no port is specified, then it defaults
  1304. to 8448.</p>
  1305. <p>With .well-known delegation, federating servers will check for a valid TLS
  1306. certificate for the delegated hostname (in our example: <code>synapse.example.com</code>).</p>
  1307. <h2 id="srv-dns-record-delegation"><a class="header" href="#srv-dns-record-delegation">SRV DNS record delegation</a></h2>
  1308. <p>It is also possible to do delegation using a SRV DNS record. However, that is
  1309. considered an advanced topic since it's a bit complex to set up, and <code>.well-known</code>
  1310. delegation is already enough in most cases.</p>
  1311. <p>However, if you really need it, you can find some documentation on how such a
  1312. 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
  1313. specification</a>.</p>
  1314. <h2 id="delegation-faq"><a class="header" href="#delegation-faq">Delegation FAQ</a></h2>
  1315. <h3 id="when-do-i-need-delegation"><a class="header" href="#when-do-i-need-delegation">When do I need delegation?</a></h3>
  1316. <p>If your homeserver's APIs are accessible on the default federation port (8448)
  1317. and the domain your <code>server_name</code> points to, you do not need any delegation.</p>
  1318. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  1319. fresh server, you could install Synapse on that host, giving it a <code>server_name</code>
  1320. of <code>example.com</code>, and once a reverse proxy has been set up to proxy all requests
  1321. sent to the port <code>8448</code> and serve TLS certificates for <code>example.com</code>, you
  1322. wouldn't need any delegation set up.</p>
  1323. <p><strong>However</strong>, if your homeserver's APIs aren't accessible on port 8448 and on the
  1324. domain <code>server_name</code> points to, you will need to let other servers know how to
  1325. find it using delegation.</p>
  1326. <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>
  1327. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  1328. find it easier to direct federation traffic to a reverse proxy and manage their
  1329. own TLS certificates, and this is a supported configuration.</p>
  1330. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  1331. reverse proxy.</p>
  1332. <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>
  1333. <p>This is no longer necessary. If you are using a reverse proxy for all of your
  1334. TLS traffic, then you can set <code>no_tls: True</code> in the Synapse config.</p>
  1335. <p>In that case, the only reason Synapse needs the certificate is to populate a legacy
  1336. <code>tls_fingerprints</code> field in the federation API. This is ignored by Synapse 0.99.0
  1337. and later, and the only time pre-0.99 Synapses will check it is when attempting to
  1338. fetch the server keys - and generally this is delegated via <code>matrix.org</code>, which
  1339. is running a modern version of Synapse.</p>
  1340. <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>
  1341. <p>No. There is nothing stopping you from using different certificates,
  1342. particularly if you are using a reverse proxy.</p>
  1343. <div style="break-before: page; page-break-before: always;"></div><h1 id="upgrading-synapse"><a class="header" href="#upgrading-synapse">Upgrading Synapse</a></h1>
  1344. <p>Before upgrading check if any special steps are required to upgrade from
  1345. the version you currently have installed to the current version of
  1346. Synapse. The extra instructions that may be required are listed later in
  1347. this document.</p>
  1348. <ul>
  1349. <li>
  1350. <p>Check that your versions of Python and PostgreSQL are still
  1351. supported.</p>
  1352. <p>Synapse follows upstream lifecycles for <a href="https://endoflife.date/python">Python</a> and
  1353. <a href="https://endoflife.date/postgresql">PostgreSQL</a>, and removes support for versions
  1354. which are no longer maintained.</p>
  1355. <p>The website <a href="https://endoflife.date">https://endoflife.date</a> also offers convenient
  1356. summaries.</p>
  1357. </li>
  1358. <li>
  1359. <p>If Synapse was installed using <a href="setup/installation.html#prebuilt-packages">prebuilt
  1360. packages</a>, you will need to follow the
  1361. normal process for upgrading those packages.</p>
  1362. </li>
  1363. <li>
  1364. <p>If Synapse was installed from source, then:</p>
  1365. <ol>
  1366. <li>
  1367. <p>Activate the virtualenv before upgrading. For example, if
  1368. Synapse is installed in a virtualenv in <code>~/synapse/env</code> then
  1369. run:</p>
  1370. <pre><code class="language-bash">source ~/synapse/env/bin/activate
  1371. </code></pre>
  1372. </li>
  1373. <li>
  1374. <p>If Synapse was installed using pip then upgrade to the latest
  1375. version by running:</p>
  1376. <pre><code class="language-bash">pip install --upgrade matrix-synapse
  1377. </code></pre>
  1378. <p>If Synapse was installed using git then upgrade to the latest
  1379. version by running:</p>
  1380. <pre><code class="language-bash">git pull
  1381. pip install --upgrade .
  1382. </code></pre>
  1383. </li>
  1384. <li>
  1385. <p>Restart Synapse:</p>
  1386. <pre><code class="language-bash">./synctl restart
  1387. </code></pre>
  1388. </li>
  1389. </ol>
  1390. </li>
  1391. </ul>
  1392. <p>To check whether your update was successful, you can check the running
  1393. server version with:</p>
  1394. <pre><code class="language-bash"># you may need to replace 'localhost:8008' if synapse is not configured
  1395. # to listen on port 8008.
  1396. curl http://localhost:8008/_synapse/admin/v1/server_version
  1397. </code></pre>
  1398. <h2 id="rolling-back-to-older-versions"><a class="header" href="#rolling-back-to-older-versions">Rolling back to older versions</a></h2>
  1399. <p>Rolling back to previous releases can be difficult, due to database
  1400. schema changes between releases. Where we have been able to test the
  1401. rollback process, this will be noted below.</p>
  1402. <p>In general, you will need to undo any changes made during the upgrade
  1403. process, for example:</p>
  1404. <ul>
  1405. <li>
  1406. <p>pip:</p>
  1407. <pre><code class="language-bash">source env/bin/activate
  1408. # replace `1.3.0` accordingly:
  1409. pip install matrix-synapse==1.3.0
  1410. </code></pre>
  1411. </li>
  1412. <li>
  1413. <p>Debian:</p>
  1414. <pre><code class="language-bash"># replace `1.3.0` and `stretch` accordingly:
  1415. wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1416. dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1417. </code></pre>
  1418. </li>
  1419. </ul>
  1420. <h1 id="upgrading-to-v1440"><a class="header" href="#upgrading-to-v1440">Upgrading to v1.44.0</a></h1>
  1421. <h2 id="the-url-preview-cache-is-no-longer-mirrored-to-storage-providers"><a class="header" href="#the-url-preview-cache-is-no-longer-mirrored-to-storage-providers">The URL preview cache is no longer mirrored to storage providers</a></h2>
  1422. <p>The <code>url_cache/</code> and <code>url_cache_thumbnails/</code> directories in the media store are
  1423. no longer mirrored to storage providers. These two directories can be safely
  1424. deleted from any configured storage providers to reclaim space.</p>
  1425. <h1 id="upgrading-to-v1430"><a class="header" href="#upgrading-to-v1430">Upgrading to v1.43.0</a></h1>
  1426. <h2 id="the-spaces-summary-apis-can-now-be-handled-by-workers"><a class="header" href="#the-spaces-summary-apis-can-now-be-handled-by-workers">The spaces summary APIs can now be handled by workers</a></h2>
  1427. <p>The <a href="https://matrix-org.github.io/synapse/latest/workers.html#available-worker-applications">available worker applications documentation</a>
  1428. has been updated to reflect that calls to the <code>/spaces</code>, <code>/hierarchy</code>, and
  1429. <code>/summary</code> endpoints can now be routed to workers for both client API and
  1430. federation requests.</p>
  1431. <h1 id="upgrading-to-v1420"><a class="header" href="#upgrading-to-v1420">Upgrading to v1.42.0</a></h1>
  1432. <h2 id="removal-of-old-room-admin-api"><a class="header" href="#removal-of-old-room-admin-api">Removal of old Room Admin API</a></h2>
  1433. <p>The following admin APIs were deprecated in <a href="https://github.com/matrix-org/synapse/blob/v1.25.0/CHANGES.md#removal-warning">Synapse 1.25</a>
  1434. (released on 2021-01-13) and have now been removed:</p>
  1435. <ul>
  1436. <li><code>POST /_synapse/admin/v1/purge_room</code></li>
  1437. <li><code>POST /_synapse/admin/v1/shutdown_room/&lt;room_id&gt;</code></li>
  1438. </ul>
  1439. <p>Any scripts still using the above APIs should be converted to use the
  1440. <a href="https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#delete-room-api">Delete Room API</a>.</p>
  1441. <h2 id="user-interactive-authentication-fallback-templates-can-now-display-errors"><a class="header" href="#user-interactive-authentication-fallback-templates-can-now-display-errors">User-interactive authentication fallback templates can now display errors</a></h2>
  1442. <p>This may affect you if you make use of custom HTML templates for the
  1443. <a href="../synapse/res/templates/recaptcha.html">reCAPTCHA</a> or
  1444. <a href="../synapse/res/templates/terms.html">terms</a> fallback pages.</p>
  1445. <p>The template is now provided an <code>error</code> variable if the authentication
  1446. process failed. See the default templates linked above for an example.</p>
  1447. <h2 id="removal-of-out-of-date-email-pushers"><a class="header" href="#removal-of-out-of-date-email-pushers">Removal of out-of-date email pushers</a></h2>
  1448. <p>Users will stop receiving message updates via email for addresses that were
  1449. once, but not still, linked to their account.</p>
  1450. <h1 id="upgrading-to-v1410"><a class="header" href="#upgrading-to-v1410">Upgrading to v1.41.0</a></h1>
  1451. <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>
  1452. <p>Since Synapse 1.6.0 (2019-11-26) you can set a proxy for outbound HTTP requests via
  1453. http_proxy/https_proxy environment variables. This proxy was set for:</p>
  1454. <ul>
  1455. <li>push</li>
  1456. <li>url previews</li>
  1457. <li>phone-home stats</li>
  1458. <li>recaptcha validation</li>
  1459. <li>CAS auth validation</li>
  1460. <li>OpenID Connect</li>
  1461. <li>Federation (checking public key revocation)</li>
  1462. </ul>
  1463. <p>In this version we have added support for outbound requests for:</p>
  1464. <ul>
  1465. <li>Outbound federation</li>
  1466. <li>Downloading remote media</li>
  1467. <li>Fetching public keys of other servers</li>
  1468. </ul>
  1469. <p>These requests use the same proxy configuration. If you have a proxy configuration we
  1470. recommend to verify the configuration. It may be necessary to adjust the <code>no_proxy</code>
  1471. environment variable.</p>
  1472. <p>See <a href="setup/forward_proxy.html">using a forward proxy with Synapse documentation</a> for
  1473. details.</p>
  1474. <h2 id="deprecation-of-template_dir"><a class="header" href="#deprecation-of-template_dir">Deprecation of <code>template_dir</code></a></h2>
  1475. <p>The <code>template_dir</code> settings in the <code>sso</code>, <code>account_validity</code> and <code>email</code> sections of the
  1476. configuration file are now deprecated. Server admins should use the new
  1477. <code>templates.custom_template_directory</code> setting in the configuration file and use one single
  1478. custom template directory for all aforementioned features. Template file names remain
  1479. unchanged. See <a href="https://matrix-org.github.io/synapse/latest/templates.html">the related documentation</a>
  1480. for more information and examples.</p>
  1481. <p>We plan to remove support for these settings in October 2021.</p>
  1482. <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>
  1483. <p>The <a href="https://matrix-org.github.io/synapse/latest/workers.html#synapseappmedia_repository">media repository worker documentation</a>
  1484. has been updated to reflect that calls to <code>/_synapse/admin/v1/users/{userId}/media</code>
  1485. must now be handled by media repository workers. This is due to the new <code>DELETE</code> method
  1486. of this endpoint modifying the media store.</p>
  1487. <h1 id="upgrading-to-v1390"><a class="header" href="#upgrading-to-v1390">Upgrading to v1.39.0</a></h1>
  1488. <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>
  1489. <p>The current third-party rules module interface is deprecated in favour of the new generic
  1490. modules system introduced in Synapse v1.37.0. Authors of third-party rules modules can refer
  1491. to <a href="modules.html#porting-an-existing-module-that-uses-the-old-interface">this documentation</a>
  1492. to update their modules. Synapse administrators can refer to <a href="modules.html#using-modules">this documentation</a>
  1493. to update their configuration once the modules they are using have been updated.</p>
  1494. <p>We plan to remove support for the current third-party rules interface in September 2021.</p>
  1495. <h1 id="upgrading-to-v1380"><a class="header" href="#upgrading-to-v1380">Upgrading to v1.38.0</a></h1>
  1496. <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>
  1497. <p>This release includes a database schema update which requires re-indexing one of
  1498. the larger tables in the database, <code>events</code>. This could result in increased
  1499. disk I/O for several hours or days after upgrading while the migration
  1500. completes. Furthermore, because we have to keep the old indexes until the new
  1501. indexes are ready, it could result in a significant, temporary, increase in
  1502. disk space.</p>
  1503. <p>To get a rough idea of the disk space required, check the current size of one
  1504. of the indexes. For example, from a <code>psql</code> shell, run the following sql:</p>
  1505. <pre><code class="language-sql">SELECT pg_size_pretty(pg_relation_size('events_order_room'));
  1506. </code></pre>
  1507. <p>We need to rebuild <strong>four</strong> indexes, so you will need to multiply this result
  1508. by four to give an estimate of the disk space required. For example, on one
  1509. particular server:</p>
  1510. <pre><code>synapse=# select pg_size_pretty(pg_relation_size('events_order_room'));
  1511. pg_size_pretty
  1512. ----------------
  1513. 288 MB
  1514. (1 row)
  1515. </code></pre>
  1516. <p>On this server, it would be wise to ensure that at least 1152MB are free.</p>
  1517. <p>The additional disk space will be freed once the migration completes.</p>
  1518. <p>SQLite databases are unaffected by this change.</p>
  1519. <h1 id="upgrading-to-v1370"><a class="header" href="#upgrading-to-v1370">Upgrading to v1.37.0</a></h1>
  1520. <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>
  1521. <p>The current spam checker interface is deprecated in favour of a new generic modules system.
  1522. Authors of spam checker modules can refer to <a href="modules.html#porting-an-existing-module-that-uses-the-old-interface">this
  1523. documentation</a>
  1524. to update their modules. Synapse administrators can refer to <a href="modules.html#using-modules">this
  1525. documentation</a>
  1526. to update their configuration once the modules they are using have been updated.</p>
  1527. <p>We plan to remove support for the current spam checker interface in August 2021.</p>
  1528. <p>More module interfaces will be ported over to this new generic system in future versions
  1529. of Synapse.</p>
  1530. <h1 id="upgrading-to-v1340"><a class="header" href="#upgrading-to-v1340">Upgrading to v1.34.0</a></h1>
  1531. <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>
  1532. <p>The <code>room_invite_state_types</code> configuration setting has been deprecated
  1533. 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
  1534. file</a>.</p>
  1535. <p>If you have set <code>room_invite_state_types</code> to the default value you
  1536. should simply remove it from your configuration file. The default value
  1537. used to be:</p>
  1538. <pre><code class="language-yaml">room_invite_state_types:
  1539. - &quot;m.room.join_rules&quot;
  1540. - &quot;m.room.canonical_alias&quot;
  1541. - &quot;m.room.avatar&quot;
  1542. - &quot;m.room.encryption&quot;
  1543. - &quot;m.room.name&quot;
  1544. </code></pre>
  1545. <p>If you have customised this value, you should remove
  1546. <code>room_invite_state_types</code> and configure <code>room_prejoin_state</code> instead.</p>
  1547. <h1 id="upgrading-to-v1330"><a class="header" href="#upgrading-to-v1330">Upgrading to v1.33.0</a></h1>
  1548. <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>
  1549. <p>This may affect you if you have enabled the account validity feature,
  1550. and have made use of a custom HTML template specified by the
  1551. <code>account_validity.template_dir</code> or
  1552. <code>account_validity.account_renewed_html_path</code> Synapse config options.</p>
  1553. <p>The template can now accept an <code>expiration_ts</code> variable, which
  1554. represents the unix timestamp in milliseconds for the future date of
  1555. 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
  1556. template</a>
  1557. for an example of usage.</p>
  1558. <p>ALso note that a new HTML template, <code>account_previously_renewed.html</code>,
  1559. has been added. This is is shown to users when they attempt to renew
  1560. their account with a valid renewal token that has already been used
  1561. before. The default template contents can been found
  1562. <a href="https://github.com/matrix-org/synapse/blob/release-v1.33.0/synapse/res/templates/account_previously_renewed.html">here</a>,
  1563. and can also accept an <code>expiration_ts</code> variable. This template replaces
  1564. the error message users would previously see upon attempting to use a
  1565. valid renewal token more than once.</p>
  1566. <h1 id="upgrading-to-v1320"><a class="header" href="#upgrading-to-v1320">Upgrading to v1.32.0</a></h1>
  1567. <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>
  1568. <p>This release introduces <a href="https://github.com/matrix-org/synapse/issues/9853">a
  1569. regression</a> that can
  1570. overwhelm connected Prometheus instances. This issue is not present in
  1571. Synapse v1.32.0rc1.</p>
  1572. <p>If you have been affected, please downgrade to 1.31.0. You then may need
  1573. to remove excess writeahead logs in order for Prometheus to recover.
  1574. Instructions for doing so are provided
  1575. <a href="https://github.com/matrix-org/synapse/pull/9854#issuecomment-823472183">here</a>.</p>
  1576. <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>
  1577. <p>In line with our <a href="deprecation_policy.html">deprecation policy</a>,
  1578. we've dropped support for Python 3.5 and PostgreSQL 9.5, as they are no
  1579. longer supported upstream.</p>
  1580. <p>This release of Synapse requires Python 3.6+ and PostgresSQL 9.6+ or
  1581. SQLite 3.22+.</p>
  1582. <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>
  1583. <p>The deprecated v1 &quot;list accounts&quot; admin API
  1584. (<code>GET /_synapse/admin/v1/users/&lt;user_id&gt;</code>) has been removed in this
  1585. version.</p>
  1586. <p>The <a href="admin_api/user_admin_api.html#list-accounts">v2 list accounts API</a>
  1587. has been available since Synapse 1.7.0 (2019-12-13), and is accessible
  1588. under <code>GET /_synapse/admin/v2/users</code>.</p>
  1589. <p>The deprecation of the old endpoint was announced with Synapse 1.28.0
  1590. (released on 2021-02-25).</p>
  1591. <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>
  1592. <p>In compliance with the <a href="https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions">Application Service
  1593. spec</a>,
  1594. Application Services are now required to use the
  1595. <code>m.login.application_service</code> type when registering users via the
  1596. <code>/_matrix/client/r0/register</code> endpoint. This behaviour was deprecated in
  1597. Synapse v1.30.0.</p>
  1598. <p>Please ensure your Application Services are up to date.</p>
  1599. <h1 id="upgrading-to-v1290"><a class="header" href="#upgrading-to-v1290">Upgrading to v1.29.0</a></h1>
  1600. <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>
  1601. <p>When using Synapse with a reverse proxy (in particular, when using the
  1602. [x_forwarded]{.title-ref} option on an HTTP listener), Synapse now
  1603. expects to receive an [X-Forwarded-Proto]{.title-ref} header on incoming
  1604. HTTP requests. If it is not set, Synapse will log a warning on each
  1605. received request.</p>
  1606. <p>To avoid the warning, administrators using a reverse proxy should ensure
  1607. that the reverse proxy sets [X-Forwarded-Proto]{.title-ref} header to
  1608. [https]{.title-ref} or [http]{.title-ref} to indicate the protocol used
  1609. by the client.</p>
  1610. <p>Synapse also requires the [Host]{.title-ref} header to be preserved.</p>
  1611. <p>See the <a href="reverse_proxy.html">reverse proxy documentation</a>, where the
  1612. example configurations have been updated to show how to set these
  1613. headers.</p>
  1614. <p>(Users of <a href="https://caddyserver.com/">Caddy</a> are unaffected, since we
  1615. believe it sets [X-Forwarded-Proto]{.title-ref} by default.)</p>
  1616. <h1 id="upgrading-to-v1270"><a class="header" href="#upgrading-to-v1270">Upgrading to v1.27.0</a></h1>
  1617. <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>
  1618. <p>This version changes the URI used for callbacks from OAuth2 and SAML2
  1619. identity providers:</p>
  1620. <ul>
  1621. <li>
  1622. <p>If your server is configured for single sign-on via an OpenID
  1623. Connect or OAuth2 identity provider, you will need to add
  1624. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> to the list
  1625. of permitted &quot;redirect URIs&quot; at the identity provider.</p>
  1626. <p>See the <a href="openid.html">OpenID docs</a> for more information on setting
  1627. up OpenID Connect.</p>
  1628. </li>
  1629. <li>
  1630. <p>If your server is configured for single sign-on via a SAML2 identity
  1631. provider, you will need to add
  1632. <code>[synapse public baseurl]/_synapse/client/saml2/authn_response</code> as a
  1633. permitted &quot;ACS location&quot; (also known as &quot;allowed callback URLs&quot;)
  1634. at the identity provider.</p>
  1635. <p>The &quot;Issuer&quot; in the &quot;AuthnRequest&quot; to the SAML2 identity
  1636. provider is also updated to
  1637. <code>[synapse public baseurl]/_synapse/client/saml2/metadata.xml</code>. If
  1638. your SAML2 identity provider uses this property to validate or
  1639. otherwise identify Synapse, its configuration will need to be
  1640. updated to use the new URL. Alternatively you could create a new,
  1641. separate &quot;EntityDescriptor&quot; in your SAML2 identity provider with
  1642. the new URLs and leave the URLs in the existing &quot;EntityDescriptor&quot;
  1643. as they were.</p>
  1644. </li>
  1645. </ul>
  1646. <h2 id="changes-to-html-templates"><a class="header" href="#changes-to-html-templates">Changes to HTML templates</a></h2>
  1647. <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
  1648. autoescape</a>
  1649. enabled for files ending in <code>.html</code>, <code>.htm</code>, and <code>.xml</code>. If you have
  1650. customised these templates and see issues when viewing them you might
  1651. need to update them. It is expected that most configurations will need
  1652. no changes.</p>
  1653. <p>If you have customised the templates <em>names</em> for these templates, it is
  1654. recommended to verify they end in <code>.html</code> to ensure autoescape is
  1655. enabled.</p>
  1656. <p>The above applies to the following templates:</p>
  1657. <ul>
  1658. <li><code>add_threepid.html</code></li>
  1659. <li><code>add_threepid_failure.html</code></li>
  1660. <li><code>add_threepid_success.html</code></li>
  1661. <li><code>notice_expiry.html</code></li>
  1662. <li><code>notice_expiry.html</code></li>
  1663. <li><code>notif_mail.html</code> (which, by default, includes <code>room.html</code> and
  1664. <code>notif.html</code>)</li>
  1665. <li><code>password_reset.html</code></li>
  1666. <li><code>password_reset_confirmation.html</code></li>
  1667. <li><code>password_reset_failure.html</code></li>
  1668. <li><code>password_reset_success.html</code></li>
  1669. <li><code>registration.html</code></li>
  1670. <li><code>registration_failure.html</code></li>
  1671. <li><code>registration_success.html</code></li>
  1672. <li><code>sso_account_deactivated.html</code></li>
  1673. <li><code>sso_auth_bad_user.html</code></li>
  1674. <li><code>sso_auth_confirm.html</code></li>
  1675. <li><code>sso_auth_success.html</code></li>
  1676. <li><code>sso_error.html</code></li>
  1677. <li><code>sso_login_idp_picker.html</code></li>
  1678. <li><code>sso_redirect_confirm.html</code></li>
  1679. </ul>
  1680. <h1 id="upgrading-to-v1260"><a class="header" href="#upgrading-to-v1260">Upgrading to v1.26.0</a></h1>
  1681. <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>
  1682. <p>v1.26.0 includes a lot of large changes. If something problematic
  1683. occurs, you may want to roll-back to a previous version of Synapse.
  1684. Because v1.26.0 also includes a new database schema version, reverting
  1685. that version is also required alongside the generic rollback
  1686. instructions mentioned above. In short, to roll back to v1.25.0 you need
  1687. to:</p>
  1688. <ol>
  1689. <li>
  1690. <p>Stop the server</p>
  1691. </li>
  1692. <li>
  1693. <p>Decrease the schema version in the database:</p>
  1694. <pre><code class="language-sql">UPDATE schema_version SET version = 58;
  1695. </code></pre>
  1696. </li>
  1697. <li>
  1698. <p>Delete the ignored users &amp; chain cover data:</p>
  1699. <pre><code class="language-sql">DROP TABLE IF EXISTS ignored_users;
  1700. UPDATE rooms SET has_auth_chain_index = false;
  1701. </code></pre>
  1702. <p>For PostgreSQL run:</p>
  1703. <pre><code class="language-sql">TRUNCATE event_auth_chain_links;
  1704. TRUNCATE event_auth_chains;
  1705. </code></pre>
  1706. <p>For SQLite run:</p>
  1707. <pre><code class="language-sql">DELETE FROM event_auth_chain_links;
  1708. DELETE FROM event_auth_chains;
  1709. </code></pre>
  1710. </li>
  1711. <li>
  1712. <p>Mark the deltas as not run (so they will re-run on upgrade).</p>
  1713. <pre><code class="language-sql">DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/01ignored_user.py&quot;;
  1714. DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/06chain_cover_index.sql&quot;;
  1715. </code></pre>
  1716. </li>
  1717. <li>
  1718. <p>Downgrade Synapse by following the instructions for your
  1719. installation method in the &quot;Rolling back to older versions&quot;
  1720. section above.</p>
  1721. </li>
  1722. </ol>
  1723. <h1 id="upgrading-to-v1250"><a class="header" href="#upgrading-to-v1250">Upgrading to v1.25.0</a></h1>
  1724. <h2 id="last-release-supporting-python-35"><a class="header" href="#last-release-supporting-python-35">Last release supporting Python 3.5</a></h2>
  1725. <p>This is the last release of Synapse which guarantees support with Python
  1726. 3.5, which passed its upstream End of Life date several months ago.</p>
  1727. <p>We will attempt to maintain support through March 2021, but without
  1728. guarantees.</p>
  1729. <p>In the future, Synapse will follow upstream schedules for ending support
  1730. of older versions of Python and PostgreSQL. Please upgrade to at least
  1731. Python 3.6 and PostgreSQL 9.6 as soon as possible.</p>
  1732. <h2 id="blacklisting-ip-ranges"><a class="header" href="#blacklisting-ip-ranges">Blacklisting IP ranges</a></h2>
  1733. <p>Synapse v1.25.0 includes new settings, <code>ip_range_blacklist</code> and
  1734. <code>ip_range_whitelist</code>, for controlling outgoing requests from Synapse for
  1735. federation, identity servers, push, and for checking key validity for
  1736. third-party invite events. The previous setting,
  1737. <code>federation_ip_range_blacklist</code>, is deprecated. The new
  1738. <code>ip_range_blacklist</code> defaults to private IP ranges if it is not defined.</p>
  1739. <p>If you have never customised <code>federation_ip_range_blacklist</code> it is
  1740. recommended that you remove that setting.</p>
  1741. <p>If you have customised <code>federation_ip_range_blacklist</code> you should update
  1742. the setting name to <code>ip_range_blacklist</code>.</p>
  1743. <p>If you have a custom push server that is reached via private IP space
  1744. you may need to customise <code>ip_range_blacklist</code> or <code>ip_range_whitelist</code>.</p>
  1745. <h1 id="upgrading-to-v1240"><a class="header" href="#upgrading-to-v1240">Upgrading to v1.24.0</a></h1>
  1746. <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>
  1747. <p>This release allows the OpenID Connect mapping provider to perform
  1748. normalisation of the localpart of the Matrix ID. This allows for the
  1749. mapping provider to specify different algorithms, instead of the
  1750. <a href="https://matrix.org/docs/spec/appendices#mapping-from-other-character-sets">default
  1751. way</a>.</p>
  1752. <p>If your Synapse configuration uses a custom mapping provider
  1753. ([oidc_config.user_mapping_provider.module]{.title-ref} is specified and
  1754. not equal to
  1755. [synapse.handlers.oidc_handler.JinjaOidcMappingProvider]{.title-ref})
  1756. then you <em>must</em> ensure that [map_user_attributes]{.title-ref} of the
  1757. mapping provider performs some normalisation of the
  1758. [localpart]{.title-ref} returned. To match previous behaviour you can
  1759. use the [map_username_to_mxid_localpart]{.title-ref} function provided
  1760. by Synapse. An example is shown below:</p>
  1761. <pre><code class="language-python">from synapse.types import map_username_to_mxid_localpart
  1762. class MyMappingProvider:
  1763. def map_user_attributes(self, userinfo, token):
  1764. # ... your custom logic ...
  1765. sso_user_id = ...
  1766. localpart = map_username_to_mxid_localpart(sso_user_id)
  1767. return {&quot;localpart&quot;: localpart}
  1768. </code></pre>
  1769. <h2 id="removal-historical-synapse-admin-api"><a class="header" href="#removal-historical-synapse-admin-api">Removal historical Synapse Admin API</a></h2>
  1770. <p>Historically, the Synapse Admin API has been accessible under:</p>
  1771. <ul>
  1772. <li><code>/_matrix/client/api/v1/admin</code></li>
  1773. <li><code>/_matrix/client/unstable/admin</code></li>
  1774. <li><code>/_matrix/client/r0/admin</code></li>
  1775. <li><code>/_synapse/admin/v1</code></li>
  1776. </ul>
  1777. <p>The endpoints with <code>/_matrix/client/*</code> prefixes have been removed as of
  1778. v1.24.0. The Admin API is now only accessible under:</p>
  1779. <ul>
  1780. <li><code>/_synapse/admin/v1</code></li>
  1781. </ul>
  1782. <p>The only exception is the [/admin/whois]{.title-ref} endpoint, which is
  1783. <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
  1784. API</a>.</p>
  1785. <p>The deprecation of the old endpoints was announced with Synapse 1.20.0
  1786. (released on 2020-09-22) and makes it easier for homeserver admins to
  1787. lock down external access to the Admin API endpoints.</p>
  1788. <h1 id="upgrading-to-v1230"><a class="header" href="#upgrading-to-v1230">Upgrading to v1.23.0</a></h1>
  1789. <h2 id="structured-logging-configuration-breaking-changes"><a class="header" href="#structured-logging-configuration-breaking-changes">Structured logging configuration breaking changes</a></h2>
  1790. <p>This release deprecates use of the <code>structured: true</code> logging
  1791. configuration for structured logging. If your logging configuration
  1792. contains <code>structured: true</code> then it should be modified based on the
  1793. <a href="structured_logging.html">structured logging documentation</a>.</p>
  1794. <p>The <code>structured</code> and <code>drains</code> logging options are now deprecated and
  1795. should be replaced by standard logging configuration of <code>handlers</code> and
  1796. <code>formatters</code>.</p>
  1797. <p>A future will release of Synapse will make using <code>structured: true</code> an
  1798. error.</p>
  1799. <h1 id="upgrading-to-v1220"><a class="header" href="#upgrading-to-v1220">Upgrading to v1.22.0</a></h1>
  1800. <h2 id="thirdpartyeventrules-breaking-changes"><a class="header" href="#thirdpartyeventrules-breaking-changes">ThirdPartyEventRules breaking changes</a></h2>
  1801. <p>This release introduces a backwards-incompatible change to modules
  1802. making use of <code>ThirdPartyEventRules</code> in Synapse. If you make use of a
  1803. module defined under the <code>third_party_event_rules</code> config option, please
  1804. make sure it is updated to handle the below change:</p>
  1805. <p>The <code>http_client</code> argument is no longer passed to modules as they are
  1806. initialised. Instead, modules are expected to make use of the
  1807. <code>http_client</code> property on the <code>ModuleApi</code> class. Modules are now passed
  1808. a <code>module_api</code> argument during initialisation, which is an instance of
  1809. <code>ModuleApi</code>. <code>ModuleApi</code> instances have a <code>http_client</code> property which
  1810. acts the same as the <code>http_client</code> argument previously passed to
  1811. <code>ThirdPartyEventRules</code> modules.</p>
  1812. <h1 id="upgrading-to-v1210"><a class="header" href="#upgrading-to-v1210">Upgrading to v1.21.0</a></h1>
  1813. <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>
  1814. <p>The <a href="reverse_proxy.html">reverse proxy documentation</a>
  1815. has been updated to include reverse proxy directives for
  1816. <code>/_synapse/client/*</code> endpoints. As the user password reset flow now uses
  1817. endpoints under this prefix, <strong>you must update your reverse proxy
  1818. configurations for user password reset to work</strong>.</p>
  1819. <p>Additionally, note that the <a href="workers.html">Synapse worker documentation</a> has been updated to</p>
  1820. <p>: state that the <code>/_synapse/client/password_reset/email/submit_token</code>
  1821. endpoint can be handled</p>
  1822. <p>by all workers. If you make use of Synapse's worker feature, please
  1823. update your reverse proxy configuration to reflect this change.</p>
  1824. <h2 id="new-html-templates"><a class="header" href="#new-html-templates">New HTML templates</a></h2>
  1825. <p>A new HTML template,
  1826. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/res/templates/password_reset_confirmation.html">password_reset_confirmation.html</a>,
  1827. has been added to the <code>synapse/res/templates</code> directory. If you are
  1828. using a custom template directory, you may want to copy the template
  1829. over and modify it.</p>
  1830. <p>Note that as of v1.20.0, templates do not need to be included in custom
  1831. template directories for Synapse to start. The default templates will be
  1832. used if a custom template cannot be found.</p>
  1833. <p>This page will appear to the user after clicking a password reset link
  1834. that has been emailed to them.</p>
  1835. <p>To complete password reset, the page must include a way to make a
  1836. [POST]{.title-ref} request to
  1837. <code>/_synapse/client/password_reset/{medium}/submit_token</code> with the query
  1838. parameters from the original link, presented as a URL-encoded form. See
  1839. the file itself for more details.</p>
  1840. <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>
  1841. <p>The <code>saml_error.html</code> template was removed from Synapse and replaced
  1842. with the <code>sso_error.html</code> template. If your Synapse is configured to use
  1843. SAML and a custom <code>sso_redirect_confirm_template_dir</code> configuration then
  1844. any customisations of the <code>saml_error.html</code> template will need to be
  1845. merged into the <code>sso_error.html</code> template. These templates are similar,
  1846. but the parameters are slightly different:</p>
  1847. <ul>
  1848. <li>The <code>msg</code> parameter should be renamed to <code>error_description</code>.</li>
  1849. <li>There is no longer a <code>code</code> parameter for the response code.</li>
  1850. <li>A string <code>error</code> parameter is available that includes a short hint
  1851. of why a user is seeing the error page.</li>
  1852. </ul>
  1853. <h1 id="upgrading-to-v1180"><a class="header" href="#upgrading-to-v1180">Upgrading to v1.18.0</a></h1>
  1854. <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>
  1855. <p>From 10th August 2020, we will no longer publish Docker images with the
  1856. [-py3]{.title-ref} tag suffix. The images tagged with the
  1857. [-py3]{.title-ref} suffix have been identical to the non-suffixed tags
  1858. since release 0.99.0, and the suffix is obsolete.</p>
  1859. <p>On 10th August, we will remove the [latest-py3]{.title-ref} tag.
  1860. Existing per-release tags (such as [v1.18.0-py3]{.title-ref}) will not
  1861. be removed, but no new [-py3]{.title-ref} tags will be added.</p>
  1862. <p>Scripts relying on the [-py3]{.title-ref} suffix will need to be
  1863. updated.</p>
  1864. <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>
  1865. <p>When setting up worker processes, we now recommend the use of a Redis
  1866. server for replication. <strong>The old direct TCP connection method is
  1867. deprecated and will be removed in a future release.</strong> See
  1868. <a href="workers.html">workers</a> for more details.</p>
  1869. <h1 id="upgrading-to-v1140"><a class="header" href="#upgrading-to-v1140">Upgrading to v1.14.0</a></h1>
  1870. <p>This version includes a database update which is run as part of the
  1871. upgrade, and which may take a couple of minutes in the case of a large
  1872. server. Synapse will not respond to HTTP requests while this update is
  1873. taking place.</p>
  1874. <h1 id="upgrading-to-v1130"><a class="header" href="#upgrading-to-v1130">Upgrading to v1.13.0</a></h1>
  1875. <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>
  1876. <p>A bug was introduced in Synapse 1.4.0 which could cause the room
  1877. directory to be incomplete or empty if Synapse was upgraded directly
  1878. from v1.2.1 or earlier, to versions between v1.4.0 and v1.12.x.</p>
  1879. <p>This will <em>not</em> be a problem for Synapse installations which were:</p>
  1880. <p>: - created at v1.4.0 or later,
  1881. - upgraded via v1.3.x, or
  1882. - upgraded straight from v1.2.1 or earlier to v1.13.0 or later.</p>
  1883. <p>If completeness of the room directory is a concern, installations which
  1884. are affected can be repaired as follows:</p>
  1885. <ol>
  1886. <li>
  1887. <p>Run the following sql from a [psql]{.title-ref} or
  1888. [sqlite3]{.title-ref} console:</p>
  1889. <pre><code class="language-sql">INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1890. ('populate_stats_process_rooms', '{}', 'current_state_events_membership');
  1891. INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1892. ('populate_stats_process_users', '{}', 'populate_stats_process_rooms');
  1893. </code></pre>
  1894. </li>
  1895. <li>
  1896. <p>Restart synapse.</p>
  1897. </li>
  1898. </ol>
  1899. <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>
  1900. <p>New templates (<code>sso_auth_confirm.html</code>, <code>sso_auth_success.html</code>, and
  1901. <code>sso_account_deactivated.html</code>) were added to Synapse. If your Synapse
  1902. is configured to use SSO and a custom
  1903. <code>sso_redirect_confirm_template_dir</code> configuration then these templates
  1904. will need to be copied from
  1905. <a href="synapse/res/templates">synapse/res/templates</a> into that directory.</p>
  1906. <h2 id="synapse-sso-plugins-method-deprecation"><a class="header" href="#synapse-sso-plugins-method-deprecation">Synapse SSO Plugins Method Deprecation</a></h2>
  1907. <p>Plugins using the <code>complete_sso_login</code> method of
  1908. <code>synapse.module_api.ModuleApi</code> should update to using the async/await
  1909. version <code>complete_sso_login_async</code> which includes additional checks. The
  1910. non-async version is considered deprecated.</p>
  1911. <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>
  1912. <p>v1.13.0 includes a lot of large changes. If something problematic
  1913. occurs, you may want to roll-back to a previous version of Synapse.
  1914. Because v1.13.0 also includes a new database schema version, reverting
  1915. that version is also required alongside the generic rollback
  1916. instructions mentioned above. In short, to roll back to v1.12.4 you need
  1917. to:</p>
  1918. <ol>
  1919. <li>
  1920. <p>Stop the server</p>
  1921. </li>
  1922. <li>
  1923. <p>Decrease the schema version in the database:</p>
  1924. <pre><code class="language-sql">UPDATE schema_version SET version = 57;
  1925. </code></pre>
  1926. </li>
  1927. <li>
  1928. <p>Downgrade Synapse by following the instructions for your
  1929. installation method in the &quot;Rolling back to older versions&quot;
  1930. section above.</p>
  1931. </li>
  1932. </ol>
  1933. <h1 id="upgrading-to-v1120"><a class="header" href="#upgrading-to-v1120">Upgrading to v1.12.0</a></h1>
  1934. <p>This version includes a database update which is run as part of the
  1935. upgrade, and which may take some time (several hours in the case of a
  1936. large server). Synapse will not respond to HTTP requests while this
  1937. update is taking place.</p>
  1938. <p>This is only likely to be a problem in the case of a server which is
  1939. participating in many rooms.</p>
  1940. <ol start="0">
  1941. <li>
  1942. <p>As with all upgrades, it is recommended that you have a recent
  1943. backup of your database which can be used for recovery in the event
  1944. of any problems.</p>
  1945. </li>
  1946. <li>
  1947. <p>As an initial check to see if you will be affected, you can try
  1948. running the following query from the [psql]{.title-ref} or
  1949. [sqlite3]{.title-ref} console. It is safe to run it while Synapse is
  1950. still running.</p>
  1951. <pre><code class="language-sql">SELECT MAX(q.v) FROM (
  1952. SELECT (
  1953. SELECT ej.json AS v
  1954. FROM state_events se INNER JOIN event_json ej USING (event_id)
  1955. WHERE se.room_id=rooms.room_id AND se.type='m.room.create' AND se.state_key=''
  1956. LIMIT 1
  1957. ) FROM rooms WHERE rooms.room_version IS NULL
  1958. ) q;
  1959. </code></pre>
  1960. <p>This query will take about the same amount of time as the upgrade
  1961. process: ie, if it takes 5 minutes, then it is likely that Synapse
  1962. will be unresponsive for 5 minutes during the upgrade.</p>
  1963. <p>If you consider an outage of this duration to be acceptable, no
  1964. further action is necessary and you can simply start Synapse 1.12.0.</p>
  1965. <p>If you would prefer to reduce the downtime, continue with the steps
  1966. below.</p>
  1967. </li>
  1968. <li>
  1969. <p>The easiest workaround for this issue is to manually create a new
  1970. index before upgrading. On PostgreSQL, his can be done as follows:</p>
  1971. <pre><code class="language-sql">CREATE INDEX CONCURRENTLY tmp_upgrade_1_12_0_index
  1972. ON state_events(room_id) WHERE type = 'm.room.create';
  1973. </code></pre>
  1974. <p>The above query may take some time, but is also safe to run while
  1975. Synapse is running.</p>
  1976. <p>We assume that no SQLite users have databases large enough to be
  1977. affected. If you <em>are</em> affected, you can run a similar query,
  1978. omitting the <code>CONCURRENTLY</code> keyword. Note however that this
  1979. operation may in itself cause Synapse to stop running for some time.
  1980. Synapse admins are reminded that <a href="postgres.html">SQLite is not recommended for use
  1981. outside a test environment</a>.</p>
  1982. </li>
  1983. <li>
  1984. <p>Once the index has been created, the <code>SELECT</code> query in step 1 above
  1985. should complete quickly. It is therefore safe to upgrade to Synapse
  1986. 1.12.0.</p>
  1987. </li>
  1988. <li>
  1989. <p>Once Synapse 1.12.0 has successfully started and is responding to
  1990. HTTP requests, the temporary index can be removed:</p>
  1991. <pre><code class="language-sql">DROP INDEX tmp_upgrade_1_12_0_index;
  1992. </code></pre>
  1993. </li>
  1994. </ol>
  1995. <h1 id="upgrading-to-v1100"><a class="header" href="#upgrading-to-v1100">Upgrading to v1.10.0</a></h1>
  1996. <p>Synapse will now log a warning on start up if used with a PostgreSQL
  1997. database that has a non-recommended locale set.</p>
  1998. <p>See <a href="postgres.html">Postgres</a> for details.</p>
  1999. <h1 id="upgrading-to-v180"><a class="header" href="#upgrading-to-v180">Upgrading to v1.8.0</a></h1>
  2000. <p>Specifying a <code>log_file</code> config option will now cause Synapse to refuse
  2001. to start, and should be replaced by with the <code>log_config</code> option.
  2002. Support for the <code>log_file</code> option was removed in v1.3.0 and has since
  2003. had no effect.</p>
  2004. <h1 id="upgrading-to-v170"><a class="header" href="#upgrading-to-v170">Upgrading to v1.7.0</a></h1>
  2005. <p>In an attempt to configure Synapse in a privacy preserving way, the
  2006. default behaviours of <code>allow_public_rooms_without_auth</code> and
  2007. <code>allow_public_rooms_over_federation</code> have been inverted. This means that
  2008. by default, only authenticated users querying the Client/Server API will
  2009. be able to query the room directory, and relatedly that the server will
  2010. not share room directory information with other servers over federation.</p>
  2011. <p>If your installation does not explicitly set these settings one way or
  2012. the other and you want either setting to be <code>true</code> then it will
  2013. necessary to update your homeserver configuration file accordingly.</p>
  2014. <p>For more details on the surrounding context see our
  2015. <a href="https://matrix.org/blog/2019/11/09/avoiding-unwelcome-visitors-on-private-matrix-servers">explainer</a>.</p>
  2016. <h1 id="upgrading-to-v150"><a class="header" href="#upgrading-to-v150">Upgrading to v1.5.0</a></h1>
  2017. <p>This release includes a database migration which may take several
  2018. minutes to complete if there are a large number (more than a million or
  2019. so) of entries in the <code>devices</code> table. This is only likely to a be a
  2020. problem on very large installations.</p>
  2021. <h1 id="upgrading-to-v140"><a class="header" href="#upgrading-to-v140">Upgrading to v1.4.0</a></h1>
  2022. <h2 id="new-custom-templates"><a class="header" href="#new-custom-templates">New custom templates</a></h2>
  2023. <p>If you have configured a custom template directory with the
  2024. <code>email.template_dir</code> option, be aware that there are new templates
  2025. regarding registration and threepid management (see below) that must be
  2026. included.</p>
  2027. <ul>
  2028. <li><code>registration.html</code> and <code>registration.txt</code></li>
  2029. <li><code>registration_success.html</code> and <code>registration_failure.html</code></li>
  2030. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code></li>
  2031. <li><code>add_threepid_failure.html</code> and <code>add_threepid_success.html</code></li>
  2032. </ul>
  2033. <p>Synapse will expect these files to exist inside the configured template
  2034. directory, and <strong>will fail to start</strong> if they are absent. To view the
  2035. default templates, see
  2036. <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">synapse/res/templates</a>.</p>
  2037. <h2 id="3pid-verification-changes"><a class="header" href="#3pid-verification-changes">3pid verification changes</a></h2>
  2038. <p><strong>Note: As of this release, users will be unable to add phone numbers or
  2039. email addresses to their accounts, without changes to the Synapse
  2040. configuration. This includes adding an email address during
  2041. registration.</strong></p>
  2042. <p>It is possible for a user to associate an email address or phone number
  2043. with their account, for a number of reasons:</p>
  2044. <ul>
  2045. <li>for use when logging in, as an alternative to the user id.</li>
  2046. <li>in the case of email, as an alternative contact to help with account
  2047. recovery.</li>
  2048. <li>in the case of email, to receive notifications of missed messages.</li>
  2049. </ul>
  2050. <p>Before an email address or phone number can be added to a user's
  2051. account, or before such an address is used to carry out a
  2052. password-reset, Synapse must confirm the operation with the owner of the
  2053. email address or phone number. It does this by sending an email or text
  2054. giving the user a link or token to confirm receipt. This process is
  2055. known as '3pid verification'. ('3pid', or 'threepid', stands for
  2056. third-party identifier, and we use it to refer to external identifiers
  2057. such as email addresses and phone numbers.)</p>
  2058. <p>Previous versions of Synapse delegated the task of 3pid verification to
  2059. an identity server by default. In most cases this server is <code>vector.im</code>
  2060. or <code>matrix.org</code>.</p>
  2061. <p>In Synapse 1.4.0, for security and privacy reasons, the homeserver will
  2062. no longer delegate this task to an identity server by default. Instead,
  2063. the server administrator will need to explicitly decide how they would
  2064. like the verification messages to be sent.</p>
  2065. <p>In the medium term, the <code>vector.im</code> and <code>matrix.org</code> identity servers
  2066. will disable support for delegated 3pid verification entirely. However,
  2067. in order to ease the transition, they will retain the capability for a
  2068. limited period. Delegated email verification will be disabled on Monday
  2069. 2nd December 2019 (giving roughly 2 months notice). Disabling delegated
  2070. SMS verification will follow some time after that once SMS verification
  2071. support lands in Synapse.</p>
  2072. <p>Once delegated 3pid verification support has been disabled in the
  2073. <code>vector.im</code> and <code>matrix.org</code> identity servers, all Synapse versions that
  2074. depend on those instances will be unable to verify email and phone
  2075. numbers through them. There are no imminent plans to remove delegated
  2076. 3pid verification from Sydent generally. (Sydent is the identity server
  2077. project that backs the <code>vector.im</code> and <code>matrix.org</code> instances).</p>
  2078. <h3 id="email-1"><a class="header" href="#email-1">Email</a></h3>
  2079. <p>Following upgrade, to continue verifying email (e.g. as part of the
  2080. registration process), admins can either:-</p>
  2081. <ul>
  2082. <li>Configure Synapse to use an email server.</li>
  2083. <li>Run or choose an identity server which allows delegated email
  2084. verification and delegate to it.</li>
  2085. </ul>
  2086. <h4 id="configure-smtp-in-synapse"><a class="header" href="#configure-smtp-in-synapse">Configure SMTP in Synapse</a></h4>
  2087. <p>To configure an SMTP server for Synapse, modify the configuration
  2088. section headed <code>email</code>, and be sure to have at least the
  2089. <code>smtp_host, smtp_port</code> and <code>notif_from</code> fields filled out.</p>
  2090. <p>You may also need to set <code>smtp_user</code>, <code>smtp_pass</code>, and
  2091. <code>require_transport_security</code>.</p>
  2092. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2093. for more details on these settings.</p>
  2094. <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>
  2095. <p>Some admins will wish to continue using email verification as part of
  2096. the registration process, but will not immediately have an appropriate
  2097. SMTP server at hand.</p>
  2098. <p>To this end, we will continue to support email verification delegation
  2099. via the <code>vector.im</code> and <code>matrix.org</code> identity servers for two months.
  2100. Support for delegated email verification will be disabled on Monday 2nd
  2101. December.</p>
  2102. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2103. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2104. server</a>) to handle
  2105. sending confirmation messages via email and SMS.</p>
  2106. <p>So to delegate email verification, in <code>homeserver.yaml</code>, set
  2107. <code>account_threepid_delegates.email</code> to the base URL of an identity
  2108. server. For example:</p>
  2109. <pre><code class="language-yaml">account_threepid_delegates:
  2110. email: https://example.com # Delegate email sending to example.com
  2111. </code></pre>
  2112. <p>Note that <code>account_threepid_delegates.email</code> replaces the deprecated
  2113. <code>email.trust_identity_server_for_password_resets</code>: if
  2114. <code>email.trust_identity_server_for_password_resets</code> is set to <code>true</code>, and
  2115. <code>account_threepid_delegates.email</code> is not set, then the first entry in
  2116. <code>trusted_third_party_id_servers</code> will be used as the
  2117. <code>account_threepid_delegate</code> for email. This is to ensure compatibility
  2118. with existing Synapse installs that set up external server handling for
  2119. these tasks before v1.4.0. If
  2120. <code>email.trust_identity_server_for_password_resets</code> is <code>true</code> and no
  2121. trusted identity server domains are configured, Synapse will report an
  2122. error and refuse to start.</p>
  2123. <p>If <code>email.trust_identity_server_for_password_resets</code> is <code>false</code> or
  2124. absent and no <code>email</code> delegate is configured in
  2125. <code>account_threepid_delegates</code>, then Synapse will send email verification
  2126. messages itself, using the configured SMTP server (see above). that
  2127. type.</p>
  2128. <h3 id="phone-numbers"><a class="header" href="#phone-numbers">Phone numbers</a></h3>
  2129. <p>Synapse does not support phone-number verification itself, so the only
  2130. way to maintain the ability for users to add phone numbers to their
  2131. accounts will be by continuing to delegate phone number verification to
  2132. the <code>matrix.org</code> and <code>vector.im</code> identity servers (or another identity
  2133. server that supports SMS sending).</p>
  2134. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2135. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2136. server</a>) to handle
  2137. sending confirmation messages via email and SMS.</p>
  2138. <p>So to delegate phone number verification, in <code>homeserver.yaml</code>, set
  2139. <code>account_threepid_delegates.msisdn</code> to the base URL of an identity
  2140. server. For example:</p>
  2141. <pre><code class="language-yaml">account_threepid_delegates:
  2142. msisdn: https://example.com # Delegate sms sending to example.com
  2143. </code></pre>
  2144. <p>The <code>matrix.org</code> and <code>vector.im</code> identity servers will continue to
  2145. support delegated phone number verification via SMS until such time as
  2146. it is possible for admins to configure their servers to perform phone
  2147. number verification directly. More details will follow in a future
  2148. release.</p>
  2149. <h2 id="rolling-back-to-v131"><a class="header" href="#rolling-back-to-v131">Rolling back to v1.3.1</a></h2>
  2150. <p>If you encounter problems with v1.4.0, it should be possible to roll
  2151. back to v1.3.1, subject to the following:</p>
  2152. <ul>
  2153. <li>
  2154. <p>The 'room statistics' engine was heavily reworked in this release
  2155. (see <a href="https://github.com/matrix-org/synapse/pull/5971">#5971</a>),
  2156. including significant changes to the database schema, which are not
  2157. easily reverted. This will cause the room statistics engine to stop
  2158. updating when you downgrade.</p>
  2159. <p>The room statistics are essentially unused in v1.3.1 (in future
  2160. versions of Synapse, they will be used to populate the room
  2161. directory), so there should be no loss of functionality. However,
  2162. the statistics engine will write errors to the logs, which can be
  2163. avoided by setting the following in <code>homeserver.yaml</code>:</p>
  2164. <pre><code class="language-yaml">stats:
  2165. enabled: false
  2166. </code></pre>
  2167. <p>Don't forget to re-enable it when you upgrade again, in preparation
  2168. for its use in the room directory!</p>
  2169. </li>
  2170. </ul>
  2171. <h1 id="upgrading-to-v120"><a class="header" href="#upgrading-to-v120">Upgrading to v1.2.0</a></h1>
  2172. <p>Some counter metrics have been renamed, with the old names deprecated.
  2173. See <a href="metrics-howto.html#renaming-of-metrics--deprecation-of-old-names-in-12">the metrics
  2174. documentation</a>
  2175. for details.</p>
  2176. <h1 id="upgrading-to-v110"><a class="header" href="#upgrading-to-v110">Upgrading to v1.1.0</a></h1>
  2177. <p>Synapse v1.1.0 removes support for older Python and PostgreSQL versions,
  2178. as outlined in <a href="https://matrix.org/blog/2019/04/08/synapse-deprecating-postgres-9-4-and-python-2-x">our deprecation
  2179. notice</a>.</p>
  2180. <h2 id="minimum-python-version"><a class="header" href="#minimum-python-version">Minimum Python Version</a></h2>
  2181. <p>Synapse v1.1.0 has a minimum Python requirement of Python 3.5. Python
  2182. 3.6 or Python 3.7 are recommended as they have improved internal string
  2183. handling, significantly reducing memory usage.</p>
  2184. <p>If you use current versions of the Matrix.org-distributed Debian
  2185. packages or Docker images, action is not required.</p>
  2186. <p>If you install Synapse in a Python virtual environment, please see
  2187. &quot;Upgrading to v0.34.0&quot; for notes on setting up a new virtualenv under
  2188. Python 3.</p>
  2189. <h2 id="minimum-postgresql-version"><a class="header" href="#minimum-postgresql-version">Minimum PostgreSQL Version</a></h2>
  2190. <p>If using PostgreSQL under Synapse, you will need to use PostgreSQL 9.5
  2191. or above. Please see the <a href="https://www.postgresql.org/docs/11/upgrading.html">PostgreSQL
  2192. documentation</a> for
  2193. more details on upgrading your database.</p>
  2194. <h1 id="upgrading-to-v10"><a class="header" href="#upgrading-to-v10">Upgrading to v1.0</a></h1>
  2195. <h2 id="validation-of-tls-certificates"><a class="header" href="#validation-of-tls-certificates">Validation of TLS certificates</a></h2>
  2196. <p>Synapse v1.0 is the first release to enforce validation of TLS
  2197. certificates for the federation API. It is therefore essential that your
  2198. certificates are correctly configured. See the
  2199. <a href="MSC1711_certificates_FAQ.html">FAQ</a> for more information.</p>
  2200. <p>Note, v1.0 installations will also no longer be able to federate with
  2201. servers that have not correctly configured their certificates.</p>
  2202. <p>In rare cases, it may be desirable to disable certificate checking: for
  2203. example, it might be essential to be able to federate with a given
  2204. legacy server in a closed federation. This can be done in one of two
  2205. ways:-</p>
  2206. <ul>
  2207. <li>Configure the global switch <code>federation_verify_certificates</code> to
  2208. <code>false</code>.</li>
  2209. <li>Configure a whitelist of server domains to trust via
  2210. <code>federation_certificate_verification_whitelist</code>.</li>
  2211. </ul>
  2212. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2213. for more details on these settings.</p>
  2214. <h2 id="email-2"><a class="header" href="#email-2">Email</a></h2>
  2215. <p>When a user requests a password reset, Synapse will send an email to the
  2216. user to confirm the request.</p>
  2217. <p>Previous versions of Synapse delegated the job of sending this email to
  2218. an identity server. If the identity server was somehow malicious or
  2219. became compromised, it would be theoretically possible to hijack an
  2220. account through this means.</p>
  2221. <p>Therefore, by default, Synapse v1.0 will send the confirmation email
  2222. itself. If Synapse is not configured with an SMTP server, password reset
  2223. via email will be disabled.</p>
  2224. <p>To configure an SMTP server for Synapse, modify the configuration
  2225. section headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>,
  2226. <code>smtp_port</code> and <code>notif_from</code> fields filled out. You may also need to set
  2227. <code>smtp_user</code>, <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  2228. <p>If you are absolutely certain that you wish to continue using an
  2229. identity server for password resets, set
  2230. <code>trust_identity_server_for_password_resets</code> to <code>true</code>.</p>
  2231. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2232. for more details on these settings.</p>
  2233. <h2 id="new-email-templates"><a class="header" href="#new-email-templates">New email templates</a></h2>
  2234. <p>Some new templates have been added to the default template directory for the purpose of
  2235. the homeserver sending its own password reset emails. If you have configured a
  2236. custom <code>template_dir</code> in your Synapse config, these files will need to be added.</p>
  2237. <p><code>password_reset.html</code> and <code>password_reset.txt</code> are HTML and plain text
  2238. templates respectively that contain the contents of what will be emailed
  2239. to the user upon attempting to reset their password via email.
  2240. <code>password_reset_success.html</code> and <code>password_reset_failure.html</code> are HTML
  2241. files that the content of which (assuming no redirect URL is set) will
  2242. be shown to the user after they attempt to click the link in the email
  2243. sent to them.</p>
  2244. <h1 id="upgrading-to-v0990"><a class="header" href="#upgrading-to-v0990">Upgrading to v0.99.0</a></h1>
  2245. <p>Please be aware that, before Synapse v1.0 is released around March 2019,
  2246. you will need to replace any self-signed certificates with those
  2247. verified by a root CA. Information on how to do so can be found at the
  2248. ACME docs.</p>
  2249. <p>For more information on configuring TLS certificates see the
  2250. <a href="MSC1711_certificates_FAQ.html">FAQ</a>.</p>
  2251. <h1 id="upgrading-to-v0340"><a class="header" href="#upgrading-to-v0340">Upgrading to v0.34.0</a></h1>
  2252. <ol>
  2253. <li>
  2254. <p>This release is the first to fully support Python 3. Synapse will
  2255. now run on Python versions 3.5, or 3.6 (as well as 2.7). We
  2256. recommend switching to Python 3, as it has been shown to give
  2257. performance improvements.</p>
  2258. <p>For users who have installed Synapse into a virtualenv, we recommend
  2259. doing this by creating a new virtualenv. For example:</p>
  2260. <pre><code>virtualenv -p python3 ~/synapse/env3
  2261. source ~/synapse/env3/bin/activate
  2262. pip install matrix-synapse
  2263. </code></pre>
  2264. <p>You can then start synapse as normal, having activated the new
  2265. virtualenv:</p>
  2266. <pre><code>cd ~/synapse
  2267. source env3/bin/activate
  2268. synctl start
  2269. </code></pre>
  2270. <p>Users who have installed from distribution packages should see the
  2271. relevant package documentation. See below for notes on Debian
  2272. packages.</p>
  2273. <ul>
  2274. <li>
  2275. <p>When upgrading to Python 3, you <strong>must</strong> make sure that your log
  2276. files are configured as UTF-8, by adding <code>encoding: utf8</code> to the
  2277. <code>RotatingFileHandler</code> configuration (if you have one) in your
  2278. <code>&lt;server&gt;.log.config</code> file. For example, if your <code>log.config</code>
  2279. file contains:</p>
  2280. <pre><code>handlers:
  2281. file:
  2282. class: logging.handlers.RotatingFileHandler
  2283. formatter: precise
  2284. filename: homeserver.log
  2285. maxBytes: 104857600
  2286. backupCount: 10
  2287. filters: [context]
  2288. console:
  2289. class: logging.StreamHandler
  2290. formatter: precise
  2291. filters: [context]
  2292. </code></pre>
  2293. <p>Then you should update this to be:</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. encoding: utf8
  2303. console:
  2304. class: logging.StreamHandler
  2305. formatter: precise
  2306. filters: [context]
  2307. </code></pre>
  2308. <p>There is no need to revert this change if downgrading to
  2309. Python 2.</p>
  2310. </li>
  2311. </ul>
  2312. <p>We are also making available Debian packages which will run Synapse
  2313. on Python 3. You can switch to these packages with
  2314. <code>apt-get install matrix-synapse-py3</code>, however, please read
  2315. <a href="https://github.com/matrix-org/synapse/blob/release-v0.34.0/debian/NEWS">debian/NEWS</a>
  2316. before doing so. The existing <code>matrix-synapse</code> packages will
  2317. continue to use Python 2 for the time being.</p>
  2318. </li>
  2319. <li>
  2320. <p>This release removes the <code>riot.im</code> from the default list of trusted
  2321. identity servers.</p>
  2322. <p>If <code>riot.im</code> is in your homeserver's list of
  2323. <code>trusted_third_party_id_servers</code>, you should remove it. It was added
  2324. in case a hypothetical future identity server was put there. If you
  2325. don't remove it, users may be unable to deactivate their accounts.</p>
  2326. </li>
  2327. <li>
  2328. <p>This release no longer installs the (unmaintained) Matrix Console
  2329. web client as part of the default installation. It is possible to
  2330. re-enable it by installing it separately and setting the
  2331. <code>web_client_location</code> config option, but please consider switching
  2332. to another client.</p>
  2333. </li>
  2334. </ol>
  2335. <h1 id="upgrading-to-v0337"><a class="header" href="#upgrading-to-v0337">Upgrading to v0.33.7</a></h1>
  2336. <p>This release removes the example email notification templates from
  2337. <code>res/templates</code> (they are now internal to the python package). This
  2338. should only affect you if you (a) deploy your Synapse instance from a
  2339. git checkout or a github snapshot URL, and (b) have email notifications
  2340. enabled.</p>
  2341. <p>If you have email notifications enabled, you should ensure that
  2342. <code>email.template_dir</code> is either configured to point at a directory where
  2343. you have installed customised templates, or leave it unset to use the
  2344. default templates.</p>
  2345. <h1 id="upgrading-to-v0273"><a class="header" href="#upgrading-to-v0273">Upgrading to v0.27.3</a></h1>
  2346. <p>This release expands the anonymous usage stats sent if the opt-in
  2347. <code>report_stats</code> configuration is set to <code>true</code>. We now capture RSS memory
  2348. and cpu use at a very coarse level. This requires administrators to
  2349. install the optional <code>psutil</code> python module.</p>
  2350. <p>We would appreciate it if you could assist by ensuring this module is
  2351. available and <code>report_stats</code> is enabled. This will let us see if
  2352. performance changes to synapse are having an impact to the general
  2353. community.</p>
  2354. <h1 id="upgrading-to-v0150"><a class="header" href="#upgrading-to-v0150">Upgrading to v0.15.0</a></h1>
  2355. <p>If you want to use the new URL previewing API
  2356. (<code>/_matrix/media/r0/preview_url</code>) then you have to explicitly enable it
  2357. in the config and update your dependencies dependencies. See README.rst
  2358. for details.</p>
  2359. <h1 id="upgrading-to-v0110"><a class="header" href="#upgrading-to-v0110">Upgrading to v0.11.0</a></h1>
  2360. <p>This release includes the option to send anonymous usage stats to
  2361. matrix.org, and requires that administrators explictly opt in or out by
  2362. setting the <code>report_stats</code> option to either <code>true</code> or <code>false</code>.</p>
  2363. <p>We would really appreciate it if you could help our project out by
  2364. reporting anonymized usage statistics from your homeserver. Only very
  2365. basic aggregate data (e.g. number of users) will be reported, but it
  2366. helps us to track the growth of the Matrix community, and helps us to
  2367. make Matrix a success, as well as to convince other networks that they
  2368. should peer with us.</p>
  2369. <h1 id="upgrading-to-v090"><a class="header" href="#upgrading-to-v090">Upgrading to v0.9.0</a></h1>
  2370. <p>Application services have had a breaking API change in this version.</p>
  2371. <p>They can no longer register themselves with a home server using the AS
  2372. HTTP API. This decision was made because a compromised application
  2373. service with free reign to register any regex in effect grants full
  2374. read/write access to the home server if a regex of <code>.*</code> is used. An
  2375. attack where a compromised AS re-registers itself with <code>.*</code> was deemed
  2376. too big of a security risk to ignore, and so the ability to register
  2377. with the HS remotely has been removed.</p>
  2378. <p>It has been replaced by specifying a list of application service
  2379. registrations in <code>homeserver.yaml</code>:</p>
  2380. <pre><code>app_service_config_files: [&quot;registration-01.yaml&quot;, &quot;registration-02.yaml&quot;]
  2381. </code></pre>
  2382. <p>Where <code>registration-01.yaml</code> looks like:</p>
  2383. <pre><code>url: &lt;String&gt; # e.g. &quot;https://my.application.service.com&quot;
  2384. as_token: &lt;String&gt;
  2385. hs_token: &lt;String&gt;
  2386. sender_localpart: &lt;String&gt; # This is a new field which denotes the user_id localpart when using the AS token
  2387. namespaces:
  2388. users:
  2389. - exclusive: &lt;Boolean&gt;
  2390. regex: &lt;String&gt; # e.g. &quot;@prefix_.*&quot;
  2391. aliases:
  2392. - exclusive: &lt;Boolean&gt;
  2393. regex: &lt;String&gt;
  2394. rooms:
  2395. - exclusive: &lt;Boolean&gt;
  2396. regex: &lt;String&gt;
  2397. </code></pre>
  2398. <h1 id="upgrading-to-v080"><a class="header" href="#upgrading-to-v080">Upgrading to v0.8.0</a></h1>
  2399. <p>Servers which use captchas will need to add their public key to:</p>
  2400. <pre><code>static/client/register/register_config.js
  2401. window.matrixRegistrationConfig = {
  2402. recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  2403. };
  2404. </code></pre>
  2405. <p>This is required in order to support registration fallback (typically
  2406. used on mobile devices).</p>
  2407. <h1 id="upgrading-to-v070"><a class="header" href="#upgrading-to-v070">Upgrading to v0.7.0</a></h1>
  2408. <p>New dependencies are:</p>
  2409. <ul>
  2410. <li>pydenticon</li>
  2411. <li>simplejson</li>
  2412. <li>syutil</li>
  2413. <li>matrix-angular-sdk</li>
  2414. </ul>
  2415. <p>To pull in these dependencies in a virtual env, run:</p>
  2416. <pre><code>python synapse/python_dependencies.py | xargs -n 1 pip install
  2417. </code></pre>
  2418. <h1 id="upgrading-to-v060"><a class="header" href="#upgrading-to-v060">Upgrading to v0.6.0</a></h1>
  2419. <p>To pull in new dependencies, run:</p>
  2420. <pre><code>python setup.py develop --user
  2421. </code></pre>
  2422. <p>This update includes a change to the database schema. To upgrade you
  2423. first need to upgrade the database by running:</p>
  2424. <pre><code>python scripts/upgrade_db_to_v0.6.0.py &lt;db&gt; &lt;server_name&gt; &lt;signing_key&gt;
  2425. </code></pre>
  2426. <p>Where [<db>]{.title-ref} is the location of the database,
  2427. [&lt;server_name&gt;]{.title-ref} is the server name as specified in the
  2428. synapse configuration, and [&lt;signing_key&gt;]{.title-ref} is the location
  2429. of the signing key as specified in the synapse configuration.</p>
  2430. <p>This may take some time to complete. Failures of signatures and content
  2431. hashes can safely be ignored.</p>
  2432. <h1 id="upgrading-to-v051"><a class="header" href="#upgrading-to-v051">Upgrading to v0.5.1</a></h1>
  2433. <p>Depending on precisely when you installed v0.5.0 you may have ended up
  2434. with a stale release of the reference matrix webclient installed as a
  2435. python module. To uninstall it and ensure you are depending on the
  2436. latest module, please run:</p>
  2437. <pre><code>$ pip uninstall syweb
  2438. </code></pre>
  2439. <h1 id="upgrading-to-v050"><a class="header" href="#upgrading-to-v050">Upgrading to v0.5.0</a></h1>
  2440. <p>The webclient has been split out into a seperate repository/pacakage in
  2441. this release. Before you restart your homeserver you will need to pull
  2442. in the webclient package by running:</p>
  2443. <pre><code>python setup.py develop --user
  2444. </code></pre>
  2445. <p>This release completely changes the database schema and so requires
  2446. upgrading it before starting the new version of the homeserver.</p>
  2447. <p>The script &quot;database-prepare-for-0.5.0.sh&quot; should be used to upgrade
  2448. the database. This will save all user information, such as logins and
  2449. profiles, but will otherwise purge the database. This includes messages,
  2450. which rooms the home server was a member of and room alias mappings.</p>
  2451. <p>If you would like to keep your history, please take a copy of your
  2452. database file and ask for help in #matrix:matrix.org. The upgrade
  2453. process is, unfortunately, non trivial and requires human intervention
  2454. to resolve any resulting conflicts during the upgrade process.</p>
  2455. <p>Before running the command the homeserver should be first completely
  2456. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2457. <blockquote>
  2458. <p>./scripts/database-prepare-for-0.5.0.sh &quot;homeserver.db&quot;</p>
  2459. </blockquote>
  2460. <p>Once this has successfully completed it will be safe to restart the
  2461. homeserver. You may notice that the homeserver takes a few seconds
  2462. longer to restart than usual as it reinitializes the database.</p>
  2463. <p>On startup of the new version, users can either rejoin remote rooms
  2464. using room aliases or by being reinvited. Alternatively, if any other
  2465. homeserver sends a message to a room that the homeserver was previously
  2466. in the local HS will automatically rejoin the room.</p>
  2467. <h1 id="upgrading-to-v040"><a class="header" href="#upgrading-to-v040">Upgrading to v0.4.0</a></h1>
  2468. <p>This release needs an updated syutil version. Run:</p>
  2469. <pre><code>python setup.py develop
  2470. </code></pre>
  2471. <p>You will also need to upgrade your configuration as the signing key
  2472. format has changed. Run:</p>
  2473. <pre><code>python -m synapse.app.homeserver --config-path &lt;CONFIG&gt; --generate-config
  2474. </code></pre>
  2475. <h1 id="upgrading-to-v030"><a class="header" href="#upgrading-to-v030">Upgrading to v0.3.0</a></h1>
  2476. <p>This registration API now closely matches the login API. This introduces
  2477. a bit more backwards and forwards between the HS and the client, but
  2478. this improves the overall flexibility of the API. You can now GET on
  2479. /register to retrieve a list of valid registration flows. Upon choosing
  2480. one, they are submitted in the same way as login, e.g:</p>
  2481. <pre><code>{
  2482. type: m.login.password,
  2483. user: foo,
  2484. password: bar
  2485. }
  2486. </code></pre>
  2487. <p>The default HS supports 2 flows, with and without Identity Server email
  2488. authentication. Enabling captcha on the HS will add in an extra step to
  2489. all flows: <code>m.login.recaptcha</code> which must be completed before you can
  2490. transition to the next stage. There is a new login type:
  2491. <code>m.login.email.identity</code> which contains the <code>threepidCreds</code> key which
  2492. were previously sent in the original register request. For more
  2493. information on this, see the specification.</p>
  2494. <h2 id="web-client"><a class="header" href="#web-client">Web Client</a></h2>
  2495. <p>The VoIP specification has changed between v0.2.0 and v0.3.0. Users
  2496. should refresh any browser tabs to get the latest web client code. Users
  2497. on v0.2.0 of the web client will not be able to call those on v0.3.0 and
  2498. vice versa.</p>
  2499. <h1 id="upgrading-to-v020"><a class="header" href="#upgrading-to-v020">Upgrading to v0.2.0</a></h1>
  2500. <p>The home server now requires setting up of SSL config before it can run.
  2501. To automatically generate default config use:</p>
  2502. <pre><code>$ python synapse/app/homeserver.py \
  2503. --server-name machine.my.domain.name \
  2504. --bind-port 8448 \
  2505. --config-path homeserver.config \
  2506. --generate-config
  2507. </code></pre>
  2508. <p>This config can be edited if desired, for example to specify a different
  2509. SSL certificate to use. Once done you can run the home server using:</p>
  2510. <pre><code>$ python synapse/app/homeserver.py --config-path homeserver.config
  2511. </code></pre>
  2512. <p>See the README.rst for more information.</p>
  2513. <p>Also note that some config options have been renamed, including:</p>
  2514. <ul>
  2515. <li>&quot;host&quot; to &quot;server-name&quot;</li>
  2516. <li>&quot;database&quot; to &quot;database-path&quot;</li>
  2517. <li>&quot;port&quot; to &quot;bind-port&quot; and &quot;unsecure-port&quot;</li>
  2518. </ul>
  2519. <h1 id="upgrading-to-v001"><a class="header" href="#upgrading-to-v001">Upgrading to v0.0.1</a></h1>
  2520. <p>This release completely changes the database schema and so requires
  2521. upgrading it before starting the new version of the homeserver.</p>
  2522. <p>The script &quot;database-prepare-for-0.0.1.sh&quot; should be used to upgrade
  2523. the database. This will save all user information, such as logins and
  2524. profiles, but will otherwise purge the database. This includes messages,
  2525. which rooms the home server was a member of and room alias mappings.</p>
  2526. <p>Before running the command the homeserver should be first completely
  2527. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2528. <blockquote>
  2529. <p>./scripts/database-prepare-for-0.0.1.sh &quot;homeserver.db&quot;</p>
  2530. </blockquote>
  2531. <p>Once this has successfully completed it will be safe to restart the
  2532. homeserver. You may notice that the homeserver takes a few seconds
  2533. longer to restart than usual as it reinitializes the database.</p>
  2534. <p>On startup of the new version, users can either rejoin remote rooms
  2535. using room aliases or by being reinvited. Alternatively, if any other
  2536. homeserver sends a message to a room that the homeserver was previously
  2537. in the local HS will automatically rejoin the room.</p>
  2538. <div 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>
  2539. <h2 id="historical-note"><a class="header" href="#historical-note">Historical Note</a></h2>
  2540. <p>This document was originally written to guide server admins through the upgrade
  2541. path towards Synapse 1.0. Specifically,
  2542. <a href="https://github.com/matrix-org/matrix-doc/blob/master/proposals/1711-x509-for-federation.md">MSC1711</a>
  2543. required that all servers present valid TLS certificates on their federation
  2544. API. Admins were encouraged to achieve compliance from version 0.99.0 (released
  2545. in February 2019) ahead of version 1.0 (released June 2019) enforcing the
  2546. certificate checks.</p>
  2547. <p>Much of what follows is now outdated since most admins will have already
  2548. upgraded, however it may be of use to those with old installs returning to the
  2549. project.</p>
  2550. <p>If you are setting up a server from scratch you almost certainly should look at
  2551. the <a href="setup/installation.html">installation guide</a> instead.</p>
  2552. <h2 id="introduction-1"><a class="header" href="#introduction-1">Introduction</a></h2>
  2553. <p>The goal of Synapse 0.99.0 is to act as a stepping stone to Synapse 1.0.0. It
  2554. supports the r0.1 release of the server to server specification, but is
  2555. compatible with both the legacy Matrix federation behaviour (pre-r0.1) as well
  2556. as post-r0.1 behaviour, in order to allow for a smooth upgrade across the
  2557. federation.</p>
  2558. <p>The most important thing to know is that Synapse 1.0.0 will require a valid TLS
  2559. certificate on federation endpoints. Self signed certificates will not be
  2560. sufficient.</p>
  2561. <p>Synapse 0.99.0 makes it easy to configure TLS certificates and will
  2562. interoperate with both &gt;= 1.0.0 servers as well as existing servers yet to
  2563. upgrade.</p>
  2564. <p><strong>It is critical that all admins upgrade to 0.99.0 and configure a valid TLS
  2565. certificate.</strong> Admins will have 1 month to do so, after which 1.0.0 will be
  2566. released and those servers without a valid certificate will not longer be able
  2567. to federate with &gt;= 1.0.0 servers.</p>
  2568. <p>Full details on how to carry out this configuration change is given
  2569. <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">below</a>. A
  2570. timeline and some frequently asked questions are also given below.</p>
  2571. <p>For more details and context on the release of the r0.1 Server/Server API and
  2572. imminent Matrix 1.0 release, you can also see our
  2573. <a href="https://matrix.org/blog/2019/02/04/matrix-at-fosdem-2019/">main talk from FOSDEM 2019</a>.</p>
  2574. <h2 id="contents"><a class="header" href="#contents">Contents</a></h2>
  2575. <ul>
  2576. <li>Timeline</li>
  2577. <li>Configuring certificates for compatibility with Synapse 1.0</li>
  2578. <li>FAQ
  2579. <ul>
  2580. <li>Synapse 0.99.0 has just been released, what do I need to do right now?</li>
  2581. <li>How do I upgrade?</li>
  2582. <li>What will happen if I do not set up a valid federation certificate
  2583. immediately?</li>
  2584. <li>What will happen if I do nothing at all?</li>
  2585. <li>When do I need a SRV record or .well-known URI?</li>
  2586. <li>Can I still use an SRV record?</li>
  2587. <li>I have created a .well-known URI. Do I still need an SRV record?</li>
  2588. <li>It used to work just fine, why are you breaking everything?</li>
  2589. <li>Can I manage my own certificates rather than having Synapse renew
  2590. certificates itself?</li>
  2591. <li>Do you still recommend against using a reverse proxy on the federation port?</li>
  2592. <li>Do I still need to give my TLS certificates to Synapse if I am using a
  2593. reverse proxy?</li>
  2594. <li>Do I need the same certificate for the client and federation port?</li>
  2595. <li>How do I tell Synapse to reload my keys/certificates after I replace them?</li>
  2596. </ul>
  2597. </li>
  2598. </ul>
  2599. <h2 id="timeline"><a class="header" href="#timeline">Timeline</a></h2>
  2600. <p><strong>5th Feb 2019 - Synapse 0.99.0 is released.</strong></p>
  2601. <p>All server admins are encouraged to upgrade.</p>
  2602. <p>0.99.0:</p>
  2603. <ul>
  2604. <li>
  2605. <p>provides support for ACME to make setting up Let's Encrypt certs easy, as
  2606. well as .well-known support.</p>
  2607. </li>
  2608. <li>
  2609. <p>does not enforce that a valid CA cert is present on the federation API, but
  2610. rather makes it easy to set one up.</p>
  2611. </li>
  2612. <li>
  2613. <p>provides support for .well-known</p>
  2614. </li>
  2615. </ul>
  2616. <p>Admins should upgrade and configure a valid CA cert. Homeservers that require a
  2617. .well-known entry (see below), should retain their SRV record and use it
  2618. alongside their .well-known record.</p>
  2619. <p><strong>10th June 2019 - Synapse 1.0.0 is released</strong></p>
  2620. <p>1.0.0 is scheduled for release on 10th June. In
  2621. accordance with the the <a href="https://matrix.org/docs/spec/server_server/r0.1.0.html">S2S spec</a>
  2622. 1.0.0 will enforce certificate validity. This means that any homeserver without a
  2623. valid certificate after this point will no longer be able to federate with
  2624. 1.0.0 servers.</p>
  2625. <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>
  2626. <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>
  2627. <p>In this case, your <code>server_name</code> points to the host where your Synapse is
  2628. running. There is no need to create a <code>.well-known</code> URI or an SRV record, but
  2629. you will need to give Synapse a valid, signed, certificate.</p>
  2630. <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>
  2631. <p>If you are using an SRV record, your matrix domain (<code>server_name</code>) may not
  2632. point to the same host that your Synapse is running on (the 'target
  2633. domain'). (If it does, you can follow the recommendation above; otherwise, read
  2634. on.)</p>
  2635. <p>Let's assume that your <code>server_name</code> is <code>example.com</code>, and your Synapse is
  2636. hosted at a target domain of <code>customer.example.net</code>. Currently you should have
  2637. an SRV record which looks like:</p>
  2638. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 8000 customer.example.net.
  2639. </code></pre>
  2640. <p>In this situation, you have three choices for how to proceed:</p>
  2641. <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>
  2642. <p>Synapse 1.0 will expect your server to present a TLS certificate for your
  2643. <code>server_name</code> (<code>example.com</code> in the above example). You can achieve this by acquiring a
  2644. certificate for the <code>server_name</code> yourself (for example, using <code>certbot</code>), and giving it
  2645. and the key to Synapse via <code>tls_certificate_path</code> and <code>tls_private_key_path</code>.</p>
  2646. <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>
  2647. <p>If you have an existing reverse proxy set up with correct TLS certificates for
  2648. your domain, you can simply route all traffic through the reverse proxy by
  2649. updating the SRV record appropriately (or removing it, if the proxy listens on
  2650. 8448).</p>
  2651. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2652. reverse proxy.</p>
  2653. <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>
  2654. <p>This will allow you to keep Synapse on a separate domain, without having to
  2655. give it a certificate for the matrix domain.</p>
  2656. <p>You can do this with a <code>.well-known</code> file as follows:</p>
  2657. <ol>
  2658. <li>
  2659. <p>Keep the SRV record in place - it is needed for backwards compatibility
  2660. with Synapse 0.34 and earlier.</p>
  2661. </li>
  2662. <li>
  2663. <p>Give Synapse a certificate corresponding to the target domain
  2664. (<code>customer.example.net</code> in the above example). You can do this by acquire a
  2665. certificate for the target domain and giving it to Synapse via <code>tls_certificate_path</code>
  2666. and <code>tls_private_key_path</code>.</p>
  2667. </li>
  2668. <li>
  2669. <p>Restart Synapse to ensure the new certificate is loaded.</p>
  2670. </li>
  2671. <li>
  2672. <p>Arrange for a <code>.well-known</code> file at
  2673. <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> with contents:</p>
  2674. <pre><code class="language-json">{&quot;m.server&quot;: &quot;&lt;target server name&gt;&quot;}
  2675. </code></pre>
  2676. <p>where the target server name is resolved as usual (i.e. SRV lookup, falling
  2677. back to talking to port 8448).</p>
  2678. <p>In the above example, where synapse is listening on port 8000,
  2679. <code>https://example.com/.well-known/matrix/server</code> should have <code>m.server</code> set to one of:</p>
  2680. <ol>
  2681. <li>
  2682. <p><code>customer.example.net</code> ─ with a SRV record on
  2683. <code>_matrix._tcp.customer.example.com</code> pointing to port 8000, or:</p>
  2684. </li>
  2685. <li>
  2686. <p><code>customer.example.net</code> ─ updating synapse to listen on the default port
  2687. 8448, or:</p>
  2688. </li>
  2689. <li>
  2690. <p><code>customer.example.net:8000</code> ─ ensuring that if there is a reverse proxy
  2691. on <code>customer.example.net:8000</code> it correctly handles HTTP requests with
  2692. Host header set to <code>customer.example.net:8000</code>.</p>
  2693. </li>
  2694. </ol>
  2695. </li>
  2696. </ol>
  2697. <h2 id="faq"><a class="header" href="#faq">FAQ</a></h2>
  2698. <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>
  2699. <p>Upgrade as soon as you can in preparation for Synapse 1.0.0, and update your
  2700. TLS certificates as <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">above</a>.</p>
  2701. <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>
  2702. <p>Nothing initially, but once 1.0.0 is in the wild it will not be possible to
  2703. federate with 1.0.0 servers.</p>
  2704. <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>
  2705. <p>If the admin takes no action at all, and remains on a Synapse &lt; 0.99.0 then the
  2706. homeserver will be unable to federate with those who have implemented
  2707. .well-known. Then, as above, once the month upgrade window has expired the
  2708. homeserver will not be able to federate with any Synapse &gt;= 1.0.0</p>
  2709. <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>
  2710. <p>If your homeserver listens on the default federation port (8448), and your
  2711. <code>server_name</code> points to the host that your homeserver runs on, you do not need an
  2712. SRV record or <code>.well-known/matrix/server</code> URI.</p>
  2713. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  2714. fresh Upcloud VPS or similar, you could install Synapse 0.99 on that host,
  2715. giving it a server_name of <code>example.com</code>, and it would automatically generate a
  2716. valid TLS certificate for you via Let's Encrypt and no SRV record or
  2717. <code>.well-known</code> URI would be needed.</p>
  2718. <p>This is the common case, although you can add an SRV record or
  2719. <code>.well-known/matrix/server</code> URI for completeness if you wish.</p>
  2720. <p><strong>However</strong>, if your server does not listen on port 8448, or if your <code>server_name</code>
  2721. does not point to the host that your homeserver runs on, you will need to let
  2722. other servers know how to find it.</p>
  2723. <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
  2724. currently&quot;</a> above.</p>
  2725. <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>
  2726. <p>Firstly, if you didn't need an SRV record before (because your server is
  2727. listening on port 8448 of your server_name), you certainly don't need one now:
  2728. the defaults are still the same.</p>
  2729. <p>If you previously had an SRV record, you can keep using it provided you are
  2730. able to give Synapse a TLS certificate corresponding to your server name. For
  2731. example, suppose you had the following SRV record, which directs matrix traffic
  2732. for example.com to matrix.example.com:443:</p>
  2733. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 443 matrix.example.com
  2734. </code></pre>
  2735. <p>In this case, Synapse must be given a certificate for example.com - or be
  2736. configured to acquire one from Let's Encrypt.</p>
  2737. <p>If you are unable to give Synapse a certificate for your server_name, you will
  2738. also need to use a .well-known URI instead. However, see also &quot;I have created a
  2739. .well-known URI. Do I still need an SRV record?&quot;.</p>
  2740. <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>
  2741. <p>As of Synapse 0.99, Synapse will first check for the existence of a <code>.well-known</code>
  2742. URI and follow any delegation it suggests. It will only then check for the
  2743. existence of an SRV record.</p>
  2744. <p>That means that the SRV record will often be redundant. However, you should
  2745. remember that there may still be older versions of Synapse in the federation
  2746. which do not understand <code>.well-known</code> URIs, so if you removed your SRV record you
  2747. would no longer be able to federate with them.</p>
  2748. <p>It is therefore best to leave the SRV record in place for now. Synapse 0.34 and
  2749. earlier will follow the SRV record (and not care about the invalid
  2750. certificate). Synapse 0.99 and later will follow the .well-known URI, with the
  2751. correct certificate chain.</p>
  2752. <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>
  2753. <p>We have always wanted Matrix servers to be as easy to set up as possible, and
  2754. so back when we started federation in 2014 we didn't want admins to have to go
  2755. through the cumbersome process of buying a valid TLS certificate to run a
  2756. server. This was before Let's Encrypt came along and made getting a free and
  2757. valid TLS certificate straightforward. So instead, we adopted a system based on
  2758. <a href="https://en.wikipedia.org/wiki/Convergence_(SSL)">Perspectives</a>: an approach
  2759. where you check a set of &quot;notary servers&quot; (in practice, homeservers) to vouch
  2760. for the validity of a certificate rather than having it signed by a CA. As long
  2761. as enough different notaries agree on the certificate's validity, then it is
  2762. trusted.</p>
  2763. <p>However, in practice this has never worked properly. Most people only use the
  2764. default notary server (matrix.org), leading to inadvertent centralisation which
  2765. we want to eliminate. Meanwhile, we never implemented the full consensus
  2766. algorithm to query the servers participating in a room to determine consensus
  2767. on whether a given certificate is valid. This is fiddly to get right
  2768. (especially in face of sybil attacks), and we found ourselves questioning
  2769. whether it was worth the effort to finish the work and commit to maintaining a
  2770. secure certificate validation system as opposed to focusing on core Matrix
  2771. development.</p>
  2772. <p>Meanwhile, Let's Encrypt came along in 2016, and put the final nail in the
  2773. coffin of the Perspectives project (which was already pretty dead). So, the
  2774. Spec Core Team decided that a better approach would be to mandate valid TLS
  2775. certificates for federation alongside the rest of the Web. More details can be
  2776. found in
  2777. <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>
  2778. <p>This results in a breaking change, which is disruptive, but absolutely critical
  2779. for the security model. However, the existence of Let's Encrypt as a trivial
  2780. way to replace the old self-signed certificates with valid CA-signed ones helps
  2781. smooth things over massively, especially as Synapse can now automate Let's
  2782. Encrypt certificate generation if needed.</p>
  2783. <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>
  2784. <p>Yes, you are welcome to manage your certificates yourself. Synapse will only
  2785. attempt to obtain certificates from Let's Encrypt if you configure it to do
  2786. so.The only requirement is that there is a valid TLS cert present for
  2787. federation end points.</p>
  2788. <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>
  2789. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  2790. find it easier to direct federation traffic to a reverse proxy and manage their
  2791. own TLS certificates, and this is a supported configuration.</p>
  2792. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2793. reverse proxy.</p>
  2794. <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>
  2795. <p>Practically speaking, this is no longer necessary.</p>
  2796. <p>If you are using a reverse proxy for all of your TLS traffic, then you can set
  2797. <code>no_tls: True</code>. In that case, the only reason Synapse needs the certificate is
  2798. to populate a legacy 'tls_fingerprints' field in the federation API. This is
  2799. ignored by Synapse 0.99.0 and later, and the only time pre-0.99 Synapses will
  2800. check it is when attempting to fetch the server keys - and generally this is
  2801. delegated via <code>matrix.org</code>, which is on 0.99.0.</p>
  2802. <p>However, there is a bug in Synapse 0.99.0
  2803. <a href="https://github.com/matrix-org/synapse/issues/4554">4554</a> which prevents
  2804. Synapse from starting if you do not give it a TLS certificate. To work around
  2805. this, you can give it any TLS certificate at all. This will be fixed soon.</p>
  2806. <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>
  2807. <p>No. There is nothing stopping you from using different certificates,
  2808. particularly if you are using a reverse proxy. However, Synapse will use the
  2809. same certificate on any ports where TLS is configured.</p>
  2810. <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>
  2811. <p>Synapse will reload the keys and certificates when it receives a SIGHUP - for
  2812. example <code>kill -HUP $(cat homeserver.pid)</code>. Alternatively, simply restart
  2813. Synapse, though this will result in downtime while it restarts.</p>
  2814. <div 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>
  2815. <p>Federation is the process by which users on different servers can participate
  2816. in the same room. For this to work, those other servers must be able to contact
  2817. yours to send messages.</p>
  2818. <p>The <code>server_name</code> configured in the Synapse configuration file (often
  2819. <code>homeserver.yaml</code>) defines how resources (users, rooms, etc.) will be
  2820. identified (eg: <code>@user:example.com</code>, <code>#room:example.com</code>). By default,
  2821. it is also the domain that other servers will use to try to reach your
  2822. server (via port 8448). This is easy to set up and will work provided
  2823. you set the <code>server_name</code> to match your machine's public DNS hostname.</p>
  2824. <p>For this default configuration to work, you will need to listen for TLS
  2825. connections on port 8448. The preferred way to do that is by using a
  2826. reverse proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions
  2827. on how to correctly set one up.</p>
  2828. <p>In some cases you might not want to run Synapse on the machine that has
  2829. the <code>server_name</code> as its public DNS hostname, or you might want federation
  2830. traffic to use a different port than 8448. For example, you might want to
  2831. have your user names look like <code>@user:example.com</code>, but you want to run
  2832. Synapse on <code>synapse.example.com</code> on port 443. This can be done using
  2833. delegation, which allows an admin to control where federation traffic should
  2834. be sent. See <a href="delegate.html">the delegation documentation</a> for instructions on how to set this up.</p>
  2835. <p>Once federation has been configured, you should be able to join a room over
  2836. federation. A good place to start is <code>#synapse:matrix.org</code> - a room for
  2837. Synapse admins.</p>
  2838. <h2 id="troubleshooting-3"><a class="header" href="#troubleshooting-3">Troubleshooting</a></h2>
  2839. <p>You can use the <a href="https://matrix.org/federationtester">federation tester</a>
  2840. to check if your homeserver is configured correctly. Alternatively try the
  2841. <a href="https://matrix.org/federationtester/api/report?server_name=DOMAIN">JSON API used by the federation tester</a>.
  2842. Note that you'll have to modify this URL to replace <code>DOMAIN</code> with your
  2843. <code>server_name</code>. Hitting the API directly provides extra detail.</p>
  2844. <p>The typical failure mode for federation is that when the server tries to join
  2845. a room, it is rejected with &quot;401: Unauthorized&quot;. Generally this means that other
  2846. servers in the room could not access yours. (Joining a room over federation is
  2847. a complicated dance which requires connections in both directions).</p>
  2848. <p>Another common problem is that people on other servers can't join rooms that
  2849. you invite them to. This can be caused by an incorrectly-configured reverse
  2850. proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions on how
  2851. to correctly configure a reverse proxy.</p>
  2852. <h3 id="known-issues"><a class="header" href="#known-issues">Known issues</a></h3>
  2853. <p><strong>HTTP <code>308 Permanent Redirect</code> redirects are not followed</strong>: Due to missing features
  2854. in the HTTP library used by Synapse, 308 redirects are currently not followed by
  2855. federating servers, which can cause <code>M_UNKNOWN</code> or <code>401 Unauthorized</code> errors. This
  2856. may affect users who are redirecting apex-to-www (e.g. <code>example.com</code> -&gt; <code>www.example.com</code>),
  2857. and especially users of the Kubernetes <em>Nginx Ingress</em> module, which uses 308 redirect
  2858. codes by default. For those Kubernetes users, <a href="https://stackoverflow.com/a/52617528/5096871">this Stackoverflow post</a>
  2859. might be helpful. For other users, switching to a <code>301 Moved Permanently</code> code may be
  2860. an option. 308 redirect codes will be supported properly in a future
  2861. release of Synapse.</p>
  2862. <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>
  2863. <p>If you want to get up and running quickly with a trio of homeservers in a
  2864. private federation, there is a script in the <code>demo</code> directory. This is mainly
  2865. useful just for development purposes. See <a href="https://github.com/matrix-org/synapse/tree/develop/demo/">demo/README</a>.</p>
  2866. <div style="break-before: page; page-break-before: always;"></div><h1 id="configuration-1"><a class="header" href="#configuration-1">Configuration</a></h1>
  2867. <p>This section contains information on tweaking Synapse via the various options in the configuration file. A configuration
  2868. file should have been generated when you <a href="usage/configuration/../../setup/installation.html">installed Synapse</a>.</p>
  2869. <div 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>
  2870. <p>Below is a sample homeserver configuration file. The homeserver configuration file
  2871. can be tweaked to change the behaviour of your homeserver. A restart of the server is
  2872. generally required to apply any changes made to this file.</p>
  2873. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  2874. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  2875. a fresh config using Synapse by following the instructions in
  2876. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  2877. <pre><code class="language-yaml"># This file is maintained as an up-to-date snapshot of the default
  2878. # homeserver.yaml configuration generated by Synapse.
  2879. #
  2880. # It is intended to act as a reference for the default configuration,
  2881. # helping admins keep track of new options and other changes, and compare
  2882. # their configs with the current default. As such, many of the actual
  2883. # config values shown are placeholders.
  2884. #
  2885. # It is *not* intended to be copied and used as the basis for a real
  2886. # homeserver.yaml. Instead, if you are starting from scratch, please generate
  2887. # a fresh config using Synapse by following the instructions in
  2888. # https://matrix-org.github.io/synapse/latest/setup/installation.html.
  2889. # Configuration options that take a time period can be set using a number
  2890. # followed by a letter. Letters have the following meanings:
  2891. # s = second
  2892. # m = minute
  2893. # h = hour
  2894. # d = day
  2895. # w = week
  2896. # y = year
  2897. # For example, setting redaction_retention_period: 5m would remove redacted
  2898. # messages from the database after 5 minutes, rather than 5 months.
  2899. ################################################################################
  2900. # Configuration file for Synapse.
  2901. #
  2902. # This is a YAML file: see [1] for a quick introduction. Note in particular
  2903. # that *indentation is important*: all the elements of a list or dictionary
  2904. # should have the same indentation.
  2905. #
  2906. # [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  2907. ## Modules ##
  2908. # Server admins can expand Synapse's functionality with external modules.
  2909. #
  2910. # See https://matrix-org.github.io/synapse/latest/modules.html for more
  2911. # documentation on how to configure or create custom modules for Synapse.
  2912. #
  2913. modules:
  2914. # - module: my_super_module.MySuperClass
  2915. # config:
  2916. # do_thing: true
  2917. # - module: my_other_super_module.SomeClass
  2918. # config: {}
  2919. ## Server ##
  2920. # The public-facing domain of the server
  2921. #
  2922. # The server_name name will appear at the end of usernames and room addresses
  2923. # created on this server. For example if the server_name was example.com,
  2924. # usernames on this server would be in the format @user:example.com
  2925. #
  2926. # In most cases you should avoid using a matrix specific subdomain such as
  2927. # matrix.example.com or synapse.example.com as the server_name for the same
  2928. # reasons you wouldn't use user@email.example.com as your email address.
  2929. # See https://matrix-org.github.io/synapse/latest/delegate.html
  2930. # for information on how to host Synapse on a subdomain while preserving
  2931. # a clean server_name.
  2932. #
  2933. # The server_name cannot be changed later so it is important to
  2934. # configure this correctly before you start Synapse. It should be all
  2935. # lowercase and may contain an explicit port.
  2936. # Examples: matrix.org, localhost:8080
  2937. #
  2938. server_name: &quot;SERVERNAME&quot;
  2939. # When running as a daemon, the file to store the pid in
  2940. #
  2941. pid_file: DATADIR/homeserver.pid
  2942. # The absolute URL to the web client which /_matrix/client will redirect
  2943. # to if 'webclient' is configured under the 'listeners' configuration.
  2944. #
  2945. # This option can be also set to the filesystem path to the web client
  2946. # which will be served at /_matrix/client/ if 'webclient' is configured
  2947. # under the 'listeners' configuration, however this is a security risk:
  2948. # https://github.com/matrix-org/synapse#security-note
  2949. #
  2950. #web_client_location: https://riot.example.com/
  2951. # The public-facing base URL that clients use to access this Homeserver (not
  2952. # including _matrix/...). This is the same URL a user might enter into the
  2953. # 'Custom Homeserver URL' field on their client. If you use Synapse with a
  2954. # reverse proxy, this should be the URL to reach Synapse via the proxy.
  2955. # Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
  2956. # 'listeners' below).
  2957. #
  2958. #public_baseurl: https://example.com/
  2959. # Set the soft limit on the number of file descriptors synapse can use
  2960. # Zero is used to indicate synapse should set the soft limit to the
  2961. # hard limit.
  2962. #
  2963. #soft_file_limit: 0
  2964. # Presence tracking allows users to see the state (e.g online/offline)
  2965. # of other local and remote users.
  2966. #
  2967. presence:
  2968. # Uncomment to disable presence tracking on this homeserver. This option
  2969. # replaces the previous top-level 'use_presence' option.
  2970. #
  2971. #enabled: false
  2972. # Whether to require authentication to retrieve profile data (avatars,
  2973. # display names) of other users through the client API. Defaults to
  2974. # 'false'. Note that profile data is also available via the federation
  2975. # API, unless allow_profile_lookup_over_federation is set to false.
  2976. #
  2977. #require_auth_for_profile_requests: true
  2978. # Uncomment to require a user to share a room with another user in order
  2979. # to retrieve their profile information. Only checked on Client-Server
  2980. # requests. Profile requests from other servers should be checked by the
  2981. # requesting server. Defaults to 'false'.
  2982. #
  2983. #limit_profile_requests_to_users_who_share_rooms: true
  2984. # Uncomment to prevent a user's profile data from being retrieved and
  2985. # displayed in a room until they have joined it. By default, a user's
  2986. # profile data is included in an invite event, regardless of the values
  2987. # of the above two settings, and whether or not the users share a server.
  2988. # Defaults to 'true'.
  2989. #
  2990. #include_profile_data_on_invite: false
  2991. # If set to 'true', removes the need for authentication to access the server's
  2992. # public rooms directory through the client API, meaning that anyone can
  2993. # query the room directory. Defaults to 'false'.
  2994. #
  2995. #allow_public_rooms_without_auth: true
  2996. # If set to 'true', allows any other homeserver to fetch the server's public
  2997. # rooms directory via federation. Defaults to 'false'.
  2998. #
  2999. #allow_public_rooms_over_federation: true
  3000. # The default room version for newly created rooms.
  3001. #
  3002. # Known room versions are listed here:
  3003. # https://matrix.org/docs/spec/#complete-list-of-room-versions
  3004. #
  3005. # For example, for room version 1, default_room_version should be set
  3006. # to &quot;1&quot;.
  3007. #
  3008. #default_room_version: &quot;6&quot;
  3009. # The GC threshold parameters to pass to `gc.set_threshold`, if defined
  3010. #
  3011. #gc_thresholds: [700, 10, 10]
  3012. # The minimum time in seconds between each GC for a generation, regardless of
  3013. # the GC thresholds. This ensures that we don't do GC too frequently.
  3014. #
  3015. # A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
  3016. # generation 0 GCs, etc.
  3017. #
  3018. # Defaults to `[1s, 10s, 30s]`.
  3019. #
  3020. #gc_min_interval: [0.5s, 30s, 1m]
  3021. # Set the limit on the returned events in the timeline in the get
  3022. # and sync operations. The default value is 100. -1 means no upper limit.
  3023. #
  3024. # Uncomment the following to increase the limit to 5000.
  3025. #
  3026. #filter_timeline_limit: 5000
  3027. # Whether room invites to users on this server should be blocked
  3028. # (except those sent by local server admins). The default is False.
  3029. #
  3030. #block_non_admin_invites: true
  3031. # Room searching
  3032. #
  3033. # If disabled, new messages will not be indexed for searching and users
  3034. # will receive errors when searching for messages. Defaults to enabled.
  3035. #
  3036. #enable_search: false
  3037. # Prevent outgoing requests from being sent to the following blacklisted IP address
  3038. # CIDR ranges. If this option is not specified then it defaults to private IP
  3039. # address ranges (see the example below).
  3040. #
  3041. # The blacklist applies to the outbound requests for federation, identity servers,
  3042. # push servers, and for checking key validity for third-party invite events.
  3043. #
  3044. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3045. # listed here, since they correspond to unroutable addresses.)
  3046. #
  3047. # This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
  3048. #
  3049. # Note: The value is ignored when an HTTP proxy is in use
  3050. #
  3051. #ip_range_blacklist:
  3052. # - '127.0.0.0/8'
  3053. # - '10.0.0.0/8'
  3054. # - '172.16.0.0/12'
  3055. # - '192.168.0.0/16'
  3056. # - '100.64.0.0/10'
  3057. # - '192.0.0.0/24'
  3058. # - '169.254.0.0/16'
  3059. # - '192.88.99.0/24'
  3060. # - '198.18.0.0/15'
  3061. # - '192.0.2.0/24'
  3062. # - '198.51.100.0/24'
  3063. # - '203.0.113.0/24'
  3064. # - '224.0.0.0/4'
  3065. # - '::1/128'
  3066. # - 'fe80::/10'
  3067. # - 'fc00::/7'
  3068. # - '2001:db8::/32'
  3069. # - 'ff00::/8'
  3070. # - 'fec0::/10'
  3071. # List of IP address CIDR ranges that should be allowed for federation,
  3072. # identity servers, push servers, and for checking key validity for
  3073. # third-party invite events. This is useful for specifying exceptions to
  3074. # wide-ranging blacklisted target IP ranges - e.g. for communication with
  3075. # a push server only visible in your network.
  3076. #
  3077. # This whitelist overrides ip_range_blacklist and defaults to an empty
  3078. # list.
  3079. #
  3080. #ip_range_whitelist:
  3081. # - '192.168.1.1'
  3082. # List of ports that Synapse should listen on, their purpose and their
  3083. # configuration.
  3084. #
  3085. # Options for each listener include:
  3086. #
  3087. # port: the TCP port to bind to
  3088. #
  3089. # bind_addresses: a list of local addresses to listen on. The default is
  3090. # 'all local interfaces'.
  3091. #
  3092. # type: the type of listener. Normally 'http', but other valid options are:
  3093. # 'manhole' (see https://matrix-org.github.io/synapse/latest/manhole.html),
  3094. # 'metrics' (see https://matrix-org.github.io/synapse/latest/metrics-howto.html),
  3095. # 'replication' (see https://matrix-org.github.io/synapse/latest/workers.html).
  3096. #
  3097. # tls: set to true to enable TLS for this listener. Will use the TLS
  3098. # key/cert specified in tls_private_key_path / tls_certificate_path.
  3099. #
  3100. # x_forwarded: Only valid for an 'http' listener. Set to true to use the
  3101. # X-Forwarded-For header as the client IP. Useful when Synapse is
  3102. # behind a reverse-proxy.
  3103. #
  3104. # resources: Only valid for an 'http' listener. A list of resources to host
  3105. # on this port. Options for each resource are:
  3106. #
  3107. # names: a list of names of HTTP resources. See below for a list of
  3108. # valid resource names.
  3109. #
  3110. # compress: set to true to enable HTTP compression for this resource.
  3111. #
  3112. # additional_resources: Only valid for an 'http' listener. A map of
  3113. # additional endpoints which should be loaded via dynamic modules.
  3114. #
  3115. # Valid resource names are:
  3116. #
  3117. # client: the client-server API (/_matrix/client), and the synapse admin
  3118. # API (/_synapse/admin). Also implies 'media' and 'static'.
  3119. #
  3120. # consent: user consent forms (/_matrix/consent).
  3121. # See https://matrix-org.github.io/synapse/latest/consent_tracking.html.
  3122. #
  3123. # federation: the server-server API (/_matrix/federation). Also implies
  3124. # 'media', 'keys', 'openid'
  3125. #
  3126. # keys: the key discovery API (/_matrix/keys).
  3127. #
  3128. # media: the media API (/_matrix/media).
  3129. #
  3130. # metrics: the metrics interface.
  3131. # See https://matrix-org.github.io/synapse/latest/metrics-howto.html.
  3132. #
  3133. # openid: OpenID authentication.
  3134. #
  3135. # replication: the HTTP replication API (/_synapse/replication).
  3136. # See https://matrix-org.github.io/synapse/latest/workers.html.
  3137. #
  3138. # static: static resources under synapse/static (/_matrix/static). (Mostly
  3139. # useful for 'fallback authentication'.)
  3140. #
  3141. # webclient: A web client. Requires web_client_location to be set.
  3142. #
  3143. listeners:
  3144. # TLS-enabled listener: for when matrix traffic is sent directly to synapse.
  3145. #
  3146. # Disabled by default. To enable it, uncomment the following. (Note that you
  3147. # will also need to give Synapse a TLS key and certificate: see the TLS section
  3148. # below.)
  3149. #
  3150. #- port: 8448
  3151. # type: http
  3152. # tls: true
  3153. # resources:
  3154. # - names: [client, federation]
  3155. # Unsecure HTTP listener: for when matrix traffic passes through a reverse proxy
  3156. # that unwraps TLS.
  3157. #
  3158. # If you plan to use a reverse proxy, please see
  3159. # https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3160. #
  3161. - port: 8008
  3162. tls: false
  3163. type: http
  3164. x_forwarded: true
  3165. bind_addresses: ['::1', '127.0.0.1']
  3166. resources:
  3167. - names: [client, federation]
  3168. compress: false
  3169. # example additional_resources:
  3170. #
  3171. #additional_resources:
  3172. # &quot;/_matrix/my/custom/endpoint&quot;:
  3173. # module: my_module.CustomRequestHandler
  3174. # config: {}
  3175. # Turn on the twisted ssh manhole service on localhost on the given
  3176. # port.
  3177. #
  3178. #- port: 9000
  3179. # bind_addresses: ['::1', '127.0.0.1']
  3180. # type: manhole
  3181. # Connection settings for the manhole
  3182. #
  3183. manhole_settings:
  3184. # The username for the manhole. This defaults to 'matrix'.
  3185. #
  3186. #username: manhole
  3187. # The password for the manhole. This defaults to 'rabbithole'.
  3188. #
  3189. #password: mypassword
  3190. # The private and public SSH key pair used to encrypt the manhole traffic.
  3191. # If these are left unset, then hardcoded and non-secret keys are used,
  3192. # which could allow traffic to be intercepted if sent over a public network.
  3193. #
  3194. #ssh_priv_key_path: CONFDIR/id_rsa
  3195. #ssh_pub_key_path: CONFDIR/id_rsa.pub
  3196. # Forward extremities can build up in a room due to networking delays between
  3197. # homeservers. Once this happens in a large room, calculation of the state of
  3198. # that room can become quite expensive. To mitigate this, once the number of
  3199. # forward extremities reaches a given threshold, Synapse will send an
  3200. # org.matrix.dummy_event event, which will reduce the forward extremities
  3201. # in the room.
  3202. #
  3203. # This setting defines the threshold (i.e. number of forward extremities in the
  3204. # room) at which dummy events are sent. The default value is 10.
  3205. #
  3206. #dummy_events_threshold: 5
  3207. ## Homeserver blocking ##
  3208. # How to reach the server admin, used in ResourceLimitError
  3209. #
  3210. #admin_contact: 'mailto:admin@server.com'
  3211. # Global blocking
  3212. #
  3213. #hs_disabled: false
  3214. #hs_disabled_message: 'Human readable reason for why the HS is blocked'
  3215. # Monthly Active User Blocking
  3216. #
  3217. # Used in cases where the admin or server owner wants to limit to the
  3218. # number of monthly active users.
  3219. #
  3220. # 'limit_usage_by_mau' disables/enables monthly active user blocking. When
  3221. # enabled and a limit is reached the server returns a 'ResourceLimitError'
  3222. # with error type Codes.RESOURCE_LIMIT_EXCEEDED
  3223. #
  3224. # 'max_mau_value' is the hard limit of monthly active users above which
  3225. # the server will start blocking user actions.
  3226. #
  3227. # 'mau_trial_days' is a means to add a grace period for active users. It
  3228. # means that users must be active for this number of days before they
  3229. # can be considered active and guards against the case where lots of users
  3230. # sign up in a short space of time never to return after their initial
  3231. # session.
  3232. #
  3233. # 'mau_limit_alerting' is a means of limiting client side alerting
  3234. # should the mau limit be reached. This is useful for small instances
  3235. # where the admin has 5 mau seats (say) for 5 specific people and no
  3236. # interest increasing the mau limit further. Defaults to True, which
  3237. # means that alerting is enabled
  3238. #
  3239. #limit_usage_by_mau: false
  3240. #max_mau_value: 50
  3241. #mau_trial_days: 2
  3242. #mau_limit_alerting: false
  3243. # If enabled, the metrics for the number of monthly active users will
  3244. # be populated, however no one will be limited. If limit_usage_by_mau
  3245. # is true, this is implied to be true.
  3246. #
  3247. #mau_stats_only: false
  3248. # Sometimes the server admin will want to ensure certain accounts are
  3249. # never blocked by mau checking. These accounts are specified here.
  3250. #
  3251. #mau_limit_reserved_threepids:
  3252. # - medium: 'email'
  3253. # address: 'reserved_user@example.com'
  3254. # Used by phonehome stats to group together related servers.
  3255. #server_context: context
  3256. # Resource-constrained homeserver settings
  3257. #
  3258. # When this is enabled, the room &quot;complexity&quot; will be checked before a user
  3259. # joins a new remote room. If it is above the complexity limit, the server will
  3260. # disallow joining, or will instantly leave.
  3261. #
  3262. # Room complexity is an arbitrary measure based on factors such as the number of
  3263. # users in the room.
  3264. #
  3265. limit_remote_rooms:
  3266. # Uncomment to enable room complexity checking.
  3267. #
  3268. #enabled: true
  3269. # the limit above which rooms cannot be joined. The default is 1.0.
  3270. #
  3271. #complexity: 0.5
  3272. # override the error which is returned when the room is too complex.
  3273. #
  3274. #complexity_error: &quot;This room is too complex.&quot;
  3275. # allow server admins to join complex rooms. Default is false.
  3276. #
  3277. #admins_can_join: true
  3278. # Whether to require a user to be in the room to add an alias to it.
  3279. # Defaults to 'true'.
  3280. #
  3281. #require_membership_for_aliases: false
  3282. # Whether to allow per-room membership profiles through the send of membership
  3283. # events with profile information that differ from the target's global profile.
  3284. # Defaults to 'true'.
  3285. #
  3286. #allow_per_room_profiles: false
  3287. # How long to keep redacted events in unredacted form in the database. After
  3288. # this period redacted events get replaced with their redacted form in the DB.
  3289. #
  3290. # Defaults to `7d`. Set to `null` to disable.
  3291. #
  3292. #redaction_retention_period: 28d
  3293. # How long to track users' last seen time and IPs in the database.
  3294. #
  3295. # Defaults to `28d`. Set to `null` to disable clearing out of old rows.
  3296. #
  3297. #user_ips_max_age: 14d
  3298. # Message retention policy at the server level.
  3299. #
  3300. # Room admins and mods can define a retention period for their rooms using the
  3301. # 'm.room.retention' state event, and server admins can cap this period by setting
  3302. # the 'allowed_lifetime_min' and 'allowed_lifetime_max' config options.
  3303. #
  3304. # If this feature is enabled, Synapse will regularly look for and purge events
  3305. # which are older than the room's maximum retention period. Synapse will also
  3306. # filter events received over federation so that events that should have been
  3307. # purged are ignored and not stored again.
  3308. #
  3309. retention:
  3310. # The message retention policies feature is disabled by default. Uncomment the
  3311. # following line to enable it.
  3312. #
  3313. #enabled: true
  3314. # Default retention policy. If set, Synapse will apply it to rooms that lack the
  3315. # 'm.room.retention' state event. Currently, the value of 'min_lifetime' doesn't
  3316. # matter much because Synapse doesn't take it into account yet.
  3317. #
  3318. #default_policy:
  3319. # min_lifetime: 1d
  3320. # max_lifetime: 1y
  3321. # Retention policy limits. If set, and the state of a room contains a
  3322. # 'm.room.retention' event in its state which contains a 'min_lifetime' or a
  3323. # 'max_lifetime' that's out of these bounds, Synapse will cap the room's policy
  3324. # to these limits when running purge jobs.
  3325. #
  3326. #allowed_lifetime_min: 1d
  3327. #allowed_lifetime_max: 1y
  3328. # Server admins can define the settings of the background jobs purging the
  3329. # events which lifetime has expired under the 'purge_jobs' section.
  3330. #
  3331. # If no configuration is provided, a single job will be set up to delete expired
  3332. # events in every room daily.
  3333. #
  3334. # Each job's configuration defines which range of message lifetimes the job
  3335. # takes care of. For example, if 'shortest_max_lifetime' is '2d' and
  3336. # 'longest_max_lifetime' is '3d', the job will handle purging expired events in
  3337. # rooms whose state defines a 'max_lifetime' that's both higher than 2 days, and
  3338. # lower than or equal to 3 days. Both the minimum and the maximum value of a
  3339. # range are optional, e.g. a job with no 'shortest_max_lifetime' and a
  3340. # 'longest_max_lifetime' of '3d' will handle every room with a retention policy
  3341. # which 'max_lifetime' is lower than or equal to three days.
  3342. #
  3343. # The rationale for this per-job configuration is that some rooms might have a
  3344. # retention policy with a low 'max_lifetime', where history needs to be purged
  3345. # of outdated messages on a more frequent basis than for the rest of the rooms
  3346. # (e.g. every 12h), but not want that purge to be performed by a job that's
  3347. # iterating over every room it knows, which could be heavy on the server.
  3348. #
  3349. # If any purge job is configured, it is strongly recommended to have at least
  3350. # a single job with neither 'shortest_max_lifetime' nor 'longest_max_lifetime'
  3351. # set, or one job without 'shortest_max_lifetime' and one job without
  3352. # 'longest_max_lifetime' set. Otherwise some rooms might be ignored, even if
  3353. # 'allowed_lifetime_min' and 'allowed_lifetime_max' are set, because capping a
  3354. # room's policy to these values is done after the policies are retrieved from
  3355. # Synapse's database (which is done using the range specified in a purge job's
  3356. # configuration).
  3357. #
  3358. #purge_jobs:
  3359. # - longest_max_lifetime: 3d
  3360. # interval: 12h
  3361. # - shortest_max_lifetime: 3d
  3362. # interval: 1d
  3363. # Inhibits the /requestToken endpoints from returning an error that might leak
  3364. # information about whether an e-mail address is in use or not on this
  3365. # homeserver.
  3366. # Note that for some endpoints the error situation is the e-mail already being
  3367. # used, and for others the error is entering the e-mail being unused.
  3368. # If this option is enabled, instead of returning an error, these endpoints will
  3369. # act as if no error happened and return a fake session ID ('sid') to clients.
  3370. #
  3371. #request_token_inhibit_3pid_errors: true
  3372. # A list of domains that the domain portion of 'next_link' parameters
  3373. # must match.
  3374. #
  3375. # This parameter is optionally provided by clients while requesting
  3376. # validation of an email or phone number, and maps to a link that
  3377. # users will be automatically redirected to after validation
  3378. # succeeds. Clients can make use this parameter to aid the validation
  3379. # process.
  3380. #
  3381. # The whitelist is applied whether the homeserver or an
  3382. # identity server is handling validation.
  3383. #
  3384. # The default value is no whitelist functionality; all domains are
  3385. # allowed. Setting this value to an empty list will instead disallow
  3386. # all domains.
  3387. #
  3388. #next_link_domain_whitelist: [&quot;matrix.org&quot;]
  3389. # Templates to use when generating email or HTML page contents.
  3390. #
  3391. templates:
  3392. # Directory in which Synapse will try to find template files to use to generate
  3393. # email or HTML page contents.
  3394. # If not set, or a file is not found within the template directory, a default
  3395. # template from within the Synapse package will be used.
  3396. #
  3397. # See https://matrix-org.github.io/synapse/latest/templates.html for more
  3398. # information about using custom templates.
  3399. #
  3400. #custom_template_directory: /path/to/custom/templates/
  3401. ## TLS ##
  3402. # PEM-encoded X509 certificate for TLS.
  3403. # This certificate, as of Synapse 1.0, will need to be a valid and verifiable
  3404. # certificate, signed by a recognised Certificate Authority.
  3405. #
  3406. # Be sure to use a `.pem` file that includes the full certificate chain including
  3407. # any intermediate certificates (for instance, if using certbot, use
  3408. # `fullchain.pem` as your certificate, not `cert.pem`).
  3409. #
  3410. #tls_certificate_path: &quot;CONFDIR/SERVERNAME.tls.crt&quot;
  3411. # PEM-encoded private key for TLS
  3412. #
  3413. #tls_private_key_path: &quot;CONFDIR/SERVERNAME.tls.key&quot;
  3414. # Whether to verify TLS server certificates for outbound federation requests.
  3415. #
  3416. # Defaults to `true`. To disable certificate verification, uncomment the
  3417. # following line.
  3418. #
  3419. #federation_verify_certificates: false
  3420. # The minimum TLS version that will be used for outbound federation requests.
  3421. #
  3422. # Defaults to `1`. Configurable to `1`, `1.1`, `1.2`, or `1.3`. Note
  3423. # that setting this value higher than `1.2` will prevent federation to most
  3424. # of the public Matrix network: only configure it to `1.3` if you have an
  3425. # entirely private federation setup and you can ensure TLS 1.3 support.
  3426. #
  3427. #federation_client_minimum_tls_version: 1.2
  3428. # Skip federation certificate verification on the following whitelist
  3429. # of domains.
  3430. #
  3431. # This setting should only be used in very specific cases, such as
  3432. # federation over Tor hidden services and similar. For private networks
  3433. # of homeservers, you likely want to use a private CA instead.
  3434. #
  3435. # Only effective if federation_verify_certicates is `true`.
  3436. #
  3437. #federation_certificate_verification_whitelist:
  3438. # - lon.example.com
  3439. # - *.domain.com
  3440. # - *.onion
  3441. # List of custom certificate authorities for federation traffic.
  3442. #
  3443. # This setting should only normally be used within a private network of
  3444. # homeservers.
  3445. #
  3446. # Note that this list will replace those that are provided by your
  3447. # operating environment. Certificates must be in PEM format.
  3448. #
  3449. #federation_custom_ca_list:
  3450. # - myCA1.pem
  3451. # - myCA2.pem
  3452. # - myCA3.pem
  3453. ## Federation ##
  3454. # Restrict federation to the following whitelist of domains.
  3455. # N.B. we recommend also firewalling your federation listener to limit
  3456. # inbound federation traffic as early as possible, rather than relying
  3457. # purely on this application-layer restriction. If not specified, the
  3458. # default is to whitelist everything.
  3459. #
  3460. #federation_domain_whitelist:
  3461. # - lon.example.com
  3462. # - nyc.example.com
  3463. # - syd.example.com
  3464. # Report prometheus metrics on the age of PDUs being sent to and received from
  3465. # the following domains. This can be used to give an idea of &quot;delay&quot; on inbound
  3466. # and outbound federation, though be aware that any delay can be due to problems
  3467. # at either end or with the intermediate network.
  3468. #
  3469. # By default, no domains are monitored in this way.
  3470. #
  3471. #federation_metrics_domains:
  3472. # - matrix.org
  3473. # - example.com
  3474. # Uncomment to disable profile lookup over federation. By default, the
  3475. # Federation API allows other homeservers to obtain profile data of any user
  3476. # on this homeserver. Defaults to 'true'.
  3477. #
  3478. #allow_profile_lookup_over_federation: false
  3479. # Uncomment to disable device display name lookup over federation. By default, the
  3480. # Federation API allows other homeservers to obtain device display names of any user
  3481. # on this homeserver. Defaults to 'true'.
  3482. #
  3483. #allow_device_name_lookup_over_federation: false
  3484. ## Caching ##
  3485. # Caching can be configured through the following options.
  3486. #
  3487. # A cache 'factor' is a multiplier that can be applied to each of
  3488. # Synapse's caches in order to increase or decrease the maximum
  3489. # number of entries that can be stored.
  3490. # The number of events to cache in memory. Not affected by
  3491. # caches.global_factor.
  3492. #
  3493. #event_cache_size: 10K
  3494. caches:
  3495. # Controls the global cache factor, which is the default cache factor
  3496. # for all caches if a specific factor for that cache is not otherwise
  3497. # set.
  3498. #
  3499. # This can also be set by the &quot;SYNAPSE_CACHE_FACTOR&quot; environment
  3500. # variable. Setting by environment variable takes priority over
  3501. # setting through the config file.
  3502. #
  3503. # Defaults to 0.5, which will half the size of all caches.
  3504. #
  3505. #global_factor: 1.0
  3506. # A dictionary of cache name to cache factor for that individual
  3507. # cache. Overrides the global cache factor for a given cache.
  3508. #
  3509. # These can also be set through environment variables comprised
  3510. # of &quot;SYNAPSE_CACHE_FACTOR_&quot; + the name of the cache in capital
  3511. # letters and underscores. Setting by environment variable
  3512. # takes priority over setting through the config file.
  3513. # Ex. SYNAPSE_CACHE_FACTOR_GET_USERS_WHO_SHARE_ROOM_WITH_USER=2.0
  3514. #
  3515. # Some caches have '*' and other characters that are not
  3516. # alphanumeric or underscores. These caches can be named with or
  3517. # without the special characters stripped. For example, to specify
  3518. # the cache factor for `*stateGroupCache*` via an environment
  3519. # variable would be `SYNAPSE_CACHE_FACTOR_STATEGROUPCACHE=2.0`.
  3520. #
  3521. per_cache_factors:
  3522. #get_users_who_share_room_with_user: 2.0
  3523. # Controls how long an entry can be in a cache without having been
  3524. # accessed before being evicted. Defaults to None, which means
  3525. # entries are never evicted based on time.
  3526. #
  3527. #expiry_time: 30m
  3528. # Controls how long the results of a /sync request are cached for after
  3529. # a successful response is returned. A higher duration can help clients with
  3530. # intermittent connections, at the cost of higher memory usage.
  3531. #
  3532. # By default, this is zero, which means that sync responses are not cached
  3533. # at all.
  3534. #
  3535. #sync_response_cache_duration: 2m
  3536. ## Database ##
  3537. # The 'database' setting defines the database that synapse uses to store all of
  3538. # its data.
  3539. #
  3540. # 'name' gives the database engine to use: either 'sqlite3' (for SQLite) or
  3541. # 'psycopg2' (for PostgreSQL).
  3542. #
  3543. # 'txn_limit' gives the maximum number of transactions to run per connection
  3544. # before reconnecting. Defaults to 0, which means no limit.
  3545. #
  3546. # 'args' gives options which are passed through to the database engine,
  3547. # except for options starting 'cp_', which are used to configure the Twisted
  3548. # connection pool. For a reference to valid arguments, see:
  3549. # * for sqlite: https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
  3550. # * for postgres: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
  3551. # * for the connection pool: https://twistedmatrix.com/documents/current/api/twisted.enterprise.adbapi.ConnectionPool.html#__init__
  3552. #
  3553. #
  3554. # Example SQLite configuration:
  3555. #
  3556. #database:
  3557. # name: sqlite3
  3558. # args:
  3559. # database: /path/to/homeserver.db
  3560. #
  3561. #
  3562. # Example Postgres configuration:
  3563. #
  3564. #database:
  3565. # name: psycopg2
  3566. # txn_limit: 10000
  3567. # args:
  3568. # user: synapse_user
  3569. # password: secretpassword
  3570. # database: synapse
  3571. # host: localhost
  3572. # port: 5432
  3573. # cp_min: 5
  3574. # cp_max: 10
  3575. #
  3576. # For more information on using Synapse with Postgres,
  3577. # see https://matrix-org.github.io/synapse/latest/postgres.html.
  3578. #
  3579. database:
  3580. name: sqlite3
  3581. args:
  3582. database: DATADIR/homeserver.db
  3583. ## Logging ##
  3584. # A yaml python logging config file as described by
  3585. # https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  3586. #
  3587. log_config: &quot;CONFDIR/SERVERNAME.log.config&quot;
  3588. ## Ratelimiting ##
  3589. # Ratelimiting settings for client actions (registration, login, messaging).
  3590. #
  3591. # Each ratelimiting configuration is made of two parameters:
  3592. # - per_second: number of requests a client can send per second.
  3593. # - burst_count: number of requests a client can send before being throttled.
  3594. #
  3595. # Synapse currently uses the following configurations:
  3596. # - one for messages that ratelimits sending based on the account the client
  3597. # is using
  3598. # - one for registration that ratelimits registration requests based on the
  3599. # client's IP address.
  3600. # - one for checking the validity of registration tokens that ratelimits
  3601. # requests based on the client's IP address.
  3602. # - one for login that ratelimits login requests based on the client's IP
  3603. # address.
  3604. # - one for login that ratelimits login requests based on the account the
  3605. # client is attempting to log into.
  3606. # - one for login that ratelimits login requests based on the account the
  3607. # client is attempting to log into, based on the amount of failed login
  3608. # attempts for this account.
  3609. # - one for ratelimiting redactions by room admins. If this is not explicitly
  3610. # set then it uses the same ratelimiting as per rc_message. This is useful
  3611. # to allow room admins to deal with abuse quickly.
  3612. # - two for ratelimiting number of rooms a user can join, &quot;local&quot; for when
  3613. # users are joining rooms the server is already in (this is cheap) vs
  3614. # &quot;remote&quot; for when users are trying to join rooms not on the server (which
  3615. # can be more expensive)
  3616. # - one for ratelimiting how often a user or IP can attempt to validate a 3PID.
  3617. # - two for ratelimiting how often invites can be sent in a room or to a
  3618. # specific user.
  3619. #
  3620. # The defaults are as shown below.
  3621. #
  3622. #rc_message:
  3623. # per_second: 0.2
  3624. # burst_count: 10
  3625. #
  3626. #rc_registration:
  3627. # per_second: 0.17
  3628. # burst_count: 3
  3629. #
  3630. #rc_registration_token_validity:
  3631. # per_second: 0.1
  3632. # burst_count: 5
  3633. #
  3634. #rc_login:
  3635. # address:
  3636. # per_second: 0.17
  3637. # burst_count: 3
  3638. # account:
  3639. # per_second: 0.17
  3640. # burst_count: 3
  3641. # failed_attempts:
  3642. # per_second: 0.17
  3643. # burst_count: 3
  3644. #
  3645. #rc_admin_redaction:
  3646. # per_second: 1
  3647. # burst_count: 50
  3648. #
  3649. #rc_joins:
  3650. # local:
  3651. # per_second: 0.1
  3652. # burst_count: 10
  3653. # remote:
  3654. # per_second: 0.01
  3655. # burst_count: 10
  3656. #
  3657. #rc_3pid_validation:
  3658. # per_second: 0.003
  3659. # burst_count: 5
  3660. #
  3661. #rc_invites:
  3662. # per_room:
  3663. # per_second: 0.3
  3664. # burst_count: 10
  3665. # per_user:
  3666. # per_second: 0.003
  3667. # burst_count: 5
  3668. # Ratelimiting settings for incoming federation
  3669. #
  3670. # The rc_federation configuration is made up of the following settings:
  3671. # - window_size: window size in milliseconds
  3672. # - sleep_limit: number of federation requests from a single server in
  3673. # a window before the server will delay processing the request.
  3674. # - sleep_delay: duration in milliseconds to delay processing events
  3675. # from remote servers by if they go over the sleep limit.
  3676. # - reject_limit: maximum number of concurrent federation requests
  3677. # allowed from a single server
  3678. # - concurrent: number of federation requests to concurrently process
  3679. # from a single server
  3680. #
  3681. # The defaults are as shown below.
  3682. #
  3683. #rc_federation:
  3684. # window_size: 1000
  3685. # sleep_limit: 10
  3686. # sleep_delay: 500
  3687. # reject_limit: 50
  3688. # concurrent: 3
  3689. # Target outgoing federation transaction frequency for sending read-receipts,
  3690. # per-room.
  3691. #
  3692. # If we end up trying to send out more read-receipts, they will get buffered up
  3693. # into fewer transactions.
  3694. #
  3695. #federation_rr_transactions_per_room_per_second: 50
  3696. ## Media Store ##
  3697. # Enable the media store service in the Synapse master. Uncomment the
  3698. # following if you are using a separate media store worker.
  3699. #
  3700. #enable_media_repo: false
  3701. # Directory where uploaded images and attachments are stored.
  3702. #
  3703. media_store_path: &quot;DATADIR/media_store&quot;
  3704. # Media storage providers allow media to be stored in different
  3705. # locations.
  3706. #
  3707. #media_storage_providers:
  3708. # - module: file_system
  3709. # # Whether to store newly uploaded local files
  3710. # store_local: false
  3711. # # Whether to store newly downloaded remote files
  3712. # store_remote: false
  3713. # # Whether to wait for successful storage for local uploads
  3714. # store_synchronous: false
  3715. # config:
  3716. # directory: /mnt/some/other/directory
  3717. # The largest allowed upload size in bytes
  3718. #
  3719. # If you are using a reverse proxy you may also need to set this value in
  3720. # your reverse proxy's config. Notably Nginx has a small max body size by default.
  3721. # See https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3722. #
  3723. #max_upload_size: 50M
  3724. # Maximum number of pixels that will be thumbnailed
  3725. #
  3726. #max_image_pixels: 32M
  3727. # Whether to generate new thumbnails on the fly to precisely match
  3728. # the resolution requested by the client. If true then whenever
  3729. # a new resolution is requested by the client the server will
  3730. # generate a new thumbnail. If false the server will pick a thumbnail
  3731. # from a precalculated list.
  3732. #
  3733. #dynamic_thumbnails: false
  3734. # List of thumbnails to precalculate when an image is uploaded.
  3735. #
  3736. #thumbnail_sizes:
  3737. # - width: 32
  3738. # height: 32
  3739. # method: crop
  3740. # - width: 96
  3741. # height: 96
  3742. # method: crop
  3743. # - width: 320
  3744. # height: 240
  3745. # method: scale
  3746. # - width: 640
  3747. # height: 480
  3748. # method: scale
  3749. # - width: 800
  3750. # height: 600
  3751. # method: scale
  3752. # Is the preview URL API enabled?
  3753. #
  3754. # 'false' by default: uncomment the following to enable it (and specify a
  3755. # url_preview_ip_range_blacklist blacklist).
  3756. #
  3757. #url_preview_enabled: true
  3758. # List of IP address CIDR ranges that the URL preview spider is denied
  3759. # from accessing. There are no defaults: you must explicitly
  3760. # specify a list for URL previewing to work. You should specify any
  3761. # internal services in your network that you do not want synapse to try
  3762. # to connect to, otherwise anyone in any Matrix room could cause your
  3763. # synapse to issue arbitrary GET requests to your internal services,
  3764. # causing serious security issues.
  3765. #
  3766. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3767. # listed here, since they correspond to unroutable addresses.)
  3768. #
  3769. # This must be specified if url_preview_enabled is set. It is recommended that
  3770. # you uncomment the following list as a starting point.
  3771. #
  3772. # Note: The value is ignored when an HTTP proxy is in use
  3773. #
  3774. #url_preview_ip_range_blacklist:
  3775. # - '127.0.0.0/8'
  3776. # - '10.0.0.0/8'
  3777. # - '172.16.0.0/12'
  3778. # - '192.168.0.0/16'
  3779. # - '100.64.0.0/10'
  3780. # - '192.0.0.0/24'
  3781. # - '169.254.0.0/16'
  3782. # - '192.88.99.0/24'
  3783. # - '198.18.0.0/15'
  3784. # - '192.0.2.0/24'
  3785. # - '198.51.100.0/24'
  3786. # - '203.0.113.0/24'
  3787. # - '224.0.0.0/4'
  3788. # - '::1/128'
  3789. # - 'fe80::/10'
  3790. # - 'fc00::/7'
  3791. # - '2001:db8::/32'
  3792. # - 'ff00::/8'
  3793. # - 'fec0::/10'
  3794. # List of IP address CIDR ranges that the URL preview spider is allowed
  3795. # to access even if they are specified in url_preview_ip_range_blacklist.
  3796. # This is useful for specifying exceptions to wide-ranging blacklisted
  3797. # target IP ranges - e.g. for enabling URL previews for a specific private
  3798. # website only visible in your network.
  3799. #
  3800. #url_preview_ip_range_whitelist:
  3801. # - '192.168.1.1'
  3802. # Optional list of URL matches that the URL preview spider is
  3803. # denied from accessing. You should use url_preview_ip_range_blacklist
  3804. # in preference to this, otherwise someone could define a public DNS
  3805. # entry that points to a private IP address and circumvent the blacklist.
  3806. # This is more useful if you know there is an entire shape of URL that
  3807. # you know that will never want synapse to try to spider.
  3808. #
  3809. # Each list entry is a dictionary of url component attributes as returned
  3810. # by urlparse.urlsplit as applied to the absolute form of the URL. See
  3811. # https://docs.python.org/2/library/urlparse.html#urlparse.urlsplit
  3812. # The values of the dictionary are treated as an filename match pattern
  3813. # applied to that component of URLs, unless they start with a ^ in which
  3814. # case they are treated as a regular expression match. If all the
  3815. # specified component matches for a given list item succeed, the URL is
  3816. # blacklisted.
  3817. #
  3818. #url_preview_url_blacklist:
  3819. # # blacklist any URL with a username in its URI
  3820. # - username: '*'
  3821. #
  3822. # # blacklist all *.google.com URLs
  3823. # - netloc: 'google.com'
  3824. # - netloc: '*.google.com'
  3825. #
  3826. # # blacklist all plain HTTP URLs
  3827. # - scheme: 'http'
  3828. #
  3829. # # blacklist http(s)://www.acme.com/foo
  3830. # - netloc: 'www.acme.com'
  3831. # path: '/foo'
  3832. #
  3833. # # blacklist any URL with a literal IPv4 address
  3834. # - netloc: '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  3835. # The largest allowed URL preview spidering size in bytes
  3836. #
  3837. #max_spider_size: 10M
  3838. # A list of values for the Accept-Language HTTP header used when
  3839. # downloading webpages during URL preview generation. This allows
  3840. # Synapse to specify the preferred languages that URL previews should
  3841. # be in when communicating with remote servers.
  3842. #
  3843. # Each value is a IETF language tag; a 2-3 letter identifier for a
  3844. # language, optionally followed by subtags separated by '-', specifying
  3845. # a country or region variant.
  3846. #
  3847. # Multiple values can be provided, and a weight can be added to each by
  3848. # using quality value syntax (;q=). '*' translates to any language.
  3849. #
  3850. # Defaults to &quot;en&quot;.
  3851. #
  3852. # Example:
  3853. #
  3854. # url_preview_accept_language:
  3855. # - en-UK
  3856. # - en-US;q=0.9
  3857. # - fr;q=0.8
  3858. # - *;q=0.7
  3859. #
  3860. url_preview_accept_language:
  3861. # - en
  3862. # oEmbed allows for easier embedding content from a website. It can be
  3863. # used for generating URLs previews of services which support it.
  3864. #
  3865. oembed:
  3866. # A default list of oEmbed providers is included with Synapse.
  3867. #
  3868. # Uncomment the following to disable using these default oEmbed URLs.
  3869. # Defaults to 'false'.
  3870. #
  3871. #disable_default_providers: true
  3872. # Additional files with oEmbed configuration (each should be in the
  3873. # form of providers.json).
  3874. #
  3875. # By default, this list is empty (so only the default providers.json
  3876. # is used).
  3877. #
  3878. #additional_providers:
  3879. # - oembed/my_providers.json
  3880. ## Captcha ##
  3881. # See docs/CAPTCHA_SETUP.md for full details of configuring this.
  3882. # This homeserver's ReCAPTCHA public key. Must be specified if
  3883. # enable_registration_captcha is enabled.
  3884. #
  3885. #recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  3886. # This homeserver's ReCAPTCHA private key. Must be specified if
  3887. # enable_registration_captcha is enabled.
  3888. #
  3889. #recaptcha_private_key: &quot;YOUR_PRIVATE_KEY&quot;
  3890. # Uncomment to enable ReCaptcha checks when registering, preventing signup
  3891. # unless a captcha is answered. Requires a valid ReCaptcha
  3892. # public/private key. Defaults to 'false'.
  3893. #
  3894. #enable_registration_captcha: true
  3895. # The API endpoint to use for verifying m.login.recaptcha responses.
  3896. # Defaults to &quot;https://www.recaptcha.net/recaptcha/api/siteverify&quot;.
  3897. #
  3898. #recaptcha_siteverify_api: &quot;https://my.recaptcha.site&quot;
  3899. ## TURN ##
  3900. # The public URIs of the TURN server to give to clients
  3901. #
  3902. #turn_uris: []
  3903. # The shared secret used to compute passwords for the TURN server
  3904. #
  3905. #turn_shared_secret: &quot;YOUR_SHARED_SECRET&quot;
  3906. # The Username and password if the TURN server needs them and
  3907. # does not use a token
  3908. #
  3909. #turn_username: &quot;TURNSERVER_USERNAME&quot;
  3910. #turn_password: &quot;TURNSERVER_PASSWORD&quot;
  3911. # How long generated TURN credentials last
  3912. #
  3913. #turn_user_lifetime: 1h
  3914. # Whether guests should be allowed to use the TURN server.
  3915. # This defaults to True, otherwise VoIP will be unreliable for guests.
  3916. # However, it does introduce a slight security risk as it allows users to
  3917. # connect to arbitrary endpoints without having first signed up for a
  3918. # valid account (e.g. by passing a CAPTCHA).
  3919. #
  3920. #turn_allow_guests: true
  3921. ## Registration ##
  3922. #
  3923. # Registration can be rate-limited using the parameters in the &quot;Ratelimiting&quot;
  3924. # section of this file.
  3925. # Enable registration for new users.
  3926. #
  3927. #enable_registration: false
  3928. # Time that a user's session remains valid for, after they log in.
  3929. #
  3930. # Note that this is not currently compatible with guest logins.
  3931. #
  3932. # Note also that this is calculated at login time: changes are not applied
  3933. # retrospectively to users who have already logged in.
  3934. #
  3935. # By default, this is infinite.
  3936. #
  3937. #session_lifetime: 24h
  3938. # The user must provide all of the below types of 3PID when registering.
  3939. #
  3940. #registrations_require_3pid:
  3941. # - email
  3942. # - msisdn
  3943. # Explicitly disable asking for MSISDNs from the registration
  3944. # flow (overrides registrations_require_3pid if MSISDNs are set as required)
  3945. #
  3946. #disable_msisdn_registration: true
  3947. # Mandate that users are only allowed to associate certain formats of
  3948. # 3PIDs with accounts on this server.
  3949. #
  3950. #allowed_local_3pids:
  3951. # - medium: email
  3952. # pattern: '^[^@]+@matrix\.org$'
  3953. # - medium: email
  3954. # pattern: '^[^@]+@vector\.im$'
  3955. # - medium: msisdn
  3956. # pattern: '\+44'
  3957. # Enable 3PIDs lookup requests to identity servers from this server.
  3958. #
  3959. #enable_3pid_lookup: true
  3960. # Require users to submit a token during registration.
  3961. # Tokens can be managed using the admin API:
  3962. # https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/registration_tokens.html
  3963. # Note that `enable_registration` must be set to `true`.
  3964. # Disabling this option will not delete any tokens previously generated.
  3965. # Defaults to false. Uncomment the following to require tokens:
  3966. #
  3967. #registration_requires_token: true
  3968. # If set, allows registration of standard or admin accounts by anyone who
  3969. # has the shared secret, even if registration is otherwise disabled.
  3970. #
  3971. #registration_shared_secret: &lt;PRIVATE STRING&gt;
  3972. # Set the number of bcrypt rounds used to generate password hash.
  3973. # Larger numbers increase the work factor needed to generate the hash.
  3974. # The default number is 12 (which equates to 2^12 rounds).
  3975. # N.B. that increasing this will exponentially increase the time required
  3976. # to register or login - e.g. 24 =&gt; 2^24 rounds which will take &gt;20 mins.
  3977. #
  3978. #bcrypt_rounds: 12
  3979. # Allows users to register as guests without a password/email/etc, and
  3980. # participate in rooms hosted on this server which have been made
  3981. # accessible to anonymous users.
  3982. #
  3983. #allow_guest_access: false
  3984. # The identity server which we suggest that clients should use when users log
  3985. # in on this server.
  3986. #
  3987. # (By default, no suggestion is made, so it is left up to the client.
  3988. # This setting is ignored unless public_baseurl is also set.)
  3989. #
  3990. #default_identity_server: https://matrix.org
  3991. # Handle threepid (email/phone etc) registration and password resets through a set of
  3992. # *trusted* identity servers. Note that this allows the configured identity server to
  3993. # reset passwords for accounts!
  3994. #
  3995. # Be aware that if `email` is not set, and SMTP options have not been
  3996. # configured in the email config block, registration and user password resets via
  3997. # email will be globally disabled.
  3998. #
  3999. # Additionally, if `msisdn` is not set, registration and password resets via msisdn
  4000. # will be disabled regardless, and users will not be able to associate an msisdn
  4001. # identifier to their account. This is due to Synapse currently not supporting
  4002. # any method of sending SMS messages on its own.
  4003. #
  4004. # To enable using an identity server for operations regarding a particular third-party
  4005. # identifier type, set the value to the URL of that identity server as shown in the
  4006. # examples below.
  4007. #
  4008. # Servers handling the these requests must answer the `/requestToken` endpoints defined
  4009. # by the Matrix Identity Service API specification:
  4010. # https://matrix.org/docs/spec/identity_service/latest
  4011. #
  4012. # If a delegate is specified, the config option public_baseurl must also be filled out.
  4013. #
  4014. account_threepid_delegates:
  4015. #email: https://example.com # Delegate email sending to example.com
  4016. #msisdn: http://localhost:8090 # Delegate SMS sending to this local process
  4017. # Whether users are allowed to change their displayname after it has
  4018. # been initially set. Useful when provisioning users based on the
  4019. # contents of a third-party directory.
  4020. #
  4021. # Does not apply to server administrators. Defaults to 'true'
  4022. #
  4023. #enable_set_displayname: false
  4024. # Whether users are allowed to change their avatar after it has been
  4025. # initially set. Useful when provisioning users based on the contents
  4026. # of a third-party directory.
  4027. #
  4028. # Does not apply to server administrators. Defaults to 'true'
  4029. #
  4030. #enable_set_avatar_url: false
  4031. # Whether users can change the 3PIDs associated with their accounts
  4032. # (email address and msisdn).
  4033. #
  4034. # Defaults to 'true'
  4035. #
  4036. #enable_3pid_changes: false
  4037. # Users who register on this homeserver will automatically be joined
  4038. # to these rooms.
  4039. #
  4040. # By default, any room aliases included in this list will be created
  4041. # as a publicly joinable room when the first user registers for the
  4042. # homeserver. This behaviour can be customised with the settings below.
  4043. # If the room already exists, make certain it is a publicly joinable
  4044. # room. The join rule of the room must be set to 'public'.
  4045. #
  4046. #auto_join_rooms:
  4047. # - &quot;#example:example.com&quot;
  4048. # Where auto_join_rooms are specified, setting this flag ensures that the
  4049. # the rooms exist by creating them when the first user on the
  4050. # homeserver registers.
  4051. #
  4052. # By default the auto-created rooms are publicly joinable from any federated
  4053. # server. Use the autocreate_auto_join_rooms_federated and
  4054. # autocreate_auto_join_room_preset settings below to customise this behaviour.
  4055. #
  4056. # Setting to false means that if the rooms are not manually created,
  4057. # users cannot be auto-joined since they do not exist.
  4058. #
  4059. # Defaults to true. Uncomment the following line to disable automatically
  4060. # creating auto-join rooms.
  4061. #
  4062. #autocreate_auto_join_rooms: false
  4063. # Whether the auto_join_rooms that are auto-created are available via
  4064. # federation. Only has an effect if autocreate_auto_join_rooms is true.
  4065. #
  4066. # Note that whether a room is federated cannot be modified after
  4067. # creation.
  4068. #
  4069. # Defaults to true: the room will be joinable from other servers.
  4070. # Uncomment the following to prevent users from other homeservers from
  4071. # joining these rooms.
  4072. #
  4073. #autocreate_auto_join_rooms_federated: false
  4074. # The room preset to use when auto-creating one of auto_join_rooms. Only has an
  4075. # effect if autocreate_auto_join_rooms is true.
  4076. #
  4077. # This can be one of &quot;public_chat&quot;, &quot;private_chat&quot;, or &quot;trusted_private_chat&quot;.
  4078. # If a value of &quot;private_chat&quot; or &quot;trusted_private_chat&quot; is used then
  4079. # auto_join_mxid_localpart must also be configured.
  4080. #
  4081. # Defaults to &quot;public_chat&quot;, meaning that the room is joinable by anyone, including
  4082. # federated servers if autocreate_auto_join_rooms_federated is true (the default).
  4083. # Uncomment the following to require an invitation to join these rooms.
  4084. #
  4085. #autocreate_auto_join_room_preset: private_chat
  4086. # The local part of the user id which is used to create auto_join_rooms if
  4087. # autocreate_auto_join_rooms is true. If this is not provided then the
  4088. # initial user account that registers will be used to create the rooms.
  4089. #
  4090. # The user id is also used to invite new users to any auto-join rooms which
  4091. # are set to invite-only.
  4092. #
  4093. # It *must* be configured if autocreate_auto_join_room_preset is set to
  4094. # &quot;private_chat&quot; or &quot;trusted_private_chat&quot;.
  4095. #
  4096. # Note that this must be specified in order for new users to be correctly
  4097. # invited to any auto-join rooms which have been set to invite-only (either
  4098. # at the time of creation or subsequently).
  4099. #
  4100. # Note that, if the room already exists, this user must be joined and
  4101. # have the appropriate permissions to invite new members.
  4102. #
  4103. #auto_join_mxid_localpart: system
  4104. # When auto_join_rooms is specified, setting this flag to false prevents
  4105. # guest accounts from being automatically joined to the rooms.
  4106. #
  4107. # Defaults to true.
  4108. #
  4109. #auto_join_rooms_for_guests: false
  4110. ## Metrics ###
  4111. # Enable collection and rendering of performance metrics
  4112. #
  4113. #enable_metrics: false
  4114. # Enable sentry integration
  4115. # NOTE: While attempts are made to ensure that the logs don't contain
  4116. # any sensitive information, this cannot be guaranteed. By enabling
  4117. # this option the sentry server may therefore receive sensitive
  4118. # information, and it in turn may then diseminate sensitive information
  4119. # through insecure notification channels if so configured.
  4120. #
  4121. #sentry:
  4122. # dsn: &quot;...&quot;
  4123. # Flags to enable Prometheus metrics which are not suitable to be
  4124. # enabled by default, either for performance reasons or limited use.
  4125. #
  4126. metrics_flags:
  4127. # Publish synapse_federation_known_servers, a gauge of the number of
  4128. # servers this homeserver knows about, including itself. May cause
  4129. # performance problems on large homeservers.
  4130. #
  4131. #known_servers: true
  4132. # Whether or not to report anonymized homeserver usage statistics.
  4133. #
  4134. #report_stats: true|false
  4135. # The endpoint to report the anonymized homeserver usage statistics to.
  4136. # Defaults to https://matrix.org/report-usage-stats/push
  4137. #
  4138. #report_stats_endpoint: https://example.com/report-usage-stats/push
  4139. ## API Configuration ##
  4140. # Controls for the state that is shared with users who receive an invite
  4141. # to a room
  4142. #
  4143. room_prejoin_state:
  4144. # By default, the following state event types are shared with users who
  4145. # receive invites to the room:
  4146. #
  4147. # - m.room.join_rules
  4148. # - m.room.canonical_alias
  4149. # - m.room.avatar
  4150. # - m.room.encryption
  4151. # - m.room.name
  4152. # - m.room.create
  4153. #
  4154. # Uncomment the following to disable these defaults (so that only the event
  4155. # types listed in 'additional_event_types' are shared). Defaults to 'false'.
  4156. #
  4157. #disable_default_event_types: true
  4158. # Additional state event types to share with users when they are invited
  4159. # to a room.
  4160. #
  4161. # By default, this list is empty (so only the default event types are shared).
  4162. #
  4163. #additional_event_types:
  4164. # - org.example.custom.event.type
  4165. # A list of application service config files to use
  4166. #
  4167. #app_service_config_files:
  4168. # - app_service_1.yaml
  4169. # - app_service_2.yaml
  4170. # Uncomment to enable tracking of application service IP addresses. Implicitly
  4171. # enables MAU tracking for application service users.
  4172. #
  4173. #track_appservice_user_ips: true
  4174. # a secret which is used to sign access tokens. If none is specified,
  4175. # the registration_shared_secret is used, if one is given; otherwise,
  4176. # a secret key is derived from the signing key.
  4177. #
  4178. #macaroon_secret_key: &lt;PRIVATE STRING&gt;
  4179. # a secret which is used to calculate HMACs for form values, to stop
  4180. # falsification of values. Must be specified for the User Consent
  4181. # forms to work.
  4182. #
  4183. #form_secret: &lt;PRIVATE STRING&gt;
  4184. ## Signing Keys ##
  4185. # Path to the signing key to sign messages with
  4186. #
  4187. signing_key_path: &quot;CONFDIR/SERVERNAME.signing.key&quot;
  4188. # The keys that the server used to sign messages with but won't use
  4189. # to sign new messages.
  4190. #
  4191. old_signing_keys:
  4192. # For each key, `key` should be the base64-encoded public key, and
  4193. # `expired_ts`should be the time (in milliseconds since the unix epoch) that
  4194. # it was last used.
  4195. #
  4196. # It is possible to build an entry from an old signing.key file using the
  4197. # `export_signing_key` script which is provided with synapse.
  4198. #
  4199. # For example:
  4200. #
  4201. #&quot;ed25519:id&quot;: { key: &quot;base64string&quot;, expired_ts: 123456789123 }
  4202. # How long key response published by this server is valid for.
  4203. # Used to set the valid_until_ts in /key/v2 APIs.
  4204. # Determines how quickly servers will query to check which keys
  4205. # are still valid.
  4206. #
  4207. #key_refresh_interval: 1d
  4208. # The trusted servers to download signing keys from.
  4209. #
  4210. # When we need to fetch a signing key, each server is tried in parallel.
  4211. #
  4212. # Normally, the connection to the key server is validated via TLS certificates.
  4213. # Additional security can be provided by configuring a `verify key`, which
  4214. # will make synapse check that the response is signed by that key.
  4215. #
  4216. # This setting supercedes an older setting named `perspectives`. The old format
  4217. # is still supported for backwards-compatibility, but it is deprecated.
  4218. #
  4219. # 'trusted_key_servers' defaults to matrix.org, but using it will generate a
  4220. # warning on start-up. To suppress this warning, set
  4221. # 'suppress_key_server_warning' to true.
  4222. #
  4223. # Options for each entry in the list include:
  4224. #
  4225. # server_name: the name of the server. required.
  4226. #
  4227. # verify_keys: an optional map from key id to base64-encoded public key.
  4228. # If specified, we will check that the response is signed by at least
  4229. # one of the given keys.
  4230. #
  4231. # accept_keys_insecurely: a boolean. Normally, if `verify_keys` is unset,
  4232. # and federation_verify_certificates is not `true`, synapse will refuse
  4233. # to start, because this would allow anyone who can spoof DNS responses
  4234. # to masquerade as the trusted key server. If you know what you are doing
  4235. # and are sure that your network environment provides a secure connection
  4236. # to the key server, you can set this to `true` to override this
  4237. # behaviour.
  4238. #
  4239. # An example configuration might look like:
  4240. #
  4241. #trusted_key_servers:
  4242. # - server_name: &quot;my_trusted_server.example.com&quot;
  4243. # verify_keys:
  4244. # &quot;ed25519:auto&quot;: &quot;abcdefghijklmnopqrstuvwxyzabcdefghijklmopqr&quot;
  4245. # - server_name: &quot;my_other_trusted_server.example.com&quot;
  4246. #
  4247. trusted_key_servers:
  4248. - server_name: &quot;matrix.org&quot;
  4249. # Uncomment the following to disable the warning that is emitted when the
  4250. # trusted_key_servers include 'matrix.org'. See above.
  4251. #
  4252. #suppress_key_server_warning: true
  4253. # The signing keys to use when acting as a trusted key server. If not specified
  4254. # defaults to the server signing key.
  4255. #
  4256. # Can contain multiple keys, one per line.
  4257. #
  4258. #key_server_signing_keys_path: &quot;key_server_signing_keys.key&quot;
  4259. ## Single sign-on integration ##
  4260. # The following settings can be used to make Synapse use a single sign-on
  4261. # provider for authentication, instead of its internal password database.
  4262. #
  4263. # You will probably also want to set the following options to `false` to
  4264. # disable the regular login/registration flows:
  4265. # * enable_registration
  4266. # * password_config.enabled
  4267. #
  4268. # You will also want to investigate the settings under the &quot;sso&quot; configuration
  4269. # section below.
  4270. # Enable SAML2 for registration and login. Uses pysaml2.
  4271. #
  4272. # At least one of `sp_config` or `config_path` must be set in this section to
  4273. # enable SAML login.
  4274. #
  4275. # Once SAML support is enabled, a metadata file will be exposed at
  4276. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/metadata.xml, which you may be able to
  4277. # use to configure your SAML IdP with. Alternatively, you can manually configure
  4278. # the IdP to use an ACS location of
  4279. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/authn_response.
  4280. #
  4281. saml2_config:
  4282. # `sp_config` is the configuration for the pysaml2 Service Provider.
  4283. # See pysaml2 docs for format of config.
  4284. #
  4285. # Default values will be used for the 'entityid' and 'service' settings,
  4286. # so it is not normally necessary to specify them unless you need to
  4287. # override them.
  4288. #
  4289. sp_config:
  4290. # Point this to the IdP's metadata. You must provide either a local
  4291. # file via the `local` attribute or (preferably) a URL via the
  4292. # `remote` attribute.
  4293. #
  4294. #metadata:
  4295. # local: [&quot;saml2/idp.xml&quot;]
  4296. # remote:
  4297. # - url: https://our_idp/metadata.xml
  4298. # Allowed clock difference in seconds between the homeserver and IdP.
  4299. #
  4300. # Uncomment the below to increase the accepted time difference from 0 to 3 seconds.
  4301. #
  4302. #accepted_time_diff: 3
  4303. # By default, the user has to go to our login page first. If you'd like
  4304. # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
  4305. # 'service.sp' section:
  4306. #
  4307. #service:
  4308. # sp:
  4309. # allow_unsolicited: true
  4310. # The examples below are just used to generate our metadata xml, and you
  4311. # may well not need them, depending on your setup. Alternatively you
  4312. # may need a whole lot more detail - see the pysaml2 docs!
  4313. #description: [&quot;My awesome SP&quot;, &quot;en&quot;]
  4314. #name: [&quot;Test SP&quot;, &quot;en&quot;]
  4315. #ui_info:
  4316. # display_name:
  4317. # - lang: en
  4318. # text: &quot;Display Name is the descriptive name of your service.&quot;
  4319. # description:
  4320. # - lang: en
  4321. # text: &quot;Description should be a short paragraph explaining the purpose of the service.&quot;
  4322. # information_url:
  4323. # - lang: en
  4324. # text: &quot;https://example.com/terms-of-service&quot;
  4325. # privacy_statement_url:
  4326. # - lang: en
  4327. # text: &quot;https://example.com/privacy-policy&quot;
  4328. # keywords:
  4329. # - lang: en
  4330. # text: [&quot;Matrix&quot;, &quot;Element&quot;]
  4331. # logo:
  4332. # - lang: en
  4333. # text: &quot;https://example.com/logo.svg&quot;
  4334. # width: &quot;200&quot;
  4335. # height: &quot;80&quot;
  4336. #organization:
  4337. # name: Example com
  4338. # display_name:
  4339. # - [&quot;Example co&quot;, &quot;en&quot;]
  4340. # url: &quot;http://example.com&quot;
  4341. #contact_person:
  4342. # - given_name: Bob
  4343. # sur_name: &quot;the Sysadmin&quot;
  4344. # email_address&quot;: [&quot;admin@example.com&quot;]
  4345. # contact_type&quot;: technical
  4346. # Instead of putting the config inline as above, you can specify a
  4347. # separate pysaml2 configuration file:
  4348. #
  4349. #config_path: &quot;CONFDIR/sp_conf.py&quot;
  4350. # The lifetime of a SAML session. This defines how long a user has to
  4351. # complete the authentication process, if allow_unsolicited is unset.
  4352. # The default is 15 minutes.
  4353. #
  4354. #saml_session_lifetime: 5m
  4355. # An external module can be provided here as a custom solution to
  4356. # mapping attributes returned from a saml provider onto a matrix user.
  4357. #
  4358. user_mapping_provider:
  4359. # The custom module's class. Uncomment to use a custom module.
  4360. #
  4361. #module: mapping_provider.SamlMappingProvider
  4362. # Custom configuration values for the module. Below options are
  4363. # intended for the built-in provider, they should be changed if
  4364. # using a custom module. This section will be passed as a Python
  4365. # dictionary to the module's `parse_config` method.
  4366. #
  4367. config:
  4368. # The SAML attribute (after mapping via the attribute maps) to use
  4369. # to derive the Matrix ID from. 'uid' by default.
  4370. #
  4371. # Note: This used to be configured by the
  4372. # saml2_config.mxid_source_attribute option. If that is still
  4373. # defined, its value will be used instead.
  4374. #
  4375. #mxid_source_attribute: displayName
  4376. # The mapping system to use for mapping the saml attribute onto a
  4377. # matrix ID.
  4378. #
  4379. # Options include:
  4380. # * 'hexencode' (which maps unpermitted characters to '=xx')
  4381. # * 'dotreplace' (which replaces unpermitted characters with
  4382. # '.').
  4383. # The default is 'hexencode'.
  4384. #
  4385. # Note: This used to be configured by the
  4386. # saml2_config.mxid_mapping option. If that is still defined, its
  4387. # value will be used instead.
  4388. #
  4389. #mxid_mapping: dotreplace
  4390. # In previous versions of synapse, the mapping from SAML attribute to
  4391. # MXID was always calculated dynamically rather than stored in a
  4392. # table. For backwards- compatibility, we will look for user_ids
  4393. # matching such a pattern before creating a new account.
  4394. #
  4395. # This setting controls the SAML attribute which will be used for this
  4396. # backwards-compatibility lookup. Typically it should be 'uid', but if
  4397. # the attribute maps are changed, it may be necessary to change it.
  4398. #
  4399. # The default is 'uid'.
  4400. #
  4401. #grandfathered_mxid_source_attribute: upn
  4402. # It is possible to configure Synapse to only allow logins if SAML attributes
  4403. # match particular values. The requirements can be listed under
  4404. # `attribute_requirements` as shown below. All of the listed attributes must
  4405. # match for the login to be permitted.
  4406. #
  4407. #attribute_requirements:
  4408. # - attribute: userGroup
  4409. # value: &quot;staff&quot;
  4410. # - attribute: department
  4411. # value: &quot;sales&quot;
  4412. # If the metadata XML contains multiple IdP entities then the `idp_entityid`
  4413. # option must be set to the entity to redirect users to.
  4414. #
  4415. # Most deployments only have a single IdP entity and so should omit this
  4416. # option.
  4417. #
  4418. #idp_entityid: 'https://our_idp/entityid'
  4419. # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration
  4420. # and login.
  4421. #
  4422. # Options for each entry include:
  4423. #
  4424. # idp_id: a unique identifier for this identity provider. Used internally
  4425. # by Synapse; should be a single word such as 'github'.
  4426. #
  4427. # Note that, if this is changed, users authenticating via that provider
  4428. # will no longer be recognised as the same user!
  4429. #
  4430. # (Use &quot;oidc&quot; here if you are migrating from an old &quot;oidc_config&quot;
  4431. # configuration.)
  4432. #
  4433. # idp_name: A user-facing name for this identity provider, which is used to
  4434. # offer the user a choice of login mechanisms.
  4435. #
  4436. # idp_icon: An optional icon for this identity provider, which is presented
  4437. # by clients and Synapse's own IdP picker page. If given, must be an
  4438. # MXC URI of the format mxc://&lt;server-name&gt;/&lt;media-id&gt;. (An easy way to
  4439. # obtain such an MXC URI is to upload an image to an (unencrypted) room
  4440. # and then copy the &quot;url&quot; from the source of the event.)
  4441. #
  4442. # idp_brand: An optional brand for this identity provider, allowing clients
  4443. # to style the login flow according to the identity provider in question.
  4444. # See the spec for possible options here.
  4445. #
  4446. # discover: set to 'false' to disable the use of the OIDC discovery mechanism
  4447. # to discover endpoints. Defaults to true.
  4448. #
  4449. # issuer: Required. The OIDC issuer. Used to validate tokens and (if discovery
  4450. # is enabled) to discover the provider's endpoints.
  4451. #
  4452. # client_id: Required. oauth2 client id to use.
  4453. #
  4454. # client_secret: oauth2 client secret to use. May be omitted if
  4455. # client_secret_jwt_key is given, or if client_auth_method is 'none'.
  4456. #
  4457. # client_secret_jwt_key: Alternative to client_secret: details of a key used
  4458. # to create a JSON Web Token to be used as an OAuth2 client secret. If
  4459. # given, must be a dictionary with the following properties:
  4460. #
  4461. # key: a pem-encoded signing key. Must be a suitable key for the
  4462. # algorithm specified. Required unless 'key_file' is given.
  4463. #
  4464. # key_file: the path to file containing a pem-encoded signing key file.
  4465. # Required unless 'key' is given.
  4466. #
  4467. # jwt_header: a dictionary giving properties to include in the JWT
  4468. # header. Must include the key 'alg', giving the algorithm used to
  4469. # sign the JWT, such as &quot;ES256&quot;, using the JWA identifiers in
  4470. # RFC7518.
  4471. #
  4472. # jwt_payload: an optional dictionary giving properties to include in
  4473. # the JWT payload. Normally this should include an 'iss' key.
  4474. #
  4475. # client_auth_method: auth method to use when exchanging the token. Valid
  4476. # values are 'client_secret_basic' (default), 'client_secret_post' and
  4477. # 'none'.
  4478. #
  4479. # scopes: list of scopes to request. This should normally include the &quot;openid&quot;
  4480. # scope. Defaults to [&quot;openid&quot;].
  4481. #
  4482. # authorization_endpoint: the oauth2 authorization endpoint. Required if
  4483. # provider discovery is disabled.
  4484. #
  4485. # token_endpoint: the oauth2 token endpoint. Required if provider discovery is
  4486. # disabled.
  4487. #
  4488. # userinfo_endpoint: the OIDC userinfo endpoint. Required if discovery is
  4489. # disabled and the 'openid' scope is not requested.
  4490. #
  4491. # jwks_uri: URI where to fetch the JWKS. Required if discovery is disabled and
  4492. # the 'openid' scope is used.
  4493. #
  4494. # skip_verification: set to 'true' to skip metadata verification. Use this if
  4495. # you are connecting to a provider that is not OpenID Connect compliant.
  4496. # Defaults to false. Avoid this in production.
  4497. #
  4498. # user_profile_method: Whether to fetch the user profile from the userinfo
  4499. # endpoint. Valid values are: 'auto' or 'userinfo_endpoint'.
  4500. #
  4501. # Defaults to 'auto', which fetches the userinfo endpoint if 'openid' is
  4502. # included in 'scopes'. Set to 'userinfo_endpoint' to always fetch the
  4503. # userinfo endpoint.
  4504. #
  4505. # allow_existing_users: set to 'true' to allow a user logging in via OIDC to
  4506. # match a pre-existing account instead of failing. This could be used if
  4507. # switching from password logins to OIDC. Defaults to false.
  4508. #
  4509. # user_mapping_provider: Configuration for how attributes returned from a OIDC
  4510. # provider are mapped onto a matrix user. This setting has the following
  4511. # sub-properties:
  4512. #
  4513. # module: The class name of a custom mapping module. Default is
  4514. # 'synapse.handlers.oidc.JinjaOidcMappingProvider'.
  4515. # See https://matrix-org.github.io/synapse/latest/sso_mapping_providers.html#openid-mapping-providers
  4516. # for information on implementing a custom mapping provider.
  4517. #
  4518. # config: Configuration for the mapping provider module. This section will
  4519. # be passed as a Python dictionary to the user mapping provider
  4520. # module's `parse_config` method.
  4521. #
  4522. # For the default provider, the following settings are available:
  4523. #
  4524. # subject_claim: name of the claim containing a unique identifier
  4525. # for the user. Defaults to 'sub', which OpenID Connect
  4526. # compliant providers should provide.
  4527. #
  4528. # localpart_template: Jinja2 template for the localpart of the MXID.
  4529. # If this is not set, the user will be prompted to choose their
  4530. # own username (see 'sso_auth_account_details.html' in the 'sso'
  4531. # section of this file).
  4532. #
  4533. # display_name_template: Jinja2 template for the display name to set
  4534. # on first login. If unset, no displayname will be set.
  4535. #
  4536. # email_template: Jinja2 template for the email address of the user.
  4537. # If unset, no email address will be added to the account.
  4538. #
  4539. # extra_attributes: a map of Jinja2 templates for extra attributes
  4540. # to send back to the client during login.
  4541. # Note that these are non-standard and clients will ignore them
  4542. # without modifications.
  4543. #
  4544. # When rendering, the Jinja2 templates are given a 'user' variable,
  4545. # which is set to the claims returned by the UserInfo Endpoint and/or
  4546. # in the ID Token.
  4547. #
  4548. # It is possible to configure Synapse to only allow logins if certain attributes
  4549. # match particular values in the OIDC userinfo. The requirements can be listed under
  4550. # `attribute_requirements` as shown below. All of the listed attributes must
  4551. # match for the login to be permitted. Additional attributes can be added to
  4552. # userinfo by expanding the `scopes` section of the OIDC config to retrieve
  4553. # additional information from the OIDC provider.
  4554. #
  4555. # If the OIDC claim is a list, then the attribute must match any value in the list.
  4556. # Otherwise, it must exactly match the value of the claim. Using the example
  4557. # below, the `family_name` claim MUST be &quot;Stephensson&quot;, but the `groups`
  4558. # claim MUST contain &quot;admin&quot;.
  4559. #
  4560. # attribute_requirements:
  4561. # - attribute: family_name
  4562. # value: &quot;Stephensson&quot;
  4563. # - attribute: groups
  4564. # value: &quot;admin&quot;
  4565. #
  4566. # See https://matrix-org.github.io/synapse/latest/openid.html
  4567. # for information on how to configure these options.
  4568. #
  4569. # For backwards compatibility, it is also possible to configure a single OIDC
  4570. # provider via an 'oidc_config' setting. This is now deprecated and admins are
  4571. # advised to migrate to the 'oidc_providers' format. (When doing that migration,
  4572. # use 'oidc' for the idp_id to ensure that existing users continue to be
  4573. # recognised.)
  4574. #
  4575. oidc_providers:
  4576. # Generic example
  4577. #
  4578. #- idp_id: my_idp
  4579. # idp_name: &quot;My OpenID provider&quot;
  4580. # idp_icon: &quot;mxc://example.com/mediaid&quot;
  4581. # discover: false
  4582. # issuer: &quot;https://accounts.example.com/&quot;
  4583. # client_id: &quot;provided-by-your-issuer&quot;
  4584. # client_secret: &quot;provided-by-your-issuer&quot;
  4585. # client_auth_method: client_secret_post
  4586. # scopes: [&quot;openid&quot;, &quot;profile&quot;]
  4587. # authorization_endpoint: &quot;https://accounts.example.com/oauth2/auth&quot;
  4588. # token_endpoint: &quot;https://accounts.example.com/oauth2/token&quot;
  4589. # userinfo_endpoint: &quot;https://accounts.example.com/userinfo&quot;
  4590. # jwks_uri: &quot;https://accounts.example.com/.well-known/jwks.json&quot;
  4591. # skip_verification: true
  4592. # user_mapping_provider:
  4593. # config:
  4594. # subject_claim: &quot;id&quot;
  4595. # localpart_template: &quot;{{ user.login }}&quot;
  4596. # display_name_template: &quot;{{ user.name }}&quot;
  4597. # email_template: &quot;{{ user.email }}&quot;
  4598. # attribute_requirements:
  4599. # - attribute: userGroup
  4600. # value: &quot;synapseUsers&quot;
  4601. # Enable Central Authentication Service (CAS) for registration and login.
  4602. #
  4603. cas_config:
  4604. # Uncomment the following to enable authorization against a CAS server.
  4605. # Defaults to false.
  4606. #
  4607. #enabled: true
  4608. # The URL of the CAS authorization endpoint.
  4609. #
  4610. #server_url: &quot;https://cas-server.com&quot;
  4611. # The attribute of the CAS response to use as the display name.
  4612. #
  4613. # If unset, no displayname will be set.
  4614. #
  4615. #displayname_attribute: name
  4616. # It is possible to configure Synapse to only allow logins if CAS attributes
  4617. # match particular values. All of the keys in the mapping below must exist
  4618. # and the values must match the given value. Alternately if the given value
  4619. # is None then any value is allowed (the attribute just must exist).
  4620. # All of the listed attributes must match for the login to be permitted.
  4621. #
  4622. #required_attributes:
  4623. # userGroup: &quot;staff&quot;
  4624. # department: None
  4625. # Additional settings to use with single-sign on systems such as OpenID Connect,
  4626. # SAML2 and CAS.
  4627. #
  4628. # Server admins can configure custom templates for pages related to SSO. See
  4629. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4630. #
  4631. sso:
  4632. # A list of client URLs which are whitelisted so that the user does not
  4633. # have to confirm giving access to their account to the URL. Any client
  4634. # whose URL starts with an entry in the following list will not be subject
  4635. # to an additional confirmation step after the SSO login is completed.
  4636. #
  4637. # WARNING: An entry such as &quot;https://my.client&quot; is insecure, because it
  4638. # will also match &quot;https://my.client.evil.site&quot;, exposing your users to
  4639. # phishing attacks from evil.site. To avoid this, include a slash after the
  4640. # hostname: &quot;https://my.client/&quot;.
  4641. #
  4642. # If public_baseurl is set, then the login fallback page (used by clients
  4643. # that don't natively support the required login flows) is whitelisted in
  4644. # addition to any URLs in this list.
  4645. #
  4646. # By default, this list is empty.
  4647. #
  4648. #client_whitelist:
  4649. # - https://riot.im/develop
  4650. # - https://my.custom.client/
  4651. # Uncomment to keep a user's profile fields in sync with information from
  4652. # the identity provider. Currently only syncing the displayname is
  4653. # supported. Fields are checked on every SSO login, and are updated
  4654. # if necessary.
  4655. #
  4656. # Note that enabling this option will override user profile information,
  4657. # regardless of whether users have opted-out of syncing that
  4658. # information when first signing in. Defaults to false.
  4659. #
  4660. #update_profile_information: true
  4661. # JSON web token integration. The following settings can be used to make
  4662. # Synapse JSON web tokens for authentication, instead of its internal
  4663. # password database.
  4664. #
  4665. # Each JSON Web Token needs to contain a &quot;sub&quot; (subject) claim, which is
  4666. # used as the localpart of the mxid.
  4667. #
  4668. # Additionally, the expiration time (&quot;exp&quot;), not before time (&quot;nbf&quot;),
  4669. # and issued at (&quot;iat&quot;) claims are validated if present.
  4670. #
  4671. # Note that this is a non-standard login type and client support is
  4672. # expected to be non-existent.
  4673. #
  4674. # See https://matrix-org.github.io/synapse/latest/jwt.html.
  4675. #
  4676. #jwt_config:
  4677. # Uncomment the following to enable authorization using JSON web
  4678. # tokens. Defaults to false.
  4679. #
  4680. #enabled: true
  4681. # This is either the private shared secret or the public key used to
  4682. # decode the contents of the JSON web token.
  4683. #
  4684. # Required if 'enabled' is true.
  4685. #
  4686. #secret: &quot;provided-by-your-issuer&quot;
  4687. # The algorithm used to sign the JSON web token.
  4688. #
  4689. # Supported algorithms are listed at
  4690. # https://pyjwt.readthedocs.io/en/latest/algorithms.html
  4691. #
  4692. # Required if 'enabled' is true.
  4693. #
  4694. #algorithm: &quot;provided-by-your-issuer&quot;
  4695. # The issuer to validate the &quot;iss&quot; claim against.
  4696. #
  4697. # Optional, if provided the &quot;iss&quot; claim will be required and
  4698. # validated for all JSON web tokens.
  4699. #
  4700. #issuer: &quot;provided-by-your-issuer&quot;
  4701. # A list of audiences to validate the &quot;aud&quot; claim against.
  4702. #
  4703. # Optional, if provided the &quot;aud&quot; claim will be required and
  4704. # validated for all JSON web tokens.
  4705. #
  4706. # Note that if the &quot;aud&quot; claim is included in a JSON web token then
  4707. # validation will fail without configuring audiences.
  4708. #
  4709. #audiences:
  4710. # - &quot;provided-by-your-issuer&quot;
  4711. password_config:
  4712. # Uncomment to disable password login
  4713. #
  4714. #enabled: false
  4715. # Uncomment to disable authentication against the local password
  4716. # database. This is ignored if `enabled` is false, and is only useful
  4717. # if you have other password_providers.
  4718. #
  4719. #localdb_enabled: false
  4720. # Uncomment and change to a secret random string for extra security.
  4721. # DO NOT CHANGE THIS AFTER INITIAL SETUP!
  4722. #
  4723. #pepper: &quot;EVEN_MORE_SECRET&quot;
  4724. # Define and enforce a password policy. Each parameter is optional.
  4725. # This is an implementation of MSC2000.
  4726. #
  4727. policy:
  4728. # Whether to enforce the password policy.
  4729. # Defaults to 'false'.
  4730. #
  4731. #enabled: true
  4732. # Minimum accepted length for a password.
  4733. # Defaults to 0.
  4734. #
  4735. #minimum_length: 15
  4736. # Whether a password must contain at least one digit.
  4737. # Defaults to 'false'.
  4738. #
  4739. #require_digit: true
  4740. # Whether a password must contain at least one symbol.
  4741. # A symbol is any character that's not a number or a letter.
  4742. # Defaults to 'false'.
  4743. #
  4744. #require_symbol: true
  4745. # Whether a password must contain at least one lowercase letter.
  4746. # Defaults to 'false'.
  4747. #
  4748. #require_lowercase: true
  4749. # Whether a password must contain at least one uppercase letter.
  4750. # Defaults to 'false'.
  4751. #
  4752. #require_uppercase: true
  4753. ui_auth:
  4754. # The amount of time to allow a user-interactive authentication session
  4755. # to be active.
  4756. #
  4757. # This defaults to 0, meaning the user is queried for their credentials
  4758. # before every action, but this can be overridden to allow a single
  4759. # validation to be re-used. This weakens the protections afforded by
  4760. # the user-interactive authentication process, by allowing for multiple
  4761. # (and potentially different) operations to use the same validation session.
  4762. #
  4763. # This is ignored for potentially &quot;dangerous&quot; operations (including
  4764. # deactivating an account, modifying an account password, and
  4765. # adding a 3PID).
  4766. #
  4767. # Uncomment below to allow for credential validation to last for 15
  4768. # seconds.
  4769. #
  4770. #session_timeout: &quot;15s&quot;
  4771. # Configuration for sending emails from Synapse.
  4772. #
  4773. # Server admins can configure custom templates for email content. See
  4774. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4775. #
  4776. email:
  4777. # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'.
  4778. #
  4779. #smtp_host: mail.server
  4780. # The port on the mail server for outgoing SMTP. Defaults to 25.
  4781. #
  4782. #smtp_port: 587
  4783. # Username/password for authentication to the SMTP server. By default, no
  4784. # authentication is attempted.
  4785. #
  4786. #smtp_user: &quot;exampleusername&quot;
  4787. #smtp_pass: &quot;examplepassword&quot;
  4788. # Uncomment the following to require TLS transport security for SMTP.
  4789. # By default, Synapse will connect over plain text, and will then switch to
  4790. # TLS via STARTTLS *if the SMTP server supports it*. If this option is set,
  4791. # Synapse will refuse to connect unless the server supports STARTTLS.
  4792. #
  4793. #require_transport_security: true
  4794. # Uncomment the following to disable TLS for SMTP.
  4795. #
  4796. # By default, if the server supports TLS, it will be used, and the server
  4797. # must present a certificate that is valid for 'smtp_host'. If this option
  4798. # is set to false, TLS will not be used.
  4799. #
  4800. #enable_tls: false
  4801. # notif_from defines the &quot;From&quot; address to use when sending emails.
  4802. # It must be set if email sending is enabled.
  4803. #
  4804. # The placeholder '%(app)s' will be replaced by the application name,
  4805. # which is normally 'app_name' (below), but may be overridden by the
  4806. # Matrix client application.
  4807. #
  4808. # Note that the placeholder must be written '%(app)s', including the
  4809. # trailing 's'.
  4810. #
  4811. #notif_from: &quot;Your Friendly %(app)s homeserver &lt;noreply@example.com&gt;&quot;
  4812. # app_name defines the default value for '%(app)s' in notif_from and email
  4813. # subjects. It defaults to 'Matrix'.
  4814. #
  4815. #app_name: my_branded_matrix_server
  4816. # Uncomment the following to enable sending emails for messages that the user
  4817. # has missed. Disabled by default.
  4818. #
  4819. #enable_notifs: true
  4820. # Uncomment the following to disable automatic subscription to email
  4821. # notifications for new users. Enabled by default.
  4822. #
  4823. #notif_for_new_users: false
  4824. # Custom URL for client links within the email notifications. By default
  4825. # links will be based on &quot;https://matrix.to&quot;.
  4826. #
  4827. # (This setting used to be called riot_base_url; the old name is still
  4828. # supported for backwards-compatibility but is now deprecated.)
  4829. #
  4830. #client_base_url: &quot;http://localhost/riot&quot;
  4831. # Configure the time that a validation email will expire after sending.
  4832. # Defaults to 1h.
  4833. #
  4834. #validation_token_lifetime: 15m
  4835. # The web client location to direct users to during an invite. This is passed
  4836. # to the identity server as the org.matrix.web_client_location key. Defaults
  4837. # to unset, giving no guidance to the identity server.
  4838. #
  4839. #invite_client_location: https://app.element.io
  4840. # Subjects to use when sending emails from Synapse.
  4841. #
  4842. # The placeholder '%(app)s' will be replaced with the value of the 'app_name'
  4843. # setting above, or by a value dictated by the Matrix client application.
  4844. #
  4845. # If a subject isn't overridden in this configuration file, the value used as
  4846. # its example will be used.
  4847. #
  4848. #subjects:
  4849. # Subjects for notification emails.
  4850. #
  4851. # On top of the '%(app)s' placeholder, these can use the following
  4852. # placeholders:
  4853. #
  4854. # * '%(person)s', which will be replaced by the display name of the user(s)
  4855. # that sent the message(s), e.g. &quot;Alice and Bob&quot;.
  4856. # * '%(room)s', which will be replaced by the name of the room the
  4857. # message(s) have been sent to, e.g. &quot;My super room&quot;.
  4858. #
  4859. # See the example provided for each setting to see which placeholder can be
  4860. # used and how to use them.
  4861. #
  4862. # Subject to use to notify about one message from one or more user(s) in a
  4863. # room which has a name.
  4864. #message_from_person_in_room: &quot;[%(app)s] You have a message on %(app)s from %(person)s in the %(room)s room...&quot;
  4865. #
  4866. # Subject to use to notify about one message from one or more user(s) in a
  4867. # room which doesn't have a name.
  4868. #message_from_person: &quot;[%(app)s] You have a message on %(app)s from %(person)s...&quot;
  4869. #
  4870. # Subject to use to notify about multiple messages from one or more users in
  4871. # a room which doesn't have a name.
  4872. #messages_from_person: &quot;[%(app)s] You have messages on %(app)s from %(person)s...&quot;
  4873. #
  4874. # Subject to use to notify about multiple messages in a room which has a
  4875. # name.
  4876. #messages_in_room: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room...&quot;
  4877. #
  4878. # Subject to use to notify about multiple messages in multiple rooms.
  4879. #messages_in_room_and_others: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room and others...&quot;
  4880. #
  4881. # Subject to use to notify about multiple messages from multiple persons in
  4882. # multiple rooms. This is similar to the setting above except it's used when
  4883. # the room in which the notification was triggered has no name.
  4884. #messages_from_person_and_others: &quot;[%(app)s] You have messages on %(app)s from %(person)s and others...&quot;
  4885. #
  4886. # Subject to use to notify about an invite to a room which has a name.
  4887. #invite_from_person_to_room: &quot;[%(app)s] %(person)s has invited you to join the %(room)s room on %(app)s...&quot;
  4888. #
  4889. # Subject to use to notify about an invite to a room which doesn't have a
  4890. # name.
  4891. #invite_from_person: &quot;[%(app)s] %(person)s has invited you to chat on %(app)s...&quot;
  4892. # Subject for emails related to account administration.
  4893. #
  4894. # On top of the '%(app)s' placeholder, these one can use the
  4895. # '%(server_name)s' placeholder, which will be replaced by the value of the
  4896. # 'server_name' setting in your Synapse configuration.
  4897. #
  4898. # Subject to use when sending a password reset email.
  4899. #password_reset: &quot;[%(server_name)s] Password reset&quot;
  4900. #
  4901. # Subject to use when sending a verification email to assert an address's
  4902. # ownership.
  4903. #email_validation: &quot;[%(server_name)s] Validate your email&quot;
  4904. # Password providers allow homeserver administrators to integrate
  4905. # their Synapse installation with existing authentication methods
  4906. # ex. LDAP, external tokens, etc.
  4907. #
  4908. # For more information and known implementations, please see
  4909. # https://matrix-org.github.io/synapse/latest/password_auth_providers.html
  4910. #
  4911. # Note: instances wishing to use SAML or CAS authentication should
  4912. # instead use the `saml2_config` or `cas_config` options,
  4913. # respectively.
  4914. #
  4915. password_providers:
  4916. # # Example config for an LDAP auth provider
  4917. # - module: &quot;ldap_auth_provider.LdapAuthProvider&quot;
  4918. # config:
  4919. # enabled: true
  4920. # uri: &quot;ldap://ldap.example.com:389&quot;
  4921. # start_tls: true
  4922. # base: &quot;ou=users,dc=example,dc=com&quot;
  4923. # attributes:
  4924. # uid: &quot;cn&quot;
  4925. # mail: &quot;email&quot;
  4926. # name: &quot;givenName&quot;
  4927. # #bind_dn:
  4928. # #bind_password:
  4929. # #filter: &quot;(objectClass=posixAccount)&quot;
  4930. ## Push ##
  4931. push:
  4932. # Clients requesting push notifications can either have the body of
  4933. # the message sent in the notification poke along with other details
  4934. # like the sender, or just the event ID and room ID (`event_id_only`).
  4935. # If clients choose the former, this option controls whether the
  4936. # notification request includes the content of the event (other details
  4937. # like the sender are still included). For `event_id_only` push, it
  4938. # has no effect.
  4939. #
  4940. # For modern android devices the notification content will still appear
  4941. # because it is loaded by the app. iPhone, however will send a
  4942. # notification saying only that a message arrived and who it came from.
  4943. #
  4944. # The default value is &quot;true&quot; to include message details. Uncomment to only
  4945. # include the event ID and room ID in push notification payloads.
  4946. #
  4947. #include_content: false
  4948. # When a push notification is received, an unread count is also sent.
  4949. # This number can either be calculated as the number of unread messages
  4950. # for the user, or the number of *rooms* the user has unread messages in.
  4951. #
  4952. # The default value is &quot;true&quot;, meaning push clients will see the number of
  4953. # rooms with unread messages in them. Uncomment to instead send the number
  4954. # of unread messages.
  4955. #
  4956. #group_unread_count_by_room: false
  4957. ## Rooms ##
  4958. # Controls whether locally-created rooms should be end-to-end encrypted by
  4959. # default.
  4960. #
  4961. # Possible options are &quot;all&quot;, &quot;invite&quot;, and &quot;off&quot;. They are defined as:
  4962. #
  4963. # * &quot;all&quot;: any locally-created room
  4964. # * &quot;invite&quot;: any room created with the &quot;private_chat&quot; or &quot;trusted_private_chat&quot;
  4965. # room creation presets
  4966. # * &quot;off&quot;: this option will take no effect
  4967. #
  4968. # The default value is &quot;off&quot;.
  4969. #
  4970. # Note that this option will only affect rooms created after it is set. It
  4971. # will also not affect rooms created by other servers.
  4972. #
  4973. #encryption_enabled_by_default_for_room_type: invite
  4974. # Uncomment to allow non-server-admin users to create groups on this server
  4975. #
  4976. #enable_group_creation: true
  4977. # If enabled, non server admins can only create groups with local parts
  4978. # starting with this prefix
  4979. #
  4980. #group_creation_prefix: &quot;unofficial_&quot;
  4981. # User Directory configuration
  4982. #
  4983. user_directory:
  4984. # Defines whether users can search the user directory. If false then
  4985. # empty responses are returned to all queries. Defaults to true.
  4986. #
  4987. # Uncomment to disable the user directory.
  4988. #
  4989. #enabled: false
  4990. # Defines whether to search all users visible to your HS when searching
  4991. # the user directory. If false, search results will only contain users
  4992. # visible in public rooms and users sharing a room with the requester.
  4993. # Defaults to false.
  4994. #
  4995. # NB. If you set this to true, and the last time the user_directory search
  4996. # indexes were (re)built was before Synapse 1.44, you'll have to
  4997. # rebuild the indexes in order to search through all known users.
  4998. # These indexes are built the first time Synapse starts; admins can
  4999. # manually trigger a rebuild following the instructions at
  5000. # https://matrix-org.github.io/synapse/latest/user_directory.html
  5001. #
  5002. # Uncomment to return search results containing all known users, even if that
  5003. # user does not share a room with the requester.
  5004. #
  5005. #search_all_users: true
  5006. # Defines whether to prefer local users in search query results.
  5007. # If True, local users are more likely to appear above remote users
  5008. # when searching the user directory. Defaults to false.
  5009. #
  5010. # Uncomment to prefer local over remote users in user directory search
  5011. # results.
  5012. #
  5013. #prefer_local_users: true
  5014. # User Consent configuration
  5015. #
  5016. # for detailed instructions, see
  5017. # https://matrix-org.github.io/synapse/latest/consent_tracking.html
  5018. #
  5019. # Parts of this section are required if enabling the 'consent' resource under
  5020. # 'listeners', in particular 'template_dir' and 'version'.
  5021. #
  5022. # 'template_dir' gives the location of the templates for the HTML forms.
  5023. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  5024. # and each language directory should contain the policy document (named as
  5025. # '&lt;version&gt;.html') and a success page (success.html).
  5026. #
  5027. # 'version' specifies the 'current' version of the policy document. It defines
  5028. # the version to be served by the consent resource if there is no 'v'
  5029. # parameter.
  5030. #
  5031. # 'server_notice_content', if enabled, will send a user a &quot;Server Notice&quot;
  5032. # asking them to consent to the privacy policy. The 'server_notices' section
  5033. # must also be configured for this to work. Notices will *not* be sent to
  5034. # guest users unless 'send_server_notice_to_guests' is set to true.
  5035. #
  5036. # 'block_events_error', if set, will block any attempts to send events
  5037. # until the user consents to the privacy policy. The value of the setting is
  5038. # used as the text of the error.
  5039. #
  5040. # 'require_at_registration', if enabled, will add a step to the registration
  5041. # process, similar to how captcha works. Users will be required to accept the
  5042. # policy before their account is created.
  5043. #
  5044. # 'policy_name' is the display name of the policy users will see when registering
  5045. # for an account. Has no effect unless `require_at_registration` is enabled.
  5046. # Defaults to &quot;Privacy Policy&quot;.
  5047. #
  5048. #user_consent:
  5049. # template_dir: res/templates/privacy
  5050. # version: 1.0
  5051. # server_notice_content:
  5052. # msgtype: m.text
  5053. # body: &gt;-
  5054. # To continue using this homeserver you must review and agree to the
  5055. # terms and conditions at %(consent_uri)s
  5056. # send_server_notice_to_guests: true
  5057. # block_events_error: &gt;-
  5058. # To continue using this homeserver you must review and agree to the
  5059. # terms and conditions at %(consent_uri)s
  5060. # require_at_registration: false
  5061. # policy_name: Privacy Policy
  5062. #
  5063. # Settings for local room and user statistics collection. See
  5064. # https://matrix-org.github.io/synapse/latest/room_and_user_statistics.html.
  5065. #
  5066. stats:
  5067. # Uncomment the following to disable room and user statistics. Note that doing
  5068. # so may cause certain features (such as the room directory) not to work
  5069. # correctly.
  5070. #
  5071. #enabled: false
  5072. # Server Notices room configuration
  5073. #
  5074. # Uncomment this section to enable a room which can be used to send notices
  5075. # from the server to users. It is a special room which cannot be left; notices
  5076. # come from a special &quot;notices&quot; user id.
  5077. #
  5078. # If you uncomment this section, you *must* define the system_mxid_localpart
  5079. # setting, which defines the id of the user which will be used to send the
  5080. # notices.
  5081. #
  5082. # It's also possible to override the room name, the display name of the
  5083. # &quot;notices&quot; user, and the avatar for the user.
  5084. #
  5085. #server_notices:
  5086. # system_mxid_localpart: notices
  5087. # system_mxid_display_name: &quot;Server Notices&quot;
  5088. # system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  5089. # room_name: &quot;Server Notices&quot;
  5090. # Uncomment to disable searching the public room list. When disabled
  5091. # blocks searching local and remote room lists for local and remote
  5092. # users by always returning an empty list for all queries.
  5093. #
  5094. #enable_room_list_search: false
  5095. # The `alias_creation` option controls who's allowed to create aliases
  5096. # on this server.
  5097. #
  5098. # The format of this option is a list of rules that contain globs that
  5099. # match against user_id, room_id and the new alias (fully qualified with
  5100. # server name). The action in the first rule that matches is taken,
  5101. # which can currently either be &quot;allow&quot; or &quot;deny&quot;.
  5102. #
  5103. # Missing user_id/room_id/alias fields default to &quot;*&quot;.
  5104. #
  5105. # If no rules match the request is denied. An empty list means no one
  5106. # can create aliases.
  5107. #
  5108. # Options for the rules include:
  5109. #
  5110. # user_id: Matches against the creator of the alias
  5111. # alias: Matches against the alias being created
  5112. # room_id: Matches against the room ID the alias is being pointed at
  5113. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5114. #
  5115. # The default is:
  5116. #
  5117. #alias_creation_rules:
  5118. # - user_id: &quot;*&quot;
  5119. # alias: &quot;*&quot;
  5120. # room_id: &quot;*&quot;
  5121. # action: allow
  5122. # The `room_list_publication_rules` option controls who can publish and
  5123. # which rooms can be published in the public room list.
  5124. #
  5125. # The format of this option is the same as that for
  5126. # `alias_creation_rules`.
  5127. #
  5128. # If the room has one or more aliases associated with it, only one of
  5129. # the aliases needs to match the alias rule. If there are no aliases
  5130. # then only rules with `alias: *` match.
  5131. #
  5132. # If no rules match the request is denied. An empty list means no one
  5133. # can publish rooms.
  5134. #
  5135. # Options for the rules include:
  5136. #
  5137. # user_id: Matches against the creator of the alias
  5138. # room_id: Matches against the room ID being published
  5139. # alias: Matches against any current local or canonical aliases
  5140. # associated with the room
  5141. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5142. #
  5143. # The default is:
  5144. #
  5145. #room_list_publication_rules:
  5146. # - user_id: &quot;*&quot;
  5147. # alias: &quot;*&quot;
  5148. # room_id: &quot;*&quot;
  5149. # action: allow
  5150. ## Opentracing ##
  5151. # These settings enable opentracing, which implements distributed tracing.
  5152. # This allows you to observe the causal chains of events across servers
  5153. # including requests, key lookups etc., across any server running
  5154. # synapse or any other other services which supports opentracing
  5155. # (specifically those implemented with Jaeger).
  5156. #
  5157. opentracing:
  5158. # tracing is disabled by default. Uncomment the following line to enable it.
  5159. #
  5160. #enabled: true
  5161. # The list of homeservers we wish to send and receive span contexts and span baggage.
  5162. # See https://matrix-org.github.io/synapse/latest/opentracing.html.
  5163. #
  5164. # This is a list of regexes which are matched against the server_name of the
  5165. # homeserver.
  5166. #
  5167. # By default, it is empty, so no servers are matched.
  5168. #
  5169. #homeserver_whitelist:
  5170. # - &quot;.*&quot;
  5171. # A list of the matrix IDs of users whose requests will always be traced,
  5172. # even if the tracing system would otherwise drop the traces due to
  5173. # probabilistic sampling.
  5174. #
  5175. # By default, the list is empty.
  5176. #
  5177. #force_tracing_for_users:
  5178. # - &quot;@user1:server_name&quot;
  5179. # - &quot;@user2:server_name&quot;
  5180. # Jaeger can be configured to sample traces at different rates.
  5181. # All configuration options provided by Jaeger can be set here.
  5182. # Jaeger's configuration is mostly related to trace sampling which
  5183. # is documented here:
  5184. # https://www.jaegertracing.io/docs/latest/sampling/.
  5185. #
  5186. #jaeger_config:
  5187. # sampler:
  5188. # type: const
  5189. # param: 1
  5190. # logging:
  5191. # false
  5192. ## Workers ##
  5193. # Disables sending of outbound federation transactions on the main process.
  5194. # Uncomment if using a federation sender worker.
  5195. #
  5196. #send_federation: false
  5197. # It is possible to run multiple federation sender workers, in which case the
  5198. # work is balanced across them.
  5199. #
  5200. # This configuration must be shared between all federation sender workers, and if
  5201. # changed all federation sender workers must be stopped at the same time and then
  5202. # started, to ensure that all instances are running with the same config (otherwise
  5203. # events may be dropped).
  5204. #
  5205. #federation_sender_instances:
  5206. # - federation_sender1
  5207. # When using workers this should be a map from `worker_name` to the
  5208. # HTTP replication listener of the worker, if configured.
  5209. #
  5210. #instance_map:
  5211. # worker1:
  5212. # host: localhost
  5213. # port: 8034
  5214. # Experimental: When using workers you can define which workers should
  5215. # handle event persistence and typing notifications. Any worker
  5216. # specified here must also be in the `instance_map`.
  5217. #
  5218. #stream_writers:
  5219. # events: worker1
  5220. # typing: worker1
  5221. # The worker that is used to run background tasks (e.g. cleaning up expired
  5222. # data). If not provided this defaults to the main process.
  5223. #
  5224. #run_background_tasks_on: worker1
  5225. # A shared secret used by the replication APIs to authenticate HTTP requests
  5226. # from workers.
  5227. #
  5228. # By default this is unused and traffic is not authenticated.
  5229. #
  5230. #worker_replication_secret: &quot;&quot;
  5231. # Configuration for Redis when using workers. This *must* be enabled when
  5232. # using workers (unless using old style direct TCP configuration).
  5233. #
  5234. redis:
  5235. # Uncomment the below to enable Redis support.
  5236. #
  5237. #enabled: true
  5238. # Optional host and port to use to connect to redis. Defaults to
  5239. # localhost and 6379
  5240. #
  5241. #host: localhost
  5242. #port: 6379
  5243. # Optional password if configured on the Redis instance
  5244. #
  5245. #password: &lt;secret_password&gt;
  5246. </code></pre>
  5247. <div 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>
  5248. <p>Below is a sample logging configuration file. This file can be tweaked to control how your
  5249. homeserver will output logs. A restart of the server is generally required to apply any
  5250. changes made to this file.</p>
  5251. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  5252. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  5253. a fresh config using Synapse by following the instructions in
  5254. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  5255. <pre><code class="language-yaml"># Log configuration for Synapse.
  5256. #
  5257. # This is a YAML file containing a standard Python logging configuration
  5258. # dictionary. See [1] for details on the valid settings.
  5259. #
  5260. # Synapse also supports structured logging for machine readable logs which can
  5261. # be ingested by ELK stacks. See [2] for details.
  5262. #
  5263. # [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  5264. # [2]: https://matrix-org.github.io/synapse/latest/structured_logging.html
  5265. version: 1
  5266. formatters:
  5267. precise:
  5268. format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
  5269. handlers:
  5270. file:
  5271. class: logging.handlers.TimedRotatingFileHandler
  5272. formatter: precise
  5273. filename: /var/log/matrix-synapse/homeserver.log
  5274. when: midnight
  5275. backupCount: 3 # Does not include the current log file.
  5276. encoding: utf8
  5277. # Default to buffering writes to log file for efficiency.
  5278. # WARNING/ERROR logs will still be flushed immediately, but there will be a
  5279. # delay (of up to `period` seconds, or until the buffer is full with
  5280. # `capacity` messages) before INFO/DEBUG logs get written.
  5281. buffer:
  5282. class: synapse.logging.handlers.PeriodicallyFlushingMemoryHandler
  5283. target: file
  5284. # The capacity is the maximum number of log lines that are buffered
  5285. # before being written to disk. Increasing this will lead to better
  5286. # performance, at the expensive of it taking longer for log lines to
  5287. # be written to disk.
  5288. # This parameter is required.
  5289. capacity: 10
  5290. # Logs with a level at or above the flush level will cause the buffer to
  5291. # be flushed immediately.
  5292. # Default value: 40 (ERROR)
  5293. # Other values: 50 (CRITICAL), 30 (WARNING), 20 (INFO), 10 (DEBUG)
  5294. flushLevel: 30 # Flush immediately for WARNING logs and higher
  5295. # The period of time, in seconds, between forced flushes.
  5296. # Messages will not be delayed for longer than this time.
  5297. # Default value: 5 seconds
  5298. period: 5
  5299. # A handler that writes logs to stderr. Unused by default, but can be used
  5300. # instead of &quot;buffer&quot; and &quot;file&quot; in the logger handlers.
  5301. console:
  5302. class: logging.StreamHandler
  5303. formatter: precise
  5304. loggers:
  5305. synapse.storage.SQL:
  5306. # beware: increasing this to DEBUG will make synapse log sensitive
  5307. # information such as access tokens.
  5308. level: INFO
  5309. twisted:
  5310. # We send the twisted logging directly to the file handler,
  5311. # to work around https://github.com/matrix-org/synapse/issues/3471
  5312. # when using &quot;buffer&quot; logger. Use &quot;console&quot; to log to stderr instead.
  5313. handlers: [file]
  5314. propagate: false
  5315. root:
  5316. level: INFO
  5317. # Write logs to the `buffer` handler, which will buffer them together in memory,
  5318. # then write them to a file.
  5319. #
  5320. # Replace &quot;buffer&quot; with &quot;console&quot; to log to stderr instead. (Note that you'll
  5321. # also need to update the configuration for the `twisted` logger above, in
  5322. # this case.)
  5323. #
  5324. handlers: [buffer]
  5325. disable_existing_loggers: false
  5326. </code></pre>
  5327. <div style="break-before: page; page-break-before: always;"></div><h1 id="structured-logging"><a class="header" href="#structured-logging">Structured Logging</a></h1>
  5328. <p>A structured logging system can be useful when your logs are destined for a
  5329. machine to parse and process. By maintaining its machine-readable characteristics,
  5330. it enables more efficient searching and aggregations when consumed by software
  5331. such as the &quot;ELK stack&quot;.</p>
  5332. <p>Synapse's structured logging system is configured via the file that Synapse's
  5333. <code>log_config</code> config option points to. The file should include a formatter which
  5334. uses the <code>synapse.logging.TerseJsonFormatter</code> class included with Synapse and a
  5335. handler which uses the above formatter.</p>
  5336. <p>There is also a <code>synapse.logging.JsonFormatter</code> option which does not include
  5337. a timestamp in the resulting JSON. This is useful if the log ingester adds its
  5338. own timestamp.</p>
  5339. <p>A structured logging configuration looks similar to the following:</p>
  5340. <pre><code class="language-yaml">version: 1
  5341. formatters:
  5342. structured:
  5343. class: synapse.logging.TerseJsonFormatter
  5344. handlers:
  5345. file:
  5346. class: logging.handlers.TimedRotatingFileHandler
  5347. formatter: structured
  5348. filename: /path/to/my/logs/homeserver.log
  5349. when: midnight
  5350. backupCount: 3 # Does not include the current log file.
  5351. encoding: utf8
  5352. loggers:
  5353. synapse:
  5354. level: INFO
  5355. handlers: [remote]
  5356. synapse.storage.SQL:
  5357. level: WARNING
  5358. </code></pre>
  5359. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5360. with the SQL layer at 'WARNING', and will log to a file, stored as JSON.</p>
  5361. <p>It is also possible to figure Synapse to log to a remote endpoint by using the
  5362. <code>synapse.logging.RemoteHandler</code> class included with Synapse. It takes the
  5363. following arguments:</p>
  5364. <ul>
  5365. <li><code>host</code>: Hostname or IP address of the log aggregator.</li>
  5366. <li><code>port</code>: Numerical port to contact on the host.</li>
  5367. <li><code>maximum_buffer</code>: (Optional, defaults to 1000) The maximum buffer size to allow.</li>
  5368. </ul>
  5369. <p>A remote structured logging configuration looks similar to the following:</p>
  5370. <pre><code class="language-yaml">version: 1
  5371. formatters:
  5372. structured:
  5373. class: synapse.logging.TerseJsonFormatter
  5374. handlers:
  5375. remote:
  5376. class: synapse.logging.RemoteHandler
  5377. formatter: structured
  5378. host: 10.1.2.3
  5379. port: 9999
  5380. loggers:
  5381. synapse:
  5382. level: INFO
  5383. handlers: [remote]
  5384. synapse.storage.SQL:
  5385. level: WARNING
  5386. </code></pre>
  5387. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5388. with the SQL layer at 'WARNING', and will log JSON formatted messages to a
  5389. remote endpoint at 10.1.2.3:9999.</p>
  5390. <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>
  5391. <p>Versions of Synapse prior to v1.23.0 included a custom structured logging
  5392. configuration which is deprecated. It used a <code>structured: true</code> flag and
  5393. configured <code>drains</code> instead of <code>handlers</code> and <code>formatters</code>.</p>
  5394. <p>Synapse currently automatically converts the old configuration to the new
  5395. configuration, but this will be removed in a future version of Synapse. The
  5396. following reference can be used to update your configuration. Based on the drain
  5397. <code>type</code>, we can pick a new handler:</p>
  5398. <ol>
  5399. <li>For a type of <code>console</code>, <code>console_json</code>, or <code>console_json_terse</code>: a handler
  5400. with a class of <code>logging.StreamHandler</code> and a <code>stream</code> of <code>ext://sys.stdout</code>
  5401. or <code>ext://sys.stderr</code> should be used.</li>
  5402. <li>For a type of <code>file</code> or <code>file_json</code>: a handler of <code>logging.FileHandler</code> with
  5403. a location of the file path should be used.</li>
  5404. <li>For a type of <code>network_json_terse</code>: a handler of <code>synapse.logging.RemoteHandler</code>
  5405. with the host and port should be used.</li>
  5406. </ol>
  5407. <p>Then based on the drain <code>type</code> we can pick a new formatter:</p>
  5408. <ol>
  5409. <li>For a type of <code>console</code> or <code>file</code> no formatter is necessary.</li>
  5410. <li>For a type of <code>console_json</code> or <code>file_json</code>: a formatter of
  5411. <code>synapse.logging.JsonFormatter</code> should be used.</li>
  5412. <li>For a type of <code>console_json_terse</code> or <code>network_json_terse</code>: a formatter of
  5413. <code>synapse.logging.TerseJsonFormatter</code> should be used.</li>
  5414. </ol>
  5415. <p>For each new handler and formatter they should be added to the logging configuration
  5416. and then assigned to either a logger or the root logger.</p>
  5417. <p>An example legacy configuration:</p>
  5418. <pre><code class="language-yaml">structured: true
  5419. loggers:
  5420. synapse:
  5421. level: INFO
  5422. synapse.storage.SQL:
  5423. level: WARNING
  5424. drains:
  5425. console:
  5426. type: console
  5427. location: stdout
  5428. file:
  5429. type: file_json
  5430. location: homeserver.log
  5431. </code></pre>
  5432. <p>Would be converted into a new configuration:</p>
  5433. <pre><code class="language-yaml">version: 1
  5434. formatters:
  5435. json:
  5436. class: synapse.logging.JsonFormatter
  5437. handlers:
  5438. console:
  5439. class: logging.StreamHandler
  5440. location: ext://sys.stdout
  5441. file:
  5442. class: logging.FileHandler
  5443. formatter: json
  5444. filename: homeserver.log
  5445. loggers:
  5446. synapse:
  5447. level: INFO
  5448. handlers: [console, file]
  5449. synapse.storage.SQL:
  5450. level: WARNING
  5451. </code></pre>
  5452. <p>The new logging configuration is a bit more verbose, but significantly more
  5453. flexible. It allows for configuration that were not previously possible, such as
  5454. sending plain logs over the network, or using different handlers for different
  5455. modules.</p>
  5456. <div style="break-before: page; page-break-before: always;"></div><h1 id="templates"><a class="header" href="#templates">Templates</a></h1>
  5457. <p>Synapse uses parametrised templates to generate the content of emails it sends and
  5458. webpages it shows to users.</p>
  5459. <p>By default, Synapse will use the templates listed <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">here</a>.
  5460. Server admins can configure an additional directory for Synapse to look for templates
  5461. in, allowing them to specify custom templates:</p>
  5462. <pre><code class="language-yaml">templates:
  5463. custom_templates_directory: /path/to/custom/templates/
  5464. </code></pre>
  5465. <p>If this setting is not set, or the files named below are not found within the directory,
  5466. default templates from within the Synapse package will be used.</p>
  5467. <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>.
  5468. Templates rendered by Jinja 2 can also access two functions on top of the functions
  5469. already available as part of Jinja 2:</p>
  5470. <pre><code class="language-python">format_ts(value: int, format: str) -&gt; str
  5471. </code></pre>
  5472. <p>Formats a timestamp in milliseconds.</p>
  5473. <p>Example: <code>reason.last_sent_ts|format_ts(&quot;%c&quot;)</code></p>
  5474. <pre><code class="language-python">mxc_to_http(value: str, width: int, height: int, resize_method: str = &quot;crop&quot;) -&gt; str
  5475. </code></pre>
  5476. <p>Turns a <code>mxc://</code> URL for media content into an HTTP(S) one using the homeserver's
  5477. <code>public_baseurl</code> configuration setting as the URL's base.</p>
  5478. <p>Example: <code>message.sender_avatar_url|mxc_to_http(32,32)</code></p>
  5479. <h2 id="email-templates"><a class="header" href="#email-templates">Email templates</a></h2>
  5480. <p>Below are the templates Synapse will look for when generating the content of an email:</p>
  5481. <ul>
  5482. <li><code>notif_mail.html</code> and <code>notif_mail.txt</code>: The contents of email notifications of missed
  5483. events.
  5484. When rendering, this template is given the following variables:
  5485. <ul>
  5486. <li><code>user_display_name</code>: the display name for the user receiving the notification</li>
  5487. <li><code>unsubscribe_link</code>: the link users can click to unsubscribe from email notifications</li>
  5488. <li><code>summary_text</code>: a summary of the notification(s). The text used can be customised
  5489. by configuring the various settings in the <code>email.subjects</code> section of the
  5490. configuration file.</li>
  5491. <li><code>rooms</code>: a list of rooms containing events to include in the email. Each element is
  5492. an object with the following attributes:
  5493. <ul>
  5494. <li><code>title</code>: a human-readable name for the room</li>
  5495. <li><code>hash</code>: a hash of the ID of the room</li>
  5496. <li><code>invite</code>: a boolean, which is <code>True</code> if the room is an invite the user hasn't
  5497. accepted yet, <code>False</code> otherwise</li>
  5498. <li><code>notifs</code>: a list of events, or an empty list if <code>invite</code> is <code>True</code>. Each element
  5499. is an object with the following attributes:
  5500. <ul>
  5501. <li><code>link</code>: a <code>matrix.to</code> link to the event</li>
  5502. <li><code>ts</code>: the time in milliseconds at which the event was received</li>
  5503. <li><code>messages</code>: a list of messages containing one message before the event, the
  5504. message in the event, and one message after the event. Each element is an
  5505. object with the following attributes:
  5506. <ul>
  5507. <li><code>event_type</code>: the type of the event</li>
  5508. <li><code>is_historical</code>: a boolean, which is <code>False</code> if the message is the one
  5509. that triggered the notification, <code>True</code> otherwise</li>
  5510. <li><code>id</code>: the ID of the event</li>
  5511. <li><code>ts</code>: the time in milliseconds at which the event was sent</li>
  5512. <li><code>sender_name</code>: the display name for the event's sender</li>
  5513. <li><code>sender_avatar_url</code>: the avatar URL (as a <code>mxc://</code> URL) for the event's
  5514. sender</li>
  5515. <li><code>sender_hash</code>: a hash of the user ID of the sender</li>
  5516. </ul>
  5517. </li>
  5518. </ul>
  5519. </li>
  5520. <li><code>link</code>: a <code>matrix.to</code> link to the room</li>
  5521. </ul>
  5522. </li>
  5523. <li><code>reason</code>: information on the event that triggered the email to be sent. It's an
  5524. object with the following attributes:
  5525. <ul>
  5526. <li><code>room_id</code>: the ID of the room the event was sent in</li>
  5527. <li><code>room_name</code>: a human-readable name for the room the event was sent in</li>
  5528. <li><code>now</code>: the current time in milliseconds</li>
  5529. <li><code>received_at</code>: the time in milliseconds at which the event was received</li>
  5530. <li><code>delay_before_mail_ms</code>: the amount of time in milliseconds Synapse always waits
  5531. before ever emailing about a notification (to give the user a chance to respond
  5532. to other push or notice the window)</li>
  5533. <li><code>last_sent_ts</code>: the time in milliseconds at which a notification was last sent
  5534. for an event in this room</li>
  5535. <li><code>throttle_ms</code>: the minimum amount of time in milliseconds between two
  5536. notifications can be sent for this room</li>
  5537. </ul>
  5538. </li>
  5539. </ul>
  5540. </li>
  5541. <li><code>password_reset.html</code> and <code>password_reset.txt</code>: The contents of password reset emails
  5542. sent by the homeserver.
  5543. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5544. user must click in order to reset their password.</li>
  5545. <li><code>registration.html</code> and <code>registration.txt</code>: The contents of address verification emails
  5546. sent during registration.
  5547. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5548. user must click in order to validate their email address.</li>
  5549. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code>: The contents of address verification emails
  5550. sent when an address is added to a Matrix account.
  5551. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5552. user must click in order to validate their email address.</li>
  5553. </ul>
  5554. <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>
  5555. <p>Below are the templates Synapse will look for when generating pages related to
  5556. registration and password reset:</p>
  5557. <ul>
  5558. <li><code>password_reset_confirmation.html</code>: An HTML page that a user will see when they follow
  5559. the link in the password reset email. The user will be asked to confirm the action
  5560. before their password is reset.
  5561. When rendering, this template is given the following variables:
  5562. <ul>
  5563. <li><code>sid</code>: the session ID for the password reset</li>
  5564. <li><code>token</code>: the token for the password reset</li>
  5565. <li><code>client_secret</code>: the client secret for the password reset</li>
  5566. </ul>
  5567. </li>
  5568. <li><code>password_reset_success.html</code> and <code>password_reset_failure.html</code>: HTML pages for success
  5569. and failure that a user will see when they confirm the password reset flow using the
  5570. page above.
  5571. When rendering, <code>password_reset_success.html</code> is given no variable, and
  5572. <code>password_reset_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5573. for the password reset failure. </li>
  5574. <li><code>registration_success.html</code> and <code>registration_failure.html</code>: HTML pages for success and
  5575. failure that a user will see when they follow the link in an address verification email
  5576. sent during registration.
  5577. When rendering, <code>registration_success.html</code> is given no variable, and
  5578. <code>registration_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5579. for the registration failure.</li>
  5580. <li><code>add_threepid_success.html</code> and <code>add_threepid_failure.html</code>: HTML pages for success and
  5581. failure that a user will see when they follow the link in an address verification email
  5582. sent when an address is added to a Matrix account.
  5583. When rendering, <code>add_threepid_success.html</code> is given no variable, and
  5584. <code>add_threepid_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5585. for the registration failure.</li>
  5586. </ul>
  5587. <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>
  5588. <p>Below are the templates Synapse will look for when generating pages related to SSO:</p>
  5589. <ul>
  5590. <li><code>sso_login_idp_picker.html</code>: HTML page to prompt the user to choose an
  5591. Identity Provider during login.
  5592. This is only used if multiple SSO Identity Providers are configured.
  5593. When rendering, this template is given the following variables:
  5594. <ul>
  5595. <li><code>redirect_url</code>: the URL that the user will be redirected to after
  5596. login.</li>
  5597. <li><code>server_name</code>: the homeserver's name.</li>
  5598. <li><code>providers</code>: a list of available Identity Providers. Each element is
  5599. 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
  5607. The rendered HTML page should contain a form which submits its results
  5608. back as a GET request, with the following query parameters:</li>
  5609. </ul>
  5610. </li>
  5611. <li><code>redirectUrl</code>: the client redirect URI (ie, the <code>redirect_url</code> passed
  5612. to the template)</li>
  5613. <li><code>idp</code>: the 'idp_id' of the chosen IDP.</li>
  5614. </ul>
  5615. </li>
  5616. <li><code>sso_auth_account_details.html</code>: HTML page to prompt new users to enter a
  5617. userid and confirm other details. This is only shown if the
  5618. SSO implementation (with any <code>user_mapping_provider</code>) does not return
  5619. a localpart.
  5620. When rendering, this template is given the following variables:
  5621. <ul>
  5622. <li><code>server_name</code>: the homeserver's name.</li>
  5623. <li><code>idp</code>: details of the SSO Identity Provider that the user logged in
  5624. with: an object with the following attributes:
  5625. <ul>
  5626. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5627. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5628. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5629. for the IdP</li>
  5630. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5631. for the brand of the IdP</li>
  5632. </ul>
  5633. </li>
  5634. <li><code>user_attributes</code>: an object containing details about the user that
  5635. we received from the IdP. May have the following attributes:
  5636. <ul>
  5637. <li>display_name: the user's display_name</li>
  5638. <li>emails: a list of email addresses
  5639. The template should render a form which submits the following fields:</li>
  5640. </ul>
  5641. </li>
  5642. <li><code>username</code>: the localpart of the user's chosen user id</li>
  5643. </ul>
  5644. </li>
  5645. <li><code>sso_new_user_consent.html</code>: HTML page allowing the user to consent to the
  5646. server's terms and conditions. This is only shown for new users, and only if
  5647. <code>user_consent.require_at_registration</code> is set.
  5648. When rendering, this template is given the following variables:
  5649. <ul>
  5650. <li><code>server_name</code>: the homeserver's name.</li>
  5651. <li><code>user_id</code>: the user's matrix proposed ID.</li>
  5652. <li><code>user_profile.display_name</code>: the user's proposed display name, if any.</li>
  5653. <li>consent_version: the version of the terms that the user will be
  5654. shown</li>
  5655. <li><code>terms_url</code>: a link to the page showing the terms.
  5656. The template should render a form which submits the following fields:</li>
  5657. <li><code>accepted_version</code>: the version of the terms accepted by the user
  5658. (ie, 'consent_version' from the input variables).</li>
  5659. </ul>
  5660. </li>
  5661. <li><code>sso_redirect_confirm.html</code>: HTML page for a confirmation step before redirecting back
  5662. to the client with the login token.
  5663. When rendering, this template is given the following variables:
  5664. <ul>
  5665. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5666. <li><code>display_url</code>: the same as <code>redirect_url</code>, but with the query
  5667. parameters stripped. The intention is to have a
  5668. human-readable URL to show to users, not to use it as
  5669. the final address to redirect to.</li>
  5670. <li><code>server_name</code>: the homeserver's name.</li>
  5671. <li><code>new_user</code>: a boolean indicating whether this is the user's first time
  5672. logging in.</li>
  5673. <li><code>user_id</code>: the user's matrix ID.</li>
  5674. <li><code>user_profile.avatar_url</code>: an MXC URI for the user's avatar, if any.
  5675. <code>None</code> if the user has not set an avatar.</li>
  5676. <li><code>user_profile.display_name</code>: the user's display name. <code>None</code> if the user
  5677. has not set a display name.</li>
  5678. </ul>
  5679. </li>
  5680. <li><code>sso_auth_confirm.html</code>: HTML page which notifies the user that they are authenticating
  5681. to confirm an operation on their account during the user interactive authentication
  5682. process.
  5683. When rendering, this template is given the following variables:
  5684. <ul>
  5685. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5686. <li><code>description</code>: the operation which the user is being asked to confirm</li>
  5687. <li><code>idp</code>: details of the Identity Provider that we will use to confirm
  5688. the user's identity: an object with the following attributes:
  5689. <ul>
  5690. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5691. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5692. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5693. for the IdP</li>
  5694. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5695. for the brand of the IdP</li>
  5696. </ul>
  5697. </li>
  5698. </ul>
  5699. </li>
  5700. <li><code>sso_auth_success.html</code>: HTML page shown after a successful user interactive
  5701. authentication session.
  5702. Note that this page must include the JavaScript which notifies of a successful
  5703. authentication (see https://matrix.org/docs/spec/client_server/r0.6.0#fallback).
  5704. This template has no additional variables.</li>
  5705. <li><code>sso_auth_bad_user.html</code>: HTML page shown after a user-interactive authentication
  5706. session which does not map correctly onto the expected user.
  5707. When rendering, this template is given the following variables:
  5708. <ul>
  5709. <li><code>server_name</code>: the homeserver's name.</li>
  5710. <li><code>user_id_to_verify</code>: the MXID of the user that we are trying to
  5711. validate.</li>
  5712. </ul>
  5713. </li>
  5714. <li><code>sso_account_deactivated.html</code>: HTML page shown during single sign-on if a deactivated
  5715. user (according to Synapse's database) attempts to login.
  5716. This template has no additional variables.</li>
  5717. <li><code>sso_error.html</code>: HTML page to display to users if something goes wrong during the
  5718. OpenID Connect authentication process.
  5719. When rendering, this template is given two variables:
  5720. <ul>
  5721. <li><code>error</code>: the technical name of the error</li>
  5722. <li><code>error_description</code>: a human-readable message for the error</li>
  5723. </ul>
  5724. </li>
  5725. </ul>
  5726. <div style="break-before: page; page-break-before: always;"></div><h1 id="user-authentication"><a class="header" href="#user-authentication">User Authentication</a></h1>
  5727. <p>Synapse supports multiple methods of authenticating users, either out-of-the-box or through custom pluggable
  5728. authentication modules.</p>
  5729. <p>Included in Synapse is support for authenticating users via:</p>
  5730. <ul>
  5731. <li>A username and password.</li>
  5732. <li>An email address and password.</li>
  5733. <li>Single Sign-On through the SAML, Open ID Connect or CAS protocols.</li>
  5734. <li>JSON Web Tokens.</li>
  5735. <li>An administrator's shared secret.</li>
  5736. </ul>
  5737. <p>Synapse can additionally be extended to support custom authentication schemes through optional &quot;password auth provider&quot;
  5738. modules.</p>
  5739. <div 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>
  5740. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  5741. authentication, instead of its own local password database.</p>
  5742. <p>Any OP should work with Synapse, as long as it supports the authorization code
  5743. flow. There are a few options for that:</p>
  5744. <ul>
  5745. <li>
  5746. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  5747. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  5748. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  5749. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  5750. environment variable set to the path of the CA.</p>
  5751. </li>
  5752. <li>
  5753. <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
  5754. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  5755. </li>
  5756. </ul>
  5757. <p>It may also be possible to use other OAuth2 providers which provide the
  5758. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  5759. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  5760. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  5761. <p>The OpenID integration in Synapse uses the
  5762. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  5763. as follows:</p>
  5764. <ul>
  5765. <li>
  5766. <p>The relevant libraries are included in the Docker images and Debian packages
  5767. provided by <code>matrix.org</code> so no further action is needed.</p>
  5768. </li>
  5769. <li>
  5770. <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>
  5771. </li>
  5772. <li>
  5773. <p>For other installation mechanisms, see the documentation provided by the
  5774. maintainer.</p>
  5775. </li>
  5776. </ul>
  5777. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  5778. setting in your configuration file (or uncomment one of the existing examples).
  5779. See <a href="./sample_config.yaml">sample_config.yaml</a> for some sample settings, as well as
  5780. the text below for example configurations for specific providers.</p>
  5781. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  5782. <p>Here are a few configs for providers that should work with Synapse.</p>
  5783. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  5784. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  5785. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  5786. application should point to your matrix server:
  5787. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5788. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  5789. Directory (tenant) ID as it will be used in the Azure links.
  5790. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  5791. <pre><code class="language-yaml">oidc_providers:
  5792. - idp_id: microsoft
  5793. idp_name: Microsoft
  5794. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  5795. client_id: &quot;&lt;client id&gt;&quot;
  5796. client_secret: &quot;&lt;client secret&gt;&quot;
  5797. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5798. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  5799. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  5800. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  5801. user_mapping_provider:
  5802. config:
  5803. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  5804. display_name_template: &quot;{{ user.name }}&quot;
  5805. </code></pre>
  5806. <h3 id="dex"><a class="header" href="#dex">Dex</a></h3>
  5807. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source, certified OpenID Connect Provider.
  5808. Although it is designed to help building a full-blown provider with an
  5809. external database, it can be configured with static passwords in a config file.</p>
  5810. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  5811. to install Dex.</p>
  5812. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  5813. <pre><code class="language-yaml">staticClients:
  5814. - id: synapse
  5815. secret: secret
  5816. redirectURIs:
  5817. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  5818. name: 'Synapse'
  5819. </code></pre>
  5820. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  5821. <p>Synapse config:</p>
  5822. <pre><code class="language-yaml">oidc_providers:
  5823. - idp_id: dex
  5824. idp_name: &quot;My Dex server&quot;
  5825. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  5826. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  5827. client_id: &quot;synapse&quot;
  5828. client_secret: &quot;secret&quot;
  5829. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5830. user_mapping_provider:
  5831. config:
  5832. localpart_template: &quot;{{ user.name }}&quot;
  5833. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  5834. </code></pre>
  5835. <h3 id="keycloak"><a class="header" href="#keycloak">Keycloak</a></h3>
  5836. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  5837. <p>Follow the <a href="https://www.keycloak.org/getting-started">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  5838. <ol>
  5839. <li>
  5840. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  5841. </li>
  5842. <li>
  5843. <p>Fill in the fields as below:</p>
  5844. </li>
  5845. </ol>
  5846. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5847. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5848. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5849. </tbody></table>
  5850. <ol start="3">
  5851. <li>Click <code>Save</code></li>
  5852. <li>Fill in the fields as below:</li>
  5853. </ol>
  5854. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5855. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5856. <tr><td>Enabled</td><td><code>On</code></td></tr>
  5857. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5858. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  5859. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  5860. </tbody></table>
  5861. <ol start="5">
  5862. <li>Click <code>Save</code></li>
  5863. <li>On the Credentials tab, update the fields:</li>
  5864. </ol>
  5865. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5866. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  5867. </tbody></table>
  5868. <ol start="7">
  5869. <li>Click <code>Regenerate Secret</code></li>
  5870. <li>Copy Secret</li>
  5871. </ol>
  5872. <pre><code class="language-yaml">oidc_providers:
  5873. - idp_id: keycloak
  5874. idp_name: &quot;My KeyCloak server&quot;
  5875. issuer: &quot;https://127.0.0.1:8443/auth/realms/{realm_name}&quot;
  5876. client_id: &quot;synapse&quot;
  5877. client_secret: &quot;copy secret generated from above&quot;
  5878. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5879. user_mapping_provider:
  5880. config:
  5881. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5882. display_name_template: &quot;{{ user.name }}&quot;
  5883. </code></pre>
  5884. <h3 id="auth0"><a class="header" href="#auth0">Auth0</a></h3>
  5885. <p><a href="https://auth0.com/">Auth0</a> is a hosted SaaS IdP solution.</p>
  5886. <ol>
  5887. <li>
  5888. <p>Create a regular web application for Synapse</p>
  5889. </li>
  5890. <li>
  5891. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5892. </li>
  5893. <li>
  5894. <p>Add a rule to add the <code>preferred_username</code> claim.</p>
  5895. <details>
  5896. <summary>Code sample</summary>
  5897. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  5898. user.user_metadata = user.user_metadata || {};
  5899. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  5900. context.idToken.preferred_username = user.user_metadata.preferred_username;
  5901. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  5902. .then(function(){
  5903. callback(null, user, context);
  5904. })
  5905. .catch(function(err){
  5906. callback(err);
  5907. });
  5908. }
  5909. </code></pre>
  5910. </li>
  5911. </ol>
  5912. </details>
  5913. <p>Synapse config:</p>
  5914. <pre><code class="language-yaml">oidc_providers:
  5915. - idp_id: auth0
  5916. idp_name: Auth0
  5917. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  5918. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5919. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5920. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5921. user_mapping_provider:
  5922. config:
  5923. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5924. display_name_template: &quot;{{ user.name }}&quot;
  5925. </code></pre>
  5926. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  5927. <p><a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">GitHub</a> is a bit special as it is not an OpenID Connect compliant provider, but
  5928. just a regular OAuth2 provider.</p>
  5929. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  5930. can be used to retrieve information on the authenticated user. As the Synapse
  5931. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5932. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5933. <ol>
  5934. <li>Create a new OAuth application: https://github.com/settings/applications/new.</li>
  5935. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5936. </ol>
  5937. <p>Synapse config:</p>
  5938. <pre><code class="language-yaml">oidc_providers:
  5939. - idp_id: github
  5940. idp_name: Github
  5941. idp_brand: &quot;github&quot; # optional: styling hint for clients
  5942. discover: false
  5943. issuer: &quot;https://github.com/&quot;
  5944. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5945. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5946. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  5947. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  5948. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  5949. scopes: [&quot;read:user&quot;]
  5950. user_mapping_provider:
  5951. config:
  5952. subject_claim: &quot;id&quot;
  5953. localpart_template: &quot;{{ user.login }}&quot;
  5954. display_name_template: &quot;{{ user.name }}&quot;
  5955. </code></pre>
  5956. <h3 id="google"><a class="header" href="#google">Google</a></h3>
  5957. <p><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a> is an OpenID certified authentication and authorisation provider.</p>
  5958. <ol>
  5959. <li>Set up a project in the Google API Console (see
  5960. https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup).</li>
  5961. <li>Add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  5962. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  5963. <pre><code class="language-yaml">oidc_providers:
  5964. - idp_id: google
  5965. idp_name: Google
  5966. idp_brand: &quot;google&quot; # optional: styling hint for clients
  5967. issuer: &quot;https://accounts.google.com/&quot;
  5968. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5969. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5970. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5971. user_mapping_provider:
  5972. config:
  5973. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  5974. display_name_template: &quot;{{ user.name }}&quot;
  5975. </code></pre>
  5976. </li>
  5977. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5978. </ol>
  5979. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  5980. <ol>
  5981. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  5982. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  5983. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5984. </ol>
  5985. <p>Synapse config:</p>
  5986. <pre><code class="language-yaml">oidc_providers:
  5987. - idp_id: twitch
  5988. idp_name: Twitch
  5989. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  5990. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5991. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5992. client_auth_method: &quot;client_secret_post&quot;
  5993. user_mapping_provider:
  5994. config:
  5995. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5996. display_name_template: &quot;{{ user.name }}&quot;
  5997. </code></pre>
  5998. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  5999. <ol>
  6000. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  6001. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  6002. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  6003. </ol>
  6004. <p>Synapse config:</p>
  6005. <pre><code class="language-yaml">oidc_providers:
  6006. - idp_id: gitlab
  6007. idp_name: Gitlab
  6008. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  6009. issuer: &quot;https://gitlab.com/&quot;
  6010. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6011. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6012. client_auth_method: &quot;client_secret_post&quot;
  6013. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  6014. user_profile_method: &quot;userinfo_endpoint&quot;
  6015. user_mapping_provider:
  6016. config:
  6017. localpart_template: '{{ user.nickname }}'
  6018. display_name_template: '{{ user.name }}'
  6019. </code></pre>
  6020. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  6021. <p>Like Github, Facebook provide a custom OAuth2 API rather than an OIDC-compliant
  6022. one so requires a little more configuration.</p>
  6023. <ol start="0">
  6024. <li>You will need a Facebook developer account. You can register for one
  6025. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  6026. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  6027. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  6028. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  6029. need to go through the whole form here.</li>
  6030. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  6031. <ul>
  6032. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  6033. URL.</li>
  6034. </ul>
  6035. </li>
  6036. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  6037. and &quot;App Secret&quot; for use below.</li>
  6038. </ol>
  6039. <p>Synapse config:</p>
  6040. <pre><code class="language-yaml"> - idp_id: facebook
  6041. idp_name: Facebook
  6042. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  6043. discover: false
  6044. issuer: &quot;https://facebook.com&quot;
  6045. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6046. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6047. scopes: [&quot;openid&quot;, &quot;email&quot;]
  6048. authorization_endpoint: https://facebook.com/dialog/oauth
  6049. token_endpoint: https://graph.facebook.com/v9.0/oauth/access_token
  6050. user_profile_method: &quot;userinfo_endpoint&quot;
  6051. userinfo_endpoint: &quot;https://graph.facebook.com/v9.0/me?fields=id,name,email,picture&quot;
  6052. user_mapping_provider:
  6053. config:
  6054. subject_claim: &quot;id&quot;
  6055. display_name_template: &quot;{{ user.name }}&quot;
  6056. </code></pre>
  6057. <p>Relevant documents:</p>
  6058. <ul>
  6059. <li>https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow</li>
  6060. <li>Using Facebook's Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/</li>
  6061. <li>Reference to the User endpoint: https://developers.facebook.com/docs/graph-api/reference/user</li>
  6062. </ul>
  6063. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  6064. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  6065. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  6066. can be used to retrieve information on the authenticated user. As the Synapse
  6067. login mechanism needs an attribute to uniquely identify users, and that endpoint
  6068. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  6069. <ol>
  6070. <li>Create a new application.</li>
  6071. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  6072. </ol>
  6073. <p>Synapse config:</p>
  6074. <pre><code class="language-yaml">oidc_providers:
  6075. - idp_id: gitea
  6076. idp_name: Gitea
  6077. discover: false
  6078. issuer: &quot;https://your-gitea.com/&quot;
  6079. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6080. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6081. client_auth_method: client_secret_post
  6082. scopes: [] # Gitea doesn't support Scopes
  6083. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  6084. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  6085. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  6086. user_mapping_provider:
  6087. config:
  6088. subject_claim: &quot;id&quot;
  6089. localpart_template: &quot;{{ user.login }}&quot;
  6090. display_name_template: &quot;{{ user.full_name }}&quot;
  6091. </code></pre>
  6092. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  6093. <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>
  6094. <p>Synapse config:</p>
  6095. <pre><code class="language-yaml">oidc_providers:
  6096. - idp_id: xwiki
  6097. idp_name: &quot;XWiki&quot;
  6098. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  6099. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6100. client_auth_method: none
  6101. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  6102. user_profile_method: &quot;userinfo_endpoint&quot;
  6103. user_mapping_provider:
  6104. config:
  6105. localpart_template: &quot;{{ user.preferred_username }}&quot;
  6106. display_name_template: &quot;{{ user.name }}&quot;
  6107. </code></pre>
  6108. <h3 id="apple"><a class="header" href="#apple">Apple</a></h3>
  6109. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  6110. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  6111. private key with &quot;SiWA&quot; enabled.</p>
  6112. <p>As well as the private key file, you will need:</p>
  6113. <ul>
  6114. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  6115. <li>Team ID: a 10-character ID associated with your developer account.</li>
  6116. <li>Key ID: the 10-character identifier for the key.</li>
  6117. </ul>
  6118. <p>https://help.apple.com/developer-account/?lang=en#/dev77c875b7e has more
  6119. documentation on setting up SiWA.</p>
  6120. <p>The synapse config will look like this:</p>
  6121. <pre><code class="language-yaml"> - idp_id: apple
  6122. idp_name: Apple
  6123. issuer: &quot;https://appleid.apple.com&quot;
  6124. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  6125. client_auth_method: &quot;client_secret_post&quot;
  6126. client_secret_jwt_key:
  6127. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  6128. jwt_header:
  6129. alg: ES256
  6130. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  6131. jwt_payload:
  6132. iss: TEAMIDCODE # Set to the 10-char Team ID
  6133. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  6134. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  6135. user_mapping_provider:
  6136. config:
  6137. email_template: &quot;{{ user.email }}&quot;
  6138. </code></pre>
  6139. <h2 id="django-oauth-toolkit"><a class="header" href="#django-oauth-toolkit">Django OAuth Toolkit</a></h2>
  6140. <p><a href="https://github.com/jazzband/django-oauth-toolkit">django-oauth-toolkit</a> is a
  6141. Django application providing out of the box all the endpoints, data and logic
  6142. needed to add OAuth2 capabilities to your Django projects. It supports
  6143. <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html">OpenID Connect too</a>.</p>
  6144. <p>Configuration on Django's side:</p>
  6145. <ol>
  6146. <li>Add an application: https://example.com/admin/oauth2_provider/application/add/ and choose parameters like this:</li>
  6147. </ol>
  6148. <ul>
  6149. <li><code>Redirect uris</code>: https://synapse.example.com/_synapse/client/oidc/callback</li>
  6150. <li><code>Client type</code>: <code>Confidential</code></li>
  6151. <li><code>Authorization grant type</code>: <code>Authorization code</code></li>
  6152. <li><code>Algorithm</code>: <code>HMAC with SHA-2 256</code></li>
  6153. </ul>
  6154. <ol start="2">
  6155. <li>
  6156. <p>You can <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html#customizing-the-oidc-responses">customize the claims</a> Django gives to synapse (optional):</p>
  6157. <details>
  6158. <summary>Code sample</summary>
  6159. <pre><code class="language-python">class CustomOAuth2Validator(OAuth2Validator):
  6160. def get_additional_claims(self, request):
  6161. return {
  6162. &quot;sub&quot;: request.user.email,
  6163. &quot;email&quot;: request.user.email,
  6164. &quot;first_name&quot;: request.user.first_name,
  6165. &quot;last_name&quot;: request.user.last_name,
  6166. }
  6167. </code></pre>
  6168. </details>
  6169. </li>
  6170. </ol>
  6171. <p>Your synapse config is then:</p>
  6172. <pre><code class="language-yaml">oidc_providers:
  6173. - idp_id: django_example
  6174. idp_name: &quot;Django Example&quot;
  6175. issuer: &quot;https://example.com/o/&quot;
  6176. client_id: &quot;your-client-id&quot; # CHANGE ME
  6177. client_secret: &quot;your-client-secret&quot; # CHANGE ME
  6178. scopes: [&quot;openid&quot;]
  6179. user_profile_method: &quot;userinfo_endpoint&quot; # needed because oauth-toolkit does not include user information in the authorization response
  6180. user_mapping_provider:
  6181. config:
  6182. localpart_template: &quot;{{ user.email.split('@')[0] }}&quot;
  6183. display_name_template: &quot;{{ user.first_name }} {{ user.last_name }}&quot;
  6184. email_template: &quot;{{ user.email }}&quot;
  6185. </code></pre>
  6186. <div 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>
  6187. <p>A mapping provider is a Python class (loaded via a Python module) that
  6188. works out how to map attributes of a SSO response to Matrix-specific
  6189. user attributes. Details such as user ID localpart, displayname, and even avatar
  6190. URLs are all things that can be mapped from talking to a SSO service.</p>
  6191. <p>As an example, a SSO service may return the email address
  6192. &quot;john.smith@example.com&quot; for a user, whereas Synapse will need to figure out how
  6193. to turn that into a displayname when creating a Matrix user for this individual.
  6194. It may choose <code>John Smith</code>, or <code>Smith, John [Example.com]</code> or any number of
  6195. variations. As each Synapse configuration may want something different, this is
  6196. where SAML mapping providers come into play.</p>
  6197. <p>SSO mapping providers are currently supported for OpenID and SAML SSO
  6198. configurations. Please see the details below for how to implement your own.</p>
  6199. <p>It is up to the mapping provider whether the user should be assigned a predefined
  6200. Matrix ID based on the SSO attributes, or if the user should be allowed to
  6201. choose their own username.</p>
  6202. <p>In the first case - where users are automatically allocated a Matrix ID - it is
  6203. the responsibility of the mapping provider to normalise the SSO attributes and
  6204. map them to a valid Matrix ID. The <a href="https://matrix.org/docs/spec/appendices#user-identifiers">specification for Matrix
  6205. IDs</a> has some
  6206. information about what is considered valid.</p>
  6207. <p>If the mapping provider does not assign a Matrix ID, then Synapse will
  6208. automatically serve an HTML page allowing the user to pick their own username.</p>
  6209. <p>External mapping providers are provided to Synapse in the form of an external
  6210. Python module. You can retrieve this module from <a href="https://pypi.org">PyPI</a> or elsewhere,
  6211. but it must be importable via Synapse (e.g. it must be in the same virtualenv
  6212. as Synapse). The Synapse config is then modified to point to the mapping provider
  6213. (and optionally provide additional configuration for it).</p>
  6214. <h2 id="openid-mapping-providers"><a class="header" href="#openid-mapping-providers">OpenID Mapping Providers</a></h2>
  6215. <p>The OpenID mapping provider can be customized by editing the
  6216. <code>oidc_config.user_mapping_provider.module</code> config option.</p>
  6217. <p><code>oidc_config.user_mapping_provider.config</code> allows you to provide custom
  6218. configuration options to the module. Check with the module's documentation for
  6219. what options it provides (if any). The options listed by default are for the
  6220. user mapping provider built in to Synapse. If using a custom module, you should
  6221. comment these options out and use those specified by the module instead.</p>
  6222. <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>
  6223. <p>A custom mapping provider must specify the following methods:</p>
  6224. <ul>
  6225. <li><code>__init__(self, parsed_config)</code>
  6226. <ul>
  6227. <li>Arguments:
  6228. <ul>
  6229. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6230. <code>parse_config</code> method. You should set any configuration options needed by
  6231. the module here.</li>
  6232. </ul>
  6233. </li>
  6234. </ul>
  6235. </li>
  6236. <li><code>parse_config(config)</code>
  6237. <ul>
  6238. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6239. <li>Arguments:
  6240. <ul>
  6241. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6242. <code>oidc_config.user_mapping_provider.config</code> homeserver config option.
  6243. Runs on homeserver startup. Providers should extract and validate
  6244. any option values they need here.</li>
  6245. </ul>
  6246. </li>
  6247. <li>Whatever is returned will be passed back to the user mapping provider module's
  6248. <code>__init__</code> method during construction.</li>
  6249. </ul>
  6250. </li>
  6251. <li><code>get_remote_user_id(self, userinfo)</code>
  6252. <ul>
  6253. <li>Arguments:
  6254. <ul>
  6255. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6256. information from.</li>
  6257. </ul>
  6258. </li>
  6259. <li>This method must return a string, which is the unique, immutable identifier
  6260. for the user. Commonly the <code>sub</code> claim of the response.</li>
  6261. </ul>
  6262. </li>
  6263. <li><code>map_user_attributes(self, userinfo, token, failures)</code>
  6264. <ul>
  6265. <li>This method must be async.</li>
  6266. <li>Arguments:
  6267. <ul>
  6268. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6269. information from.</li>
  6270. <li><code>token</code> - A dictionary which includes information necessary to make
  6271. further requests to the OpenID provider.</li>
  6272. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6273. mxid localpart mapping has failed. This should be used
  6274. to create a deduplicated mxid localpart which should be
  6275. returned instead. For example, if this method returns
  6276. <code>john.doe</code> as the value of <code>localpart</code> in the returned
  6277. dict, and that is already taken on the homeserver, this
  6278. method will be called again with the same parameters but
  6279. with failures=1. The method should then return a different
  6280. <code>localpart</code> value, such as <code>john.doe1</code>.</li>
  6281. </ul>
  6282. </li>
  6283. <li>Returns a dictionary with two keys:
  6284. <ul>
  6285. <li><code>localpart</code>: A string, used to generate the Matrix ID. If this is
  6286. <code>None</code>, the user is prompted to pick their own username. This is only used
  6287. during a user's first login. Once a localpart has been associated with a
  6288. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6289. <li><code>displayname</code>: An optional string, the display name for the user.</li>
  6290. </ul>
  6291. </li>
  6292. </ul>
  6293. </li>
  6294. <li><code>get_extra_attributes(self, userinfo, token)</code>
  6295. <ul>
  6296. <li>
  6297. <p>This method must be async.</p>
  6298. </li>
  6299. <li>
  6300. <p>Arguments:</p>
  6301. <ul>
  6302. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6303. information from.</li>
  6304. <li><code>token</code> - A dictionary which includes information necessary to make
  6305. further requests to the OpenID provider.</li>
  6306. </ul>
  6307. </li>
  6308. <li>
  6309. <p>Returns a dictionary that is suitable to be serialized to JSON. This
  6310. will be returned as part of the response during a successful login.</p>
  6311. <p>Note that care should be taken to not overwrite any of the parameters
  6312. 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>
  6313. </li>
  6314. </ul>
  6315. </li>
  6316. </ul>
  6317. <h3 id="default-openid-mapping-provider"><a class="header" href="#default-openid-mapping-provider">Default OpenID Mapping Provider</a></h3>
  6318. <p>Synapse has a built-in OpenID mapping provider if a custom provider isn't
  6319. specified in the config. It is located at
  6320. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/oidc.py"><code>synapse.handlers.oidc.JinjaOidcMappingProvider</code></a>.</p>
  6321. <h2 id="saml-mapping-providers"><a class="header" href="#saml-mapping-providers">SAML Mapping Providers</a></h2>
  6322. <p>The SAML mapping provider can be customized by editing the
  6323. <code>saml2_config.user_mapping_provider.module</code> config option.</p>
  6324. <p><code>saml2_config.user_mapping_provider.config</code> allows you to provide custom
  6325. configuration options to the module. Check with the module's documentation for
  6326. what options it provides (if any). The options listed by default are for the
  6327. user mapping provider built in to Synapse. If using a custom module, you should
  6328. comment these options out and use those specified by the module instead.</p>
  6329. <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>
  6330. <p>A custom mapping provider must specify the following methods:</p>
  6331. <ul>
  6332. <li><code>__init__(self, parsed_config, module_api)</code>
  6333. <ul>
  6334. <li>Arguments:
  6335. <ul>
  6336. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6337. <code>parse_config</code> method. You should set any configuration options needed by
  6338. the module here.</li>
  6339. <li><code>module_api</code> - a <code>synapse.module_api.ModuleApi</code> object which provides the
  6340. stable API available for extension modules.</li>
  6341. </ul>
  6342. </li>
  6343. </ul>
  6344. </li>
  6345. <li><code>parse_config(config)</code>
  6346. <ul>
  6347. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6348. <li>Arguments:
  6349. <ul>
  6350. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6351. <code>saml_config.user_mapping_provider.config</code> homeserver config option.
  6352. Runs on homeserver startup. Providers should extract and validate
  6353. any option values they need here.</li>
  6354. </ul>
  6355. </li>
  6356. <li>Whatever is returned will be passed back to the user mapping provider module's
  6357. <code>__init__</code> method during construction.</li>
  6358. </ul>
  6359. </li>
  6360. <li><code>get_saml_attributes(config)</code>
  6361. <ul>
  6362. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6363. <li>Arguments:
  6364. <ul>
  6365. <li><code>config</code> - A object resulting from a call to <code>parse_config</code>.</li>
  6366. </ul>
  6367. </li>
  6368. <li>Returns a tuple of two sets. The first set equates to the SAML auth
  6369. response attributes that are required for the module to function, whereas
  6370. the second set consists of those attributes which can be used if available,
  6371. but are not necessary.</li>
  6372. </ul>
  6373. </li>
  6374. <li><code>get_remote_user_id(self, saml_response, client_redirect_url)</code>
  6375. <ul>
  6376. <li>Arguments:
  6377. <ul>
  6378. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6379. information from.</li>
  6380. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6381. redirected to.</li>
  6382. </ul>
  6383. </li>
  6384. <li>This method must return a string, which is the unique, immutable identifier
  6385. for the user. Commonly the <code>uid</code> claim of the response.</li>
  6386. </ul>
  6387. </li>
  6388. <li><code>saml_response_to_user_attributes(self, saml_response, failures, client_redirect_url)</code>
  6389. <ul>
  6390. <li>
  6391. <p>Arguments:</p>
  6392. <ul>
  6393. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6394. information from.</li>
  6395. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6396. mxid localpart mapping has failed. This should be used
  6397. to create a deduplicated mxid localpart which should be
  6398. returned instead. For example, if this method returns
  6399. <code>john.doe</code> as the value of <code>mxid_localpart</code> in the returned
  6400. dict, and that is already taken on the homeserver, this
  6401. method will be called again with the same parameters but
  6402. with failures=1. The method should then return a different
  6403. <code>mxid_localpart</code> value, such as <code>john.doe1</code>.</li>
  6404. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6405. redirected to.</li>
  6406. </ul>
  6407. </li>
  6408. <li>
  6409. <p>This method must return a dictionary, which will then be used by Synapse
  6410. to build a new user. The following keys are allowed:</p>
  6411. <ul>
  6412. <li><code>mxid_localpart</code> - A string, the mxid localpart of the new user. If this is
  6413. <code>None</code>, the user is prompted to pick their own username. This is only used
  6414. during a user's first login. Once a localpart has been associated with a
  6415. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6416. <li><code>displayname</code> - The displayname of the new user. If not provided, will default to
  6417. the value of <code>mxid_localpart</code>.</li>
  6418. <li><code>emails</code> - A list of emails for the new user. If not provided, will
  6419. default to an empty list.</li>
  6420. </ul>
  6421. <p>Alternatively it can raise a <code>synapse.api.errors.RedirectException</code> to
  6422. redirect the user to another page. This is useful to prompt the user for
  6423. additional information, e.g. if you want them to provide their own username.
  6424. It is the responsibility of the mapping provider to either redirect back
  6425. to <code>client_redirect_url</code> (including any additional information) or to
  6426. complete registration using methods from the <code>ModuleApi</code>.</p>
  6427. </li>
  6428. </ul>
  6429. </li>
  6430. </ul>
  6431. <h3 id="default-saml-mapping-provider"><a class="header" href="#default-saml-mapping-provider">Default SAML Mapping Provider</a></h3>
  6432. <p>Synapse has a built-in SAML mapping provider if a custom provider isn't
  6433. specified in the config. It is located at
  6434. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/saml.py"><code>synapse.handlers.saml.DefaultSamlMappingProvider</code></a>.</p>
  6435. <div 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>
  6436. <p>Password auth providers offer a way for server administrators to
  6437. integrate their Synapse installation with an existing authentication
  6438. system.</p>
  6439. <p>A password auth provider is a Python class which is dynamically loaded
  6440. into Synapse, and provides a number of methods by which it can integrate
  6441. with the authentication system.</p>
  6442. <p>This document serves as a reference for those looking to implement their
  6443. own password auth providers. Additionally, here is a list of known
  6444. password auth provider module implementations:</p>
  6445. <ul>
  6446. <li><a href="https://github.com/matrix-org/matrix-synapse-ldap3/">matrix-synapse-ldap3</a></li>
  6447. <li><a href="https://github.com/devture/matrix-synapse-shared-secret-auth">matrix-synapse-shared-secret-auth</a></li>
  6448. <li><a href="https://github.com/ma1uta/matrix-synapse-rest-password-provider">matrix-synapse-rest-password-provider</a></li>
  6449. </ul>
  6450. <h2 id="required-methods"><a class="header" href="#required-methods">Required methods</a></h2>
  6451. <p>Password auth provider classes must provide the following methods:</p>
  6452. <ul>
  6453. <li>
  6454. <p><code>parse_config(config)</code>
  6455. This method is passed the <code>config</code> object for this module from the
  6456. homeserver configuration file.</p>
  6457. <p>It should perform any appropriate sanity checks on the provided
  6458. configuration, and return an object which is then passed into
  6459. <code>__init__</code>.</p>
  6460. <p>This method should have the <code>@staticmethod</code> decoration.</p>
  6461. </li>
  6462. <li>
  6463. <p><code>__init__(self, config, account_handler)</code></p>
  6464. <p>The constructor is passed the config object returned by
  6465. <code>parse_config</code>, and a <code>synapse.module_api.ModuleApi</code> object which
  6466. allows the password provider to check if accounts exist and/or create
  6467. new ones.</p>
  6468. </li>
  6469. </ul>
  6470. <h2 id="optional-methods"><a class="header" href="#optional-methods">Optional methods</a></h2>
  6471. <p>Password auth provider classes may optionally provide the following methods:</p>
  6472. <ul>
  6473. <li>
  6474. <p><code>get_db_schema_files(self)</code></p>
  6475. <p>This method, if implemented, should return an Iterable of
  6476. <code>(name, stream)</code> pairs of database schema files. Each file is applied
  6477. in turn at initialisation, and a record is then made in the database
  6478. so that it is not re-applied on the next start.</p>
  6479. </li>
  6480. <li>
  6481. <p><code>get_supported_login_types(self)</code></p>
  6482. <p>This method, if implemented, should return a <code>dict</code> mapping from a
  6483. login type identifier (such as <code>m.login.password</code>) to an iterable
  6484. giving the fields which must be provided by the user in the submission
  6485. to <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login">the <code>/login</code> API</a>.
  6486. These fields are passed in the <code>login_dict</code> dictionary to <code>check_auth</code>.</p>
  6487. <p>For example, if a password auth provider wants to implement a custom
  6488. login type of <code>com.example.custom_login</code>, where the client is expected
  6489. to pass the fields <code>secret1</code> and <code>secret2</code>, the provider should
  6490. implement this method and return the following dict:</p>
  6491. <pre><code class="language-python">{&quot;com.example.custom_login&quot;: (&quot;secret1&quot;, &quot;secret2&quot;)}
  6492. </code></pre>
  6493. </li>
  6494. <li>
  6495. <p><code>check_auth(self, username, login_type, login_dict)</code></p>
  6496. <p>This method does the real work. If implemented, it
  6497. will be called for each login attempt where the login type matches one
  6498. of the keys returned by <code>get_supported_login_types</code>.</p>
  6499. <p>It is passed the (possibly unqualified) <code>user</code> field provided by the client,
  6500. the login type, and a dictionary of login secrets passed by the
  6501. client.</p>
  6502. <p>The method should return an <code>Awaitable</code> object, which resolves
  6503. to the canonical <code>@localpart:domain</code> user ID if authentication is
  6504. successful, and <code>None</code> if not.</p>
  6505. <p>Alternatively, the <code>Awaitable</code> can resolve to a <code>(str, func)</code> tuple, in
  6506. which case the second field is a callback which will be called with
  6507. the result from the <code>/login</code> call (including <code>access_token</code>,
  6508. <code>device_id</code>, etc.)</p>
  6509. </li>
  6510. <li>
  6511. <p><code>check_3pid_auth(self, medium, address, password)</code></p>
  6512. <p>This method, if implemented, is called when a user attempts to
  6513. register or log in with a third party identifier, such as email. It is
  6514. passed the medium (ex. &quot;email&quot;), an address (ex.
  6515. &quot;<a href="mailto:jdoe@example.com">jdoe@example.com</a>&quot;) and the user's password.</p>
  6516. <p>The method should return an <code>Awaitable</code> object, which resolves
  6517. to a <code>str</code> containing the user's (canonical) User id if
  6518. authentication was successful, and <code>None</code> if not.</p>
  6519. <p>As with <code>check_auth</code>, the <code>Awaitable</code> may alternatively resolve to a
  6520. <code>(user_id, callback)</code> tuple.</p>
  6521. </li>
  6522. <li>
  6523. <p><code>check_password(self, user_id, password)</code></p>
  6524. <p>This method provides a simpler interface than
  6525. <code>get_supported_login_types</code> and <code>check_auth</code> for password auth
  6526. providers that just want to provide a mechanism for validating
  6527. <code>m.login.password</code> logins.</p>
  6528. <p>If implemented, it will be called to check logins with an
  6529. <code>m.login.password</code> login type. It is passed a qualified
  6530. <code>@localpart:domain</code> user id, and the password provided by the user.</p>
  6531. <p>The method should return an <code>Awaitable</code> object, which resolves
  6532. to <code>True</code> if authentication is successful, and <code>False</code> if not.</p>
  6533. </li>
  6534. <li>
  6535. <p><code>on_logged_out(self, user_id, device_id, access_token)</code></p>
  6536. <p>This method, if implemented, is called when a user logs out. It is
  6537. passed the qualified user ID, the ID of the deactivated device (if
  6538. any: access tokens are occasionally created without an associated
  6539. device ID), and the (now deactivated) access token.</p>
  6540. <p>It may return an <code>Awaitable</code> object; the logout request will
  6541. wait for the <code>Awaitable</code> to complete, but the result is ignored.</p>
  6542. </li>
  6543. </ul>
  6544. <div 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>
  6545. <p>Synapse comes with a non-standard login type to support
  6546. <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">JSON Web Tokens</a>. In general the
  6547. documentation for
  6548. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#login">the login endpoint</a>
  6549. is still valid (and the mechanism works similarly to the
  6550. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#token-based">token based login</a>).</p>
  6551. <p>To log in using a JSON Web Token, clients should submit a <code>/login</code> request as
  6552. follows:</p>
  6553. <pre><code class="language-json">{
  6554. &quot;type&quot;: &quot;org.matrix.login.jwt&quot;,
  6555. &quot;token&quot;: &quot;&lt;jwt&gt;&quot;
  6556. }
  6557. </code></pre>
  6558. <p>Note that the login type of <code>m.login.jwt</code> is supported, but is deprecated. This
  6559. will be removed in a future version of Synapse.</p>
  6560. <p>The <code>token</code> field should include the JSON web token with the following claims:</p>
  6561. <ul>
  6562. <li>The <code>sub</code> (subject) claim is required and should encode the local part of the
  6563. user ID.</li>
  6564. <li>The expiration time (<code>exp</code>), not before time (<code>nbf</code>), and issued at (<code>iat</code>)
  6565. claims are optional, but validated if present.</li>
  6566. <li>The issuer (<code>iss</code>) claim is optional, but required and validated if configured.</li>
  6567. <li>The audience (<code>aud</code>) claim is optional, but required and validated if configured.
  6568. Providing the audience claim when not configured will cause validation to fail.</li>
  6569. </ul>
  6570. <p>In the case that the token is not valid, the homeserver must respond with
  6571. <code>403 Forbidden</code> and an error code of <code>M_FORBIDDEN</code>.</p>
  6572. <p>As with other login types, there are additional fields (e.g. <code>device_id</code> and
  6573. <code>initial_device_display_name</code>) which can be included in the above request.</p>
  6574. <h2 id="preparing-synapse-1"><a class="header" href="#preparing-synapse-1">Preparing Synapse</a></h2>
  6575. <p>The JSON Web Token integration in Synapse uses the
  6576. <a href="https://pypi.org/project/pyjwt/"><code>PyJWT</code></a> library, which must be installed
  6577. as follows:</p>
  6578. <ul>
  6579. <li>
  6580. <p>The relevant libraries are included in the Docker images and Debian packages
  6581. provided by <code>matrix.org</code> so no further action is needed.</p>
  6582. </li>
  6583. <li>
  6584. <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>
  6585. </li>
  6586. <li>
  6587. <p>For other installation mechanisms, see the documentation provided by the
  6588. maintainer.</p>
  6589. </li>
  6590. </ul>
  6591. <p>To enable the JSON web token integration, you should then add an <code>jwt_config</code> section
  6592. to your configuration file (or uncomment the <code>enabled: true</code> line in the
  6593. existing section). See <a href="./sample_config.yaml">sample_config.yaml</a> for some
  6594. sample settings.</p>
  6595. <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>
  6596. <p>Although JSON Web Tokens are typically generated from an external server, the
  6597. examples below use <a href="https://pyjwt.readthedocs.io/en/latest/">PyJWT</a> directly.</p>
  6598. <ol>
  6599. <li>
  6600. <p>Configure Synapse with JWT logins, note that this example uses a pre-shared
  6601. secret and an algorithm of HS256:</p>
  6602. <pre><code class="language-yaml">jwt_config:
  6603. enabled: true
  6604. secret: &quot;my-secret-token&quot;
  6605. algorithm: &quot;HS256&quot;
  6606. </code></pre>
  6607. </li>
  6608. <li>
  6609. <p>Generate a JSON web token:</p>
  6610. <pre><code class="language-bash">$ pyjwt --key=my-secret-token --alg=HS256 encode sub=test-user
  6611. eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc
  6612. </code></pre>
  6613. </li>
  6614. <li>
  6615. <p>Query for the login types and ensure <code>org.matrix.login.jwt</code> is there:</p>
  6616. <pre><code class="language-bash">curl http://localhost:8080/_matrix/client/r0/login
  6617. </code></pre>
  6618. </li>
  6619. <li>
  6620. <p>Login used the generated JSON web token from above:</p>
  6621. <pre><code class="language-bash">$ curl http://localhost:8082/_matrix/client/r0/login -X POST \
  6622. --data '{&quot;type&quot;:&quot;org.matrix.login.jwt&quot;,&quot;token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc&quot;}'
  6623. {
  6624. &quot;access_token&quot;: &quot;&lt;access token&gt;&quot;,
  6625. &quot;device_id&quot;: &quot;ACBDEFGHI&quot;,
  6626. &quot;home_server&quot;: &quot;localhost:8080&quot;,
  6627. &quot;user_id&quot;: &quot;@test-user:localhost:8480&quot;
  6628. }
  6629. </code></pre>
  6630. </li>
  6631. </ol>
  6632. <p>You should now be able to use the returned access token to query the client API.</p>
  6633. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-2"><a class="header" href="#overview-2">Overview</a></h1>
  6634. <p>A captcha can be enabled on your homeserver to help prevent bots from registering
  6635. accounts. Synapse currently uses Google's reCAPTCHA service which requires API keys
  6636. from Google.</p>
  6637. <h2 id="getting-api-keys"><a class="header" href="#getting-api-keys">Getting API keys</a></h2>
  6638. <ol>
  6639. <li>Create a new site at <a href="https://www.google.com/recaptcha/admin/create">https://www.google.com/recaptcha/admin/create</a></li>
  6640. <li>Set the label to anything you want</li>
  6641. <li>Set the type to reCAPTCHA v2 using the &quot;I'm not a robot&quot; Checkbox option.
  6642. This is the only type of captcha that works with Synapse.</li>
  6643. <li>Add the public hostname for your server, as set in <code>public_baseurl</code>
  6644. in <code>homeserver.yaml</code>, to the list of authorized domains. If you have not set
  6645. <code>public_baseurl</code>, use <code>server_name</code>.</li>
  6646. <li>Agree to the terms of service and submit.</li>
  6647. <li>Copy your site key and secret key and add them to your <code>homeserver.yaml</code>
  6648. configuration file
  6649. <pre><code>recaptcha_public_key: YOUR_SITE_KEY
  6650. recaptcha_private_key: YOUR_SECRET_KEY
  6651. </code></pre>
  6652. </li>
  6653. <li>Enable the CAPTCHA for new registrations
  6654. <pre><code>enable_registration_captcha: true
  6655. </code></pre>
  6656. </li>
  6657. <li>Go to the settings page for the CAPTCHA you just created</li>
  6658. <li>Uncheck the &quot;Verify the origin of reCAPTCHA solutions&quot; checkbox so that the
  6659. captcha can be displayed in any client. If you do not disable this option then you
  6660. must specify the domains of every client that is allowed to display the CAPTCHA.</li>
  6661. </ol>
  6662. <h2 id="configuring-ip-used-for-auth"><a class="header" href="#configuring-ip-used-for-auth">Configuring IP used for auth</a></h2>
  6663. <p>The reCAPTCHA API requires that the IP address of the user who solved the
  6664. CAPTCHA is sent. If the client is connecting through a proxy or load balancer,
  6665. it may be required to use the <code>X-Forwarded-For</code> (XFF) header instead of the origin
  6666. IP address. This can be configured using the <code>x_forwarded</code> directive in the
  6667. listeners section of the <code>homeserver.yaml</code> configuration file.</p>
  6668. <div 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>
  6669. <p>The registration of new application services depends on the homeserver used.
  6670. In synapse, you need to create a new configuration file for your AS and add it
  6671. to the list specified under the <code>app_service_config_files</code> config
  6672. option in your synapse config.</p>
  6673. <p>For example:</p>
  6674. <pre><code class="language-yaml">app_service_config_files:
  6675. - /home/matrix/.synapse/&lt;your-AS&gt;.yaml
  6676. </code></pre>
  6677. <p>The format of the AS configuration file is as follows:</p>
  6678. <pre><code class="language-yaml">url: &lt;base url of AS&gt;
  6679. as_token: &lt;token AS will add to requests to HS&gt;
  6680. hs_token: &lt;token HS will add to requests to AS&gt;
  6681. sender_localpart: &lt;localpart of AS user&gt;
  6682. namespaces:
  6683. users: # List of users we're interested in
  6684. - exclusive: &lt;bool&gt;
  6685. regex: &lt;regex&gt;
  6686. group_id: &lt;group&gt;
  6687. - ...
  6688. aliases: [] # List of aliases we're interested in
  6689. rooms: [] # List of room ids we're interested in
  6690. </code></pre>
  6691. <p><code>exclusive</code>: If enabled, only this application service is allowed to register users in its namespace(s).
  6692. <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>
  6693. <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>
  6694. <div style="break-before: page; page-break-before: always;"></div><h1 id="server-notices"><a class="header" href="#server-notices">Server Notices</a></h1>
  6695. <p>'Server Notices' are a new feature introduced in Synapse 0.30. They provide a
  6696. channel whereby server administrators can send messages to users on the server.</p>
  6697. <p>They are used as part of communication of the server polices (see
  6698. <a href="consent_tracking.html">Consent Tracking</a>), however the intention is that
  6699. they may also find a use for features such as &quot;Message of the day&quot;.</p>
  6700. <p>This is a feature specific to Synapse, but it uses standard Matrix
  6701. communication mechanisms, so should work with any Matrix client.</p>
  6702. <h2 id="user-experience"><a class="header" href="#user-experience">User experience</a></h2>
  6703. <p>When the user is first sent a server notice, they will get an invitation to a
  6704. room (typically called 'Server Notices', though this is configurable in
  6705. <code>homeserver.yaml</code>). They will be <strong>unable to reject</strong> this invitation -
  6706. attempts to do so will receive an error.</p>
  6707. <p>Once they accept the invitation, they will see the notice message in the room
  6708. history; it will appear to have come from the 'server notices user' (see
  6709. below).</p>
  6710. <p>The user is prevented from sending any messages in this room by the power
  6711. levels.</p>
  6712. <p>Having joined the room, the user can leave the room if they want. Subsequent
  6713. server notices will then cause a new room to be created.</p>
  6714. <h2 id="synapse-configuration"><a class="header" href="#synapse-configuration">Synapse configuration</a></h2>
  6715. <p>Server notices come from a specific user id on the server. Server
  6716. administrators are free to choose the user id - something like <code>server</code> is
  6717. suggested, meaning the notices will come from
  6718. <code>@server:&lt;your_server_name&gt;</code>. Once the Server Notices user is configured, that
  6719. user id becomes a special, privileged user, so administrators should ensure
  6720. that <strong>it is not already allocated</strong>.</p>
  6721. <p>In order to support server notices, it is necessary to add some configuration
  6722. to the <code>homeserver.yaml</code> file. In particular, you should add a <code>server_notices</code>
  6723. section, which should look like this:</p>
  6724. <pre><code class="language-yaml">server_notices:
  6725. system_mxid_localpart: server
  6726. system_mxid_display_name: &quot;Server Notices&quot;
  6727. system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  6728. room_name: &quot;Server Notices&quot;
  6729. </code></pre>
  6730. <p>The only compulsory setting is <code>system_mxid_localpart</code>, which defines the user
  6731. id of the Server Notices user, as above. <code>room_name</code> defines the name of the
  6732. room which will be created.</p>
  6733. <p><code>system_mxid_display_name</code> and <code>system_mxid_avatar_url</code> can be used to set the
  6734. displayname and avatar of the Server Notices user.</p>
  6735. <h2 id="sending-notices"><a class="header" href="#sending-notices">Sending notices</a></h2>
  6736. <p>To send server notices to users you can use the
  6737. <a href="admin_api/server_notices.html">admin_api</a>.</p>
  6738. <div 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>
  6739. <p>Synapse 0.30 introduces support for tracking whether users have agreed to the
  6740. terms and conditions set by the administrator of a server - and blocking access
  6741. to the server until they have.</p>
  6742. <p>There are several parts to this functionality; each requires some specific
  6743. configuration in <code>homeserver.yaml</code> to be enabled.</p>
  6744. <p>Note that various parts of the configuation and this document refer to the
  6745. &quot;privacy policy&quot;: agreement with a privacy policy is one particular use of this
  6746. feature, but of course adminstrators can specify other terms and conditions
  6747. unrelated to &quot;privacy&quot; per se.</p>
  6748. <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>
  6749. <p>Synapse can be configured to serve the user a simple policy form with an
  6750. &quot;accept&quot; button. Clicking &quot;Accept&quot; records the user's acceptance in the
  6751. database and shows a success page.</p>
  6752. <p>To enable this, first create templates for the policy and success pages.
  6753. These should be stored on the local filesystem.</p>
  6754. <p>These templates use the <a href="http://jinja.pocoo.org">Jinja2</a> templating language,
  6755. and <a href="https://github.com/matrix-org/synapse/tree/develop/docs/privacy_policy_templates/">docs/privacy_policy_templates</a>
  6756. gives examples of the sort of thing that can be done.</p>
  6757. <p>Note that the templates must be stored under a name giving the language of the
  6758. template - currently this must always be <code>en</code> (for &quot;English&quot;);
  6759. internationalisation support is intended for the future.</p>
  6760. <p>The template for the policy itself should be versioned and named according to
  6761. the version: for example <code>1.0.html</code>. The version of the policy which the user
  6762. has agreed to is stored in the database.</p>
  6763. <p>Once the templates are in place, make the following changes to <code>homeserver.yaml</code>:</p>
  6764. <ol>
  6765. <li>
  6766. <p>Add a <code>user_consent</code> section, which should look like:</p>
  6767. <pre><code class="language-yaml">user_consent:
  6768. template_dir: privacy_policy_templates
  6769. version: 1.0
  6770. </code></pre>
  6771. <p><code>template_dir</code> points to the directory containing the policy
  6772. templates. <code>version</code> defines the version of the policy which will be served
  6773. to the user. In the example above, Synapse will serve
  6774. <code>privacy_policy_templates/en/1.0.html</code>.</p>
  6775. </li>
  6776. <li>
  6777. <p>Add a <code>form_secret</code> setting at the top level:</p>
  6778. <pre><code class="language-yaml">form_secret: &quot;&lt;unique secret&gt;&quot;
  6779. </code></pre>
  6780. <p>This should be set to an arbitrary secret string (try <code>pwgen -y 30</code> to
  6781. generate suitable secrets).</p>
  6782. <p>More on what this is used for below.</p>
  6783. </li>
  6784. <li>
  6785. <p>Add <code>consent</code> wherever the <code>client</code> resource is currently enabled in the
  6786. <code>listeners</code> configuration. For example:</p>
  6787. <pre><code class="language-yaml">listeners:
  6788. - port: 8008
  6789. resources:
  6790. - names:
  6791. - client
  6792. - consent
  6793. </code></pre>
  6794. </li>
  6795. </ol>
  6796. <p>Finally, ensure that <code>jinja2</code> is installed. If you are using a virtualenv, this
  6797. should be a matter of <code>pip install Jinja2</code>. On debian, try <code>apt-get install python-jinja2</code>.</p>
  6798. <p>Once this is complete, and the server has been restarted, try visiting
  6799. <code>https://&lt;server&gt;/_matrix/consent</code>. If correctly configured, this should give
  6800. an error &quot;Missing string query parameter 'u'&quot;. It is now possible to manually
  6801. construct URIs where users can give their consent.</p>
  6802. <h3 id="enabling-consent-tracking-at-registration"><a class="header" href="#enabling-consent-tracking-at-registration">Enabling consent tracking at registration</a></h3>
  6803. <ol>
  6804. <li>
  6805. <p>Add the following to your configuration:</p>
  6806. <pre><code class="language-yaml">user_consent:
  6807. require_at_registration: true
  6808. policy_name: &quot;Privacy Policy&quot; # or whatever you'd like to call the policy
  6809. </code></pre>
  6810. </li>
  6811. <li>
  6812. <p>In your consent templates, make use of the <code>public_version</code> variable to
  6813. see if an unauthenticated user is viewing the page. This is typically
  6814. wrapped around the form that would be used to actually agree to the document:</p>
  6815. <pre><code>{% if not public_version %}
  6816. &lt;!-- The variables used here are only provided when the 'u' param is given to the homeserver --&gt;
  6817. &lt;form method=&quot;post&quot; action=&quot;consent&quot;&gt;
  6818. &lt;input type=&quot;hidden&quot; name=&quot;v&quot; value=&quot;{{version}}&quot;/&gt;
  6819. &lt;input type=&quot;hidden&quot; name=&quot;u&quot; value=&quot;{{user}}&quot;/&gt;
  6820. &lt;input type=&quot;hidden&quot; name=&quot;h&quot; value=&quot;{{userhmac}}&quot;/&gt;
  6821. &lt;input type=&quot;submit&quot; value=&quot;Sure thing!&quot;/&gt;
  6822. &lt;/form&gt;
  6823. {% endif %}
  6824. </code></pre>
  6825. </li>
  6826. <li>
  6827. <p>Restart Synapse to apply the changes.</p>
  6828. </li>
  6829. </ol>
  6830. <p>Visiting <code>https://&lt;server&gt;/_matrix/consent</code> should now give you a view of the privacy
  6831. document. This is what users will be able to see when registering for accounts.</p>
  6832. <h3 id="constructing-the-consent-uri"><a class="header" href="#constructing-the-consent-uri">Constructing the consent URI</a></h3>
  6833. <p>It may be useful to manually construct the &quot;consent URI&quot; for a given user - for
  6834. instance, in order to send them an email asking them to consent. To do this,
  6835. take the base <code>https://&lt;server&gt;/_matrix/consent</code> URL and add the following
  6836. query parameters:</p>
  6837. <ul>
  6838. <li>
  6839. <p><code>u</code>: the user id of the user. This can either be a full MXID
  6840. (<code>@user:server.com</code>) or just the localpart (<code>user</code>).</p>
  6841. </li>
  6842. <li>
  6843. <p><code>h</code>: hex-encoded HMAC-SHA256 of <code>u</code> using the <code>form_secret</code> as a key. It is
  6844. possible to calculate this on the commandline with something like:</p>
  6845. <pre><code class="language-bash">echo -n '&lt;user&gt;' | openssl sha256 -hmac '&lt;form_secret&gt;'
  6846. </code></pre>
  6847. <p>This should result in a URI which looks something like:
  6848. <code>https://&lt;server&gt;/_matrix/consent?u=&lt;user&gt;&amp;h=68a152465a4d...</code>.</p>
  6849. </li>
  6850. </ul>
  6851. <p>Note that not providing a <code>u</code> parameter will be interpreted as wanting to view
  6852. the document from an unauthenticated perspective, such as prior to registration.
  6853. Therefore, the <code>h</code> parameter is not required in this scenario. To enable this
  6854. behaviour, set <code>require_at_registration</code> to <code>true</code> in your <code>user_consent</code> config.</p>
  6855. <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>
  6856. <p>It is possible to configure Synapse to send a <a href="server_notices.html">server
  6857. notice</a> to anybody who has not yet agreed to the current
  6858. version of the policy. To do so:</p>
  6859. <ul>
  6860. <li>
  6861. <p>ensure that the consent resource is configured, as in the previous section</p>
  6862. </li>
  6863. <li>
  6864. <p>ensure that server notices are configured, as in <a href="server_notices.html">the server notice documentation</a>.</p>
  6865. </li>
  6866. <li>
  6867. <p>Add <code>server_notice_content</code> under <code>user_consent</code> in <code>homeserver.yaml</code>. For
  6868. example:</p>
  6869. <pre><code class="language-yaml">user_consent:
  6870. server_notice_content:
  6871. msgtype: m.text
  6872. body: &gt;-
  6873. Please give your consent to the privacy policy at %(consent_uri)s.
  6874. </code></pre>
  6875. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6876. consent uri for that user.</p>
  6877. </li>
  6878. <li>
  6879. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6880. URI that clients use to connect to the server. (It is used to construct
  6881. <code>consent_uri</code> in the server notice.)</p>
  6882. </li>
  6883. </ul>
  6884. <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>
  6885. <p>Synapse can be configured to block any attempts to join rooms or send messages
  6886. until the user has given their agreement to the policy. (Joining the server
  6887. notices room is exempted from this).</p>
  6888. <p>To enable this, add <code>block_events_error</code> under <code>user_consent</code>. For example:</p>
  6889. <pre><code class="language-yaml">user_consent:
  6890. block_events_error: &gt;-
  6891. You can't send any messages until you consent to the privacy policy at
  6892. %(consent_uri)s.
  6893. </code></pre>
  6894. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6895. consent uri for that user.</p>
  6896. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6897. URI that clients use to connect to the server. (It is used to construct
  6898. <code>consent_uri</code> in the error.)</p>
  6899. <div 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>
  6900. <p>The <code>GET /_matrix/media/r0/preview_url</code> endpoint provides a generic preview API
  6901. for URLs which outputs <a href="https://ogp.me/">Open Graph</a> responses (with some Matrix
  6902. specific additions).</p>
  6903. <p>This does have trade-offs compared to other designs:</p>
  6904. <ul>
  6905. <li>Pros:
  6906. <ul>
  6907. <li>Simple and flexible; can be used by any clients at any point</li>
  6908. </ul>
  6909. </li>
  6910. <li>Cons:
  6911. <ul>
  6912. <li>If each homeserver provides one of these independently, all the HSes in a
  6913. room may needlessly DoS the target URI</li>
  6914. <li>The URL metadata must be stored somewhere, rather than just using Matrix
  6915. itself to store the media.</li>
  6916. <li>Matrix cannot be used to distribute the metadata between homeservers.</li>
  6917. </ul>
  6918. </li>
  6919. </ul>
  6920. <p>When Synapse is asked to preview a URL it does the following:</p>
  6921. <ol>
  6922. <li>Checks against a URL blacklist (defined as <code>url_preview_url_blacklist</code> in the
  6923. config).</li>
  6924. <li>Checks the in-memory cache by URLs and returns the result if it exists. (This
  6925. is also used to de-duplicate processing of multiple in-flight requests at once.)</li>
  6926. <li>Kicks off a background process to generate a preview:
  6927. <ol>
  6928. <li>Checks the database cache by URL and timestamp and returns the result if it
  6929. has not expired and was successful (a 2xx return code).</li>
  6930. <li>Checks if the URL matches an <a href="https://oembed.com/">oEmbed</a> pattern. If it
  6931. does, update the URL to download.</li>
  6932. <li>Downloads the URL and stores it into a file via the media storage provider
  6933. and saves the local media metadata.</li>
  6934. <li>If the media is an image:
  6935. <ol>
  6936. <li>Generates thumbnails.</li>
  6937. <li>Generates an Open Graph response based on image properties.</li>
  6938. </ol>
  6939. </li>
  6940. <li>If the media is HTML:
  6941. <ol>
  6942. <li>Decodes the HTML via the stored file.</li>
  6943. <li>Generates an Open Graph response from the HTML.</li>
  6944. <li>If an image exists in the Open Graph response:
  6945. <ol>
  6946. <li>Downloads the URL and stores it into a file via the media storage
  6947. provider and saves the local media metadata.</li>
  6948. <li>Generates thumbnails.</li>
  6949. <li>Updates the Open Graph response based on image properties.</li>
  6950. </ol>
  6951. </li>
  6952. </ol>
  6953. </li>
  6954. <li>If the media is JSON and an oEmbed URL was found:
  6955. <ol>
  6956. <li>Convert the oEmbed response to an Open Graph response.</li>
  6957. <li>If a thumbnail or image is in the oEmbed response:
  6958. <ol>
  6959. <li>Downloads the URL and stores it into a file via the media storage
  6960. provider and saves the local media metadata.</li>
  6961. <li>Generates thumbnails.</li>
  6962. <li>Updates the Open Graph response based on image properties.</li>
  6963. </ol>
  6964. </li>
  6965. </ol>
  6966. </li>
  6967. <li>Stores the result in the database cache.</li>
  6968. </ol>
  6969. </li>
  6970. <li>Returns the result.</li>
  6971. </ol>
  6972. <p>The in-memory cache expires after 1 hour.</p>
  6973. <p>Expired entries in the database cache (and their associated media files) are
  6974. deleted every 10 seconds. The default expiration time is 1 hour from download.</p>
  6975. <div 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>
  6976. <p>The user directory is currently maintained based on the 'visible' users
  6977. on this particular server - i.e. ones which your account shares a room with, or
  6978. who are present in a publicly viewable room present on the server.</p>
  6979. <p>The directory info is stored in various tables, which can (typically after
  6980. DB corruption) get stale or out of sync. If this happens, for now the
  6981. 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>
  6982. and then restart synapse. This should then start a background task to
  6983. flush the current tables and regenerate the directory.</p>
  6984. <h2 id="data-model"><a class="header" href="#data-model">Data model</a></h2>
  6985. <p>There are five relevant tables that collectively form the &quot;user directory&quot;.
  6986. Three of them track a master list of all the users we could search for.
  6987. The last two (collectively called the &quot;search tables&quot;) track who can
  6988. see who.</p>
  6989. <p>From all of these tables we exclude three types of local user:</p>
  6990. <ul>
  6991. <li>support users</li>
  6992. <li>appservice users</li>
  6993. <li>deactivated users</li>
  6994. </ul>
  6995. <ul>
  6996. <li>
  6997. <p><code>user_directory</code>. This contains the user_id, display name and avatar we'll
  6998. return when you search the directory.</p>
  6999. <ul>
  7000. <li>Because there's only one directory entry per user, it's important that we only
  7001. ever put publicly visible names here. Otherwise we might leak a private
  7002. nickname or avatar used in a private room.</li>
  7003. <li>Indexed on rooms. Indexed on users.</li>
  7004. </ul>
  7005. </li>
  7006. <li>
  7007. <p><code>user_directory_search</code>. To be joined to <code>user_directory</code>. It contains an extra
  7008. column that enables full text search based on user ids and display names.
  7009. Different schemas for SQLite and Postgres with different code paths to match.</p>
  7010. <ul>
  7011. <li>Indexed on the full text search data. Indexed on users.</li>
  7012. </ul>
  7013. </li>
  7014. <li>
  7015. <p><code>user_directory_stream_pos</code>. When the initial background update to populate
  7016. the directory is complete, we record a stream position here. This indicates
  7017. that synapse should now listen for room changes and incrementally update
  7018. the directory where necessary.</p>
  7019. </li>
  7020. <li>
  7021. <p><code>users_in_public_rooms</code>. Contains associations between users and the public rooms they're in.
  7022. Used to determine which users are in public rooms and should be publicly visible in the directory.</p>
  7023. </li>
  7024. <li>
  7025. <p><code>users_who_share_private_rooms</code>. Rows are triples <code>(L, M, room id)</code> where <code>L</code>
  7026. is a local user and <code>M</code> is a local or remote user. <code>L</code> and <code>M</code> should be
  7027. different, but this isn't enforced by a constraint.</p>
  7028. </li>
  7029. </ul>
  7030. <div 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>
  7031. <p>Synapse admins can enable support for message retention policies on
  7032. their homeserver. Message retention policies exist at a room level,
  7033. follow the semantics described in
  7034. <a href="https://github.com/matrix-org/matrix-doc/blob/matthew/msc1763/proposals/1763-configurable-retention-periods.md">MSC1763</a>,
  7035. and allow server and room admins to configure how long messages should
  7036. be kept in a homeserver's database before being purged from it.
  7037. <strong>Please note that, as this feature isn't part of the Matrix
  7038. specification yet, this implementation is to be considered as
  7039. experimental.</strong> </p>
  7040. <p>A message retention policy is mainly defined by its <code>max_lifetime</code>
  7041. parameter, which defines how long a message can be kept around after
  7042. it was sent to the room. If a room doesn't have a message retention
  7043. policy, and there's no default one for a given server, then no message
  7044. sent in that room is ever purged on that server.</p>
  7045. <p>MSC1763 also specifies semantics for a <code>min_lifetime</code> parameter which
  7046. defines the amount of time after which an event <em>can</em> get purged (after
  7047. it was sent to the room), but Synapse doesn't currently support it
  7048. beyond registering it.</p>
  7049. <p>Both <code>max_lifetime</code> and <code>min_lifetime</code> are optional parameters.</p>
  7050. <p>Note that message retention policies don't apply to state events.</p>
  7051. <p>Once an event reaches its expiry date (defined as the time it was sent
  7052. plus the value for <code>max_lifetime</code> in the room), two things happen:</p>
  7053. <ul>
  7054. <li>Synapse stops serving the event to clients via any endpoint.</li>
  7055. <li>The message gets picked up by the next purge job (see the &quot;Purge jobs&quot;
  7056. section) and is removed from Synapse's database.</li>
  7057. </ul>
  7058. <p>Since purge jobs don't run continuously, this means that an event might
  7059. stay in a server's database for longer than the value for <code>max_lifetime</code>
  7060. in the room would allow, though hidden from clients.</p>
  7061. <p>Similarly, if a server (with support for message retention policies
  7062. enabled) receives from another server an event that should have been
  7063. purged according to its room's policy, then the receiving server will
  7064. process and store that event until it's picked up by the next purge job,
  7065. though it will always hide it from clients.</p>
  7066. <p>Synapse requires at least one message in each room, so it will never
  7067. delete the last message in a room. It will, however, hide it from
  7068. clients.</p>
  7069. <h2 id="server-configuration"><a class="header" href="#server-configuration">Server configuration</a></h2>
  7070. <p>Support for this feature can be enabled and configured in the
  7071. <code>retention</code> section of the Synapse configuration file (see the
  7072. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample file</a>).</p>
  7073. <p>To enable support for message retention policies, set the setting
  7074. <code>enabled</code> in this section to <code>true</code>.</p>
  7075. <h3 id="default-policy"><a class="header" href="#default-policy">Default policy</a></h3>
  7076. <p>A default message retention policy is a policy defined in Synapse's
  7077. configuration that is used by Synapse for every room that doesn't have a
  7078. message retention policy configured in its state. This allows server
  7079. admins to ensure that messages are never kept indefinitely in a server's
  7080. database. </p>
  7081. <p>A default policy can be defined as such, in the <code>retention</code> section of
  7082. the configuration file:</p>
  7083. <pre><code class="language-yaml"> default_policy:
  7084. min_lifetime: 1d
  7085. max_lifetime: 1y
  7086. </code></pre>
  7087. <p>Here, <code>min_lifetime</code> and <code>max_lifetime</code> have the same meaning and level
  7088. of support as previously described. They can be expressed either as a
  7089. duration (using the units <code>s</code> (seconds), <code>m</code> (minutes), <code>h</code> (hours),
  7090. <code>d</code> (days), <code>w</code> (weeks) and <code>y</code> (years)) or as a number of milliseconds.</p>
  7091. <h3 id="purge-jobs"><a class="header" href="#purge-jobs">Purge jobs</a></h3>
  7092. <p>Purge jobs are the jobs that Synapse runs in the background to purge
  7093. expired events from the database. They are only run if support for
  7094. message retention policies is enabled in the server's configuration. If
  7095. no configuration for purge jobs is configured by the server admin,
  7096. Synapse will use a default configuration, which is described in the
  7097. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample configuration file</a>.</p>
  7098. <p>Some server admins might want a finer control on when events are removed
  7099. depending on an event's room's policy. This can be done by setting the
  7100. <code>purge_jobs</code> sub-section in the <code>retention</code> section of the configuration
  7101. file. An example of such configuration could be:</p>
  7102. <pre><code class="language-yaml"> purge_jobs:
  7103. - longest_max_lifetime: 3d
  7104. interval: 12h
  7105. - shortest_max_lifetime: 3d
  7106. longest_max_lifetime: 1w
  7107. interval: 1d
  7108. - shortest_max_lifetime: 1w
  7109. interval: 2d
  7110. </code></pre>
  7111. <p>In this example, we define three jobs:</p>
  7112. <ul>
  7113. <li>one that runs twice a day (every 12 hours) and purges events in rooms
  7114. which policy's <code>max_lifetime</code> is lower or equal to 3 days.</li>
  7115. <li>one that runs once a day and purges events in rooms which policy's
  7116. <code>max_lifetime</code> is between 3 days and a week.</li>
  7117. <li>one that runs once every 2 days and purges events in rooms which
  7118. policy's <code>max_lifetime</code> is greater than a week.</li>
  7119. </ul>
  7120. <p>Note that this example is tailored to show different configurations and
  7121. features slightly more jobs than it's probably necessary (in practice, a
  7122. server admin would probably consider it better to replace the two last
  7123. jobs with one that runs once a day and handles rooms which which
  7124. policy's <code>max_lifetime</code> is greater than 3 days).</p>
  7125. <p>Keep in mind, when configuring these jobs, that a purge job can become
  7126. quite heavy on the server if it targets many rooms, therefore prefer
  7127. having jobs with a low interval that target a limited set of rooms. Also
  7128. make sure to include a job with no minimum and one with no maximum to
  7129. make sure your configuration handles every policy.</p>
  7130. <p>As previously mentioned in this documentation, while a purge job that
  7131. runs e.g. every day means that an expired event might stay in the
  7132. database for up to a day after its expiry, Synapse hides expired events
  7133. from clients as soon as they expire, so the event is not visible to
  7134. local users between its expiry date and the moment it gets purged from
  7135. the server's database.</p>
  7136. <h3 id="lifetime-limits"><a class="header" href="#lifetime-limits">Lifetime limits</a></h3>
  7137. <p>Server admins can set limits on the values of <code>max_lifetime</code> to use when
  7138. purging old events in a room. These limits can be defined as such in the
  7139. <code>retention</code> section of the configuration file:</p>
  7140. <pre><code class="language-yaml"> allowed_lifetime_min: 1d
  7141. allowed_lifetime_max: 1y
  7142. </code></pre>
  7143. <p>The limits are considered when running purge jobs. If necessary, the
  7144. effective value of <code>max_lifetime</code> will be brought between
  7145. <code>allowed_lifetime_min</code> and <code>allowed_lifetime_max</code> (inclusive).
  7146. This means that, if the value of <code>max_lifetime</code> defined in the room's state
  7147. is lower than <code>allowed_lifetime_min</code>, the value of <code>allowed_lifetime_min</code>
  7148. will be used instead. Likewise, if the value of <code>max_lifetime</code> is higher
  7149. than <code>allowed_lifetime_max</code>, the value of <code>allowed_lifetime_max</code> will be
  7150. used instead.</p>
  7151. <p>In the example above, we ensure Synapse never deletes events that are less
  7152. than one day old, and that it always deletes events that are over a year
  7153. old.</p>
  7154. <p>If a default policy is set, and its <code>max_lifetime</code> value is lower than
  7155. <code>allowed_lifetime_min</code> or higher than <code>allowed_lifetime_max</code>, the same
  7156. process applies.</p>
  7157. <p>Both parameters are optional; if one is omitted Synapse won't use it to
  7158. adjust the effective value of <code>max_lifetime</code>.</p>
  7159. <p>Like other settings in this section, these parameters can be expressed
  7160. either as a duration or as a number of milliseconds.</p>
  7161. <h2 id="room-configuration"><a class="header" href="#room-configuration">Room configuration</a></h2>
  7162. <p>To configure a room's message retention policy, a room's admin or
  7163. moderator needs to send a state event in that room with the type
  7164. <code>m.room.retention</code> and the following content:</p>
  7165. <pre><code class="language-json">{
  7166. &quot;max_lifetime&quot;: ...
  7167. }
  7168. </code></pre>
  7169. <p>In this event's content, the <code>max_lifetime</code> parameter has the same
  7170. meaning as previously described, and needs to be expressed in
  7171. milliseconds. The event's content can also include a <code>min_lifetime</code>
  7172. parameter, which has the same meaning and limited support as previously
  7173. described.</p>
  7174. <p>Note that over every server in the room, only the ones with support for
  7175. message retention policies will actually remove expired events. This
  7176. support is currently not enabled by default in Synapse.</p>
  7177. <h2 id="note-on-reclaiming-disk-space"><a class="header" href="#note-on-reclaiming-disk-space">Note on reclaiming disk space</a></h2>
  7178. <p>While purge jobs actually delete data from the database, the disk space
  7179. used by the database might not decrease immediately on the database's
  7180. host. However, even though the database engine won't free up the disk
  7181. space, it will start writing new data into where the purged data was.</p>
  7182. <p>If you want to reclaim the freed disk space anyway and return it to the
  7183. operating system, the server admin needs to run <code>VACUUM FULL;</code> (or
  7184. <code>VACUUM;</code> for SQLite databases) on Synapse's database (see the related
  7185. <a href="https://www.postgresql.org/docs/current/sql-vacuum.html">PostgreSQL documentation</a>).</p>
  7186. <div style="break-before: page; page-break-before: always;"></div><h1 id="modules"><a class="header" href="#modules">Modules</a></h1>
  7187. <p>Synapse supports extending its functionality by configuring external modules.</p>
  7188. <h2 id="using-modules"><a class="header" href="#using-modules">Using modules</a></h2>
  7189. <p>To use a module on Synapse, add it to the <code>modules</code> section of the configuration file:</p>
  7190. <pre><code class="language-yaml">modules:
  7191. - module: my_super_module.MySuperClass
  7192. config:
  7193. do_thing: true
  7194. - module: my_other_super_module.SomeClass
  7195. config: {}
  7196. </code></pre>
  7197. <p>Each module is defined by a path to a Python class as well as a configuration. This
  7198. information for a given module should be available in the module's own documentation.</p>
  7199. <p><strong>Note</strong>: When using third-party modules, you effectively allow someone else to run
  7200. custom code on your Synapse homeserver. Server admins are encouraged to verify the
  7201. provenance of the modules they use on their homeserver and make sure the modules aren't
  7202. running malicious code on their instance.</p>
  7203. <p>Also note that we are currently in the process of migrating module interfaces to this
  7204. system. While some interfaces might be compatible with it, others still require
  7205. configuring modules in another part of Synapse's configuration file.</p>
  7206. <p>Currently, only the following pre-existing interfaces are compatible with this new system:</p>
  7207. <ul>
  7208. <li>spam checker</li>
  7209. <li>third-party rules</li>
  7210. <li>presence router</li>
  7211. </ul>
  7212. <div style="break-before: page; page-break-before: always;"></div><h1 id="writing-a-module"><a class="header" href="#writing-a-module">Writing a module</a></h1>
  7213. <p>A module is a Python class that uses Synapse's module API to interact with the
  7214. homeserver. It can register callbacks that Synapse will call on specific operations, as
  7215. well as web resources to attach to Synapse's web server.</p>
  7216. <p>When instantiated, a module is given its parsed configuration as well as an instance of
  7217. the <code>synapse.module_api.ModuleApi</code> class. The configuration is a dictionary, and is
  7218. either the output of the module's <code>parse_config</code> static method (see below), or the
  7219. configuration associated with the module in Synapse's configuration file.</p>
  7220. <p>See the documentation for the <code>ModuleApi</code> class
  7221. <a href="https://github.com/matrix-org/synapse/blob/master/synapse/module_api/__init__.py">here</a>.</p>
  7222. <h2 id="handling-the-modules-configuration"><a class="header" href="#handling-the-modules-configuration">Handling the module's configuration</a></h2>
  7223. <p>A module can implement the following static method:</p>
  7224. <pre><code class="language-python">@staticmethod
  7225. def parse_config(config: dict) -&gt; dict
  7226. </code></pre>
  7227. <p>This method is given a dictionary resulting from parsing the YAML configuration for the
  7228. module. It may modify it (for example by parsing durations expressed as strings (e.g.
  7229. &quot;5d&quot;) into milliseconds, etc.), and return the modified dictionary. It may also verify
  7230. that the configuration is correct, and raise an instance of
  7231. <code>synapse.module_api.errors.ConfigError</code> if not.</p>
  7232. <h2 id="registering-a-web-resource"><a class="header" href="#registering-a-web-resource">Registering a web resource</a></h2>
  7233. <p>Modules can register web resources onto Synapse's web server using the following module
  7234. API method:</p>
  7235. <pre><code class="language-python">def ModuleApi.register_web_resource(path: str, resource: IResource) -&gt; None
  7236. </code></pre>
  7237. <p>The path is the full absolute path to register the resource at. For example, if you
  7238. register a resource for the path <code>/_synapse/client/my_super_module/say_hello</code>, Synapse
  7239. will serve it at <code>http(s)://[HS_URL]/_synapse/client/my_super_module/say_hello</code>. Note
  7240. that Synapse does not allow registering resources for several sub-paths in the <code>/_matrix</code>
  7241. namespace (such as anything under <code>/_matrix/client</code> for example). It is strongly
  7242. recommended that modules register their web resources under the <code>/_synapse/client</code>
  7243. namespace.</p>
  7244. <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>
  7245. interface (such as <a href="https://twistedmatrix.com/documents/current/api/twisted.web.resource.Resource.html">Resource</a>).</p>
  7246. <p>Only one resource can be registered for a given path. If several modules attempt to
  7247. register a resource for the same path, the module that appears first in Synapse's
  7248. configuration file takes priority.</p>
  7249. <p>Modules <strong>must</strong> register their web resources in their <code>__init__</code> method.</p>
  7250. <h2 id="registering-a-callback"><a class="header" href="#registering-a-callback">Registering a callback</a></h2>
  7251. <p>Modules can use Synapse's module API to register callbacks. Callbacks are functions that
  7252. Synapse will call when performing specific actions. Callbacks must be asynchronous, and
  7253. are split in categories. A single module may implement callbacks from multiple categories,
  7254. and is under no obligation to implement all callbacks from the categories it registers
  7255. callbacks for.</p>
  7256. <p>Modules can register callbacks using one of the module API's <code>register_[...]_callbacks</code>
  7257. methods. The callback functions are passed to these methods as keyword arguments, with
  7258. the callback name as the argument name and the function as its value. This is demonstrated
  7259. in the example below. A <code>register_[...]_callbacks</code> method exists for each category.</p>
  7260. <p>Callbacks for each category can be found on their respective page of the
  7261. <a href="https://matrix-org.github.io/synapse">Synapse documentation website</a>.</p>
  7262. <div style="break-before: page; page-break-before: always;"></div><h1 id="spam-checker-callbacks"><a class="header" href="#spam-checker-callbacks">Spam checker callbacks</a></h1>
  7263. <p>Spam checker callbacks allow module developers to implement spam mitigation actions for
  7264. Synapse instances. Spam checker callbacks can be registered using the module API's
  7265. <code>register_spam_checker_callbacks</code> method.</p>
  7266. <h2 id="callbacks"><a class="header" href="#callbacks">Callbacks</a></h2>
  7267. <p>The available spam checker callbacks are:</p>
  7268. <h3 id="check_event_for_spam"><a class="header" href="#check_event_for_spam"><code>check_event_for_spam</code></a></h3>
  7269. <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]
  7270. </code></pre>
  7271. <p>Called when receiving an event from a client or via federation. The module can return
  7272. either a <code>bool</code> to indicate whether the event must be rejected because of spam, or a <code>str</code>
  7273. to indicate the event must be rejected because of spam and to give a rejection reason to
  7274. forward to clients.</p>
  7275. <h3 id="user_may_invite"><a class="header" href="#user_may_invite"><code>user_may_invite</code></a></h3>
  7276. <pre><code class="language-python">async def user_may_invite(inviter: str, invitee: str, room_id: str) -&gt; bool
  7277. </code></pre>
  7278. <p>Called when processing an invitation. The module must return a <code>bool</code> indicating whether
  7279. the inviter can invite the invitee to the given room. Both inviter and invitee are
  7280. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7281. <h3 id="user_may_create_room"><a class="header" href="#user_may_create_room"><code>user_may_create_room</code></a></h3>
  7282. <pre><code class="language-python">async def user_may_create_room(user: str) -&gt; bool
  7283. </code></pre>
  7284. <p>Called when processing a room creation request. The module must return a <code>bool</code> indicating
  7285. whether the given user (represented by their Matrix user ID) is allowed to create a room.</p>
  7286. <h3 id="user_may_create_room_with_invites"><a class="header" href="#user_may_create_room_with_invites"><code>user_may_create_room_with_invites</code></a></h3>
  7287. <pre><code class="language-python">async def user_may_create_room_with_invites(
  7288. user: str,
  7289. invites: List[str],
  7290. threepid_invites: List[Dict[str, str]],
  7291. ) -&gt; bool
  7292. </code></pre>
  7293. <p>Called when processing a room creation request (right after <code>user_may_create_room</code>).
  7294. The module is given the Matrix user ID of the user trying to create a room, as well as a
  7295. list of Matrix users to invite and a list of third-party identifiers (3PID, e.g. email
  7296. addresses) to invite.</p>
  7297. <p>An invited Matrix user to invite is represented by their Matrix user IDs, and an invited
  7298. 3PIDs is represented by a dict that includes the 3PID medium (e.g. &quot;email&quot;) through its
  7299. <code>medium</code> key and its address (e.g. &quot;alice@example.com&quot;) through its <code>address</code> key.</p>
  7300. <p>See <a href="https://matrix.org/docs/spec/appendices#pid-types">the Matrix specification</a> for more
  7301. information regarding third-party identifiers.</p>
  7302. <p>If no invite and/or 3PID invite were specified in the room creation request, the
  7303. corresponding list(s) will be empty.</p>
  7304. <p><strong>Note</strong>: This callback is not called when a room is cloned (e.g. during a room upgrade)
  7305. since no invites are sent when cloning a room. To cover this case, modules also need to
  7306. implement <code>user_may_create_room</code>.</p>
  7307. <h3 id="user_may_create_room_alias"><a class="header" href="#user_may_create_room_alias"><code>user_may_create_room_alias</code></a></h3>
  7308. <pre><code class="language-python">async def user_may_create_room_alias(user: str, room_alias: &quot;synapse.types.RoomAlias&quot;) -&gt; bool
  7309. </code></pre>
  7310. <p>Called when trying to associate an alias with an existing room. The module must return a
  7311. <code>bool</code> indicating whether the given user (represented by their Matrix user ID) is allowed
  7312. to set the given alias.</p>
  7313. <h3 id="user_may_publish_room"><a class="header" href="#user_may_publish_room"><code>user_may_publish_room</code></a></h3>
  7314. <pre><code class="language-python">async def user_may_publish_room(user: str, room_id: str) -&gt; bool
  7315. </code></pre>
  7316. <p>Called when trying to publish a room to the homeserver's public rooms directory. The
  7317. module must return a <code>bool</code> indicating whether the given user (represented by their
  7318. Matrix user ID) is allowed to publish the given room.</p>
  7319. <h3 id="check_username_for_spam"><a class="header" href="#check_username_for_spam"><code>check_username_for_spam</code></a></h3>
  7320. <pre><code class="language-python">async def check_username_for_spam(user_profile: Dict[str, str]) -&gt; bool
  7321. </code></pre>
  7322. <p>Called when computing search results in the user directory. The module must return a
  7323. <code>bool</code> indicating whether the given user profile can appear in search results. The profile
  7324. is represented as a dictionary with the following keys:</p>
  7325. <ul>
  7326. <li><code>user_id</code>: The Matrix ID for this user.</li>
  7327. <li><code>display_name</code>: The user's display name.</li>
  7328. <li><code>avatar_url</code>: The <code>mxc://</code> URL to the user's avatar.</li>
  7329. </ul>
  7330. <p>The module is given a copy of the original dictionary, so modifying it from within the
  7331. module cannot modify a user's profile when included in user directory search results.</p>
  7332. <h3 id="check_registration_for_spam"><a class="header" href="#check_registration_for_spam"><code>check_registration_for_spam</code></a></h3>
  7333. <pre><code class="language-python">async def check_registration_for_spam(
  7334. email_threepid: Optional[dict],
  7335. username: Optional[str],
  7336. request_info: Collection[Tuple[str, str]],
  7337. auth_provider_id: Optional[str] = None,
  7338. ) -&gt; &quot;synapse.spam_checker_api.RegistrationBehaviour&quot;
  7339. </code></pre>
  7340. <p>Called when registering a new user. The module must return a <code>RegistrationBehaviour</code>
  7341. indicating whether the registration can go through or must be denied, or whether the user
  7342. may be allowed to register but will be shadow banned.</p>
  7343. <p>The arguments passed to this callback are:</p>
  7344. <ul>
  7345. <li><code>email_threepid</code>: The email address used for registering, if any.</li>
  7346. <li><code>username</code>: The username the user would like to register. Can be <code>None</code>, meaning that
  7347. Synapse will generate one later.</li>
  7348. <li><code>request_info</code>: A collection of tuples, which first item is a user agent, and which
  7349. second item is an IP address. These user agents and IP addresses are the ones that were
  7350. used during the registration process.</li>
  7351. <li><code>auth_provider_id</code>: The identifier of the SSO authentication provider, if any.</li>
  7352. </ul>
  7353. <h3 id="check_media_file_for_spam"><a class="header" href="#check_media_file_for_spam"><code>check_media_file_for_spam</code></a></h3>
  7354. <pre><code class="language-python">async def check_media_file_for_spam(
  7355. file_wrapper: &quot;synapse.rest.media.v1.media_storage.ReadableFileWrapper&quot;,
  7356. file_info: &quot;synapse.rest.media.v1._base.FileInfo&quot;,
  7357. ) -&gt; bool
  7358. </code></pre>
  7359. <p>Called when storing a local or remote file. The module must return a boolean indicating
  7360. whether the given file can be stored in the homeserver's media store.</p>
  7361. <h2 id="example"><a class="header" href="#example">Example</a></h2>
  7362. <p>The example below is a module that implements the spam checker callback
  7363. <code>check_event_for_spam</code> to deny any message sent by users whose Matrix user IDs are
  7364. mentioned in a configured list, and registers a web resource to the path
  7365. <code>/_synapse/client/list_spam_checker/is_evil</code> that returns a JSON object indicating
  7366. whether the provided user appears in that list.</p>
  7367. <pre><code class="language-python">import json
  7368. from typing import Union
  7369. from twisted.web.resource import Resource
  7370. from twisted.web.server import Request
  7371. from synapse.module_api import ModuleApi
  7372. class IsUserEvilResource(Resource):
  7373. def __init__(self, config):
  7374. super(IsUserEvilResource, self).__init__()
  7375. self.evil_users = config.get(&quot;evil_users&quot;) or []
  7376. def render_GET(self, request: Request):
  7377. user = request.args.get(b&quot;user&quot;)[0].decode()
  7378. request.setHeader(b&quot;Content-Type&quot;, b&quot;application/json&quot;)
  7379. return json.dumps({&quot;evil&quot;: user in self.evil_users}).encode()
  7380. class ListSpamChecker:
  7381. def __init__(self, config: dict, api: ModuleApi):
  7382. self.api = api
  7383. self.evil_users = config.get(&quot;evil_users&quot;) or []
  7384. self.api.register_spam_checker_callbacks(
  7385. check_event_for_spam=self.check_event_for_spam,
  7386. )
  7387. self.api.register_web_resource(
  7388. path=&quot;/_synapse/client/list_spam_checker/is_evil&quot;,
  7389. resource=IsUserEvilResource(config),
  7390. )
  7391. async def check_event_for_spam(self, event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]:
  7392. return event.sender not in self.evil_users
  7393. </code></pre>
  7394. <div style="break-before: page; page-break-before: always;"></div><h1 id="third-party-rules-callbacks"><a class="header" href="#third-party-rules-callbacks">Third party rules callbacks</a></h1>
  7395. <p>Third party rules callbacks allow module developers to add extra checks to verify the
  7396. validity of incoming events. Third party event rules callbacks can be registered using
  7397. the module API's <code>register_third_party_rules_callbacks</code> method.</p>
  7398. <h2 id="callbacks-1"><a class="header" href="#callbacks-1">Callbacks</a></h2>
  7399. <p>The available third party rules callbacks are:</p>
  7400. <h3 id="check_event_allowed"><a class="header" href="#check_event_allowed"><code>check_event_allowed</code></a></h3>
  7401. <pre><code class="language-python">async def check_event_allowed(
  7402. event: &quot;synapse.events.EventBase&quot;,
  7403. state_events: &quot;synapse.types.StateMap&quot;,
  7404. ) -&gt; Tuple[bool, Optional[dict]]
  7405. </code></pre>
  7406. <p><strong><span style="color:red">
  7407. This callback is very experimental and can and will break without notice. Module developers
  7408. are encouraged to implement <code>check_event_for_spam</code> from the spam checker category instead.
  7409. </span></strong></p>
  7410. <p>Called when processing any incoming event, with the event and a <code>StateMap</code>
  7411. representing the current state of the room the event is being sent into. A <code>StateMap</code> is
  7412. a dictionary that maps tuples containing an event type and a state key to the
  7413. corresponding state event. For example retrieving the room's <code>m.room.create</code> event from
  7414. the <code>state_events</code> argument would look like this: <code>state_events.get((&quot;m.room.create&quot;, &quot;&quot;))</code>.
  7415. The module must return a boolean indicating whether the event can be allowed.</p>
  7416. <p>Note that this callback function processes incoming events coming via federation
  7417. traffic (on top of client traffic). This means denying an event might cause the local
  7418. copy of the room's history to diverge from that of remote servers. This may cause
  7419. federation issues in the room. It is strongly recommended to only deny events using this
  7420. callback function if the sender is a local user, or in a private federation in which all
  7421. servers are using the same module, with the same configuration.</p>
  7422. <p>If the boolean returned by the module is <code>True</code>, it may also tell Synapse to replace the
  7423. event with new data by returning the new event's data as a dictionary. In order to do
  7424. that, it is recommended the module calls <code>event.get_dict()</code> to get the current event as a
  7425. dictionary, and modify the returned dictionary accordingly.</p>
  7426. <p>Note that replacing the event only works for events sent by local users, not for events
  7427. received over federation.</p>
  7428. <h3 id="on_create_room"><a class="header" href="#on_create_room"><code>on_create_room</code></a></h3>
  7429. <pre><code class="language-python">async def on_create_room(
  7430. requester: &quot;synapse.types.Requester&quot;,
  7431. request_content: dict,
  7432. is_requester_admin: bool,
  7433. ) -&gt; None
  7434. </code></pre>
  7435. <p>Called when processing a room creation request, with the <code>Requester</code> object for the user
  7436. performing the request, a dictionary representing the room creation request's JSON body
  7437. (see <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom">the spec</a>
  7438. for a list of possible parameters), and a boolean indicating whether the user performing
  7439. the request is a server admin.</p>
  7440. <p>Modules can modify the <code>request_content</code> (by e.g. adding events to its <code>initial_state</code>),
  7441. or deny the room's creation by raising a <code>module_api.errors.SynapseError</code>.</p>
  7442. <h3 id="check_threepid_can_be_invited"><a class="header" href="#check_threepid_can_be_invited"><code>check_threepid_can_be_invited</code></a></h3>
  7443. <pre><code class="language-python">async def check_threepid_can_be_invited(
  7444. medium: str,
  7445. address: str,
  7446. state_events: &quot;synapse.types.StateMap&quot;,
  7447. ) -&gt; bool:
  7448. </code></pre>
  7449. <p>Called when processing an invite via a third-party identifier (i.e. email or phone number).
  7450. The module must return a boolean indicating whether the invite can go through.</p>
  7451. <h3 id="check_visibility_can_be_modified"><a class="header" href="#check_visibility_can_be_modified"><code>check_visibility_can_be_modified</code></a></h3>
  7452. <pre><code class="language-python">async def check_visibility_can_be_modified(
  7453. room_id: str,
  7454. state_events: &quot;synapse.types.StateMap&quot;,
  7455. new_visibility: str,
  7456. ) -&gt; bool:
  7457. </code></pre>
  7458. <p>Called when changing the visibility of a room in the local public room directory. The
  7459. visibility is a string that's either &quot;public&quot; or &quot;private&quot;. The module must return a
  7460. boolean indicating whether the change can go through.</p>
  7461. <h2 id="example-1"><a class="header" href="#example-1">Example</a></h2>
  7462. <p>The example below is a module that implements the third-party rules callback
  7463. <code>check_event_allowed</code> to censor incoming messages as dictated by a third-party service.</p>
  7464. <pre><code class="language-python">from typing import Optional, Tuple
  7465. from synapse.module_api import ModuleApi
  7466. _DEFAULT_CENSOR_ENDPOINT = &quot;https://my-internal-service.local/censor-event&quot;
  7467. class EventCensorer:
  7468. def __init__(self, config: dict, api: ModuleApi):
  7469. self.api = api
  7470. self._endpoint = config.get(&quot;endpoint&quot;, _DEFAULT_CENSOR_ENDPOINT)
  7471. self.api.register_third_party_rules_callbacks(
  7472. check_event_allowed=self.check_event_allowed,
  7473. )
  7474. async def check_event_allowed(
  7475. self,
  7476. event: &quot;synapse.events.EventBase&quot;,
  7477. state_events: &quot;synapse.types.StateMap&quot;,
  7478. ) -&gt; Tuple[bool, Optional[dict]]:
  7479. event_dict = event.get_dict()
  7480. new_event_content = await self.api.http_client.post_json_get_json(
  7481. uri=self._endpoint, post_json=event_dict,
  7482. )
  7483. event_dict[&quot;content&quot;] = new_event_content
  7484. return event_dict
  7485. </code></pre>
  7486. <div style="break-before: page; page-break-before: always;"></div><h1 id="presence-router-callbacks"><a class="header" href="#presence-router-callbacks">Presence router callbacks</a></h1>
  7487. <p>Presence router callbacks allow module developers to specify additional users (local or remote)
  7488. to receive certain presence updates from local users. Presence router callbacks can be
  7489. registered using the module API's <code>register_presence_router_callbacks</code> method.</p>
  7490. <h2 id="callbacks-2"><a class="header" href="#callbacks-2">Callbacks</a></h2>
  7491. <p>The available presence router callbacks are:</p>
  7492. <h3 id="get_users_for_states"><a class="header" href="#get_users_for_states"><code>get_users_for_states</code></a></h3>
  7493. <pre><code class="language-python">async def get_users_for_states(
  7494. state_updates: Iterable[&quot;synapse.api.UserPresenceState&quot;],
  7495. ) -&gt; Dict[str, Set[&quot;synapse.api.UserPresenceState&quot;]]
  7496. </code></pre>
  7497. <p><strong>Requires</strong> <code>get_interested_users</code> to also be registered</p>
  7498. <p>Called when processing updates to the presence state of one or more users. This callback can
  7499. be used to instruct the server to forward that presence state to specific users. The module
  7500. must return a dictionary that maps from Matrix user IDs (which can be local or remote) to the
  7501. <code>UserPresenceState</code> changes that they should be forwarded.</p>
  7502. <p>Synapse will then attempt to send the specified presence updates to each user when possible.</p>
  7503. <h3 id="get_interested_users"><a class="header" href="#get_interested_users"><code>get_interested_users</code></a></h3>
  7504. <pre><code class="language-python">async def get_interested_users(
  7505. user_id: str
  7506. ) -&gt; Union[Set[str], &quot;synapse.module_api.PRESENCE_ALL_USERS&quot;]
  7507. </code></pre>
  7508. <p><strong>Requires</strong> <code>get_users_for_states</code> to also be registered</p>
  7509. <p>Called when determining which users someone should be able to see the presence state of. This
  7510. callback should return complementary results to <code>get_users_for_state</code> or the presence information
  7511. may not be properly forwarded.</p>
  7512. <p>The callback is given the Matrix user ID for a local user that is requesting presence data and
  7513. should return the Matrix user IDs of the users whose presence state they are allowed to
  7514. query. The returned users can be local or remote. </p>
  7515. <p>Alternatively the callback can return <code>synapse.module_api.PRESENCE_ALL_USERS</code>
  7516. to indicate that the user should receive updates from all known users.</p>
  7517. <h2 id="example-2"><a class="header" href="#example-2">Example</a></h2>
  7518. <p>The example below is a module that implements both presence router callbacks, and ensures
  7519. that <code>@alice:example.org</code> receives all presence updates from <code>@bob:example.com</code> and
  7520. <code>@charlie:somewhere.org</code>, regardless of whether Alice shares a room with any of them.</p>
  7521. <pre><code class="language-python">from typing import Dict, Iterable, Set, Union
  7522. from synapse.module_api import ModuleApi
  7523. class CustomPresenceRouter:
  7524. def __init__(self, config: dict, api: ModuleApi):
  7525. self.api = api
  7526. self.api.register_presence_router_callbacks(
  7527. get_users_for_states=self.get_users_for_states,
  7528. get_interested_users=self.get_interested_users,
  7529. )
  7530. async def get_users_for_states(
  7531. self,
  7532. state_updates: Iterable[&quot;synapse.api.UserPresenceState&quot;],
  7533. ) -&gt; Dict[str, Set[&quot;synapse.api.UserPresenceState&quot;]]:
  7534. res = {}
  7535. for update in state_updates:
  7536. if (
  7537. update.user_id == &quot;@bob:example.com&quot;
  7538. or update.user_id == &quot;@charlie:somewhere.org&quot;
  7539. ):
  7540. res.setdefault(&quot;@alice:example.com&quot;, set()).add(update)
  7541. return res
  7542. async def get_interested_users(
  7543. self,
  7544. user_id: str,
  7545. ) -&gt; Union[Set[str], &quot;synapse.module_api.PRESENCE_ALL_USERS&quot;]:
  7546. if user_id == &quot;@alice:example.com&quot;:
  7547. return {&quot;@bob:example.com&quot;, &quot;@charlie:somewhere.org&quot;}
  7548. return set()
  7549. </code></pre>
  7550. <div style="break-before: page; page-break-before: always;"></div><h1 id="account-validity-callbacks"><a class="header" href="#account-validity-callbacks">Account validity callbacks</a></h1>
  7551. <p>Account validity callbacks allow module developers to add extra steps to verify the
  7552. validity on an account, i.e. see if a user can be granted access to their account on the
  7553. Synapse instance. Account validity callbacks can be registered using the module API's
  7554. <code>register_account_validity_callbacks</code> method.</p>
  7555. <p>The available account validity callbacks are:</p>
  7556. <h3 id="is_user_expired"><a class="header" href="#is_user_expired"><code>is_user_expired</code></a></h3>
  7557. <pre><code class="language-python">async def is_user_expired(user: str) -&gt; Optional[bool]
  7558. </code></pre>
  7559. <p>Called when processing any authenticated request (except for logout requests). The module
  7560. can return a <code>bool</code> to indicate whether the user has expired and should be locked out of
  7561. their account, or <code>None</code> if the module wasn't able to figure it out. The user is
  7562. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7563. <p>If the module returns <code>True</code>, the current request will be denied with the error code
  7564. <code>ORG_MATRIX_EXPIRED_ACCOUNT</code> and the HTTP status code 403. Note that this doesn't
  7565. invalidate the user's access token.</p>
  7566. <h3 id="on_user_registration"><a class="header" href="#on_user_registration"><code>on_user_registration</code></a></h3>
  7567. <pre><code class="language-python">async def on_user_registration(user: str) -&gt; None
  7568. </code></pre>
  7569. <p>Called after successfully registering a user, in case the module needs to perform extra
  7570. operations to keep track of them. (e.g. add them to a database table). The user is
  7571. represented by their Matrix user ID.</p>
  7572. <div style="break-before: page; page-break-before: always;"></div><h1 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></h1>
  7573. <p>In order to port a module that uses Synapse's old module interface, its author needs to:</p>
  7574. <ul>
  7575. <li>ensure the module's callbacks are all asynchronous.</li>
  7576. <li>register their callbacks using one or more of the <code>register_[...]_callbacks</code> methods
  7577. from the <code>ModuleApi</code> class in the module's <code>__init__</code> method (see <a href="modules/writing_a_module.html#registering-a-callback">this section</a>
  7578. for more info).</li>
  7579. </ul>
  7580. <p>Additionally, if the module is packaged with an additional web resource, the module
  7581. should register this resource in its <code>__init__</code> method using the <code>register_web_resource</code>
  7582. method from the <code>ModuleApi</code> class (see <a href="modules/writing_a_module.html#registering-a-web-resource">this section</a> for
  7583. more info).</p>
  7584. <p>The module's author should also update any example in the module's configuration to only
  7585. use the new <code>modules</code> section in Synapse's configuration file (see <a href="modules/index.html#using-modules">this section</a>
  7586. for more info).</p>
  7587. <div 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>
  7588. <p>For small instances it recommended to run Synapse in the default monolith mode.
  7589. For larger instances where performance is a concern it can be helpful to split
  7590. out functionality into multiple separate python processes. These processes are
  7591. called 'workers', and are (eventually) intended to scale horizontally
  7592. independently.</p>
  7593. <p>Synapse's worker support is under active development and subject to change as
  7594. we attempt to rapidly scale ever larger Synapse instances. However we are
  7595. documenting it here to help admins needing a highly scalable Synapse instance
  7596. similar to the one running <code>matrix.org</code>.</p>
  7597. <p>All processes continue to share the same database instance, and as such,
  7598. workers only work with PostgreSQL-based Synapse deployments. SQLite should only
  7599. be used for demo purposes and any admin considering workers should already be
  7600. running PostgreSQL.</p>
  7601. <p>See also <a href="https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability">Matrix.org blog post</a>
  7602. for a higher level overview.</p>
  7603. <h2 id="main-processworker-communication"><a class="header" href="#main-processworker-communication">Main process/worker communication</a></h2>
  7604. <p>The processes communicate with each other via a Synapse-specific protocol called
  7605. 'replication' (analogous to MySQL- or Postgres-style database replication) which
  7606. feeds streams of newly written data between processes so they can be kept in
  7607. sync with the database state.</p>
  7608. <p>When configured to do so, Synapse uses a
  7609. <a href="https://redis.io/topics/pubsub">Redis pub/sub channel</a> to send the replication
  7610. stream between all configured Synapse processes. Additionally, processes may
  7611. make HTTP requests to each other, primarily for operations which need to wait
  7612. for a reply ─ such as sending an event.</p>
  7613. <p>Redis support was added in v1.13.0 with it becoming the recommended method in
  7614. v1.18.0. It replaced the old direct TCP connections (which is deprecated as of
  7615. v1.18.0) to the main process. With Redis, rather than all the workers connecting
  7616. to the main process, all the workers and the main process connect to Redis,
  7617. which relays replication commands between processes. This can give a significant
  7618. cpu saving on the main process and will be a prerequisite for upcoming
  7619. performance improvements.</p>
  7620. <p>If Redis support is enabled Synapse will use it as a shared cache, as well as a
  7621. pub/sub mechanism.</p>
  7622. <p>See the <a href="workers.html#architectural-diagram">Architectural diagram</a> section at the end for
  7623. a visualisation of what this looks like.</p>
  7624. <h2 id="setting-up-workers"><a class="header" href="#setting-up-workers">Setting up workers</a></h2>
  7625. <p>A Redis server is required to manage the communication between the processes.
  7626. The Redis server should be installed following the normal procedure for your
  7627. distribution (e.g. <code>apt install redis-server</code> on Debian). It is safe to use an
  7628. existing Redis deployment if you have one.</p>
  7629. <p>Once installed, check that Redis is running and accessible from the host running
  7630. Synapse, for example by executing <code>echo PING | nc -q1 localhost 6379</code> and seeing
  7631. a response of <code>+PONG</code>.</p>
  7632. <p>The appropriate dependencies must also be installed for Synapse. If using a
  7633. virtualenv, these can be installed with:</p>
  7634. <pre><code class="language-sh">pip install &quot;matrix-synapse[redis]&quot;
  7635. </code></pre>
  7636. <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
  7637. <code>matrix.org</code> and in the docker images at
  7638. https://hub.docker.com/r/matrixdotorg/synapse/.</p>
  7639. <p>To make effective use of the workers, you will need to configure an HTTP
  7640. reverse-proxy such as nginx or haproxy, which will direct incoming requests to
  7641. the correct worker, or to the main synapse instance. See
  7642. <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a reverse
  7643. proxy.</p>
  7644. <p>When using workers, each worker process has its own configuration file which
  7645. contains settings specific to that worker, such as the HTTP listener that it
  7646. provides (if any), logging configuration, etc.</p>
  7647. <p>Normally, the worker processes are configured to read from a shared
  7648. configuration file as well as the worker-specific configuration files. This
  7649. makes it easier to keep common configuration settings synchronised across all
  7650. the processes.</p>
  7651. <p>The main process is somewhat special in this respect: it does not normally
  7652. need its own configuration file and can take all of its configuration from the
  7653. shared configuration file.</p>
  7654. <h3 id="shared-configuration"><a class="header" href="#shared-configuration">Shared configuration</a></h3>
  7655. <p>Normally, only a couple of changes are needed to make an existing configuration
  7656. file suitable for use with workers. First, you need to enable an &quot;HTTP replication
  7657. listener&quot; for the main process; and secondly, you need to enable redis-based
  7658. replication. Optionally, a shared secret can be used to authenticate HTTP
  7659. traffic between workers. For example:</p>
  7660. <pre><code class="language-yaml"># extend the existing `listeners` section. This defines the ports that the
  7661. # main process will listen on.
  7662. listeners:
  7663. # The HTTP replication port
  7664. - port: 9093
  7665. bind_address: '127.0.0.1'
  7666. type: http
  7667. resources:
  7668. - names: [replication]
  7669. # Add a random shared secret to authenticate traffic.
  7670. worker_replication_secret: &quot;&quot;
  7671. redis:
  7672. enabled: true
  7673. </code></pre>
  7674. <p>See the sample config for the full documentation of each option.</p>
  7675. <p>Under <strong>no circumstances</strong> should the replication listener be exposed to the
  7676. public internet; it has no authentication and is unencrypted.</p>
  7677. <h3 id="worker-configuration"><a class="header" href="#worker-configuration">Worker configuration</a></h3>
  7678. <p>In the config file for each worker, you must specify the type of worker
  7679. application (<code>worker_app</code>), and you should specify a unique name for the worker
  7680. (<code>worker_name</code>). The currently available worker applications are listed below.
  7681. You must also specify the HTTP replication endpoint that it should talk to on
  7682. the main synapse process. <code>worker_replication_host</code> should specify the host of
  7683. the main synapse and <code>worker_replication_http_port</code> should point to the HTTP
  7684. replication port. If the worker will handle HTTP requests then the
  7685. <code>worker_listeners</code> option should be set with a <code>http</code> listener, in the same way
  7686. as the <code>listeners</code> option in the shared config.</p>
  7687. <p>For example:</p>
  7688. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  7689. worker_name: worker1
  7690. # The replication listener on the main synapse process.
  7691. worker_replication_host: 127.0.0.1
  7692. worker_replication_http_port: 9093
  7693. worker_listeners:
  7694. - type: http
  7695. port: 8083
  7696. resources:
  7697. - names:
  7698. - client
  7699. - federation
  7700. worker_log_config: /home/matrix/synapse/config/worker1_log_config.yaml
  7701. </code></pre>
  7702. <p>...is a full configuration for a generic worker instance, which will expose a
  7703. plain HTTP endpoint on port 8083 separately serving various endpoints, e.g.
  7704. <code>/sync</code>, which are listed below.</p>
  7705. <p>Obviously you should configure your reverse-proxy to route the relevant
  7706. endpoints to the worker (<code>localhost:8083</code> in the above example).</p>
  7707. <h3 id="running-synapse-with-workers"><a class="header" href="#running-synapse-with-workers">Running Synapse with workers</a></h3>
  7708. <p>Finally, you need to start your worker processes. This can be done with either
  7709. <code>synctl</code> or your distribution's preferred service manager such as <code>systemd</code>. We
  7710. recommend the use of <code>systemd</code> where available: for information on setting up
  7711. <code>systemd</code> to start synapse workers, see
  7712. <a href="systemd-with-workers">Systemd with Workers</a>. To use <code>synctl</code>, see
  7713. <a href="synctl_workers.html">Using synctl with Workers</a>.</p>
  7714. <h2 id="available-worker-applications"><a class="header" href="#available-worker-applications">Available worker applications</a></h2>
  7715. <h3 id="synapseappgeneric_worker"><a class="header" href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a></h3>
  7716. <p>This worker can handle API requests matching the following regular
  7717. expressions:</p>
  7718. <pre><code># Sync requests
  7719. ^/_matrix/client/(v2_alpha|r0)/sync$
  7720. ^/_matrix/client/(api/v1|v2_alpha|r0)/events$
  7721. ^/_matrix/client/(api/v1|r0)/initialSync$
  7722. ^/_matrix/client/(api/v1|r0)/rooms/[^/]+/initialSync$
  7723. # Federation requests
  7724. ^/_matrix/federation/v1/event/
  7725. ^/_matrix/federation/v1/state/
  7726. ^/_matrix/federation/v1/state_ids/
  7727. ^/_matrix/federation/v1/backfill/
  7728. ^/_matrix/federation/v1/get_missing_events/
  7729. ^/_matrix/federation/v1/publicRooms
  7730. ^/_matrix/federation/v1/query/
  7731. ^/_matrix/federation/v1/make_join/
  7732. ^/_matrix/federation/v1/make_leave/
  7733. ^/_matrix/federation/v1/send_join/
  7734. ^/_matrix/federation/v2/send_join/
  7735. ^/_matrix/federation/v1/send_leave/
  7736. ^/_matrix/federation/v2/send_leave/
  7737. ^/_matrix/federation/v1/invite/
  7738. ^/_matrix/federation/v2/invite/
  7739. ^/_matrix/federation/v1/query_auth/
  7740. ^/_matrix/federation/v1/event_auth/
  7741. ^/_matrix/federation/v1/exchange_third_party_invite/
  7742. ^/_matrix/federation/v1/user/devices/
  7743. ^/_matrix/federation/v1/get_groups_publicised$
  7744. ^/_matrix/key/v2/query
  7745. ^/_matrix/federation/unstable/org.matrix.msc2946/spaces/
  7746. ^/_matrix/federation/unstable/org.matrix.msc2946/hierarchy/
  7747. # Inbound federation transaction request
  7748. ^/_matrix/federation/v1/send/
  7749. # Client API requests
  7750. ^/_matrix/client/(api/v1|r0|unstable)/createRoom$
  7751. ^/_matrix/client/(api/v1|r0|unstable)/publicRooms$
  7752. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/joined_members$
  7753. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/context/.*$
  7754. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/members$
  7755. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state$
  7756. ^/_matrix/client/unstable/org.matrix.msc2946/rooms/.*/spaces$
  7757. ^/_matrix/client/unstable/org.matrix.msc2946/rooms/.*/hierarchy$
  7758. ^/_matrix/client/unstable/im.nheko.summary/rooms/.*/summary$
  7759. ^/_matrix/client/(api/v1|r0|unstable)/account/3pid$
  7760. ^/_matrix/client/(api/v1|r0|unstable)/devices$
  7761. ^/_matrix/client/(api/v1|r0|unstable)/keys/query$
  7762. ^/_matrix/client/(api/v1|r0|unstable)/keys/changes$
  7763. ^/_matrix/client/versions$
  7764. ^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$
  7765. ^/_matrix/client/(api/v1|r0|unstable)/joined_groups$
  7766. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups$
  7767. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups/
  7768. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/event/
  7769. ^/_matrix/client/(api/v1|r0|unstable)/joined_rooms$
  7770. ^/_matrix/client/(api/v1|r0|unstable)/search$
  7771. # Registration/login requests
  7772. ^/_matrix/client/(api/v1|r0|unstable)/login$
  7773. ^/_matrix/client/(r0|unstable)/register$
  7774. ^/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity$
  7775. # Event sending requests
  7776. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/redact
  7777. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/send
  7778. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state/
  7779. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
  7780. ^/_matrix/client/(api/v1|r0|unstable)/join/
  7781. ^/_matrix/client/(api/v1|r0|unstable)/profile/
  7782. </code></pre>
  7783. <p>Additionally, the following REST endpoints can be handled for GET requests:</p>
  7784. <pre><code>^/_matrix/federation/v1/groups/
  7785. </code></pre>
  7786. <p>Pagination requests can also be handled, but all requests for a given
  7787. room must be routed to the same instance. Additionally, care must be taken to
  7788. ensure that the purge history admin API is not used while pagination requests
  7789. for the room are in flight:</p>
  7790. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/messages$
  7791. </code></pre>
  7792. <p>Additionally, the following endpoints should be included if Synapse is configured
  7793. to use SSO (you only need to include the ones for whichever SSO provider you're
  7794. using):</p>
  7795. <pre><code># for all SSO providers
  7796. ^/_matrix/client/(api/v1|r0|unstable)/login/sso/redirect
  7797. ^/_synapse/client/pick_idp$
  7798. ^/_synapse/client/pick_username
  7799. ^/_synapse/client/new_user_consent$
  7800. ^/_synapse/client/sso_register$
  7801. # OpenID Connect requests.
  7802. ^/_synapse/client/oidc/callback$
  7803. # SAML requests.
  7804. ^/_synapse/client/saml2/authn_response$
  7805. # CAS requests.
  7806. ^/_matrix/client/(api/v1|r0|unstable)/login/cas/ticket$
  7807. </code></pre>
  7808. <p>Ensure that all SSO logins go to a single process.
  7809. For multiple workers not handling the SSO endpoints properly, see
  7810. <a href="https://github.com/matrix-org/synapse/issues/7530">#7530</a> and
  7811. <a href="https://github.com/matrix-org/synapse/issues/9427">#9427</a>.</p>
  7812. <p>Note that a HTTP listener with <code>client</code> and <code>federation</code> resources must be
  7813. configured in the <code>worker_listeners</code> option in the worker config.</p>
  7814. <h4 id="load-balancing"><a class="header" href="#load-balancing">Load balancing</a></h4>
  7815. <p>It is possible to run multiple instances of this worker app, with incoming requests
  7816. being load-balanced between them by the reverse-proxy. However, different endpoints
  7817. have different characteristics and so admins
  7818. may wish to run multiple groups of workers handling different endpoints so that
  7819. load balancing can be done in different ways.</p>
  7820. <p>For <code>/sync</code> and <code>/initialSync</code> requests it will be more efficient if all
  7821. requests from a particular user are routed to a single instance. Extracting a
  7822. user ID from the access token or <code>Authorization</code> header is currently left as an
  7823. exercise for the reader. Admins may additionally wish to separate out <code>/sync</code>
  7824. requests that have a <code>since</code> query parameter from those that don't (and
  7825. <code>/initialSync</code>), as requests that don't are known as &quot;initial sync&quot; that happens
  7826. when a user logs in on a new device and can be <em>very</em> resource intensive, so
  7827. isolating these requests will stop them from interfering with other users ongoing
  7828. syncs.</p>
  7829. <p>Federation and client requests can be balanced via simple round robin.</p>
  7830. <p>The inbound federation transaction request <code>^/_matrix/federation/v1/send/</code>
  7831. should be balanced by source IP so that transactions from the same remote server
  7832. go to the same process.</p>
  7833. <p>Registration/login requests can be handled separately purely to help ensure that
  7834. unexpected load doesn't affect new logins and sign ups.</p>
  7835. <p>Finally, event sending requests can be balanced by the room ID in the URI (or
  7836. the full URI, or even just round robin), the room ID is the path component after
  7837. <code>/rooms/</code>. If there is a large bridge connected that is sending or may send lots
  7838. of events, then a dedicated set of workers can be provisioned to limit the
  7839. effects of bursts of events from that bridge on events sent by normal users.</p>
  7840. <h4 id="stream-writers"><a class="header" href="#stream-writers">Stream writers</a></h4>
  7841. <p>Additionally, there is <em>experimental</em> support for moving writing of specific
  7842. streams (such as events) off of the main process to a particular worker. (This
  7843. is only supported with Redis-based replication.)</p>
  7844. <p>Currently supported streams are <code>events</code> and <code>typing</code>.</p>
  7845. <p>To enable this, the worker must have a HTTP replication listener configured,
  7846. have a <code>worker_name</code> and be listed in the <code>instance_map</code> config. For example to
  7847. move event persistence off to a dedicated worker, the shared configuration would
  7848. include:</p>
  7849. <pre><code class="language-yaml">instance_map:
  7850. event_persister1:
  7851. host: localhost
  7852. port: 8034
  7853. stream_writers:
  7854. events: event_persister1
  7855. </code></pre>
  7856. <p>The <code>events</code> stream also experimentally supports having multiple writers, where
  7857. work is sharded between them by room ID. Note that you <em>must</em> restart all worker
  7858. instances when adding or removing event persisters. An example <code>stream_writers</code>
  7859. configuration with multiple writers:</p>
  7860. <pre><code class="language-yaml">stream_writers:
  7861. events:
  7862. - event_persister1
  7863. - event_persister2
  7864. </code></pre>
  7865. <h4 id="background-tasks"><a class="header" href="#background-tasks">Background tasks</a></h4>
  7866. <p>There is also <em>experimental</em> support for moving background tasks to a separate
  7867. worker. Background tasks are run periodically or started via replication. Exactly
  7868. which tasks are configured to run depends on your Synapse configuration (e.g. if
  7869. stats is enabled).</p>
  7870. <p>To enable this, the worker must have a <code>worker_name</code> and can be configured to run
  7871. background tasks. For example, to move background tasks to a dedicated worker,
  7872. the shared configuration would include:</p>
  7873. <pre><code class="language-yaml">run_background_tasks_on: background_worker
  7874. </code></pre>
  7875. <p>You might also wish to investigate the <code>update_user_directory</code> and
  7876. <code>media_instance_running_background_jobs</code> settings.</p>
  7877. <h3 id="synapseapppusher"><a class="header" href="#synapseapppusher"><code>synapse.app.pusher</code></a></h3>
  7878. <p>Handles sending push notifications to sygnal and email. Doesn't handle any
  7879. REST endpoints itself, but you should set <code>start_pushers: False</code> in the
  7880. shared configuration file to stop the main synapse sending push notifications.</p>
  7881. <p>To run multiple instances at once the <code>pusher_instances</code> option should list all
  7882. pusher instances by their worker name, e.g.:</p>
  7883. <pre><code class="language-yaml">pusher_instances:
  7884. - pusher_worker1
  7885. - pusher_worker2
  7886. </code></pre>
  7887. <h3 id="synapseappappservice"><a class="header" href="#synapseappappservice"><code>synapse.app.appservice</code></a></h3>
  7888. <p>Handles sending output traffic to Application Services. Doesn't handle any
  7889. REST endpoints itself, but you should set <code>notify_appservices: False</code> in the
  7890. shared configuration file to stop the main synapse sending appservice notifications.</p>
  7891. <p>Note this worker cannot be load-balanced: only one instance should be active.</p>
  7892. <h3 id="synapseappfederation_sender"><a class="header" href="#synapseappfederation_sender"><code>synapse.app.federation_sender</code></a></h3>
  7893. <p>Handles sending federation traffic to other servers. Doesn't handle any
  7894. REST endpoints itself, but you should set <code>send_federation: False</code> in the
  7895. shared configuration file to stop the main synapse sending this traffic.</p>
  7896. <p>If running multiple federation senders then you must list each
  7897. instance in the <code>federation_sender_instances</code> option by their <code>worker_name</code>.
  7898. All instances must be stopped and started when adding or removing instances.
  7899. For example:</p>
  7900. <pre><code class="language-yaml">federation_sender_instances:
  7901. - federation_sender1
  7902. - federation_sender2
  7903. </code></pre>
  7904. <h3 id="synapseappmedia_repository"><a class="header" href="#synapseappmedia_repository"><code>synapse.app.media_repository</code></a></h3>
  7905. <p>Handles the media repository. It can handle all endpoints starting with:</p>
  7906. <pre><code>/_matrix/media/
  7907. </code></pre>
  7908. <p>... and the following regular expressions matching media-specific administration APIs:</p>
  7909. <pre><code>^/_synapse/admin/v1/purge_media_cache$
  7910. ^/_synapse/admin/v1/room/.*/media.*$
  7911. ^/_synapse/admin/v1/user/.*/media.*$
  7912. ^/_synapse/admin/v1/media/.*$
  7913. ^/_synapse/admin/v1/quarantine_media/.*$
  7914. ^/_synapse/admin/v1/users/.*/media$
  7915. </code></pre>
  7916. <p>You should also set <code>enable_media_repo: False</code> in the shared configuration
  7917. file to stop the main synapse running background jobs related to managing the
  7918. media repository. Note that doing so will prevent the main process from being
  7919. able to handle the above endpoints.</p>
  7920. <p>In the <code>media_repository</code> worker configuration file, configure the http listener to
  7921. expose the <code>media</code> resource. For example:</p>
  7922. <pre><code class="language-yaml"> worker_listeners:
  7923. - type: http
  7924. port: 8085
  7925. resources:
  7926. - names:
  7927. - media
  7928. </code></pre>
  7929. <p>Note that if running multiple media repositories they must be on the same server
  7930. and you must configure a single instance to run the background tasks, e.g.:</p>
  7931. <pre><code class="language-yaml"> media_instance_running_background_jobs: &quot;media-repository-1&quot;
  7932. </code></pre>
  7933. <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>
  7934. <h3 id="synapseappuser_dir"><a class="header" href="#synapseappuser_dir"><code>synapse.app.user_dir</code></a></h3>
  7935. <p>Handles searches in the user directory. It can handle REST endpoints matching
  7936. the following regular expressions:</p>
  7937. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$
  7938. </code></pre>
  7939. <p>When using this worker you must also set <code>update_user_directory: False</code> in the
  7940. shared configuration file to stop the main synapse running background
  7941. jobs related to updating the user directory.</p>
  7942. <h3 id="synapseappfrontend_proxy"><a class="header" href="#synapseappfrontend_proxy"><code>synapse.app.frontend_proxy</code></a></h3>
  7943. <p>Proxies some frequently-requested client endpoints to add caching and remove
  7944. load from the main synapse. It can handle REST endpoints matching the following
  7945. regular expressions:</p>
  7946. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/keys/upload
  7947. </code></pre>
  7948. <p>If <code>use_presence</code> is False in the homeserver config, it can also handle REST
  7949. endpoints matching the following regular expressions:</p>
  7950. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/presence/[^/]+/status
  7951. </code></pre>
  7952. <p>This &quot;stub&quot; presence handler will pass through <code>GET</code> request but make the
  7953. <code>PUT</code> effectively a no-op.</p>
  7954. <p>It will proxy any requests it cannot handle to the main synapse instance. It
  7955. must therefore be configured with the location of the main instance, via
  7956. the <code>worker_main_http_uri</code> setting in the <code>frontend_proxy</code> worker configuration
  7957. file. For example:</p>
  7958. <pre><code>worker_main_http_uri: http://127.0.0.1:8008
  7959. </code></pre>
  7960. <h3 id="historical-apps"><a class="header" href="#historical-apps">Historical apps</a></h3>
  7961. <p><em>Note:</em> Historically there used to be more apps, however they have been
  7962. amalgamated into a single <code>synapse.app.generic_worker</code> app. The remaining apps
  7963. are ones that do specific processing unrelated to requests, e.g. the <code>pusher</code>
  7964. that handles sending out push notifications for new events. The intention is for
  7965. all these to be folded into the <code>generic_worker</code> app and to use config to define
  7966. which processes handle the various proccessing such as push notifications.</p>
  7967. <h2 id="migration-from-old-config"><a class="header" href="#migration-from-old-config">Migration from old config</a></h2>
  7968. <p>There are two main independent changes that have been made: introducing Redis
  7969. support and merging apps into <code>synapse.app.generic_worker</code>. Both these changes
  7970. are backwards compatible and so no changes to the config are required, however
  7971. server admins are encouraged to plan to migrate to Redis as the old style direct
  7972. TCP replication config is deprecated.</p>
  7973. <p>To migrate to Redis add the <code>redis</code> config as above, and optionally remove the
  7974. TCP <code>replication</code> listener from master and <code>worker_replication_port</code> from worker
  7975. config.</p>
  7976. <p>To migrate apps to use <code>synapse.app.generic_worker</code> simply update the
  7977. <code>worker_app</code> option in the worker configs, and where worker are started (e.g.
  7978. in systemd service files, but not required for synctl).</p>
  7979. <h2 id="architectural-diagram"><a class="header" href="#architectural-diagram">Architectural diagram</a></h2>
  7980. <p>The following shows an example setup using Redis and a reverse proxy:</p>
  7981. <pre><code> Clients &amp; Federation
  7982. |
  7983. v
  7984. +-----------+
  7985. | |
  7986. | Reverse |
  7987. | Proxy |
  7988. | |
  7989. +-----------+
  7990. | | |
  7991. | | | HTTP requests
  7992. +-------------------+ | +-----------+
  7993. | +---+ |
  7994. | | |
  7995. v v v
  7996. +--------------+ +--------------+ +--------------+ +--------------+
  7997. | Main | | Generic | | Generic | | Event |
  7998. | Process | | Worker 1 | | Worker 2 | | Persister |
  7999. +--------------+ +--------------+ +--------------+ +--------------+
  8000. ^ ^ | ^ | | ^ | ^ ^
  8001. | | | | | | | | | |
  8002. | | | | | HTTP | | | | |
  8003. | +----------+&lt;--|---|---------+ | | | |
  8004. | | +-------------|--&gt;+----------+ |
  8005. | | | |
  8006. | | | |
  8007. v v v v
  8008. ====================================================================
  8009. Redis pub/sub channel
  8010. </code></pre>
  8011. <div 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>
  8012. <p>If you want to use <code>synctl</code> to manage your synapse processes, you will need to
  8013. create an an additional configuration file for the main synapse process. That
  8014. configuration should look like this:</p>
  8015. <pre><code class="language-yaml">worker_app: synapse.app.homeserver
  8016. </code></pre>
  8017. <p>Additionally, each worker app must be configured with the name of a &quot;pid file&quot;,
  8018. to which it will write its process ID when it starts. For example, for a
  8019. synchrotron, you might write:</p>
  8020. <pre><code class="language-yaml">worker_pid_file: /home/matrix/synapse/worker1.pid
  8021. </code></pre>
  8022. <p>Finally, to actually run your worker-based synapse, you must pass synctl the <code>-a</code>
  8023. commandline option to tell it to operate on all the worker configurations found
  8024. in the given directory, e.g.:</p>
  8025. <pre><code>synctl -a $CONFIG/workers start
  8026. </code></pre>
  8027. <p>Currently one should always restart all workers when restarting or upgrading
  8028. synapse, unless you explicitly know it's safe not to. For instance, restarting
  8029. synapse without restarting all the synchrotrons may result in broken typing
  8030. notifications.</p>
  8031. <p>To manipulate a specific worker, you pass the -w option to synctl:</p>
  8032. <pre><code>synctl -w $CONFIG/workers/worker1.yaml restart
  8033. </code></pre>
  8034. <div 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>
  8035. <p>This is a setup for managing synapse with systemd, including support for
  8036. managing workers. It provides a <code>matrix-synapse</code> service for the master, as
  8037. well as a <code>matrix-synapse-worker@</code> service template for any workers you
  8038. require. Additionally, to group the required services, it sets up a
  8039. <code>matrix-synapse.target</code>.</p>
  8040. <p>See the folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/system/">system</a>
  8041. for the systemd unit files.</p>
  8042. <p>The folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/workers/">workers</a>
  8043. contains an example configuration for the <code>federation_reader</code> worker.</p>
  8044. <h2 id="synapse-configuration-files"><a class="header" href="#synapse-configuration-files">Synapse configuration files</a></h2>
  8045. <p>See <a href="systemd-with-workers/../workers.html">the worker documentation</a> for information on how to set up the
  8046. configuration files and reverse-proxy correctly.
  8047. Below is a sample <code>federation_reader</code> worker configuration file.</p>
  8048. <pre><code class="language-yaml">worker_app: synapse.app.federation_reader
  8049. worker_name: federation_reader1
  8050. worker_replication_host: 127.0.0.1
  8051. worker_replication_http_port: 9093
  8052. worker_listeners:
  8053. - type: http
  8054. port: 8011
  8055. resources:
  8056. - names: [federation]
  8057. worker_log_config: /etc/matrix-synapse/federation-reader-log.yaml
  8058. </code></pre>
  8059. <p>Systemd manages daemonization itself, so ensure that none of the configuration
  8060. files set either <code>daemonize</code> or <code>worker_daemonize</code>.</p>
  8061. <p>The config files of all workers are expected to be located in
  8062. <code>/etc/matrix-synapse/workers</code>. If you want to use a different location, edit
  8063. the provided <code>*.service</code> files accordingly.</p>
  8064. <p>There is no need for a separate configuration file for the master process.</p>
  8065. <h2 id="set-up"><a class="header" href="#set-up">Set up</a></h2>
  8066. <ol>
  8067. <li>Adjust synapse configuration files as above.</li>
  8068. <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>
  8069. to <code>/etc/systemd/system</code>.</li>
  8070. <li>Run <code>systemctl daemon-reload</code> to tell systemd to load the new unit files.</li>
  8071. <li>Run <code>systemctl enable matrix-synapse.service</code>. This will configure the
  8072. synapse master process to be started as part of the <code>matrix-synapse.target</code>
  8073. target.</li>
  8074. <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
  8075. should be a corresponding configuration file.
  8076. <code>/etc/matrix-synapse/workers/&lt;worker_name&gt;.yaml</code>.</li>
  8077. <li>Start all the synapse processes with <code>systemctl start matrix-synapse.target</code>.</li>
  8078. <li>Tell systemd to start synapse on boot with <code>systemctl enable matrix-synapse.target</code>.</li>
  8079. </ol>
  8080. <h2 id="usage"><a class="header" href="#usage">Usage</a></h2>
  8081. <p>Once the services are correctly set up, you can use the following commands
  8082. to manage your synapse installation:</p>
  8083. <pre><code class="language-sh"># Restart Synapse master and all workers
  8084. systemctl restart matrix-synapse.target
  8085. # Stop Synapse and all workers
  8086. systemctl stop matrix-synapse.target
  8087. # Restart the master alone
  8088. systemctl start matrix-synapse.service
  8089. # Restart a specific worker (eg. federation_reader); the master is
  8090. # unaffected by this.
  8091. systemctl restart matrix-synapse-worker@federation_reader.service
  8092. # Add a new worker (assuming all configs are set up already)
  8093. systemctl enable matrix-synapse-worker@federation_writer.service
  8094. systemctl restart matrix-synapse.target
  8095. </code></pre>
  8096. <h2 id="hardening"><a class="header" href="#hardening">Hardening</a></h2>
  8097. <p><strong>Optional:</strong> If further hardening is desired, the file
  8098. <code>override-hardened.conf</code> may be copied from
  8099. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/systemd/">contrib/systemd/override-hardened.conf</a>
  8100. in this repository to the location
  8101. <code>/etc/systemd/system/matrix-synapse.service.d/override-hardened.conf</code> (the
  8102. directory may have to be created). It enables certain sandboxing features in
  8103. systemd to further secure the synapse service. You may read the comments to
  8104. understand what the override file is doing. The same file will need to be copied to
  8105. <code>/etc/systemd/system/matrix-synapse-worker@.service.d/override-hardened-worker.conf</code>
  8106. (this directory may also have to be created) in order to apply the same
  8107. hardening options to any worker processes.</p>
  8108. <p>Once these files have been copied to their appropriate locations, simply reload
  8109. systemd's manager config files and restart all Synapse services to apply the hardening options. They will automatically
  8110. be applied at every restart as long as the override files are present at the
  8111. specified locations.</p>
  8112. <pre><code class="language-sh">systemctl daemon-reload
  8113. # Restart services
  8114. systemctl restart matrix-synapse.target
  8115. </code></pre>
  8116. <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
  8117. the changes being applied at a glance.</p>
  8118. <div style="break-before: page; page-break-before: always;"></div><h1 id="administration"><a class="header" href="#administration">Administration</a></h1>
  8119. <p>This section contains information on managing your Synapse homeserver. This includes:</p>
  8120. <ul>
  8121. <li>Managing users, rooms and media via the Admin API.</li>
  8122. <li>Setting up metrics and monitoring to give you insight into your homeserver's health.</li>
  8123. <li>Configuring structured logging.</li>
  8124. </ul>
  8125. <div 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>
  8126. <h2 id="authenticate-as-a-server-admin"><a class="header" href="#authenticate-as-a-server-admin">Authenticate as a server admin</a></h2>
  8127. <p>Many of the API calls in the admin api will require an <code>access_token</code> for a
  8128. server admin. (Note that a server admin is distinct from a room admin.)</p>
  8129. <p>A user can be marked as a server admin by updating the database directly, e.g.:</p>
  8130. <pre><code class="language-sql">UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
  8131. </code></pre>
  8132. <p>A new server admin user can also be created using the <code>register_new_matrix_user</code>
  8133. command. This is a script that is located in the <code>scripts/</code> directory, or possibly
  8134. already on your <code>$PATH</code> depending on how Synapse was installed.</p>
  8135. <p>Finding your user's <code>access_token</code> is client-dependent, but will usually be shown in the client's settings.</p>
  8136. <h2 id="making-an-admin-api-request"><a class="header" href="#making-an-admin-api-request">Making an Admin API request</a></h2>
  8137. <p>Once you have your <code>access_token</code>, you will need to authenticate each request to an Admin API endpoint by
  8138. providing the token as either a query parameter or a request header. To add it as a request header in cURL:</p>
  8139. <pre><code class="language-sh">curl --header &quot;Authorization: Bearer &lt;access_token&gt;&quot; &lt;the_rest_of_your_API_request&gt;
  8140. </code></pre>
  8141. <p>For more details on access tokens in Matrix, please refer to the complete
  8142. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#using-access-tokens">matrix spec documentation</a>.</p>
  8143. <div 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>
  8144. <p>This API allows a server administrator to manage the validity of an account. To
  8145. use it, you must enable the account validity feature (under
  8146. <code>account_validity</code>) in Synapse's configuration.</p>
  8147. <h2 id="renew-account"><a class="header" href="#renew-account">Renew account</a></h2>
  8148. <p>This API extends the validity of an account by as much time as configured in the
  8149. <code>period</code> parameter from the <code>account_validity</code> configuration.</p>
  8150. <p>The API is:</p>
  8151. <pre><code>POST /_synapse/admin/v1/account_validity/validity
  8152. </code></pre>
  8153. <p>with the following body:</p>
  8154. <pre><code class="language-json">{
  8155. &quot;user_id&quot;: &quot;&lt;user ID for the account to renew&gt;&quot;,
  8156. &quot;expiration_ts&quot;: 0,
  8157. &quot;enable_renewal_emails&quot;: true
  8158. }
  8159. </code></pre>
  8160. <p><code>expiration_ts</code> is an optional parameter and overrides the expiration date,
  8161. which otherwise defaults to now + validity period.</p>
  8162. <p><code>enable_renewal_emails</code> is also an optional parameter and enables/disables
  8163. sending renewal emails to the user. Defaults to true.</p>
  8164. <p>The API returns with the new expiration date for this account, as a timestamp in
  8165. milliseconds since epoch:</p>
  8166. <pre><code class="language-json">{
  8167. &quot;expiration_ts&quot;: 0
  8168. }
  8169. </code></pre>
  8170. <div 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>
  8171. <p>This API lets a server admin delete a local group. Doing so will kick all
  8172. users out of the group so that their clients will correctly handle the group
  8173. being deleted.</p>
  8174. <p>The API is:</p>
  8175. <pre><code>POST /_synapse/admin/v1/delete_group/&lt;group_id&gt;
  8176. </code></pre>
  8177. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8178. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8179. <div 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>
  8180. <p>This API returns information about reported events.</p>
  8181. <p>The api is:</p>
  8182. <pre><code>GET /_synapse/admin/v1/event_reports?from=0&amp;limit=10
  8183. </code></pre>
  8184. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8185. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8186. <p>It returns a JSON body like the following:</p>
  8187. <pre><code class="language-json">{
  8188. &quot;event_reports&quot;: [
  8189. {
  8190. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8191. &quot;id&quot;: 2,
  8192. &quot;reason&quot;: &quot;foo&quot;,
  8193. &quot;score&quot;: -100,
  8194. &quot;received_ts&quot;: 1570897107409,
  8195. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8196. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8197. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8198. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8199. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8200. },
  8201. {
  8202. &quot;event_id&quot;: &quot;$3IcdZsDaN_En-S1DF4EMCy3v4gNRKeOJs8W5qTOKj4I&quot;,
  8203. &quot;id&quot;: 3,
  8204. &quot;reason&quot;: &quot;bar&quot;,
  8205. &quot;score&quot;: -100,
  8206. &quot;received_ts&quot;: 1598889612059,
  8207. &quot;canonical_alias&quot;: &quot;#alias2:matrix.org&quot;,
  8208. &quot;room_id&quot;: &quot;!eGvUQuTCkHGVwNMOjv:matrix.org&quot;,
  8209. &quot;name&quot;: &quot;Your room name here&quot;,
  8210. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8211. &quot;user_id&quot;: &quot;@bar:matrix.org&quot;
  8212. }
  8213. ],
  8214. &quot;next_token&quot;: 2,
  8215. &quot;total&quot;: 4
  8216. }
  8217. </code></pre>
  8218. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again with <code>from</code>
  8219. set to the value of <code>next_token</code>. This will return a new page.</p>
  8220. <p>If the endpoint does not return a <code>next_token</code> then there are no more reports to
  8221. paginate through.</p>
  8222. <p><strong>URL parameters:</strong></p>
  8223. <ul>
  8224. <li><code>limit</code>: integer - Is optional but is used for pagination, denoting the maximum number
  8225. of items to return in this call. Defaults to <code>100</code>.</li>
  8226. <li><code>from</code>: integer - Is optional but used for pagination, denoting the offset in the
  8227. returned results. This should be treated as an opaque value and not explicitly set to
  8228. anything other than the return value of <code>next_token</code> from a previous call. Defaults to <code>0</code>.</li>
  8229. <li><code>dir</code>: string - Direction of event report order. Whether to fetch the most recent
  8230. first (<code>b</code>) or the oldest first (<code>f</code>). Defaults to <code>b</code>.</li>
  8231. <li><code>user_id</code>: string - Is optional and filters to only return users with user IDs that
  8232. contain this value. This is the user who reported the event and wrote the reason.</li>
  8233. <li><code>room_id</code>: string - Is optional and filters to only return rooms with room IDs that
  8234. contain this value.</li>
  8235. </ul>
  8236. <p><strong>Response</strong></p>
  8237. <p>The following fields are returned in the JSON response body:</p>
  8238. <ul>
  8239. <li><code>id</code>: integer - ID of event report.</li>
  8240. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8241. report was sent.</li>
  8242. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8243. <li><code>name</code>: string - The name of the room.</li>
  8244. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8245. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8246. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank or <code>null</code>.</li>
  8247. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8248. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;. May be <code>null</code>.</li>
  8249. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8250. was reported.</li>
  8251. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8252. have a canonical alias set.</li>
  8253. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  8254. <li><code>total</code>: integer - Total number of event reports related to the query
  8255. (<code>user_id</code> and <code>room_id</code>).</li>
  8256. </ul>
  8257. <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>
  8258. <p>This API returns information about a specific event report.</p>
  8259. <p>The api is:</p>
  8260. <pre><code>GET /_synapse/admin/v1/event_reports/&lt;report_id&gt;
  8261. </code></pre>
  8262. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8263. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8264. <p>It returns a JSON body like the following:</p>
  8265. <pre><code class="language-jsonc">{
  8266. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8267. &quot;event_json&quot;: {
  8268. &quot;auth_events&quot;: [
  8269. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;,
  8270. &quot;$oggsNXxzPFRE3y53SUNd7nsj69-QzKv03a1RucHu-ws&quot;
  8271. ],
  8272. &quot;content&quot;: {
  8273. &quot;body&quot;: &quot;matrix.org: This Week in Matrix&quot;,
  8274. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  8275. &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;,
  8276. &quot;msgtype&quot;: &quot;m.notice&quot;
  8277. },
  8278. &quot;depth&quot;: 546,
  8279. &quot;hashes&quot;: {
  8280. &quot;sha256&quot;: &quot;xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw&quot;
  8281. },
  8282. &quot;origin&quot;: &quot;matrix.org&quot;,
  8283. &quot;origin_server_ts&quot;: 1592291711430,
  8284. &quot;prev_events&quot;: [
  8285. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;
  8286. ],
  8287. &quot;prev_state&quot;: [],
  8288. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8289. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8290. &quot;signatures&quot;: {
  8291. &quot;matrix.org&quot;: {
  8292. &quot;ed25519:a_JaEG&quot;: &quot;cs+OUKW/iHx5pEidbWxh0UiNNHwe46Ai9LwNz+Ah16aWDNszVIe2gaAcVZfvNsBhakQTew51tlKmL2kspXk/Dg&quot;
  8293. }
  8294. },
  8295. &quot;type&quot;: &quot;m.room.message&quot;,
  8296. &quot;unsigned&quot;: {
  8297. &quot;age_ts&quot;: 1592291711430,
  8298. }
  8299. },
  8300. &quot;id&quot;: &lt;report_id&gt;,
  8301. &quot;reason&quot;: &quot;foo&quot;,
  8302. &quot;score&quot;: -100,
  8303. &quot;received_ts&quot;: 1570897107409,
  8304. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8305. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8306. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8307. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8308. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8309. }
  8310. </code></pre>
  8311. <p><strong>URL parameters:</strong></p>
  8312. <ul>
  8313. <li><code>report_id</code>: string - The ID of the event report.</li>
  8314. </ul>
  8315. <p><strong>Response</strong></p>
  8316. <p>The following fields are returned in the JSON response body:</p>
  8317. <ul>
  8318. <li><code>id</code>: integer - ID of event report.</li>
  8319. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8320. report was sent.</li>
  8321. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8322. <li><code>name</code>: string - The name of the room.</li>
  8323. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8324. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8325. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank.</li>
  8326. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8327. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;.</li>
  8328. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8329. was reported.</li>
  8330. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8331. have a canonical alias set.</li>
  8332. <li><code>event_json</code>: object - Details of the original event that was reported.</li>
  8333. </ul>
  8334. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-1"><a class="header" href="#contents-1">Contents</a></h1>
  8335. <ul>
  8336. <li><a href="admin_api/media_admin_api.html#querying-media">Querying media</a>
  8337. <ul>
  8338. <li><a href="admin_api/media_admin_api.html#list-all-media-in-a-room">List all media in a room</a></li>
  8339. <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>
  8340. </ul>
  8341. </li>
  8342. <li><a href="admin_api/media_admin_api.html#quarantine-media">Quarantine media</a>
  8343. <ul>
  8344. <li><a href="admin_api/media_admin_api.html#quarantining-media-by-id">Quarantining media by ID</a></li>
  8345. <li><a href="admin_api/media_admin_api.html#remove-media-from-quarantine-by-id">Remove media from quarantine by ID</a></li>
  8346. <li><a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">Quarantining media in a room</a></li>
  8347. <li><a href="admin_api/media_admin_api.html#quarantining-all-media-of-a-user">Quarantining all media of a user</a></li>
  8348. <li><a href="admin_api/media_admin_api.html#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></li>
  8349. <li><a href="admin_api/media_admin_api.html#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></li>
  8350. </ul>
  8351. </li>
  8352. <li><a href="admin_api/media_admin_api.html#delete-local-media">Delete local media</a>
  8353. <ul>
  8354. <li><a href="admin_api/media_admin_api.html#delete-a-specific-local-media">Delete a specific local media</a></li>
  8355. <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>
  8356. <li><a href="admin_api/media_admin_api.html#delete-media-uploaded-by-a-user">Delete media uploaded by a user</a></li>
  8357. </ul>
  8358. </li>
  8359. <li><a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a></li>
  8360. </ul>
  8361. <h1 id="querying-media"><a class="header" href="#querying-media">Querying media</a></h1>
  8362. <p>These APIs allow extracting media information from the homeserver.</p>
  8363. <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>
  8364. <p>This API gets a list of known media in a room.
  8365. However, it only shows media from unencrypted events or rooms.</p>
  8366. <p>The API is:</p>
  8367. <pre><code>GET /_synapse/admin/v1/room/&lt;room_id&gt;/media
  8368. </code></pre>
  8369. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8370. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8371. <p>The API returns a JSON body like the following:</p>
  8372. <pre><code class="language-json">{
  8373. &quot;local&quot;: [
  8374. &quot;mxc://localhost/xwvutsrqponmlkjihgfedcba&quot;,
  8375. &quot;mxc://localhost/abcdefghijklmnopqrstuvwx&quot;
  8376. ],
  8377. &quot;remote&quot;: [
  8378. &quot;mxc://matrix.org/xwvutsrqponmlkjihgfedcba&quot;,
  8379. &quot;mxc://matrix.org/abcdefghijklmnopqrstuvwx&quot;
  8380. ]
  8381. }
  8382. </code></pre>
  8383. <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>
  8384. <p>Listing all media that has been uploaded by a local user can be achieved through
  8385. the use of the
  8386. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>
  8387. Admin API.</p>
  8388. <h1 id="quarantine-media"><a class="header" href="#quarantine-media">Quarantine media</a></h1>
  8389. <p>Quarantining media means that it is marked as inaccessible by users. It applies
  8390. to any local media, and any locally-cached copies of remote media.</p>
  8391. <p>The media file itself (and any thumbnails) is not deleted from the server.</p>
  8392. <h2 id="quarantining-media-by-id"><a class="header" href="#quarantining-media-by-id">Quarantining media by ID</a></h2>
  8393. <p>This API quarantines a single piece of local or remote media.</p>
  8394. <p>Request:</p>
  8395. <pre><code>POST /_synapse/admin/v1/media/quarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8396. {}
  8397. </code></pre>
  8398. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8399. form of <code>abcdefg12345...</code>.</p>
  8400. <p>Response:</p>
  8401. <pre><code class="language-json">{}
  8402. </code></pre>
  8403. <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>
  8404. <p>This API removes a single piece of local or remote media from quarantine.</p>
  8405. <p>Request:</p>
  8406. <pre><code>POST /_synapse/admin/v1/media/unquarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8407. {}
  8408. </code></pre>
  8409. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8410. form of <code>abcdefg12345...</code>.</p>
  8411. <p>Response:</p>
  8412. <pre><code class="language-json">{}
  8413. </code></pre>
  8414. <h2 id="quarantining-media-in-a-room"><a class="header" href="#quarantining-media-in-a-room">Quarantining media in a room</a></h2>
  8415. <p>This API quarantines all local and remote media in a room.</p>
  8416. <p>Request:</p>
  8417. <pre><code>POST /_synapse/admin/v1/room/&lt;room_id&gt;/media/quarantine
  8418. {}
  8419. </code></pre>
  8420. <p>Where <code>room_id</code> is in the form of <code>!roomid12345:example.org</code>.</p>
  8421. <p>Response:</p>
  8422. <pre><code class="language-json">{
  8423. &quot;num_quarantined&quot;: 10
  8424. }
  8425. </code></pre>
  8426. <p>The following fields are returned in the JSON response body:</p>
  8427. <ul>
  8428. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8429. </ul>
  8430. <p>Note that there is a legacy endpoint, <code>POST /_synapse/admin/v1/quarantine_media/&lt;room_id&gt;</code>, that operates the same.
  8431. However, it is deprecated and may be removed in a future release.</p>
  8432. <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>
  8433. <p>This API quarantines all <em>local</em> media that a <em>local</em> user has uploaded. That is to say, if
  8434. you would like to quarantine media uploaded by a user on a remote homeserver, you should
  8435. instead use one of the other APIs.</p>
  8436. <p>Request:</p>
  8437. <pre><code>POST /_synapse/admin/v1/user/&lt;user_id&gt;/media/quarantine
  8438. {}
  8439. </code></pre>
  8440. <p>URL Parameters</p>
  8441. <ul>
  8442. <li><code>user_id</code>: string - User ID in the form of <code>@bob:example.org</code></li>
  8443. </ul>
  8444. <p>Response:</p>
  8445. <pre><code class="language-json">{
  8446. &quot;num_quarantined&quot;: 10
  8447. }
  8448. </code></pre>
  8449. <p>The following fields are returned in the JSON response body:</p>
  8450. <ul>
  8451. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8452. </ul>
  8453. <h2 id="protecting-media-from-being-quarantined"><a class="header" href="#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></h2>
  8454. <p>This API protects a single piece of local media from being quarantined using the
  8455. above APIs. This is useful for sticker packs and other shared media which you do
  8456. not want to get quarantined, especially when
  8457. <a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">quarantining media in a room</a>.</p>
  8458. <p>Request:</p>
  8459. <pre><code>POST /_synapse/admin/v1/media/protect/&lt;media_id&gt;
  8460. {}
  8461. </code></pre>
  8462. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8463. <p>Response:</p>
  8464. <pre><code class="language-json">{}
  8465. </code></pre>
  8466. <h2 id="unprotecting-media-from-being-quarantined"><a class="header" href="#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></h2>
  8467. <p>This API reverts the protection of a media.</p>
  8468. <p>Request:</p>
  8469. <pre><code>POST /_synapse/admin/v1/media/unprotect/&lt;media_id&gt;
  8470. {}
  8471. </code></pre>
  8472. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8473. <p>Response:</p>
  8474. <pre><code class="language-json">{}
  8475. </code></pre>
  8476. <h1 id="delete-local-media"><a class="header" href="#delete-local-media">Delete local media</a></h1>
  8477. <p>This API deletes the <em>local</em> media from the disk of your own server.
  8478. This includes any local thumbnails and copies of media downloaded from
  8479. remote homeservers.
  8480. This API will not affect media that has been uploaded to external
  8481. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
  8482. See also <a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a>.</p>
  8483. <h2 id="delete-a-specific-local-media"><a class="header" href="#delete-a-specific-local-media">Delete a specific local media</a></h2>
  8484. <p>Delete a specific <code>media_id</code>.</p>
  8485. <p>Request:</p>
  8486. <pre><code>DELETE /_synapse/admin/v1/media/&lt;server_name&gt;/&lt;media_id&gt;
  8487. {}
  8488. </code></pre>
  8489. <p>URL Parameters</p>
  8490. <ul>
  8491. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>)</li>
  8492. <li><code>media_id</code>: string - The ID of the media (e.g <code>abcdefghijklmnopqrstuvwx</code>)</li>
  8493. </ul>
  8494. <p>Response:</p>
  8495. <pre><code class="language-json">{
  8496. &quot;deleted_media&quot;: [
  8497. &quot;abcdefghijklmnopqrstuvwx&quot;
  8498. ],
  8499. &quot;total&quot;: 1
  8500. }
  8501. </code></pre>
  8502. <p>The following fields are returned in the JSON response body:</p>
  8503. <ul>
  8504. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8505. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8506. </ul>
  8507. <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>
  8508. <p>Request:</p>
  8509. <pre><code>POST /_synapse/admin/v1/media/&lt;server_name&gt;/delete?before_ts=&lt;before_ts&gt;
  8510. {}
  8511. </code></pre>
  8512. <p>URL Parameters</p>
  8513. <ul>
  8514. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>).</li>
  8515. <li><code>before_ts</code>: string representing a positive integer - Unix timestamp in ms.
  8516. Files that were last used before this timestamp will be deleted. It is the timestamp of
  8517. last access and not the timestamp creation.</li>
  8518. <li><code>size_gt</code>: Optional - string representing a positive integer - Size of the media in bytes.
  8519. Files that are larger will be deleted. Defaults to <code>0</code>.</li>
  8520. <li><code>keep_profiles</code>: Optional - string representing a boolean - Switch to also delete files
  8521. that are still used in image data (e.g user profile, room avatar).
  8522. If <code>false</code> these files will be deleted. Defaults to <code>true</code>.</li>
  8523. </ul>
  8524. <p>Response:</p>
  8525. <pre><code class="language-json">{
  8526. &quot;deleted_media&quot;: [
  8527. &quot;abcdefghijklmnopqrstuvwx&quot;,
  8528. &quot;abcdefghijklmnopqrstuvwz&quot;
  8529. ],
  8530. &quot;total&quot;: 2
  8531. }
  8532. </code></pre>
  8533. <p>The following fields are returned in the JSON response body:</p>
  8534. <ul>
  8535. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8536. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8537. </ul>
  8538. <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>
  8539. <p>You can find details of how to delete multiple media uploaded by a user in
  8540. <a href="admin_api/user_admin_api.html#delete-media-uploaded-by-a-user">User Admin API</a>.</p>
  8541. <h1 id="purge-remote-media-api"><a class="header" href="#purge-remote-media-api">Purge Remote Media API</a></h1>
  8542. <p>The purge remote media API allows server admins to purge old cached remote media.</p>
  8543. <p>The API is:</p>
  8544. <pre><code>POST /_synapse/admin/v1/purge_media_cache?before_ts=&lt;unix_timestamp_in_ms&gt;
  8545. {}
  8546. </code></pre>
  8547. <p>URL Parameters</p>
  8548. <ul>
  8549. <li><code>unix_timestamp_in_ms</code>: string representing a positive integer - Unix timestamp in ms.
  8550. All cached media that was last accessed before this timestamp will be removed.</li>
  8551. </ul>
  8552. <p>Response:</p>
  8553. <pre><code class="language-json">{
  8554. &quot;deleted&quot;: 10
  8555. }
  8556. </code></pre>
  8557. <p>The following fields are returned in the JSON response body:</p>
  8558. <ul>
  8559. <li><code>deleted</code>: integer - The number of media items successfully deleted</li>
  8560. </ul>
  8561. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8562. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8563. <p>If the user re-requests purged remote media, synapse will re-request the media
  8564. from the originating server.</p>
  8565. <div 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>
  8566. <p>The purge history API allows server admins to purge historic events from their
  8567. database, reclaiming disk space.</p>
  8568. <p>Depending on the amount of history being purged a call to the API may take
  8569. several minutes or longer. During this period users will not be able to
  8570. paginate further back in the room from the point being purged from.</p>
  8571. <p>Note that Synapse requires at least one message in each room, so it will never
  8572. delete the last message in a room.</p>
  8573. <p>The API is:</p>
  8574. <pre><code>POST /_synapse/admin/v1/purge_history/&lt;room_id&gt;[/&lt;event_id&gt;]
  8575. </code></pre>
  8576. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8577. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  8578. <p>By default, events sent by local users are not deleted, as they may represent
  8579. the only copies of this content in existence. (Events sent by remote users are
  8580. deleted.)</p>
  8581. <p>Room state data (such as joins, leaves, topic) is always preserved.</p>
  8582. <p>To delete local message events as well, set <code>delete_local_events</code> in the body:</p>
  8583. <pre><code>{
  8584. &quot;delete_local_events&quot;: true
  8585. }
  8586. </code></pre>
  8587. <p>The caller must specify the point in the room to purge up to. This can be
  8588. specified by including an event_id in the URI, or by setting a
  8589. <code>purge_up_to_event_id</code> or <code>purge_up_to_ts</code> in the request body. If an event
  8590. id is given, that event (and others at the same graph depth) will be retained.
  8591. If <code>purge_up_to_ts</code> is given, it should be a timestamp since the unix epoch,
  8592. in milliseconds.</p>
  8593. <p>The API starts the purge running, and returns immediately with a JSON body with
  8594. a purge id:</p>
  8595. <pre><code class="language-json">{
  8596. &quot;purge_id&quot;: &quot;&lt;opaque id&gt;&quot;
  8597. }
  8598. </code></pre>
  8599. <h2 id="purge-status-query"><a class="header" href="#purge-status-query">Purge status query</a></h2>
  8600. <p>It is possible to poll for updates on recent purges with a second API;</p>
  8601. <pre><code>GET /_synapse/admin/v1/purge_history_status/&lt;purge_id&gt;
  8602. </code></pre>
  8603. <p>Again, you will need to authenticate by providing an <code>access_token</code> for a
  8604. server admin.</p>
  8605. <p>This API returns a JSON body like the following:</p>
  8606. <pre><code class="language-json">{
  8607. &quot;status&quot;: &quot;active&quot;
  8608. }
  8609. </code></pre>
  8610. <p>The status will be one of <code>active</code>, <code>complete</code>, or <code>failed</code>.</p>
  8611. <h2 id="reclaim-disk-space-postgres"><a class="header" href="#reclaim-disk-space-postgres">Reclaim disk space (Postgres)</a></h2>
  8612. <p>To reclaim the disk space and return it to the operating system, you need to run
  8613. <code>VACUUM FULL;</code> on the database.</p>
  8614. <p><a href="https://www.postgresql.org/docs/current/sql-vacuum.html">https://www.postgresql.org/docs/current/sql-vacuum.html</a></p>
  8615. <div 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>
  8616. <p>This API allows for the creation of users in an administrative and
  8617. non-interactive way. This is generally used for bootstrapping a Synapse
  8618. instance with administrator accounts.</p>
  8619. <p>To authenticate yourself to the server, you will need both the shared secret
  8620. (<code>registration_shared_secret</code> in the homeserver configuration), and a
  8621. one-time nonce. If the registration shared secret is not configured, this API
  8622. is not enabled.</p>
  8623. <p>To fetch the nonce, you need to request one from the API:</p>
  8624. <pre><code>&gt; GET /_synapse/admin/v1/register
  8625. &lt; {&quot;nonce&quot;: &quot;thisisanonce&quot;}
  8626. </code></pre>
  8627. <p>Once you have the nonce, you can make a <code>POST</code> to the same URL with a JSON
  8628. body containing the nonce, username, password, whether they are an admin
  8629. (optional, False by default), and a HMAC digest of the content. Also you can
  8630. set the displayname (optional, <code>username</code> by default).</p>
  8631. <p>As an example:</p>
  8632. <pre><code>&gt; POST /_synapse/admin/v1/register
  8633. &gt; {
  8634. &quot;nonce&quot;: &quot;thisisanonce&quot;,
  8635. &quot;username&quot;: &quot;pepper_roni&quot;,
  8636. &quot;displayname&quot;: &quot;Pepper Roni&quot;,
  8637. &quot;password&quot;: &quot;pizza&quot;,
  8638. &quot;admin&quot;: true,
  8639. &quot;mac&quot;: &quot;mac_digest_here&quot;
  8640. }
  8641. &lt; {
  8642. &quot;access_token&quot;: &quot;token_here&quot;,
  8643. &quot;user_id&quot;: &quot;@pepper_roni:localhost&quot;,
  8644. &quot;home_server&quot;: &quot;test&quot;,
  8645. &quot;device_id&quot;: &quot;device_id_here&quot;
  8646. }
  8647. </code></pre>
  8648. <p>The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
  8649. the shared secret and the content being the nonce, user, password, either the
  8650. string &quot;admin&quot; or &quot;notadmin&quot;, and optionally the user_type
  8651. each separated by NULs. For an example of generation in Python:</p>
  8652. <pre><code class="language-python">import hmac, hashlib
  8653. def generate_mac(nonce, user, password, admin=False, user_type=None):
  8654. mac = hmac.new(
  8655. key=shared_secret,
  8656. digestmod=hashlib.sha1,
  8657. )
  8658. mac.update(nonce.encode('utf8'))
  8659. mac.update(b&quot;\x00&quot;)
  8660. mac.update(user.encode('utf8'))
  8661. mac.update(b&quot;\x00&quot;)
  8662. mac.update(password.encode('utf8'))
  8663. mac.update(b&quot;\x00&quot;)
  8664. mac.update(b&quot;admin&quot; if admin else b&quot;notadmin&quot;)
  8665. if user_type:
  8666. mac.update(b&quot;\x00&quot;)
  8667. mac.update(user_type.encode('utf8'))
  8668. return mac.hexdigest()
  8669. </code></pre>
  8670. <div style="break-before: page; page-break-before: always;"></div><h1 id="registration-tokens"><a class="header" href="#registration-tokens">Registration Tokens</a></h1>
  8671. <p>This API allows you to manage tokens which can be used to authenticate
  8672. registration requests, as proposed in <a href="https://github.com/govynnus/matrix-doc/blob/token-registration/proposals/3231-token-authenticated-registration.md">MSC3231</a>.
  8673. To use it, you will need to enable the <code>registration_requires_token</code> config
  8674. option, and authenticate by providing an <code>access_token</code> for a server admin:
  8675. see <a href="usage/administration/admin_api/../../usage/administration/admin_api">Admin API</a>.
  8676. Note that this API is still experimental; not all clients may support it yet.</p>
  8677. <h2 id="registration-token-objects"><a class="header" href="#registration-token-objects">Registration token objects</a></h2>
  8678. <p>Most endpoints make use of JSON objects that contain details about tokens.
  8679. These objects have the following fields:</p>
  8680. <ul>
  8681. <li><code>token</code>: The token which can be used to authenticate registration.</li>
  8682. <li><code>uses_allowed</code>: The number of times the token can be used to complete a
  8683. registration before it becomes invalid.</li>
  8684. <li><code>pending</code>: The number of pending uses the token has. When someone uses
  8685. the token to authenticate themselves, the pending counter is incremented
  8686. so that the token is not used more than the permitted number of times.
  8687. When the person completes registration the pending counter is decremented,
  8688. and the completed counter is incremented.</li>
  8689. <li><code>completed</code>: The number of times the token has been used to successfully
  8690. complete a registration.</li>
  8691. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  8692. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  8693. To convert this into a human-readable form you can remove the milliseconds
  8694. and use the <code>date</code> command. For example, <code>date -d '@1625394937'</code>.</li>
  8695. </ul>
  8696. <h2 id="list-all-tokens"><a class="header" href="#list-all-tokens">List all tokens</a></h2>
  8697. <p>Lists all tokens and details about them. If the request is successful, the top
  8698. level JSON object will have a <code>registration_tokens</code> key which is an array of
  8699. registration token objects.</p>
  8700. <pre><code>GET /_synapse/admin/v1/registration_tokens
  8701. </code></pre>
  8702. <p>Optional query parameters:</p>
  8703. <ul>
  8704. <li><code>valid</code>: <code>true</code> or <code>false</code>. If <code>true</code>, only valid tokens are returned.
  8705. If <code>false</code>, only tokens that have expired or have had all uses exhausted are
  8706. returned. If omitted, all tokens are returned regardless of validity.</li>
  8707. </ul>
  8708. <p>Example:</p>
  8709. <pre><code>GET /_synapse/admin/v1/registration_tokens
  8710. </code></pre>
  8711. <pre><code>200 OK
  8712. {
  8713. &quot;registration_tokens&quot;: [
  8714. {
  8715. &quot;token&quot;: &quot;abcd&quot;,
  8716. &quot;uses_allowed&quot;: 3,
  8717. &quot;pending&quot;: 0,
  8718. &quot;completed&quot;: 1,
  8719. &quot;expiry_time&quot;: null
  8720. },
  8721. {
  8722. &quot;token&quot;: &quot;pqrs&quot;,
  8723. &quot;uses_allowed&quot;: 2,
  8724. &quot;pending&quot;: 1,
  8725. &quot;completed&quot;: 1,
  8726. &quot;expiry_time&quot;: null
  8727. },
  8728. {
  8729. &quot;token&quot;: &quot;wxyz&quot;,
  8730. &quot;uses_allowed&quot;: null,
  8731. &quot;pending&quot;: 0,
  8732. &quot;completed&quot;: 9,
  8733. &quot;expiry_time&quot;: 1625394937000 // 2021-07-04 10:35:37 UTC
  8734. }
  8735. ]
  8736. }
  8737. </code></pre>
  8738. <p>Example using the <code>valid</code> query parameter:</p>
  8739. <pre><code>GET /_synapse/admin/v1/registration_tokens?valid=false
  8740. </code></pre>
  8741. <pre><code>200 OK
  8742. {
  8743. &quot;registration_tokens&quot;: [
  8744. {
  8745. &quot;token&quot;: &quot;pqrs&quot;,
  8746. &quot;uses_allowed&quot;: 2,
  8747. &quot;pending&quot;: 1,
  8748. &quot;completed&quot;: 1,
  8749. &quot;expiry_time&quot;: null
  8750. },
  8751. {
  8752. &quot;token&quot;: &quot;wxyz&quot;,
  8753. &quot;uses_allowed&quot;: null,
  8754. &quot;pending&quot;: 0,
  8755. &quot;completed&quot;: 9,
  8756. &quot;expiry_time&quot;: 1625394937000 // 2021-07-04 10:35:37 UTC
  8757. }
  8758. ]
  8759. }
  8760. </code></pre>
  8761. <h2 id="get-one-token"><a class="header" href="#get-one-token">Get one token</a></h2>
  8762. <p>Get details about a single token. If the request is successful, the response
  8763. body will be a registration token object.</p>
  8764. <pre><code>GET /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  8765. </code></pre>
  8766. <p>Path parameters:</p>
  8767. <ul>
  8768. <li><code>token</code>: The registration token to return details of.</li>
  8769. </ul>
  8770. <p>Example:</p>
  8771. <pre><code>GET /_synapse/admin/v1/registration_tokens/abcd
  8772. </code></pre>
  8773. <pre><code>200 OK
  8774. {
  8775. &quot;token&quot;: &quot;abcd&quot;,
  8776. &quot;uses_allowed&quot;: 3,
  8777. &quot;pending&quot;: 0,
  8778. &quot;completed&quot;: 1,
  8779. &quot;expiry_time&quot;: null
  8780. }
  8781. </code></pre>
  8782. <h2 id="create-token"><a class="header" href="#create-token">Create token</a></h2>
  8783. <p>Create a new registration token. If the request is successful, the newly created
  8784. token will be returned as a registration token object in the response body.</p>
  8785. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  8786. </code></pre>
  8787. <p>The request body must be a JSON object and can contain the following fields:</p>
  8788. <ul>
  8789. <li><code>token</code>: The registration token. A string of no more than 64 characters that
  8790. consists only of characters matched by the regex <code>[A-Za-z0-9-_]</code>.
  8791. Default: randomly generated.</li>
  8792. <li><code>uses_allowed</code>: The integer number of times the token can be used to complete
  8793. a registration before it becomes invalid.
  8794. Default: <code>null</code> (unlimited uses).</li>
  8795. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  8796. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  8797. You could use, for example, <code>date '+%s000' -d 'tomorrow'</code>.
  8798. Default: <code>null</code> (token does not expire).</li>
  8799. <li><code>length</code>: The length of the token randomly generated if <code>token</code> is not
  8800. specified. Must be between 1 and 64 inclusive. Default: <code>16</code>.</li>
  8801. </ul>
  8802. <p>If a field is omitted the default is used.</p>
  8803. <p>Example using defaults:</p>
  8804. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  8805. {}
  8806. </code></pre>
  8807. <pre><code>200 OK
  8808. {
  8809. &quot;token&quot;: &quot;0M-9jbkf2t_Tgiw1&quot;,
  8810. &quot;uses_allowed&quot;: null,
  8811. &quot;pending&quot;: 0,
  8812. &quot;completed&quot;: 0,
  8813. &quot;expiry_time&quot;: null
  8814. }
  8815. </code></pre>
  8816. <p>Example specifying some fields:</p>
  8817. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  8818. {
  8819. &quot;token&quot;: &quot;defg&quot;,
  8820. &quot;uses_allowed&quot;: 1
  8821. }
  8822. </code></pre>
  8823. <pre><code>200 OK
  8824. {
  8825. &quot;token&quot;: &quot;defg&quot;,
  8826. &quot;uses_allowed&quot;: 1,
  8827. &quot;pending&quot;: 0,
  8828. &quot;completed&quot;: 0,
  8829. &quot;expiry_time&quot;: null
  8830. }
  8831. </code></pre>
  8832. <h2 id="update-token"><a class="header" href="#update-token">Update token</a></h2>
  8833. <p>Update the number of allowed uses or expiry time of a token. If the request is
  8834. successful, the updated token will be returned as a registration token object
  8835. in the response body.</p>
  8836. <pre><code>PUT /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  8837. </code></pre>
  8838. <p>Path parameters:</p>
  8839. <ul>
  8840. <li><code>token</code>: The registration token to update.</li>
  8841. </ul>
  8842. <p>The request body must be a JSON object and can contain the following fields:</p>
  8843. <ul>
  8844. <li><code>uses_allowed</code>: The integer number of times the token can be used to complete
  8845. a registration before it becomes invalid. By setting <code>uses_allowed</code> to <code>0</code>
  8846. the token can be easily made invalid without deleting it.
  8847. If <code>null</code> the token will have an unlimited number of uses.</li>
  8848. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  8849. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  8850. If <code>null</code> the token will not expire.</li>
  8851. </ul>
  8852. <p>If a field is omitted its value is not modified.</p>
  8853. <p>Example:</p>
  8854. <pre><code>PUT /_synapse/admin/v1/registration_tokens/defg
  8855. {
  8856. &quot;expiry_time&quot;: 4781243146000 // 2121-07-06 11:05:46 UTC
  8857. }
  8858. </code></pre>
  8859. <pre><code>200 OK
  8860. {
  8861. &quot;token&quot;: &quot;defg&quot;,
  8862. &quot;uses_allowed&quot;: 1,
  8863. &quot;pending&quot;: 0,
  8864. &quot;completed&quot;: 0,
  8865. &quot;expiry_time&quot;: 4781243146000
  8866. }
  8867. </code></pre>
  8868. <h2 id="delete-token"><a class="header" href="#delete-token">Delete token</a></h2>
  8869. <p>Delete a registration token. If the request is successful, the response body
  8870. will be an empty JSON object.</p>
  8871. <pre><code>DELETE /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  8872. </code></pre>
  8873. <p>Path parameters:</p>
  8874. <ul>
  8875. <li><code>token</code>: The registration token to delete.</li>
  8876. </ul>
  8877. <p>Example:</p>
  8878. <pre><code>DELETE /_synapse/admin/v1/registration_tokens/wxyz
  8879. </code></pre>
  8880. <pre><code>200 OK
  8881. {}
  8882. </code></pre>
  8883. <h2 id="errors"><a class="header" href="#errors">Errors</a></h2>
  8884. <p>If a request fails a &quot;standard error response&quot; will be returned as defined in
  8885. the <a href="https://matrix.org/docs/spec/client_server/r0.6.1#api-standards">Matrix Client-Server API specification</a>.</p>
  8886. <p>For example, if the token specified in a path parameter does not exist a
  8887. <code>404 Not Found</code> error will be returned.</p>
  8888. <pre><code>GET /_synapse/admin/v1/registration_tokens/1234
  8889. </code></pre>
  8890. <pre><code>404 Not Found
  8891. {
  8892. &quot;errcode&quot;: &quot;M_NOT_FOUND&quot;,
  8893. &quot;error&quot;: &quot;No such registration token: 1234&quot;
  8894. }
  8895. </code></pre>
  8896. <div 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>
  8897. <p>This API allows an administrator to join an user account with a given <code>user_id</code>
  8898. to a room with a given <code>room_id_or_alias</code>. You can only modify the membership of
  8899. local users. The server administrator must be in the room and have permission to
  8900. invite users.</p>
  8901. <h2 id="parameters"><a class="header" href="#parameters">Parameters</a></h2>
  8902. <p>The following parameters are available:</p>
  8903. <ul>
  8904. <li><code>user_id</code> - Fully qualified user: for example, <code>@user:server.com</code>.</li>
  8905. <li><code>room_id_or_alias</code> - The room identifier or alias to join: for example,
  8906. <code>!636q39766251:server.com</code>.</li>
  8907. </ul>
  8908. <h2 id="usage-1"><a class="header" href="#usage-1">Usage</a></h2>
  8909. <pre><code>POST /_synapse/admin/v1/join/&lt;room_id_or_alias&gt;
  8910. {
  8911. &quot;user_id&quot;: &quot;@user:server.com&quot;
  8912. }
  8913. </code></pre>
  8914. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8915. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8916. <p>Response:</p>
  8917. <pre><code>{
  8918. &quot;room_id&quot;: &quot;!636q39766251:server.com&quot;
  8919. }
  8920. </code></pre>
  8921. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-2"><a class="header" href="#contents-2">Contents</a></h1>
  8922. <ul>
  8923. <li><a href="admin_api/rooms.html#list-room-api">List Room API</a></li>
  8924. <li><a href="admin_api/rooms.html#room-details-api">Room Details API</a></li>
  8925. <li><a href="admin_api/rooms.html#room-members-api">Room Members API</a></li>
  8926. <li><a href="admin_api/rooms.html#room-state-api">Room State API</a></li>
  8927. <li><a href="admin_api/rooms.html#delete-room-api">Delete Room API</a>
  8928. <ul>
  8929. <li><a href="admin_api/rooms.html#undoing-room-shutdowns">Undoing room shutdowns</a></li>
  8930. </ul>
  8931. </li>
  8932. <li><a href="admin_api/rooms.html#make-room-admin-api">Make Room Admin API</a></li>
  8933. <li><a href="admin_api/rooms.html#forward-extremities-admin-api">Forward Extremities Admin API</a></li>
  8934. <li><a href="admin_api/rooms.html#event-context-api">Event Context API</a></li>
  8935. </ul>
  8936. <h1 id="list-room-api"><a class="header" href="#list-room-api">List Room API</a></h1>
  8937. <p>The List Room admin API allows server admins to get a list of rooms on their
  8938. server. There are various parameters available that allow for filtering and
  8939. sorting the returned list. This API supports pagination.</p>
  8940. <p><strong>Parameters</strong></p>
  8941. <p>The following query parameters are available:</p>
  8942. <ul>
  8943. <li><code>from</code> - Offset in the returned list. Defaults to <code>0</code>.</li>
  8944. <li><code>limit</code> - Maximum amount of rooms to return. Defaults to <code>100</code>.</li>
  8945. <li><code>order_by</code> - The method in which to sort the returned list of rooms. Valid values are:
  8946. <ul>
  8947. <li><code>alphabetical</code> - Same as <code>name</code>. This is deprecated.</li>
  8948. <li><code>size</code> - Same as <code>joined_members</code>. This is deprecated.</li>
  8949. <li><code>name</code> - Rooms are ordered alphabetically by room name. This is the default.</li>
  8950. <li><code>canonical_alias</code> - Rooms are ordered alphabetically by main alias address of the room.</li>
  8951. <li><code>joined_members</code> - Rooms are ordered by the number of members. Largest to smallest.</li>
  8952. <li><code>joined_local_members</code> - Rooms are ordered by the number of local members. Largest to smallest.</li>
  8953. <li><code>version</code> - Rooms are ordered by room version. Largest to smallest.</li>
  8954. <li><code>creator</code> - Rooms are ordered alphabetically by creator of the room.</li>
  8955. <li><code>encryption</code> - Rooms are ordered alphabetically by the end-to-end encryption algorithm.</li>
  8956. <li><code>federatable</code> - Rooms are ordered by whether the room is federatable.</li>
  8957. <li><code>public</code> - Rooms are ordered by visibility in room list.</li>
  8958. <li><code>join_rules</code> - Rooms are ordered alphabetically by join rules of the room.</li>
  8959. <li><code>guest_access</code> - Rooms are ordered alphabetically by guest access option of the room.</li>
  8960. <li><code>history_visibility</code> - Rooms are ordered alphabetically by visibility of history of the room.</li>
  8961. <li><code>state_events</code> - Rooms are ordered by number of state events. Largest to smallest.</li>
  8962. </ul>
  8963. </li>
  8964. <li><code>dir</code> - Direction of room order. Either <code>f</code> for forwards or <code>b</code> for backwards. Setting
  8965. this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  8966. <li><code>search_term</code> - Filter rooms by their room name. Search term can be contained in any
  8967. part of the room name. Defaults to no filtering.</li>
  8968. </ul>
  8969. <p><strong>Response</strong></p>
  8970. <p>The following fields are possible in the JSON response body:</p>
  8971. <ul>
  8972. <li><code>rooms</code> - An array of objects, each containing information about a room.
  8973. <ul>
  8974. <li>Room objects contain the following fields:
  8975. <ul>
  8976. <li><code>room_id</code> - The ID of the room.</li>
  8977. <li><code>name</code> - The name of the room.</li>
  8978. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  8979. <li><code>joined_members</code> - How many users are currently in the room.</li>
  8980. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  8981. <li><code>version</code> - The version of the room as a string.</li>
  8982. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  8983. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  8984. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  8985. <li><code>public</code> - Whether the room is visible in room directory.</li>
  8986. <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>
  8987. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  8988. <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>
  8989. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  8990. </ul>
  8991. </li>
  8992. </ul>
  8993. </li>
  8994. <li><code>offset</code> - The current pagination offset in rooms. This parameter should be
  8995. used instead of <code>next_token</code> for room offset as <code>next_token</code> is
  8996. not intended to be parsed.</li>
  8997. <li><code>total_rooms</code> - The total number of rooms this query can return. Using this
  8998. and <code>offset</code>, you have enough information to know the current
  8999. progression through the list.</li>
  9000. <li><code>next_batch</code> - If this field is present, we know that there are potentially
  9001. more rooms on the server that did not all fit into this response.
  9002. We can use <code>next_batch</code> to get the &quot;next page&quot; of results. To do
  9003. so, simply repeat your request, setting the <code>from</code> parameter to
  9004. the value of <code>next_batch</code>.</li>
  9005. <li><code>prev_batch</code> - If this field is present, it is possible to paginate backwards.
  9006. Use <code>prev_batch</code> for the <code>from</code> value in the next request to
  9007. get the &quot;previous page&quot; of results.</li>
  9008. </ul>
  9009. <p>The API is:</p>
  9010. <p>A standard request with no filtering:</p>
  9011. <pre><code>GET /_synapse/admin/v1/rooms
  9012. </code></pre>
  9013. <p>A response body like the following is returned:</p>
  9014. <pre><code class="language-jsonc">{
  9015. &quot;rooms&quot;: [
  9016. {
  9017. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  9018. &quot;name&quot;: &quot;Matrix HQ&quot;,
  9019. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  9020. &quot;joined_members&quot;: 8326,
  9021. &quot;joined_local_members&quot;: 2,
  9022. &quot;version&quot;: &quot;1&quot;,
  9023. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9024. &quot;encryption&quot;: null,
  9025. &quot;federatable&quot;: true,
  9026. &quot;public&quot;: true,
  9027. &quot;join_rules&quot;: &quot;invite&quot;,
  9028. &quot;guest_access&quot;: null,
  9029. &quot;history_visibility&quot;: &quot;shared&quot;,
  9030. &quot;state_events&quot;: 93534
  9031. },
  9032. ... (8 hidden items) ...
  9033. {
  9034. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9035. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9036. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9037. &quot;joined_members&quot;: 314,
  9038. &quot;joined_local_members&quot;: 20,
  9039. &quot;version&quot;: &quot;4&quot;,
  9040. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9041. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9042. &quot;federatable&quot;: true,
  9043. &quot;public&quot;: false,
  9044. &quot;join_rules&quot;: &quot;invite&quot;,
  9045. &quot;guest_access&quot;: null,
  9046. &quot;history_visibility&quot;: &quot;shared&quot;,
  9047. &quot;state_events&quot;: 8345
  9048. }
  9049. ],
  9050. &quot;offset&quot;: 0,
  9051. &quot;total_rooms&quot;: 10
  9052. }
  9053. </code></pre>
  9054. <p>Filtering by room name:</p>
  9055. <pre><code>GET /_synapse/admin/v1/rooms?search_term=TWIM
  9056. </code></pre>
  9057. <p>A response body like the following is returned:</p>
  9058. <pre><code class="language-json">{
  9059. &quot;rooms&quot;: [
  9060. {
  9061. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9062. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9063. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9064. &quot;joined_members&quot;: 314,
  9065. &quot;joined_local_members&quot;: 20,
  9066. &quot;version&quot;: &quot;4&quot;,
  9067. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9068. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9069. &quot;federatable&quot;: true,
  9070. &quot;public&quot;: false,
  9071. &quot;join_rules&quot;: &quot;invite&quot;,
  9072. &quot;guest_access&quot;: null,
  9073. &quot;history_visibility&quot;: &quot;shared&quot;,
  9074. &quot;state_events&quot;: 8
  9075. }
  9076. ],
  9077. &quot;offset&quot;: 0,
  9078. &quot;total_rooms&quot;: 1
  9079. }
  9080. </code></pre>
  9081. <p>Paginating through a list of rooms:</p>
  9082. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size
  9083. </code></pre>
  9084. <p>A response body like the following is returned:</p>
  9085. <pre><code class="language-jsonc">{
  9086. &quot;rooms&quot;: [
  9087. {
  9088. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  9089. &quot;name&quot;: &quot;Matrix HQ&quot;,
  9090. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  9091. &quot;joined_members&quot;: 8326,
  9092. &quot;joined_local_members&quot;: 2,
  9093. &quot;version&quot;: &quot;1&quot;,
  9094. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9095. &quot;encryption&quot;: null,
  9096. &quot;federatable&quot;: true,
  9097. &quot;public&quot;: true,
  9098. &quot;join_rules&quot;: &quot;invite&quot;,
  9099. &quot;guest_access&quot;: null,
  9100. &quot;history_visibility&quot;: &quot;shared&quot;,
  9101. &quot;state_events&quot;: 93534
  9102. },
  9103. ... (98 hidden items) ...
  9104. {
  9105. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9106. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9107. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9108. &quot;joined_members&quot;: 314,
  9109. &quot;joined_local_members&quot;: 20,
  9110. &quot;version&quot;: &quot;4&quot;,
  9111. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9112. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9113. &quot;federatable&quot;: true,
  9114. &quot;public&quot;: false,
  9115. &quot;join_rules&quot;: &quot;invite&quot;,
  9116. &quot;guest_access&quot;: null,
  9117. &quot;history_visibility&quot;: &quot;shared&quot;,
  9118. &quot;state_events&quot;: 8345
  9119. }
  9120. ],
  9121. &quot;offset&quot;: 0,
  9122. &quot;total_rooms&quot;: 150
  9123. &quot;next_token&quot;: 100
  9124. }
  9125. </code></pre>
  9126. <p>The presence of the <code>next_token</code> parameter tells us that there are more rooms
  9127. than returned in this request, and we need to make another request to get them.
  9128. To get the next batch of room results, we repeat our request, setting the <code>from</code>
  9129. parameter to the value of <code>next_token</code>.</p>
  9130. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size&amp;from=100
  9131. </code></pre>
  9132. <p>A response body like the following is returned:</p>
  9133. <pre><code class="language-jsonc">{
  9134. &quot;rooms&quot;: [
  9135. {
  9136. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  9137. &quot;name&quot;: &quot;Music Theory&quot;,
  9138. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  9139. &quot;joined_members&quot;: 127,
  9140. &quot;joined_local_members&quot;: 2,
  9141. &quot;version&quot;: &quot;1&quot;,
  9142. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9143. &quot;encryption&quot;: null,
  9144. &quot;federatable&quot;: true,
  9145. &quot;public&quot;: true,
  9146. &quot;join_rules&quot;: &quot;invite&quot;,
  9147. &quot;guest_access&quot;: null,
  9148. &quot;history_visibility&quot;: &quot;shared&quot;,
  9149. &quot;state_events&quot;: 93534
  9150. },
  9151. ... (48 hidden items) ...
  9152. {
  9153. &quot;room_id&quot;: &quot;!twcBhHVdZlQWuuxBhN:termina.org.uk&quot;,
  9154. &quot;name&quot;: &quot;weechat-matrix&quot;,
  9155. &quot;canonical_alias&quot;: &quot;#weechat-matrix:termina.org.uk&quot;,
  9156. &quot;joined_members&quot;: 137,
  9157. &quot;joined_local_members&quot;: 20,
  9158. &quot;version&quot;: &quot;4&quot;,
  9159. &quot;creator&quot;: &quot;@foo:termina.org.uk&quot;,
  9160. &quot;encryption&quot;: null,
  9161. &quot;federatable&quot;: true,
  9162. &quot;public&quot;: true,
  9163. &quot;join_rules&quot;: &quot;invite&quot;,
  9164. &quot;guest_access&quot;: null,
  9165. &quot;history_visibility&quot;: &quot;shared&quot;,
  9166. &quot;state_events&quot;: 8345
  9167. }
  9168. ],
  9169. &quot;offset&quot;: 100,
  9170. &quot;prev_batch&quot;: 0,
  9171. &quot;total_rooms&quot;: 150
  9172. }
  9173. </code></pre>
  9174. <p>Once the <code>next_token</code> parameter is no longer present, we know we've reached the
  9175. end of the list.</p>
  9176. <h1 id="room-details-api"><a class="header" href="#room-details-api">Room Details API</a></h1>
  9177. <p>The Room Details admin API allows server admins to get all details of a room.</p>
  9178. <p>The following fields are possible in the JSON response body:</p>
  9179. <ul>
  9180. <li><code>room_id</code> - The ID of the room.</li>
  9181. <li><code>name</code> - The name of the room.</li>
  9182. <li><code>topic</code> - The topic of the room.</li>
  9183. <li><code>avatar</code> - The <code>mxc</code> URI to the avatar of the room.</li>
  9184. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  9185. <li><code>joined_members</code> - How many users are currently in the room.</li>
  9186. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  9187. <li><code>joined_local_devices</code> - How many local devices are currently in the room.</li>
  9188. <li><code>version</code> - The version of the room as a string.</li>
  9189. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  9190. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  9191. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  9192. <li><code>public</code> - Whether the room is visible in room directory.</li>
  9193. <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>
  9194. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  9195. <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>
  9196. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  9197. </ul>
  9198. <p>The API is:</p>
  9199. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9200. </code></pre>
  9201. <p>A response body like the following is returned:</p>
  9202. <pre><code class="language-json">{
  9203. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  9204. &quot;name&quot;: &quot;Music Theory&quot;,
  9205. &quot;avatar&quot;: &quot;mxc://matrix.org/AQDaVFlbkQoErdOgqWRgiGSV&quot;,
  9206. &quot;topic&quot;: &quot;Theory, Composition, Notation, Analysis&quot;,
  9207. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  9208. &quot;joined_members&quot;: 127,
  9209. &quot;joined_local_members&quot;: 2,
  9210. &quot;joined_local_devices&quot;: 2,
  9211. &quot;version&quot;: &quot;1&quot;,
  9212. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9213. &quot;encryption&quot;: null,
  9214. &quot;federatable&quot;: true,
  9215. &quot;public&quot;: true,
  9216. &quot;join_rules&quot;: &quot;invite&quot;,
  9217. &quot;guest_access&quot;: null,
  9218. &quot;history_visibility&quot;: &quot;shared&quot;,
  9219. &quot;state_events&quot;: 93534
  9220. }
  9221. </code></pre>
  9222. <h1 id="room-members-api"><a class="header" href="#room-members-api">Room Members API</a></h1>
  9223. <p>The Room Members admin API allows server admins to get a list of all members of a room.</p>
  9224. <p>The response includes the following fields:</p>
  9225. <ul>
  9226. <li><code>members</code> - A list of all the members that are present in the room, represented by their ids.</li>
  9227. <li><code>total</code> - Total number of members in the room.</li>
  9228. </ul>
  9229. <p>The API is:</p>
  9230. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/members
  9231. </code></pre>
  9232. <p>A response body like the following is returned:</p>
  9233. <pre><code class="language-json">{
  9234. &quot;members&quot;: [
  9235. &quot;@foo:matrix.org&quot;,
  9236. &quot;@bar:matrix.org&quot;,
  9237. &quot;@foobar:matrix.org&quot;
  9238. ],
  9239. &quot;total&quot;: 3
  9240. }
  9241. </code></pre>
  9242. <h1 id="room-state-api"><a class="header" href="#room-state-api">Room State API</a></h1>
  9243. <p>The Room State admin API allows server admins to get a list of all state events in a room.</p>
  9244. <p>The response includes the following fields:</p>
  9245. <ul>
  9246. <li><code>state</code> - The current state of the room at the time of request.</li>
  9247. </ul>
  9248. <p>The API is:</p>
  9249. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/state
  9250. </code></pre>
  9251. <p>A response body like the following is returned:</p>
  9252. <pre><code class="language-json">{
  9253. &quot;state&quot;: [
  9254. {&quot;type&quot;: &quot;m.room.create&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9255. {&quot;type&quot;: &quot;m.room.power_levels&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9256. {&quot;type&quot;: &quot;m.room.name&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true}
  9257. ]
  9258. }
  9259. </code></pre>
  9260. <h1 id="delete-room-api"><a class="header" href="#delete-room-api">Delete Room API</a></h1>
  9261. <p>The Delete Room admin API allows server admins to remove rooms from server
  9262. and block these rooms.</p>
  9263. <p>Shuts down a room. Moves all local users and room aliases automatically to a
  9264. new room if <code>new_room_user_id</code> is set. Otherwise local users only
  9265. leave the room without any information.</p>
  9266. <p>The new room will be created with the user specified by the <code>new_room_user_id</code> parameter
  9267. as room administrator and will contain a message explaining what happened. Users invited
  9268. to the new room will have power level <code>-10</code> by default, and thus be unable to speak.</p>
  9269. <p>If <code>block</code> is <code>True</code> it prevents new joins to the old room.</p>
  9270. <p>This API will remove all trace of the old room from your database after removing
  9271. all local users. If <code>purge</code> is <code>true</code> (the default), all traces of the old room will
  9272. be removed from your database after removing all local users. If you do not want
  9273. this to happen, set <code>purge</code> to <code>false</code>.
  9274. Depending on the amount of history being purged a call to the API may take
  9275. several minutes or longer.</p>
  9276. <p>The local server will only have the power to move local user and room aliases to
  9277. the new room. Users on other servers will be unaffected.</p>
  9278. <p>The API is:</p>
  9279. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9280. </code></pre>
  9281. <p>with a body of:</p>
  9282. <pre><code class="language-json">{
  9283. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  9284. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  9285. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;,
  9286. &quot;block&quot;: true,
  9287. &quot;purge&quot;: true
  9288. }
  9289. </code></pre>
  9290. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9291. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9292. <p>A response body like the following is returned:</p>
  9293. <pre><code class="language-json">{
  9294. &quot;kicked_users&quot;: [
  9295. &quot;@foobar:example.com&quot;
  9296. ],
  9297. &quot;failed_to_kick_users&quot;: [],
  9298. &quot;local_aliases&quot;: [
  9299. &quot;#badroom:example.com&quot;,
  9300. &quot;#evilsaloon:example.com&quot;
  9301. ],
  9302. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;
  9303. }
  9304. </code></pre>
  9305. <p><strong>Parameters</strong></p>
  9306. <p>The following parameters should be set in the URL:</p>
  9307. <ul>
  9308. <li><code>room_id</code> - The ID of the room.</li>
  9309. </ul>
  9310. <p>The following JSON body parameters are available:</p>
  9311. <ul>
  9312. <li><code>new_room_user_id</code> - Optional. If set, a new room will be created with this user ID
  9313. as the creator and admin, and all users in the old room will be moved into that
  9314. room. If not set, no new room will be created and the users will just be removed
  9315. from the old room. The user ID must be on the local server, but does not necessarily
  9316. have to belong to a registered user.</li>
  9317. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  9318. invited to. Defaults to <code>Content Violation Notification</code></li>
  9319. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  9320. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  9321. 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>
  9322. <li><code>block</code> - Optional. If set to <code>true</code>, this room will be added to a blocking list, preventing
  9323. future attempts to join the room. Defaults to <code>false</code>.</li>
  9324. <li><code>purge</code> - Optional. If set to <code>true</code>, it will remove all traces of the room from your database.
  9325. Defaults to <code>true</code>.</li>
  9326. <li><code>force_purge</code> - Optional, and ignored unless <code>purge</code> is <code>true</code>. If set to <code>true</code>, it
  9327. will force a purge to go ahead even if there are local users still in the room. Do not
  9328. use this unless a regular <code>purge</code> operation fails, as it could leave those users'
  9329. clients in a confused state.</li>
  9330. </ul>
  9331. <p>The JSON body must not be empty. The body must be at least <code>{}</code>.</p>
  9332. <p><strong>Response</strong></p>
  9333. <p>The following fields are returned in the JSON response body:</p>
  9334. <ul>
  9335. <li><code>kicked_users</code> - An array of users (<code>user_id</code>) that were kicked.</li>
  9336. <li><code>failed_to_kick_users</code> - An array of users (<code>user_id</code>) that that were not kicked.</li>
  9337. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  9338. the old room to the new.</li>
  9339. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  9340. </ul>
  9341. <h2 id="undoing-room-deletions"><a class="header" href="#undoing-room-deletions">Undoing room deletions</a></h2>
  9342. <p><em>Note</em>: This guide may be outdated by the time you read it. By nature of room deletions being performed at the database level,
  9343. the structure can and does change without notice.</p>
  9344. <p>First, it's important to understand that a room deletion is very destructive. Undoing a deletion is not as simple as pretending it
  9345. 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
  9346. to recover at all:</p>
  9347. <ul>
  9348. <li>If the room was invite-only, your users will need to be re-invited.</li>
  9349. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  9350. <li>The first user to rejoin will have to do so via an alias on a different
  9351. server (or receive an invite from a user on a different server).</li>
  9352. </ul>
  9353. <p>With all that being said, if you still want to try and recover the room:</p>
  9354. <ol>
  9355. <li>
  9356. <p>If the room was <code>block</code>ed, you must unblock it on your server. This can be
  9357. accomplished as follows:</p>
  9358. <ol>
  9359. <li>For safety reasons, shut down Synapse.</li>
  9360. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  9361. <ul>
  9362. <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>
  9363. <li>The room ID is the same one supplied to the delete room API, not the Content Violation room.</li>
  9364. </ul>
  9365. </li>
  9366. <li>Restart Synapse.</li>
  9367. </ol>
  9368. <p>This step is unnecessary if <code>block</code> was not set.</p>
  9369. </li>
  9370. <li>
  9371. <p>Any room aliases on your server that pointed to the deleted room may have
  9372. been deleted, or redirected to the Content Violation room. These will need
  9373. to be restored manually.</p>
  9374. </li>
  9375. <li>
  9376. <p>Users on your server that were in the deleted room will have been kicked
  9377. from the room. Consider whether you want to update their membership
  9378. (possibly via the <a href="admin_api/room_membership.html">Edit Room Membership API</a>) or let
  9379. them handle rejoining themselves.</p>
  9380. </li>
  9381. <li>
  9382. <p>If <code>new_room_user_id</code> was given, a 'Content Violation' will have been
  9383. created. Consider whether you want to delete that roomm.</p>
  9384. </li>
  9385. </ol>
  9386. <h2 id="deprecated-endpoint"><a class="header" href="#deprecated-endpoint">Deprecated endpoint</a></h2>
  9387. <p>The previous deprecated API will be removed in a future release, it was:</p>
  9388. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id&gt;/delete
  9389. </code></pre>
  9390. <p>It behaves the same way than the current endpoint except the path and the method.</p>
  9391. <h1 id="make-room-admin-api"><a class="header" href="#make-room-admin-api">Make Room Admin API</a></h1>
  9392. <p>Grants another user the highest power available to a local user who is in the room.
  9393. If the user is not in the room, and it is not publicly joinable, then invite the user.</p>
  9394. <p>By default the server admin (the caller) is granted power, but another user can
  9395. optionally be specified, e.g.:</p>
  9396. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/make_room_admin
  9397. {
  9398. &quot;user_id&quot;: &quot;@foo:example.com&quot;
  9399. }
  9400. </code></pre>
  9401. <h1 id="forward-extremities-admin-api"><a class="header" href="#forward-extremities-admin-api">Forward Extremities Admin API</a></h1>
  9402. <p>Enables querying and deleting forward extremities from rooms. When a lot of forward
  9403. extremities accumulate in a room, performance can become degraded. For details, see
  9404. <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.</p>
  9405. <h2 id="check-for-forward-extremities"><a class="header" href="#check-for-forward-extremities">Check for forward extremities</a></h2>
  9406. <p>To check the status of forward extremities for a room:</p>
  9407. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9408. </code></pre>
  9409. <p>A response as follows will be returned:</p>
  9410. <pre><code class="language-json">{
  9411. &quot;count&quot;: 1,
  9412. &quot;results&quot;: [
  9413. {
  9414. &quot;event_id&quot;: &quot;$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdefgh&quot;,
  9415. &quot;state_group&quot;: 439,
  9416. &quot;depth&quot;: 123,
  9417. &quot;received_ts&quot;: 1611263016761
  9418. }
  9419. ]
  9420. }
  9421. </code></pre>
  9422. <h2 id="deleting-forward-extremities"><a class="header" href="#deleting-forward-extremities">Deleting forward extremities</a></h2>
  9423. <p><strong>WARNING</strong>: Please ensure you know what you're doing and have read
  9424. the related issue <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.
  9425. Under no situations should this API be executed as an automated maintenance task!</p>
  9426. <p>If a room has lots of forward extremities, the extra can be
  9427. deleted as follows:</p>
  9428. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9429. </code></pre>
  9430. <p>A response as follows will be returned, indicating the amount of forward extremities
  9431. that were deleted.</p>
  9432. <pre><code class="language-json">{
  9433. &quot;deleted&quot;: 1
  9434. }
  9435. </code></pre>
  9436. <h1 id="event-context-api"><a class="header" href="#event-context-api">Event Context API</a></h1>
  9437. <p>This API lets a client find the context of an event. This is designed primarily to investigate abuse reports.</p>
  9438. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/context/&lt;event_id&gt;
  9439. </code></pre>
  9440. <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>
  9441. <p>Example response:</p>
  9442. <pre><code class="language-json">{
  9443. &quot;end&quot;: &quot;t29-57_2_0_2&quot;,
  9444. &quot;events_after&quot;: [
  9445. {
  9446. &quot;content&quot;: {
  9447. &quot;body&quot;: &quot;This is an example text message&quot;,
  9448. &quot;msgtype&quot;: &quot;m.text&quot;,
  9449. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  9450. &quot;formatted_body&quot;: &quot;&lt;b&gt;This is an example text message&lt;/b&gt;&quot;
  9451. },
  9452. &quot;type&quot;: &quot;m.room.message&quot;,
  9453. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9454. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9455. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9456. &quot;origin_server_ts&quot;: 1432735824653,
  9457. &quot;unsigned&quot;: {
  9458. &quot;age&quot;: 1234
  9459. }
  9460. }
  9461. ],
  9462. &quot;event&quot;: {
  9463. &quot;content&quot;: {
  9464. &quot;body&quot;: &quot;filename.jpg&quot;,
  9465. &quot;info&quot;: {
  9466. &quot;h&quot;: 398,
  9467. &quot;w&quot;: 394,
  9468. &quot;mimetype&quot;: &quot;image/jpeg&quot;,
  9469. &quot;size&quot;: 31037
  9470. },
  9471. &quot;url&quot;: &quot;mxc://example.org/JWEIFJgwEIhweiWJE&quot;,
  9472. &quot;msgtype&quot;: &quot;m.image&quot;
  9473. },
  9474. &quot;type&quot;: &quot;m.room.message&quot;,
  9475. &quot;event_id&quot;: &quot;$f3h4d129462ha:example.com&quot;,
  9476. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9477. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9478. &quot;origin_server_ts&quot;: 1432735824653,
  9479. &quot;unsigned&quot;: {
  9480. &quot;age&quot;: 1234
  9481. }
  9482. },
  9483. &quot;events_before&quot;: [
  9484. {
  9485. &quot;content&quot;: {
  9486. &quot;body&quot;: &quot;something-important.doc&quot;,
  9487. &quot;filename&quot;: &quot;something-important.doc&quot;,
  9488. &quot;info&quot;: {
  9489. &quot;mimetype&quot;: &quot;application/msword&quot;,
  9490. &quot;size&quot;: 46144
  9491. },
  9492. &quot;msgtype&quot;: &quot;m.file&quot;,
  9493. &quot;url&quot;: &quot;mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe&quot;
  9494. },
  9495. &quot;type&quot;: &quot;m.room.message&quot;,
  9496. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9497. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9498. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9499. &quot;origin_server_ts&quot;: 1432735824653,
  9500. &quot;unsigned&quot;: {
  9501. &quot;age&quot;: 1234
  9502. }
  9503. }
  9504. ],
  9505. &quot;start&quot;: &quot;t27-54_2_0_2&quot;,
  9506. &quot;state&quot;: [
  9507. {
  9508. &quot;content&quot;: {
  9509. &quot;creator&quot;: &quot;@example:example.org&quot;,
  9510. &quot;room_version&quot;: &quot;1&quot;,
  9511. &quot;m.federate&quot;: true,
  9512. &quot;predecessor&quot;: {
  9513. &quot;event_id&quot;: &quot;$something:example.org&quot;,
  9514. &quot;room_id&quot;: &quot;!oldroom:example.org&quot;
  9515. }
  9516. },
  9517. &quot;type&quot;: &quot;m.room.create&quot;,
  9518. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9519. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9520. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9521. &quot;origin_server_ts&quot;: 1432735824653,
  9522. &quot;unsigned&quot;: {
  9523. &quot;age&quot;: 1234
  9524. },
  9525. &quot;state_key&quot;: &quot;&quot;
  9526. },
  9527. {
  9528. &quot;content&quot;: {
  9529. &quot;membership&quot;: &quot;join&quot;,
  9530. &quot;avatar_url&quot;: &quot;mxc://example.org/SEsfnsuifSDFSSEF&quot;,
  9531. &quot;displayname&quot;: &quot;Alice Margatroid&quot;
  9532. },
  9533. &quot;type&quot;: &quot;m.room.member&quot;,
  9534. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9535. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9536. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9537. &quot;origin_server_ts&quot;: 1432735824653,
  9538. &quot;unsigned&quot;: {
  9539. &quot;age&quot;: 1234
  9540. },
  9541. &quot;state_key&quot;: &quot;@alice:example.org&quot;
  9542. }
  9543. ]
  9544. }
  9545. </code></pre>
  9546. <div 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>
  9547. <p>The API to send notices is as follows:</p>
  9548. <pre><code>POST /_synapse/admin/v1/send_server_notice
  9549. </code></pre>
  9550. <p>or:</p>
  9551. <pre><code>PUT /_synapse/admin/v1/send_server_notice/{txnId}
  9552. </code></pre>
  9553. <p>You will need to authenticate with an access token for an admin user.</p>
  9554. <p>When using the <code>PUT</code> form, retransmissions with the same transaction ID will be
  9555. ignored in the same way as with <code>PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}</code>.</p>
  9556. <p>The request body should look something like the following:</p>
  9557. <pre><code class="language-json">{
  9558. &quot;user_id&quot;: &quot;@target_user:server_name&quot;,
  9559. &quot;content&quot;: {
  9560. &quot;msgtype&quot;: &quot;m.text&quot;,
  9561. &quot;body&quot;: &quot;This is my message&quot;
  9562. }
  9563. }
  9564. </code></pre>
  9565. <p>You can optionally include the following additional parameters:</p>
  9566. <ul>
  9567. <li><code>type</code>: the type of event. Defaults to <code>m.room.message</code>.</li>
  9568. <li><code>state_key</code>: Setting this will result in a state event being sent.</li>
  9569. </ul>
  9570. <p>Once the notice has been sent, the API will return the following response:</p>
  9571. <pre><code class="language-json">{
  9572. &quot;event_id&quot;: &quot;&lt;event_id&gt;&quot;
  9573. }
  9574. </code></pre>
  9575. <p>Note that server notices must be enabled in <code>homeserver.yaml</code> before this API
  9576. can be used. See <a href="admin_api/../server_notices.html">the server notices documentation</a> for more information.</p>
  9577. <div 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>
  9578. <p>Returns information about all local media usage of users. Gives the
  9579. possibility to filter them by time and user.</p>
  9580. <p>The API is:</p>
  9581. <pre><code>GET /_synapse/admin/v1/statistics/users/media
  9582. </code></pre>
  9583. <p>To use it, you will need to authenticate by providing an <code>access_token</code>
  9584. for a server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9585. <p>A response body like the following is returned:</p>
  9586. <pre><code class="language-json">{
  9587. &quot;users&quot;: [
  9588. {
  9589. &quot;displayname&quot;: &quot;foo_user_0&quot;,
  9590. &quot;media_count&quot;: 2,
  9591. &quot;media_length&quot;: 134,
  9592. &quot;user_id&quot;: &quot;@foo_user_0:test&quot;
  9593. },
  9594. {
  9595. &quot;displayname&quot;: &quot;foo_user_1&quot;,
  9596. &quot;media_count&quot;: 2,
  9597. &quot;media_length&quot;: 134,
  9598. &quot;user_id&quot;: &quot;@foo_user_1:test&quot;
  9599. }
  9600. ],
  9601. &quot;next_token&quot;: 3,
  9602. &quot;total&quot;: 10
  9603. }
  9604. </code></pre>
  9605. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint
  9606. again with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9607. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9608. reports to paginate through.</p>
  9609. <p><strong>Parameters</strong></p>
  9610. <p>The following parameters should be set in the URL:</p>
  9611. <ul>
  9612. <li><code>limit</code>: string representing a positive integer - Is optional but is
  9613. used for pagination, denoting the maximum number of items to return
  9614. in this call. Defaults to <code>100</code>.</li>
  9615. <li><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9616. denoting the offset in the returned results. This should be treated as an opaque value
  9617. and not explicitly set to anything other than the return value of <code>next_token</code> from a
  9618. previous call. Defaults to <code>0</code>.</li>
  9619. <li><code>order_by</code> - string - The method in which to sort the returned list of users. Valid values are:
  9620. <ul>
  9621. <li><code>user_id</code> - Users are ordered alphabetically by <code>user_id</code>. This is the default.</li>
  9622. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9623. <li><code>media_length</code> - Users are ordered by the total size of uploaded media in bytes.
  9624. Smallest to largest.</li>
  9625. <li><code>media_count</code> - Users are ordered by number of uploaded media. Smallest to largest.</li>
  9626. </ul>
  9627. </li>
  9628. <li><code>from_ts</code> - string representing a positive integer - Considers only
  9629. files created at this timestamp or later. Unix timestamp in ms.</li>
  9630. <li><code>until_ts</code> - string representing a positive integer - Considers only
  9631. files created at this timestamp or earlier. Unix timestamp in ms.</li>
  9632. <li><code>search_term</code> - string - Filter users by their user ID localpart <strong>or</strong> displayname.
  9633. The search term can be found in any part of the string.
  9634. Defaults to no filtering.</li>
  9635. <li><code>dir</code> - string - Direction of order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9636. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  9637. </ul>
  9638. <p><strong>Response</strong></p>
  9639. <p>The following fields are returned in the JSON response body:</p>
  9640. <ul>
  9641. <li><code>users</code> - An array of objects, each containing information
  9642. about the user and their local media. Objects contain the following fields:
  9643. <ul>
  9644. <li><code>displayname</code> - string - Displayname of this user.</li>
  9645. <li><code>media_count</code> - integer - Number of uploaded media by this user.</li>
  9646. <li><code>media_length</code> - integer - Size of uploaded media in bytes by this user.</li>
  9647. <li><code>user_id</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9648. </ul>
  9649. </li>
  9650. <li><code>next_token</code> - integer - Opaque value used for pagination. See above.</li>
  9651. <li><code>total</code> - integer - Total number of users after filtering.</li>
  9652. </ul>
  9653. <div 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>
  9654. <h2 id="query-user-account"><a class="header" href="#query-user-account">Query User Account</a></h2>
  9655. <p>This API returns information about a specific user account.</p>
  9656. <p>The api is:</p>
  9657. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;
  9658. </code></pre>
  9659. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9660. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9661. <p>It returns a JSON body like the following:</p>
  9662. <pre><code class="language-json">{
  9663. &quot;displayname&quot;: &quot;User&quot;,
  9664. &quot;threepids&quot;: [
  9665. {
  9666. &quot;medium&quot;: &quot;email&quot;,
  9667. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;,
  9668. &quot;added_at&quot;: 1586458409743,
  9669. &quot;validated_at&quot;: 1586458409743
  9670. },
  9671. {
  9672. &quot;medium&quot;: &quot;email&quot;,
  9673. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;,
  9674. &quot;added_at&quot;: 1586458409743,
  9675. &quot;validated_at&quot;: 1586458409743
  9676. }
  9677. ],
  9678. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9679. &quot;admin&quot;: 0,
  9680. &quot;deactivated&quot;: 0,
  9681. &quot;shadow_banned&quot;: 0,
  9682. &quot;password_hash&quot;: &quot;$2b$12$p9B4GkqYdRTPGD&quot;,
  9683. &quot;creation_ts&quot;: 1560432506,
  9684. &quot;appservice_id&quot;: null,
  9685. &quot;consent_server_notice_sent&quot;: null,
  9686. &quot;consent_version&quot;: null,
  9687. &quot;external_ids&quot;: [
  9688. {
  9689. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9690. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9691. },
  9692. {
  9693. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9694. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9695. }
  9696. ]
  9697. }
  9698. </code></pre>
  9699. <p>URL parameters:</p>
  9700. <ul>
  9701. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9702. </ul>
  9703. <h2 id="create-or-modify-account"><a class="header" href="#create-or-modify-account">Create or modify Account</a></h2>
  9704. <p>This API allows an administrator to create or modify a user account with a
  9705. specific <code>user_id</code>.</p>
  9706. <p>This api is:</p>
  9707. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;
  9708. </code></pre>
  9709. <p>with a body of:</p>
  9710. <pre><code class="language-json">{
  9711. &quot;password&quot;: &quot;user_password&quot;,
  9712. &quot;displayname&quot;: &quot;User&quot;,
  9713. &quot;threepids&quot;: [
  9714. {
  9715. &quot;medium&quot;: &quot;email&quot;,
  9716. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9717. },
  9718. {
  9719. &quot;medium&quot;: &quot;email&quot;,
  9720. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9721. }
  9722. ],
  9723. &quot;external_ids&quot;: [
  9724. {
  9725. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9726. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9727. },
  9728. {
  9729. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9730. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9731. }
  9732. ],
  9733. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9734. &quot;admin&quot;: false,
  9735. &quot;deactivated&quot;: false
  9736. }
  9737. </code></pre>
  9738. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9739. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9740. <p>Returns HTTP status code:</p>
  9741. <ul>
  9742. <li><code>201</code> - When a new user object was created.</li>
  9743. <li><code>200</code> - When a user was modified.</li>
  9744. </ul>
  9745. <p>URL parameters:</p>
  9746. <ul>
  9747. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9748. </ul>
  9749. <p>Body parameters:</p>
  9750. <ul>
  9751. <li><code>password</code> - string, optional. If provided, the user's password is updated and all
  9752. devices are logged out.</li>
  9753. <li><code>displayname</code> - string, optional, defaults to the value of <code>user_id</code>.</li>
  9754. <li><code>threepids</code> - array, optional, allows setting the third-party IDs (email, msisdn)
  9755. <ul>
  9756. <li><code>medium</code> - string. Kind of third-party ID, either <code>email</code> or <code>msisdn</code>.</li>
  9757. <li><code>address</code> - string. Value of third-party ID.
  9758. belonging to a user.</li>
  9759. </ul>
  9760. </li>
  9761. <li><code>external_ids</code> - array, optional. Allow setting the identifier of the external identity
  9762. provider for SSO (Single sign-on). Details in
  9763. <a href="admin_api/../usage/configuration/homeserver_sample_config.html">Sample Configuration File</a>
  9764. section <code>sso</code> and <code>oidc_providers</code>.
  9765. <ul>
  9766. <li><code>auth_provider</code> - string. ID of the external identity provider. Value of <code>idp_id</code>
  9767. in homeserver configuration.</li>
  9768. <li><code>external_id</code> - string, user ID in the external identity provider.</li>
  9769. </ul>
  9770. </li>
  9771. <li><code>avatar_url</code> - string, optional, must be a
  9772. <a href="https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris">MXC URI</a>.</li>
  9773. <li><code>admin</code> - bool, optional, defaults to <code>false</code>.</li>
  9774. <li><code>deactivated</code> - bool, optional. If unspecified, deactivation state will be left
  9775. unchanged on existing accounts and set to <code>false</code> for new accounts.
  9776. A user cannot be erased by deactivating with this API. For details on
  9777. deactivating users see <a href="admin_api/user_admin_api.html#deactivate-account">Deactivate Account</a>.</li>
  9778. </ul>
  9779. <p>If the user already exists then optional parameters default to the current value.</p>
  9780. <p>In order to re-activate an account <code>deactivated</code> must be set to <code>false</code>. If
  9781. users do not login via single-sign-on, a new <code>password</code> must be provided.</p>
  9782. <h2 id="list-accounts"><a class="header" href="#list-accounts">List Accounts</a></h2>
  9783. <p>This API returns all local user accounts.
  9784. By default, the response is ordered by ascending user ID.</p>
  9785. <pre><code>GET /_synapse/admin/v2/users?from=0&amp;limit=10&amp;guests=false
  9786. </code></pre>
  9787. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9788. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9789. <p>A response body like the following is returned:</p>
  9790. <pre><code class="language-json">{
  9791. &quot;users&quot;: [
  9792. {
  9793. &quot;name&quot;: &quot;&lt;user_id1&gt;&quot;,
  9794. &quot;is_guest&quot;: 0,
  9795. &quot;admin&quot;: 0,
  9796. &quot;user_type&quot;: null,
  9797. &quot;deactivated&quot;: 0,
  9798. &quot;shadow_banned&quot;: 0,
  9799. &quot;displayname&quot;: &quot;&lt;User One&gt;&quot;,
  9800. &quot;avatar_url&quot;: null,
  9801. &quot;creation_ts&quot;: 1560432668000
  9802. }, {
  9803. &quot;name&quot;: &quot;&lt;user_id2&gt;&quot;,
  9804. &quot;is_guest&quot;: 0,
  9805. &quot;admin&quot;: 1,
  9806. &quot;user_type&quot;: null,
  9807. &quot;deactivated&quot;: 0,
  9808. &quot;shadow_banned&quot;: 0,
  9809. &quot;displayname&quot;: &quot;&lt;User Two&gt;&quot;,
  9810. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9811. &quot;creation_ts&quot;: 1561550621000
  9812. }
  9813. ],
  9814. &quot;next_token&quot;: &quot;100&quot;,
  9815. &quot;total&quot;: 200
  9816. }
  9817. </code></pre>
  9818. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9819. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9820. <p>If the endpoint does not return a <code>next_token</code> then there are no more users
  9821. to paginate through.</p>
  9822. <p><strong>Parameters</strong></p>
  9823. <p>The following parameters should be set in the URL:</p>
  9824. <ul>
  9825. <li>
  9826. <p><code>user_id</code> - Is optional and filters to only return users with user IDs
  9827. that contain this value. This parameter is ignored when using the <code>name</code> parameter.</p>
  9828. </li>
  9829. <li>
  9830. <p><code>name</code> - Is optional and filters to only return users with user ID localparts
  9831. <strong>or</strong> displaynames that contain this value.</p>
  9832. </li>
  9833. <li>
  9834. <p><code>guests</code> - string representing a bool - Is optional and if <code>false</code> will <strong>exclude</strong> guest users.
  9835. Defaults to <code>true</code> to include guest users.</p>
  9836. </li>
  9837. <li>
  9838. <p><code>deactivated</code> - string representing a bool - Is optional and if <code>true</code> will <strong>include</strong> deactivated users.
  9839. Defaults to <code>false</code> to exclude deactivated users.</p>
  9840. </li>
  9841. <li>
  9842. <p><code>limit</code> - string representing a positive integer - Is optional but is used for pagination,
  9843. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9844. </li>
  9845. <li>
  9846. <p><code>from</code> - string representing a positive integer - Is optional but used for pagination,
  9847. denoting the offset in the returned results. This should be treated as an opaque value and
  9848. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9849. Defaults to <code>0</code>.</p>
  9850. </li>
  9851. <li>
  9852. <p><code>order_by</code> - The method by which to sort the returned list of users.
  9853. If the ordered field has duplicates, the second order is always by ascending <code>name</code>,
  9854. which guarantees a stable ordering. Valid values are:</p>
  9855. <ul>
  9856. <li><code>name</code> - Users are ordered alphabetically by <code>name</code>. This is the default.</li>
  9857. <li><code>is_guest</code> - Users are ordered by <code>is_guest</code> status.</li>
  9858. <li><code>admin</code> - Users are ordered by <code>admin</code> status.</li>
  9859. <li><code>user_type</code> - Users are ordered alphabetically by <code>user_type</code>.</li>
  9860. <li><code>deactivated</code> - Users are ordered by <code>deactivated</code> status.</li>
  9861. <li><code>shadow_banned</code> - Users are ordered by <code>shadow_banned</code> status.</li>
  9862. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9863. <li><code>avatar_url</code> - Users are ordered alphabetically by avatar URL.</li>
  9864. <li><code>creation_ts</code> - Users are ordered by when the users was created in ms.</li>
  9865. </ul>
  9866. </li>
  9867. <li>
  9868. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9869. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  9870. </li>
  9871. </ul>
  9872. <p>Caution. The database only has indexes on the columns <code>name</code> and <code>creation_ts</code>.
  9873. This means that if a different sort order is used (<code>is_guest</code>, <code>admin</code>,
  9874. <code>user_type</code>, <code>deactivated</code>, <code>shadow_banned</code>, <code>avatar_url</code> or <code>displayname</code>),
  9875. this can cause a large load on the database, especially for large environments.</p>
  9876. <p><strong>Response</strong></p>
  9877. <p>The following fields are returned in the JSON response body:</p>
  9878. <ul>
  9879. <li>
  9880. <p><code>users</code> - An array of objects, each containing information about an user.
  9881. User objects contain the following fields:</p>
  9882. <ul>
  9883. <li><code>name</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9884. <li><code>is_guest</code> - bool - Status if that user is a guest account.</li>
  9885. <li><code>admin</code> - bool - Status if that user is a server administrator.</li>
  9886. <li><code>user_type</code> - string - Type of the user. Normal users are type <code>None</code>.
  9887. This allows user type specific behaviour. There are also types <code>support</code> and <code>bot</code>. </li>
  9888. <li><code>deactivated</code> - bool - Status if that user has been marked as deactivated.</li>
  9889. <li><code>shadow_banned</code> - bool - Status if that user has been marked as shadow banned.</li>
  9890. <li><code>displayname</code> - string - The user's display name if they have set one.</li>
  9891. <li><code>avatar_url</code> - string - The user's avatar URL if they have set one.</li>
  9892. <li><code>creation_ts</code> - integer - The user's creation timestamp in ms.</li>
  9893. </ul>
  9894. </li>
  9895. <li>
  9896. <p><code>next_token</code>: string representing a positive integer - Indication for pagination. See above.</p>
  9897. </li>
  9898. <li>
  9899. <p><code>total</code> - integer - Total number of media.</p>
  9900. </li>
  9901. </ul>
  9902. <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>
  9903. <p>This API returns information about the active sessions for a specific user.</p>
  9904. <p>The endpoints are:</p>
  9905. <pre><code>GET /_synapse/admin/v1/whois/&lt;user_id&gt;
  9906. </code></pre>
  9907. <p>and:</p>
  9908. <pre><code>GET /_matrix/client/r0/admin/whois/&lt;userId&gt;
  9909. </code></pre>
  9910. <p>See also: <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid">Client Server
  9911. API Whois</a>.</p>
  9912. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9913. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9914. <p>It returns a JSON body like the following:</p>
  9915. <pre><code class="language-json">{
  9916. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;,
  9917. &quot;devices&quot;: {
  9918. &quot;&quot;: {
  9919. &quot;sessions&quot;: [
  9920. {
  9921. &quot;connections&quot;: [
  9922. {
  9923. &quot;ip&quot;: &quot;1.2.3.4&quot;,
  9924. &quot;last_seen&quot;: 1417222374433,
  9925. &quot;user_agent&quot;: &quot;Mozilla/5.0 ...&quot;
  9926. },
  9927. {
  9928. &quot;ip&quot;: &quot;1.2.3.10&quot;,
  9929. &quot;last_seen&quot;: 1417222374500,
  9930. &quot;user_agent&quot;: &quot;Dalvik/2.1.0 ...&quot;
  9931. }
  9932. ]
  9933. }
  9934. ]
  9935. }
  9936. }
  9937. }
  9938. </code></pre>
  9939. <p><code>last_seen</code> is measured in milliseconds since the Unix epoch.</p>
  9940. <h2 id="deactivate-account"><a class="header" href="#deactivate-account">Deactivate Account</a></h2>
  9941. <p>This API deactivates an account. It removes active access tokens, resets the
  9942. password, and deletes third-party IDs (to prevent the user requesting a
  9943. password reset).</p>
  9944. <p>It can also mark the user as GDPR-erased. This means messages sent by the
  9945. user will still be visible by anyone that was in the room when these messages
  9946. were sent, but hidden from users joining the room afterwards.</p>
  9947. <p>The api is:</p>
  9948. <pre><code>POST /_synapse/admin/v1/deactivate/&lt;user_id&gt;
  9949. </code></pre>
  9950. <p>with a body of:</p>
  9951. <pre><code class="language-json">{
  9952. &quot;erase&quot;: true
  9953. }
  9954. </code></pre>
  9955. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9956. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9957. <p>The erase parameter is optional and defaults to <code>false</code>.
  9958. An empty body may be passed for backwards compatibility.</p>
  9959. <p>The following actions are performed when deactivating an user:</p>
  9960. <ul>
  9961. <li>Try to unpind 3PIDs from the identity server</li>
  9962. <li>Remove all 3PIDs from the homeserver</li>
  9963. <li>Delete all devices and E2EE keys</li>
  9964. <li>Delete all access tokens</li>
  9965. <li>Delete the password hash</li>
  9966. <li>Removal from all rooms the user is a member of</li>
  9967. <li>Remove the user from the user directory</li>
  9968. <li>Reject all pending invites</li>
  9969. <li>Remove all account validity information related to the user</li>
  9970. </ul>
  9971. <p>The following additional actions are performed during deactivation if <code>erase</code>
  9972. is set to <code>true</code>:</p>
  9973. <ul>
  9974. <li>Remove the user's display name</li>
  9975. <li>Remove the user's avatar URL</li>
  9976. <li>Mark the user as erased</li>
  9977. </ul>
  9978. <h2 id="reset-password"><a class="header" href="#reset-password">Reset password</a></h2>
  9979. <p>Changes the password of another user. This will automatically log the user out of all their devices.</p>
  9980. <p>The api is:</p>
  9981. <pre><code>POST /_synapse/admin/v1/reset_password/&lt;user_id&gt;
  9982. </code></pre>
  9983. <p>with a body of:</p>
  9984. <pre><code class="language-json">{
  9985. &quot;new_password&quot;: &quot;&lt;secret&gt;&quot;,
  9986. &quot;logout_devices&quot;: true
  9987. }
  9988. </code></pre>
  9989. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9990. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9991. <p>The parameter <code>new_password</code> is required.
  9992. The parameter <code>logout_devices</code> is optional and defaults to <code>true</code>.</p>
  9993. <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>
  9994. <p>The api is:</p>
  9995. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  9996. </code></pre>
  9997. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9998. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9999. <p>A response body like the following is returned:</p>
  10000. <pre><code class="language-json">{
  10001. &quot;admin&quot;: true
  10002. }
  10003. </code></pre>
  10004. <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>
  10005. <p>Note that you cannot demote yourself.</p>
  10006. <p>The api is:</p>
  10007. <pre><code>PUT /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  10008. </code></pre>
  10009. <p>with a body of:</p>
  10010. <pre><code class="language-json">{
  10011. &quot;admin&quot;: true
  10012. }
  10013. </code></pre>
  10014. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10015. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10016. <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>
  10017. <p>Gets a list of all <code>room_id</code> that a specific <code>user_id</code> is member.</p>
  10018. <p>The API is:</p>
  10019. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/joined_rooms
  10020. </code></pre>
  10021. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10022. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10023. <p>A response body like the following is returned:</p>
  10024. <pre><code class="language-json"> {
  10025. &quot;joined_rooms&quot;: [
  10026. &quot;!DuGcnbhHGaSZQoNQR:matrix.org&quot;,
  10027. &quot;!ZtSaPCawyWtxfWiIy:matrix.org&quot;
  10028. ],
  10029. &quot;total&quot;: 2
  10030. }
  10031. </code></pre>
  10032. <p>The server returns the list of rooms of which the user and the server
  10033. are member. If the user is local, all the rooms of which the user is
  10034. member are returned.</p>
  10035. <p><strong>Parameters</strong></p>
  10036. <p>The following parameters should be set in the URL:</p>
  10037. <ul>
  10038. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10039. </ul>
  10040. <p><strong>Response</strong></p>
  10041. <p>The following fields are returned in the JSON response body:</p>
  10042. <ul>
  10043. <li><code>joined_rooms</code> - An array of <code>room_id</code>.</li>
  10044. <li><code>total</code> - Number of rooms.</li>
  10045. </ul>
  10046. <h2 id="user-media"><a class="header" href="#user-media">User media</a></h2>
  10047. <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>
  10048. <p>Gets a list of all local media that a specific <code>user_id</code> has created.
  10049. By default, the response is ordered by descending creation date and ascending media ID.
  10050. The newest media is on top. You can change the order with parameters
  10051. <code>order_by</code> and <code>dir</code>.</p>
  10052. <p>The API is:</p>
  10053. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/media
  10054. </code></pre>
  10055. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10056. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10057. <p>A response body like the following is returned:</p>
  10058. <pre><code class="language-json">{
  10059. &quot;media&quot;: [
  10060. {
  10061. &quot;created_ts&quot;: 100400,
  10062. &quot;last_access_ts&quot;: null,
  10063. &quot;media_id&quot;: &quot;qXhyRzulkwLsNHTbpHreuEgo&quot;,
  10064. &quot;media_length&quot;: 67,
  10065. &quot;media_type&quot;: &quot;image/png&quot;,
  10066. &quot;quarantined_by&quot;: null,
  10067. &quot;safe_from_quarantine&quot;: false,
  10068. &quot;upload_name&quot;: &quot;test1.png&quot;
  10069. },
  10070. {
  10071. &quot;created_ts&quot;: 200400,
  10072. &quot;last_access_ts&quot;: null,
  10073. &quot;media_id&quot;: &quot;FHfiSnzoINDatrXHQIXBtahw&quot;,
  10074. &quot;media_length&quot;: 67,
  10075. &quot;media_type&quot;: &quot;image/png&quot;,
  10076. &quot;quarantined_by&quot;: null,
  10077. &quot;safe_from_quarantine&quot;: false,
  10078. &quot;upload_name&quot;: &quot;test2.png&quot;
  10079. }
  10080. ],
  10081. &quot;next_token&quot;: 3,
  10082. &quot;total&quot;: 2
  10083. }
  10084. </code></pre>
  10085. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  10086. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  10087. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  10088. reports to paginate through.</p>
  10089. <p><strong>Parameters</strong></p>
  10090. <p>The following parameters should be set in the URL:</p>
  10091. <ul>
  10092. <li>
  10093. <p><code>user_id</code> - string - fully qualified: for example, <code>@user:server.com</code>.</p>
  10094. </li>
  10095. <li>
  10096. <p><code>limit</code>: string representing a positive integer - Is optional but is used for pagination,
  10097. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  10098. </li>
  10099. <li>
  10100. <p><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  10101. denoting the offset in the returned results. This should be treated as an opaque value and
  10102. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  10103. Defaults to <code>0</code>.</p>
  10104. </li>
  10105. <li>
  10106. <p><code>order_by</code> - The method by which to sort the returned list of media.
  10107. If the ordered field has duplicates, the second order is always by ascending <code>media_id</code>,
  10108. which guarantees a stable ordering. Valid values are:</p>
  10109. <ul>
  10110. <li><code>media_id</code> - Media are ordered alphabetically by <code>media_id</code>.</li>
  10111. <li><code>upload_name</code> - Media are ordered alphabetically by name the media was uploaded with.</li>
  10112. <li><code>created_ts</code> - Media are ordered by when the content was uploaded in ms.
  10113. Smallest to largest. This is the default.</li>
  10114. <li><code>last_access_ts</code> - Media are ordered by when the content was last accessed in ms.
  10115. Smallest to largest.</li>
  10116. <li><code>media_length</code> - Media are ordered by length of the media in bytes.
  10117. Smallest to largest.</li>
  10118. <li><code>media_type</code> - Media are ordered alphabetically by MIME-type.</li>
  10119. <li><code>quarantined_by</code> - Media are ordered alphabetically by the user ID that
  10120. initiated the quarantine request for this media.</li>
  10121. <li><code>safe_from_quarantine</code> - Media are ordered by the status if this media is safe
  10122. from quarantining.</li>
  10123. </ul>
  10124. </li>
  10125. <li>
  10126. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  10127. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  10128. </li>
  10129. </ul>
  10130. <p>If neither <code>order_by</code> nor <code>dir</code> is set, the default order is newest media on top
  10131. (corresponds to <code>order_by</code> = <code>created_ts</code> and <code>dir</code> = <code>b</code>).</p>
  10132. <p>Caution. The database only has indexes on the columns <code>media_id</code>,
  10133. <code>user_id</code> and <code>created_ts</code>. This means that if a different sort order is used
  10134. (<code>upload_name</code>, <code>last_access_ts</code>, <code>media_length</code>, <code>media_type</code>,
  10135. <code>quarantined_by</code> or <code>safe_from_quarantine</code>), this can cause a large load on the
  10136. database, especially for large environments.</p>
  10137. <p><strong>Response</strong></p>
  10138. <p>The following fields are returned in the JSON response body:</p>
  10139. <ul>
  10140. <li><code>media</code> - An array of objects, each containing information about a media.
  10141. Media objects contain the following fields:
  10142. <ul>
  10143. <li><code>created_ts</code> - integer - Timestamp when the content was uploaded in ms.</li>
  10144. <li><code>last_access_ts</code> - integer - Timestamp when the content was last accessed in ms.</li>
  10145. <li><code>media_id</code> - string - The id used to refer to the media.</li>
  10146. <li><code>media_length</code> - integer - Length of the media in bytes.</li>
  10147. <li><code>media_type</code> - string - The MIME-type of the media.</li>
  10148. <li><code>quarantined_by</code> - string - The user ID that initiated the quarantine request
  10149. for this media.</li>
  10150. <li><code>safe_from_quarantine</code> - bool - Status if this media is safe from quarantining.</li>
  10151. <li><code>upload_name</code> - string - The name the media was uploaded with.</li>
  10152. </ul>
  10153. </li>
  10154. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  10155. <li><code>total</code> - integer - Total number of media.</li>
  10156. </ul>
  10157. <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>
  10158. <p>This API deletes the <em>local</em> media from the disk of your own server
  10159. that a specific <code>user_id</code> has created. This includes any local thumbnails.</p>
  10160. <p>This API will not affect media that has been uploaded to external
  10161. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).</p>
  10162. <p>By default, the API deletes media ordered by descending creation date and ascending media ID.
  10163. The newest media is deleted first. You can change the order with parameters
  10164. <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>
  10165. <p>The API is:</p>
  10166. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/media
  10167. </code></pre>
  10168. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10169. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10170. <p>A response body like the following is returned:</p>
  10171. <pre><code class="language-json">{
  10172. &quot;deleted_media&quot;: [
  10173. &quot;abcdefghijklmnopqrstuvwx&quot;
  10174. ],
  10175. &quot;total&quot;: 1
  10176. }
  10177. </code></pre>
  10178. <p>The following fields are returned in the JSON response body:</p>
  10179. <ul>
  10180. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  10181. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  10182. </ul>
  10183. <p><strong>Note</strong>: There is no <code>next_token</code>. This is not useful for deleting media, because
  10184. after deleting media the remaining media have a new order.</p>
  10185. <p><strong>Parameters</strong></p>
  10186. <p>This API has the same parameters as
  10187. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>.
  10188. With the parameters you can for example limit the number of files to delete at once or
  10189. delete largest/smallest or newest/oldest files first.</p>
  10190. <h2 id="login-as-a-user"><a class="header" href="#login-as-a-user">Login as a user</a></h2>
  10191. <p>Get an access token that can be used to authenticate as that user. Useful for
  10192. when admins wish to do actions on behalf of a user.</p>
  10193. <p>The API is:</p>
  10194. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/login
  10195. {}
  10196. </code></pre>
  10197. <p>An optional <code>valid_until_ms</code> field can be specified in the request body as an
  10198. integer timestamp that specifies when the token should expire. By default tokens
  10199. do not expire.</p>
  10200. <p>A response body like the following is returned:</p>
  10201. <pre><code class="language-json">{
  10202. &quot;access_token&quot;: &quot;&lt;opaque_access_token_string&gt;&quot;
  10203. }
  10204. </code></pre>
  10205. <p>This API does <em>not</em> generate a new device for the user, and so will not appear
  10206. their <code>/devices</code> list, and in general the target user should not be able to
  10207. tell they have been logged in as.</p>
  10208. <p>To expire the token call the standard <code>/logout</code> API with the token.</p>
  10209. <p>Note: The token will expire if the <em>admin</em> user calls <code>/logout/all</code> from any
  10210. of their devices, but the token will <em>not</em> expire if the target user does the
  10211. same.</p>
  10212. <h2 id="user-devices"><a class="header" href="#user-devices">User devices</a></h2>
  10213. <h3 id="list-all-devices"><a class="header" href="#list-all-devices">List all devices</a></h3>
  10214. <p>Gets information about all devices for a specific <code>user_id</code>.</p>
  10215. <p>The API is:</p>
  10216. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices
  10217. </code></pre>
  10218. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10219. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10220. <p>A response body like the following is returned:</p>
  10221. <pre><code class="language-json">{
  10222. &quot;devices&quot;: [
  10223. {
  10224. &quot;device_id&quot;: &quot;QBUAZIFURK&quot;,
  10225. &quot;display_name&quot;: &quot;android&quot;,
  10226. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10227. &quot;last_seen_ts&quot;: 1474491775024,
  10228. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10229. },
  10230. {
  10231. &quot;device_id&quot;: &quot;AUIECTSRND&quot;,
  10232. &quot;display_name&quot;: &quot;ios&quot;,
  10233. &quot;last_seen_ip&quot;: &quot;1.2.3.5&quot;,
  10234. &quot;last_seen_ts&quot;: 1474491775025,
  10235. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10236. }
  10237. ],
  10238. &quot;total&quot;: 2
  10239. }
  10240. </code></pre>
  10241. <p><strong>Parameters</strong></p>
  10242. <p>The following parameters should be set in the URL:</p>
  10243. <ul>
  10244. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10245. </ul>
  10246. <p><strong>Response</strong></p>
  10247. <p>The following fields are returned in the JSON response body:</p>
  10248. <ul>
  10249. <li>
  10250. <p><code>devices</code> - An array of objects, each containing information about a device.
  10251. Device objects contain the following fields:</p>
  10252. <ul>
  10253. <li><code>device_id</code> - Identifier of device.</li>
  10254. <li><code>display_name</code> - Display name set by the user for this device.
  10255. Absent if no name has been set.</li>
  10256. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10257. (May be a few minutes out of date, for efficiency reasons).</li>
  10258. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10259. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10260. <li><code>user_id</code> - Owner of device.</li>
  10261. </ul>
  10262. </li>
  10263. <li>
  10264. <p><code>total</code> - Total number of user's devices.</p>
  10265. </li>
  10266. </ul>
  10267. <h3 id="delete-multiple-devices"><a class="header" href="#delete-multiple-devices">Delete multiple devices</a></h3>
  10268. <p>Deletes the given devices for a specific <code>user_id</code>, and invalidates
  10269. any access token associated with them.</p>
  10270. <p>The API is:</p>
  10271. <pre><code>POST /_synapse/admin/v2/users/&lt;user_id&gt;/delete_devices
  10272. {
  10273. &quot;devices&quot;: [
  10274. &quot;QBUAZIFURK&quot;,
  10275. &quot;AUIECTSRND&quot;
  10276. ],
  10277. }
  10278. </code></pre>
  10279. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10280. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10281. <p>An empty JSON dict is returned.</p>
  10282. <p><strong>Parameters</strong></p>
  10283. <p>The following parameters should be set in the URL:</p>
  10284. <ul>
  10285. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10286. </ul>
  10287. <p>The following fields are required in the JSON request body:</p>
  10288. <ul>
  10289. <li><code>devices</code> - The list of device IDs to delete.</li>
  10290. </ul>
  10291. <h3 id="show-a-device"><a class="header" href="#show-a-device">Show a device</a></h3>
  10292. <p>Gets information on a single device, by <code>device_id</code> for a specific <code>user_id</code>.</p>
  10293. <p>The API is:</p>
  10294. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10295. </code></pre>
  10296. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10297. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10298. <p>A response body like the following is returned:</p>
  10299. <pre><code class="language-json">{
  10300. &quot;device_id&quot;: &quot;&lt;device_id&gt;&quot;,
  10301. &quot;display_name&quot;: &quot;android&quot;,
  10302. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10303. &quot;last_seen_ts&quot;: 1474491775024,
  10304. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10305. }
  10306. </code></pre>
  10307. <p><strong>Parameters</strong></p>
  10308. <p>The following parameters should be set in the URL:</p>
  10309. <ul>
  10310. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10311. <li><code>device_id</code> - The device to retrieve.</li>
  10312. </ul>
  10313. <p><strong>Response</strong></p>
  10314. <p>The following fields are returned in the JSON response body:</p>
  10315. <ul>
  10316. <li><code>device_id</code> - Identifier of device.</li>
  10317. <li><code>display_name</code> - Display name set by the user for this device.
  10318. Absent if no name has been set.</li>
  10319. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10320. (May be a few minutes out of date, for efficiency reasons).</li>
  10321. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10322. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10323. <li><code>user_id</code> - Owner of device.</li>
  10324. </ul>
  10325. <h3 id="update-a-device"><a class="header" href="#update-a-device">Update a device</a></h3>
  10326. <p>Updates the metadata on the given <code>device_id</code> for a specific <code>user_id</code>.</p>
  10327. <p>The API is:</p>
  10328. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10329. {
  10330. &quot;display_name&quot;: &quot;My other phone&quot;
  10331. }
  10332. </code></pre>
  10333. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10334. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10335. <p>An empty JSON dict is returned.</p>
  10336. <p><strong>Parameters</strong></p>
  10337. <p>The following parameters should be set in the URL:</p>
  10338. <ul>
  10339. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10340. <li><code>device_id</code> - The device to update.</li>
  10341. </ul>
  10342. <p>The following fields are required in the JSON request body:</p>
  10343. <ul>
  10344. <li><code>display_name</code> - The new display name for this device. If not given,
  10345. the display name is unchanged.</li>
  10346. </ul>
  10347. <h3 id="delete-a-device"><a class="header" href="#delete-a-device">Delete a device</a></h3>
  10348. <p>Deletes the given <code>device_id</code> for a specific <code>user_id</code>,
  10349. and invalidates any access token associated with it.</p>
  10350. <p>The API is:</p>
  10351. <pre><code>DELETE /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10352. {}
  10353. </code></pre>
  10354. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10355. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10356. <p>An empty JSON dict is returned.</p>
  10357. <p><strong>Parameters</strong></p>
  10358. <p>The following parameters should be set in the URL:</p>
  10359. <ul>
  10360. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10361. <li><code>device_id</code> - The device to delete.</li>
  10362. </ul>
  10363. <h2 id="list-all-pushers"><a class="header" href="#list-all-pushers">List all pushers</a></h2>
  10364. <p>Gets information about all pushers for a specific <code>user_id</code>.</p>
  10365. <p>The API is:</p>
  10366. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/pushers
  10367. </code></pre>
  10368. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10369. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10370. <p>A response body like the following is returned:</p>
  10371. <pre><code class="language-json">{
  10372. &quot;pushers&quot;: [
  10373. {
  10374. &quot;app_display_name&quot;:&quot;HTTP Push Notifications&quot;,
  10375. &quot;app_id&quot;:&quot;m.http&quot;,
  10376. &quot;data&quot;: {
  10377. &quot;url&quot;:&quot;example.com&quot;
  10378. },
  10379. &quot;device_display_name&quot;:&quot;pushy push&quot;,
  10380. &quot;kind&quot;:&quot;http&quot;,
  10381. &quot;lang&quot;:&quot;None&quot;,
  10382. &quot;profile_tag&quot;:&quot;&quot;,
  10383. &quot;pushkey&quot;:&quot;a@example.com&quot;
  10384. }
  10385. ],
  10386. &quot;total&quot;: 1
  10387. }
  10388. </code></pre>
  10389. <p><strong>Parameters</strong></p>
  10390. <p>The following parameters should be set in the URL:</p>
  10391. <ul>
  10392. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10393. </ul>
  10394. <p><strong>Response</strong></p>
  10395. <p>The following fields are returned in the JSON response body:</p>
  10396. <ul>
  10397. <li>
  10398. <p><code>pushers</code> - An array containing the current pushers for the user</p>
  10399. <ul>
  10400. <li>
  10401. <p><code>app_display_name</code> - string - A string that will allow the user to identify
  10402. what application owns this pusher.</p>
  10403. </li>
  10404. <li>
  10405. <p><code>app_id</code> - string - This is a reverse-DNS style identifier for the application.
  10406. Max length, 64 chars.</p>
  10407. </li>
  10408. <li>
  10409. <p><code>data</code> - A dictionary of information for the pusher implementation itself.</p>
  10410. <ul>
  10411. <li>
  10412. <p><code>url</code> - string - Required if <code>kind</code> is <code>http</code>. The URL to use to send
  10413. notifications to.</p>
  10414. </li>
  10415. <li>
  10416. <p><code>format</code> - string - The format to use when sending notifications to the
  10417. Push Gateway.</p>
  10418. </li>
  10419. </ul>
  10420. </li>
  10421. <li>
  10422. <p><code>device_display_name</code> - string - A string that will allow the user to identify
  10423. what device owns this pusher.</p>
  10424. </li>
  10425. <li>
  10426. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10427. this pusher executes.</p>
  10428. </li>
  10429. <li>
  10430. <p><code>kind</code> - string - The kind of pusher. &quot;http&quot; is a pusher that sends HTTP pokes.</p>
  10431. </li>
  10432. <li>
  10433. <p><code>lang</code> - string - The preferred language for receiving notifications
  10434. (e.g. 'en' or 'en-US')</p>
  10435. </li>
  10436. <li>
  10437. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10438. this pusher executes.</p>
  10439. </li>
  10440. <li>
  10441. <p><code>pushkey</code> - string - This is a unique identifier for this pusher.
  10442. Max length, 512 bytes.</p>
  10443. </li>
  10444. </ul>
  10445. </li>
  10446. <li>
  10447. <p><code>total</code> - integer - Number of pushers.</p>
  10448. </li>
  10449. </ul>
  10450. <p>See also the
  10451. <a href="https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers">Client-Server API Spec on pushers</a>.</p>
  10452. <h2 id="shadow-banning-users"><a class="header" href="#shadow-banning-users">Shadow-banning users</a></h2>
  10453. <p>Shadow-banning is a useful tool for moderating malicious or egregiously abusive users.
  10454. A shadow-banned users receives successful responses to their client-server API requests,
  10455. but the events are not propagated into rooms. This can be an effective tool as it
  10456. (hopefully) takes longer for the user to realise they are being moderated before
  10457. pivoting to another account.</p>
  10458. <p>Shadow-banning a user should be used as a tool of last resort and may lead to confusing
  10459. or broken behaviour for the client. A shadow-banned user will not receive any
  10460. notification and it is generally more appropriate to ban or kick abusive users.
  10461. A shadow-banned user will be unable to contact anyone on the server.</p>
  10462. <p>The API is:</p>
  10463. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/shadow_ban
  10464. </code></pre>
  10465. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10466. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10467. <p>An empty JSON dict is returned.</p>
  10468. <p><strong>Parameters</strong></p>
  10469. <p>The following parameters should be set in the URL:</p>
  10470. <ul>
  10471. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10472. be local.</li>
  10473. </ul>
  10474. <h2 id="override-ratelimiting-for-users"><a class="header" href="#override-ratelimiting-for-users">Override ratelimiting for users</a></h2>
  10475. <p>This API allows to override or disable ratelimiting for a specific user.
  10476. There are specific APIs to set, get and delete a ratelimit.</p>
  10477. <h3 id="get-status-of-ratelimit"><a class="header" href="#get-status-of-ratelimit">Get status of ratelimit</a></h3>
  10478. <p>The API is:</p>
  10479. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10480. </code></pre>
  10481. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10482. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10483. <p>A response body like the following is returned:</p>
  10484. <pre><code class="language-json">{
  10485. &quot;messages_per_second&quot;: 0,
  10486. &quot;burst_count&quot;: 0
  10487. }
  10488. </code></pre>
  10489. <p><strong>Parameters</strong></p>
  10490. <p>The following parameters should be set in the URL:</p>
  10491. <ul>
  10492. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10493. be local.</li>
  10494. </ul>
  10495. <p><strong>Response</strong></p>
  10496. <p>The following fields are returned in the JSON response body:</p>
  10497. <ul>
  10498. <li><code>messages_per_second</code> - integer - The number of actions that can
  10499. be performed in a second. <code>0</code> mean that ratelimiting is disabled for this user.</li>
  10500. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10501. being limited.</li>
  10502. </ul>
  10503. <p>If <strong>no</strong> custom ratelimit is set, an empty JSON dict is returned.</p>
  10504. <pre><code class="language-json">{}
  10505. </code></pre>
  10506. <h3 id="set-ratelimit"><a class="header" href="#set-ratelimit">Set ratelimit</a></h3>
  10507. <p>The API is:</p>
  10508. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10509. </code></pre>
  10510. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10511. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10512. <p>A response body like the following is returned:</p>
  10513. <pre><code class="language-json">{
  10514. &quot;messages_per_second&quot;: 0,
  10515. &quot;burst_count&quot;: 0
  10516. }
  10517. </code></pre>
  10518. <p><strong>Parameters</strong></p>
  10519. <p>The following parameters should be set in the URL:</p>
  10520. <ul>
  10521. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10522. be local.</li>
  10523. </ul>
  10524. <p>Body parameters:</p>
  10525. <ul>
  10526. <li><code>messages_per_second</code> - positive integer, optional. The number of actions that can
  10527. be performed in a second. Defaults to <code>0</code>.</li>
  10528. <li><code>burst_count</code> - positive integer, optional. How many actions that can be performed
  10529. before being limited. Defaults to <code>0</code>.</li>
  10530. </ul>
  10531. <p>To disable users' ratelimit set both values to <code>0</code>.</p>
  10532. <p><strong>Response</strong></p>
  10533. <p>The following fields are returned in the JSON response body:</p>
  10534. <ul>
  10535. <li><code>messages_per_second</code> - integer - The number of actions that can
  10536. be performed in a second.</li>
  10537. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10538. being limited.</li>
  10539. </ul>
  10540. <h3 id="delete-ratelimit"><a class="header" href="#delete-ratelimit">Delete ratelimit</a></h3>
  10541. <p>The API is:</p>
  10542. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10543. </code></pre>
  10544. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10545. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10546. <p>An empty JSON dict is returned.</p>
  10547. <pre><code class="language-json">{}
  10548. </code></pre>
  10549. <p><strong>Parameters</strong></p>
  10550. <p>The following parameters should be set in the URL:</p>
  10551. <ul>
  10552. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10553. be local.</li>
  10554. </ul>
  10555. <h3 id="check-username-availability"><a class="header" href="#check-username-availability">Check username availability</a></h3>
  10556. <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
  10557. API</a>
  10558. for more information.</p>
  10559. <p>This endpoint will work even if registration is disabled on the server, unlike
  10560. <code>/_matrix/client/r0/register/available</code>.</p>
  10561. <p>The API is:</p>
  10562. <pre><code>POST /_synapse/admin/v1/username_availabile?username=$localpart
  10563. </code></pre>
  10564. <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>
  10565. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10566. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10567. <div style="break-before: page; page-break-before: always;"></div><h1 id="version-api"><a class="header" href="#version-api">Version API</a></h1>
  10568. <p>This API returns the running Synapse version and the Python version
  10569. on which Synapse is being run. This is useful when a Synapse instance
  10570. is behind a proxy that does not forward the 'Server' header (which also
  10571. contains Synapse version information).</p>
  10572. <p>The api is:</p>
  10573. <pre><code>GET /_synapse/admin/v1/server_version
  10574. </code></pre>
  10575. <p>It returns a JSON body like the following:</p>
  10576. <pre><code class="language-json">{
  10577. &quot;server_version&quot;: &quot;0.99.2rc1 (b=develop, abcdef123)&quot;,
  10578. &quot;python_version&quot;: &quot;3.6.8&quot;
  10579. }
  10580. </code></pre>
  10581. <div 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>
  10582. <p>The &quot;manhole&quot; allows server administrators to access a Python shell on a running
  10583. Synapse installation. This is a very powerful mechanism for administration and
  10584. debugging.</p>
  10585. <p><strong><em>Security Warning</em></strong></p>
  10586. <p>Note that this will give administrative access to synapse to <strong>all users</strong> with
  10587. shell access to the server. It should therefore <strong>not</strong> be enabled in
  10588. environments where untrusted users have shell access.</p>
  10589. <h2 id="configuring-the-manhole"><a class="header" href="#configuring-the-manhole">Configuring the manhole</a></h2>
  10590. <p>To enable it, first uncomment the <code>manhole</code> listener configuration in
  10591. <code>homeserver.yaml</code>. The configuration is slightly different if you're using docker.</p>
  10592. <h4 id="docker-config"><a class="header" href="#docker-config">Docker config</a></h4>
  10593. <p>If you are using Docker, set <code>bind_addresses</code> to <code>['0.0.0.0']</code> as shown:</p>
  10594. <pre><code class="language-yaml">listeners:
  10595. - port: 9000
  10596. bind_addresses: ['0.0.0.0']
  10597. type: manhole
  10598. </code></pre>
  10599. <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
  10600. <code>manhole</code> port forwarding. The <code>-p 127.0.0.1:9000:9000</code> below is important: it
  10601. ensures that access to the <code>manhole</code> is only possible for local users.</p>
  10602. <pre><code class="language-bash">docker run -d --name synapse \
  10603. --mount type=volume,src=synapse-data,dst=/data \
  10604. -p 8008:8008 \
  10605. -p 127.0.0.1:9000:9000 \
  10606. matrixdotorg/synapse:latest
  10607. </code></pre>
  10608. <h4 id="native-config"><a class="header" href="#native-config">Native config</a></h4>
  10609. <p>If you are not using docker, set <code>bind_addresses</code> to <code>['::1', '127.0.0.1']</code> as shown.
  10610. The <code>bind_addresses</code> in the example below is important: it ensures that access to the
  10611. <code>manhole</code> is only possible for local users).</p>
  10612. <pre><code class="language-yaml">listeners:
  10613. - port: 9000
  10614. bind_addresses: ['::1', '127.0.0.1']
  10615. type: manhole
  10616. </code></pre>
  10617. <h3 id="security-settings"><a class="header" href="#security-settings">Security settings</a></h3>
  10618. <p>The following config options are available:</p>
  10619. <ul>
  10620. <li><code>username</code> - The username for the manhole (defaults to <code>matrix</code>)</li>
  10621. <li><code>password</code> - The password for the manhole (defaults to <code>rabbithole</code>)</li>
  10622. <li><code>ssh_priv_key</code> - The path to a private SSH key (defaults to a hardcoded value)</li>
  10623. <li><code>ssh_pub_key</code> - The path to a public SSH key (defaults to a hardcoded value)</li>
  10624. </ul>
  10625. <p>For example:</p>
  10626. <pre><code class="language-yaml">manhole_settings:
  10627. username: manhole
  10628. password: mypassword
  10629. ssh_priv_key: &quot;/home/synapse/manhole_keys/id_rsa&quot;
  10630. ssh_pub_key: &quot;/home/synapse/manhole_keys/id_rsa.pub&quot;
  10631. </code></pre>
  10632. <h2 id="accessing-synapse-manhole"><a class="header" href="#accessing-synapse-manhole">Accessing synapse manhole</a></h2>
  10633. <p>Then restart synapse, and point an ssh client at port 9000 on localhost, using
  10634. the username and password configured in <code>homeserver.yaml</code> - with the default
  10635. configuration, this would be:</p>
  10636. <pre><code class="language-bash">ssh -p9000 matrix@localhost
  10637. </code></pre>
  10638. <p>Then enter the password when prompted (the default is <code>rabbithole</code>).</p>
  10639. <p>This gives a Python REPL in which <code>hs</code> gives access to the
  10640. <code>synapse.server.HomeServer</code> object - which in turn gives access to many other
  10641. parts of the process.</p>
  10642. <p>Note that, prior to Synapse 1.41, any call which returns a coroutine will need to be wrapped in <code>ensureDeferred</code>.</p>
  10643. <p>As a simple example, retrieving an event from the database:</p>
  10644. <pre><code class="language-pycon">&gt;&gt;&gt; from twisted.internet import defer
  10645. &gt;&gt;&gt; defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
  10646. &lt;Deferred at 0x7ff253fc6998 current result: &lt;FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''&gt;&gt;
  10647. </code></pre>
  10648. <div 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>
  10649. <ol>
  10650. <li>
  10651. <p>Install Prometheus:</p>
  10652. <p>Follow instructions at
  10653. <a href="http://prometheus.io/docs/introduction/install/">http://prometheus.io/docs/introduction/install/</a></p>
  10654. </li>
  10655. <li>
  10656. <p>Enable Synapse metrics:</p>
  10657. <p>There are two methods of enabling metrics in Synapse.</p>
  10658. <p>The first serves the metrics as a part of the usual web server and
  10659. can be enabled by adding the &quot;metrics&quot; resource to the existing
  10660. listener as such:</p>
  10661. <pre><code class="language-yaml"> resources:
  10662. - names:
  10663. - client
  10664. - metrics
  10665. </code></pre>
  10666. <p>This provides a simple way of adding metrics to your Synapse
  10667. installation, and serves under <code>/_synapse/metrics</code>. If you do not
  10668. wish your metrics be publicly exposed, you will need to either
  10669. filter it out at your load balancer, or use the second method.</p>
  10670. <p>The second method runs the metrics server on a different port, in a
  10671. different thread to Synapse. This can make it more resilient to
  10672. heavy load meaning metrics cannot be retrieved, and can be exposed
  10673. to just internal networks easier. The served metrics are available
  10674. over HTTP only, and will be available at <code>/_synapse/metrics</code>.</p>
  10675. <p>Add a new listener to homeserver.yaml:</p>
  10676. <pre><code class="language-yaml"> listeners:
  10677. - type: metrics
  10678. port: 9000
  10679. bind_addresses:
  10680. - '0.0.0.0'
  10681. </code></pre>
  10682. <p>For both options, you will need to ensure that <code>enable_metrics</code> is
  10683. set to <code>True</code>.</p>
  10684. </li>
  10685. <li>
  10686. <p>Restart Synapse.</p>
  10687. </li>
  10688. <li>
  10689. <p>Add a Prometheus target for Synapse.</p>
  10690. <p>It needs to set the <code>metrics_path</code> to a non-default value (under
  10691. <code>scrape_configs</code>):</p>
  10692. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10693. scrape_interval: 15s
  10694. metrics_path: &quot;/_synapse/metrics&quot;
  10695. static_configs:
  10696. - targets: [&quot;my.server.here:port&quot;]
  10697. </code></pre>
  10698. <p>where <code>my.server.here</code> is the IP address of Synapse, and <code>port</code> is
  10699. the listener port configured with the <code>metrics</code> resource.</p>
  10700. <p>If your prometheus is older than 1.5.2, you will need to replace
  10701. <code>static_configs</code> in the above with <code>target_groups</code>.</p>
  10702. </li>
  10703. <li>
  10704. <p>Restart Prometheus.</p>
  10705. </li>
  10706. <li>
  10707. <p>Consider using the <a href="https://github.com/matrix-org/synapse/tree/master/contrib/grafana/">grafana dashboard</a>
  10708. and required <a href="https://github.com/matrix-org/synapse/tree/master/contrib/prometheus/">recording rules</a> </p>
  10709. </li>
  10710. </ol>
  10711. <h2 id="monitoring-workers"><a class="header" href="#monitoring-workers">Monitoring workers</a></h2>
  10712. <p>To monitor a Synapse installation using <a href="workers.html">workers</a>,
  10713. every worker needs to be monitored independently, in addition to
  10714. the main homeserver process. This is because workers don't send
  10715. their metrics to the main homeserver process, but expose them
  10716. directly (if they are configured to do so).</p>
  10717. <p>To allow collecting metrics from a worker, you need to add a
  10718. <code>metrics</code> listener to its configuration, by adding the following
  10719. under <code>worker_listeners</code>:</p>
  10720. <pre><code class="language-yaml"> - type: metrics
  10721. bind_address: ''
  10722. port: 9101
  10723. </code></pre>
  10724. <p>The <code>bind_address</code> and <code>port</code> parameters should be set so that
  10725. the resulting listener can be reached by prometheus, and they
  10726. don't clash with an existing worker.
  10727. With this example, the worker's metrics would then be available
  10728. on <code>http://127.0.0.1:9101</code>.</p>
  10729. <p>Example Prometheus target for Synapse with workers:</p>
  10730. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10731. scrape_interval: 15s
  10732. metrics_path: &quot;/_synapse/metrics&quot;
  10733. static_configs:
  10734. - targets: [&quot;my.server.here:port&quot;]
  10735. labels:
  10736. instance: &quot;my.server&quot;
  10737. job: &quot;master&quot;
  10738. index: 1
  10739. - targets: [&quot;my.workerserver.here:port&quot;]
  10740. labels:
  10741. instance: &quot;my.server&quot;
  10742. job: &quot;generic_worker&quot;
  10743. index: 1
  10744. - targets: [&quot;my.workerserver.here:port&quot;]
  10745. labels:
  10746. instance: &quot;my.server&quot;
  10747. job: &quot;generic_worker&quot;
  10748. index: 2
  10749. - targets: [&quot;my.workerserver.here:port&quot;]
  10750. labels:
  10751. instance: &quot;my.server&quot;
  10752. job: &quot;media_repository&quot;
  10753. index: 1
  10754. </code></pre>
  10755. <p>Labels (<code>instance</code>, <code>job</code>, <code>index</code>) can be defined as anything.
  10756. The labels are used to group graphs in grafana.</p>
  10757. <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>
  10758. <p>Synapse 1.2 updates the Prometheus metrics to match the naming
  10759. convention of the upstream <code>prometheus_client</code>. The old names are
  10760. considered deprecated and will be removed in a future version of
  10761. Synapse.</p>
  10762. <table><thead><tr><th>New Name</th><th>Old Name</th></tr></thead><tbody>
  10763. <tr><td>python_gc_objects_collected_total</td><td>python_gc_objects_collected</td></tr>
  10764. <tr><td>python_gc_objects_uncollectable_total</td><td>python_gc_objects_uncollectable</td></tr>
  10765. <tr><td>python_gc_collections_total</td><td>python_gc_collections</td></tr>
  10766. <tr><td>process_cpu_seconds_total</td><td>process_cpu_seconds</td></tr>
  10767. <tr><td>synapse_federation_client_sent_transactions_total</td><td>synapse_federation_client_sent_transactions</td></tr>
  10768. <tr><td>synapse_federation_client_events_processed_total</td><td>synapse_federation_client_events_processed</td></tr>
  10769. <tr><td>synapse_event_processing_loop_count_total</td><td>synapse_event_processing_loop_count</td></tr>
  10770. <tr><td>synapse_event_processing_loop_room_count_total</td><td>synapse_event_processing_loop_room_count</td></tr>
  10771. <tr><td>synapse_util_metrics_block_count_total</td><td>synapse_util_metrics_block_count</td></tr>
  10772. <tr><td>synapse_util_metrics_block_time_seconds_total</td><td>synapse_util_metrics_block_time_seconds</td></tr>
  10773. <tr><td>synapse_util_metrics_block_ru_utime_seconds_total</td><td>synapse_util_metrics_block_ru_utime_seconds</td></tr>
  10774. <tr><td>synapse_util_metrics_block_ru_stime_seconds_total</td><td>synapse_util_metrics_block_ru_stime_seconds</td></tr>
  10775. <tr><td>synapse_util_metrics_block_db_txn_count_total</td><td>synapse_util_metrics_block_db_txn_count</td></tr>
  10776. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds_total</td><td>synapse_util_metrics_block_db_txn_duration_seconds</td></tr>
  10777. <tr><td>synapse_util_metrics_block_db_sched_duration_seconds_total</td><td>synapse_util_metrics_block_db_sched_duration_seconds</td></tr>
  10778. <tr><td>synapse_background_process_start_count_total</td><td>synapse_background_process_start_count</td></tr>
  10779. <tr><td>synapse_background_process_ru_utime_seconds_total</td><td>synapse_background_process_ru_utime_seconds</td></tr>
  10780. <tr><td>synapse_background_process_ru_stime_seconds_total</td><td>synapse_background_process_ru_stime_seconds</td></tr>
  10781. <tr><td>synapse_background_process_db_txn_count_total</td><td>synapse_background_process_db_txn_count</td></tr>
  10782. <tr><td>synapse_background_process_db_txn_duration_seconds_total</td><td>synapse_background_process_db_txn_duration_seconds</td></tr>
  10783. <tr><td>synapse_background_process_db_sched_duration_seconds_total</td><td>synapse_background_process_db_sched_duration_seconds</td></tr>
  10784. <tr><td>synapse_storage_events_persisted_events_total</td><td>synapse_storage_events_persisted_events</td></tr>
  10785. <tr><td>synapse_storage_events_persisted_events_sep_total</td><td>synapse_storage_events_persisted_events_sep</td></tr>
  10786. <tr><td>synapse_storage_events_state_delta_total</td><td>synapse_storage_events_state_delta</td></tr>
  10787. <tr><td>synapse_storage_events_state_delta_single_event_total</td><td>synapse_storage_events_state_delta_single_event</td></tr>
  10788. <tr><td>synapse_storage_events_state_delta_reuse_delta_total</td><td>synapse_storage_events_state_delta_reuse_delta</td></tr>
  10789. <tr><td>synapse_federation_server_received_pdus_total</td><td>synapse_federation_server_received_pdus</td></tr>
  10790. <tr><td>synapse_federation_server_received_edus_total</td><td>synapse_federation_server_received_edus</td></tr>
  10791. <tr><td>synapse_handler_presence_notified_presence_total</td><td>synapse_handler_presence_notified_presence</td></tr>
  10792. <tr><td>synapse_handler_presence_federation_presence_out_total</td><td>synapse_handler_presence_federation_presence_out</td></tr>
  10793. <tr><td>synapse_handler_presence_presence_updates_total</td><td>synapse_handler_presence_presence_updates</td></tr>
  10794. <tr><td>synapse_handler_presence_timers_fired_total</td><td>synapse_handler_presence_timers_fired</td></tr>
  10795. <tr><td>synapse_handler_presence_federation_presence_total</td><td>synapse_handler_presence_federation_presence</td></tr>
  10796. <tr><td>synapse_handler_presence_bump_active_time_total</td><td>synapse_handler_presence_bump_active_time</td></tr>
  10797. <tr><td>synapse_federation_client_sent_edus_total</td><td>synapse_federation_client_sent_edus</td></tr>
  10798. <tr><td>synapse_federation_client_sent_pdu_destinations_count_total</td><td>synapse_federation_client_sent_pdu_destinations:count</td></tr>
  10799. <tr><td>synapse_federation_client_sent_pdu_destinations_total</td><td>synapse_federation_client_sent_pdu_destinations:total</td></tr>
  10800. <tr><td>synapse_handlers_appservice_events_processed_total</td><td>synapse_handlers_appservice_events_processed</td></tr>
  10801. <tr><td>synapse_notifier_notified_events_total</td><td>synapse_notifier_notified_events</td></tr>
  10802. <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>
  10803. <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>
  10804. <tr><td>synapse_http_httppusher_http_pushes_processed_total</td><td>synapse_http_httppusher_http_pushes_processed</td></tr>
  10805. <tr><td>synapse_http_httppusher_http_pushes_failed_total</td><td>synapse_http_httppusher_http_pushes_failed</td></tr>
  10806. <tr><td>synapse_http_httppusher_badge_updates_processed_total</td><td>synapse_http_httppusher_badge_updates_processed</td></tr>
  10807. <tr><td>synapse_http_httppusher_badge_updates_failed_total</td><td>synapse_http_httppusher_badge_updates_failed</td></tr>
  10808. </tbody></table>
  10809. <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>
  10810. <p>The duplicated metrics deprecated in Synapse 0.27.0 have been removed.</p>
  10811. <p>All time duration-based metrics have been changed to be seconds. This
  10812. affects:</p>
  10813. <table><thead><tr><th>msec -&gt; sec metrics</th></tr></thead><tbody>
  10814. <tr><td>python_gc_time</td></tr>
  10815. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10816. <tr><td>synapse_storage_query_time</td></tr>
  10817. <tr><td>synapse_storage_schedule_time</td></tr>
  10818. <tr><td>synapse_storage_transaction_time</td></tr>
  10819. </tbody></table>
  10820. <p>Several metrics have been changed to be histograms, which sort entries
  10821. into buckets and allow better analysis. The following metrics are now
  10822. histograms:</p>
  10823. <table><thead><tr><th>Altered metrics</th></tr></thead><tbody>
  10824. <tr><td>python_gc_time</td></tr>
  10825. <tr><td>python_twisted_reactor_pending_calls</td></tr>
  10826. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10827. <tr><td>synapse_http_server_response_time_seconds</td></tr>
  10828. <tr><td>synapse_storage_query_time</td></tr>
  10829. <tr><td>synapse_storage_schedule_time</td></tr>
  10830. <tr><td>synapse_storage_transaction_time</td></tr>
  10831. </tbody></table>
  10832. <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>
  10833. <p>Synapse 0.27.0 begins the process of rationalising the duplicate
  10834. <code>*:count</code> metrics reported for the resource tracking for code blocks and
  10835. HTTP requests.</p>
  10836. <p>At the same time, the corresponding <code>*:total</code> metrics are being renamed,
  10837. as the <code>:total</code> suffix no longer makes sense in the absence of a
  10838. corresponding <code>:count</code> metric.</p>
  10839. <p>To enable a graceful migration path, this release just adds new names
  10840. for the metrics being renamed. A future release will remove the old
  10841. ones.</p>
  10842. <p>The following table shows the new metrics, and the old metrics which
  10843. they are replacing.</p>
  10844. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10845. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_timer:count</td></tr>
  10846. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_utime:count</td></tr>
  10847. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_stime:count</td></tr>
  10848. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_count:count</td></tr>
  10849. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_duration:count</td></tr>
  10850. <tr><td>synapse_util_metrics_block_time_seconds</td><td>synapse_util_metrics_block_timer:total</td></tr>
  10851. <tr><td>synapse_util_metrics_block_ru_utime_seconds</td><td>synapse_util_metrics_block_ru_utime:total</td></tr>
  10852. <tr><td>synapse_util_metrics_block_ru_stime_seconds</td><td>synapse_util_metrics_block_ru_stime:total</td></tr>
  10853. <tr><td>synapse_util_metrics_block_db_txn_count</td><td>synapse_util_metrics_block_db_txn_count:total</td></tr>
  10854. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds</td><td>synapse_util_metrics_block_db_txn_duration:total</td></tr>
  10855. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_requests</td></tr>
  10856. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_time:count</td></tr>
  10857. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_utime:count</td></tr>
  10858. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_stime:count</td></tr>
  10859. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_count:count</td></tr>
  10860. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_duration:count</td></tr>
  10861. <tr><td>synapse_http_server_response_time_seconds</td><td>synapse_http_server_response_time:total</td></tr>
  10862. <tr><td>synapse_http_server_response_ru_utime_seconds</td><td>synapse_http_server_response_ru_utime:total</td></tr>
  10863. <tr><td>synapse_http_server_response_ru_stime_seconds</td><td>synapse_http_server_response_ru_stime:total</td></tr>
  10864. <tr><td>synapse_http_server_response_db_txn_count</td><td>synapse_http_server_response_db_txn_count:total</td></tr>
  10865. <tr><td>synapse_http_server_response_db_txn_duration_seconds</td><td>synapse_http_server_response_db_txn_duration:total</td></tr>
  10866. </tbody></table>
  10867. <h2 id="standard-metric-names"><a class="header" href="#standard-metric-names">Standard Metric Names</a></h2>
  10868. <p>As of synapse version 0.18.2, the format of the process-wide metrics has
  10869. been changed to fit prometheus standard naming conventions. Additionally
  10870. the units have been changed to seconds, from miliseconds.</p>
  10871. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10872. <tr><td>process_cpu_user_seconds_total</td><td>process_resource_utime / 1000</td></tr>
  10873. <tr><td>process_cpu_system_seconds_total</td><td>process_resource_stime / 1000</td></tr>
  10874. <tr><td>process_open_fds (no 'type' label)</td><td>process_fds</td></tr>
  10875. </tbody></table>
  10876. <p>The python-specific counts of garbage collector performance have been
  10877. renamed.</p>
  10878. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10879. <tr><td>python_gc_time</td><td>reactor_gc_time</td></tr>
  10880. <tr><td>python_gc_unreachable_total</td><td>reactor_gc_unreachable</td></tr>
  10881. <tr><td>python_gc_counts</td><td>reactor_gc_counts</td></tr>
  10882. </tbody></table>
  10883. <p>The twisted-specific reactor metrics have been renamed.</p>
  10884. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10885. <tr><td>python_twisted_reactor_pending_calls</td><td>reactor_pending_calls</td></tr>
  10886. <tr><td>python_twisted_reactor_tick_time</td><td>reactor_tick_time</td></tr>
  10887. </tbody></table>
  10888. <div 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>
  10889. <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>
  10890. <p>See the following for how to decode the dense data available from the default logging configuration.</p>
  10891. <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]
  10892. -AAAAAAAAAAAAAAAAAAAAA- -BBBBBBBBBBBBBBBBBBBBBB- -C- -DD- -EEEEEE- -FFFFFFFFF- -GG- -HHHHHHHHHHHHHHHHHHHHHHH- -IIIIII- -JJJJJJJ- -KKKKKK-, -LLLLLL- -MMMMMMM- -NNNNNN- O -P- -QQ- -RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR- -SSSSSSSSSSSS- -TTTTTT-
  10893. </code></pre>
  10894. <table><thead><tr><th>Part</th><th>Explanation</th></tr></thead><tbody>
  10895. <tr><td>AAAA</td><td>Timestamp request was logged (not recieved)</td></tr>
  10896. <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>
  10897. <tr><td>CCCC</td><td>Line number in code</td></tr>
  10898. <tr><td>DDDD</td><td>Log Level</td></tr>
  10899. <tr><td>EEEE</td><td>Request Identifier (This identifier is shared by related log lines)</td></tr>
  10900. <tr><td>FFFF</td><td>Source IP (Or X-Forwarded-For if enabled)</td></tr>
  10901. <tr><td>GGGG</td><td>Server Port</td></tr>
  10902. <tr><td>HHHH</td><td>Federated Server or Local User making request (blank if unauthenticated or not supplied)</td></tr>
  10903. <tr><td>IIII</td><td>Total Time to process the request</td></tr>
  10904. <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>
  10905. <tr><td>KKKK</td><td>Userland CPU time</td></tr>
  10906. <tr><td>LLLL</td><td>System CPU time</td></tr>
  10907. <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>
  10908. <tr><td>NNNN</td><td>Total time waiting for response to DB queries across all parallel DB work from this request</td></tr>
  10909. <tr><td>OOOO</td><td>Count of DB transactions performed</td></tr>
  10910. <tr><td>PPPP</td><td>Response body size</td></tr>
  10911. <tr><td>QQQQ</td><td>Response status code (prefixed with ! if the socket was closed before the response was generated)</td></tr>
  10912. <tr><td>RRRR</td><td>Request</td></tr>
  10913. <tr><td>SSSS</td><td>User-agent</td></tr>
  10914. <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>
  10915. </tbody></table>
  10916. <p>MMMM / NNNN can be greater than IIII if there are multiple slow database queries
  10917. running in parallel.</p>
  10918. <p>Some actions can result in multiple identical http requests, which will return
  10919. the same data, but only the first request will report time/transactions in
  10920. <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
  10921. response and will simultaneously return with the first request, but with very
  10922. small processing times.</p>
  10923. <div style="break-before: page; page-break-before: always;"></div><h1 id="contributing"><a class="header" href="#contributing">Contributing</a></h1>
  10924. <p>This document aims to get you started with contributing to Synapse!</p>
  10925. <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>
  10926. <p>Everyone is welcome to contribute code to <a href="https://github.com/matrix-org">matrix.org
  10927. projects</a>, provided that they are willing to
  10928. license their contributions under the same license as the project itself. We
  10929. follow a simple 'inbound=outbound' model for contributions: the act of
  10930. submitting an 'inbound' contribution means that the contributor agrees to
  10931. license the code under the same terms as the project's overall 'outbound'
  10932. license - in our case, this is almost always Apache Software License v2 (see
  10933. <a href="https://github.com/matrix-org/synapse/blob/develop/LICENSE">LICENSE</a>).</p>
  10934. <h1 id="2-what-do-i-need"><a class="header" href="#2-what-do-i-need">2. What do I need?</a></h1>
  10935. <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>
  10936. <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>
  10937. <p>For some tests, you will need <a href="https://docs.docker.com/get-docker/">a recent version of Docker</a>.</p>
  10938. <h1 id="3-get-the-source"><a class="header" href="#3-get-the-source">3. Get the source.</a></h1>
  10939. <p>The preferred and easiest way to contribute changes is to fork the relevant
  10940. 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
  10941. changes into our repo.</p>
  10942. <p>Please base your changes on the <code>develop</code> branch.</p>
  10943. <pre><code class="language-sh">git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git
  10944. git checkout develop
  10945. </code></pre>
  10946. <p>If you need help getting started with git, this is beyond the scope of the document, but you
  10947. can find many good git tutorials on the web.</p>
  10948. <h1 id="4-install-the-dependencies"><a class="header" href="#4-install-the-dependencies">4. Install the dependencies</a></h1>
  10949. <h2 id="under-unix-macos-linux-bsd-"><a class="header" href="#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></h2>
  10950. <p>Once you have installed Python 3 and added the source, please open a terminal and
  10951. setup a <em>virtualenv</em>, as follows:</p>
  10952. <pre><code class="language-sh">cd path/where/you/have/cloned/the/repository
  10953. python3 -m venv ./env
  10954. source ./env/bin/activate
  10955. pip install -e &quot;.[all,lint,mypy,test]&quot;
  10956. pip install tox
  10957. </code></pre>
  10958. <p>This will install the developer dependencies for the project.</p>
  10959. <h2 id="under-windows"><a class="header" href="#under-windows">Under Windows</a></h2>
  10960. <p>TBD</p>
  10961. <h1 id="5-get-in-touch"><a class="header" href="#5-get-in-touch">5. Get in touch.</a></h1>
  10962. <p>Join our developer community on Matrix: #synapse-dev:matrix.org !</p>
  10963. <h1 id="6-pick-an-issue"><a class="header" href="#6-pick-an-issue">6. Pick an issue.</a></h1>
  10964. <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>
  10965. to work on.</p>
  10966. <h1 id="7-turn-coffee-into-code-and-documentation"><a class="header" href="#7-turn-coffee-into-code-and-documentation">7. Turn coffee into code and documentation!</a></h1>
  10967. <p>There is a growing amount of documentation located in the
  10968. <a href="https://github.com/matrix-org/synapse/tree/develop/docs"><code>docs</code></a>
  10969. directory, with a rendered version <a href="https://matrix-org.github.io/synapse">available online</a>.
  10970. This documentation is intended primarily for sysadmins running their
  10971. own Synapse instance, as well as developers interacting externally with
  10972. Synapse.
  10973. <a href="https://github.com/matrix-org/synapse/tree/develop/docs/development"><code>docs/development</code></a>
  10974. exists primarily to house documentation for
  10975. Synapse developers.
  10976. <a href="https://github.com/matrix-org/synapse/tree/develop/docs/admin_api"><code>docs/admin_api</code></a> houses documentation
  10977. regarding Synapse's Admin API, which is used mostly by sysadmins and external
  10978. service developers.</p>
  10979. <p>Synapse's code style is documented <a href="development/../code_style.html">here</a>. Please follow
  10980. it, including the conventions for the <a href="development/../code_style.html#configuration-file-format">sample configuration
  10981. file</a>.</p>
  10982. <p>We welcome improvements and additions to our documentation itself! When
  10983. writing new pages, please
  10984. <a href="https://github.com/matrix-org/synapse/tree/develop/docs#adding-to-the-documentation">build <code>docs</code> to a book</a>
  10985. to check that your contributions render correctly. The docs are written in
  10986. <a href="https://guides.github.com/features/mastering-markdown/">GitHub-Flavoured Markdown</a>.</p>
  10987. <p>Some documentation also exists in <a href="https://github.com/matrix-org/synapse/wiki">Synapse's GitHub
  10988. Wiki</a>, although this is primarily
  10989. contributed to by community authors.</p>
  10990. <h1 id="8-test-test-test"><a class="header" href="#8-test-test-test">8. Test, test, test!</a></h1>
  10991. <p><a name="test-test-test"></a></p>
  10992. <p>While you're developing and before submitting a patch, you'll
  10993. want to test your code.</p>
  10994. <h2 id="run-the-linters"><a class="header" href="#run-the-linters">Run the linters.</a></h2>
  10995. <p>The linters look at your code and do two things:</p>
  10996. <ul>
  10997. <li>ensure that your code follows the coding style adopted by the project;</li>
  10998. <li>catch a number of errors in your code.</li>
  10999. </ul>
  11000. <p>They're pretty fast, don't hesitate!</p>
  11001. <pre><code class="language-sh">source ./env/bin/activate
  11002. ./scripts-dev/lint.sh
  11003. </code></pre>
  11004. <p>Note that this script <em>will modify your files</em> to fix styling errors.
  11005. Make sure that you have saved all your files.</p>
  11006. <p>If you wish to restrict the linters to only the files changed since the last commit
  11007. (much faster!), you can instead run:</p>
  11008. <pre><code class="language-sh">source ./env/bin/activate
  11009. ./scripts-dev/lint.sh -d
  11010. </code></pre>
  11011. <p>Or if you know exactly which files you wish to lint, you can instead run:</p>
  11012. <pre><code class="language-sh">source ./env/bin/activate
  11013. ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
  11014. </code></pre>
  11015. <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>
  11016. <p>The unit tests run parts of Synapse, including your changes, to see if anything
  11017. was broken. They are slower than the linters but will typically catch more errors.</p>
  11018. <pre><code class="language-sh">source ./env/bin/activate
  11019. trial tests
  11020. </code></pre>
  11021. <p>If you wish to only run <em>some</em> unit tests, you may specify
  11022. another module instead of <code>tests</code> - or a test class or a method:</p>
  11023. <pre><code class="language-sh">source ./env/bin/activate
  11024. trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
  11025. </code></pre>
  11026. <p>If your tests fail, you may wish to look at the logs (the default log level is <code>ERROR</code>):</p>
  11027. <pre><code class="language-sh">less _trial_temp/test.log
  11028. </code></pre>
  11029. <p>To increase the log level for the tests, set <code>SYNAPSE_TEST_LOG_LEVEL</code>:</p>
  11030. <pre><code class="language-sh">SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
  11031. </code></pre>
  11032. <h3 id="running-tests-under-postgresql"><a class="header" href="#running-tests-under-postgresql">Running tests under PostgreSQL</a></h3>
  11033. <p>Invoking <code>trial</code> as above will use an in-memory SQLite database. This is great for
  11034. quick development and testing. However, we recommend using a PostgreSQL database
  11035. in production (and indeed, we have some code paths specific to each database).
  11036. This means that we need to run our unit tests against PostgreSQL too. Our CI does
  11037. this automatically for pull requests and release candidates, but it's sometimes
  11038. useful to reproduce this locally.</p>
  11039. <p>To do so, <a href="development/../postgres.html">configure Postgres</a> and run <code>trial</code> with the
  11040. following environment variables matching your configuration:</p>
  11041. <ul>
  11042. <li><code>SYNAPSE_POSTGRES</code> to anything nonempty</li>
  11043. <li><code>SYNAPSE_POSTGRES_HOST</code></li>
  11044. <li><code>SYNAPSE_POSTGRES_USER</code></li>
  11045. <li><code>SYNAPSE_POSTGRES_PASSWORD</code></li>
  11046. </ul>
  11047. <p>For example:</p>
  11048. <pre><code class="language-shell">export SYNAPSE_POSTGRES=1
  11049. export SYNAPSE_POSTGRES_HOST=localhost
  11050. export SYNAPSE_POSTGRES_USER=postgres
  11051. export SYNAPSE_POSTGRES_PASSWORD=mydevenvpassword
  11052. trial
  11053. </code></pre>
  11054. <h4 id="prebuilt-container"><a class="header" href="#prebuilt-container">Prebuilt container</a></h4>
  11055. <p>Since configuring PostgreSQL can be fiddly, we can make use of a pre-made
  11056. Docker container to set up PostgreSQL and run our tests for us. To do so, run</p>
  11057. <pre><code class="language-shell">scripts-dev/test_postgresql.sh
  11058. </code></pre>
  11059. <p>Any extra arguments to the script will be passed to <code>tox</code> and then to <code>trial</code>,
  11060. so we can run a specific test in this container with e.g.</p>
  11061. <pre><code class="language-shell">scripts-dev/test_postgresql.sh tests.replication.test_sharded_event_persister.EventPersisterShardTestCase
  11062. </code></pre>
  11063. <p>The container creates a folder in your Synapse checkout called
  11064. <code>.tox-pg-container</code> and uses this as a tox environment. The output of any
  11065. <code>trial</code> runs goes into <code>_trial_temp</code> in your synapse source directory — the same
  11066. as running <code>trial</code> directly on your host machine.</p>
  11067. <h2 id="run-the-integration-tests-sytest"><a class="header" href="#run-the-integration-tests-sytest">Run the integration tests (<a href="https://github.com/matrix-org/sytest">Sytest</a>).</a></h2>
  11068. <p>The integration tests are a more comprehensive suite of tests. They
  11069. run a full version of Synapse, including your changes, to check if
  11070. anything was broken. They are slower than the unit tests but will
  11071. typically catch more errors.</p>
  11072. <p>The following command will let you run the integration test with the most common
  11073. configuration:</p>
  11074. <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
  11075. </code></pre>
  11076. <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>
  11077. <h2 id="run-the-integration-tests-complement"><a class="header" href="#run-the-integration-tests-complement">Run the integration tests (<a href="https://github.com/matrix-org/complement">Complement</a>).</a></h2>
  11078. <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>
  11079. <p>It's often nice to develop on Synapse and write Complement tests at the same time.
  11080. Here is how to run your local Synapse checkout against your local Complement checkout.</p>
  11081. <p>(checkout <a href="https://github.com/matrix-org/complement"><code>complement</code></a> alongside your <code>synapse</code> checkout)</p>
  11082. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh
  11083. </code></pre>
  11084. <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>
  11085. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory
  11086. </code></pre>
  11087. <p>To run a specific test, you can specify the whole name structure:</p>
  11088. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory/parallel/Backfilled_historical_events_resolve_with_proper_state_in_correct_order
  11089. </code></pre>
  11090. <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>
  11091. <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>
  11092. <ol>
  11093. <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>
  11094. <li>Start the Complement tests</li>
  11095. <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>
  11096. <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>
  11097. <li>Install sqlite (database driver), <code>apt-get update &amp;&amp; apt-get install -y sqlite3</code></li>
  11098. <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>
  11099. </ol>
  11100. <h1 id="9-submit-your-patch"><a class="header" href="#9-submit-your-patch">9. Submit your patch.</a></h1>
  11101. <p>Once you're happy with your patch, it's time to prepare a Pull Request.</p>
  11102. <p>To prepare a Pull Request, please:</p>
  11103. <ol>
  11104. <li>verify that <a href="development/contributing_guide.html#test-test-test">all the tests pass</a>, including the coding style;</li>
  11105. <li><a href="development/contributing_guide.html#sign-off">sign off</a> your contribution;</li>
  11106. <li><code>git push</code> your commit to your fork of Synapse;</li>
  11107. <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>
  11108. <li>add a <a href="development/contributing_guide.html#changelog">changelog entry</a> and push it to your Pull Request;</li>
  11109. <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>
  11110. <li>if you need to update your PR, please avoid rebasing and just add new commits to your branch.</li>
  11111. </ol>
  11112. <h2 id="changelog"><a class="header" href="#changelog">Changelog</a></h2>
  11113. <p>All changes, even minor ones, need a corresponding changelog / newsfragment
  11114. entry. These are managed by <a href="https://github.com/hawkowl/towncrier">Towncrier</a>.</p>
  11115. <p>To create a changelog entry, make a new file in the <code>changelog.d</code> directory named
  11116. in the format of <code>PRnumber.type</code>. The type can be one of the following:</p>
  11117. <ul>
  11118. <li><code>feature</code></li>
  11119. <li><code>bugfix</code></li>
  11120. <li><code>docker</code> (for updates to the Docker image)</li>
  11121. <li><code>doc</code> (for updates to the documentation)</li>
  11122. <li><code>removal</code> (also used for deprecations)</li>
  11123. <li><code>misc</code> (for internal-only changes)</li>
  11124. </ul>
  11125. <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
  11126. release, so the content of the file should be a short description of your
  11127. change in the same style as the rest of the changelog. The file can contain Markdown
  11128. formatting, and should end with a full stop (.) or an exclamation mark (!) for
  11129. consistency.</p>
  11130. <p>Adding credits to the changelog is encouraged, we value your
  11131. contributions and would like to have you shouted out in the release notes!</p>
  11132. <p>For example, a fix in PR #1234 would have its changelog entry in
  11133. <code>changelog.d/1234.bugfix</code>, and contain content like:</p>
  11134. <blockquote>
  11135. <p>The security levels of Florbs are now validated when received
  11136. via the <code>/federation/florb</code> endpoint. Contributed by Jane Matrix.</p>
  11137. </blockquote>
  11138. <p>If there are multiple pull requests involved in a single bugfix/feature/etc,
  11139. then the content for each <code>changelog.d</code> file should be the same. Towncrier will
  11140. merge the matching files together into a single changelog entry when we come to
  11141. release.</p>
  11142. <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>
  11143. <p>Obviously, you don't know if you should call your newsfile
  11144. <code>1234.bugfix</code> or <code>5678.bugfix</code> until you create the PR, which leads to a
  11145. chicken-and-egg problem.</p>
  11146. <p>There are two options for solving this:</p>
  11147. <ol>
  11148. <li>
  11149. <p>Open the PR without a changelog file, see what number you got, and <em>then</em>
  11150. add the changelog file to your branch (see <a href="development/contributing_guide.html#updating-your-pull-request">Updating your pull
  11151. request</a>), or:</p>
  11152. </li>
  11153. <li>
  11154. <p>Look at the <a href="https://github.com/matrix-org/synapse/issues?q=">list of all
  11155. issues/PRs</a>, add one to the
  11156. highest number you see, and quickly open the PR before somebody else claims
  11157. your number.</p>
  11158. <p><a href="https://github.com/richvdh/scripts/blob/master/next_github_number.sh">This
  11159. script</a>
  11160. might be helpful if you find yourself doing this a lot.</p>
  11161. </li>
  11162. </ol>
  11163. <p>Sorry, we know it's a bit fiddly, but it's <em>really</em> helpful for us when we come
  11164. to put together a release!</p>
  11165. <h3 id="debian-changelog"><a class="header" href="#debian-changelog">Debian changelog</a></h3>
  11166. <p>Changes which affect the debian packaging files (in <code>debian</code>) are an
  11167. exception to the rule that all changes require a <code>changelog.d</code> file.</p>
  11168. <p>In this case, you will need to add an entry to the debian changelog for the
  11169. next release. For this, run the following command:</p>
  11170. <pre><code>dch
  11171. </code></pre>
  11172. <p>This will make up a new version number (if there isn't already an unreleased
  11173. version in flight), and open an editor where you can add a new changelog entry.
  11174. (Our release process will ensure that the version number and maintainer name is
  11175. corrected for the release.)</p>
  11176. <p>If your change affects both the debian packaging <em>and</em> files outside the debian
  11177. directory, you will need both a regular newsfragment <em>and</em> an entry in the
  11178. debian changelog. (Though typically such changes should be submitted as two
  11179. separate pull requests.)</p>
  11180. <h2 id="sign-off"><a class="header" href="#sign-off">Sign off</a></h2>
  11181. <p>In order to have a concrete record that your contribution is intentional
  11182. and you agree to license it under the same terms as the project's license, we've adopted the
  11183. same lightweight approach that the Linux Kernel
  11184. <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>,
  11185. <a href="https://github.com/docker/docker/blob/master/CONTRIBUTING.md">Docker</a>, and many other
  11186. projects use: the DCO (Developer Certificate of Origin:
  11187. http://developercertificate.org/). This is a simple declaration that you wrote
  11188. the contribution or otherwise have the right to contribute it to Matrix:</p>
  11189. <pre><code>Developer Certificate of Origin
  11190. Version 1.1
  11191. Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
  11192. 660 York Street, Suite 102,
  11193. San Francisco, CA 94110 USA
  11194. Everyone is permitted to copy and distribute verbatim copies of this
  11195. license document, but changing it is not allowed.
  11196. Developer's Certificate of Origin 1.1
  11197. By making a contribution to this project, I certify that:
  11198. (a) The contribution was created in whole or in part by me and I
  11199. have the right to submit it under the open source license
  11200. indicated in the file; or
  11201. (b) The contribution is based upon previous work that, to the best
  11202. of my knowledge, is covered under an appropriate open source
  11203. license and I have the right under that license to submit that
  11204. work with modifications, whether created in whole or in part
  11205. by me, under the same open source license (unless I am
  11206. permitted to submit under a different license), as indicated
  11207. in the file; or
  11208. (c) The contribution was provided directly to me by some other
  11209. person who certified (a), (b) or (c) and I have not modified
  11210. it.
  11211. (d) I understand and agree that this project and the contribution
  11212. are public and that a record of the contribution (including all
  11213. personal information I submit with it, including my sign-off) is
  11214. maintained indefinitely and may be redistributed consistent with
  11215. this project or the open source license(s) involved.
  11216. </code></pre>
  11217. <p>If you agree to this for your contribution, then all that's needed is to
  11218. include the line in your commit or pull request comment:</p>
  11219. <pre><code>Signed-off-by: Your Name &lt;your@email.example.org&gt;
  11220. </code></pre>
  11221. <p>We accept contributions under a legally identifiable name, such as
  11222. your name on government documentation or common-law names (names
  11223. claimed by legitimate usage or repute). Unfortunately, we cannot
  11224. accept anonymous contributions at this time.</p>
  11225. <p>Git allows you to add this signoff automatically when using the <code>-s</code>
  11226. flag to <code>git commit</code>, which uses the name and email set in your
  11227. <code>user.name</code> and <code>user.email</code> git configs.</p>
  11228. <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>
  11229. <p>Once the Pull Request is opened, you will see a few things:</p>
  11230. <ol>
  11231. <li>our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;</li>
  11232. <li>one or more of the developers will take a look at your Pull Request and offer feedback.</li>
  11233. </ol>
  11234. <p>From this point, you should:</p>
  11235. <ol>
  11236. <li>Look at the results of the CI pipeline.
  11237. <ul>
  11238. <li>If there is any error, fix the error.</li>
  11239. </ul>
  11240. </li>
  11241. <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>
  11242. <li>Create a new commit with the changes.
  11243. <ul>
  11244. <li>Please do NOT overwrite the history. New commits make the reviewer's life easier.</li>
  11245. <li>Push this commits to your Pull Request.</li>
  11246. </ul>
  11247. </li>
  11248. <li>Back to 1.</li>
  11249. </ol>
  11250. <p>Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!</p>
  11251. <h1 id="11-find-a-new-issue"><a class="header" href="#11-find-a-new-issue">11. Find a new issue.</a></h1>
  11252. <p>By now, you know the drill!</p>
  11253. <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>
  11254. <p>There are some notes for those with commit access to the project on how we
  11255. manage git <a href="development/git.html">here</a>.</p>
  11256. <h1 id="conclusion"><a class="header" href="#conclusion">Conclusion</a></h1>
  11257. <p>That's it! Matrix is a very open and collaborative project as you might expect
  11258. given our obsession with open communication. If we're going to successfully
  11259. matrix together all the fragmented communication technologies out there we are
  11260. reliant on contributions and collaboration from the community to do so. So
  11261. please get involved - and we hope you have as much fun hacking on Matrix as we
  11262. do!</p>
  11263. <div style="break-before: page; page-break-before: always;"></div><h1 id="code-style"><a class="header" href="#code-style">Code Style</a></h1>
  11264. <h2 id="formatting-tools"><a class="header" href="#formatting-tools">Formatting tools</a></h2>
  11265. <p>The Synapse codebase uses a number of code formatting tools in order to
  11266. quickly and automatically check for formatting (and sometimes logical)
  11267. errors in code.</p>
  11268. <p>The necessary tools are detailed below.</p>
  11269. <p>First install them with:</p>
  11270. <pre><code>pip install -e &quot;.[lint,mypy]&quot;
  11271. </code></pre>
  11272. <ul>
  11273. <li>
  11274. <p><strong>black</strong></p>
  11275. <p>The Synapse codebase uses <a href="https://pypi.org/project/black/">black</a>
  11276. as an opinionated code formatter, ensuring all comitted code is
  11277. properly formatted.</p>
  11278. <p>Have <code>black</code> auto-format your code (it shouldn't change any
  11279. functionality) with:</p>
  11280. <pre><code>black . --exclude=&quot;\.tox|build|env&quot;
  11281. </code></pre>
  11282. </li>
  11283. <li>
  11284. <p><strong>flake8</strong></p>
  11285. <p><code>flake8</code> is a code checking tool. We require code to pass <code>flake8</code>
  11286. before being merged into the codebase.</p>
  11287. <p>Check all application and test code with:</p>
  11288. <pre><code>flake8 synapse tests
  11289. </code></pre>
  11290. </li>
  11291. <li>
  11292. <p><strong>isort</strong></p>
  11293. <p><code>isort</code> ensures imports are nicely formatted, and can suggest and
  11294. auto-fix issues such as double-importing.</p>
  11295. <p>Auto-fix imports with:</p>
  11296. <pre><code>isort -rc synapse tests
  11297. </code></pre>
  11298. <p><code>-rc</code> means to recursively search the given directories.</p>
  11299. </li>
  11300. </ul>
  11301. <p>It's worth noting that modern IDEs and text editors can run these tools
  11302. automatically on save. It may be worth looking into whether this
  11303. functionality is supported in your editor for a more convenient
  11304. development workflow. It is not, however, recommended to run <code>flake8</code> on
  11305. save as it takes a while and is very resource intensive.</p>
  11306. <h2 id="general-rules"><a class="header" href="#general-rules">General rules</a></h2>
  11307. <ul>
  11308. <li><strong>Naming</strong>:
  11309. <ul>
  11310. <li>Use camel case for class and type names</li>
  11311. <li>Use underscores for functions and variables.</li>
  11312. </ul>
  11313. </li>
  11314. <li><strong>Docstrings</strong>: should follow the <a href="https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings">google code
  11315. style</a>.
  11316. See the
  11317. <a href="http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html">examples</a>
  11318. in the sphinx documentation.</li>
  11319. <li><strong>Imports</strong>:
  11320. <ul>
  11321. <li>
  11322. <p>Imports should be sorted by <code>isort</code> as described above.</p>
  11323. </li>
  11324. <li>
  11325. <p>Prefer to import classes and functions rather than packages or
  11326. modules.</p>
  11327. <p>Example:</p>
  11328. <pre><code>from synapse.types import UserID
  11329. ...
  11330. user_id = UserID(local, server)
  11331. </code></pre>
  11332. <p>is preferred over:</p>
  11333. <pre><code>from synapse import types
  11334. ...
  11335. user_id = types.UserID(local, server)
  11336. </code></pre>
  11337. <p>(or any other variant).</p>
  11338. <p>This goes against the advice in the Google style guide, but it
  11339. means that errors in the name are caught early (at import time).</p>
  11340. </li>
  11341. <li>
  11342. <p>Avoid wildcard imports (<code>from synapse.types import *</code>) and
  11343. relative imports (<code>from .types import UserID</code>).</p>
  11344. </li>
  11345. </ul>
  11346. </li>
  11347. </ul>
  11348. <h2 id="configuration-file-format"><a class="header" href="#configuration-file-format">Configuration file format</a></h2>
  11349. <p>The <a href="./sample_config.yaml">sample configuration file</a> acts as a
  11350. reference to Synapse's configuration options for server administrators.
  11351. Remember that many readers will be unfamiliar with YAML and server
  11352. administration in general, so that it is important that the file be as
  11353. easy to understand as possible, which includes following a consistent
  11354. format.</p>
  11355. <p>Some guidelines follow:</p>
  11356. <ul>
  11357. <li>
  11358. <p>Sections should be separated with a heading consisting of a single
  11359. line prefixed and suffixed with <code>##</code>. There should be <strong>two</strong> blank
  11360. lines before the section header, and <strong>one</strong> after.</p>
  11361. </li>
  11362. <li>
  11363. <p>Each option should be listed in the file with the following format:</p>
  11364. <ul>
  11365. <li>
  11366. <p>A comment describing the setting. Each line of this comment
  11367. should be prefixed with a hash (<code>#</code>) and a space.</p>
  11368. <p>The comment should describe the default behaviour (ie, what
  11369. happens if the setting is omitted), as well as what the effect
  11370. will be if the setting is changed.</p>
  11371. <p>Often, the comment end with something like &quot;uncomment the
  11372. following to <do action>&quot;.</p>
  11373. </li>
  11374. <li>
  11375. <p>A line consisting of only <code>#</code>.</p>
  11376. </li>
  11377. <li>
  11378. <p>A commented-out example setting, prefixed with only <code>#</code>.</p>
  11379. <p>For boolean (on/off) options, convention is that this example
  11380. should be the <em>opposite</em> to the default (so the comment will end
  11381. with &quot;Uncomment the following to enable [or disable]
  11382. <feature>.&quot; For other options, the example should give some
  11383. non-default value which is likely to be useful to the reader.</p>
  11384. </li>
  11385. </ul>
  11386. </li>
  11387. <li>
  11388. <p>There should be a blank line between each option.</p>
  11389. </li>
  11390. <li>
  11391. <p>Where several settings are grouped into a single dict, <em>avoid</em> the
  11392. convention where the whole block is commented out, resulting in
  11393. comment lines starting <code># #</code>, as this is hard to read and confusing
  11394. to edit. Instead, leave the top-level config option uncommented, and
  11395. follow the conventions above for sub-options. Ensure that your code
  11396. correctly handles the top-level option being set to <code>None</code> (as it
  11397. will be if no sub-options are enabled).</p>
  11398. </li>
  11399. <li>
  11400. <p>Lines should be wrapped at 80 characters.</p>
  11401. </li>
  11402. <li>
  11403. <p>Use two-space indents.</p>
  11404. </li>
  11405. <li>
  11406. <p><code>true</code> and <code>false</code> are spelt thus (as opposed to <code>True</code>, etc.)</p>
  11407. </li>
  11408. <li>
  11409. <p>Use single quotes (<code>'</code>) rather than double-quotes (<code>&quot;</code>) or backticks
  11410. (<code>`</code>) to refer to configuration options.</p>
  11411. </li>
  11412. </ul>
  11413. <p>Example:</p>
  11414. <pre><code>## Frobnication ##
  11415. # The frobnicator will ensure that all requests are fully frobnicated.
  11416. # To enable it, uncomment the following.
  11417. #
  11418. #frobnicator_enabled: true
  11419. # By default, the frobnicator will frobnicate with the default frobber.
  11420. # The following will make it use an alternative frobber.
  11421. #
  11422. #frobincator_frobber: special_frobber
  11423. # Settings for the frobber
  11424. #
  11425. frobber:
  11426. # frobbing speed. Defaults to 1.
  11427. #
  11428. #speed: 10
  11429. # frobbing distance. Defaults to 1000.
  11430. #
  11431. #distance: 100
  11432. </code></pre>
  11433. <p>Note that the sample configuration is generated from the synapse code
  11434. and is maintained by a script, <code>scripts-dev/generate_sample_config</code>.
  11435. Making sure that the output from this script matches the desired format
  11436. is left as an exercise for the reader!</p>
  11437. <div 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>
  11438. <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>
  11439. <p>In an ideal world, our git commit history would be a linear progression of
  11440. commits each of which contains a single change building on what came
  11441. before. Here, by way of an arbitrary example, is the top of <code>git log --graph b2dba0607</code>:</p>
  11442. <img src="development/img/git/clean.png" alt="clean git graph" width="500px">
  11443. <p>Note how the commit comment explains clearly what is changing and why. Also
  11444. note the <em>absence</em> of merge commits, as well as the absence of commits called
  11445. things like (to pick a few culprits):
  11446. <a href="https://github.com/matrix-org/synapse/commit/84691da6c">“pep8”</a>, <a href="https://github.com/matrix-org/synapse/commit/474810d9d">“fix broken
  11447. test”</a>,
  11448. <a href="https://github.com/matrix-org/synapse/commit/c9d72e457">“oops”</a>,
  11449. <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
  11450. the president?”</a>.</p>
  11451. <p>There are a number of reasons why keeping a clean commit history is a good
  11452. thing:</p>
  11453. <ul>
  11454. <li>
  11455. <p>From time to time, after a change lands, it turns out to be necessary to
  11456. revert it, or to backport it to a release branch. Those operations are
  11457. <em>much</em> easier when the change is contained in a single commit.</p>
  11458. </li>
  11459. <li>
  11460. <p>Similarly, it's much easier to answer questions like “is the fix for
  11461. <code>/publicRooms</code> on the release branch?” if that change consists of a single
  11462. commit.</p>
  11463. </li>
  11464. <li>
  11465. <p>Likewise: “what has changed on this branch in the last week?” is much
  11466. clearer without merges and “pep8” commits everywhere.</p>
  11467. </li>
  11468. <li>
  11469. <p>Sometimes we need to figure out where a bug got introduced, or some
  11470. behaviour changed. One way of doing that is with <code>git bisect</code>: pick an
  11471. arbitrary commit between the known good point and the known bad point, and
  11472. see how the code behaves. However, that strategy fails if the commit you
  11473. chose is the middle of someone's epic branch in which they broke the world
  11474. before putting it back together again.</p>
  11475. </li>
  11476. </ul>
  11477. <p>One counterargument is that it is sometimes useful to see how a PR evolved as
  11478. it went through review cycles. This is true, but that information is always
  11479. 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
  11480. namespace</a>).</p>
  11481. <p>Of course, in reality, things are more complicated than that. We have release
  11482. branches as well as <code>develop</code> and <code>master</code>, and we deliberately merge changes
  11483. between them. Bugs often slip through and have to be fixed later. That's all
  11484. fine: this not a cast-iron rule which must be obeyed, but an ideal to aim
  11485. towards.</p>
  11486. <h2 id="merges-squashes-rebases-wtf"><a class="header" href="#merges-squashes-rebases-wtf">Merges, squashes, rebases: wtf?</a></h2>
  11487. <p>Ok, so that's what we'd like to achieve. How do we achieve it?</p>
  11488. <p>The TL;DR is: when you come to merge a pull request, you <em>probably</em> want to
  11489. “squash and merge”:</p>
  11490. <p><img src="development/img/git/squash.png" alt="squash and merge" />.</p>
  11491. <p>(This applies whether you are merging your own PR, or that of another
  11492. contributor.)</p>
  11493. <p>“Squash and merge”<sup id="a1"><a href="development/git.html#f1">1</a></sup> takes all of the changes in the
  11494. PR, and bundles them into a single commit. GitHub gives you the opportunity to
  11495. edit the commit message before you confirm, and normally you should do so,
  11496. because the default will be useless (again: <code>* woops typo</code> is not a useful
  11497. thing to keep in the historical record).</p>
  11498. <p>The main problem with this approach comes when you have a series of pull
  11499. requests which build on top of one another: as soon as you squash-merge the
  11500. first PR, you'll end up with a stack of conflicts to resolve in all of the
  11501. others. In general, it's best to avoid this situation in the first place by
  11502. trying not to have multiple related PRs in flight at the same time. Still,
  11503. sometimes that's not possible and doing a regular merge is the lesser evil.</p>
  11504. <p>Another occasion in which a regular merge makes more sense is a PR where you've
  11505. deliberately created a series of commits each of which makes sense in its own
  11506. right. For example: <a href="https://github.com/matrix-org/synapse/pull/6837">a PR which gradually propagates a refactoring operation
  11507. through the codebase</a>, or <a href="https://github.com/matrix-org/synapse/pull/5987">a
  11508. PR which is the culmination of several other
  11509. PRs</a>. In this case the ability
  11510. to figure out when a particular change/bug was introduced could be very useful.</p>
  11511. <p>Ultimately: <strong>this is not a hard-and-fast-rule</strong>. If in doubt, ask yourself “do
  11512. each of the commits I am about to merge make sense in their own right”, but
  11513. remember that we're just doing our best to balance “keeping the commit history
  11514. clean” with other factors.</p>
  11515. <h2 id="git-branching-model"><a class="header" href="#git-branching-model">Git branching model</a></h2>
  11516. <p>A <a href="https://nvie.com/posts/a-successful-git-branching-model/">lot</a>
  11517. <a href="http://scottchacon.com/2011/08/31/github-flow.html">of</a>
  11518. <a href="https://www.endoflineblog.com/gitflow-considered-harmful">words</a> have been
  11519. written in the past about git branching models (no really, <a href="https://martinfowler.com/articles/branching-patterns.html">a
  11520. lot</a>). I tend to
  11521. think the whole thing is overblown. Fundamentally, it's not that
  11522. complicated. Here's how we do it.</p>
  11523. <p>Let's start with a picture:</p>
  11524. <p><img src="development/img/git/branches.jpg" alt="branching model" /></p>
  11525. <p>It looks complicated, but it's really not. There's one basic rule: <em>anyone</em> is
  11526. free to merge from <em>any</em> more-stable branch to <em>any</em> less-stable branch at
  11527. <em>any</em> time<sup id="a2"><a href="development/git.html#f2">2</a></sup>. (The principle behind this is that if a
  11528. change is good enough for the more-stable branch, then it's also good enough go
  11529. put in a less-stable branch.)</p>
  11530. <p>Meanwhile, merging (or squashing, as per the above) from a less-stable to a
  11531. more-stable branch is a deliberate action in which you want to publish a change
  11532. or a set of changes to (some subset of) the world: for example, this happens
  11533. when a PR is landed, or as part of our release process.</p>
  11534. <p>So, what counts as a more- or less-stable branch? A little reflection will show
  11535. that our active branches are ordered thus, from more-stable to less-stable:</p>
  11536. <ul>
  11537. <li><code>master</code> (tracks our last release).</li>
  11538. <li><code>release-vX.Y</code> (the branch where we prepare the next release)<sup
  11539. id="a3"><a href="development/git.html#f3">3</a></sup>.</li>
  11540. <li>PR branches which are targeting the release.</li>
  11541. <li><code>develop</code> (our &quot;mainline&quot; branch containing our bleeding-edge).</li>
  11542. <li>regular PR branches.</li>
  11543. </ul>
  11544. <p>The corollary is: if you have a bugfix that needs to land in both
  11545. <code>release-vX.Y</code> <em>and</em> <code>develop</code>, then you should base your PR on
  11546. <code>release-vX.Y</code>, get it merged there, and then merge from <code>release-vX.Y</code> to
  11547. <code>develop</code>. (If a fix lands in <code>develop</code> and we later need it in a
  11548. release-branch, we can of course cherry-pick it, but landing it in the release
  11549. branch first helps reduce the chance of annoying conflicts.)</p>
  11550. <hr />
  11551. <p><b id="f1">[1]</b>: “Squash and merge” is GitHub's term for this
  11552. operation. Given that there is no merge involved, I'm not convinced it's the
  11553. most intuitive name. <a href="development/git.html#a1">^</a></p>
  11554. <p><b id="f2">[2]</b>: Well, anyone with commit access.<a href="development/git.html#a2">^</a></p>
  11555. <p><b id="f3">[3]</b>: Very, very occasionally (I think this has happened once in
  11556. the history of Synapse), we've had two releases in flight at once. Obviously,
  11557. <code>release-v1.2</code> is more-stable than <code>release-v1.3</code>. <a href="development/git.html#a3">^</a></p>
  11558. <div style="break-before: page; page-break-before: always;"></div><h1 id="opentracing"><a class="header" href="#opentracing">OpenTracing</a></h1>
  11559. <h2 id="background"><a class="header" href="#background">Background</a></h2>
  11560. <p>OpenTracing is a semi-standard being adopted by a number of distributed
  11561. tracing platforms. It is a common api for facilitating vendor-agnostic
  11562. tracing instrumentation. That is, we can use the OpenTracing api and
  11563. select one of a number of tracer implementations to do the heavy lifting
  11564. in the background. Our current selected implementation is Jaeger.</p>
  11565. <p>OpenTracing is a tool which gives an insight into the causal
  11566. relationship of work done in and between servers. The servers each track
  11567. events and report them to a centralised server - in Synapse's case:
  11568. Jaeger. The basic unit used to represent events is the span. The span
  11569. roughly represents a single piece of work that was done and the time at
  11570. which it occurred. A span can have child spans, meaning that the work of
  11571. the child had to be completed for the parent span to complete, or it can
  11572. have follow-on spans which represent work that is undertaken as a result
  11573. of the parent but is not depended on by the parent to in order to
  11574. finish.</p>
  11575. <p>Since this is undertaken in a distributed environment a request to
  11576. another server, such as an RPC or a simple GET, can be considered a span
  11577. (a unit or work) for the local server. This causal link is what
  11578. OpenTracing aims to capture and visualise. In order to do this metadata
  11579. about the local server's span, i.e the 'span context', needs to be
  11580. included with the request to the remote.</p>
  11581. <p>It is up to the remote server to decide what it does with the spans it
  11582. creates. This is called the sampling policy and it can be configured
  11583. through Jaeger's settings.</p>
  11584. <p>For OpenTracing concepts see
  11585. <a href="https://opentracing.io/docs/overview/what-is-tracing/">https://opentracing.io/docs/overview/what-is-tracing/</a>.</p>
  11586. <p>For more information about Jaeger's implementation see
  11587. <a href="https://www.jaegertracing.io/docs/">https://www.jaegertracing.io/docs/</a></p>
  11588. <h2 id="setting-up-opentracing"><a class="header" href="#setting-up-opentracing">Setting up OpenTracing</a></h2>
  11589. <p>To receive OpenTracing spans, start up a Jaeger server. This can be done
  11590. using docker like so:</p>
  11591. <pre><code class="language-sh">docker run -d --name jaeger \
  11592. -p 6831:6831/udp \
  11593. -p 6832:6832/udp \
  11594. -p 5778:5778 \
  11595. -p 16686:16686 \
  11596. -p 14268:14268 \
  11597. jaegertracing/all-in-one:1
  11598. </code></pre>
  11599. <p>Latest documentation is probably at
  11600. https://www.jaegertracing.io/docs/latest/getting-started.</p>
  11601. <h2 id="enable-opentracing-in-synapse"><a class="header" href="#enable-opentracing-in-synapse">Enable OpenTracing in Synapse</a></h2>
  11602. <p>OpenTracing is not enabled by default. It must be enabled in the
  11603. homeserver config by uncommenting the config options under <code>opentracing</code>
  11604. as shown in the <a href="./sample_config.yaml">sample config</a>. For example:</p>
  11605. <pre><code class="language-yaml">opentracing:
  11606. enabled: true
  11607. homeserver_whitelist:
  11608. - &quot;mytrustedhomeserver.org&quot;
  11609. - &quot;*.myotherhomeservers.com&quot;
  11610. </code></pre>
  11611. <h2 id="homeserver-whitelisting"><a class="header" href="#homeserver-whitelisting">Homeserver whitelisting</a></h2>
  11612. <p>The homeserver whitelist is configured using regular expressions. A list
  11613. of regular expressions can be given and their union will be compared
  11614. when propagating any spans contexts to another homeserver.</p>
  11615. <p>Though it's mostly safe to send and receive span contexts to and from
  11616. untrusted users since span contexts are usually opaque ids it can lead
  11617. to two problems, namely:</p>
  11618. <ul>
  11619. <li>If the span context is marked as sampled by the sending homeserver
  11620. the receiver will sample it. Therefore two homeservers with wildly
  11621. different sampling policies could incur higher sampling counts than
  11622. intended.</li>
  11623. <li>Sending servers can attach arbitrary data to spans, known as
  11624. 'baggage'. For safety this has been disabled in Synapse but that
  11625. doesn't prevent another server sending you baggage which will be
  11626. logged to OpenTracing's logs.</li>
  11627. </ul>
  11628. <h2 id="configuring-jaeger"><a class="header" href="#configuring-jaeger">Configuring Jaeger</a></h2>
  11629. <p>Sampling strategies can be set as in this document:
  11630. <a href="https://www.jaegertracing.io/docs/latest/sampling/">https://www.jaegertracing.io/docs/latest/sampling/</a>.</p>
  11631. <div 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>
  11632. <p>Synapse's database schema is stored in the <code>synapse.storage.schema</code> module.</p>
  11633. <h2 id="logical-databases"><a class="header" href="#logical-databases">Logical databases</a></h2>
  11634. <p>Synapse supports splitting its datastore across multiple physical databases (which can
  11635. be useful for large installations), and the schema files are therefore split according
  11636. to the logical database they apply to.</p>
  11637. <p>At the time of writing, the following &quot;logical&quot; databases are supported:</p>
  11638. <ul>
  11639. <li><code>state</code> - used to store Matrix room state (more specifically, <code>state_groups</code>,
  11640. their relationships and contents).</li>
  11641. <li><code>main</code> - stores everything else.</li>
  11642. </ul>
  11643. <p>Additionally, the <code>common</code> directory contains schema files for tables which must be
  11644. present on <em>all</em> physical databases.</p>
  11645. <h2 id="synapse-schema-versions"><a class="header" href="#synapse-schema-versions">Synapse schema versions</a></h2>
  11646. <p>Synapse manages its database schema via &quot;schema versions&quot;. These are mainly used to
  11647. help avoid confusion if the Synapse codebase is rolled back after the database is
  11648. updated. They work as follows:</p>
  11649. <ul>
  11650. <li>
  11651. <p>The Synapse codebase defines a constant <code>synapse.storage.schema.SCHEMA_VERSION</code>
  11652. which represents the expectations made about the database by that version. For
  11653. example, as of Synapse v1.36, this is <code>59</code>.</p>
  11654. </li>
  11655. <li>
  11656. <p>The database stores a &quot;compatibility version&quot; in
  11657. <code>schema_compat_version.compat_version</code> which defines the <code>SCHEMA_VERSION</code> of the
  11658. oldest version of Synapse which will work with the database. On startup, if
  11659. <code>compat_version</code> is found to be newer than <code>SCHEMA_VERSION</code>, Synapse will refuse to
  11660. start.</p>
  11661. <p>Synapse automatically updates this field from
  11662. <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code>.</p>
  11663. </li>
  11664. <li>
  11665. <p>Whenever a backwards-incompatible change is made to the database format (normally
  11666. via a <code>delta</code> file), <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code> is also updated
  11667. so that administrators can not accidentally roll back to a too-old version of Synapse.</p>
  11668. </li>
  11669. </ul>
  11670. <p>Generally, the goal is to maintain compatibility with at least one or two previous
  11671. releases of Synapse, so any substantial change tends to require multiple releases and a
  11672. bit of forward-planning to get right.</p>
  11673. <p>As a worked example: we want to remove the <code>room_stats_historical</code> table. Here is how it
  11674. might pan out.</p>
  11675. <ol>
  11676. <li>
  11677. <p>Replace any code that <em>reads</em> from <code>room_stats_historical</code> with alternative
  11678. implementations, but keep writing to it in case of rollback to an earlier version.
  11679. Also, increase <code>synapse.storage.schema.SCHEMA_VERSION</code>. In this
  11680. instance, there is no existing code which reads from <code>room_stats_historical</code>, so
  11681. our starting point is:</p>
  11682. <p>v1.36.0: <code>SCHEMA_VERSION=59</code>, <code>SCHEMA_COMPAT_VERSION=59</code></p>
  11683. </li>
  11684. <li>
  11685. <p>Next (say in Synapse v1.37.0): remove the code that <em>writes</em> to
  11686. <code>room_stats_historical</code>, but don’t yet remove the table in case of rollback to
  11687. v1.36.0. Again, we increase <code>synapse.storage.schema.SCHEMA_VERSION</code>, but
  11688. because we have not broken compatibility with v1.36, we do not yet update
  11689. <code>SCHEMA_COMPAT_VERSION</code>. We now have:</p>
  11690. <p>v1.37.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=59</code>.</p>
  11691. </li>
  11692. <li>
  11693. <p>Later (say in Synapse v1.38.0): we can remove the table altogether. This will
  11694. break compatibility with v1.36.0, so we must update <code>SCHEMA_COMPAT_VERSION</code> accordingly.
  11695. There is no need to update <code>synapse.storage.schema.SCHEMA_VERSION</code>, since there is no
  11696. change to the Synapse codebase here. So we end up with:</p>
  11697. <p>v1.38.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=60</code>.</p>
  11698. </li>
  11699. </ol>
  11700. <p>If in doubt about whether to update <code>SCHEMA_VERSION</code> or not, it is generally best to
  11701. lean towards doing so.</p>
  11702. <h2 id="full-schema-dumps"><a class="header" href="#full-schema-dumps">Full schema dumps</a></h2>
  11703. <p>In the <code>full_schemas</code> directories, only the most recently-numbered snapshot is used
  11704. (<code>54</code> at the time of writing). Older snapshots (eg, <code>16</code>) are present for historical
  11705. reference only.</p>
  11706. <h3 id="building-full-schema-dumps"><a class="header" href="#building-full-schema-dumps">Building full schema dumps</a></h3>
  11707. <p>If you want to recreate these schemas, they need to be made from a database that
  11708. has had all background updates run.</p>
  11709. <p>To do so, use <code>scripts-dev/make_full_schema.sh</code>. This will produce new
  11710. <code>full.sql.postgres</code> and <code>full.sql.sqlite</code> files.</p>
  11711. <p>Ensure postgres is installed, then run:</p>
  11712. <pre><code>./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
  11713. </code></pre>
  11714. <p>NB at the time of writing, this script predates the split into separate <code>state</code>/<code>main</code>
  11715. databases so will require updates to handle that correctly.</p>
  11716. <h2 id="boolean-columns"><a class="header" href="#boolean-columns">Boolean columns</a></h2>
  11717. <p>Boolean columns require special treatment, since SQLite treats booleans the
  11718. same as integers.</p>
  11719. <p>There are three separate aspects to this:</p>
  11720. <ul>
  11721. <li>
  11722. <p>Any new boolean column must be added to the <code>BOOLEAN_COLUMNS</code> list in
  11723. <code>scripts/synapse_port_db</code>. This tells the port script to cast the integer
  11724. value from SQLite to a boolean before writing the value to the postgres
  11725. database.</p>
  11726. </li>
  11727. <li>
  11728. <p>Before SQLite 3.23, <code>TRUE</code> and <code>FALSE</code> were not recognised as constants by
  11729. SQLite, and the <code>IS [NOT] TRUE</code>/<code>IS [NOT] FALSE</code> operators were not
  11730. supported. This makes it necessary to avoid using <code>TRUE</code> and <code>FALSE</code>
  11731. constants in SQL commands.</p>
  11732. <p>For example, to insert a <code>TRUE</code> value into the database, write:</p>
  11733. <pre><code class="language-python">txn.execute(&quot;INSERT INTO tbl(col) VALUES (?)&quot;, (True, ))
  11734. </code></pre>
  11735. </li>
  11736. <li>
  11737. <p>Default values for new boolean columns present a particular
  11738. difficulty. Generally it is best to create separate schema files for
  11739. Postgres and SQLite. For example:</p>
  11740. <pre><code class="language-sql"># in 00delta.sql.postgres:
  11741. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT FALSE;
  11742. </code></pre>
  11743. <pre><code class="language-sql"># in 00delta.sql.sqlite:
  11744. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT 0;
  11745. </code></pre>
  11746. <p>Note that there is a particularly insidious failure mode here: the Postgres
  11747. flavour will be accepted by SQLite 3.22, but will give a column whose
  11748. default value is the <strong>string</strong> <code>&quot;FALSE&quot;</code> - which, when cast back to a boolean
  11749. in Python, evaluates to <code>True</code>.</p>
  11750. </li>
  11751. </ul>
  11752. <div style="break-before: page; page-break-before: always;"></div><h1 id="implementing-experimental-features-in-synapse"><a class="header" href="#implementing-experimental-features-in-synapse">Implementing experimental features in Synapse</a></h1>
  11753. <p>It can be desirable to implement &quot;experimental&quot; features which are disabled by
  11754. default and must be explicitly enabled via the Synapse configuration. This is
  11755. applicable for features which:</p>
  11756. <ul>
  11757. <li>Are unstable in the Matrix spec (e.g. those defined by an MSC that has not yet been merged).</li>
  11758. <li>Developers are not confident in their use by general Synapse administrators/users
  11759. (e.g. a feature is incomplete, buggy, performs poorly, or needs further testing).</li>
  11760. </ul>
  11761. <p>Note that this only really applies to features which are expected to be desirable
  11762. to a broad audience. The <a href="development/../modules/index.html">module infrastructure</a> should
  11763. instead be investigated for non-standard features.</p>
  11764. <p>Guarding experimental features behind configuration flags should help with some
  11765. of the following scenarios:</p>
  11766. <ul>
  11767. <li>Ensure that clients do not assume that unstable features exist (failing
  11768. gracefully if they do not).</li>
  11769. <li>Unstable features do not become de-facto standards and can be removed
  11770. aggressively (since only those who have opted-in will be affected).</li>
  11771. <li>Ease finding the implementation of unstable features in Synapse (for future
  11772. removal or stabilization).</li>
  11773. <li>Ease testing a feature (or removal of feature) due to enabling/disabling without
  11774. code changes. It also becomes possible to ask for wider testing, if desired.</li>
  11775. </ul>
  11776. <p>Experimental configuration flags should be disabled by default (requiring Synapse
  11777. administrators to explicitly opt-in), although there are situations where it makes
  11778. sense (from a product point-of-view) to enable features by default. This is
  11779. expected and not an issue.</p>
  11780. <p>It is not a requirement for experimental features to be behind a configuration flag,
  11781. but one should be used if unsure.</p>
  11782. <p>New experimental configuration flags should be added under the <code>experimental</code>
  11783. configuration key (see the <code>synapse.config.experimental</code> file) and either explain
  11784. (briefly) what is being enabled, or include the MSC number.</p>
  11785. <div style="break-before: page; page-break-before: always;"></div><h1 id="log-contexts"><a class="header" href="#log-contexts">Log Contexts</a></h1>
  11786. <p>To help track the processing of individual requests, synapse uses a
  11787. '<code>log context</code>' to track which request it is handling at any given
  11788. moment. This is done via a thread-local variable; a <code>logging.Filter</code> is
  11789. then used to fish the information back out of the thread-local variable
  11790. and add it to each log record.</p>
  11791. <p>Logcontexts are also used for CPU and database accounting, so that we
  11792. can track which requests were responsible for high CPU use or database
  11793. activity.</p>
  11794. <p>The <code>synapse.logging.context</code> module provides facilities for managing
  11795. the current log context (as well as providing the <code>LoggingContextFilter</code>
  11796. class).</p>
  11797. <p>Asynchronous functions make the whole thing complicated, so this document describes
  11798. how it all works, and how to write code which follows the rules.</p>
  11799. <p>In this document, &quot;awaitable&quot; refers to any object which can be <code>await</code>ed. In the context of
  11800. Synapse, that normally means either a coroutine or a Twisted
  11801. <a href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html"><code>Deferred</code></a>.</p>
  11802. <h2 id="logcontexts-without-asynchronous-code"><a class="header" href="#logcontexts-without-asynchronous-code">Logcontexts without asynchronous code</a></h2>
  11803. <p>In the absence of any asynchronous voodoo, things are simple enough. As with
  11804. any code of this nature, the rule is that our function should leave
  11805. things as it found them:</p>
  11806. <pre><code class="language-python">from synapse.logging import context # omitted from future snippets
  11807. def handle_request(request_id):
  11808. request_context = context.LoggingContext()
  11809. calling_context = context.set_current_context(request_context)
  11810. try:
  11811. request_context.request = request_id
  11812. do_request_handling()
  11813. logger.debug(&quot;finished&quot;)
  11814. finally:
  11815. context.set_current_context(calling_context)
  11816. def do_request_handling():
  11817. logger.debug(&quot;phew&quot;) # this will be logged against request_id
  11818. </code></pre>
  11819. <p>LoggingContext implements the context management methods, so the above
  11820. can be written much more succinctly as:</p>
  11821. <pre><code class="language-python">def handle_request(request_id):
  11822. with context.LoggingContext() as request_context:
  11823. request_context.request = request_id
  11824. do_request_handling()
  11825. logger.debug(&quot;finished&quot;)
  11826. def do_request_handling():
  11827. logger.debug(&quot;phew&quot;)
  11828. </code></pre>
  11829. <h2 id="using-logcontexts-with-awaitables"><a class="header" href="#using-logcontexts-with-awaitables">Using logcontexts with awaitables</a></h2>
  11830. <p>Awaitables break the linear flow of code so that there is no longer a single entry point
  11831. where we should set the logcontext and a single exit point where we should remove it.</p>
  11832. <p>Consider the example above, where <code>do_request_handling</code> needs to do some
  11833. blocking operation, and returns an awaitable:</p>
  11834. <pre><code class="language-python">async def handle_request(request_id):
  11835. with context.LoggingContext() as request_context:
  11836. request_context.request = request_id
  11837. await do_request_handling()
  11838. logger.debug(&quot;finished&quot;)
  11839. </code></pre>
  11840. <p>In the above flow:</p>
  11841. <ul>
  11842. <li>The logcontext is set</li>
  11843. <li><code>do_request_handling</code> is called, and returns an awaitable</li>
  11844. <li><code>handle_request</code> awaits the awaitable</li>
  11845. <li>Execution of <code>handle_request</code> is suspended</li>
  11846. </ul>
  11847. <p>So we have stopped processing the request (and will probably go on to
  11848. start processing the next), without clearing the logcontext.</p>
  11849. <p>To circumvent this problem, synapse code assumes that, wherever you have
  11850. an awaitable, you will want to <code>await</code> it. To that end, whereever
  11851. functions return awaitables, we adopt the following conventions:</p>
  11852. <p><strong>Rules for functions returning awaitables:</strong></p>
  11853. <blockquote>
  11854. <ul>
  11855. <li>If the awaitable is already complete, the function returns with the
  11856. same logcontext it started with.</li>
  11857. <li>If the awaitable is incomplete, the function clears the logcontext
  11858. before returning; when the awaitable completes, it restores the
  11859. logcontext before running any callbacks.</li>
  11860. </ul>
  11861. </blockquote>
  11862. <p>That sounds complicated, but actually it means a lot of code (including
  11863. the example above) &quot;just works&quot;. There are two cases:</p>
  11864. <ul>
  11865. <li>
  11866. <p>If <code>do_request_handling</code> returns a completed awaitable, then the
  11867. logcontext will still be in place. In this case, execution will
  11868. continue immediately after the <code>await</code>; the &quot;finished&quot; line will
  11869. be logged against the right context, and the <code>with</code> block restores
  11870. the original context before we return to the caller.</p>
  11871. </li>
  11872. <li>
  11873. <p>If the returned awaitable is incomplete, <code>do_request_handling</code> clears
  11874. the logcontext before returning. The logcontext is therefore clear
  11875. when <code>handle_request</code> <code>await</code>s the awaitable.</p>
  11876. <p>Once <code>do_request_handling</code>'s awaitable completes, it will reinstate
  11877. the logcontext, before running the second half of <code>handle_request</code>,
  11878. so again the &quot;finished&quot; line will be logged against the right context,
  11879. and the <code>with</code> block restores the original context.</p>
  11880. </li>
  11881. </ul>
  11882. <p>As an aside, it's worth noting that <code>handle_request</code> follows our rules</p>
  11883. <ul>
  11884. <li>though that only matters if the caller has its own logcontext which it
  11885. cares about.</li>
  11886. </ul>
  11887. <p>The following sections describe pitfalls and helpful patterns when
  11888. implementing these rules.</p>
  11889. <h2 id="always-await-your-awaitables"><a class="header" href="#always-await-your-awaitables">Always await your awaitables</a></h2>
  11890. <p>Whenever you get an awaitable back from a function, you should <code>await</code> on
  11891. it as soon as possible. Do not pass go; do not do any logging; do not
  11892. call any other functions.</p>
  11893. <pre><code class="language-python">async def fun():
  11894. logger.debug(&quot;starting&quot;)
  11895. await do_some_stuff() # just like this
  11896. coro = more_stuff()
  11897. result = await coro # also fine, of course
  11898. return result
  11899. </code></pre>
  11900. <p>Provided this pattern is followed all the way back up to the callchain
  11901. to where the logcontext was set, this will make things work out ok:
  11902. provided <code>do_some_stuff</code> and <code>more_stuff</code> follow the rules above, then
  11903. so will <code>fun</code>.</p>
  11904. <p>It's all too easy to forget to <code>await</code>: for instance if we forgot that
  11905. <code>do_some_stuff</code> returned an awaitable, we might plough on regardless. This
  11906. leads to a mess; it will probably work itself out eventually, but not
  11907. before a load of stuff has been logged against the wrong context.
  11908. (Normally, other things will break, more obviously, if you forget to
  11909. <code>await</code>, so this tends not to be a major problem in practice.)</p>
  11910. <p>Of course sometimes you need to do something a bit fancier with your
  11911. awaitable - not all code follows the linear A-then-B-then-C pattern.
  11912. Notes on implementing more complex patterns are in later sections.</p>
  11913. <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>
  11914. <p>Most of the time, an awaitable comes from another synapse function.
  11915. Sometimes, though, we need to make up a new awaitable, or we get an awaitable
  11916. back from external code. We need to make it follow our rules.</p>
  11917. <p>The easy way to do it is by using <code>context.make_deferred_yieldable</code>. Suppose we want to implement
  11918. <code>sleep</code>, which returns a deferred which will run its callbacks after a
  11919. given number of seconds. That might look like:</p>
  11920. <pre><code class="language-python"># not a logcontext-rules-compliant function
  11921. def get_sleep_deferred(seconds):
  11922. d = defer.Deferred()
  11923. reactor.callLater(seconds, d.callback, None)
  11924. return d
  11925. </code></pre>
  11926. <p>That doesn't follow the rules, but we can fix it by calling it through
  11927. <code>context.make_deferred_yieldable</code>:</p>
  11928. <pre><code class="language-python">async def sleep(seconds):
  11929. return await context.make_deferred_yieldable(get_sleep_deferred(seconds))
  11930. </code></pre>
  11931. <h2 id="fire-and-forget"><a class="header" href="#fire-and-forget">Fire-and-forget</a></h2>
  11932. <p>Sometimes you want to fire off a chain of execution, but not wait for
  11933. its result. That might look a bit like this:</p>
  11934. <pre><code class="language-python">async def do_request_handling():
  11935. await foreground_operation()
  11936. # *don't* do this
  11937. background_operation()
  11938. logger.debug(&quot;Request handling complete&quot;)
  11939. async def background_operation():
  11940. await first_background_step()
  11941. logger.debug(&quot;Completed first step&quot;)
  11942. await second_background_step()
  11943. logger.debug(&quot;Completed second step&quot;)
  11944. </code></pre>
  11945. <p>The above code does a couple of steps in the background after
  11946. <code>do_request_handling</code> has finished. The log lines are still logged
  11947. against the <code>request_context</code> logcontext, which may or may not be
  11948. desirable. There are two big problems with the above, however. The first
  11949. problem is that, if <code>background_operation</code> returns an incomplete
  11950. awaitable, it will expect its caller to <code>await</code> immediately, so will have
  11951. cleared the logcontext. In this example, that means that 'Request
  11952. handling complete' will be logged without any context.</p>
  11953. <p>The second problem, which is potentially even worse, is that when the
  11954. awaitable returned by <code>background_operation</code> completes, it will restore
  11955. the original logcontext. There is nothing waiting on that awaitable, so
  11956. the logcontext will leak into the reactor and possibly get attached to
  11957. some arbitrary future operation.</p>
  11958. <p>There are two potential solutions to this.</p>
  11959. <p>One option is to surround the call to <code>background_operation</code> with a
  11960. <code>PreserveLoggingContext</code> call. That will reset the logcontext before
  11961. starting <code>background_operation</code> (so the context restored when the
  11962. deferred completes will be the empty logcontext), and will restore the
  11963. current logcontext before continuing the foreground process:</p>
  11964. <pre><code class="language-python">async def do_request_handling():
  11965. await foreground_operation()
  11966. # start background_operation off in the empty logcontext, to
  11967. # avoid leaking the current context into the reactor.
  11968. with PreserveLoggingContext():
  11969. background_operation()
  11970. # this will now be logged against the request context
  11971. logger.debug(&quot;Request handling complete&quot;)
  11972. </code></pre>
  11973. <p>Obviously that option means that the operations done in
  11974. <code>background_operation</code> would be not be logged against a logcontext
  11975. (though that might be fixed by setting a different logcontext via a
  11976. <code>with LoggingContext(...)</code> in <code>background_operation</code>).</p>
  11977. <p>The second option is to use <code>context.run_in_background</code>, which wraps a
  11978. function so that it doesn't reset the logcontext even when it returns
  11979. an incomplete awaitable, and adds a callback to the returned awaitable to
  11980. reset the logcontext. In other words, it turns a function that follows
  11981. the Synapse rules about logcontexts and awaitables into one which behaves
  11982. more like an external function --- the opposite operation to that
  11983. described in the previous section. It can be used like this:</p>
  11984. <pre><code class="language-python">async def do_request_handling():
  11985. await foreground_operation()
  11986. context.run_in_background(background_operation)
  11987. # this will now be logged against the request context
  11988. logger.debug(&quot;Request handling complete&quot;)
  11989. </code></pre>
  11990. <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>
  11991. <p>A typical example of this is where we want to collect together two or
  11992. more awaitables via <code>defer.gatherResults</code>:</p>
  11993. <pre><code class="language-python">a1 = operation1()
  11994. a2 = operation2()
  11995. a3 = defer.gatherResults([a1, a2])
  11996. </code></pre>
  11997. <p>This is really a variation of the fire-and-forget problem above, in that
  11998. we are firing off <code>a1</code> and <code>a2</code> without awaiting on them. The difference
  11999. is that we now have third-party code attached to their callbacks. Anyway
  12000. either technique given in the <a href="log_contexts.html#fire-and-forget">Fire-and-forget</a>
  12001. section will work.</p>
  12002. <p>Of course, the new awaitable returned by <code>gather</code> needs to be
  12003. wrapped in order to make it follow the logcontext rules before we can
  12004. 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
  12005. follow the
  12006. rules</a>.</p>
  12007. <p>So, option one: reset the logcontext before starting the operations to
  12008. be gathered:</p>
  12009. <pre><code class="language-python">async def do_request_handling():
  12010. with PreserveLoggingContext():
  12011. a1 = operation1()
  12012. a2 = operation2()
  12013. result = await defer.gatherResults([a1, a2])
  12014. </code></pre>
  12015. <p>In this case particularly, though, option two, of using
  12016. <code>context.run_in_background</code> almost certainly makes more sense, so that
  12017. <code>operation1</code> and <code>operation2</code> are both logged against the original
  12018. logcontext. This looks like:</p>
  12019. <pre><code class="language-python">async def do_request_handling():
  12020. a1 = context.run_in_background(operation1)
  12021. a2 = context.run_in_background(operation2)
  12022. result = await make_deferred_yieldable(defer.gatherResults([a1, a2]))
  12023. </code></pre>
  12024. <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>
  12025. <p>It turns out that our logcontext rules do not play nicely with awaitable
  12026. chains which get orphaned and garbage-collected.</p>
  12027. <p>Imagine we have some code that looks like this:</p>
  12028. <pre><code class="language-python">listener_queue = []
  12029. def on_something_interesting():
  12030. for d in listener_queue:
  12031. d.callback(&quot;foo&quot;)
  12032. async def await_something_interesting():
  12033. new_awaitable = defer.Deferred()
  12034. listener_queue.append(new_awaitable)
  12035. with PreserveLoggingContext():
  12036. await new_awaitable
  12037. </code></pre>
  12038. <p>Obviously, the idea here is that we have a bunch of things which are
  12039. waiting for an event. (It's just an example of the problem here, but a
  12040. relatively common one.)</p>
  12041. <p>Now let's imagine two further things happen. First of all, whatever was
  12042. waiting for the interesting thing goes away. (Perhaps the request times
  12043. out, or something <em>even more</em> interesting happens.)</p>
  12044. <p>Secondly, let's suppose that we decide that the interesting thing is
  12045. never going to happen, and we reset the listener queue:</p>
  12046. <pre><code class="language-python">def reset_listener_queue():
  12047. listener_queue.clear()
  12048. </code></pre>
  12049. <p>So, both ends of the awaitable chain have now dropped their references,
  12050. and the awaitable chain is now orphaned, and will be garbage-collected at
  12051. some point. Note that <code>await_something_interesting</code> is a coroutine,
  12052. which Python implements as a generator function. When Python
  12053. garbage-collects generator functions, it gives them a chance to
  12054. clean up by making the <code>await</code> (or <code>yield</code>) raise a <code>GeneratorExit</code>
  12055. exception. In our case, that means that the <code>__exit__</code> handler of
  12056. <code>PreserveLoggingContext</code> will carefully restore the request context, but
  12057. there is now nothing waiting for its return, so the request context is
  12058. never cleared.</p>
  12059. <p>To reiterate, this problem only arises when <em>both</em> ends of a awaitable
  12060. chain are dropped. Dropping the the reference to an awaitable you're
  12061. supposed to be awaiting is bad practice, so this doesn't
  12062. actually happen too much. Unfortunately, when it does happen, it will
  12063. lead to leaked logcontexts which are incredibly hard to track down.</p>
  12064. <div style="break-before: page; page-break-before: always;"></div><h1 id="replication-architecture"><a class="header" href="#replication-architecture">Replication Architecture</a></h1>
  12065. <h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
  12066. <p>We'd like to be able to split some of the work that synapse does into
  12067. multiple python processes. In theory multiple synapse processes could
  12068. share a single postgresql database and we'd scale up by running more
  12069. synapse processes. However much of synapse assumes that only one process
  12070. is interacting with the database, both for assigning unique identifiers
  12071. when inserting into tables, notifying components about new updates, and
  12072. for invalidating its caches.</p>
  12073. <p>So running multiple copies of the current code isn't an option. One way
  12074. to run multiple processes would be to have a single writer process and
  12075. multiple reader processes connected to the same database. In order to do
  12076. this we'd need a way for the reader process to invalidate its in-memory
  12077. caches when an update happens on the writer. One way to do this is for
  12078. the writer to present an append-only log of updates which the readers
  12079. can consume to invalidate their caches and to push updates to listening
  12080. clients or pushers.</p>
  12081. <p>Synapse already stores much of its data as an append-only log so that it
  12082. can correctly respond to <code>/sync</code> requests so the amount of code changes
  12083. needed to expose the append-only log to the readers should be fairly
  12084. minimal.</p>
  12085. <h2 id="architecture"><a class="header" href="#architecture">Architecture</a></h2>
  12086. <h3 id="the-replication-protocol"><a class="header" href="#the-replication-protocol">The Replication Protocol</a></h3>
  12087. <p>See <a href="tcp_replication.html">the TCP replication documentation</a>.</p>
  12088. <h3 id="the-slaved-datastore"><a class="header" href="#the-slaved-datastore">The Slaved DataStore</a></h3>
  12089. <p>There are read-only version of the synapse storage layer in
  12090. <code>synapse/replication/slave/storage</code> that use the response of the
  12091. replication API to invalidate their caches.</p>
  12092. <div style="break-before: page; page-break-before: always;"></div><h1 id="tcp-replication"><a class="header" href="#tcp-replication">TCP Replication</a></h1>
  12093. <h2 id="motivation-1"><a class="header" href="#motivation-1">Motivation</a></h2>
  12094. <p>Previously the workers used an HTTP long poll mechanism to get updates
  12095. from the master, which had the problem of causing a lot of duplicate
  12096. work on the server. This TCP protocol replaces those APIs with the aim
  12097. of increased efficiency.</p>
  12098. <h2 id="overview-3"><a class="header" href="#overview-3">Overview</a></h2>
  12099. <p>The protocol is based on fire and forget, line based commands. An
  12100. example flow would be (where '&gt;' indicates master to worker and
  12101. '&lt;' worker to master flows):</p>
  12102. <pre><code>&gt; SERVER example.com
  12103. &lt; REPLICATE
  12104. &gt; POSITION events master 53 53
  12105. &gt; RDATA events master 54 [&quot;$foo1:bar.com&quot;, ...]
  12106. &gt; RDATA events master 55 [&quot;$foo4:bar.com&quot;, ...]
  12107. </code></pre>
  12108. <p>The example shows the server accepting a new connection and sending its identity
  12109. with the <code>SERVER</code> command, followed by the client server to respond with the
  12110. position of all streams. The server then periodically sends <code>RDATA</code> commands
  12111. which have the format <code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row&gt;</code>, where
  12112. the format of <code>&lt;row&gt;</code> is defined by the individual streams. The
  12113. <code>&lt;instance_name&gt;</code> is the name of the Synapse process that generated the data
  12114. (usually &quot;master&quot;).</p>
  12115. <p>Error reporting happens by either the client or server sending an ERROR
  12116. command, and usually the connection will be closed.</p>
  12117. <p>Since the protocol is a simple line based, its possible to manually
  12118. connect to the server using a tool like netcat. A few things should be
  12119. noted when manually using the protocol:</p>
  12120. <ul>
  12121. <li>The federation stream is only available if federation sending has
  12122. been disabled on the main process.</li>
  12123. <li>The server will only time connections out that have sent a <code>PING</code>
  12124. command. If a ping is sent then the connection will be closed if no
  12125. further commands are receieved within 15s. Both the client and
  12126. server protocol implementations will send an initial PING on
  12127. connection and ensure at least one command every 5s is sent (not
  12128. necessarily <code>PING</code>).</li>
  12129. <li><code>RDATA</code> commands <em>usually</em> include a numeric token, however if the
  12130. stream has multiple rows to replicate per token the server will send
  12131. multiple <code>RDATA</code> commands, with all but the last having a token of
  12132. <code>batch</code>. See the documentation on <code>commands.RdataCommand</code> for
  12133. further details.</li>
  12134. </ul>
  12135. <h2 id="architecture-1"><a class="header" href="#architecture-1">Architecture</a></h2>
  12136. <p>The basic structure of the protocol is line based, where the initial
  12137. word of each line specifies the command. The rest of the line is parsed
  12138. based on the command. For example, the RDATA command is defined as:</p>
  12139. <pre><code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row_json&gt;
  12140. </code></pre>
  12141. <p>(Note that &lt;row_json&gt; may contains spaces, but cannot contain
  12142. newlines.)</p>
  12143. <p>Blank lines are ignored.</p>
  12144. <h3 id="keep-alives"><a class="header" href="#keep-alives">Keep alives</a></h3>
  12145. <p>Both sides are expected to send at least one command every 5s or so, and
  12146. should send a <code>PING</code> command if necessary. If either side do not receive
  12147. a command within e.g. 15s then the connection should be closed.</p>
  12148. <p>Because the server may be connected to manually using e.g. netcat, the
  12149. timeouts aren't enabled until an initial <code>PING</code> command is seen. Both
  12150. the client and server implementations below send a <code>PING</code> command
  12151. immediately on connection to ensure the timeouts are enabled.</p>
  12152. <p>This ensures that both sides can quickly realize if the tcp connection
  12153. has gone and handle the situation appropriately.</p>
  12154. <h3 id="start-up"><a class="header" href="#start-up">Start up</a></h3>
  12155. <p>When a new connection is made, the server:</p>
  12156. <ul>
  12157. <li>Sends a <code>SERVER</code> command, which includes the identity of the server,
  12158. allowing the client to detect if its connected to the expected
  12159. server</li>
  12160. <li>Sends a <code>PING</code> command as above, to enable the client to time out
  12161. connections promptly.</li>
  12162. </ul>
  12163. <p>The client:</p>
  12164. <ul>
  12165. <li>Sends a <code>NAME</code> command, allowing the server to associate a human
  12166. friendly name with the connection. This is optional.</li>
  12167. <li>Sends a <code>PING</code> as above</li>
  12168. <li>Sends a <code>REPLICATE</code> to get the current position of all streams.</li>
  12169. <li>On receipt of a <code>SERVER</code> command, checks that the server name
  12170. matches the expected server name.</li>
  12171. </ul>
  12172. <h3 id="error-handling"><a class="header" href="#error-handling">Error handling</a></h3>
  12173. <p>If either side detects an error it can send an <code>ERROR</code> command and close
  12174. the connection.</p>
  12175. <p>If the client side loses the connection to the server it should
  12176. reconnect, following the steps above.</p>
  12177. <h3 id="congestion"><a class="header" href="#congestion">Congestion</a></h3>
  12178. <p>If the server sends messages faster than the client can consume them the
  12179. server will first buffer a (fairly large) number of commands and then
  12180. disconnect the client. This ensures that we don't queue up an unbounded
  12181. number of commands in memory and gives us a potential oppurtunity to
  12182. squawk loudly. When/if the client recovers it can reconnect to the
  12183. server and ask for missed messages.</p>
  12184. <h3 id="reliability"><a class="header" href="#reliability">Reliability</a></h3>
  12185. <p>In general the replication stream should be considered an unreliable
  12186. transport since e.g. commands are not resent if the connection
  12187. disappears.</p>
  12188. <p>The exception to that are the replication streams, i.e. RDATA commands,
  12189. since these include tokens which can be used to restart the stream on
  12190. connection errors.</p>
  12191. <p>The client should keep track of the token in the last RDATA command
  12192. received for each stream so that on reconneciton it can start streaming
  12193. from the correct place. Note: not all RDATA have valid tokens due to
  12194. batching. See <code>RdataCommand</code> for more details.</p>
  12195. <h3 id="example-3"><a class="header" href="#example-3">Example</a></h3>
  12196. <p>An example iteraction is shown below. Each line is prefixed with '&gt;'
  12197. or '&lt;' to indicate which side is sending, these are <em>not</em> included on
  12198. the wire:</p>
  12199. <pre><code>* connection established *
  12200. &gt; SERVER localhost:8823
  12201. &gt; PING 1490197665618
  12202. &lt; NAME synapse.app.appservice
  12203. &lt; PING 1490197665618
  12204. &lt; REPLICATE
  12205. &gt; POSITION events master 1 1
  12206. &gt; POSITION backfill master 1 1
  12207. &gt; POSITION caches master 1 1
  12208. &gt; RDATA caches master 2 [&quot;get_user_by_id&quot;,[&quot;@01register-user:localhost:8823&quot;],1490197670513]
  12209. &gt; RDATA events master 14 [&quot;$149019767112vOHxz:localhost:8823&quot;,
  12210. &quot;!AFDCvgApUmpdfVjIXm:localhost:8823&quot;,&quot;m.room.guest_access&quot;,&quot;&quot;,null]
  12211. &lt; PING 1490197675618
  12212. &gt; ERROR server stopping
  12213. * connection closed by server *
  12214. </code></pre>
  12215. <p>The <code>POSITION</code> command sent by the server is used to set the clients
  12216. position without needing to send data with the <code>RDATA</code> command.</p>
  12217. <p>An example of a batched set of <code>RDATA</code> is:</p>
  12218. <pre><code>&gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test:localhost:8823&quot;],1490197670513]
  12219. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test2:localhost:8823&quot;],1490197670513]
  12220. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test3:localhost:8823&quot;],1490197670513]
  12221. &gt; RDATA caches master 54 [&quot;get_user_by_id&quot;,[&quot;@test4:localhost:8823&quot;],1490197670513]
  12222. </code></pre>
  12223. <p>In this case the client shouldn't advance their caches token until it
  12224. sees the the last <code>RDATA</code>.</p>
  12225. <h3 id="list-of-commands"><a class="header" href="#list-of-commands">List of commands</a></h3>
  12226. <p>The list of valid commands, with which side can send it: server (S) or
  12227. client (C):</p>
  12228. <h4 id="server-s"><a class="header" href="#server-s">SERVER (S)</a></h4>
  12229. <p>Sent at the start to identify which server the client is talking to</p>
  12230. <h4 id="rdata-s"><a class="header" href="#rdata-s">RDATA (S)</a></h4>
  12231. <p>A single update in a stream</p>
  12232. <h4 id="position-s"><a class="header" href="#position-s">POSITION (S)</a></h4>
  12233. <p>On receipt of a POSITION command clients should check if they have missed any
  12234. updates, and if so then fetch them out of band. Sent in response to a
  12235. REPLICATE command (but can happen at any time).</p>
  12236. <p>The POSITION command includes the source of the stream. Currently all streams
  12237. are written by a single process (usually &quot;master&quot;). If fetching missing
  12238. updates via HTTP API, rather than via the DB, then processes should make the
  12239. request to the appropriate process.</p>
  12240. <p>Two positions are included, the &quot;new&quot; position and the last position sent respectively.
  12241. This allows servers to tell instances that the positions have advanced but no
  12242. data has been written, without clients needlessly checking to see if they
  12243. have missed any updates.</p>
  12244. <h4 id="error-s-c"><a class="header" href="#error-s-c">ERROR (S, C)</a></h4>
  12245. <p>There was an error</p>
  12246. <h4 id="ping-s-c"><a class="header" href="#ping-s-c">PING (S, C)</a></h4>
  12247. <p>Sent periodically to ensure the connection is still alive</p>
  12248. <h4 id="name-c"><a class="header" href="#name-c">NAME (C)</a></h4>
  12249. <p>Sent at the start by client to inform the server who they are</p>
  12250. <h4 id="replicate-c"><a class="header" href="#replicate-c">REPLICATE (C)</a></h4>
  12251. <p>Asks the server for the current position of all streams.</p>
  12252. <h4 id="user_sync-c"><a class="header" href="#user_sync-c">USER_SYNC (C)</a></h4>
  12253. <p>A user has started or stopped syncing on this process.</p>
  12254. <h4 id="clear_user_sync-c"><a class="header" href="#clear_user_sync-c">CLEAR_USER_SYNC (C)</a></h4>
  12255. <p>The server should clear all associated user sync data from the worker.</p>
  12256. <p>This is used when a worker is shutting down.</p>
  12257. <h4 id="federation_ack-c"><a class="header" href="#federation_ack-c">FEDERATION_ACK (C)</a></h4>
  12258. <p>Acknowledge receipt of some federation data</p>
  12259. <h3 id="remote_server_up-s-c"><a class="header" href="#remote_server_up-s-c">REMOTE_SERVER_UP (S, C)</a></h3>
  12260. <p>Inform other processes that a remote server may have come back online.</p>
  12261. <p>See <code>synapse/replication/tcp/commands.py</code> for a detailed description and
  12262. the format of each command.</p>
  12263. <h3 id="cache-invalidation-stream"><a class="header" href="#cache-invalidation-stream">Cache Invalidation Stream</a></h3>
  12264. <p>The cache invalidation stream is used to inform workers when they need
  12265. to invalidate any of their caches in the data store. This is done by
  12266. streaming all cache invalidations done on master down to the workers,
  12267. assuming that any caches on the workers also exist on the master.</p>
  12268. <p>Each individual cache invalidation results in a row being sent down
  12269. replication, which includes the cache name (the name of the function)
  12270. and they key to invalidate. For example:</p>
  12271. <pre><code>&gt; RDATA caches master 550953771 [&quot;get_user_by_id&quot;, [&quot;@bob:example.com&quot;], 1550574873251]
  12272. </code></pre>
  12273. <p>Alternatively, an entire cache can be invalidated by sending down a <code>null</code>
  12274. instead of the key. For example:</p>
  12275. <pre><code>&gt; RDATA caches master 550953772 [&quot;get_user_by_id&quot;, null, 1550574873252]
  12276. </code></pre>
  12277. <p>However, there are times when a number of caches need to be invalidated
  12278. at the same time with the same key. To reduce traffic we batch those
  12279. invalidations into a single poke by defining a special cache name that
  12280. workers understand to mean to expand to invalidate the correct caches.</p>
  12281. <p>Currently the special cache names are declared in
  12282. <code>synapse/storage/_base.py</code> and are:</p>
  12283. <ol>
  12284. <li><code>cs_cache_fake</code> ─ invalidates caches that depend on the current
  12285. state</li>
  12286. </ol>
  12287. <div style="break-before: page; page-break-before: always;"></div><h1 id="internal-documentation"><a class="header" href="#internal-documentation">Internal Documentation</a></h1>
  12288. <p>This section covers implementation documentation for various parts of Synapse.</p>
  12289. <p>If a developer is planning to make a change to a feature of Synapse, it can be useful for
  12290. general documentation of how that feature is implemented to be available. This saves the
  12291. developer time in place of needing to understand how the feature works by reading the
  12292. code.</p>
  12293. <p>Documentation that would be more useful for the perspective of a system administrator,
  12294. rather than a developer who's intending to change to code, should instead be placed
  12295. under the Usage section of the documentation.</p>
  12296. <div 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>
  12297. <p>https://capriza.github.io/samling/samling.html (https://github.com/capriza/samling) is a great
  12298. resource for being able to tinker with the SAML options within Synapse without needing to
  12299. deploy and configure a complicated software stack.</p>
  12300. <p>To make Synapse (and therefore Riot) use it:</p>
  12301. <ol>
  12302. <li>Use the samling.html URL above or deploy your own and visit the IdP Metadata tab.</li>
  12303. <li>Copy the XML to your clipboard.</li>
  12304. <li>On your Synapse server, create a new file <code>samling.xml</code> next to your <code>homeserver.yaml</code> with
  12305. the XML from step 2 as the contents.</li>
  12306. <li>Edit your <code>homeserver.yaml</code> to include:
  12307. <pre><code class="language-yaml">saml2_config:
  12308. sp_config:
  12309. allow_unknown_attributes: true # Works around a bug with AVA Hashes: https://github.com/IdentityPython/pysaml2/issues/388
  12310. metadata:
  12311. local: [&quot;samling.xml&quot;]
  12312. </code></pre>
  12313. </li>
  12314. <li>Ensure that your <code>homeserver.yaml</code> has a setting for <code>public_baseurl</code>:
  12315. <pre><code class="language-yaml">public_baseurl: http://localhost:8080/
  12316. </code></pre>
  12317. </li>
  12318. <li>Run <code>apt-get install xmlsec1</code> and <code>pip install --upgrade --force 'pysaml2&gt;=4.5.0'</code> to ensure
  12319. the dependencies are installed and ready to go.</li>
  12320. <li>Restart Synapse.</li>
  12321. </ol>
  12322. <p>Then in Riot:</p>
  12323. <ol>
  12324. <li>Visit the login page with a Riot pointing at your homeserver.</li>
  12325. <li>Click the Single Sign-On button.</li>
  12326. <li>On the samling page, enter a Name Identifier and add a SAML Attribute for <code>uid=your_localpart</code>.
  12327. The response must also be signed.</li>
  12328. <li>Click &quot;Next&quot;.</li>
  12329. <li>Click &quot;Post Response&quot; (change nothing).</li>
  12330. <li>You should be logged in.</li>
  12331. </ol>
  12332. <p>If you try and repeat this process, you may be automatically logged in using the information you
  12333. gave previously. To fix this, open your developer console (<code>F12</code> or <code>Ctrl+Shift+I</code>) while on the
  12334. samling page and clear the site data. In Chrome, this will be a button on the Application tab.</p>
  12335. <div 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>
  12336. <p>The <a href="https://github.com/jbittel/django-mama-cas">django-mama-cas</a> project is an
  12337. easy to run CAS implementation built on top of Django.</p>
  12338. <h2 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h2>
  12339. <ol>
  12340. <li>Create a new virtualenv: <code>python3 -m venv &lt;your virtualenv&gt;</code></li>
  12341. <li>Activate your virtualenv: <code>source /path/to/your/virtualenv/bin/activate</code></li>
  12342. <li>Install Django and django-mama-cas:
  12343. <pre><code>python -m pip install &quot;django&lt;3&quot; &quot;django-mama-cas==2.4.0&quot;
  12344. </code></pre>
  12345. </li>
  12346. <li>Create a Django project in the current directory:
  12347. <pre><code>django-admin startproject cas_test .
  12348. </code></pre>
  12349. </li>
  12350. <li>Follow the <a href="https://django-mama-cas.readthedocs.io/en/latest/installation.html#configuring">install directions</a> for django-mama-cas</li>
  12351. <li>Setup the SQLite database: <code>python manage.py migrate</code></li>
  12352. <li>Create a user:
  12353. <pre><code>python manage.py createsuperuser
  12354. </code></pre>
  12355. <ol>
  12356. <li>Use whatever you want as the username and password.</li>
  12357. <li>Leave the other fields blank.</li>
  12358. </ol>
  12359. </li>
  12360. <li>Use the built-in Django test server to serve the CAS endpoints on port 8000:
  12361. <pre><code>python manage.py runserver
  12362. </code></pre>
  12363. </li>
  12364. </ol>
  12365. <p>You should now have a Django project configured to serve CAS authentication with
  12366. a single user created.</p>
  12367. <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>
  12368. <ol>
  12369. <li>Modify your <code>homeserver.yaml</code> to enable CAS and point it to your locally
  12370. running Django test server:
  12371. <pre><code class="language-yaml">cas_config:
  12372. enabled: true
  12373. server_url: &quot;http://localhost:8000&quot;
  12374. service_url: &quot;http://localhost:8081&quot;
  12375. #displayname_attribute: name
  12376. #required_attributes:
  12377. # name: value
  12378. </code></pre>
  12379. </li>
  12380. <li>Restart Synapse.</li>
  12381. </ol>
  12382. <p>Note that the above configuration assumes the homeserver is running on port 8081
  12383. and that the CAS server is on port 8000, both on localhost.</p>
  12384. <h2 id="testing-the-configuration"><a class="header" href="#testing-the-configuration">Testing the configuration</a></h2>
  12385. <p>Then in Element:</p>
  12386. <ol>
  12387. <li>Visit the login page with a Element pointing at your homeserver.</li>
  12388. <li>Click the Single Sign-On button.</li>
  12389. <li>Login using the credentials created with <code>createsuperuser</code>.</li>
  12390. <li>You should be logged in.</li>
  12391. </ol>
  12392. <p>If you want to repeat this process you'll need to manually logout first:</p>
  12393. <ol>
  12394. <li>http://localhost:8000/admin/</li>
  12395. <li>Click &quot;logout&quot; in the top right.</li>
  12396. </ol>
  12397. <div 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>
  12398. <h2 id="edges"><a class="header" href="#edges">Edges</a></h2>
  12399. <p>The word &quot;edge&quot; comes from graph theory lingo. An edge is just a connection
  12400. between two events. In Synapse, we connect events by specifying their
  12401. <code>prev_events</code>. A subsequent event points back at a previous event.</p>
  12402. <pre><code>A (oldest) &lt;---- B &lt;---- C (most recent)
  12403. </code></pre>
  12404. <h2 id="depth-and-stream-ordering"><a class="header" href="#depth-and-stream-ordering">Depth and stream ordering</a></h2>
  12405. <p>Events are normally sorted by <code>(topological_ordering, stream_ordering)</code> where
  12406. <code>topological_ordering</code> is just <code>depth</code>. In other words, we first sort by <code>depth</code>
  12407. and then tie-break based on <code>stream_ordering</code>. <code>depth</code> is incremented as new
  12408. messages are added to the DAG. Normally, <code>stream_ordering</code> is an auto
  12409. incrementing integer, but backfilled events start with <code>stream_ordering=-1</code> and decrement.</p>
  12410. <hr />
  12411. <ul>
  12412. <li><code>/sync</code> returns things in the order they arrive at the server (<code>stream_ordering</code>).</li>
  12413. <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>
  12414. </ul>
  12415. <p>The general idea is that, if you're following a room in real-time (i.e.
  12416. <code>/sync</code>), you probably want to see the messages as they arrive at your server,
  12417. rather than skipping any that arrived late; whereas if you're looking at a
  12418. historical section of timeline (i.e. <code>/messages</code>), you want to see the best
  12419. representation of the state of the room as others were seeing it at the time.</p>
  12420. <h2 id="forward-extremity"><a class="header" href="#forward-extremity">Forward extremity</a></h2>
  12421. <p>Most-recent-in-time events in the DAG which are not referenced by any other events' <code>prev_events</code> yet.</p>
  12422. <p>The forward extremities of a room are used as the <code>prev_events</code> when the next event is sent.</p>
  12423. <h2 id="backwards-extremity"><a class="header" href="#backwards-extremity">Backwards extremity</a></h2>
  12424. <p>The current marker of where we have backfilled up to and will generally be the
  12425. oldest-in-time events we know of in the DAG.</p>
  12426. <p>This is an event where we haven't fetched all of the <code>prev_events</code> for.</p>
  12427. <p>Once we have fetched all of its <code>prev_events</code>, it's unmarked as a backwards
  12428. extremity (although we may have formed new backwards extremities from the prev
  12429. events during the backfilling process).</p>
  12430. <h2 id="outliers"><a class="header" href="#outliers">Outliers</a></h2>
  12431. <p>We mark an event as an <code>outlier</code> when we haven't figured out the state for the
  12432. room at that point in the DAG yet.</p>
  12433. <p>We won't <em>necessarily</em> have the <code>prev_events</code> of an <code>outlier</code> in the database,
  12434. but it's entirely possible that we <em>might</em>. The status of whether we have all of
  12435. the <code>prev_events</code> is marked as a <a href="development/room-dag-concepts.html#backwards-extremity">backwards extremity</a>.</p>
  12436. <p>For example, when we fetch the event auth chain or state for a given event, we
  12437. mark all of those claimed auth events as outliers because we haven't done the
  12438. state calculation ourself.</p>
  12439. <h2 id="state-groups"><a class="header" href="#state-groups">State groups</a></h2>
  12440. <p>For every non-outlier event we need to know the state at that event. Instead of
  12441. storing the full state for each event in the DB (i.e. a <code>event_id -&gt; state</code>
  12442. mapping), which is <em>very</em> space inefficient when state doesn't change, we
  12443. instead assign each different set of state a &quot;state group&quot; and then have
  12444. mappings of <code>event_id -&gt; state_group</code> and <code>state_group -&gt; state</code>.</p>
  12445. <h3 id="stage-group-edges"><a class="header" href="#stage-group-edges">Stage group edges</a></h3>
  12446. <p>TODO: <code>state_group_edges</code> is a further optimization...
  12447. notes from @Azrenbeth, https://pastebin.com/seUGVGeT</p>
  12448. <div 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>
  12449. <p>The auth chain difference algorithm is used by V2 state resolution, where a
  12450. naive implementation can be a significant source of CPU and DB usage.</p>
  12451. <h3 id="definitions"><a class="header" href="#definitions">Definitions</a></h3>
  12452. <p>A <em>state set</em> is a set of state events; e.g. the input of a state resolution
  12453. algorithm is a collection of state sets.</p>
  12454. <p>The <em>auth chain</em> of a set of events are all the events' auth events and <em>their</em>
  12455. auth events, recursively (i.e. the events reachable by walking the graph induced
  12456. by an event's auth events links).</p>
  12457. <p>The <em>auth chain difference</em> of a collection of state sets is the union minus the
  12458. intersection of the sets of auth chains corresponding to the state sets, i.e an
  12459. event is in the auth chain difference if it is reachable by walking the auth
  12460. event graph from at least one of the state sets but not from <em>all</em> of the state
  12461. sets.</p>
  12462. <h2 id="breadth-first-walk-algorithm"><a class="header" href="#breadth-first-walk-algorithm">Breadth First Walk Algorithm</a></h2>
  12463. <p>A way of calculating the auth chain difference without calculating the full auth
  12464. chains for each state set is to do a parallel breadth first walk (ordered by
  12465. depth) of each state set's auth chain. By tracking which events are reachable
  12466. from each state set we can finish early if every pending event is reachable from
  12467. every state set.</p>
  12468. <p>This can work well for state sets that have a small auth chain difference, but
  12469. can be very inefficient for larger differences. However, this algorithm is still
  12470. used if we don't have a chain cover index for the room (e.g. because we're in
  12471. the process of indexing it).</p>
  12472. <h2 id="chain-cover-index"><a class="header" href="#chain-cover-index">Chain Cover Index</a></h2>
  12473. <p>Synapse computes auth chain differences by pre-computing a &quot;chain cover&quot; index
  12474. for the auth chain in a room, allowing efficient reachability queries like &quot;is
  12475. event A in the auth chain of event B&quot;. This is done by assigning every event a
  12476. <em>chain ID</em> and <em>sequence number</em> (e.g. <code>(5,3)</code>), and having a map of <em>links</em>
  12477. between chains (e.g. <code>(5,3) -&gt; (2,4)</code>) such that A is reachable by B (i.e. <code>A</code>
  12478. is in the auth chain of <code>B</code>) if and only if either:</p>
  12479. <ol>
  12480. <li>A and B have the same chain ID and <code>A</code>'s sequence number is less than <code>B</code>'s
  12481. sequence number; or</li>
  12482. <li>there is a link <code>L</code> between <code>B</code>'s chain ID and <code>A</code>'s chain ID such that
  12483. <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>
  12484. </ol>
  12485. <p>There are actually two potential implementations, one where we store links from
  12486. each chain to every other reachable chain (the transitive closure of the links
  12487. graph), and one where we remove redundant links (the transitive reduction of the
  12488. links graph) e.g. if we have chains <code>C3 -&gt; C2 -&gt; C1</code> then the link <code>C3 -&gt; C1</code>
  12489. would not be stored. Synapse uses the former implementations so that it doesn't
  12490. need to recurse to test reachability between chains.</p>
  12491. <h3 id="example-4"><a class="header" href="#example-4">Example</a></h3>
  12492. <p>An example auth graph would look like the following, where chains have been
  12493. formed based on type/state_key and are denoted by colour and are labelled with
  12494. <code>(chain ID, sequence number)</code>. Links are denoted by the arrows (links in grey
  12495. are those that would be remove in the second implementation described above).</p>
  12496. <p><img src="auth_chain_diff.dot.png" alt="Example" /></p>
  12497. <p>Note that we don't include all links between events and their auth events, as
  12498. most of those links would be redundant. For example, all events point to the
  12499. create event, but each chain only needs the one link from it's base to the
  12500. create event.</p>
  12501. <h2 id="using-the-index"><a class="header" href="#using-the-index">Using the Index</a></h2>
  12502. <p>This index can be used to calculate the auth chain difference of the state sets
  12503. by looking at the chain ID and sequence numbers reachable from each state set:</p>
  12504. <ol>
  12505. <li>For every state set lookup the chain ID/sequence numbers of each state event</li>
  12506. <li>Use the index to find all chains and the maximum sequence number reachable
  12507. from each state set.</li>
  12508. <li>The auth chain difference is then all events in each chain that have sequence
  12509. numbers between the maximum sequence number reachable from <em>any</em> state set and
  12510. the minimum reachable by <em>all</em> state sets (if any).</li>
  12511. </ol>
  12512. <p>Note that steps 2 is effectively calculating the auth chain for each state set
  12513. (in terms of chain IDs and sequence numbers), and step 3 is calculating the
  12514. difference between the union and intersection of the auth chains.</p>
  12515. <h3 id="worked-example"><a class="header" href="#worked-example">Worked Example</a></h3>
  12516. <p>For example, given the above graph, we can calculate the difference between
  12517. state sets consisting of:</p>
  12518. <ol>
  12519. <li><code>S1</code>: Alice's invite <code>(4,1)</code> and Bob's second join <code>(2,2)</code>; and</li>
  12520. <li><code>S2</code>: Alice's second join <code>(4,3)</code> and Bob's first join <code>(2,1)</code>.</li>
  12521. </ol>
  12522. <p>Using the index we see that the following auth chains are reachable from each
  12523. state set:</p>
  12524. <ol>
  12525. <li><code>S1</code>: <code>(1,1)</code>, <code>(2,2)</code>, <code>(3,1)</code> &amp; <code>(4,1)</code></li>
  12526. <li><code>S2</code>: <code>(1,1)</code>, <code>(2,1)</code>, <code>(3,2)</code> &amp; <code>(4,3)</code></li>
  12527. </ol>
  12528. <p>And so, for each the ranges that are in the auth chain difference:</p>
  12529. <ol>
  12530. <li>Chain 1: None, (since everything can reach the create event).</li>
  12531. <li>Chain 2: The range <code>(1, 2]</code> (i.e. just <code>2</code>), as <code>1</code> is reachable by all state
  12532. sets and the maximum reachable is <code>2</code> (corresponding to Bob's second join).</li>
  12533. <li>Chain 3: Similarly the range <code>(1, 2]</code> (corresponding to the second power
  12534. level).</li>
  12535. <li>Chain 4: The range <code>(1, 3]</code> (corresponding to both of Alice's joins).</li>
  12536. </ol>
  12537. <p>So the final result is: Bob's second join <code>(2,2)</code>, the second power level
  12538. <code>(3,2)</code> and both of Alice's joins <code>(4,2)</code> &amp; <code>(4,3)</code>.</p>
  12539. <div style="break-before: page; page-break-before: always;"></div><h1 id="media-repository"><a class="header" href="#media-repository">Media Repository</a></h1>
  12540. <p><em>Synapse implementation-specific details for the media repository</em></p>
  12541. <p>The media repository is where attachments and avatar photos are stored.
  12542. It stores attachment content and thumbnails for media uploaded by local users.
  12543. It caches attachment content and thumbnails for media uploaded by remote users.</p>
  12544. <h2 id="storage"><a class="header" href="#storage">Storage</a></h2>
  12545. <p>Each item of media is assigned a <code>media_id</code> when it is uploaded.
  12546. The <code>media_id</code> is a randomly chosen, URL safe 24 character string.</p>
  12547. <p>Metadata such as the MIME type, upload time and length are stored in the
  12548. sqlite3 database indexed by <code>media_id</code>.</p>
  12549. <p>Content is stored on the filesystem under a <code>&quot;local_content&quot;</code> directory.</p>
  12550. <p>Thumbnails are stored under a <code>&quot;local_thumbnails&quot;</code> directory.</p>
  12551. <p>The item with <code>media_id</code> <code>&quot;aabbccccccccdddddddddddd&quot;</code> is stored under
  12552. <code>&quot;local_content/aa/bb/ccccccccdddddddddddd&quot;</code>. Its thumbnail with width
  12553. <code>128</code> and height <code>96</code> and type <code>&quot;image/jpeg&quot;</code> is stored under
  12554. <code>&quot;local_thumbnails/aa/bb/ccccccccdddddddddddd/128-96-image-jpeg&quot;</code></p>
  12555. <p>Remote content is cached under <code>&quot;remote_content&quot;</code> directory. Each item of
  12556. remote content is assigned a local <code>&quot;filesystem_id&quot;</code> to ensure that the
  12557. directory structure <code>&quot;remote_content/server_name/aa/bb/ccccccccdddddddddddd&quot;</code>
  12558. is appropriate. Thumbnails for remote content are stored under
  12559. <code>&quot;remote_thumbnail/server_name/...&quot;</code></p>
  12560. <div 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>
  12561. <p>Synapse maintains room and user statistics in various tables. These can be used
  12562. for administrative purposes but are also used when generating the public room
  12563. directory.</p>
  12564. <h1 id="synapse-developer-documentation"><a class="header" href="#synapse-developer-documentation">Synapse Developer Documentation</a></h1>
  12565. <h2 id="high-level-concepts"><a class="header" href="#high-level-concepts">High-Level Concepts</a></h2>
  12566. <h3 id="definitions-1"><a class="header" href="#definitions-1">Definitions</a></h3>
  12567. <ul>
  12568. <li><strong>subject</strong>: Something we are tracking stats about – currently a room or user.</li>
  12569. <li><strong>current row</strong>: An entry for a subject in the appropriate current statistics
  12570. table. Each subject can have only one.</li>
  12571. </ul>
  12572. <h3 id="overview-4"><a class="header" href="#overview-4">Overview</a></h3>
  12573. <p>Stats correspond to the present values. Current rows contain the most up-to-date
  12574. statistics for a room. Each subject can only have one entry.</p>
  12575. <div 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>
  12576. <p>Synapse has a number of platform dependencies, including Python and PostgreSQL.
  12577. This document outlines the policy towards which versions we support, and when we
  12578. drop support for versions in the future.</p>
  12579. <h2 id="policy"><a class="header" href="#policy">Policy</a></h2>
  12580. <p>Synapse follows the upstream support life cycles for Python and PostgreSQL,
  12581. i.e. when a version reaches End of Life Synapse will withdraw support for that
  12582. version in future releases.</p>
  12583. <p>Details on the upstream support life cycles for Python and PostgreSQL are
  12584. documented at https://endoflife.date/python and
  12585. https://endoflife.date/postgresql.</p>
  12586. <h2 id="context"><a class="header" href="#context">Context</a></h2>
  12587. <p>It is important for system admins to have a clear understanding of the platform
  12588. requirements of Synapse and its deprecation policies so that they can
  12589. effectively plan upgrading their infrastructure ahead of time. This is
  12590. especially important in contexts where upgrading the infrastructure requires
  12591. auditing and approval from a security team, or where otherwise upgrading is a
  12592. long process.</p>
  12593. <p>By following the upstream support life cycles Synapse can ensure that its
  12594. dependencies continue to get security patches, while not requiring system admins
  12595. to constantly update their platform dependencies to the latest versions.</p>
  12596. </main>
  12597. <nav class="nav-wrapper" aria-label="Page navigation">
  12598. <!-- Mobile navigation buttons -->
  12599. <div style="clear: both"></div>
  12600. </nav>
  12601. </div>
  12602. </div>
  12603. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  12604. </nav>
  12605. </div>
  12606. <script type="text/javascript">
  12607. window.playground_copyable = true;
  12608. </script>
  12609. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  12610. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  12611. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  12612. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  12613. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  12614. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  12615. <!-- Custom JS scripts -->
  12616. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  12617. <script type="text/javascript" src="docs/website_files/version-picker.js"></script>
  12618. <script type="text/javascript" src="docs/website_files/version.js"></script>
  12619. <script type="text/javascript">
  12620. window.addEventListener('load', function() {
  12621. window.setTimeout(window.print, 100);
  12622. });
  12623. </script>
  12624. </body>
  12625. </html>