print.html 649 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591
  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="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="usage/configuration/user_authentication/index.html">User Authentication</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single-Sign On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="openid.html">OpenID Connect</a></li><li class="chapter-item expanded "><div>SAML</div></li><li class="chapter-item expanded "><div>CAS</div></li><li class="chapter-item expanded "><a href="sso_mapping_providers.html">SSO Mapping Providers</a></li></ol></li><li class="chapter-item expanded "><a href="password_auth_providers.html">Password Auth Providers</a></li><li class="chapter-item expanded "><a href="jwt.html">JSON Web Tokens</a></li></ol></li><li class="chapter-item expanded "><a href="CAPTCHA_SETUP.html">Registration Captcha</a></li><li class="chapter-item expanded "><a href="application_services.html">Application Services</a></li><li class="chapter-item expanded "><a href="server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="consent_tracking.html">Consent Tracking</a></li><li class="chapter-item expanded "><a href="url_previews.html">URL Previews</a></li><li class="chapter-item expanded "><a href="user_directory.html">User Directory</a></li><li class="chapter-item expanded "><a href="message_retention_policies.html">Message Retention Policies</a></li><li class="chapter-item expanded "><a href="modules.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Third Party Rules</div></li><li class="chapter-item expanded "><a href="spam_checker.html">Spam Checker</a></li><li class="chapter-item expanded "><a href="presence_router_module.html">Presence Router</a></li><li class="chapter-item expanded "><div>Media Storage Providers</div></li></ol></li><li class="chapter-item expanded "><a href="workers.html">Workers</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="synctl_workers.html">Using synctl with Workers</a></li><li class="chapter-item expanded "><a href="systemd-with-workers/index.html">Systemd</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/index.html">Administration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/admin_api/index.html">Admin API</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="admin_api/account_validity.html">Account Validity</a></li><li class="chapter-item expanded "><a href="admin_api/delete_group.html">Delete Group</a></li><li class="chapter-item expanded "><a href="admin_api/event_reports.html">Event Reports</a></li><li class="chapter-item expanded "><a href="admin_api/media_admin_api.html">Media</a></li><li class="chapter-item expanded "><a href="admin_api/purge_history_api.html">Purge History</a></li><li class="chapter-item expanded "><a href="admin_api/purge_room.html">Purge Rooms</a></li><li class="chapter-item expanded "><a href="admin_api/register_api.html">Register Users</a></li><li class="chapter-item expanded "><a href="admin_api/room_membership.html">Manipulate Room Membership</a></li><li class="chapter-item expanded "><a href="admin_api/rooms.html">Rooms</a></li><li class="chapter-item expanded "><a href="admin_api/server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="admin_api/shutdown_room.html">Shutdown Room</a></li><li class="chapter-item expanded "><a href="admin_api/statistics.html">Statistics</a></li><li class="chapter-item expanded "><a href="admin_api/user_admin_api.html">Users</a></li><li class="chapter-item expanded "><a href="admin_api/version_api.html">Server Version</a></li></ol></li><li class="chapter-item expanded "><a href="manhole.html">Manhole</a></li><li class="chapter-item expanded "><a href="metrics-howto.html">Monitoring</a></li><li class="chapter-item expanded "><a href="usage/administration/request_log.html">Request log format</a></li><li class="chapter-item expanded "><div>Scripts</div></li></ol></li><li class="chapter-item expanded "><li class="part-title">Development</li><li class="chapter-item expanded "><a href="development/contributing_guide.html">Contributing Guide</a></li><li class="chapter-item expanded "><a href="code_style.html">Code Style</a></li><li class="chapter-item expanded "><a href="dev/git.html">Git Usage</a></li><li class="chapter-item expanded "><div>Testing</div></li><li class="chapter-item expanded "><a href="opentracing.html">OpenTracing</a></li><li class="chapter-item expanded "><a href="development/database_schema.html">Database Schemas</a></li><li class="chapter-item expanded "><div>Synapse Architecture</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="log_contexts.html">Log Contexts</a></li><li class="chapter-item expanded "><a href="replication.html">Replication</a></li><li class="chapter-item expanded "><a href="tcp_replication.html">TCP Replication</a></li></ol></li><li class="chapter-item expanded "><a href="development/internal_documentation/index.html">Internal Documentation</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single Sign-On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="dev/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="dev/cas.html">CAS</a></li></ol></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. <p>There are 3 steps to follow under <strong>Installation Instructions</strong>.</p>
  152. <ul>
  153. <li><a href="setup/installation.html#installation-instructions">Installation Instructions</a>
  154. <ul>
  155. <li><a href="setup/installation.html#choosing-your-server-name">Choosing your server name</a></li>
  156. <li><a href="setup/installation.html#installing-synapse">Installing Synapse</a>
  157. <ul>
  158. <li><a href="setup/installation.html#installing-from-source">Installing from source</a>
  159. <ul>
  160. <li><a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a>
  161. <ul>
  162. <li><a href="setup/installation.html#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></li>
  163. <li><a href="setup/installation.html#archlinux">ArchLinux</a></li>
  164. <li><a href="setup/installation.html#centosfedora">CentOS/Fedora</a></li>
  165. <li><a href="setup/installation.html#macos">macOS</a></li>
  166. <li><a href="setup/installation.html#opensuse">OpenSUSE</a></li>
  167. <li><a href="setup/installation.html#openbsd">OpenBSD</a></li>
  168. <li><a href="setup/installation.html#windows">Windows</a></li>
  169. </ul>
  170. </li>
  171. </ul>
  172. </li>
  173. <li><a href="setup/installation.html#prebuilt-packages">Prebuilt packages</a>
  174. <ul>
  175. <li><a href="setup/installation.html#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></li>
  176. <li><a href="setup/installation.html#debianubuntu">Debian/Ubuntu</a>
  177. <ul>
  178. <li><a href="setup/installation.html#matrixorg-packages">Matrix.org packages</a></li>
  179. <li><a href="setup/installation.html#downstream-debian-packages">Downstream Debian packages</a></li>
  180. <li><a href="setup/installation.html#downstream-ubuntu-packages">Downstream Ubuntu packages</a></li>
  181. </ul>
  182. </li>
  183. <li><a href="setup/installation.html#fedora">Fedora</a></li>
  184. <li><a href="setup/installation.html#opensuse-1">OpenSUSE</a></li>
  185. <li><a href="setup/installation.html#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></li>
  186. <li><a href="setup/installation.html#archlinux-1">ArchLinux</a></li>
  187. <li><a href="setup/installation.html#void-linux">Void Linux</a></li>
  188. <li><a href="setup/installation.html#freebsd">FreeBSD</a></li>
  189. <li><a href="setup/installation.html#openbsd-1">OpenBSD</a></li>
  190. <li><a href="setup/installation.html#nixos">NixOS</a></li>
  191. </ul>
  192. </li>
  193. </ul>
  194. </li>
  195. <li><a href="setup/installation.html#setting-up-synapse">Setting up Synapse</a>
  196. <ul>
  197. <li><a href="setup/installation.html#using-postgresql">Using PostgreSQL</a></li>
  198. <li><a href="setup/installation.html#tls-certificates">TLS certificates</a></li>
  199. <li><a href="setup/installation.html#client-well-known-uri">Client Well-Known URI</a></li>
  200. <li><a href="setup/installation.html#email">Email</a></li>
  201. <li><a href="setup/installation.html#registering-a-user">Registering a user</a></li>
  202. <li><a href="setup/installation.html#setting-up-a-turn-server">Setting up a TURN server</a></li>
  203. <li><a href="setup/installation.html#url-previews">URL previews</a></li>
  204. <li><a href="setup/installation.html#troubleshooting-installation">Troubleshooting Installation</a></li>
  205. </ul>
  206. </li>
  207. </ul>
  208. </li>
  209. </ul>
  210. <h2 id="choosing-your-server-name"><a class="header" href="#choosing-your-server-name">Choosing your server name</a></h2>
  211. <p>It is important to choose the name for your server before you install Synapse,
  212. because it cannot be changed later.</p>
  213. <p>The server name determines the &quot;domain&quot; part of user-ids for users on your
  214. server: these will all be of the format <code>@user:my.domain.name</code>. It also
  215. determines how other matrix servers will reach yours for federation.</p>
  216. <p>For a test configuration, set this to the hostname of your server. For a more
  217. production-ready setup, you will probably want to specify your domain
  218. (<code>example.com</code>) rather than a matrix-specific hostname here (in the same way
  219. that your email address is probably <code>user@example.com</code> rather than
  220. <code>user@email.example.com</code>) - but doing so may require more advanced setup: see
  221. <a href="setup/../federate.html">Setting up Federation</a>.</p>
  222. <h2 id="installing-synapse"><a class="header" href="#installing-synapse">Installing Synapse</a></h2>
  223. <h3 id="installing-from-source"><a class="header" href="#installing-from-source">Installing from source</a></h3>
  224. <p>(Prebuilt packages are available for some platforms - see <a href="setup/installation.html#prebuilt-packages">Prebuilt packages</a>.)</p>
  225. <p>When installing from source please make sure that the <a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a> are already installed.</p>
  226. <p>System requirements:</p>
  227. <ul>
  228. <li>POSIX-compliant system (tested on Linux &amp; OS X)</li>
  229. <li>Python 3.5.2 or later, up to Python 3.9.</li>
  230. <li>At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org</li>
  231. </ul>
  232. <p>To install the Synapse homeserver run:</p>
  233. <pre><code class="language-sh">mkdir -p ~/synapse
  234. virtualenv -p python3 ~/synapse/env
  235. source ~/synapse/env/bin/activate
  236. pip install --upgrade pip
  237. pip install --upgrade setuptools
  238. pip install matrix-synapse
  239. </code></pre>
  240. <p>This will download Synapse from <a href="https://pypi.org/project/matrix-synapse">PyPI</a>
  241. and install it, along with the python libraries it uses, into a virtual environment
  242. under <code>~/synapse/env</code>. Feel free to pick a different directory if you
  243. prefer.</p>
  244. <p>This Synapse installation can then be later upgraded by using pip again with the
  245. update flag:</p>
  246. <pre><code class="language-sh">source ~/synapse/env/bin/activate
  247. pip install -U matrix-synapse
  248. </code></pre>
  249. <p>Before you can start Synapse, you will need to generate a configuration
  250. file. To do this, run (in your virtualenv, as before):</p>
  251. <pre><code class="language-sh">cd ~/synapse
  252. python -m synapse.app.homeserver \
  253. --server-name my.domain.name \
  254. --config-path homeserver.yaml \
  255. --generate-config \
  256. --report-stats=[yes|no]
  257. </code></pre>
  258. <p>... substituting an appropriate value for <code>--server-name</code>.</p>
  259. <p>This command will generate you a config file that you can then customise, but it will
  260. also generate a set of keys for you. These keys will allow your homeserver to
  261. identify itself to other homeserver, so don't lose or delete them. It would be
  262. wise to back them up somewhere safe. (If, for whatever reason, you do need to
  263. change your homeserver's keys, you may find that other homeserver have the
  264. old key cached. If you update the signing key, you should change the name of the
  265. key in the <code>&lt;server name&gt;.signing.key</code> file (the second word) to something
  266. 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>
  267. <p>To actually run your new homeserver, pick a working directory for Synapse to
  268. run (e.g. <code>~/synapse</code>), and:</p>
  269. <pre><code class="language-sh">cd ~/synapse
  270. source env/bin/activate
  271. synctl start
  272. </code></pre>
  273. <h4 id="platform-specific-prerequisites"><a class="header" href="#platform-specific-prerequisites">Platform-specific prerequisites</a></h4>
  274. <p>Synapse is written in Python but some of the libraries it uses are written in
  275. C. So before we can install Synapse itself we need a working C compiler and the
  276. header files for Python C extensions.</p>
  277. <h5 id="debianubunturaspbian"><a class="header" href="#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></h5>
  278. <p>Installing prerequisites on Ubuntu or Debian:</p>
  279. <pre><code class="language-sh">sudo apt install build-essential python3-dev libffi-dev \
  280. python3-pip python3-setuptools sqlite3 \
  281. libssl-dev virtualenv libjpeg-dev libxslt1-dev
  282. </code></pre>
  283. <h5 id="archlinux"><a class="header" href="#archlinux">ArchLinux</a></h5>
  284. <p>Installing prerequisites on ArchLinux:</p>
  285. <pre><code class="language-sh">sudo pacman -S base-devel python python-pip \
  286. python-setuptools python-virtualenv sqlite3
  287. </code></pre>
  288. <h5 id="centosfedora"><a class="header" href="#centosfedora">CentOS/Fedora</a></h5>
  289. <p>Installing prerequisites on CentOS or Fedora Linux:</p>
  290. <pre><code class="language-sh">sudo dnf install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
  291. libwebp-devel libxml2-devel libxslt-devel libpq-devel \
  292. python3-virtualenv libffi-devel openssl-devel python3-devel
  293. sudo dnf groupinstall &quot;Development Tools&quot;
  294. </code></pre>
  295. <h5 id="macos"><a class="header" href="#macos">macOS</a></h5>
  296. <p>Installing prerequisites on macOS:</p>
  297. <p>You may need to install the latest Xcode developer tools:</p>
  298. <pre><code class="language-sh">xcode-select --install
  299. </code></pre>
  300. <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>
  301. <pre><code class="language-sh"> brew install jpeg
  302. </code></pre>
  303. <p>On macOS Catalina (10.15) you may need to explicitly install OpenSSL
  304. via brew and inform <code>pip</code> about it so that <code>psycopg2</code> builds:</p>
  305. <pre><code class="language-sh">brew install openssl@1.1
  306. export LDFLAGS=&quot;-L/usr/local/opt/openssl/lib&quot;
  307. export CPPFLAGS=&quot;-I/usr/local/opt/openssl/include&quot;
  308. </code></pre>
  309. <h5 id="opensuse"><a class="header" href="#opensuse">OpenSUSE</a></h5>
  310. <p>Installing prerequisites on openSUSE:</p>
  311. <pre><code class="language-sh">sudo zypper in -t pattern devel_basis
  312. sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
  313. python-devel libffi-devel libopenssl-devel libjpeg62-devel
  314. </code></pre>
  315. <h5 id="openbsd"><a class="header" href="#openbsd">OpenBSD</a></h5>
  316. <p>A port of Synapse is available under <code>net/synapse</code>. The filesystem
  317. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  318. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  319. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  320. <p>To be able to build Synapse's dependency on python the <code>WRKOBJDIR</code>
  321. (cf. <code>bsd.port.mk(5)</code>) for building python, too, needs to be on a filesystem
  322. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>).</p>
  323. <p>Creating a <code>WRKOBJDIR</code> for building python under <code>/usr/local</code> (which on a
  324. default OpenBSD installation is mounted with <code>wxallowed</code>):</p>
  325. <pre><code class="language-sh">doas mkdir /usr/local/pobj_wxallowed
  326. </code></pre>
  327. <p>Assuming <code>PORTS_PRIVSEP=Yes</code> (cf. <code>bsd.port.mk(5)</code>) and <code>SUDO=doas</code> are
  328. configured in <code>/etc/mk.conf</code>:</p>
  329. <pre><code class="language-sh">doas chown _pbuild:_pbuild /usr/local/pobj_wxallowed
  330. </code></pre>
  331. <p>Setting the <code>WRKOBJDIR</code> for building python:</p>
  332. <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
  333. </code></pre>
  334. <p>Building Synapse:</p>
  335. <pre><code class="language-sh">cd /usr/ports/net/synapse
  336. make install
  337. </code></pre>
  338. <h5 id="windows"><a class="header" href="#windows">Windows</a></h5>
  339. <p>If you wish to run or develop Synapse on Windows, the Windows Subsystem For
  340. Linux provides a Linux environment on Windows 10 which is capable of using the
  341. Debian, Fedora, or source installation methods. More information about WSL can
  342. 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
  343. 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>
  344. for Windows Server.</p>
  345. <h3 id="prebuilt-packages"><a class="header" href="#prebuilt-packages">Prebuilt packages</a></h3>
  346. <p>As an alternative to installing from source, prebuilt packages are available
  347. for a number of platforms.</p>
  348. <h4 id="docker-images-and-ansible-playbooks"><a class="header" href="#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></h4>
  349. <p>There is an official synapse image available at
  350. <a href="https://hub.docker.com/r/matrixdotorg/synapse">https://hub.docker.com/r/matrixdotorg/synapse</a> which can be used with
  351. the docker-compose file available at
  352. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/docker">contrib/docker</a>.
  353. Further information on this including configuration options is available in the README
  354. on hub.docker.com.</p>
  355. <p>Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a
  356. Dockerfile to automate a synapse server in a single Docker image, at
  357. <a href="https://hub.docker.com/r/avhost/docker-matrix/tags/">https://hub.docker.com/r/avhost/docker-matrix/tags/</a></p>
  358. <p>Slavi Pantaleev has created an Ansible playbook,
  359. which installs the offical Docker image of Matrix Synapse
  360. along with many other Matrix-related services (Postgres database, Element, coturn,
  361. ma1sd, SSL support, etc.).
  362. For more details, see
  363. <a href="https://github.com/spantaleev/matrix-docker-ansible-deploy">https://github.com/spantaleev/matrix-docker-ansible-deploy</a></p>
  364. <h4 id="debianubuntu"><a class="header" href="#debianubuntu">Debian/Ubuntu</a></h4>
  365. <h5 id="matrixorg-packages"><a class="header" href="#matrixorg-packages">Matrix.org packages</a></h5>
  366. <p>Matrix.org provides Debian/Ubuntu packages of Synapse via
  367. <a href="https://packages.matrix.org/debian/">https://packages.matrix.org/debian/</a>. To install the latest release:</p>
  368. <pre><code class="language-sh">sudo apt install -y lsb-release wget apt-transport-https
  369. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  370. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main&quot; |
  371. sudo tee /etc/apt/sources.list.d/matrix-org.list
  372. sudo apt update
  373. sudo apt install matrix-synapse-py3
  374. </code></pre>
  375. <p>Packages are also published for release candidates. To enable the prerelease
  376. channel, add <code>prerelease</code> to the <code>sources.list</code> line. For example:</p>
  377. <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
  378. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main prerelease&quot; |
  379. sudo tee /etc/apt/sources.list.d/matrix-org.list
  380. sudo apt update
  381. sudo apt install matrix-synapse-py3
  382. </code></pre>
  383. <p>The fingerprint of the repository signing key (as shown by <code>gpg /usr/share/keyrings/matrix-org-archive-keyring.gpg</code>) is
  384. <code>AAF9AE843A7584B5A3E4CD2BCF45A512DE2DA058</code>.</p>
  385. <h5 id="downstream-debian-packages"><a class="header" href="#downstream-debian-packages">Downstream Debian packages</a></h5>
  386. <p>We do not recommend using the packages from the default Debian <code>buster</code>
  387. repository at this time, as they are old and suffer from known security
  388. vulnerabilities. You can install the latest version of Synapse from
  389. <a href="setup/installation.html#matrixorg-packages">our repository</a> or from <code>buster-backports</code>. Please
  390. see the <a href="https://backports.debian.org/Instructions/">Debian documentation</a>
  391. for information on how to use backports.</p>
  392. <p>If you are using Debian <code>sid</code> or testing, Synapse is available in the default
  393. repositories and it should be possible to install it simply with:</p>
  394. <pre><code class="language-sh">sudo apt install matrix-synapse
  395. </code></pre>
  396. <h5 id="downstream-ubuntu-packages"><a class="header" href="#downstream-ubuntu-packages">Downstream Ubuntu packages</a></h5>
  397. <p>We do not recommend using the packages in the default Ubuntu repository
  398. at this time, as they are old and suffer from known security vulnerabilities.
  399. The latest version of Synapse can be installed from <a href="setup/installation.html#matrixorg-packages">our repository</a>.</p>
  400. <h4 id="fedora"><a class="header" href="#fedora">Fedora</a></h4>
  401. <p>Synapse is in the Fedora repositories as <code>matrix-synapse</code>:</p>
  402. <pre><code class="language-sh">sudo dnf install matrix-synapse
  403. </code></pre>
  404. <p>Oleg Girko provides Fedora RPMs at
  405. <a href="https://obs.infoserver.lv/project/monitor/matrix-synapse">https://obs.infoserver.lv/project/monitor/matrix-synapse</a></p>
  406. <h4 id="opensuse-1"><a class="header" href="#opensuse-1">OpenSUSE</a></h4>
  407. <p>Synapse is in the OpenSUSE repositories as <code>matrix-synapse</code>:</p>
  408. <pre><code class="language-sh">sudo zypper install matrix-synapse
  409. </code></pre>
  410. <h4 id="suse-linux-enterprise-server"><a class="header" href="#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></h4>
  411. <p>Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at
  412. <a href="https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/">https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/</a></p>
  413. <h4 id="archlinux-1"><a class="header" href="#archlinux-1">ArchLinux</a></h4>
  414. <p>The quickest way to get up and running with ArchLinux is probably with the community package
  415. <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
  416. the necessary dependencies.</p>
  417. <p>pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):</p>
  418. <pre><code class="language-sh">sudo pip install --upgrade pip
  419. </code></pre>
  420. <p>If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  421. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  422. compile it under the right architecture. (This should not be needed if
  423. installing under virtualenv):</p>
  424. <pre><code class="language-sh">sudo pip uninstall py-bcrypt
  425. sudo pip install py-bcrypt
  426. </code></pre>
  427. <h4 id="void-linux"><a class="header" href="#void-linux">Void Linux</a></h4>
  428. <p>Synapse can be found in the void repositories as 'synapse':</p>
  429. <pre><code class="language-sh">xbps-install -Su
  430. xbps-install -S synapse
  431. </code></pre>
  432. <h4 id="freebsd"><a class="header" href="#freebsd">FreeBSD</a></h4>
  433. <p>Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:</p>
  434. <ul>
  435. <li>Ports: <code>cd /usr/ports/net-im/py-matrix-synapse &amp;&amp; make install clean</code></li>
  436. <li>Packages: <code>pkg install py37-matrix-synapse</code></li>
  437. </ul>
  438. <h4 id="openbsd-1"><a class="header" href="#openbsd-1">OpenBSD</a></h4>
  439. <p>As of OpenBSD 6.7 Synapse is available as a pre-compiled binary. The filesystem
  440. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  441. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  442. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  443. <p>Installing Synapse:</p>
  444. <pre><code class="language-sh">doas pkg_add synapse
  445. </code></pre>
  446. <h4 id="nixos"><a class="header" href="#nixos">NixOS</a></h4>
  447. <p>Robin Lambertz has packaged Synapse for NixOS at:
  448. <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>
  449. <h2 id="setting-up-synapse"><a class="header" href="#setting-up-synapse">Setting up Synapse</a></h2>
  450. <p>Once you have installed synapse as above, you will need to configure it.</p>
  451. <h3 id="using-postgresql"><a class="header" href="#using-postgresql">Using PostgreSQL</a></h3>
  452. <p>By default Synapse uses an <a href="https://sqlite.org/">SQLite</a> database and in doing so trades
  453. performance for convenience. Almost all installations should opt to use <a href="https://www.postgresql.org">PostgreSQL</a>
  454. instead. Advantages include:</p>
  455. <ul>
  456. <li>significant performance improvements due to the superior threading and
  457. caching model, smarter query optimiser</li>
  458. <li>allowing the DB to be run on separate hardware</li>
  459. </ul>
  460. <p>For information on how to install and use PostgreSQL in Synapse, please see
  461. <a href="setup/../postgres.html">Using Postgres</a></p>
  462. <p>SQLite is only acceptable for testing purposes. SQLite should not be used in
  463. a production server. Synapse will perform poorly when using
  464. SQLite, especially when participating in large rooms.</p>
  465. <h3 id="tls-certificates"><a class="header" href="#tls-certificates">TLS certificates</a></h3>
  466. <p>The default configuration exposes a single HTTP port on the local
  467. interface: <code>http://localhost:8008</code>. It is suitable for local testing,
  468. but for any practical use, you will need Synapse's APIs to be served
  469. over HTTPS.</p>
  470. <p>The recommended way to do so is to set up a reverse proxy on port
  471. <code>8448</code>. You can find documentation on doing so in
  472. <a href="setup/../reverse_proxy.html">the reverse proxy documentation</a>.</p>
  473. <p>Alternatively, you can configure Synapse to expose an HTTPS port. To do
  474. so, you will need to edit <code>homeserver.yaml</code>, as follows:</p>
  475. <ul>
  476. <li>First, under the <code>listeners</code> section, uncomment the configuration for the
  477. TLS-enabled listener. (Remove the hash sign (<code>#</code>) at the start of
  478. each line). The relevant lines are like this:</li>
  479. </ul>
  480. <pre><code class="language-yaml"> - port: 8448
  481. type: http
  482. tls: true
  483. resources:
  484. - names: [client, federation]
  485. </code></pre>
  486. <ul>
  487. <li>
  488. <p>You will also need to uncomment the <code>tls_certificate_path</code> and
  489. <code>tls_private_key_path</code> lines under the <code>TLS</code> section. You will need to manage
  490. provisioning of these certificates yourself.</p>
  491. <p>If you are using your own certificate, be sure to use a <code>.pem</code> file that
  492. includes the full certificate chain including any intermediate certificates
  493. (for instance, if using certbot, use <code>fullchain.pem</code> as your certificate, not
  494. <code>cert.pem</code>).</p>
  495. </li>
  496. </ul>
  497. <p>For a more detailed guide to configuring your server for federation, see
  498. <a href="setup/../federate.html">Federation</a>.</p>
  499. <h3 id="client-well-known-uri"><a class="header" href="#client-well-known-uri">Client Well-Known URI</a></h3>
  500. <p>Setting up the client Well-Known URI is optional but if you set it up, it will
  501. allow users to enter their full username (e.g. <code>@user:&lt;server_name&gt;</code>) into clients
  502. which support well-known lookup to automatically configure the homeserver and
  503. identity server URLs. This is useful so that users don't have to memorize or think
  504. about the actual homeserver URL you are using.</p>
  505. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/client</code> should return JSON in
  506. the following format.</p>
  507. <pre><code class="language-json">{
  508. &quot;m.homeserver&quot;: {
  509. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  510. }
  511. }
  512. </code></pre>
  513. <p>It can optionally contain identity server information as well.</p>
  514. <pre><code class="language-json">{
  515. &quot;m.homeserver&quot;: {
  516. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  517. },
  518. &quot;m.identity_server&quot;: {
  519. &quot;base_url&quot;: &quot;https://&lt;identity.example.com&gt;&quot;
  520. }
  521. }
  522. </code></pre>
  523. <p>To work in browser based clients, the file must be served with the appropriate
  524. Cross-Origin Resource Sharing (CORS) headers. A recommended value would be
  525. <code>Access-Control-Allow-Origin: *</code> which would allow all browser based clients to
  526. view it.</p>
  527. <p>In nginx this would be something like:</p>
  528. <pre><code class="language-nginx">location /.well-known/matrix/client {
  529. return 200 '{&quot;m.homeserver&quot;: {&quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;}}';
  530. default_type application/json;
  531. add_header Access-Control-Allow-Origin *;
  532. }
  533. </code></pre>
  534. <p>You should also ensure the <code>public_baseurl</code> option in <code>homeserver.yaml</code> is set
  535. correctly. <code>public_baseurl</code> should be set to the URL that clients will use to
  536. connect to your server. This is the same URL you put for the <code>m.homeserver</code>
  537. <code>base_url</code> above.</p>
  538. <pre><code class="language-yaml">public_baseurl: &quot;https://&lt;matrix.example.com&gt;&quot;
  539. </code></pre>
  540. <h3 id="email"><a class="header" href="#email">Email</a></h3>
  541. <p>It is desirable for Synapse to have the capability to send email. This allows
  542. Synapse to send password reset emails, send verifications when an email address
  543. is added to a user's account, and send email notifications to users when they
  544. receive new messages.</p>
  545. <p>To configure an SMTP server for Synapse, modify the configuration section
  546. headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>, <code>smtp_port</code>
  547. and <code>notif_from</code> fields filled out. You may also need to set <code>smtp_user</code>,
  548. <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  549. <p>If email is not configured, password reset, registration and notifications via
  550. email will be disabled.</p>
  551. <h3 id="registering-a-user"><a class="header" href="#registering-a-user">Registering a user</a></h3>
  552. <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>
  553. <p>Alternatively, you can do so from the command line. This can be done as follows:</p>
  554. <ol>
  555. <li>If synapse was installed via pip, activate the virtualenv as follows (if Synapse was
  556. installed via a prebuilt package, <code>register_new_matrix_user</code> should already be
  557. on the search path):
  558. <pre><code class="language-sh">cd ~/synapse
  559. source env/bin/activate
  560. synctl start # if not already running
  561. </code></pre>
  562. </li>
  563. <li>Run the following command:
  564. <pre><code class="language-sh">register_new_matrix_user -c homeserver.yaml http://localhost:8008
  565. </code></pre>
  566. </li>
  567. </ol>
  568. <p>This will prompt you to add details for the new user, and will then connect to
  569. the running Synapse to create the new user. For example:</p>
  570. <pre><code>New user localpart: erikj
  571. Password:
  572. Confirm password:
  573. Make admin [no]:
  574. Success!
  575. </code></pre>
  576. <p>This process uses a setting <code>registration_shared_secret</code> in
  577. <code>homeserver.yaml</code>, which is shared between Synapse itself and the
  578. <code>register_new_matrix_user</code> script. It doesn't matter what it is (a random
  579. value is generated by <code>--generate-config</code>), but it should be kept secret, as
  580. anyone with knowledge of it can register users, including admin accounts,
  581. on your server even if <code>enable_registration</code> is <code>false</code>.</p>
  582. <h3 id="setting-up-a-turn-server"><a class="header" href="#setting-up-a-turn-server">Setting up a TURN server</a></h3>
  583. <p>For reliable VoIP calls to be routed via this homeserver, you MUST configure
  584. a TURN server. See <a href="setup/../turn-howto.html">TURN setup</a> for details.</p>
  585. <h3 id="url-previews"><a class="header" href="#url-previews">URL previews</a></h3>
  586. <p>Synapse includes support for previewing URLs, which is disabled by default. To
  587. turn it on you must enable the <code>url_preview_enabled: True</code> config parameter
  588. and explicitly specify the IP ranges that Synapse is not allowed to spider for
  589. previewing in the <code>url_preview_ip_range_blacklist</code> configuration parameter.
  590. This is critical from a security perspective to stop arbitrary Matrix users
  591. spidering 'internal' URLs on your network. At the very least we recommend that
  592. your loopback and RFC1918 IP addresses are blacklisted.</p>
  593. <p>This also requires the optional <code>lxml</code> python dependency to be installed. This
  594. in turn requires the <code>libxml2</code> library to be available - on Debian/Ubuntu this
  595. means <code>apt-get install libxml2-dev</code>, or equivalent for your OS.</p>
  596. <h3 id="troubleshooting-installation"><a class="header" href="#troubleshooting-installation">Troubleshooting Installation</a></h3>
  597. <p><code>pip</code> seems to leak <em>lots</em> of memory during installation. For instance, a Linux
  598. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  599. happens, you will have to individually install the dependencies which are
  600. failing, e.g.:</p>
  601. <pre><code class="language-sh">pip install twisted
  602. </code></pre>
  603. <p>If you have any other problems, feel free to ask in
  604. <a href="https://matrix.to/#/#synapse:matrix.org">#synapse:matrix.org</a>.</p>
  605. <div style="break-before: page; page-break-before: always;"></div><h1 id="using-postgres"><a class="header" href="#using-postgres">Using Postgres</a></h1>
  606. <p>Synapse supports PostgreSQL versions 9.6 or later.</p>
  607. <h2 id="install-postgres-client-libraries"><a class="header" href="#install-postgres-client-libraries">Install postgres client libraries</a></h2>
  608. <p>Synapse will require the python postgres client library in order to
  609. connect to a postgres database.</p>
  610. <ul>
  611. <li>
  612. <p>If you are using the <a href="setup/installation.html#matrixorg-packages">matrix.org debian/ubuntu
  613. packages</a>, the necessary python
  614. library will already be installed, but you will need to ensure the
  615. low-level postgres library is installed, which you can do with
  616. <code>apt install libpq5</code>.</p>
  617. </li>
  618. <li>
  619. <p>For other pre-built packages, please consult the documentation from
  620. the relevant package.</p>
  621. </li>
  622. <li>
  623. <p>If you installed synapse <a href="setup/installation.html#installing-from-source">in a
  624. virtualenv</a>, you can install
  625. the library with:</p>
  626. <pre><code>~/synapse/env/bin/pip install &quot;matrix-synapse[postgres]&quot;
  627. </code></pre>
  628. <p>(substituting the path to your virtualenv for <code>~/synapse/env</code>, if
  629. you used a different path). You will require the postgres
  630. development files. These are in the <code>libpq-dev</code> package on
  631. Debian-derived distributions.</p>
  632. </li>
  633. </ul>
  634. <h2 id="set-up-database"><a class="header" href="#set-up-database">Set up database</a></h2>
  635. <p>Assuming your PostgreSQL database user is called <code>postgres</code>, first authenticate as the database user with:</p>
  636. <pre><code>su - postgres
  637. # Or, if your system uses sudo to get administrative rights
  638. sudo -u postgres bash
  639. </code></pre>
  640. <p>Then, create a postgres user and a database with:</p>
  641. <pre><code># this will prompt for a password for the new user
  642. createuser --pwprompt synapse_user
  643. createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse
  644. </code></pre>
  645. <p>The above will create a user called <code>synapse_user</code>, and a database called
  646. <code>synapse</code>.</p>
  647. <p>Note that the PostgreSQL database <em>must</em> have the correct encoding set
  648. (as shown above), otherwise it will not be able to store UTF8 strings.</p>
  649. <p>You may need to enable password authentication so <code>synapse_user</code> can
  650. connect to the database. See
  651. <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>
  652. <h2 id="synapse-config"><a class="header" href="#synapse-config">Synapse config</a></h2>
  653. <p>When you are ready to start using PostgreSQL, edit the <code>database</code>
  654. section in your config file to match the following lines:</p>
  655. <pre><code class="language-yaml">database:
  656. name: psycopg2
  657. args:
  658. user: &lt;user&gt;
  659. password: &lt;pass&gt;
  660. database: &lt;db&gt;
  661. host: &lt;host&gt;
  662. cp_min: 5
  663. cp_max: 10
  664. </code></pre>
  665. <p>All key, values in <code>args</code> are passed to the <code>psycopg2.connect(..)</code>
  666. function, except keys beginning with <code>cp_</code>, which are consumed by the
  667. twisted adbapi connection pool. See the <a href="https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS">libpq
  668. documentation</a>
  669. for a list of options which can be passed.</p>
  670. <p>You should consider tuning the <code>args.keepalives_*</code> options if there is any danger of
  671. the connection between your homeserver and database dropping, otherwise Synapse
  672. may block for an extended period while it waits for a response from the
  673. database server. Example values might be:</p>
  674. <pre><code class="language-yaml">database:
  675. args:
  676. # ... as above
  677. # seconds of inactivity after which TCP should send a keepalive message to the server
  678. keepalives_idle: 10
  679. # the number of seconds after which a TCP keepalive message that is not
  680. # acknowledged by the server should be retransmitted
  681. keepalives_interval: 10
  682. # the number of TCP keepalives that can be lost before the client's connection
  683. # to the server is considered dead
  684. keepalives_count: 3
  685. </code></pre>
  686. <h2 id="tuning-postgres"><a class="header" href="#tuning-postgres">Tuning Postgres</a></h2>
  687. <p>The default settings should be fine for most deployments. For larger
  688. scale deployments tuning some of the settings is recommended, details of
  689. which can be found at
  690. <a href="https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server">https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server</a>.</p>
  691. <p>In particular, we've found tuning the following values helpful for
  692. performance:</p>
  693. <ul>
  694. <li><code>shared_buffers</code></li>
  695. <li><code>effective_cache_size</code></li>
  696. <li><code>work_mem</code></li>
  697. <li><code>maintenance_work_mem</code></li>
  698. <li><code>autovacuum_work_mem</code></li>
  699. </ul>
  700. <p>Note that the appropriate values for those fields depend on the amount
  701. of free memory the database host has available.</p>
  702. <h2 id="porting-from-sqlite"><a class="header" href="#porting-from-sqlite">Porting from SQLite</a></h2>
  703. <h3 id="overview"><a class="header" href="#overview">Overview</a></h3>
  704. <p>The script <code>synapse_port_db</code> allows porting an existing synapse server
  705. backed by SQLite to using PostgreSQL. This is done in as a two phase
  706. process:</p>
  707. <ol>
  708. <li>Copy the existing SQLite database to a separate location and run
  709. the port script against that offline database.</li>
  710. <li>Shut down the server. Rerun the port script to port any data that
  711. has come in since taking the first snapshot. Restart server against
  712. the PostgreSQL database.</li>
  713. </ol>
  714. <p>The port script is designed to be run repeatedly against newer snapshots
  715. of the SQLite database file. This makes it safe to repeat step 1 if
  716. there was a delay between taking the previous snapshot and being ready
  717. to do step 2.</p>
  718. <p>It is safe to at any time kill the port script and restart it.</p>
  719. <p>Note that the database may take up significantly more (25% - 100% more)
  720. space on disk after porting to Postgres.</p>
  721. <h3 id="using-the-port-script"><a class="header" href="#using-the-port-script">Using the port script</a></h3>
  722. <p>Firstly, shut down the currently running synapse server and copy its
  723. database file (typically <code>homeserver.db</code>) to another location. Once the
  724. copy is complete, restart synapse. For instance:</p>
  725. <pre><code>./synctl stop
  726. cp homeserver.db homeserver.db.snapshot
  727. ./synctl start
  728. </code></pre>
  729. <p>Copy the old config file into a new config file:</p>
  730. <pre><code>cp homeserver.yaml homeserver-postgres.yaml
  731. </code></pre>
  732. <p>Edit the database section as described in the section <em>Synapse config</em>
  733. above and with the SQLite snapshot located at <code>homeserver.db.snapshot</code>
  734. simply run:</p>
  735. <pre><code>synapse_port_db --sqlite-database homeserver.db.snapshot \
  736. --postgres-config homeserver-postgres.yaml
  737. </code></pre>
  738. <p>The flag <code>--curses</code> displays a coloured curses progress UI.</p>
  739. <p>If the script took a long time to complete, or time has otherwise passed
  740. since the original snapshot was taken, repeat the previous steps with a
  741. newer snapshot.</p>
  742. <p>To complete the conversion shut down the synapse server and run the port
  743. script one last time, e.g. if the SQLite database is at <code>homeserver.db</code>
  744. run:</p>
  745. <pre><code>synapse_port_db --sqlite-database homeserver.db \
  746. --postgres-config homeserver-postgres.yaml
  747. </code></pre>
  748. <p>Once that has completed, change the synapse config to point at the
  749. PostgreSQL database configuration file <code>homeserver-postgres.yaml</code>:</p>
  750. <pre><code>./synctl stop
  751. mv homeserver.yaml homeserver-old-sqlite.yaml
  752. mv homeserver-postgres.yaml homeserver.yaml
  753. ./synctl start
  754. </code></pre>
  755. <p>Synapse should now be running against PostgreSQL.</p>
  756. <h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
  757. <h3 id="alternative-auth-methods"><a class="header" href="#alternative-auth-methods">Alternative auth methods</a></h3>
  758. <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
  759. <code>ident</code>:</p>
  760. <ul>
  761. <li>
  762. <p>If the <code>synapse_user</code> user has a password, add the password to the <code>database:</code>
  763. section of <code>homeserver.yaml</code>. Then add the following to <code>pg_hba.conf</code>:</p>
  764. <pre><code>host synapse synapse_user ::1/128 md5 # or `scram-sha-256` instead of `md5` if you use that
  765. </code></pre>
  766. </li>
  767. <li>
  768. <p>If the <code>synapse_user</code> user does not have a password, then a password doesn't
  769. have to be added to <code>homeserver.yaml</code>. But the following does need to be added
  770. to <code>pg_hba.conf</code>:</p>
  771. <pre><code>host synapse synapse_user ::1/128 trust
  772. </code></pre>
  773. </li>
  774. </ul>
  775. <p>Note that line order matters in <code>pg_hba.conf</code>, so make sure that if you do add a
  776. new line, it is inserted before:</p>
  777. <pre><code>host all all ::1/128 ident
  778. </code></pre>
  779. <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>
  780. <p>Synapse will refuse to set up a new database if it has the wrong values of
  781. <code>COLLATE</code> and <code>CTYPE</code> set, and will log warnings on existing databases. Using
  782. different locales can cause issues if the locale library is updated from
  783. underneath the database, or if a different version of the locale is used on any
  784. replicas.</p>
  785. <p>The safest way to fix the issue is to dump the database and recreate it with
  786. the correct locale parameter (as shown above). It is also possible to change the
  787. parameters on a live database and run a <code>REINDEX</code> on the entire database,
  788. however extreme care must be taken to avoid database corruption.</p>
  789. <p>Note that the above may fail with an error about duplicate rows if corruption
  790. has already occurred, and such duplicate rows will need to be manually removed.</p>
  791. <h3 id="fixing-inconsistent-sequences-error"><a class="header" href="#fixing-inconsistent-sequences-error">Fixing inconsistent sequences error</a></h3>
  792. <p>Synapse uses Postgres sequences to generate IDs for various tables. A sequence
  793. and associated table can get out of sync if, for example, Synapse has been
  794. downgraded and then upgraded again.</p>
  795. <p>To fix the issue shut down Synapse (including any and all workers) and run the
  796. SQL command included in the error message. Once done Synapse should start
  797. successfully.</p>
  798. <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>
  799. <p>It is recommended to put a reverse proxy such as
  800. <a href="https://nginx.org/en/docs/http/ngx_http_proxy_module.html">nginx</a>,
  801. <a href="https://httpd.apache.org/docs/current/mod/mod_proxy_http.html">Apache</a>,
  802. <a href="https://caddyserver.com/docs/quick-starts/reverse-proxy">Caddy</a>,
  803. <a href="https://www.haproxy.org/">HAProxy</a> or
  804. <a href="https://man.openbsd.org/relayd.8">relayd</a> in front of Synapse. One advantage
  805. of doing so is that it means that you can expose the default https port
  806. (443) to Matrix clients without needing to run Synapse with root
  807. privileges.</p>
  808. <p>You should configure your reverse proxy to forward requests to <code>/_matrix</code> or
  809. <code>/_synapse/client</code> to Synapse, and have it set the <code>X-Forwarded-For</code> and
  810. <code>X-Forwarded-Proto</code> request headers.</p>
  811. <p>You should remember that Matrix clients and other Matrix servers do not
  812. necessarily need to connect to your server via the same server name or
  813. port. Indeed, clients will use port 443 by default, whereas servers default to
  814. port 8448. Where these are different, we refer to the 'client port' and the
  815. 'federation port'. See <a href="https://matrix.org/docs/spec/server_server/latest#resolving-server-names">the Matrix
  816. specification</a>
  817. for more details of the algorithm used for federation connections, and
  818. <a href="delegate.html">Delegation</a> for instructions on setting up delegation.</p>
  819. <p><strong>NOTE</strong>: Your reverse proxy must not <code>canonicalise</code> or <code>normalise</code>
  820. the requested URI in any way (for example, by decoding <code>%xx</code> escapes).
  821. Beware that Apache <em>will</em> canonicalise URIs unless you specify
  822. <code>nocanon</code>.</p>
  823. <p>Let's assume that we expect clients to connect to our server at
  824. <code>https://matrix.example.com</code>, and other servers to connect at
  825. <code>https://example.com:8448</code>. The following sections detail the configuration of
  826. the reverse proxy and the homeserver.</p>
  827. <h2 id="reverse-proxy-configuration-examples"><a class="header" href="#reverse-proxy-configuration-examples">Reverse-proxy configuration examples</a></h2>
  828. <p><strong>NOTE</strong>: You only need one of these.</p>
  829. <h3 id="nginx"><a class="header" href="#nginx">nginx</a></h3>
  830. <pre><code>server {
  831. listen 443 ssl http2;
  832. listen [::]:443 ssl http2;
  833. # For the federation port
  834. listen 8448 ssl http2 default_server;
  835. listen [::]:8448 ssl http2 default_server;
  836. server_name matrix.example.com;
  837. location ~* ^(\/_matrix|\/_synapse\/client) {
  838. proxy_pass http://localhost:8008;
  839. proxy_set_header X-Forwarded-For $remote_addr;
  840. proxy_set_header X-Forwarded-Proto $scheme;
  841. proxy_set_header Host $host;
  842. # Nginx by default only allows file uploads up to 1M in size
  843. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  844. client_max_body_size 50M;
  845. }
  846. }
  847. </code></pre>
  848. <p><strong>NOTE</strong>: Do not add a path after the port in <code>proxy_pass</code>, otherwise nginx will
  849. canonicalise/normalise the URI.</p>
  850. <h3 id="caddy-1"><a class="header" href="#caddy-1">Caddy 1</a></h3>
  851. <pre><code>matrix.example.com {
  852. proxy /_matrix http://localhost:8008 {
  853. transparent
  854. }
  855. proxy /_synapse/client http://localhost:8008 {
  856. transparent
  857. }
  858. }
  859. example.com:8448 {
  860. proxy / http://localhost:8008 {
  861. transparent
  862. }
  863. }
  864. </code></pre>
  865. <h3 id="caddy-2"><a class="header" href="#caddy-2">Caddy 2</a></h3>
  866. <pre><code>matrix.example.com {
  867. reverse_proxy /_matrix/* http://localhost:8008
  868. reverse_proxy /_synapse/client/* http://localhost:8008
  869. }
  870. example.com:8448 {
  871. reverse_proxy http://localhost:8008
  872. }
  873. </code></pre>
  874. <p><a href="delegate.html">Delegation</a> example:</p>
  875. <pre><code>(matrix-well-known-header) {
  876. # Headers
  877. header Access-Control-Allow-Origin &quot;*&quot;
  878. header Access-Control-Allow-Methods &quot;GET, POST, PUT, DELETE, OPTIONS&quot;
  879. header Access-Control-Allow-Headers &quot;Origin, X-Requested-With, Content-Type, Accept, Authorization&quot;
  880. header Content-Type &quot;application/json&quot;
  881. }
  882. example.com {
  883. handle /.well-known/matrix/server {
  884. import matrix-well-known-header
  885. respond `{&quot;m.server&quot;:&quot;matrix.example.com:443&quot;}`
  886. }
  887. handle /.well-known/matrix/client {
  888. import matrix-well-known-header
  889. 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;}}`
  890. }
  891. }
  892. matrix.example.com {
  893. reverse_proxy /_matrix/* http://localhost:8008
  894. reverse_proxy /_synapse/client/* http://localhost:8008
  895. }
  896. </code></pre>
  897. <h3 id="apache"><a class="header" href="#apache">Apache</a></h3>
  898. <pre><code>&lt;VirtualHost *:443&gt;
  899. SSLEngine on
  900. ServerName matrix.example.com
  901. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  902. AllowEncodedSlashes NoDecode
  903. ProxyPreserveHost on
  904. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  905. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  906. ProxyPass /_synapse/client http://127.0.0.1:8008/_synapse/client nocanon
  907. ProxyPassReverse /_synapse/client http://127.0.0.1:8008/_synapse/client
  908. &lt;/VirtualHost&gt;
  909. &lt;VirtualHost *:8448&gt;
  910. SSLEngine on
  911. ServerName example.com
  912. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  913. AllowEncodedSlashes NoDecode
  914. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  915. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  916. &lt;/VirtualHost&gt;
  917. </code></pre>
  918. <p><strong>NOTE</strong>: ensure the <code>nocanon</code> options are included.</p>
  919. <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>
  920. <pre><code>&lt;IfModule security2_module&gt;
  921. SecRuleEngine off
  922. &lt;/IfModule&gt;
  923. </code></pre>
  924. <p><strong>NOTE 3</strong>: Missing <code>ProxyPreserveHost on</code> can lead to a redirect loop.</p>
  925. <h3 id="haproxy"><a class="header" href="#haproxy">HAProxy</a></h3>
  926. <pre><code>frontend https
  927. bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
  928. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  929. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  930. http-request set-header X-Forwarded-For %[src]
  931. # Matrix client traffic
  932. acl matrix-host hdr(host) -i matrix.example.com
  933. acl matrix-path path_beg /_matrix
  934. acl matrix-path path_beg /_synapse/client
  935. use_backend matrix if matrix-host matrix-path
  936. frontend matrix-federation
  937. bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
  938. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  939. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  940. http-request set-header X-Forwarded-For %[src]
  941. default_backend matrix
  942. backend matrix
  943. server matrix 127.0.0.1:8008
  944. </code></pre>
  945. <h3 id="relayd"><a class="header" href="#relayd">Relayd</a></h3>
  946. <pre><code>table &lt;webserver&gt; { 127.0.0.1 }
  947. table &lt;matrixserver&gt; { 127.0.0.1 }
  948. http protocol &quot;https&quot; {
  949. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  950. tls keypair &quot;example.com&quot;
  951. match header set &quot;X-Forwarded-For&quot; value &quot;$REMOTE_ADDR&quot;
  952. match header set &quot;X-Forwarded-Proto&quot; value &quot;https&quot;
  953. # set CORS header for .well-known/matrix/server, .well-known/matrix/client
  954. # httpd does not support setting headers, so do it here
  955. match request path &quot;/.well-known/matrix/*&quot; tag &quot;matrix-cors&quot;
  956. match response tagged &quot;matrix-cors&quot; header set &quot;Access-Control-Allow-Origin&quot; value &quot;*&quot;
  957. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  958. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  959. # pass on non-matrix traffic to webserver
  960. pass forward to &lt;webserver&gt;
  961. }
  962. relay &quot;https_traffic&quot; {
  963. listen on egress port 443 tls
  964. protocol &quot;https&quot;
  965. forward to &lt;matrixserver&gt; port 8008 check tcp
  966. forward to &lt;webserver&gt; port 8080 check tcp
  967. }
  968. http protocol &quot;matrix&quot; {
  969. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  970. tls keypair &quot;example.com&quot;
  971. block
  972. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  973. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  974. }
  975. relay &quot;matrix_federation&quot; {
  976. listen on egress port 8448 tls
  977. protocol &quot;matrix&quot;
  978. forward to &lt;matrixserver&gt; port 8008 check tcp
  979. }
  980. </code></pre>
  981. <h2 id="homeserver-configuration"><a class="header" href="#homeserver-configuration">Homeserver Configuration</a></h2>
  982. <p>You will also want to set <code>bind_addresses: ['127.0.0.1']</code> and
  983. <code>x_forwarded: true</code> for port 8008 in <code>homeserver.yaml</code> to ensure that
  984. client IP addresses are recorded correctly.</p>
  985. <p>Having done so, you can then use <code>https://matrix.example.com</code> (instead
  986. of <code>https://matrix.example.com:8448</code>) as the &quot;Custom server&quot; when
  987. connecting to Synapse from a client.</p>
  988. <h2 id="health-check-endpoint"><a class="header" href="#health-check-endpoint">Health check endpoint</a></h2>
  989. <p>Synapse exposes a health check endpoint for use by reverse proxies.
  990. Each configured HTTP listener has a <code>/health</code> endpoint which always returns
  991. 200 OK (and doesn't get logged).</p>
  992. <h2 id="synapse-administration-endpoints"><a class="header" href="#synapse-administration-endpoints">Synapse administration endpoints</a></h2>
  993. <p>Endpoints for administering your Synapse instance are placed under
  994. <code>/_synapse/admin</code>. These require authentication through an access token of an
  995. admin user. However as access to these endpoints grants the caller a lot of power,
  996. we do not recommend exposing them to the public internet without good reason.</p>
  997. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-1"><a class="header" href="#overview-1">Overview</a></h1>
  998. <p>This document explains how to enable VoIP relaying on your Home Server with
  999. TURN.</p>
  1000. <p>The synapse Matrix Home Server supports integration with TURN server via the
  1001. <a href="https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00">TURN server REST API</a>. This
  1002. allows the Home Server to generate credentials that are valid for use on the
  1003. TURN server through the use of a secret shared between the Home Server and the
  1004. TURN server.</p>
  1005. <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>
  1006. <h2 id="requirements"><a class="header" href="#requirements">Requirements</a></h2>
  1007. <p>For TURN relaying with <code>coturn</code> to work, it must be hosted on a server/endpoint with a public IP.</p>
  1008. <p>Hosting TURN behind a NAT (even with appropriate port forwarding) is known to cause issues
  1009. and to often not work.</p>
  1010. <h2 id="coturn-setup"><a class="header" href="#coturn-setup"><code>coturn</code> setup</a></h2>
  1011. <h3 id="initial-installation"><a class="header" href="#initial-installation">Initial installation</a></h3>
  1012. <p>The TURN daemon <code>coturn</code> is available from a variety of sources such as native package managers, or installation from source.</p>
  1013. <h4 id="debian-installation"><a class="header" href="#debian-installation">Debian installation</a></h4>
  1014. <p>Just install the debian package:</p>
  1015. <pre><code class="language-sh">apt install coturn
  1016. </code></pre>
  1017. <p>This will install and start a systemd service called <code>coturn</code>.</p>
  1018. <h4 id="source-installation"><a class="header" href="#source-installation">Source installation</a></h4>
  1019. <ol>
  1020. <li>
  1021. <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>
  1022. </li>
  1023. <li>
  1024. <p>Configure it:</p>
  1025. <pre><code>./configure
  1026. </code></pre>
  1027. <p>You may need to install <code>libevent2</code>: if so, you should do so in
  1028. the way recommended by your operating system. You can ignore
  1029. warnings about lack of database support: a database is unnecessary
  1030. for this purpose.</p>
  1031. </li>
  1032. <li>
  1033. <p>Build and install it:</p>
  1034. <pre><code>make
  1035. make install
  1036. </code></pre>
  1037. </li>
  1038. </ol>
  1039. <h3 id="configuration"><a class="header" href="#configuration">Configuration</a></h3>
  1040. <ol>
  1041. <li>
  1042. <p>Create or edit the config file in <code>/etc/turnserver.conf</code>. The relevant
  1043. lines, with example values, are:</p>
  1044. <pre><code>use-auth-secret
  1045. static-auth-secret=[your secret key here]
  1046. realm=turn.myserver.org
  1047. </code></pre>
  1048. <p>See <code>turnserver.conf</code> for explanations of the options. One way to generate
  1049. the <code>static-auth-secret</code> is with <code>pwgen</code>:</p>
  1050. <pre><code>pwgen -s 64 1
  1051. </code></pre>
  1052. <p>A <code>realm</code> must be specified, but its value is somewhat arbitrary. (It is
  1053. sent to clients as part of the authentication flow.) It is conventional to
  1054. set it to be your server name.</p>
  1055. </li>
  1056. <li>
  1057. <p>You will most likely want to configure coturn to write logs somewhere. The
  1058. easiest way is normally to send them to the syslog:</p>
  1059. <pre><code>syslog
  1060. </code></pre>
  1061. <p>(in which case, the logs will be available via <code>journalctl -u coturn</code> on a
  1062. systemd system). Alternatively, coturn can be configured to write to a
  1063. logfile - check the example config file supplied with coturn.</p>
  1064. </li>
  1065. <li>
  1066. <p>Consider your security settings. TURN lets users request a relay which will
  1067. connect to arbitrary IP addresses and ports. The following configuration is
  1068. suggested as a minimum starting point:</p>
  1069. <pre><code># VoIP traffic is all UDP. There is no reason to let users connect to arbitrary TCP endpoints via the relay.
  1070. no-tcp-relay
  1071. # don't let the relay ever try to connect to private IP address ranges within your network (if any)
  1072. # given the turn server is likely behind your firewall, remember to include any privileged public IPs too.
  1073. denied-peer-ip=10.0.0.0-10.255.255.255
  1074. denied-peer-ip=192.168.0.0-192.168.255.255
  1075. denied-peer-ip=172.16.0.0-172.31.255.255
  1076. # special case the turn server itself so that client-&gt;TURN-&gt;TURN-&gt;client flows work
  1077. allowed-peer-ip=10.0.0.1
  1078. # consider whether you want to limit the quota of relayed streams per user (or total) to avoid risk of DoS.
  1079. user-quota=12 # 4 streams per video call, so 12 streams = 3 simultaneous relayed calls per user.
  1080. total-quota=1200
  1081. </code></pre>
  1082. </li>
  1083. <li>
  1084. <p>Also consider supporting TLS/DTLS. To do this, add the following settings
  1085. to <code>turnserver.conf</code>:</p>
  1086. <pre><code># TLS certificates, including intermediate certs.
  1087. # For Let's Encrypt certificates, use `fullchain.pem` here.
  1088. cert=/path/to/fullchain.pem
  1089. # TLS private key file
  1090. pkey=/path/to/privkey.pem
  1091. </code></pre>
  1092. <p>In this case, replace the <code>turn:</code> schemes in the <code>turn_uri</code> settings below
  1093. with <code>turns:</code>.</p>
  1094. <p>We recommend that you only try to set up TLS/DTLS once you have set up a
  1095. basic installation and got it working.</p>
  1096. </li>
  1097. <li>
  1098. <p>Ensure your firewall allows traffic into the TURN server on the ports
  1099. you've configured it to listen on (By default: 3478 and 5349 for TURN
  1100. traffic (remember to allow both TCP and UDP traffic), and ports 49152-65535
  1101. for the UDP relay.)</p>
  1102. </li>
  1103. <li>
  1104. <p>We do not recommend running a TURN server behind NAT, and are not aware of
  1105. anyone doing so successfully.</p>
  1106. <p>If you want to try it anyway, you will at least need to tell coturn its
  1107. external IP address:</p>
  1108. <pre><code>external-ip=192.88.99.1
  1109. </code></pre>
  1110. <p>... and your NAT gateway must forward all of the relayed ports directly
  1111. (eg, port 56789 on the external IP must be always be forwarded to port
  1112. 56789 on the internal IP).</p>
  1113. <p>If you get this working, let us know!</p>
  1114. </li>
  1115. <li>
  1116. <p>(Re)start the turn server:</p>
  1117. <ul>
  1118. <li>
  1119. <p>If you used the Debian package (or have set up a systemd unit yourself):</p>
  1120. <pre><code class="language-sh">systemctl restart coturn
  1121. </code></pre>
  1122. </li>
  1123. <li>
  1124. <p>If you installed from source:</p>
  1125. <pre><code class="language-sh">bin/turnserver -o
  1126. </code></pre>
  1127. </li>
  1128. </ul>
  1129. </li>
  1130. </ol>
  1131. <h2 id="synapse-setup"><a class="header" href="#synapse-setup">Synapse setup</a></h2>
  1132. <p>Your home server configuration file needs the following extra keys:</p>
  1133. <ol>
  1134. <li>&quot;<code>turn_uris</code>&quot;: This needs to be a yaml list of public-facing URIs
  1135. for your TURN server to be given out to your clients. Add separate
  1136. entries for each transport your TURN server supports.</li>
  1137. <li>&quot;<code>turn_shared_secret</code>&quot;: This is the secret shared between your
  1138. Home server and your TURN server, so you should set it to the same
  1139. string you used in turnserver.conf.</li>
  1140. <li>&quot;<code>turn_user_lifetime</code>&quot;: This is the amount of time credentials
  1141. generated by your Home Server are valid for (in milliseconds).
  1142. Shorter times offer less potential for abuse at the expense of
  1143. increased traffic between web clients and your home server to
  1144. refresh credentials. The TURN REST API specification recommends
  1145. one day (86400000).</li>
  1146. <li>&quot;<code>turn_allow_guests</code>&quot;: Whether to allow guest users to use the
  1147. TURN server. This is enabled by default, as otherwise VoIP will
  1148. not work reliably for guests. However, it does introduce a
  1149. security risk as it lets guests connect to arbitrary endpoints
  1150. without having gone through a CAPTCHA or similar to register a
  1151. real account.</li>
  1152. </ol>
  1153. <p>As an example, here is the relevant section of the config file for <code>matrix.org</code>. The
  1154. <code>turn_uris</code> are appropriate for TURN servers listening on the default ports, with no TLS.</p>
  1155. <pre><code>turn_uris: [ &quot;turn:turn.matrix.org?transport=udp&quot;, &quot;turn:turn.matrix.org?transport=tcp&quot; ]
  1156. turn_shared_secret: &quot;n0t4ctuAllymatr1Xd0TorgSshar3d5ecret4obvIousreAsons&quot;
  1157. turn_user_lifetime: 86400000
  1158. turn_allow_guests: True
  1159. </code></pre>
  1160. <p>After updating the homeserver configuration, you must restart synapse:</p>
  1161. <ul>
  1162. <li>If you use synctl:
  1163. <pre><code class="language-sh">cd /where/you/run/synapse
  1164. ./synctl restart
  1165. </code></pre>
  1166. </li>
  1167. <li>If you use systemd:
  1168. <pre><code>systemctl restart matrix-synapse.service
  1169. </code></pre>
  1170. </li>
  1171. </ul>
  1172. <p>... and then reload any clients (or wait an hour for them to refresh their
  1173. settings).</p>
  1174. <h2 id="troubleshooting-1"><a class="header" href="#troubleshooting-1">Troubleshooting</a></h2>
  1175. <p>The normal symptoms of a misconfigured TURN server are that calls between
  1176. devices on different networks ring, but get stuck at &quot;call
  1177. connecting&quot;. Unfortunately, troubleshooting this can be tricky.</p>
  1178. <p>Here are a few things to try:</p>
  1179. <ul>
  1180. <li>
  1181. <p>Check that your TURN server is not behind NAT. As above, we're not aware of
  1182. anyone who has successfully set this up.</p>
  1183. </li>
  1184. <li>
  1185. <p>Check that you have opened your firewall to allow TCP and UDP traffic to the
  1186. TURN ports (normally 3478 and 5479).</p>
  1187. </li>
  1188. <li>
  1189. <p>Check that you have opened your firewall to allow UDP traffic to the UDP
  1190. relay ports (49152-65535 by default).</p>
  1191. </li>
  1192. <li>
  1193. <p>Some WebRTC implementations (notably, that of Google Chrome) appear to get
  1194. confused by TURN servers which are reachable over IPv6 (this appears to be
  1195. an unexpected side-effect of its handling of multiple IP addresses as
  1196. defined by
  1197. <a href="https://tools.ietf.org/html/draft-ietf-rtcweb-ip-handling-12"><code>draft-ietf-rtcweb-ip-handling</code></a>).</p>
  1198. <p>Try removing any AAAA records for your TURN server, so that it is only
  1199. reachable over IPv4.</p>
  1200. </li>
  1201. <li>
  1202. <p>Enable more verbose logging in coturn via the <code>verbose</code> setting:</p>
  1203. <pre><code>verbose
  1204. </code></pre>
  1205. <p>... and then see if there are any clues in its logs.</p>
  1206. </li>
  1207. <li>
  1208. <p>If you are using a browser-based client under Chrome, check
  1209. <code>chrome://webrtc-internals/</code> for insights into the internals of the
  1210. negotiation. On Firefox, check the &quot;Connection Log&quot; on <code>about:webrtc</code>.</p>
  1211. <p>(Understanding the output is beyond the scope of this document!)</p>
  1212. </li>
  1213. <li>
  1214. <p>You can test your Matrix homeserver TURN setup with https://test.voip.librepush.net/.
  1215. Note that this test is not fully reliable yet, so don't be discouraged if
  1216. the test fails.
  1217. <a href="https://github.com/matrix-org/voip-tester">Here</a> is the github repo of the
  1218. source of the tester, where you can file bug reports.</p>
  1219. </li>
  1220. <li>
  1221. <p>There is a WebRTC test tool at
  1222. https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/. To
  1223. use it, you will need a username/password for your TURN server. You can
  1224. either:</p>
  1225. <ul>
  1226. <li>
  1227. <p>look for the <code>GET /_matrix/client/r0/voip/turnServer</code> request made by a
  1228. matrix client to your homeserver in your browser's network inspector. In
  1229. the response you should see <code>username</code> and <code>password</code>. Or:</p>
  1230. </li>
  1231. <li>
  1232. <p>Use the following shell commands:</p>
  1233. <pre><code class="language-sh">secret=staticAuthSecretHere
  1234. u=$((`date +%s` + 3600)):test
  1235. p=$(echo -n $u | openssl dgst -hmac $secret -sha1 -binary | base64)
  1236. echo -e &quot;username: $u\npassword: $p&quot;
  1237. </code></pre>
  1238. <p>Or:</p>
  1239. </li>
  1240. <li>
  1241. <p>Temporarily configure coturn to accept a static username/password. To do
  1242. this, comment out <code>use-auth-secret</code> and <code>static-auth-secret</code> and add the
  1243. following:</p>
  1244. <pre><code>lt-cred-mech
  1245. user=username:password
  1246. </code></pre>
  1247. <p><strong>Note</strong>: these settings will not take effect unless <code>use-auth-secret</code>
  1248. and <code>static-auth-secret</code> are disabled.</p>
  1249. <p>Restart coturn after changing the configuration file.</p>
  1250. <p>Remember to restore the original settings to go back to testing with
  1251. Matrix clients!</p>
  1252. </li>
  1253. </ul>
  1254. <p>If the TURN server is working correctly, you should see at least one <code>relay</code>
  1255. entry in the results.</p>
  1256. </li>
  1257. </ul>
  1258. <div style="break-before: page; page-break-before: always;"></div><h1 id="delegation"><a class="header" href="#delegation">Delegation</a></h1>
  1259. <p>By default, other homeservers will expect to be able to reach yours via
  1260. your <code>server_name</code>, on port 8448. For example, if you set your <code>server_name</code>
  1261. to <code>example.com</code> (so that your user names look like <code>@user:example.com</code>),
  1262. other servers will try to connect to yours at <code>https://example.com:8448/</code>.</p>
  1263. <p>Delegation is a Matrix feature allowing a homeserver admin to retain a
  1264. <code>server_name</code> of <code>example.com</code> so that user IDs, room aliases, etc continue
  1265. to look like <code>*:example.com</code>, whilst having federation traffic routed
  1266. to a different server and/or port (e.g. <code>synapse.example.com:443</code>).</p>
  1267. <h2 id="well-known-delegation"><a class="header" href="#well-known-delegation">.well-known delegation</a></h2>
  1268. <p>To use this method, you need to be able to alter the
  1269. <code>server_name</code> 's https server to serve the <code>/.well-known/matrix/server</code>
  1270. URL. Having an active server (with a valid TLS certificate) serving your
  1271. <code>server_name</code> domain is out of the scope of this documentation.</p>
  1272. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> should
  1273. return a JSON structure containing the key <code>m.server</code> like so:</p>
  1274. <pre><code class="language-json">{
  1275. &quot;m.server&quot;: &quot;&lt;synapse.server.name&gt;[:&lt;yourport&gt;]&quot;
  1276. }
  1277. </code></pre>
  1278. <p>In our example, this would mean that URL <code>https://example.com/.well-known/matrix/server</code>
  1279. should return:</p>
  1280. <pre><code class="language-json">{
  1281. &quot;m.server&quot;: &quot;synapse.example.com:443&quot;
  1282. }
  1283. </code></pre>
  1284. <p>Note, specifying a port is optional. If no port is specified, then it defaults
  1285. to 8448.</p>
  1286. <p>With .well-known delegation, federating servers will check for a valid TLS
  1287. certificate for the delegated hostname (in our example: <code>synapse.example.com</code>).</p>
  1288. <h2 id="srv-dns-record-delegation"><a class="header" href="#srv-dns-record-delegation">SRV DNS record delegation</a></h2>
  1289. <p>It is also possible to do delegation using a SRV DNS record. However, that is
  1290. considered an advanced topic since it's a bit complex to set up, and <code>.well-known</code>
  1291. delegation is already enough in most cases.</p>
  1292. <p>However, if you really need it, you can find some documentation on how such a
  1293. 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
  1294. specification</a>.</p>
  1295. <h2 id="delegation-faq"><a class="header" href="#delegation-faq">Delegation FAQ</a></h2>
  1296. <h3 id="when-do-i-need-delegation"><a class="header" href="#when-do-i-need-delegation">When do I need delegation?</a></h3>
  1297. <p>If your homeserver's APIs are accessible on the default federation port (8448)
  1298. and the domain your <code>server_name</code> points to, you do not need any delegation.</p>
  1299. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  1300. fresh server, you could install Synapse on that host, giving it a <code>server_name</code>
  1301. of <code>example.com</code>, and once a reverse proxy has been set up to proxy all requests
  1302. sent to the port <code>8448</code> and serve TLS certificates for <code>example.com</code>, you
  1303. wouldn't need any delegation set up.</p>
  1304. <p><strong>However</strong>, if your homeserver's APIs aren't accessible on port 8448 and on the
  1305. domain <code>server_name</code> points to, you will need to let other servers know how to
  1306. find it using delegation.</p>
  1307. <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>
  1308. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  1309. find it easier to direct federation traffic to a reverse proxy and manage their
  1310. own TLS certificates, and this is a supported configuration.</p>
  1311. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  1312. reverse proxy.</p>
  1313. <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>
  1314. <p>This is no longer necessary. If you are using a reverse proxy for all of your
  1315. TLS traffic, then you can set <code>no_tls: True</code> in the Synapse config.</p>
  1316. <p>In that case, the only reason Synapse needs the certificate is to populate a legacy
  1317. <code>tls_fingerprints</code> field in the federation API. This is ignored by Synapse 0.99.0
  1318. and later, and the only time pre-0.99 Synapses will check it is when attempting to
  1319. fetch the server keys - and generally this is delegated via <code>matrix.org</code>, which
  1320. is running a modern version of Synapse.</p>
  1321. <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>
  1322. <p>No. There is nothing stopping you from using different certificates,
  1323. particularly if you are using a reverse proxy.</p>
  1324. <div style="break-before: page; page-break-before: always;"></div><h1 id="upgrading-synapse"><a class="header" href="#upgrading-synapse">Upgrading Synapse</a></h1>
  1325. <p>Before upgrading check if any special steps are required to upgrade from
  1326. the version you currently have installed to the current version of
  1327. Synapse. The extra instructions that may be required are listed later in
  1328. this document.</p>
  1329. <ul>
  1330. <li>
  1331. <p>Check that your versions of Python and PostgreSQL are still
  1332. supported.</p>
  1333. <p>Synapse follows upstream lifecycles for <a href="https://endoflife.date/python">Python</a> and
  1334. <a href="https://endoflife.date/postgresql">PostgreSQL</a>, and removes support for versions
  1335. which are no longer maintained.</p>
  1336. <p>The website <a href="https://endoflife.date">https://endoflife.date</a> also offers convenient
  1337. summaries.</p>
  1338. </li>
  1339. <li>
  1340. <p>If Synapse was installed using <a href="setup/installation.html#prebuilt-packages">prebuilt
  1341. packages</a>, you will need to follow the
  1342. normal process for upgrading those packages.</p>
  1343. </li>
  1344. <li>
  1345. <p>If Synapse was installed from source, then:</p>
  1346. <ol>
  1347. <li>
  1348. <p>Activate the virtualenv before upgrading. For example, if
  1349. Synapse is installed in a virtualenv in <code>~/synapse/env</code> then
  1350. run:</p>
  1351. <pre><code class="language-bash">source ~/synapse/env/bin/activate
  1352. </code></pre>
  1353. </li>
  1354. <li>
  1355. <p>If Synapse was installed using pip then upgrade to the latest
  1356. version by running:</p>
  1357. <pre><code class="language-bash">pip install --upgrade matrix-synapse
  1358. </code></pre>
  1359. <p>If Synapse was installed using git then upgrade to the latest
  1360. version by running:</p>
  1361. <pre><code class="language-bash">git pull
  1362. pip install --upgrade .
  1363. </code></pre>
  1364. </li>
  1365. <li>
  1366. <p>Restart Synapse:</p>
  1367. <pre><code class="language-bash">./synctl restart
  1368. </code></pre>
  1369. </li>
  1370. </ol>
  1371. </li>
  1372. </ul>
  1373. <p>To check whether your update was successful, you can check the running
  1374. server version with:</p>
  1375. <pre><code class="language-bash"># you may need to replace 'localhost:8008' if synapse is not configured
  1376. # to listen on port 8008.
  1377. curl http://localhost:8008/_synapse/admin/v1/server_version
  1378. </code></pre>
  1379. <h2 id="rolling-back-to-older-versions"><a class="header" href="#rolling-back-to-older-versions">Rolling back to older versions</a></h2>
  1380. <p>Rolling back to previous releases can be difficult, due to database
  1381. schema changes between releases. Where we have been able to test the
  1382. rollback process, this will be noted below.</p>
  1383. <p>In general, you will need to undo any changes made during the upgrade
  1384. process, for example:</p>
  1385. <ul>
  1386. <li>
  1387. <p>pip:</p>
  1388. <pre><code class="language-bash">source env/bin/activate
  1389. # replace `1.3.0` accordingly:
  1390. pip install matrix-synapse==1.3.0
  1391. </code></pre>
  1392. </li>
  1393. <li>
  1394. <p>Debian:</p>
  1395. <pre><code class="language-bash"># replace `1.3.0` and `stretch` accordingly:
  1396. wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1397. dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1398. </code></pre>
  1399. </li>
  1400. </ul>
  1401. <h1 id="upgrading-to-v1390"><a class="header" href="#upgrading-to-v1390">Upgrading to v1.39.0</a></h1>
  1402. <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>
  1403. <p>The current third-party rules module interface is deprecated in favour of the new generic
  1404. modules system introduced in Synapse v1.37.0. Authors of third-party rules modules can refer
  1405. to <a href="modules.html#porting-an-existing-module-that-uses-the-old-interface">this documentation</a>
  1406. to update their modules. Synapse administrators can refer to <a href="modules.html#using-modules">this documentation</a>
  1407. to update their configuration once the modules they are using have been updated.</p>
  1408. <p>We plan to remove support for the current third-party rules interface in September 2021.</p>
  1409. <h1 id="upgrading-to-v1380"><a class="header" href="#upgrading-to-v1380">Upgrading to v1.38.0</a></h1>
  1410. <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>
  1411. <p>This release includes a database schema update which requires re-indexing one of
  1412. the larger tables in the database, <code>events</code>. This could result in increased
  1413. disk I/O for several hours or days after upgrading while the migration
  1414. completes. Furthermore, because we have to keep the old indexes until the new
  1415. indexes are ready, it could result in a significant, temporary, increase in
  1416. disk space.</p>
  1417. <p>To get a rough idea of the disk space required, check the current size of one
  1418. of the indexes. For example, from a <code>psql</code> shell, run the following sql:</p>
  1419. <pre><code class="language-sql">SELECT pg_size_pretty(pg_relation_size('events_order_room'));
  1420. </code></pre>
  1421. <p>We need to rebuild <strong>four</strong> indexes, so you will need to multiply this result
  1422. by four to give an estimate of the disk space required. For example, on one
  1423. particular server:</p>
  1424. <pre><code>synapse=# select pg_size_pretty(pg_relation_size('events_order_room'));
  1425. pg_size_pretty
  1426. ----------------
  1427. 288 MB
  1428. (1 row)
  1429. </code></pre>
  1430. <p>On this server, it would be wise to ensure that at least 1152MB are free.</p>
  1431. <p>The additional disk space will be freed once the migration completes.</p>
  1432. <p>SQLite databases are unaffected by this change.</p>
  1433. <h1 id="upgrading-to-v1370"><a class="header" href="#upgrading-to-v1370">Upgrading to v1.37.0</a></h1>
  1434. <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>
  1435. <p>The current spam checker interface is deprecated in favour of a new generic modules system.
  1436. Authors of spam checker modules can refer to <a href="https://matrix-org.github.io/synapse/develop/modules.html#porting-an-existing-module-that-uses-the-old-interface">this
  1437. documentation</a>
  1438. to update their modules. Synapse administrators can refer to <a href="https://matrix-org.github.io/synapse/develop/modules.html#using-modules">this
  1439. documentation</a>
  1440. to update their configuration once the modules they are using have been updated.</p>
  1441. <p>We plan to remove support for the current spam checker interface in August 2021.</p>
  1442. <p>More module interfaces will be ported over to this new generic system in future versions
  1443. of Synapse.</p>
  1444. <h1 id="upgrading-to-v1340"><a class="header" href="#upgrading-to-v1340">Upgrading to v1.34.0</a></h1>
  1445. <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>
  1446. <p>The <code>room_invite_state_types</code> configuration setting has been deprecated
  1447. 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
  1448. file</a>.</p>
  1449. <p>If you have set <code>room_invite_state_types</code> to the default value you
  1450. should simply remove it from your configuration file. The default value
  1451. used to be:</p>
  1452. <pre><code class="language-yaml">room_invite_state_types:
  1453. - &quot;m.room.join_rules&quot;
  1454. - &quot;m.room.canonical_alias&quot;
  1455. - &quot;m.room.avatar&quot;
  1456. - &quot;m.room.encryption&quot;
  1457. - &quot;m.room.name&quot;
  1458. </code></pre>
  1459. <p>If you have customised this value, you should remove
  1460. <code>room_invite_state_types</code> and configure <code>room_prejoin_state</code> instead.</p>
  1461. <h1 id="upgrading-to-v1330"><a class="header" href="#upgrading-to-v1330">Upgrading to v1.33.0</a></h1>
  1462. <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>
  1463. <p>This may affect you if you have enabled the account validity feature,
  1464. and have made use of a custom HTML template specified by the
  1465. <code>account_validity.template_dir</code> or
  1466. <code>account_validity.account_renewed_html_path</code> Synapse config options.</p>
  1467. <p>The template can now accept an <code>expiration_ts</code> variable, which
  1468. represents the unix timestamp in milliseconds for the future date of
  1469. 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
  1470. template</a>
  1471. for an example of usage.</p>
  1472. <p>ALso note that a new HTML template, <code>account_previously_renewed.html</code>,
  1473. has been added. This is is shown to users when they attempt to renew
  1474. their account with a valid renewal token that has already been used
  1475. before. The default template contents can been found
  1476. <a href="https://github.com/matrix-org/synapse/blob/release-v1.33.0/synapse/res/templates/account_previously_renewed.html">here</a>,
  1477. and can also accept an <code>expiration_ts</code> variable. This template replaces
  1478. the error message users would previously see upon attempting to use a
  1479. valid renewal token more than once.</p>
  1480. <h1 id="upgrading-to-v1320"><a class="header" href="#upgrading-to-v1320">Upgrading to v1.32.0</a></h1>
  1481. <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>
  1482. <p>This release introduces <a href="https://github.com/matrix-org/synapse/issues/9853">a
  1483. regression</a> that can
  1484. overwhelm connected Prometheus instances. This issue is not present in
  1485. Synapse v1.32.0rc1.</p>
  1486. <p>If you have been affected, please downgrade to 1.31.0. You then may need
  1487. to remove excess writeahead logs in order for Prometheus to recover.
  1488. Instructions for doing so are provided
  1489. <a href="https://github.com/matrix-org/synapse/pull/9854#issuecomment-823472183">here</a>.</p>
  1490. <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>
  1491. <p>In line with our <a href="https://github.com/matrix-org/synapse/blob/release-v1.32.0/docs/deprecation_policy.md">deprecation
  1492. policy</a>,
  1493. we've dropped support for Python 3.5 and PostgreSQL 9.5, as they are no
  1494. longer supported upstream.</p>
  1495. <p>This release of Synapse requires Python 3.6+ and PostgresSQL 9.6+ or
  1496. SQLite 3.22+.</p>
  1497. <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>
  1498. <p>The deprecated v1 &quot;list accounts&quot; admin API
  1499. (<code>GET /_synapse/admin/v1/users/&lt;user_id&gt;</code>) has been removed in this
  1500. version.</p>
  1501. <p>The <a href="https://github.com/matrix-org/synapse/blob/master/docs/admin_api/user_admin_api.rst#list-accounts">v2 list accounts
  1502. API</a>
  1503. has been available since Synapse 1.7.0 (2019-12-13), and is accessible
  1504. under <code>GET /_synapse/admin/v2/users</code>.</p>
  1505. <p>The deprecation of the old endpoint was announced with Synapse 1.28.0
  1506. (released on 2021-02-25).</p>
  1507. <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>
  1508. <p>In compliance with the <a href="https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions">Application Service
  1509. spec</a>,
  1510. Application Services are now required to use the
  1511. <code>m.login.application_service</code> type when registering users via the
  1512. <code>/_matrix/client/r0/register</code> endpoint. This behaviour was deprecated in
  1513. Synapse v1.30.0.</p>
  1514. <p>Please ensure your Application Services are up to date.</p>
  1515. <h1 id="upgrading-to-v1290"><a class="header" href="#upgrading-to-v1290">Upgrading to v1.29.0</a></h1>
  1516. <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>
  1517. <p>When using Synapse with a reverse proxy (in particular, when using the
  1518. [x_forwarded]{.title-ref} option on an HTTP listener), Synapse now
  1519. expects to receive an [X-Forwarded-Proto]{.title-ref} header on incoming
  1520. HTTP requests. If it is not set, Synapse will log a warning on each
  1521. received request.</p>
  1522. <p>To avoid the warning, administrators using a reverse proxy should ensure
  1523. that the reverse proxy sets [X-Forwarded-Proto]{.title-ref} header to
  1524. [https]{.title-ref} or [http]{.title-ref} to indicate the protocol used
  1525. by the client.</p>
  1526. <p>Synapse also requires the [Host]{.title-ref} header to be preserved.</p>
  1527. <p>See the <a href="../reverse_proxy.html">reverse proxy documentation</a>, where the
  1528. example configurations have been updated to show how to set these
  1529. headers.</p>
  1530. <p>(Users of <a href="https://caddyserver.com/">Caddy</a> are unaffected, since we
  1531. believe it sets [X-Forwarded-Proto]{.title-ref} by default.)</p>
  1532. <h1 id="upgrading-to-v1270"><a class="header" href="#upgrading-to-v1270">Upgrading to v1.27.0</a></h1>
  1533. <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>
  1534. <p>This version changes the URI used for callbacks from OAuth2 and SAML2
  1535. identity providers:</p>
  1536. <ul>
  1537. <li>
  1538. <p>If your server is configured for single sign-on via an OpenID
  1539. Connect or OAuth2 identity provider, you will need to add
  1540. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> to the list
  1541. of permitted &quot;redirect URIs&quot; at the identity provider.</p>
  1542. <p>See the <a href="../openid.html">OpenID docs</a> for more information on setting
  1543. up OpenID Connect.</p>
  1544. </li>
  1545. <li>
  1546. <p>If your server is configured for single sign-on via a SAML2 identity
  1547. provider, you will need to add
  1548. <code>[synapse public baseurl]/_synapse/client/saml2/authn_response</code> as a
  1549. permitted &quot;ACS location&quot; (also known as &quot;allowed callback URLs&quot;)
  1550. at the identity provider.</p>
  1551. <p>The &quot;Issuer&quot; in the &quot;AuthnRequest&quot; to the SAML2 identity
  1552. provider is also updated to
  1553. <code>[synapse public baseurl]/_synapse/client/saml2/metadata.xml</code>. If
  1554. your SAML2 identity provider uses this property to validate or
  1555. otherwise identify Synapse, its configuration will need to be
  1556. updated to use the new URL. Alternatively you could create a new,
  1557. separate &quot;EntityDescriptor&quot; in your SAML2 identity provider with
  1558. the new URLs and leave the URLs in the existing &quot;EntityDescriptor&quot;
  1559. as they were.</p>
  1560. </li>
  1561. </ul>
  1562. <h2 id="changes-to-html-templates"><a class="header" href="#changes-to-html-templates">Changes to HTML templates</a></h2>
  1563. <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
  1564. autoescape</a>
  1565. enabled for files ending in <code>.html</code>, <code>.htm</code>, and <code>.xml</code>. If you have
  1566. customised these templates and see issues when viewing them you might
  1567. need to update them. It is expected that most configurations will need
  1568. no changes.</p>
  1569. <p>If you have customised the templates <em>names</em> for these templates, it is
  1570. recommended to verify they end in <code>.html</code> to ensure autoescape is
  1571. enabled.</p>
  1572. <p>The above applies to the following templates:</p>
  1573. <ul>
  1574. <li><code>add_threepid.html</code></li>
  1575. <li><code>add_threepid_failure.html</code></li>
  1576. <li><code>add_threepid_success.html</code></li>
  1577. <li><code>notice_expiry.html</code></li>
  1578. <li><code>notice_expiry.html</code></li>
  1579. <li><code>notif_mail.html</code> (which, by default, includes <code>room.html</code> and
  1580. <code>notif.html</code>)</li>
  1581. <li><code>password_reset.html</code></li>
  1582. <li><code>password_reset_confirmation.html</code></li>
  1583. <li><code>password_reset_failure.html</code></li>
  1584. <li><code>password_reset_success.html</code></li>
  1585. <li><code>registration.html</code></li>
  1586. <li><code>registration_failure.html</code></li>
  1587. <li><code>registration_success.html</code></li>
  1588. <li><code>sso_account_deactivated.html</code></li>
  1589. <li><code>sso_auth_bad_user.html</code></li>
  1590. <li><code>sso_auth_confirm.html</code></li>
  1591. <li><code>sso_auth_success.html</code></li>
  1592. <li><code>sso_error.html</code></li>
  1593. <li><code>sso_login_idp_picker.html</code></li>
  1594. <li><code>sso_redirect_confirm.html</code></li>
  1595. </ul>
  1596. <h1 id="upgrading-to-v1260"><a class="header" href="#upgrading-to-v1260">Upgrading to v1.26.0</a></h1>
  1597. <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>
  1598. <p>v1.26.0 includes a lot of large changes. If something problematic
  1599. occurs, you may want to roll-back to a previous version of Synapse.
  1600. Because v1.26.0 also includes a new database schema version, reverting
  1601. that version is also required alongside the generic rollback
  1602. instructions mentioned above. In short, to roll back to v1.25.0 you need
  1603. to:</p>
  1604. <ol>
  1605. <li>
  1606. <p>Stop the server</p>
  1607. </li>
  1608. <li>
  1609. <p>Decrease the schema version in the database:</p>
  1610. <pre><code class="language-sql">UPDATE schema_version SET version = 58;
  1611. </code></pre>
  1612. </li>
  1613. <li>
  1614. <p>Delete the ignored users &amp; chain cover data:</p>
  1615. <pre><code class="language-sql">DROP TABLE IF EXISTS ignored_users;
  1616. UPDATE rooms SET has_auth_chain_index = false;
  1617. </code></pre>
  1618. <p>For PostgreSQL run:</p>
  1619. <pre><code class="language-sql">TRUNCATE event_auth_chain_links;
  1620. TRUNCATE event_auth_chains;
  1621. </code></pre>
  1622. <p>For SQLite run:</p>
  1623. <pre><code class="language-sql">DELETE FROM event_auth_chain_links;
  1624. DELETE FROM event_auth_chains;
  1625. </code></pre>
  1626. </li>
  1627. <li>
  1628. <p>Mark the deltas as not run (so they will re-run on upgrade).</p>
  1629. <pre><code class="language-sql">DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/01ignored_user.py&quot;;
  1630. DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/06chain_cover_index.sql&quot;;
  1631. </code></pre>
  1632. </li>
  1633. <li>
  1634. <p>Downgrade Synapse by following the instructions for your
  1635. installation method in the &quot;Rolling back to older versions&quot;
  1636. section above.</p>
  1637. </li>
  1638. </ol>
  1639. <h1 id="upgrading-to-v1250"><a class="header" href="#upgrading-to-v1250">Upgrading to v1.25.0</a></h1>
  1640. <h2 id="last-release-supporting-python-35"><a class="header" href="#last-release-supporting-python-35">Last release supporting Python 3.5</a></h2>
  1641. <p>This is the last release of Synapse which guarantees support with Python
  1642. 3.5, which passed its upstream End of Life date several months ago.</p>
  1643. <p>We will attempt to maintain support through March 2021, but without
  1644. guarantees.</p>
  1645. <p>In the future, Synapse will follow upstream schedules for ending support
  1646. of older versions of Python and PostgreSQL. Please upgrade to at least
  1647. Python 3.6 and PostgreSQL 9.6 as soon as possible.</p>
  1648. <h2 id="blacklisting-ip-ranges"><a class="header" href="#blacklisting-ip-ranges">Blacklisting IP ranges</a></h2>
  1649. <p>Synapse v1.25.0 includes new settings, <code>ip_range_blacklist</code> and
  1650. <code>ip_range_whitelist</code>, for controlling outgoing requests from Synapse for
  1651. federation, identity servers, push, and for checking key validity for
  1652. third-party invite events. The previous setting,
  1653. <code>federation_ip_range_blacklist</code>, is deprecated. The new
  1654. <code>ip_range_blacklist</code> defaults to private IP ranges if it is not defined.</p>
  1655. <p>If you have never customised <code>federation_ip_range_blacklist</code> it is
  1656. recommended that you remove that setting.</p>
  1657. <p>If you have customised <code>federation_ip_range_blacklist</code> you should update
  1658. the setting name to <code>ip_range_blacklist</code>.</p>
  1659. <p>If you have a custom push server that is reached via private IP space
  1660. you may need to customise <code>ip_range_blacklist</code> or <code>ip_range_whitelist</code>.</p>
  1661. <h1 id="upgrading-to-v1240"><a class="header" href="#upgrading-to-v1240">Upgrading to v1.24.0</a></h1>
  1662. <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>
  1663. <p>This release allows the OpenID Connect mapping provider to perform
  1664. normalisation of the localpart of the Matrix ID. This allows for the
  1665. mapping provider to specify different algorithms, instead of the
  1666. <a href="https://matrix.org/docs/spec/appendices#mapping-from-other-character-sets">default
  1667. way</a>.</p>
  1668. <p>If your Synapse configuration uses a custom mapping provider
  1669. ([oidc_config.user_mapping_provider.module]{.title-ref} is specified and
  1670. not equal to
  1671. [synapse.handlers.oidc_handler.JinjaOidcMappingProvider]{.title-ref})
  1672. then you <em>must</em> ensure that [map_user_attributes]{.title-ref} of the
  1673. mapping provider performs some normalisation of the
  1674. [localpart]{.title-ref} returned. To match previous behaviour you can
  1675. use the [map_username_to_mxid_localpart]{.title-ref} function provided
  1676. by Synapse. An example is shown below:</p>
  1677. <pre><code class="language-python">from synapse.types import map_username_to_mxid_localpart
  1678. class MyMappingProvider:
  1679. def map_user_attributes(self, userinfo, token):
  1680. # ... your custom logic ...
  1681. sso_user_id = ...
  1682. localpart = map_username_to_mxid_localpart(sso_user_id)
  1683. return {&quot;localpart&quot;: localpart}
  1684. </code></pre>
  1685. <h2 id="removal-historical-synapse-admin-api"><a class="header" href="#removal-historical-synapse-admin-api">Removal historical Synapse Admin API</a></h2>
  1686. <p>Historically, the Synapse Admin API has been accessible under:</p>
  1687. <ul>
  1688. <li><code>/_matrix/client/api/v1/admin</code></li>
  1689. <li><code>/_matrix/client/unstable/admin</code></li>
  1690. <li><code>/_matrix/client/r0/admin</code></li>
  1691. <li><code>/_synapse/admin/v1</code></li>
  1692. </ul>
  1693. <p>The endpoints with <code>/_matrix/client/*</code> prefixes have been removed as of
  1694. v1.24.0. The Admin API is now only accessible under:</p>
  1695. <ul>
  1696. <li><code>/_synapse/admin/v1</code></li>
  1697. </ul>
  1698. <p>The only exception is the [/admin/whois]{.title-ref} endpoint, which is
  1699. <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
  1700. API</a>.</p>
  1701. <p>The deprecation of the old endpoints was announced with Synapse 1.20.0
  1702. (released on 2020-09-22) and makes it easier for homeserver admins to
  1703. lock down external access to the Admin API endpoints.</p>
  1704. <h1 id="upgrading-to-v1230"><a class="header" href="#upgrading-to-v1230">Upgrading to v1.23.0</a></h1>
  1705. <h2 id="structured-logging-configuration-breaking-changes"><a class="header" href="#structured-logging-configuration-breaking-changes">Structured logging configuration breaking changes</a></h2>
  1706. <p>This release deprecates use of the <code>structured: true</code> logging
  1707. configuration for structured logging. If your logging configuration
  1708. contains <code>structured: true</code> then it should be modified based on the
  1709. <a href="../structured_logging.html">structured logging
  1710. documentation</a>.</p>
  1711. <p>The <code>structured</code> and <code>drains</code> logging options are now deprecated and
  1712. should be replaced by standard logging configuration of <code>handlers</code> and
  1713. <code>formatters</code>.</p>
  1714. <p>A future will release of Synapse will make using <code>structured: true</code> an
  1715. error.</p>
  1716. <h1 id="upgrading-to-v1220"><a class="header" href="#upgrading-to-v1220">Upgrading to v1.22.0</a></h1>
  1717. <h2 id="thirdpartyeventrules-breaking-changes"><a class="header" href="#thirdpartyeventrules-breaking-changes">ThirdPartyEventRules breaking changes</a></h2>
  1718. <p>This release introduces a backwards-incompatible change to modules
  1719. making use of <code>ThirdPartyEventRules</code> in Synapse. If you make use of a
  1720. module defined under the <code>third_party_event_rules</code> config option, please
  1721. make sure it is updated to handle the below change:</p>
  1722. <p>The <code>http_client</code> argument is no longer passed to modules as they are
  1723. initialised. Instead, modules are expected to make use of the
  1724. <code>http_client</code> property on the <code>ModuleApi</code> class. Modules are now passed
  1725. a <code>module_api</code> argument during initialisation, which is an instance of
  1726. <code>ModuleApi</code>. <code>ModuleApi</code> instances have a <code>http_client</code> property which
  1727. acts the same as the <code>http_client</code> argument previously passed to
  1728. <code>ThirdPartyEventRules</code> modules.</p>
  1729. <h1 id="upgrading-to-v1210"><a class="header" href="#upgrading-to-v1210">Upgrading to v1.21.0</a></h1>
  1730. <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>
  1731. <p>The <a href="https://github.com/matrix-org/synapse/blob/develop/docs/reverse_proxy.md">reverse proxy
  1732. documentation</a>
  1733. has been updated to include reverse proxy directives for
  1734. <code>/_synapse/client/*</code> endpoints. As the user password reset flow now uses
  1735. endpoints under this prefix, <strong>you must update your reverse proxy
  1736. configurations for user password reset to work</strong>.</p>
  1737. <p>Additionally, note that the <a href="https://github.com/matrix-org/synapse/blob/develop/docs/workers.md">Synapse worker documentation</a> has been updated to</p>
  1738. <p>: state that the <code>/_synapse/client/password_reset/email/submit_token</code>
  1739. endpoint can be handled</p>
  1740. <p>by all workers. If you make use of Synapse's worker feature, please
  1741. update your reverse proxy configuration to reflect this change.</p>
  1742. <h2 id="new-html-templates"><a class="header" href="#new-html-templates">New HTML templates</a></h2>
  1743. <p>A new HTML template,
  1744. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/res/templates/password_reset_confirmation.html">password_reset_confirmation.html</a>,
  1745. has been added to the <code>synapse/res/templates</code> directory. If you are
  1746. using a custom template directory, you may want to copy the template
  1747. over and modify it.</p>
  1748. <p>Note that as of v1.20.0, templates do not need to be included in custom
  1749. template directories for Synapse to start. The default templates will be
  1750. used if a custom template cannot be found.</p>
  1751. <p>This page will appear to the user after clicking a password reset link
  1752. that has been emailed to them.</p>
  1753. <p>To complete password reset, the page must include a way to make a
  1754. [POST]{.title-ref} request to
  1755. <code>/_synapse/client/password_reset/{medium}/submit_token</code> with the query
  1756. parameters from the original link, presented as a URL-encoded form. See
  1757. the file itself for more details.</p>
  1758. <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>
  1759. <p>The <code>saml_error.html</code> template was removed from Synapse and replaced
  1760. with the <code>sso_error.html</code> template. If your Synapse is configured to use
  1761. SAML and a custom <code>sso_redirect_confirm_template_dir</code> configuration then
  1762. any customisations of the <code>saml_error.html</code> template will need to be
  1763. merged into the <code>sso_error.html</code> template. These templates are similar,
  1764. but the parameters are slightly different:</p>
  1765. <ul>
  1766. <li>The <code>msg</code> parameter should be renamed to <code>error_description</code>.</li>
  1767. <li>There is no longer a <code>code</code> parameter for the response code.</li>
  1768. <li>A string <code>error</code> parameter is available that includes a short hint
  1769. of why a user is seeing the error page.</li>
  1770. </ul>
  1771. <h1 id="upgrading-to-v1180"><a class="header" href="#upgrading-to-v1180">Upgrading to v1.18.0</a></h1>
  1772. <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>
  1773. <p>From 10th August 2020, we will no longer publish Docker images with the
  1774. [-py3]{.title-ref} tag suffix. The images tagged with the
  1775. [-py3]{.title-ref} suffix have been identical to the non-suffixed tags
  1776. since release 0.99.0, and the suffix is obsolete.</p>
  1777. <p>On 10th August, we will remove the [latest-py3]{.title-ref} tag.
  1778. Existing per-release tags (such as [v1.18.0-py3]{.title-ref}) will not
  1779. be removed, but no new [-py3]{.title-ref} tags will be added.</p>
  1780. <p>Scripts relying on the [-py3]{.title-ref} suffix will need to be
  1781. updated.</p>
  1782. <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>
  1783. <p>When setting up worker processes, we now recommend the use of a Redis
  1784. server for replication. <strong>The old direct TCP connection method is
  1785. deprecated and will be removed in a future release.</strong> See
  1786. <a href="../workers.html">workers</a> for more details.</p>
  1787. <h1 id="upgrading-to-v1140"><a class="header" href="#upgrading-to-v1140">Upgrading to v1.14.0</a></h1>
  1788. <p>This version includes a database update which is run as part of the
  1789. upgrade, and which may take a couple of minutes in the case of a large
  1790. server. Synapse will not respond to HTTP requests while this update is
  1791. taking place.</p>
  1792. <h1 id="upgrading-to-v1130"><a class="header" href="#upgrading-to-v1130">Upgrading to v1.13.0</a></h1>
  1793. <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>
  1794. <p>A bug was introduced in Synapse 1.4.0 which could cause the room
  1795. directory to be incomplete or empty if Synapse was upgraded directly
  1796. from v1.2.1 or earlier, to versions between v1.4.0 and v1.12.x.</p>
  1797. <p>This will <em>not</em> be a problem for Synapse installations which were:</p>
  1798. <p>: - created at v1.4.0 or later,
  1799. - upgraded via v1.3.x, or
  1800. - upgraded straight from v1.2.1 or earlier to v1.13.0 or later.</p>
  1801. <p>If completeness of the room directory is a concern, installations which
  1802. are affected can be repaired as follows:</p>
  1803. <ol>
  1804. <li>
  1805. <p>Run the following sql from a [psql]{.title-ref} or
  1806. [sqlite3]{.title-ref} console:</p>
  1807. <pre><code class="language-sql">INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1808. ('populate_stats_process_rooms', '{}', 'current_state_events_membership');
  1809. INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1810. ('populate_stats_process_users', '{}', 'populate_stats_process_rooms');
  1811. </code></pre>
  1812. </li>
  1813. <li>
  1814. <p>Restart synapse.</p>
  1815. </li>
  1816. </ol>
  1817. <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>
  1818. <p>New templates (<code>sso_auth_confirm.html</code>, <code>sso_auth_success.html</code>, and
  1819. <code>sso_account_deactivated.html</code>) were added to Synapse. If your Synapse
  1820. is configured to use SSO and a custom
  1821. <code>sso_redirect_confirm_template_dir</code> configuration then these templates
  1822. will need to be copied from
  1823. <a href="synapse/res/templates">synapse/res/templates</a> into that directory.</p>
  1824. <h2 id="synapse-sso-plugins-method-deprecation"><a class="header" href="#synapse-sso-plugins-method-deprecation">Synapse SSO Plugins Method Deprecation</a></h2>
  1825. <p>Plugins using the <code>complete_sso_login</code> method of
  1826. <code>synapse.module_api.ModuleApi</code> should update to using the async/await
  1827. version <code>complete_sso_login_async</code> which includes additional checks. The
  1828. non-async version is considered deprecated.</p>
  1829. <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>
  1830. <p>v1.13.0 includes a lot of large changes. If something problematic
  1831. occurs, you may want to roll-back to a previous version of Synapse.
  1832. Because v1.13.0 also includes a new database schema version, reverting
  1833. that version is also required alongside the generic rollback
  1834. instructions mentioned above. In short, to roll back to v1.12.4 you need
  1835. to:</p>
  1836. <ol>
  1837. <li>
  1838. <p>Stop the server</p>
  1839. </li>
  1840. <li>
  1841. <p>Decrease the schema version in the database:</p>
  1842. <pre><code class="language-sql">UPDATE schema_version SET version = 57;
  1843. </code></pre>
  1844. </li>
  1845. <li>
  1846. <p>Downgrade Synapse by following the instructions for your
  1847. installation method in the &quot;Rolling back to older versions&quot;
  1848. section above.</p>
  1849. </li>
  1850. </ol>
  1851. <h1 id="upgrading-to-v1120"><a class="header" href="#upgrading-to-v1120">Upgrading to v1.12.0</a></h1>
  1852. <p>This version includes a database update which is run as part of the
  1853. upgrade, and which may take some time (several hours in the case of a
  1854. large server). Synapse will not respond to HTTP requests while this
  1855. update is taking place.</p>
  1856. <p>This is only likely to be a problem in the case of a server which is
  1857. participating in many rooms.</p>
  1858. <ol start="0">
  1859. <li>
  1860. <p>As with all upgrades, it is recommended that you have a recent
  1861. backup of your database which can be used for recovery in the event
  1862. of any problems.</p>
  1863. </li>
  1864. <li>
  1865. <p>As an initial check to see if you will be affected, you can try
  1866. running the following query from the [psql]{.title-ref} or
  1867. [sqlite3]{.title-ref} console. It is safe to run it while Synapse is
  1868. still running.</p>
  1869. <pre><code class="language-sql">SELECT MAX(q.v) FROM (
  1870. SELECT (
  1871. SELECT ej.json AS v
  1872. FROM state_events se INNER JOIN event_json ej USING (event_id)
  1873. WHERE se.room_id=rooms.room_id AND se.type='m.room.create' AND se.state_key=''
  1874. LIMIT 1
  1875. ) FROM rooms WHERE rooms.room_version IS NULL
  1876. ) q;
  1877. </code></pre>
  1878. <p>This query will take about the same amount of time as the upgrade
  1879. process: ie, if it takes 5 minutes, then it is likely that Synapse
  1880. will be unresponsive for 5 minutes during the upgrade.</p>
  1881. <p>If you consider an outage of this duration to be acceptable, no
  1882. further action is necessary and you can simply start Synapse 1.12.0.</p>
  1883. <p>If you would prefer to reduce the downtime, continue with the steps
  1884. below.</p>
  1885. </li>
  1886. <li>
  1887. <p>The easiest workaround for this issue is to manually create a new
  1888. index before upgrading. On PostgreSQL, his can be done as follows:</p>
  1889. <pre><code class="language-sql">CREATE INDEX CONCURRENTLY tmp_upgrade_1_12_0_index
  1890. ON state_events(room_id) WHERE type = 'm.room.create';
  1891. </code></pre>
  1892. <p>The above query may take some time, but is also safe to run while
  1893. Synapse is running.</p>
  1894. <p>We assume that no SQLite users have databases large enough to be
  1895. affected. If you <em>are</em> affected, you can run a similar query,
  1896. omitting the <code>CONCURRENTLY</code> keyword. Note however that this
  1897. operation may in itself cause Synapse to stop running for some time.
  1898. Synapse admins are reminded that <a href="https://github.com/matrix-org/synapse/blob/master/README.rst#using-postgresql">SQLite is not recommended for use
  1899. outside a test
  1900. environment</a>.</p>
  1901. </li>
  1902. <li>
  1903. <p>Once the index has been created, the <code>SELECT</code> query in step 1 above
  1904. should complete quickly. It is therefore safe to upgrade to Synapse
  1905. 1.12.0.</p>
  1906. </li>
  1907. <li>
  1908. <p>Once Synapse 1.12.0 has successfully started and is responding to
  1909. HTTP requests, the temporary index can be removed:</p>
  1910. <pre><code class="language-sql">DROP INDEX tmp_upgrade_1_12_0_index;
  1911. </code></pre>
  1912. </li>
  1913. </ol>
  1914. <h1 id="upgrading-to-v1100"><a class="header" href="#upgrading-to-v1100">Upgrading to v1.10.0</a></h1>
  1915. <p>Synapse will now log a warning on start up if used with a PostgreSQL
  1916. database that has a non-recommended locale set.</p>
  1917. <p>See <a href="../postgres.html">Postgres</a> for details.</p>
  1918. <h1 id="upgrading-to-v180"><a class="header" href="#upgrading-to-v180">Upgrading to v1.8.0</a></h1>
  1919. <p>Specifying a <code>log_file</code> config option will now cause Synapse to refuse
  1920. to start, and should be replaced by with the <code>log_config</code> option.
  1921. Support for the <code>log_file</code> option was removed in v1.3.0 and has since
  1922. had no effect.</p>
  1923. <h1 id="upgrading-to-v170"><a class="header" href="#upgrading-to-v170">Upgrading to v1.7.0</a></h1>
  1924. <p>In an attempt to configure Synapse in a privacy preserving way, the
  1925. default behaviours of <code>allow_public_rooms_without_auth</code> and
  1926. <code>allow_public_rooms_over_federation</code> have been inverted. This means that
  1927. by default, only authenticated users querying the Client/Server API will
  1928. be able to query the room directory, and relatedly that the server will
  1929. not share room directory information with other servers over federation.</p>
  1930. <p>If your installation does not explicitly set these settings one way or
  1931. the other and you want either setting to be <code>true</code> then it will
  1932. necessary to update your homeserver configuration file accordingly.</p>
  1933. <p>For more details on the surrounding context see our
  1934. <a href="https://matrix.org/blog/2019/11/09/avoiding-unwelcome-visitors-on-private-matrix-servers">explainer</a>.</p>
  1935. <h1 id="upgrading-to-v150"><a class="header" href="#upgrading-to-v150">Upgrading to v1.5.0</a></h1>
  1936. <p>This release includes a database migration which may take several
  1937. minutes to complete if there are a large number (more than a million or
  1938. so) of entries in the <code>devices</code> table. This is only likely to a be a
  1939. problem on very large installations.</p>
  1940. <h1 id="upgrading-to-v140"><a class="header" href="#upgrading-to-v140">Upgrading to v1.4.0</a></h1>
  1941. <h2 id="new-custom-templates"><a class="header" href="#new-custom-templates">New custom templates</a></h2>
  1942. <p>If you have configured a custom template directory with the
  1943. <code>email.template_dir</code> option, be aware that there are new templates
  1944. regarding registration and threepid management (see below) that must be
  1945. included.</p>
  1946. <ul>
  1947. <li><code>registration.html</code> and <code>registration.txt</code></li>
  1948. <li><code>registration_success.html</code> and <code>registration_failure.html</code></li>
  1949. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code></li>
  1950. <li><code>add_threepid_failure.html</code> and <code>add_threepid_success.html</code></li>
  1951. </ul>
  1952. <p>Synapse will expect these files to exist inside the configured template
  1953. directory, and <strong>will fail to start</strong> if they are absent. To view the
  1954. default templates, see
  1955. <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">synapse/res/templates</a>.</p>
  1956. <h2 id="3pid-verification-changes"><a class="header" href="#3pid-verification-changes">3pid verification changes</a></h2>
  1957. <p><strong>Note: As of this release, users will be unable to add phone numbers or
  1958. email addresses to their accounts, without changes to the Synapse
  1959. configuration. This includes adding an email address during
  1960. registration.</strong></p>
  1961. <p>It is possible for a user to associate an email address or phone number
  1962. with their account, for a number of reasons:</p>
  1963. <ul>
  1964. <li>for use when logging in, as an alternative to the user id.</li>
  1965. <li>in the case of email, as an alternative contact to help with account
  1966. recovery.</li>
  1967. <li>in the case of email, to receive notifications of missed messages.</li>
  1968. </ul>
  1969. <p>Before an email address or phone number can be added to a user's
  1970. account, or before such an address is used to carry out a
  1971. password-reset, Synapse must confirm the operation with the owner of the
  1972. email address or phone number. It does this by sending an email or text
  1973. giving the user a link or token to confirm receipt. This process is
  1974. known as '3pid verification'. ('3pid', or 'threepid', stands for
  1975. third-party identifier, and we use it to refer to external identifiers
  1976. such as email addresses and phone numbers.)</p>
  1977. <p>Previous versions of Synapse delegated the task of 3pid verification to
  1978. an identity server by default. In most cases this server is <code>vector.im</code>
  1979. or <code>matrix.org</code>.</p>
  1980. <p>In Synapse 1.4.0, for security and privacy reasons, the homeserver will
  1981. no longer delegate this task to an identity server by default. Instead,
  1982. the server administrator will need to explicitly decide how they would
  1983. like the verification messages to be sent.</p>
  1984. <p>In the medium term, the <code>vector.im</code> and <code>matrix.org</code> identity servers
  1985. will disable support for delegated 3pid verification entirely. However,
  1986. in order to ease the transition, they will retain the capability for a
  1987. limited period. Delegated email verification will be disabled on Monday
  1988. 2nd December 2019 (giving roughly 2 months notice). Disabling delegated
  1989. SMS verification will follow some time after that once SMS verification
  1990. support lands in Synapse.</p>
  1991. <p>Once delegated 3pid verification support has been disabled in the
  1992. <code>vector.im</code> and <code>matrix.org</code> identity servers, all Synapse versions that
  1993. depend on those instances will be unable to verify email and phone
  1994. numbers through them. There are no imminent plans to remove delegated
  1995. 3pid verification from Sydent generally. (Sydent is the identity server
  1996. project that backs the <code>vector.im</code> and <code>matrix.org</code> instances).</p>
  1997. <h3 id="email-1"><a class="header" href="#email-1">Email</a></h3>
  1998. <p>Following upgrade, to continue verifying email (e.g. as part of the
  1999. registration process), admins can either:-</p>
  2000. <ul>
  2001. <li>Configure Synapse to use an email server.</li>
  2002. <li>Run or choose an identity server which allows delegated email
  2003. verification and delegate to it.</li>
  2004. </ul>
  2005. <h4 id="configure-smtp-in-synapse"><a class="header" href="#configure-smtp-in-synapse">Configure SMTP in Synapse</a></h4>
  2006. <p>To configure an SMTP server for Synapse, modify the configuration
  2007. section headed <code>email</code>, and be sure to have at least the
  2008. <code>smtp_host, smtp_port</code> and <code>notif_from</code> fields filled out.</p>
  2009. <p>You may also need to set <code>smtp_user</code>, <code>smtp_pass</code>, and
  2010. <code>require_transport_security</code>.</p>
  2011. <p>See the <a href="docs/sample_config.yaml">sample configuration file</a> for more
  2012. details on these settings.</p>
  2013. <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>
  2014. <p>Some admins will wish to continue using email verification as part of
  2015. the registration process, but will not immediately have an appropriate
  2016. SMTP server at hand.</p>
  2017. <p>To this end, we will continue to support email verification delegation
  2018. via the <code>vector.im</code> and <code>matrix.org</code> identity servers for two months.
  2019. Support for delegated email verification will be disabled on Monday 2nd
  2020. December.</p>
  2021. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2022. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2023. server</a>) to handle
  2024. sending confirmation messages via email and SMS.</p>
  2025. <p>So to delegate email verification, in <code>homeserver.yaml</code>, set
  2026. <code>account_threepid_delegates.email</code> to the base URL of an identity
  2027. server. For example:</p>
  2028. <pre><code class="language-yaml">account_threepid_delegates:
  2029. email: https://example.com # Delegate email sending to example.com
  2030. </code></pre>
  2031. <p>Note that <code>account_threepid_delegates.email</code> replaces the deprecated
  2032. <code>email.trust_identity_server_for_password_resets</code>: if
  2033. <code>email.trust_identity_server_for_password_resets</code> is set to <code>true</code>, and
  2034. <code>account_threepid_delegates.email</code> is not set, then the first entry in
  2035. <code>trusted_third_party_id_servers</code> will be used as the
  2036. <code>account_threepid_delegate</code> for email. This is to ensure compatibility
  2037. with existing Synapse installs that set up external server handling for
  2038. these tasks before v1.4.0. If
  2039. <code>email.trust_identity_server_for_password_resets</code> is <code>true</code> and no
  2040. trusted identity server domains are configured, Synapse will report an
  2041. error and refuse to start.</p>
  2042. <p>If <code>email.trust_identity_server_for_password_resets</code> is <code>false</code> or
  2043. absent and no <code>email</code> delegate is configured in
  2044. <code>account_threepid_delegates</code>, then Synapse will send email verification
  2045. messages itself, using the configured SMTP server (see above). that
  2046. type.</p>
  2047. <h3 id="phone-numbers"><a class="header" href="#phone-numbers">Phone numbers</a></h3>
  2048. <p>Synapse does not support phone-number verification itself, so the only
  2049. way to maintain the ability for users to add phone numbers to their
  2050. accounts will be by continuing to delegate phone number verification to
  2051. the <code>matrix.org</code> and <code>vector.im</code> identity servers (or another identity
  2052. server that supports SMS sending).</p>
  2053. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2054. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2055. server</a>) to handle
  2056. sending confirmation messages via email and SMS.</p>
  2057. <p>So to delegate phone number verification, in <code>homeserver.yaml</code>, set
  2058. <code>account_threepid_delegates.msisdn</code> to the base URL of an identity
  2059. server. For example:</p>
  2060. <pre><code class="language-yaml">account_threepid_delegates:
  2061. msisdn: https://example.com # Delegate sms sending to example.com
  2062. </code></pre>
  2063. <p>The <code>matrix.org</code> and <code>vector.im</code> identity servers will continue to
  2064. support delegated phone number verification via SMS until such time as
  2065. it is possible for admins to configure their servers to perform phone
  2066. number verification directly. More details will follow in a future
  2067. release.</p>
  2068. <h2 id="rolling-back-to-v131"><a class="header" href="#rolling-back-to-v131">Rolling back to v1.3.1</a></h2>
  2069. <p>If you encounter problems with v1.4.0, it should be possible to roll
  2070. back to v1.3.1, subject to the following:</p>
  2071. <ul>
  2072. <li>
  2073. <p>The 'room statistics' engine was heavily reworked in this release
  2074. (see <a href="https://github.com/matrix-org/synapse/pull/5971">#5971</a>),
  2075. including significant changes to the database schema, which are not
  2076. easily reverted. This will cause the room statistics engine to stop
  2077. updating when you downgrade.</p>
  2078. <p>The room statistics are essentially unused in v1.3.1 (in future
  2079. versions of Synapse, they will be used to populate the room
  2080. directory), so there should be no loss of functionality. However,
  2081. the statistics engine will write errors to the logs, which can be
  2082. avoided by setting the following in <code>homeserver.yaml</code>:</p>
  2083. <pre><code class="language-yaml">stats:
  2084. enabled: false
  2085. </code></pre>
  2086. <p>Don't forget to re-enable it when you upgrade again, in preparation
  2087. for its use in the room directory!</p>
  2088. </li>
  2089. </ul>
  2090. <h1 id="upgrading-to-v120"><a class="header" href="#upgrading-to-v120">Upgrading to v1.2.0</a></h1>
  2091. <p>Some counter metrics have been renamed, with the old names deprecated.
  2092. See <a href="../metrics-howto.html#renaming-of-metrics--deprecation-of-old-names-in-12">the metrics
  2093. documentation</a>
  2094. for details.</p>
  2095. <h1 id="upgrading-to-v110"><a class="header" href="#upgrading-to-v110">Upgrading to v1.1.0</a></h1>
  2096. <p>Synapse v1.1.0 removes support for older Python and PostgreSQL versions,
  2097. as outlined in <a href="https://matrix.org/blog/2019/04/08/synapse-deprecating-postgres-9-4-and-python-2-x">our deprecation
  2098. notice</a>.</p>
  2099. <h2 id="minimum-python-version"><a class="header" href="#minimum-python-version">Minimum Python Version</a></h2>
  2100. <p>Synapse v1.1.0 has a minimum Python requirement of Python 3.5. Python
  2101. 3.6 or Python 3.7 are recommended as they have improved internal string
  2102. handling, significantly reducing memory usage.</p>
  2103. <p>If you use current versions of the Matrix.org-distributed Debian
  2104. packages or Docker images, action is not required.</p>
  2105. <p>If you install Synapse in a Python virtual environment, please see
  2106. &quot;Upgrading to v0.34.0&quot; for notes on setting up a new virtualenv under
  2107. Python 3.</p>
  2108. <h2 id="minimum-postgresql-version"><a class="header" href="#minimum-postgresql-version">Minimum PostgreSQL Version</a></h2>
  2109. <p>If using PostgreSQL under Synapse, you will need to use PostgreSQL 9.5
  2110. or above. Please see the <a href="https://www.postgresql.org/docs/11/upgrading.html">PostgreSQL
  2111. documentation</a> for
  2112. more details on upgrading your database.</p>
  2113. <h1 id="upgrading-to-v10"><a class="header" href="#upgrading-to-v10">Upgrading to v1.0</a></h1>
  2114. <h2 id="validation-of-tls-certificates"><a class="header" href="#validation-of-tls-certificates">Validation of TLS certificates</a></h2>
  2115. <p>Synapse v1.0 is the first release to enforce validation of TLS
  2116. certificates for the federation API. It is therefore essential that your
  2117. certificates are correctly configured. See the
  2118. <a href="../MSC1711_certificates_FAQ.html">FAQ</a> for more information.</p>
  2119. <p>Note, v1.0 installations will also no longer be able to federate with
  2120. servers that have not correctly configured their certificates.</p>
  2121. <p>In rare cases, it may be desirable to disable certificate checking: for
  2122. example, it might be essential to be able to federate with a given
  2123. legacy server in a closed federation. This can be done in one of two
  2124. ways:-</p>
  2125. <ul>
  2126. <li>Configure the global switch <code>federation_verify_certificates</code> to
  2127. <code>false</code>.</li>
  2128. <li>Configure a whitelist of server domains to trust via
  2129. <code>federation_certificate_verification_whitelist</code>.</li>
  2130. </ul>
  2131. <p>See the <a href="docs/sample_config.yaml">sample configuration file</a> for more
  2132. details on these settings.</p>
  2133. <h2 id="email-2"><a class="header" href="#email-2">Email</a></h2>
  2134. <p>When a user requests a password reset, Synapse will send an email to the
  2135. user to confirm the request.</p>
  2136. <p>Previous versions of Synapse delegated the job of sending this email to
  2137. an identity server. If the identity server was somehow malicious or
  2138. became compromised, it would be theoretically possible to hijack an
  2139. account through this means.</p>
  2140. <p>Therefore, by default, Synapse v1.0 will send the confirmation email
  2141. itself. If Synapse is not configured with an SMTP server, password reset
  2142. via email will be disabled.</p>
  2143. <p>To configure an SMTP server for Synapse, modify the configuration
  2144. section headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>,
  2145. <code>smtp_port</code> and <code>notif_from</code> fields filled out. You may also need to set
  2146. <code>smtp_user</code>, <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  2147. <p>If you are absolutely certain that you wish to continue using an
  2148. identity server for password resets, set
  2149. <code>trust_identity_server_for_password_resets</code> to <code>true</code>.</p>
  2150. <p>See the <a href="docs/sample_config.yaml">sample configuration file</a> for more
  2151. details on these settings.</p>
  2152. <h2 id="new-email-templates"><a class="header" href="#new-email-templates">New email templates</a></h2>
  2153. <p>Some new templates have been added to the default template directory for the purpose of
  2154. the homeserver sending its own password reset emails. If you have configured a
  2155. custom <code>template_dir</code> in your Synapse config, these files will need to be added.</p>
  2156. <p><code>password_reset.html</code> and <code>password_reset.txt</code> are HTML and plain text
  2157. templates respectively that contain the contents of what will be emailed
  2158. to the user upon attempting to reset their password via email.
  2159. <code>password_reset_success.html</code> and <code>password_reset_failure.html</code> are HTML
  2160. files that the content of which (assuming no redirect URL is set) will
  2161. be shown to the user after they attempt to click the link in the email
  2162. sent to them.</p>
  2163. <h1 id="upgrading-to-v0990"><a class="header" href="#upgrading-to-v0990">Upgrading to v0.99.0</a></h1>
  2164. <p>Please be aware that, before Synapse v1.0 is released around March 2019,
  2165. you will need to replace any self-signed certificates with those
  2166. verified by a root CA. Information on how to do so can be found at <a href="../ACME.html">the
  2167. ACME docs</a>.</p>
  2168. <p>For more information on configuring TLS certificates see the
  2169. <a href="../MSC1711_certificates_FAQ.html">FAQ</a>.</p>
  2170. <h1 id="upgrading-to-v0340"><a class="header" href="#upgrading-to-v0340">Upgrading to v0.34.0</a></h1>
  2171. <ol>
  2172. <li>
  2173. <p>This release is the first to fully support Python 3. Synapse will
  2174. now run on Python versions 3.5, or 3.6 (as well as 2.7). We
  2175. recommend switching to Python 3, as it has been shown to give
  2176. performance improvements.</p>
  2177. <p>For users who have installed Synapse into a virtualenv, we recommend
  2178. doing this by creating a new virtualenv. For example:</p>
  2179. <pre><code>virtualenv -p python3 ~/synapse/env3
  2180. source ~/synapse/env3/bin/activate
  2181. pip install matrix-synapse
  2182. </code></pre>
  2183. <p>You can then start synapse as normal, having activated the new
  2184. virtualenv:</p>
  2185. <pre><code>cd ~/synapse
  2186. source env3/bin/activate
  2187. synctl start
  2188. </code></pre>
  2189. <p>Users who have installed from distribution packages should see the
  2190. relevant package documentation. See below for notes on Debian
  2191. packages.</p>
  2192. <ul>
  2193. <li>
  2194. <p>When upgrading to Python 3, you <strong>must</strong> make sure that your log
  2195. files are configured as UTF-8, by adding <code>encoding: utf8</code> to the
  2196. <code>RotatingFileHandler</code> configuration (if you have one) in your
  2197. <code>&lt;server&gt;.log.config</code> file. For example, if your <code>log.config</code>
  2198. file contains:</p>
  2199. <pre><code>handlers:
  2200. file:
  2201. class: logging.handlers.RotatingFileHandler
  2202. formatter: precise
  2203. filename: homeserver.log
  2204. maxBytes: 104857600
  2205. backupCount: 10
  2206. filters: [context]
  2207. console:
  2208. class: logging.StreamHandler
  2209. formatter: precise
  2210. filters: [context]
  2211. </code></pre>
  2212. <p>Then you should update this to be:</p>
  2213. <pre><code>handlers:
  2214. file:
  2215. class: logging.handlers.RotatingFileHandler
  2216. formatter: precise
  2217. filename: homeserver.log
  2218. maxBytes: 104857600
  2219. backupCount: 10
  2220. filters: [context]
  2221. encoding: utf8
  2222. console:
  2223. class: logging.StreamHandler
  2224. formatter: precise
  2225. filters: [context]
  2226. </code></pre>
  2227. <p>There is no need to revert this change if downgrading to
  2228. Python 2.</p>
  2229. </li>
  2230. </ul>
  2231. <p>We are also making available Debian packages which will run Synapse
  2232. on Python 3. You can switch to these packages with
  2233. <code>apt-get install matrix-synapse-py3</code>, however, please read
  2234. <a href="https://github.com/matrix-org/synapse/blob/release-v0.34.0/debian/NEWS">debian/NEWS</a>
  2235. before doing so. The existing <code>matrix-synapse</code> packages will
  2236. continue to use Python 2 for the time being.</p>
  2237. </li>
  2238. <li>
  2239. <p>This release removes the <code>riot.im</code> from the default list of trusted
  2240. identity servers.</p>
  2241. <p>If <code>riot.im</code> is in your homeserver's list of
  2242. <code>trusted_third_party_id_servers</code>, you should remove it. It was added
  2243. in case a hypothetical future identity server was put there. If you
  2244. don't remove it, users may be unable to deactivate their accounts.</p>
  2245. </li>
  2246. <li>
  2247. <p>This release no longer installs the (unmaintained) Matrix Console
  2248. web client as part of the default installation. It is possible to
  2249. re-enable it by installing it separately and setting the
  2250. <code>web_client_location</code> config option, but please consider switching
  2251. to another client.</p>
  2252. </li>
  2253. </ol>
  2254. <h1 id="upgrading-to-v0337"><a class="header" href="#upgrading-to-v0337">Upgrading to v0.33.7</a></h1>
  2255. <p>This release removes the example email notification templates from
  2256. <code>res/templates</code> (they are now internal to the python package). This
  2257. should only affect you if you (a) deploy your Synapse instance from a
  2258. git checkout or a github snapshot URL, and (b) have email notifications
  2259. enabled.</p>
  2260. <p>If you have email notifications enabled, you should ensure that
  2261. <code>email.template_dir</code> is either configured to point at a directory where
  2262. you have installed customised templates, or leave it unset to use the
  2263. default templates.</p>
  2264. <h1 id="upgrading-to-v0273"><a class="header" href="#upgrading-to-v0273">Upgrading to v0.27.3</a></h1>
  2265. <p>This release expands the anonymous usage stats sent if the opt-in
  2266. <code>report_stats</code> configuration is set to <code>true</code>. We now capture RSS memory
  2267. and cpu use at a very coarse level. This requires administrators to
  2268. install the optional <code>psutil</code> python module.</p>
  2269. <p>We would appreciate it if you could assist by ensuring this module is
  2270. available and <code>report_stats</code> is enabled. This will let us see if
  2271. performance changes to synapse are having an impact to the general
  2272. community.</p>
  2273. <h1 id="upgrading-to-v0150"><a class="header" href="#upgrading-to-v0150">Upgrading to v0.15.0</a></h1>
  2274. <p>If you want to use the new URL previewing API
  2275. (<code>/_matrix/media/r0/preview_url</code>) then you have to explicitly enable it
  2276. in the config and update your dependencies dependencies. See README.rst
  2277. for details.</p>
  2278. <h1 id="upgrading-to-v0110"><a class="header" href="#upgrading-to-v0110">Upgrading to v0.11.0</a></h1>
  2279. <p>This release includes the option to send anonymous usage stats to
  2280. matrix.org, and requires that administrators explictly opt in or out by
  2281. setting the <code>report_stats</code> option to either <code>true</code> or <code>false</code>.</p>
  2282. <p>We would really appreciate it if you could help our project out by
  2283. reporting anonymized usage statistics from your homeserver. Only very
  2284. basic aggregate data (e.g. number of users) will be reported, but it
  2285. helps us to track the growth of the Matrix community, and helps us to
  2286. make Matrix a success, as well as to convince other networks that they
  2287. should peer with us.</p>
  2288. <h1 id="upgrading-to-v090"><a class="header" href="#upgrading-to-v090">Upgrading to v0.9.0</a></h1>
  2289. <p>Application services have had a breaking API change in this version.</p>
  2290. <p>They can no longer register themselves with a home server using the AS
  2291. HTTP API. This decision was made because a compromised application
  2292. service with free reign to register any regex in effect grants full
  2293. read/write access to the home server if a regex of <code>.*</code> is used. An
  2294. attack where a compromised AS re-registers itself with <code>.*</code> was deemed
  2295. too big of a security risk to ignore, and so the ability to register
  2296. with the HS remotely has been removed.</p>
  2297. <p>It has been replaced by specifying a list of application service
  2298. registrations in <code>homeserver.yaml</code>:</p>
  2299. <pre><code>app_service_config_files: [&quot;registration-01.yaml&quot;, &quot;registration-02.yaml&quot;]
  2300. </code></pre>
  2301. <p>Where <code>registration-01.yaml</code> looks like:</p>
  2302. <pre><code>url: &lt;String&gt; # e.g. &quot;https://my.application.service.com&quot;
  2303. as_token: &lt;String&gt;
  2304. hs_token: &lt;String&gt;
  2305. sender_localpart: &lt;String&gt; # This is a new field which denotes the user_id localpart when using the AS token
  2306. namespaces:
  2307. users:
  2308. - exclusive: &lt;Boolean&gt;
  2309. regex: &lt;String&gt; # e.g. &quot;@prefix_.*&quot;
  2310. aliases:
  2311. - exclusive: &lt;Boolean&gt;
  2312. regex: &lt;String&gt;
  2313. rooms:
  2314. - exclusive: &lt;Boolean&gt;
  2315. regex: &lt;String&gt;
  2316. </code></pre>
  2317. <h1 id="upgrading-to-v080"><a class="header" href="#upgrading-to-v080">Upgrading to v0.8.0</a></h1>
  2318. <p>Servers which use captchas will need to add their public key to:</p>
  2319. <pre><code>static/client/register/register_config.js
  2320. window.matrixRegistrationConfig = {
  2321. recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  2322. };
  2323. </code></pre>
  2324. <p>This is required in order to support registration fallback (typically
  2325. used on mobile devices).</p>
  2326. <h1 id="upgrading-to-v070"><a class="header" href="#upgrading-to-v070">Upgrading to v0.7.0</a></h1>
  2327. <p>New dependencies are:</p>
  2328. <ul>
  2329. <li>pydenticon</li>
  2330. <li>simplejson</li>
  2331. <li>syutil</li>
  2332. <li>matrix-angular-sdk</li>
  2333. </ul>
  2334. <p>To pull in these dependencies in a virtual env, run:</p>
  2335. <pre><code>python synapse/python_dependencies.py | xargs -n 1 pip install
  2336. </code></pre>
  2337. <h1 id="upgrading-to-v060"><a class="header" href="#upgrading-to-v060">Upgrading to v0.6.0</a></h1>
  2338. <p>To pull in new dependencies, run:</p>
  2339. <pre><code>python setup.py develop --user
  2340. </code></pre>
  2341. <p>This update includes a change to the database schema. To upgrade you
  2342. first need to upgrade the database by running:</p>
  2343. <pre><code>python scripts/upgrade_db_to_v0.6.0.py &lt;db&gt; &lt;server_name&gt; &lt;signing_key&gt;
  2344. </code></pre>
  2345. <p>Where [<db>]{.title-ref} is the location of the database,
  2346. [&lt;server_name&gt;]{.title-ref} is the server name as specified in the
  2347. synapse configuration, and [&lt;signing_key&gt;]{.title-ref} is the location
  2348. of the signing key as specified in the synapse configuration.</p>
  2349. <p>This may take some time to complete. Failures of signatures and content
  2350. hashes can safely be ignored.</p>
  2351. <h1 id="upgrading-to-v051"><a class="header" href="#upgrading-to-v051">Upgrading to v0.5.1</a></h1>
  2352. <p>Depending on precisely when you installed v0.5.0 you may have ended up
  2353. with a stale release of the reference matrix webclient installed as a
  2354. python module. To uninstall it and ensure you are depending on the
  2355. latest module, please run:</p>
  2356. <pre><code>$ pip uninstall syweb
  2357. </code></pre>
  2358. <h1 id="upgrading-to-v050"><a class="header" href="#upgrading-to-v050">Upgrading to v0.5.0</a></h1>
  2359. <p>The webclient has been split out into a seperate repository/pacakage in
  2360. this release. Before you restart your homeserver you will need to pull
  2361. in the webclient package by running:</p>
  2362. <pre><code>python setup.py develop --user
  2363. </code></pre>
  2364. <p>This release completely changes the database schema and so requires
  2365. upgrading it before starting the new version of the homeserver.</p>
  2366. <p>The script &quot;database-prepare-for-0.5.0.sh&quot; should be used to upgrade
  2367. the database. This will save all user information, such as logins and
  2368. profiles, but will otherwise purge the database. This includes messages,
  2369. which rooms the home server was a member of and room alias mappings.</p>
  2370. <p>If you would like to keep your history, please take a copy of your
  2371. database file and ask for help in #matrix:matrix.org. The upgrade
  2372. process is, unfortunately, non trivial and requires human intervention
  2373. to resolve any resulting conflicts during the upgrade process.</p>
  2374. <p>Before running the command the homeserver should be first completely
  2375. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2376. <blockquote>
  2377. <p>./scripts/database-prepare-for-0.5.0.sh &quot;homeserver.db&quot;</p>
  2378. </blockquote>
  2379. <p>Once this has successfully completed it will be safe to restart the
  2380. homeserver. You may notice that the homeserver takes a few seconds
  2381. longer to restart than usual as it reinitializes the database.</p>
  2382. <p>On startup of the new version, users can either rejoin remote rooms
  2383. using room aliases or by being reinvited. Alternatively, if any other
  2384. homeserver sends a message to a room that the homeserver was previously
  2385. in the local HS will automatically rejoin the room.</p>
  2386. <h1 id="upgrading-to-v040"><a class="header" href="#upgrading-to-v040">Upgrading to v0.4.0</a></h1>
  2387. <p>This release needs an updated syutil version. Run:</p>
  2388. <pre><code>python setup.py develop
  2389. </code></pre>
  2390. <p>You will also need to upgrade your configuration as the signing key
  2391. format has changed. Run:</p>
  2392. <pre><code>python -m synapse.app.homeserver --config-path &lt;CONFIG&gt; --generate-config
  2393. </code></pre>
  2394. <h1 id="upgrading-to-v030"><a class="header" href="#upgrading-to-v030">Upgrading to v0.3.0</a></h1>
  2395. <p>This registration API now closely matches the login API. This introduces
  2396. a bit more backwards and forwards between the HS and the client, but
  2397. this improves the overall flexibility of the API. You can now GET on
  2398. /register to retrieve a list of valid registration flows. Upon choosing
  2399. one, they are submitted in the same way as login, e.g:</p>
  2400. <pre><code>{
  2401. type: m.login.password,
  2402. user: foo,
  2403. password: bar
  2404. }
  2405. </code></pre>
  2406. <p>The default HS supports 2 flows, with and without Identity Server email
  2407. authentication. Enabling captcha on the HS will add in an extra step to
  2408. all flows: <code>m.login.recaptcha</code> which must be completed before you can
  2409. transition to the next stage. There is a new login type:
  2410. <code>m.login.email.identity</code> which contains the <code>threepidCreds</code> key which
  2411. were previously sent in the original register request. For more
  2412. information on this, see the specification.</p>
  2413. <h2 id="web-client"><a class="header" href="#web-client">Web Client</a></h2>
  2414. <p>The VoIP specification has changed between v0.2.0 and v0.3.0. Users
  2415. should refresh any browser tabs to get the latest web client code. Users
  2416. on v0.2.0 of the web client will not be able to call those on v0.3.0 and
  2417. vice versa.</p>
  2418. <h1 id="upgrading-to-v020"><a class="header" href="#upgrading-to-v020">Upgrading to v0.2.0</a></h1>
  2419. <p>The home server now requires setting up of SSL config before it can run.
  2420. To automatically generate default config use:</p>
  2421. <pre><code>$ python synapse/app/homeserver.py \
  2422. --server-name machine.my.domain.name \
  2423. --bind-port 8448 \
  2424. --config-path homeserver.config \
  2425. --generate-config
  2426. </code></pre>
  2427. <p>This config can be edited if desired, for example to specify a different
  2428. SSL certificate to use. Once done you can run the home server using:</p>
  2429. <pre><code>$ python synapse/app/homeserver.py --config-path homeserver.config
  2430. </code></pre>
  2431. <p>See the README.rst for more information.</p>
  2432. <p>Also note that some config options have been renamed, including:</p>
  2433. <ul>
  2434. <li>&quot;host&quot; to &quot;server-name&quot;</li>
  2435. <li>&quot;database&quot; to &quot;database-path&quot;</li>
  2436. <li>&quot;port&quot; to &quot;bind-port&quot; and &quot;unsecure-port&quot;</li>
  2437. </ul>
  2438. <h1 id="upgrading-to-v001"><a class="header" href="#upgrading-to-v001">Upgrading to v0.0.1</a></h1>
  2439. <p>This release completely changes the database schema and so requires
  2440. upgrading it before starting the new version of the homeserver.</p>
  2441. <p>The script &quot;database-prepare-for-0.0.1.sh&quot; should be used to upgrade
  2442. the database. This will save all user information, such as logins and
  2443. profiles, but will otherwise purge the database. This includes messages,
  2444. which rooms the home server was a member of and room alias mappings.</p>
  2445. <p>Before running the command the homeserver should be first completely
  2446. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2447. <blockquote>
  2448. <p>./scripts/database-prepare-for-0.0.1.sh &quot;homeserver.db&quot;</p>
  2449. </blockquote>
  2450. <p>Once this has successfully completed it will be safe to restart the
  2451. homeserver. You may notice that the homeserver takes a few seconds
  2452. longer to restart than usual as it reinitializes the database.</p>
  2453. <p>On startup of the new version, users can either rejoin remote rooms
  2454. using room aliases or by being reinvited. Alternatively, if any other
  2455. homeserver sends a message to a room that the homeserver was previously
  2456. in the local HS will automatically rejoin the room.</p>
  2457. <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>
  2458. <h2 id="historical-note"><a class="header" href="#historical-note">Historical Note</a></h2>
  2459. <p>This document was originally written to guide server admins through the upgrade
  2460. path towards Synapse 1.0. Specifically,
  2461. <a href="https://github.com/matrix-org/matrix-doc/blob/master/proposals/1711-x509-for-federation.md">MSC1711</a>
  2462. required that all servers present valid TLS certificates on their federation
  2463. API. Admins were encouraged to achieve compliance from version 0.99.0 (released
  2464. in February 2019) ahead of version 1.0 (released June 2019) enforcing the
  2465. certificate checks.</p>
  2466. <p>Much of what follows is now outdated since most admins will have already
  2467. upgraded, however it may be of use to those with old installs returning to the
  2468. project.</p>
  2469. <p>If you are setting up a server from scratch you almost certainly should look at
  2470. the <a href="setup/installation.html">installation guide</a> instead.</p>
  2471. <h2 id="introduction-1"><a class="header" href="#introduction-1">Introduction</a></h2>
  2472. <p>The goal of Synapse 0.99.0 is to act as a stepping stone to Synapse 1.0.0. It
  2473. supports the r0.1 release of the server to server specification, but is
  2474. compatible with both the legacy Matrix federation behaviour (pre-r0.1) as well
  2475. as post-r0.1 behaviour, in order to allow for a smooth upgrade across the
  2476. federation.</p>
  2477. <p>The most important thing to know is that Synapse 1.0.0 will require a valid TLS
  2478. certificate on federation endpoints. Self signed certificates will not be
  2479. sufficient.</p>
  2480. <p>Synapse 0.99.0 makes it easy to configure TLS certificates and will
  2481. interoperate with both &gt;= 1.0.0 servers as well as existing servers yet to
  2482. upgrade.</p>
  2483. <p><strong>It is critical that all admins upgrade to 0.99.0 and configure a valid TLS
  2484. certificate.</strong> Admins will have 1 month to do so, after which 1.0.0 will be
  2485. released and those servers without a valid certificate will not longer be able
  2486. to federate with &gt;= 1.0.0 servers.</p>
  2487. <p>Full details on how to carry out this configuration change is given
  2488. <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">below</a>. A
  2489. timeline and some frequently asked questions are also given below.</p>
  2490. <p>For more details and context on the release of the r0.1 Server/Server API and
  2491. imminent Matrix 1.0 release, you can also see our
  2492. <a href="https://matrix.org/blog/2019/02/04/matrix-at-fosdem-2019/">main talk from FOSDEM 2019</a>.</p>
  2493. <h2 id="contents"><a class="header" href="#contents">Contents</a></h2>
  2494. <ul>
  2495. <li>Timeline</li>
  2496. <li>Configuring certificates for compatibility with Synapse 1.0</li>
  2497. <li>FAQ
  2498. <ul>
  2499. <li>Synapse 0.99.0 has just been released, what do I need to do right now?</li>
  2500. <li>How do I upgrade?</li>
  2501. <li>What will happen if I do not set up a valid federation certificate
  2502. immediately?</li>
  2503. <li>What will happen if I do nothing at all?</li>
  2504. <li>When do I need a SRV record or .well-known URI?</li>
  2505. <li>Can I still use an SRV record?</li>
  2506. <li>I have created a .well-known URI. Do I still need an SRV record?</li>
  2507. <li>It used to work just fine, why are you breaking everything?</li>
  2508. <li>Can I manage my own certificates rather than having Synapse renew
  2509. certificates itself?</li>
  2510. <li>Do you still recommend against using a reverse proxy on the federation port?</li>
  2511. <li>Do I still need to give my TLS certificates to Synapse if I am using a
  2512. reverse proxy?</li>
  2513. <li>Do I need the same certificate for the client and federation port?</li>
  2514. <li>How do I tell Synapse to reload my keys/certificates after I replace them?</li>
  2515. </ul>
  2516. </li>
  2517. </ul>
  2518. <h2 id="timeline"><a class="header" href="#timeline">Timeline</a></h2>
  2519. <p><strong>5th Feb 2019 - Synapse 0.99.0 is released.</strong></p>
  2520. <p>All server admins are encouraged to upgrade.</p>
  2521. <p>0.99.0:</p>
  2522. <ul>
  2523. <li>
  2524. <p>provides support for ACME to make setting up Let's Encrypt certs easy, as
  2525. well as .well-known support.</p>
  2526. </li>
  2527. <li>
  2528. <p>does not enforce that a valid CA cert is present on the federation API, but
  2529. rather makes it easy to set one up.</p>
  2530. </li>
  2531. <li>
  2532. <p>provides support for .well-known</p>
  2533. </li>
  2534. </ul>
  2535. <p>Admins should upgrade and configure a valid CA cert. Homeservers that require a
  2536. .well-known entry (see below), should retain their SRV record and use it
  2537. alongside their .well-known record.</p>
  2538. <p><strong>10th June 2019 - Synapse 1.0.0 is released</strong></p>
  2539. <p>1.0.0 is scheduled for release on 10th June. In
  2540. accordance with the the <a href="https://matrix.org/docs/spec/server_server/r0.1.0.html">S2S spec</a>
  2541. 1.0.0 will enforce certificate validity. This means that any homeserver without a
  2542. valid certificate after this point will no longer be able to federate with
  2543. 1.0.0 servers.</p>
  2544. <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>
  2545. <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>
  2546. <p>In this case, your <code>server_name</code> points to the host where your Synapse is
  2547. running. There is no need to create a <code>.well-known</code> URI or an SRV record, but
  2548. you will need to give Synapse a valid, signed, certificate.</p>
  2549. <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>
  2550. <p>If you are using an SRV record, your matrix domain (<code>server_name</code>) may not
  2551. point to the same host that your Synapse is running on (the 'target
  2552. domain'). (If it does, you can follow the recommendation above; otherwise, read
  2553. on.)</p>
  2554. <p>Let's assume that your <code>server_name</code> is <code>example.com</code>, and your Synapse is
  2555. hosted at a target domain of <code>customer.example.net</code>. Currently you should have
  2556. an SRV record which looks like:</p>
  2557. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 8000 customer.example.net.
  2558. </code></pre>
  2559. <p>In this situation, you have three choices for how to proceed:</p>
  2560. <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>
  2561. <p>Synapse 1.0 will expect your server to present a TLS certificate for your
  2562. <code>server_name</code> (<code>example.com</code> in the above example). You can achieve this by acquiring a
  2563. certificate for the <code>server_name</code> yourself (for example, using <code>certbot</code>), and giving it
  2564. and the key to Synapse via <code>tls_certificate_path</code> and <code>tls_private_key_path</code>.</p>
  2565. <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>
  2566. <p>If you have an existing reverse proxy set up with correct TLS certificates for
  2567. your domain, you can simply route all traffic through the reverse proxy by
  2568. updating the SRV record appropriately (or removing it, if the proxy listens on
  2569. 8448).</p>
  2570. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2571. reverse proxy.</p>
  2572. <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>
  2573. <p>This will allow you to keep Synapse on a separate domain, without having to
  2574. give it a certificate for the matrix domain.</p>
  2575. <p>You can do this with a <code>.well-known</code> file as follows:</p>
  2576. <ol>
  2577. <li>
  2578. <p>Keep the SRV record in place - it is needed for backwards compatibility
  2579. with Synapse 0.34 and earlier.</p>
  2580. </li>
  2581. <li>
  2582. <p>Give Synapse a certificate corresponding to the target domain
  2583. (<code>customer.example.net</code> in the above example). You can do this by acquire a
  2584. certificate for the target domain and giving it to Synapse via <code>tls_certificate_path</code>
  2585. and <code>tls_private_key_path</code>.</p>
  2586. </li>
  2587. <li>
  2588. <p>Restart Synapse to ensure the new certificate is loaded.</p>
  2589. </li>
  2590. <li>
  2591. <p>Arrange for a <code>.well-known</code> file at
  2592. <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> with contents:</p>
  2593. <pre><code class="language-json">{&quot;m.server&quot;: &quot;&lt;target server name&gt;&quot;}
  2594. </code></pre>
  2595. <p>where the target server name is resolved as usual (i.e. SRV lookup, falling
  2596. back to talking to port 8448).</p>
  2597. <p>In the above example, where synapse is listening on port 8000,
  2598. <code>https://example.com/.well-known/matrix/server</code> should have <code>m.server</code> set to one of:</p>
  2599. <ol>
  2600. <li>
  2601. <p><code>customer.example.net</code> ─ with a SRV record on
  2602. <code>_matrix._tcp.customer.example.com</code> pointing to port 8000, or:</p>
  2603. </li>
  2604. <li>
  2605. <p><code>customer.example.net</code> ─ updating synapse to listen on the default port
  2606. 8448, or:</p>
  2607. </li>
  2608. <li>
  2609. <p><code>customer.example.net:8000</code> ─ ensuring that if there is a reverse proxy
  2610. on <code>customer.example.net:8000</code> it correctly handles HTTP requests with
  2611. Host header set to <code>customer.example.net:8000</code>.</p>
  2612. </li>
  2613. </ol>
  2614. </li>
  2615. </ol>
  2616. <h2 id="faq"><a class="header" href="#faq">FAQ</a></h2>
  2617. <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>
  2618. <p>Upgrade as soon as you can in preparation for Synapse 1.0.0, and update your
  2619. TLS certificates as <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">above</a>.</p>
  2620. <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>
  2621. <p>Nothing initially, but once 1.0.0 is in the wild it will not be possible to
  2622. federate with 1.0.0 servers.</p>
  2623. <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>
  2624. <p>If the admin takes no action at all, and remains on a Synapse &lt; 0.99.0 then the
  2625. homeserver will be unable to federate with those who have implemented
  2626. .well-known. Then, as above, once the month upgrade window has expired the
  2627. homeserver will not be able to federate with any Synapse &gt;= 1.0.0</p>
  2628. <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>
  2629. <p>If your homeserver listens on the default federation port (8448), and your
  2630. <code>server_name</code> points to the host that your homeserver runs on, you do not need an
  2631. SRV record or <code>.well-known/matrix/server</code> URI.</p>
  2632. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  2633. fresh Upcloud VPS or similar, you could install Synapse 0.99 on that host,
  2634. giving it a server_name of <code>example.com</code>, and it would automatically generate a
  2635. valid TLS certificate for you via Let's Encrypt and no SRV record or
  2636. <code>.well-known</code> URI would be needed.</p>
  2637. <p>This is the common case, although you can add an SRV record or
  2638. <code>.well-known/matrix/server</code> URI for completeness if you wish.</p>
  2639. <p><strong>However</strong>, if your server does not listen on port 8448, or if your <code>server_name</code>
  2640. does not point to the host that your homeserver runs on, you will need to let
  2641. other servers know how to find it.</p>
  2642. <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
  2643. currently&quot;</a> above.</p>
  2644. <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>
  2645. <p>Firstly, if you didn't need an SRV record before (because your server is
  2646. listening on port 8448 of your server_name), you certainly don't need one now:
  2647. the defaults are still the same.</p>
  2648. <p>If you previously had an SRV record, you can keep using it provided you are
  2649. able to give Synapse a TLS certificate corresponding to your server name. For
  2650. example, suppose you had the following SRV record, which directs matrix traffic
  2651. for example.com to matrix.example.com:443:</p>
  2652. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 443 matrix.example.com
  2653. </code></pre>
  2654. <p>In this case, Synapse must be given a certificate for example.com - or be
  2655. configured to acquire one from Let's Encrypt.</p>
  2656. <p>If you are unable to give Synapse a certificate for your server_name, you will
  2657. also need to use a .well-known URI instead. However, see also &quot;I have created a
  2658. .well-known URI. Do I still need an SRV record?&quot;.</p>
  2659. <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>
  2660. <p>As of Synapse 0.99, Synapse will first check for the existence of a <code>.well-known</code>
  2661. URI and follow any delegation it suggests. It will only then check for the
  2662. existence of an SRV record.</p>
  2663. <p>That means that the SRV record will often be redundant. However, you should
  2664. remember that there may still be older versions of Synapse in the federation
  2665. which do not understand <code>.well-known</code> URIs, so if you removed your SRV record you
  2666. would no longer be able to federate with them.</p>
  2667. <p>It is therefore best to leave the SRV record in place for now. Synapse 0.34 and
  2668. earlier will follow the SRV record (and not care about the invalid
  2669. certificate). Synapse 0.99 and later will follow the .well-known URI, with the
  2670. correct certificate chain.</p>
  2671. <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>
  2672. <p>We have always wanted Matrix servers to be as easy to set up as possible, and
  2673. so back when we started federation in 2014 we didn't want admins to have to go
  2674. through the cumbersome process of buying a valid TLS certificate to run a
  2675. server. This was before Let's Encrypt came along and made getting a free and
  2676. valid TLS certificate straightforward. So instead, we adopted a system based on
  2677. <a href="https://en.wikipedia.org/wiki/Convergence_(SSL)">Perspectives</a>: an approach
  2678. where you check a set of &quot;notary servers&quot; (in practice, homeservers) to vouch
  2679. for the validity of a certificate rather than having it signed by a CA. As long
  2680. as enough different notaries agree on the certificate's validity, then it is
  2681. trusted.</p>
  2682. <p>However, in practice this has never worked properly. Most people only use the
  2683. default notary server (matrix.org), leading to inadvertent centralisation which
  2684. we want to eliminate. Meanwhile, we never implemented the full consensus
  2685. algorithm to query the servers participating in a room to determine consensus
  2686. on whether a given certificate is valid. This is fiddly to get right
  2687. (especially in face of sybil attacks), and we found ourselves questioning
  2688. whether it was worth the effort to finish the work and commit to maintaining a
  2689. secure certificate validation system as opposed to focusing on core Matrix
  2690. development.</p>
  2691. <p>Meanwhile, Let's Encrypt came along in 2016, and put the final nail in the
  2692. coffin of the Perspectives project (which was already pretty dead). So, the
  2693. Spec Core Team decided that a better approach would be to mandate valid TLS
  2694. certificates for federation alongside the rest of the Web. More details can be
  2695. found in
  2696. <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>
  2697. <p>This results in a breaking change, which is disruptive, but absolutely critical
  2698. for the security model. However, the existence of Let's Encrypt as a trivial
  2699. way to replace the old self-signed certificates with valid CA-signed ones helps
  2700. smooth things over massively, especially as Synapse can now automate Let's
  2701. Encrypt certificate generation if needed.</p>
  2702. <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>
  2703. <p>Yes, you are welcome to manage your certificates yourself. Synapse will only
  2704. attempt to obtain certificates from Let's Encrypt if you configure it to do
  2705. so.The only requirement is that there is a valid TLS cert present for
  2706. federation end points.</p>
  2707. <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>
  2708. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  2709. find it easier to direct federation traffic to a reverse proxy and manage their
  2710. own TLS certificates, and this is a supported configuration.</p>
  2711. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2712. reverse proxy.</p>
  2713. <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>
  2714. <p>Practically speaking, this is no longer necessary.</p>
  2715. <p>If you are using a reverse proxy for all of your TLS traffic, then you can set
  2716. <code>no_tls: True</code>. In that case, the only reason Synapse needs the certificate is
  2717. to populate a legacy 'tls_fingerprints' field in the federation API. This is
  2718. ignored by Synapse 0.99.0 and later, and the only time pre-0.99 Synapses will
  2719. check it is when attempting to fetch the server keys - and generally this is
  2720. delegated via <code>matrix.org</code>, which is on 0.99.0.</p>
  2721. <p>However, there is a bug in Synapse 0.99.0
  2722. <a href="https://github.com/matrix-org/synapse/issues/4554">4554</a> which prevents
  2723. Synapse from starting if you do not give it a TLS certificate. To work around
  2724. this, you can give it any TLS certificate at all. This will be fixed soon.</p>
  2725. <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>
  2726. <p>No. There is nothing stopping you from using different certificates,
  2727. particularly if you are using a reverse proxy. However, Synapse will use the
  2728. same certificate on any ports where TLS is configured.</p>
  2729. <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>
  2730. <p>Synapse will reload the keys and certificates when it receives a SIGHUP - for
  2731. example <code>kill -HUP $(cat homeserver.pid)</code>. Alternatively, simply restart
  2732. Synapse, though this will result in downtime while it restarts.</p>
  2733. <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>
  2734. <p>Federation is the process by which users on different servers can participate
  2735. in the same room. For this to work, those other servers must be able to contact
  2736. yours to send messages.</p>
  2737. <p>The <code>server_name</code> configured in the Synapse configuration file (often
  2738. <code>homeserver.yaml</code>) defines how resources (users, rooms, etc.) will be
  2739. identified (eg: <code>@user:example.com</code>, <code>#room:example.com</code>). By default,
  2740. it is also the domain that other servers will use to try to reach your
  2741. server (via port 8448). This is easy to set up and will work provided
  2742. you set the <code>server_name</code> to match your machine's public DNS hostname.</p>
  2743. <p>For this default configuration to work, you will need to listen for TLS
  2744. connections on port 8448. The preferred way to do that is by using a
  2745. reverse proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions
  2746. on how to correctly set one up.</p>
  2747. <p>In some cases you might not want to run Synapse on the machine that has
  2748. the <code>server_name</code> as its public DNS hostname, or you might want federation
  2749. traffic to use a different port than 8448. For example, you might want to
  2750. have your user names look like <code>@user:example.com</code>, but you want to run
  2751. Synapse on <code>synapse.example.com</code> on port 443. This can be done using
  2752. delegation, which allows an admin to control where federation traffic should
  2753. be sent. See <a href="delegate.html">the delegation documentation</a> for instructions on how to set this up.</p>
  2754. <p>Once federation has been configured, you should be able to join a room over
  2755. federation. A good place to start is <code>#synapse:matrix.org</code> - a room for
  2756. Synapse admins.</p>
  2757. <h2 id="troubleshooting-2"><a class="header" href="#troubleshooting-2">Troubleshooting</a></h2>
  2758. <p>You can use the <a href="https://matrix.org/federationtester">federation tester</a>
  2759. to check if your homeserver is configured correctly. Alternatively try the
  2760. <a href="https://matrix.org/federationtester/api/report?server_name=DOMAIN">JSON API used by the federation tester</a>.
  2761. Note that you'll have to modify this URL to replace <code>DOMAIN</code> with your
  2762. <code>server_name</code>. Hitting the API directly provides extra detail.</p>
  2763. <p>The typical failure mode for federation is that when the server tries to join
  2764. a room, it is rejected with &quot;401: Unauthorized&quot;. Generally this means that other
  2765. servers in the room could not access yours. (Joining a room over federation is
  2766. a complicated dance which requires connections in both directions).</p>
  2767. <p>Another common problem is that people on other servers can't join rooms that
  2768. you invite them to. This can be caused by an incorrectly-configured reverse
  2769. proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions on how
  2770. to correctly configure a reverse proxy.</p>
  2771. <h3 id="known-issues"><a class="header" href="#known-issues">Known issues</a></h3>
  2772. <p><strong>HTTP <code>308 Permanent Redirect</code> redirects are not followed</strong>: Due to missing features
  2773. in the HTTP library used by Synapse, 308 redirects are currently not followed by
  2774. federating servers, which can cause <code>M_UNKNOWN</code> or <code>401 Unauthorized</code> errors. This
  2775. may affect users who are redirecting apex-to-www (e.g. <code>example.com</code> -&gt; <code>www.example.com</code>),
  2776. and especially users of the Kubernetes <em>Nginx Ingress</em> module, which uses 308 redirect
  2777. codes by default. For those Kubernetes users, <a href="https://stackoverflow.com/a/52617528/5096871">this Stackoverflow post</a>
  2778. might be helpful. For other users, switching to a <code>301 Moved Permanently</code> code may be
  2779. an option. 308 redirect codes will be supported properly in a future
  2780. release of Synapse.</p>
  2781. <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>
  2782. <p>If you want to get up and running quickly with a trio of homeservers in a
  2783. private federation, there is a script in the <code>demo</code> directory. This is mainly
  2784. useful just for development purposes. See <a href="https://github.com/matrix-org/synapse/tree/develop/demo/">demo/README</a>.</p>
  2785. <div style="break-before: page; page-break-before: always;"></div><h1 id="configuration-1"><a class="header" href="#configuration-1">Configuration</a></h1>
  2786. <p>This section contains information on tweaking Synapse via the various options in the configuration file. A configuration
  2787. file should have been generated when you <a href="usage/configuration/../../setup/installation.html">installed Synapse</a>.</p>
  2788. <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>
  2789. <p>Below is a sample homeserver configuration file. The homeserver configuration file
  2790. can be tweaked to change the behaviour of your homeserver. A restart of the server is
  2791. generally required to apply any changes made to this file.</p>
  2792. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  2793. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  2794. a fresh config using Synapse by following the instructions in
  2795. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  2796. <pre><code class="language-yaml"># This file is maintained as an up-to-date snapshot of the default
  2797. # homeserver.yaml configuration generated by Synapse.
  2798. #
  2799. # It is intended to act as a reference for the default configuration,
  2800. # helping admins keep track of new options and other changes, and compare
  2801. # their configs with the current default. As such, many of the actual
  2802. # config values shown are placeholders.
  2803. #
  2804. # It is *not* intended to be copied and used as the basis for a real
  2805. # homeserver.yaml. Instead, if you are starting from scratch, please generate
  2806. # a fresh config using Synapse by following the instructions in
  2807. # https://matrix-org.github.io/synapse/latest/setup/installation.html.
  2808. # Configuration options that take a time period can be set using a number
  2809. # followed by a letter. Letters have the following meanings:
  2810. # s = second
  2811. # m = minute
  2812. # h = hour
  2813. # d = day
  2814. # w = week
  2815. # y = year
  2816. # For example, setting redaction_retention_period: 5m would remove redacted
  2817. # messages from the database after 5 minutes, rather than 5 months.
  2818. ################################################################################
  2819. # Configuration file for Synapse.
  2820. #
  2821. # This is a YAML file: see [1] for a quick introduction. Note in particular
  2822. # that *indentation is important*: all the elements of a list or dictionary
  2823. # should have the same indentation.
  2824. #
  2825. # [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  2826. ## Modules ##
  2827. # Server admins can expand Synapse's functionality with external modules.
  2828. #
  2829. # See https://matrix-org.github.io/synapse/latest/modules.html for more
  2830. # documentation on how to configure or create custom modules for Synapse.
  2831. #
  2832. modules:
  2833. # - module: my_super_module.MySuperClass
  2834. # config:
  2835. # do_thing: true
  2836. # - module: my_other_super_module.SomeClass
  2837. # config: {}
  2838. ## Server ##
  2839. # The public-facing domain of the server
  2840. #
  2841. # The server_name name will appear at the end of usernames and room addresses
  2842. # created on this server. For example if the server_name was example.com,
  2843. # usernames on this server would be in the format @user:example.com
  2844. #
  2845. # In most cases you should avoid using a matrix specific subdomain such as
  2846. # matrix.example.com or synapse.example.com as the server_name for the same
  2847. # reasons you wouldn't use user@email.example.com as your email address.
  2848. # See https://matrix-org.github.io/synapse/latest/delegate.html
  2849. # for information on how to host Synapse on a subdomain while preserving
  2850. # a clean server_name.
  2851. #
  2852. # The server_name cannot be changed later so it is important to
  2853. # configure this correctly before you start Synapse. It should be all
  2854. # lowercase and may contain an explicit port.
  2855. # Examples: matrix.org, localhost:8080
  2856. #
  2857. server_name: &quot;SERVERNAME&quot;
  2858. # When running as a daemon, the file to store the pid in
  2859. #
  2860. pid_file: DATADIR/homeserver.pid
  2861. # The absolute URL to the web client which /_matrix/client will redirect
  2862. # to if 'webclient' is configured under the 'listeners' configuration.
  2863. #
  2864. # This option can be also set to the filesystem path to the web client
  2865. # which will be served at /_matrix/client/ if 'webclient' is configured
  2866. # under the 'listeners' configuration, however this is a security risk:
  2867. # https://github.com/matrix-org/synapse#security-note
  2868. #
  2869. #web_client_location: https://riot.example.com/
  2870. # The public-facing base URL that clients use to access this Homeserver (not
  2871. # including _matrix/...). This is the same URL a user might enter into the
  2872. # 'Custom Homeserver URL' field on their client. If you use Synapse with a
  2873. # reverse proxy, this should be the URL to reach Synapse via the proxy.
  2874. # Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
  2875. # 'listeners' below).
  2876. #
  2877. #public_baseurl: https://example.com/
  2878. # Set the soft limit on the number of file descriptors synapse can use
  2879. # Zero is used to indicate synapse should set the soft limit to the
  2880. # hard limit.
  2881. #
  2882. #soft_file_limit: 0
  2883. # Presence tracking allows users to see the state (e.g online/offline)
  2884. # of other local and remote users.
  2885. #
  2886. presence:
  2887. # Uncomment to disable presence tracking on this homeserver. This option
  2888. # replaces the previous top-level 'use_presence' option.
  2889. #
  2890. #enabled: false
  2891. # Presence routers are third-party modules that can specify additional logic
  2892. # to where presence updates from users are routed.
  2893. #
  2894. presence_router:
  2895. # The custom module's class. Uncomment to use a custom presence router module.
  2896. #
  2897. #module: &quot;my_custom_router.PresenceRouter&quot;
  2898. # Configuration options of the custom module. Refer to your module's
  2899. # documentation for available options.
  2900. #
  2901. #config:
  2902. # example_option: 'something'
  2903. # Whether to require authentication to retrieve profile data (avatars,
  2904. # display names) of other users through the client API. Defaults to
  2905. # 'false'. Note that profile data is also available via the federation
  2906. # API, unless allow_profile_lookup_over_federation is set to false.
  2907. #
  2908. #require_auth_for_profile_requests: true
  2909. # Uncomment to require a user to share a room with another user in order
  2910. # to retrieve their profile information. Only checked on Client-Server
  2911. # requests. Profile requests from other servers should be checked by the
  2912. # requesting server. Defaults to 'false'.
  2913. #
  2914. #limit_profile_requests_to_users_who_share_rooms: true
  2915. # Uncomment to prevent a user's profile data from being retrieved and
  2916. # displayed in a room until they have joined it. By default, a user's
  2917. # profile data is included in an invite event, regardless of the values
  2918. # of the above two settings, and whether or not the users share a server.
  2919. # Defaults to 'true'.
  2920. #
  2921. #include_profile_data_on_invite: false
  2922. # If set to 'true', removes the need for authentication to access the server's
  2923. # public rooms directory through the client API, meaning that anyone can
  2924. # query the room directory. Defaults to 'false'.
  2925. #
  2926. #allow_public_rooms_without_auth: true
  2927. # If set to 'true', allows any other homeserver to fetch the server's public
  2928. # rooms directory via federation. Defaults to 'false'.
  2929. #
  2930. #allow_public_rooms_over_federation: true
  2931. # The default room version for newly created rooms.
  2932. #
  2933. # Known room versions are listed here:
  2934. # https://matrix.org/docs/spec/#complete-list-of-room-versions
  2935. #
  2936. # For example, for room version 1, default_room_version should be set
  2937. # to &quot;1&quot;.
  2938. #
  2939. #default_room_version: &quot;6&quot;
  2940. # The GC threshold parameters to pass to `gc.set_threshold`, if defined
  2941. #
  2942. #gc_thresholds: [700, 10, 10]
  2943. # The minimum time in seconds between each GC for a generation, regardless of
  2944. # the GC thresholds. This ensures that we don't do GC too frequently.
  2945. #
  2946. # A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
  2947. # generation 0 GCs, etc.
  2948. #
  2949. # Defaults to `[1s, 10s, 30s]`.
  2950. #
  2951. #gc_min_interval: [0.5s, 30s, 1m]
  2952. # Set the limit on the returned events in the timeline in the get
  2953. # and sync operations. The default value is 100. -1 means no upper limit.
  2954. #
  2955. # Uncomment the following to increase the limit to 5000.
  2956. #
  2957. #filter_timeline_limit: 5000
  2958. # Whether room invites to users on this server should be blocked
  2959. # (except those sent by local server admins). The default is False.
  2960. #
  2961. #block_non_admin_invites: true
  2962. # Room searching
  2963. #
  2964. # If disabled, new messages will not be indexed for searching and users
  2965. # will receive errors when searching for messages. Defaults to enabled.
  2966. #
  2967. #enable_search: false
  2968. # Prevent outgoing requests from being sent to the following blacklisted IP address
  2969. # CIDR ranges. If this option is not specified then it defaults to private IP
  2970. # address ranges (see the example below).
  2971. #
  2972. # The blacklist applies to the outbound requests for federation, identity servers,
  2973. # push servers, and for checking key validity for third-party invite events.
  2974. #
  2975. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  2976. # listed here, since they correspond to unroutable addresses.)
  2977. #
  2978. # This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
  2979. #
  2980. #ip_range_blacklist:
  2981. # - '127.0.0.0/8'
  2982. # - '10.0.0.0/8'
  2983. # - '172.16.0.0/12'
  2984. # - '192.168.0.0/16'
  2985. # - '100.64.0.0/10'
  2986. # - '192.0.0.0/24'
  2987. # - '169.254.0.0/16'
  2988. # - '192.88.99.0/24'
  2989. # - '198.18.0.0/15'
  2990. # - '192.0.2.0/24'
  2991. # - '198.51.100.0/24'
  2992. # - '203.0.113.0/24'
  2993. # - '224.0.0.0/4'
  2994. # - '::1/128'
  2995. # - 'fe80::/10'
  2996. # - 'fc00::/7'
  2997. # - '2001:db8::/32'
  2998. # - 'ff00::/8'
  2999. # - 'fec0::/10'
  3000. # List of IP address CIDR ranges that should be allowed for federation,
  3001. # identity servers, push servers, and for checking key validity for
  3002. # third-party invite events. This is useful for specifying exceptions to
  3003. # wide-ranging blacklisted target IP ranges - e.g. for communication with
  3004. # a push server only visible in your network.
  3005. #
  3006. # This whitelist overrides ip_range_blacklist and defaults to an empty
  3007. # list.
  3008. #
  3009. #ip_range_whitelist:
  3010. # - '192.168.1.1'
  3011. # List of ports that Synapse should listen on, their purpose and their
  3012. # configuration.
  3013. #
  3014. # Options for each listener include:
  3015. #
  3016. # port: the TCP port to bind to
  3017. #
  3018. # bind_addresses: a list of local addresses to listen on. The default is
  3019. # 'all local interfaces'.
  3020. #
  3021. # type: the type of listener. Normally 'http', but other valid options are:
  3022. # 'manhole' (see https://matrix-org.github.io/synapse/latest/manhole.html),
  3023. # 'metrics' (see https://matrix-org.github.io/synapse/latest/metrics-howto.html),
  3024. # 'replication' (see https://matrix-org.github.io/synapse/latest/workers.html).
  3025. #
  3026. # tls: set to true to enable TLS for this listener. Will use the TLS
  3027. # key/cert specified in tls_private_key_path / tls_certificate_path.
  3028. #
  3029. # x_forwarded: Only valid for an 'http' listener. Set to true to use the
  3030. # X-Forwarded-For header as the client IP. Useful when Synapse is
  3031. # behind a reverse-proxy.
  3032. #
  3033. # resources: Only valid for an 'http' listener. A list of resources to host
  3034. # on this port. Options for each resource are:
  3035. #
  3036. # names: a list of names of HTTP resources. See below for a list of
  3037. # valid resource names.
  3038. #
  3039. # compress: set to true to enable HTTP compression for this resource.
  3040. #
  3041. # additional_resources: Only valid for an 'http' listener. A map of
  3042. # additional endpoints which should be loaded via dynamic modules.
  3043. #
  3044. # Valid resource names are:
  3045. #
  3046. # client: the client-server API (/_matrix/client), and the synapse admin
  3047. # API (/_synapse/admin). Also implies 'media' and 'static'.
  3048. #
  3049. # consent: user consent forms (/_matrix/consent).
  3050. # See https://matrix-org.github.io/synapse/latest/consent_tracking.html.
  3051. #
  3052. # federation: the server-server API (/_matrix/federation). Also implies
  3053. # 'media', 'keys', 'openid'
  3054. #
  3055. # keys: the key discovery API (/_matrix/keys).
  3056. #
  3057. # media: the media API (/_matrix/media).
  3058. #
  3059. # metrics: the metrics interface.
  3060. # See https://matrix-org.github.io/synapse/latest/metrics-howto.html.
  3061. #
  3062. # openid: OpenID authentication.
  3063. #
  3064. # replication: the HTTP replication API (/_synapse/replication).
  3065. # See https://matrix-org.github.io/synapse/latest/workers.html.
  3066. #
  3067. # static: static resources under synapse/static (/_matrix/static). (Mostly
  3068. # useful for 'fallback authentication'.)
  3069. #
  3070. # webclient: A web client. Requires web_client_location to be set.
  3071. #
  3072. listeners:
  3073. # TLS-enabled listener: for when matrix traffic is sent directly to synapse.
  3074. #
  3075. # Disabled by default. To enable it, uncomment the following. (Note that you
  3076. # will also need to give Synapse a TLS key and certificate: see the TLS section
  3077. # below.)
  3078. #
  3079. #- port: 8448
  3080. # type: http
  3081. # tls: true
  3082. # resources:
  3083. # - names: [client, federation]
  3084. # Unsecure HTTP listener: for when matrix traffic passes through a reverse proxy
  3085. # that unwraps TLS.
  3086. #
  3087. # If you plan to use a reverse proxy, please see
  3088. # https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3089. #
  3090. - port: 8008
  3091. tls: false
  3092. type: http
  3093. x_forwarded: true
  3094. bind_addresses: ['::1', '127.0.0.1']
  3095. resources:
  3096. - names: [client, federation]
  3097. compress: false
  3098. # example additional_resources:
  3099. #
  3100. #additional_resources:
  3101. # &quot;/_matrix/my/custom/endpoint&quot;:
  3102. # module: my_module.CustomRequestHandler
  3103. # config: {}
  3104. # Turn on the twisted ssh manhole service on localhost on the given
  3105. # port.
  3106. #
  3107. #- port: 9000
  3108. # bind_addresses: ['::1', '127.0.0.1']
  3109. # type: manhole
  3110. # Forward extremities can build up in a room due to networking delays between
  3111. # homeservers. Once this happens in a large room, calculation of the state of
  3112. # that room can become quite expensive. To mitigate this, once the number of
  3113. # forward extremities reaches a given threshold, Synapse will send an
  3114. # org.matrix.dummy_event event, which will reduce the forward extremities
  3115. # in the room.
  3116. #
  3117. # This setting defines the threshold (i.e. number of forward extremities in the
  3118. # room) at which dummy events are sent. The default value is 10.
  3119. #
  3120. #dummy_events_threshold: 5
  3121. ## Homeserver blocking ##
  3122. # How to reach the server admin, used in ResourceLimitError
  3123. #
  3124. #admin_contact: 'mailto:admin@server.com'
  3125. # Global blocking
  3126. #
  3127. #hs_disabled: false
  3128. #hs_disabled_message: 'Human readable reason for why the HS is blocked'
  3129. # Monthly Active User Blocking
  3130. #
  3131. # Used in cases where the admin or server owner wants to limit to the
  3132. # number of monthly active users.
  3133. #
  3134. # 'limit_usage_by_mau' disables/enables monthly active user blocking. When
  3135. # enabled and a limit is reached the server returns a 'ResourceLimitError'
  3136. # with error type Codes.RESOURCE_LIMIT_EXCEEDED
  3137. #
  3138. # 'max_mau_value' is the hard limit of monthly active users above which
  3139. # the server will start blocking user actions.
  3140. #
  3141. # 'mau_trial_days' is a means to add a grace period for active users. It
  3142. # means that users must be active for this number of days before they
  3143. # can be considered active and guards against the case where lots of users
  3144. # sign up in a short space of time never to return after their initial
  3145. # session.
  3146. #
  3147. # 'mau_limit_alerting' is a means of limiting client side alerting
  3148. # should the mau limit be reached. This is useful for small instances
  3149. # where the admin has 5 mau seats (say) for 5 specific people and no
  3150. # interest increasing the mau limit further. Defaults to True, which
  3151. # means that alerting is enabled
  3152. #
  3153. #limit_usage_by_mau: false
  3154. #max_mau_value: 50
  3155. #mau_trial_days: 2
  3156. #mau_limit_alerting: false
  3157. # If enabled, the metrics for the number of monthly active users will
  3158. # be populated, however no one will be limited. If limit_usage_by_mau
  3159. # is true, this is implied to be true.
  3160. #
  3161. #mau_stats_only: false
  3162. # Sometimes the server admin will want to ensure certain accounts are
  3163. # never blocked by mau checking. These accounts are specified here.
  3164. #
  3165. #mau_limit_reserved_threepids:
  3166. # - medium: 'email'
  3167. # address: 'reserved_user@example.com'
  3168. # Used by phonehome stats to group together related servers.
  3169. #server_context: context
  3170. # Resource-constrained homeserver settings
  3171. #
  3172. # When this is enabled, the room &quot;complexity&quot; will be checked before a user
  3173. # joins a new remote room. If it is above the complexity limit, the server will
  3174. # disallow joining, or will instantly leave.
  3175. #
  3176. # Room complexity is an arbitrary measure based on factors such as the number of
  3177. # users in the room.
  3178. #
  3179. limit_remote_rooms:
  3180. # Uncomment to enable room complexity checking.
  3181. #
  3182. #enabled: true
  3183. # the limit above which rooms cannot be joined. The default is 1.0.
  3184. #
  3185. #complexity: 0.5
  3186. # override the error which is returned when the room is too complex.
  3187. #
  3188. #complexity_error: &quot;This room is too complex.&quot;
  3189. # allow server admins to join complex rooms. Default is false.
  3190. #
  3191. #admins_can_join: true
  3192. # Whether to require a user to be in the room to add an alias to it.
  3193. # Defaults to 'true'.
  3194. #
  3195. #require_membership_for_aliases: false
  3196. # Whether to allow per-room membership profiles through the send of membership
  3197. # events with profile information that differ from the target's global profile.
  3198. # Defaults to 'true'.
  3199. #
  3200. #allow_per_room_profiles: false
  3201. # How long to keep redacted events in unredacted form in the database. After
  3202. # this period redacted events get replaced with their redacted form in the DB.
  3203. #
  3204. # Defaults to `7d`. Set to `null` to disable.
  3205. #
  3206. #redaction_retention_period: 28d
  3207. # How long to track users' last seen time and IPs in the database.
  3208. #
  3209. # Defaults to `28d`. Set to `null` to disable clearing out of old rows.
  3210. #
  3211. #user_ips_max_age: 14d
  3212. # Message retention policy at the server level.
  3213. #
  3214. # Room admins and mods can define a retention period for their rooms using the
  3215. # 'm.room.retention' state event, and server admins can cap this period by setting
  3216. # the 'allowed_lifetime_min' and 'allowed_lifetime_max' config options.
  3217. #
  3218. # If this feature is enabled, Synapse will regularly look for and purge events
  3219. # which are older than the room's maximum retention period. Synapse will also
  3220. # filter events received over federation so that events that should have been
  3221. # purged are ignored and not stored again.
  3222. #
  3223. retention:
  3224. # The message retention policies feature is disabled by default. Uncomment the
  3225. # following line to enable it.
  3226. #
  3227. #enabled: true
  3228. # Default retention policy. If set, Synapse will apply it to rooms that lack the
  3229. # 'm.room.retention' state event. Currently, the value of 'min_lifetime' doesn't
  3230. # matter much because Synapse doesn't take it into account yet.
  3231. #
  3232. #default_policy:
  3233. # min_lifetime: 1d
  3234. # max_lifetime: 1y
  3235. # Retention policy limits. If set, and the state of a room contains a
  3236. # 'm.room.retention' event in its state which contains a 'min_lifetime' or a
  3237. # 'max_lifetime' that's out of these bounds, Synapse will cap the room's policy
  3238. # to these limits when running purge jobs.
  3239. #
  3240. #allowed_lifetime_min: 1d
  3241. #allowed_lifetime_max: 1y
  3242. # Server admins can define the settings of the background jobs purging the
  3243. # events which lifetime has expired under the 'purge_jobs' section.
  3244. #
  3245. # If no configuration is provided, a single job will be set up to delete expired
  3246. # events in every room daily.
  3247. #
  3248. # Each job's configuration defines which range of message lifetimes the job
  3249. # takes care of. For example, if 'shortest_max_lifetime' is '2d' and
  3250. # 'longest_max_lifetime' is '3d', the job will handle purging expired events in
  3251. # rooms whose state defines a 'max_lifetime' that's both higher than 2 days, and
  3252. # lower than or equal to 3 days. Both the minimum and the maximum value of a
  3253. # range are optional, e.g. a job with no 'shortest_max_lifetime' and a
  3254. # 'longest_max_lifetime' of '3d' will handle every room with a retention policy
  3255. # which 'max_lifetime' is lower than or equal to three days.
  3256. #
  3257. # The rationale for this per-job configuration is that some rooms might have a
  3258. # retention policy with a low 'max_lifetime', where history needs to be purged
  3259. # of outdated messages on a more frequent basis than for the rest of the rooms
  3260. # (e.g. every 12h), but not want that purge to be performed by a job that's
  3261. # iterating over every room it knows, which could be heavy on the server.
  3262. #
  3263. # If any purge job is configured, it is strongly recommended to have at least
  3264. # a single job with neither 'shortest_max_lifetime' nor 'longest_max_lifetime'
  3265. # set, or one job without 'shortest_max_lifetime' and one job without
  3266. # 'longest_max_lifetime' set. Otherwise some rooms might be ignored, even if
  3267. # 'allowed_lifetime_min' and 'allowed_lifetime_max' are set, because capping a
  3268. # room's policy to these values is done after the policies are retrieved from
  3269. # Synapse's database (which is done using the range specified in a purge job's
  3270. # configuration).
  3271. #
  3272. #purge_jobs:
  3273. # - longest_max_lifetime: 3d
  3274. # interval: 12h
  3275. # - shortest_max_lifetime: 3d
  3276. # interval: 1d
  3277. # Inhibits the /requestToken endpoints from returning an error that might leak
  3278. # information about whether an e-mail address is in use or not on this
  3279. # homeserver.
  3280. # Note that for some endpoints the error situation is the e-mail already being
  3281. # used, and for others the error is entering the e-mail being unused.
  3282. # If this option is enabled, instead of returning an error, these endpoints will
  3283. # act as if no error happened and return a fake session ID ('sid') to clients.
  3284. #
  3285. #request_token_inhibit_3pid_errors: true
  3286. # A list of domains that the domain portion of 'next_link' parameters
  3287. # must match.
  3288. #
  3289. # This parameter is optionally provided by clients while requesting
  3290. # validation of an email or phone number, and maps to a link that
  3291. # users will be automatically redirected to after validation
  3292. # succeeds. Clients can make use this parameter to aid the validation
  3293. # process.
  3294. #
  3295. # The whitelist is applied whether the homeserver or an
  3296. # identity server is handling validation.
  3297. #
  3298. # The default value is no whitelist functionality; all domains are
  3299. # allowed. Setting this value to an empty list will instead disallow
  3300. # all domains.
  3301. #
  3302. #next_link_domain_whitelist: [&quot;matrix.org&quot;]
  3303. ## TLS ##
  3304. # PEM-encoded X509 certificate for TLS.
  3305. # This certificate, as of Synapse 1.0, will need to be a valid and verifiable
  3306. # certificate, signed by a recognised Certificate Authority.
  3307. #
  3308. # Be sure to use a `.pem` file that includes the full certificate chain including
  3309. # any intermediate certificates (for instance, if using certbot, use
  3310. # `fullchain.pem` as your certificate, not `cert.pem`).
  3311. #
  3312. #tls_certificate_path: &quot;CONFDIR/SERVERNAME.tls.crt&quot;
  3313. # PEM-encoded private key for TLS
  3314. #
  3315. #tls_private_key_path: &quot;CONFDIR/SERVERNAME.tls.key&quot;
  3316. # Whether to verify TLS server certificates for outbound federation requests.
  3317. #
  3318. # Defaults to `true`. To disable certificate verification, uncomment the
  3319. # following line.
  3320. #
  3321. #federation_verify_certificates: false
  3322. # The minimum TLS version that will be used for outbound federation requests.
  3323. #
  3324. # Defaults to `1`. Configurable to `1`, `1.1`, `1.2`, or `1.3`. Note
  3325. # that setting this value higher than `1.2` will prevent federation to most
  3326. # of the public Matrix network: only configure it to `1.3` if you have an
  3327. # entirely private federation setup and you can ensure TLS 1.3 support.
  3328. #
  3329. #federation_client_minimum_tls_version: 1.2
  3330. # Skip federation certificate verification on the following whitelist
  3331. # of domains.
  3332. #
  3333. # This setting should only be used in very specific cases, such as
  3334. # federation over Tor hidden services and similar. For private networks
  3335. # of homeservers, you likely want to use a private CA instead.
  3336. #
  3337. # Only effective if federation_verify_certicates is `true`.
  3338. #
  3339. #federation_certificate_verification_whitelist:
  3340. # - lon.example.com
  3341. # - *.domain.com
  3342. # - *.onion
  3343. # List of custom certificate authorities for federation traffic.
  3344. #
  3345. # This setting should only normally be used within a private network of
  3346. # homeservers.
  3347. #
  3348. # Note that this list will replace those that are provided by your
  3349. # operating environment. Certificates must be in PEM format.
  3350. #
  3351. #federation_custom_ca_list:
  3352. # - myCA1.pem
  3353. # - myCA2.pem
  3354. # - myCA3.pem
  3355. ## Federation ##
  3356. # Restrict federation to the following whitelist of domains.
  3357. # N.B. we recommend also firewalling your federation listener to limit
  3358. # inbound federation traffic as early as possible, rather than relying
  3359. # purely on this application-layer restriction. If not specified, the
  3360. # default is to whitelist everything.
  3361. #
  3362. #federation_domain_whitelist:
  3363. # - lon.example.com
  3364. # - nyc.example.com
  3365. # - syd.example.com
  3366. # Report prometheus metrics on the age of PDUs being sent to and received from
  3367. # the following domains. This can be used to give an idea of &quot;delay&quot; on inbound
  3368. # and outbound federation, though be aware that any delay can be due to problems
  3369. # at either end or with the intermediate network.
  3370. #
  3371. # By default, no domains are monitored in this way.
  3372. #
  3373. #federation_metrics_domains:
  3374. # - matrix.org
  3375. # - example.com
  3376. # Uncomment to disable profile lookup over federation. By default, the
  3377. # Federation API allows other homeservers to obtain profile data of any user
  3378. # on this homeserver. Defaults to 'true'.
  3379. #
  3380. #allow_profile_lookup_over_federation: false
  3381. # Uncomment to disable device display name lookup over federation. By default, the
  3382. # Federation API allows other homeservers to obtain device display names of any user
  3383. # on this homeserver. Defaults to 'true'.
  3384. #
  3385. #allow_device_name_lookup_over_federation: false
  3386. ## Caching ##
  3387. # Caching can be configured through the following options.
  3388. #
  3389. # A cache 'factor' is a multiplier that can be applied to each of
  3390. # Synapse's caches in order to increase or decrease the maximum
  3391. # number of entries that can be stored.
  3392. # The number of events to cache in memory. Not affected by
  3393. # caches.global_factor.
  3394. #
  3395. #event_cache_size: 10K
  3396. caches:
  3397. # Controls the global cache factor, which is the default cache factor
  3398. # for all caches if a specific factor for that cache is not otherwise
  3399. # set.
  3400. #
  3401. # This can also be set by the &quot;SYNAPSE_CACHE_FACTOR&quot; environment
  3402. # variable. Setting by environment variable takes priority over
  3403. # setting through the config file.
  3404. #
  3405. # Defaults to 0.5, which will half the size of all caches.
  3406. #
  3407. #global_factor: 1.0
  3408. # A dictionary of cache name to cache factor for that individual
  3409. # cache. Overrides the global cache factor for a given cache.
  3410. #
  3411. # These can also be set through environment variables comprised
  3412. # of &quot;SYNAPSE_CACHE_FACTOR_&quot; + the name of the cache in capital
  3413. # letters and underscores. Setting by environment variable
  3414. # takes priority over setting through the config file.
  3415. # Ex. SYNAPSE_CACHE_FACTOR_GET_USERS_WHO_SHARE_ROOM_WITH_USER=2.0
  3416. #
  3417. # Some caches have '*' and other characters that are not
  3418. # alphanumeric or underscores. These caches can be named with or
  3419. # without the special characters stripped. For example, to specify
  3420. # the cache factor for `*stateGroupCache*` via an environment
  3421. # variable would be `SYNAPSE_CACHE_FACTOR_STATEGROUPCACHE=2.0`.
  3422. #
  3423. per_cache_factors:
  3424. #get_users_who_share_room_with_user: 2.0
  3425. # Controls how long an entry can be in a cache without having been
  3426. # accessed before being evicted. Defaults to None, which means
  3427. # entries are never evicted based on time.
  3428. #
  3429. #expiry_time: 30m
  3430. ## Database ##
  3431. # The 'database' setting defines the database that synapse uses to store all of
  3432. # its data.
  3433. #
  3434. # 'name' gives the database engine to use: either 'sqlite3' (for SQLite) or
  3435. # 'psycopg2' (for PostgreSQL).
  3436. #
  3437. # 'args' gives options which are passed through to the database engine,
  3438. # except for options starting 'cp_', which are used to configure the Twisted
  3439. # connection pool. For a reference to valid arguments, see:
  3440. # * for sqlite: https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
  3441. # * for postgres: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
  3442. # * for the connection pool: https://twistedmatrix.com/documents/current/api/twisted.enterprise.adbapi.ConnectionPool.html#__init__
  3443. #
  3444. #
  3445. # Example SQLite configuration:
  3446. #
  3447. #database:
  3448. # name: sqlite3
  3449. # args:
  3450. # database: /path/to/homeserver.db
  3451. #
  3452. #
  3453. # Example Postgres configuration:
  3454. #
  3455. #database:
  3456. # name: psycopg2
  3457. # args:
  3458. # user: synapse_user
  3459. # password: secretpassword
  3460. # database: synapse
  3461. # host: localhost
  3462. # port: 5432
  3463. # cp_min: 5
  3464. # cp_max: 10
  3465. #
  3466. # For more information on using Synapse with Postgres,
  3467. # see https://matrix-org.github.io/synapse/latest/postgres.html.
  3468. #
  3469. database:
  3470. name: sqlite3
  3471. args:
  3472. database: DATADIR/homeserver.db
  3473. ## Logging ##
  3474. # A yaml python logging config file as described by
  3475. # https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  3476. #
  3477. log_config: &quot;CONFDIR/SERVERNAME.log.config&quot;
  3478. ## Ratelimiting ##
  3479. # Ratelimiting settings for client actions (registration, login, messaging).
  3480. #
  3481. # Each ratelimiting configuration is made of two parameters:
  3482. # - per_second: number of requests a client can send per second.
  3483. # - burst_count: number of requests a client can send before being throttled.
  3484. #
  3485. # Synapse currently uses the following configurations:
  3486. # - one for messages that ratelimits sending based on the account the client
  3487. # is using
  3488. # - one for registration that ratelimits registration requests based on the
  3489. # client's IP address.
  3490. # - one for login that ratelimits login requests based on the client's IP
  3491. # address.
  3492. # - one for login that ratelimits login requests based on the account the
  3493. # client is attempting to log into.
  3494. # - one for login that ratelimits login requests based on the account the
  3495. # client is attempting to log into, based on the amount of failed login
  3496. # attempts for this account.
  3497. # - one for ratelimiting redactions by room admins. If this is not explicitly
  3498. # set then it uses the same ratelimiting as per rc_message. This is useful
  3499. # to allow room admins to deal with abuse quickly.
  3500. # - two for ratelimiting number of rooms a user can join, &quot;local&quot; for when
  3501. # users are joining rooms the server is already in (this is cheap) vs
  3502. # &quot;remote&quot; for when users are trying to join rooms not on the server (which
  3503. # can be more expensive)
  3504. # - one for ratelimiting how often a user or IP can attempt to validate a 3PID.
  3505. # - two for ratelimiting how often invites can be sent in a room or to a
  3506. # specific user.
  3507. #
  3508. # The defaults are as shown below.
  3509. #
  3510. #rc_message:
  3511. # per_second: 0.2
  3512. # burst_count: 10
  3513. #
  3514. #rc_registration:
  3515. # per_second: 0.17
  3516. # burst_count: 3
  3517. #
  3518. #rc_login:
  3519. # address:
  3520. # per_second: 0.17
  3521. # burst_count: 3
  3522. # account:
  3523. # per_second: 0.17
  3524. # burst_count: 3
  3525. # failed_attempts:
  3526. # per_second: 0.17
  3527. # burst_count: 3
  3528. #
  3529. #rc_admin_redaction:
  3530. # per_second: 1
  3531. # burst_count: 50
  3532. #
  3533. #rc_joins:
  3534. # local:
  3535. # per_second: 0.1
  3536. # burst_count: 10
  3537. # remote:
  3538. # per_second: 0.01
  3539. # burst_count: 10
  3540. #
  3541. #rc_3pid_validation:
  3542. # per_second: 0.003
  3543. # burst_count: 5
  3544. #
  3545. #rc_invites:
  3546. # per_room:
  3547. # per_second: 0.3
  3548. # burst_count: 10
  3549. # per_user:
  3550. # per_second: 0.003
  3551. # burst_count: 5
  3552. # Ratelimiting settings for incoming federation
  3553. #
  3554. # The rc_federation configuration is made up of the following settings:
  3555. # - window_size: window size in milliseconds
  3556. # - sleep_limit: number of federation requests from a single server in
  3557. # a window before the server will delay processing the request.
  3558. # - sleep_delay: duration in milliseconds to delay processing events
  3559. # from remote servers by if they go over the sleep limit.
  3560. # - reject_limit: maximum number of concurrent federation requests
  3561. # allowed from a single server
  3562. # - concurrent: number of federation requests to concurrently process
  3563. # from a single server
  3564. #
  3565. # The defaults are as shown below.
  3566. #
  3567. #rc_federation:
  3568. # window_size: 1000
  3569. # sleep_limit: 10
  3570. # sleep_delay: 500
  3571. # reject_limit: 50
  3572. # concurrent: 3
  3573. # Target outgoing federation transaction frequency for sending read-receipts,
  3574. # per-room.
  3575. #
  3576. # If we end up trying to send out more read-receipts, they will get buffered up
  3577. # into fewer transactions.
  3578. #
  3579. #federation_rr_transactions_per_room_per_second: 50
  3580. ## Media Store ##
  3581. # Enable the media store service in the Synapse master. Uncomment the
  3582. # following if you are using a separate media store worker.
  3583. #
  3584. #enable_media_repo: false
  3585. # Directory where uploaded images and attachments are stored.
  3586. #
  3587. media_store_path: &quot;DATADIR/media_store&quot;
  3588. # Media storage providers allow media to be stored in different
  3589. # locations.
  3590. #
  3591. #media_storage_providers:
  3592. # - module: file_system
  3593. # # Whether to store newly uploaded local files
  3594. # store_local: false
  3595. # # Whether to store newly downloaded remote files
  3596. # store_remote: false
  3597. # # Whether to wait for successful storage for local uploads
  3598. # store_synchronous: false
  3599. # config:
  3600. # directory: /mnt/some/other/directory
  3601. # The largest allowed upload size in bytes
  3602. #
  3603. # If you are using a reverse proxy you may also need to set this value in
  3604. # your reverse proxy's config. Notably Nginx has a small max body size by default.
  3605. # See https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3606. #
  3607. #max_upload_size: 50M
  3608. # Maximum number of pixels that will be thumbnailed
  3609. #
  3610. #max_image_pixels: 32M
  3611. # Whether to generate new thumbnails on the fly to precisely match
  3612. # the resolution requested by the client. If true then whenever
  3613. # a new resolution is requested by the client the server will
  3614. # generate a new thumbnail. If false the server will pick a thumbnail
  3615. # from a precalculated list.
  3616. #
  3617. #dynamic_thumbnails: false
  3618. # List of thumbnails to precalculate when an image is uploaded.
  3619. #
  3620. #thumbnail_sizes:
  3621. # - width: 32
  3622. # height: 32
  3623. # method: crop
  3624. # - width: 96
  3625. # height: 96
  3626. # method: crop
  3627. # - width: 320
  3628. # height: 240
  3629. # method: scale
  3630. # - width: 640
  3631. # height: 480
  3632. # method: scale
  3633. # - width: 800
  3634. # height: 600
  3635. # method: scale
  3636. # Is the preview URL API enabled?
  3637. #
  3638. # 'false' by default: uncomment the following to enable it (and specify a
  3639. # url_preview_ip_range_blacklist blacklist).
  3640. #
  3641. #url_preview_enabled: true
  3642. # List of IP address CIDR ranges that the URL preview spider is denied
  3643. # from accessing. There are no defaults: you must explicitly
  3644. # specify a list for URL previewing to work. You should specify any
  3645. # internal services in your network that you do not want synapse to try
  3646. # to connect to, otherwise anyone in any Matrix room could cause your
  3647. # synapse to issue arbitrary GET requests to your internal services,
  3648. # causing serious security issues.
  3649. #
  3650. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3651. # listed here, since they correspond to unroutable addresses.)
  3652. #
  3653. # This must be specified if url_preview_enabled is set. It is recommended that
  3654. # you uncomment the following list as a starting point.
  3655. #
  3656. #url_preview_ip_range_blacklist:
  3657. # - '127.0.0.0/8'
  3658. # - '10.0.0.0/8'
  3659. # - '172.16.0.0/12'
  3660. # - '192.168.0.0/16'
  3661. # - '100.64.0.0/10'
  3662. # - '192.0.0.0/24'
  3663. # - '169.254.0.0/16'
  3664. # - '192.88.99.0/24'
  3665. # - '198.18.0.0/15'
  3666. # - '192.0.2.0/24'
  3667. # - '198.51.100.0/24'
  3668. # - '203.0.113.0/24'
  3669. # - '224.0.0.0/4'
  3670. # - '::1/128'
  3671. # - 'fe80::/10'
  3672. # - 'fc00::/7'
  3673. # - '2001:db8::/32'
  3674. # - 'ff00::/8'
  3675. # - 'fec0::/10'
  3676. # List of IP address CIDR ranges that the URL preview spider is allowed
  3677. # to access even if they are specified in url_preview_ip_range_blacklist.
  3678. # This is useful for specifying exceptions to wide-ranging blacklisted
  3679. # target IP ranges - e.g. for enabling URL previews for a specific private
  3680. # website only visible in your network.
  3681. #
  3682. #url_preview_ip_range_whitelist:
  3683. # - '192.168.1.1'
  3684. # Optional list of URL matches that the URL preview spider is
  3685. # denied from accessing. You should use url_preview_ip_range_blacklist
  3686. # in preference to this, otherwise someone could define a public DNS
  3687. # entry that points to a private IP address and circumvent the blacklist.
  3688. # This is more useful if you know there is an entire shape of URL that
  3689. # you know that will never want synapse to try to spider.
  3690. #
  3691. # Each list entry is a dictionary of url component attributes as returned
  3692. # by urlparse.urlsplit as applied to the absolute form of the URL. See
  3693. # https://docs.python.org/2/library/urlparse.html#urlparse.urlsplit
  3694. # The values of the dictionary are treated as an filename match pattern
  3695. # applied to that component of URLs, unless they start with a ^ in which
  3696. # case they are treated as a regular expression match. If all the
  3697. # specified component matches for a given list item succeed, the URL is
  3698. # blacklisted.
  3699. #
  3700. #url_preview_url_blacklist:
  3701. # # blacklist any URL with a username in its URI
  3702. # - username: '*'
  3703. #
  3704. # # blacklist all *.google.com URLs
  3705. # - netloc: 'google.com'
  3706. # - netloc: '*.google.com'
  3707. #
  3708. # # blacklist all plain HTTP URLs
  3709. # - scheme: 'http'
  3710. #
  3711. # # blacklist http(s)://www.acme.com/foo
  3712. # - netloc: 'www.acme.com'
  3713. # path: '/foo'
  3714. #
  3715. # # blacklist any URL with a literal IPv4 address
  3716. # - netloc: '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  3717. # The largest allowed URL preview spidering size in bytes
  3718. #
  3719. #max_spider_size: 10M
  3720. # A list of values for the Accept-Language HTTP header used when
  3721. # downloading webpages during URL preview generation. This allows
  3722. # Synapse to specify the preferred languages that URL previews should
  3723. # be in when communicating with remote servers.
  3724. #
  3725. # Each value is a IETF language tag; a 2-3 letter identifier for a
  3726. # language, optionally followed by subtags separated by '-', specifying
  3727. # a country or region variant.
  3728. #
  3729. # Multiple values can be provided, and a weight can be added to each by
  3730. # using quality value syntax (;q=). '*' translates to any language.
  3731. #
  3732. # Defaults to &quot;en&quot;.
  3733. #
  3734. # Example:
  3735. #
  3736. # url_preview_accept_language:
  3737. # - en-UK
  3738. # - en-US;q=0.9
  3739. # - fr;q=0.8
  3740. # - *;q=0.7
  3741. #
  3742. url_preview_accept_language:
  3743. # - en
  3744. ## Captcha ##
  3745. # See docs/CAPTCHA_SETUP.md for full details of configuring this.
  3746. # This homeserver's ReCAPTCHA public key. Must be specified if
  3747. # enable_registration_captcha is enabled.
  3748. #
  3749. #recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  3750. # This homeserver's ReCAPTCHA private key. Must be specified if
  3751. # enable_registration_captcha is enabled.
  3752. #
  3753. #recaptcha_private_key: &quot;YOUR_PRIVATE_KEY&quot;
  3754. # Uncomment to enable ReCaptcha checks when registering, preventing signup
  3755. # unless a captcha is answered. Requires a valid ReCaptcha
  3756. # public/private key. Defaults to 'false'.
  3757. #
  3758. #enable_registration_captcha: true
  3759. # The API endpoint to use for verifying m.login.recaptcha responses.
  3760. # Defaults to &quot;https://www.recaptcha.net/recaptcha/api/siteverify&quot;.
  3761. #
  3762. #recaptcha_siteverify_api: &quot;https://my.recaptcha.site&quot;
  3763. ## TURN ##
  3764. # The public URIs of the TURN server to give to clients
  3765. #
  3766. #turn_uris: []
  3767. # The shared secret used to compute passwords for the TURN server
  3768. #
  3769. #turn_shared_secret: &quot;YOUR_SHARED_SECRET&quot;
  3770. # The Username and password if the TURN server needs them and
  3771. # does not use a token
  3772. #
  3773. #turn_username: &quot;TURNSERVER_USERNAME&quot;
  3774. #turn_password: &quot;TURNSERVER_PASSWORD&quot;
  3775. # How long generated TURN credentials last
  3776. #
  3777. #turn_user_lifetime: 1h
  3778. # Whether guests should be allowed to use the TURN server.
  3779. # This defaults to True, otherwise VoIP will be unreliable for guests.
  3780. # However, it does introduce a slight security risk as it allows users to
  3781. # connect to arbitrary endpoints without having first signed up for a
  3782. # valid account (e.g. by passing a CAPTCHA).
  3783. #
  3784. #turn_allow_guests: true
  3785. ## Registration ##
  3786. #
  3787. # Registration can be rate-limited using the parameters in the &quot;Ratelimiting&quot;
  3788. # section of this file.
  3789. # Enable registration for new users.
  3790. #
  3791. #enable_registration: false
  3792. # Time that a user's session remains valid for, after they log in.
  3793. #
  3794. # Note that this is not currently compatible with guest logins.
  3795. #
  3796. # Note also that this is calculated at login time: changes are not applied
  3797. # retrospectively to users who have already logged in.
  3798. #
  3799. # By default, this is infinite.
  3800. #
  3801. #session_lifetime: 24h
  3802. # The user must provide all of the below types of 3PID when registering.
  3803. #
  3804. #registrations_require_3pid:
  3805. # - email
  3806. # - msisdn
  3807. # Explicitly disable asking for MSISDNs from the registration
  3808. # flow (overrides registrations_require_3pid if MSISDNs are set as required)
  3809. #
  3810. #disable_msisdn_registration: true
  3811. # Mandate that users are only allowed to associate certain formats of
  3812. # 3PIDs with accounts on this server.
  3813. #
  3814. #allowed_local_3pids:
  3815. # - medium: email
  3816. # pattern: '^[^@]+@matrix\.org$'
  3817. # - medium: email
  3818. # pattern: '^[^@]+@vector\.im$'
  3819. # - medium: msisdn
  3820. # pattern: '\+44'
  3821. # Enable 3PIDs lookup requests to identity servers from this server.
  3822. #
  3823. #enable_3pid_lookup: true
  3824. # If set, allows registration of standard or admin accounts by anyone who
  3825. # has the shared secret, even if registration is otherwise disabled.
  3826. #
  3827. #registration_shared_secret: &lt;PRIVATE STRING&gt;
  3828. # Set the number of bcrypt rounds used to generate password hash.
  3829. # Larger numbers increase the work factor needed to generate the hash.
  3830. # The default number is 12 (which equates to 2^12 rounds).
  3831. # N.B. that increasing this will exponentially increase the time required
  3832. # to register or login - e.g. 24 =&gt; 2^24 rounds which will take &gt;20 mins.
  3833. #
  3834. #bcrypt_rounds: 12
  3835. # Allows users to register as guests without a password/email/etc, and
  3836. # participate in rooms hosted on this server which have been made
  3837. # accessible to anonymous users.
  3838. #
  3839. #allow_guest_access: false
  3840. # The identity server which we suggest that clients should use when users log
  3841. # in on this server.
  3842. #
  3843. # (By default, no suggestion is made, so it is left up to the client.
  3844. # This setting is ignored unless public_baseurl is also set.)
  3845. #
  3846. #default_identity_server: https://matrix.org
  3847. # Handle threepid (email/phone etc) registration and password resets through a set of
  3848. # *trusted* identity servers. Note that this allows the configured identity server to
  3849. # reset passwords for accounts!
  3850. #
  3851. # Be aware that if `email` is not set, and SMTP options have not been
  3852. # configured in the email config block, registration and user password resets via
  3853. # email will be globally disabled.
  3854. #
  3855. # Additionally, if `msisdn` is not set, registration and password resets via msisdn
  3856. # will be disabled regardless, and users will not be able to associate an msisdn
  3857. # identifier to their account. This is due to Synapse currently not supporting
  3858. # any method of sending SMS messages on its own.
  3859. #
  3860. # To enable using an identity server for operations regarding a particular third-party
  3861. # identifier type, set the value to the URL of that identity server as shown in the
  3862. # examples below.
  3863. #
  3864. # Servers handling the these requests must answer the `/requestToken` endpoints defined
  3865. # by the Matrix Identity Service API specification:
  3866. # https://matrix.org/docs/spec/identity_service/latest
  3867. #
  3868. # If a delegate is specified, the config option public_baseurl must also be filled out.
  3869. #
  3870. account_threepid_delegates:
  3871. #email: https://example.com # Delegate email sending to example.com
  3872. #msisdn: http://localhost:8090 # Delegate SMS sending to this local process
  3873. # Whether users are allowed to change their displayname after it has
  3874. # been initially set. Useful when provisioning users based on the
  3875. # contents of a third-party directory.
  3876. #
  3877. # Does not apply to server administrators. Defaults to 'true'
  3878. #
  3879. #enable_set_displayname: false
  3880. # Whether users are allowed to change their avatar after it has been
  3881. # initially set. Useful when provisioning users based on the contents
  3882. # of a third-party directory.
  3883. #
  3884. # Does not apply to server administrators. Defaults to 'true'
  3885. #
  3886. #enable_set_avatar_url: false
  3887. # Whether users can change the 3PIDs associated with their accounts
  3888. # (email address and msisdn).
  3889. #
  3890. # Defaults to 'true'
  3891. #
  3892. #enable_3pid_changes: false
  3893. # Users who register on this homeserver will automatically be joined
  3894. # to these rooms.
  3895. #
  3896. # By default, any room aliases included in this list will be created
  3897. # as a publicly joinable room when the first user registers for the
  3898. # homeserver. This behaviour can be customised with the settings below.
  3899. # If the room already exists, make certain it is a publicly joinable
  3900. # room. The join rule of the room must be set to 'public'.
  3901. #
  3902. #auto_join_rooms:
  3903. # - &quot;#example:example.com&quot;
  3904. # Where auto_join_rooms are specified, setting this flag ensures that the
  3905. # the rooms exist by creating them when the first user on the
  3906. # homeserver registers.
  3907. #
  3908. # By default the auto-created rooms are publicly joinable from any federated
  3909. # server. Use the autocreate_auto_join_rooms_federated and
  3910. # autocreate_auto_join_room_preset settings below to customise this behaviour.
  3911. #
  3912. # Setting to false means that if the rooms are not manually created,
  3913. # users cannot be auto-joined since they do not exist.
  3914. #
  3915. # Defaults to true. Uncomment the following line to disable automatically
  3916. # creating auto-join rooms.
  3917. #
  3918. #autocreate_auto_join_rooms: false
  3919. # Whether the auto_join_rooms that are auto-created are available via
  3920. # federation. Only has an effect if autocreate_auto_join_rooms is true.
  3921. #
  3922. # Note that whether a room is federated cannot be modified after
  3923. # creation.
  3924. #
  3925. # Defaults to true: the room will be joinable from other servers.
  3926. # Uncomment the following to prevent users from other homeservers from
  3927. # joining these rooms.
  3928. #
  3929. #autocreate_auto_join_rooms_federated: false
  3930. # The room preset to use when auto-creating one of auto_join_rooms. Only has an
  3931. # effect if autocreate_auto_join_rooms is true.
  3932. #
  3933. # This can be one of &quot;public_chat&quot;, &quot;private_chat&quot;, or &quot;trusted_private_chat&quot;.
  3934. # If a value of &quot;private_chat&quot; or &quot;trusted_private_chat&quot; is used then
  3935. # auto_join_mxid_localpart must also be configured.
  3936. #
  3937. # Defaults to &quot;public_chat&quot;, meaning that the room is joinable by anyone, including
  3938. # federated servers if autocreate_auto_join_rooms_federated is true (the default).
  3939. # Uncomment the following to require an invitation to join these rooms.
  3940. #
  3941. #autocreate_auto_join_room_preset: private_chat
  3942. # The local part of the user id which is used to create auto_join_rooms if
  3943. # autocreate_auto_join_rooms is true. If this is not provided then the
  3944. # initial user account that registers will be used to create the rooms.
  3945. #
  3946. # The user id is also used to invite new users to any auto-join rooms which
  3947. # are set to invite-only.
  3948. #
  3949. # It *must* be configured if autocreate_auto_join_room_preset is set to
  3950. # &quot;private_chat&quot; or &quot;trusted_private_chat&quot;.
  3951. #
  3952. # Note that this must be specified in order for new users to be correctly
  3953. # invited to any auto-join rooms which have been set to invite-only (either
  3954. # at the time of creation or subsequently).
  3955. #
  3956. # Note that, if the room already exists, this user must be joined and
  3957. # have the appropriate permissions to invite new members.
  3958. #
  3959. #auto_join_mxid_localpart: system
  3960. # When auto_join_rooms is specified, setting this flag to false prevents
  3961. # guest accounts from being automatically joined to the rooms.
  3962. #
  3963. # Defaults to true.
  3964. #
  3965. #auto_join_rooms_for_guests: false
  3966. ## Metrics ###
  3967. # Enable collection and rendering of performance metrics
  3968. #
  3969. #enable_metrics: false
  3970. # Enable sentry integration
  3971. # NOTE: While attempts are made to ensure that the logs don't contain
  3972. # any sensitive information, this cannot be guaranteed. By enabling
  3973. # this option the sentry server may therefore receive sensitive
  3974. # information, and it in turn may then diseminate sensitive information
  3975. # through insecure notification channels if so configured.
  3976. #
  3977. #sentry:
  3978. # dsn: &quot;...&quot;
  3979. # Flags to enable Prometheus metrics which are not suitable to be
  3980. # enabled by default, either for performance reasons or limited use.
  3981. #
  3982. metrics_flags:
  3983. # Publish synapse_federation_known_servers, a gauge of the number of
  3984. # servers this homeserver knows about, including itself. May cause
  3985. # performance problems on large homeservers.
  3986. #
  3987. #known_servers: true
  3988. # Whether or not to report anonymized homeserver usage statistics.
  3989. #
  3990. #report_stats: true|false
  3991. # The endpoint to report the anonymized homeserver usage statistics to.
  3992. # Defaults to https://matrix.org/report-usage-stats/push
  3993. #
  3994. #report_stats_endpoint: https://example.com/report-usage-stats/push
  3995. ## API Configuration ##
  3996. # Controls for the state that is shared with users who receive an invite
  3997. # to a room
  3998. #
  3999. room_prejoin_state:
  4000. # By default, the following state event types are shared with users who
  4001. # receive invites to the room:
  4002. #
  4003. # - m.room.join_rules
  4004. # - m.room.canonical_alias
  4005. # - m.room.avatar
  4006. # - m.room.encryption
  4007. # - m.room.name
  4008. # - m.room.create
  4009. #
  4010. # Uncomment the following to disable these defaults (so that only the event
  4011. # types listed in 'additional_event_types' are shared). Defaults to 'false'.
  4012. #
  4013. #disable_default_event_types: true
  4014. # Additional state event types to share with users when they are invited
  4015. # to a room.
  4016. #
  4017. # By default, this list is empty (so only the default event types are shared).
  4018. #
  4019. #additional_event_types:
  4020. # - org.example.custom.event.type
  4021. # A list of application service config files to use
  4022. #
  4023. #app_service_config_files:
  4024. # - app_service_1.yaml
  4025. # - app_service_2.yaml
  4026. # Uncomment to enable tracking of application service IP addresses. Implicitly
  4027. # enables MAU tracking for application service users.
  4028. #
  4029. #track_appservice_user_ips: true
  4030. # a secret which is used to sign access tokens. If none is specified,
  4031. # the registration_shared_secret is used, if one is given; otherwise,
  4032. # a secret key is derived from the signing key.
  4033. #
  4034. #macaroon_secret_key: &lt;PRIVATE STRING&gt;
  4035. # a secret which is used to calculate HMACs for form values, to stop
  4036. # falsification of values. Must be specified for the User Consent
  4037. # forms to work.
  4038. #
  4039. #form_secret: &lt;PRIVATE STRING&gt;
  4040. ## Signing Keys ##
  4041. # Path to the signing key to sign messages with
  4042. #
  4043. signing_key_path: &quot;CONFDIR/SERVERNAME.signing.key&quot;
  4044. # The keys that the server used to sign messages with but won't use
  4045. # to sign new messages.
  4046. #
  4047. old_signing_keys:
  4048. # For each key, `key` should be the base64-encoded public key, and
  4049. # `expired_ts`should be the time (in milliseconds since the unix epoch) that
  4050. # it was last used.
  4051. #
  4052. # It is possible to build an entry from an old signing.key file using the
  4053. # `export_signing_key` script which is provided with synapse.
  4054. #
  4055. # For example:
  4056. #
  4057. #&quot;ed25519:id&quot;: { key: &quot;base64string&quot;, expired_ts: 123456789123 }
  4058. # How long key response published by this server is valid for.
  4059. # Used to set the valid_until_ts in /key/v2 APIs.
  4060. # Determines how quickly servers will query to check which keys
  4061. # are still valid.
  4062. #
  4063. #key_refresh_interval: 1d
  4064. # The trusted servers to download signing keys from.
  4065. #
  4066. # When we need to fetch a signing key, each server is tried in parallel.
  4067. #
  4068. # Normally, the connection to the key server is validated via TLS certificates.
  4069. # Additional security can be provided by configuring a `verify key`, which
  4070. # will make synapse check that the response is signed by that key.
  4071. #
  4072. # This setting supercedes an older setting named `perspectives`. The old format
  4073. # is still supported for backwards-compatibility, but it is deprecated.
  4074. #
  4075. # 'trusted_key_servers' defaults to matrix.org, but using it will generate a
  4076. # warning on start-up. To suppress this warning, set
  4077. # 'suppress_key_server_warning' to true.
  4078. #
  4079. # Options for each entry in the list include:
  4080. #
  4081. # server_name: the name of the server. required.
  4082. #
  4083. # verify_keys: an optional map from key id to base64-encoded public key.
  4084. # If specified, we will check that the response is signed by at least
  4085. # one of the given keys.
  4086. #
  4087. # accept_keys_insecurely: a boolean. Normally, if `verify_keys` is unset,
  4088. # and federation_verify_certificates is not `true`, synapse will refuse
  4089. # to start, because this would allow anyone who can spoof DNS responses
  4090. # to masquerade as the trusted key server. If you know what you are doing
  4091. # and are sure that your network environment provides a secure connection
  4092. # to the key server, you can set this to `true` to override this
  4093. # behaviour.
  4094. #
  4095. # An example configuration might look like:
  4096. #
  4097. #trusted_key_servers:
  4098. # - server_name: &quot;my_trusted_server.example.com&quot;
  4099. # verify_keys:
  4100. # &quot;ed25519:auto&quot;: &quot;abcdefghijklmnopqrstuvwxyzabcdefghijklmopqr&quot;
  4101. # - server_name: &quot;my_other_trusted_server.example.com&quot;
  4102. #
  4103. trusted_key_servers:
  4104. - server_name: &quot;matrix.org&quot;
  4105. # Uncomment the following to disable the warning that is emitted when the
  4106. # trusted_key_servers include 'matrix.org'. See above.
  4107. #
  4108. #suppress_key_server_warning: true
  4109. # The signing keys to use when acting as a trusted key server. If not specified
  4110. # defaults to the server signing key.
  4111. #
  4112. # Can contain multiple keys, one per line.
  4113. #
  4114. #key_server_signing_keys_path: &quot;key_server_signing_keys.key&quot;
  4115. ## Single sign-on integration ##
  4116. # The following settings can be used to make Synapse use a single sign-on
  4117. # provider for authentication, instead of its internal password database.
  4118. #
  4119. # You will probably also want to set the following options to `false` to
  4120. # disable the regular login/registration flows:
  4121. # * enable_registration
  4122. # * password_config.enabled
  4123. #
  4124. # You will also want to investigate the settings under the &quot;sso&quot; configuration
  4125. # section below.
  4126. # Enable SAML2 for registration and login. Uses pysaml2.
  4127. #
  4128. # At least one of `sp_config` or `config_path` must be set in this section to
  4129. # enable SAML login.
  4130. #
  4131. # Once SAML support is enabled, a metadata file will be exposed at
  4132. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/metadata.xml, which you may be able to
  4133. # use to configure your SAML IdP with. Alternatively, you can manually configure
  4134. # the IdP to use an ACS location of
  4135. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/authn_response.
  4136. #
  4137. saml2_config:
  4138. # `sp_config` is the configuration for the pysaml2 Service Provider.
  4139. # See pysaml2 docs for format of config.
  4140. #
  4141. # Default values will be used for the 'entityid' and 'service' settings,
  4142. # so it is not normally necessary to specify them unless you need to
  4143. # override them.
  4144. #
  4145. sp_config:
  4146. # Point this to the IdP's metadata. You must provide either a local
  4147. # file via the `local` attribute or (preferably) a URL via the
  4148. # `remote` attribute.
  4149. #
  4150. #metadata:
  4151. # local: [&quot;saml2/idp.xml&quot;]
  4152. # remote:
  4153. # - url: https://our_idp/metadata.xml
  4154. # Allowed clock difference in seconds between the homeserver and IdP.
  4155. #
  4156. # Uncomment the below to increase the accepted time difference from 0 to 3 seconds.
  4157. #
  4158. #accepted_time_diff: 3
  4159. # By default, the user has to go to our login page first. If you'd like
  4160. # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
  4161. # 'service.sp' section:
  4162. #
  4163. #service:
  4164. # sp:
  4165. # allow_unsolicited: true
  4166. # The examples below are just used to generate our metadata xml, and you
  4167. # may well not need them, depending on your setup. Alternatively you
  4168. # may need a whole lot more detail - see the pysaml2 docs!
  4169. #description: [&quot;My awesome SP&quot;, &quot;en&quot;]
  4170. #name: [&quot;Test SP&quot;, &quot;en&quot;]
  4171. #ui_info:
  4172. # display_name:
  4173. # - lang: en
  4174. # text: &quot;Display Name is the descriptive name of your service.&quot;
  4175. # description:
  4176. # - lang: en
  4177. # text: &quot;Description should be a short paragraph explaining the purpose of the service.&quot;
  4178. # information_url:
  4179. # - lang: en
  4180. # text: &quot;https://example.com/terms-of-service&quot;
  4181. # privacy_statement_url:
  4182. # - lang: en
  4183. # text: &quot;https://example.com/privacy-policy&quot;
  4184. # keywords:
  4185. # - lang: en
  4186. # text: [&quot;Matrix&quot;, &quot;Element&quot;]
  4187. # logo:
  4188. # - lang: en
  4189. # text: &quot;https://example.com/logo.svg&quot;
  4190. # width: &quot;200&quot;
  4191. # height: &quot;80&quot;
  4192. #organization:
  4193. # name: Example com
  4194. # display_name:
  4195. # - [&quot;Example co&quot;, &quot;en&quot;]
  4196. # url: &quot;http://example.com&quot;
  4197. #contact_person:
  4198. # - given_name: Bob
  4199. # sur_name: &quot;the Sysadmin&quot;
  4200. # email_address&quot;: [&quot;admin@example.com&quot;]
  4201. # contact_type&quot;: technical
  4202. # Instead of putting the config inline as above, you can specify a
  4203. # separate pysaml2 configuration file:
  4204. #
  4205. #config_path: &quot;CONFDIR/sp_conf.py&quot;
  4206. # The lifetime of a SAML session. This defines how long a user has to
  4207. # complete the authentication process, if allow_unsolicited is unset.
  4208. # The default is 15 minutes.
  4209. #
  4210. #saml_session_lifetime: 5m
  4211. # An external module can be provided here as a custom solution to
  4212. # mapping attributes returned from a saml provider onto a matrix user.
  4213. #
  4214. user_mapping_provider:
  4215. # The custom module's class. Uncomment to use a custom module.
  4216. #
  4217. #module: mapping_provider.SamlMappingProvider
  4218. # Custom configuration values for the module. Below options are
  4219. # intended for the built-in provider, they should be changed if
  4220. # using a custom module. This section will be passed as a Python
  4221. # dictionary to the module's `parse_config` method.
  4222. #
  4223. config:
  4224. # The SAML attribute (after mapping via the attribute maps) to use
  4225. # to derive the Matrix ID from. 'uid' by default.
  4226. #
  4227. # Note: This used to be configured by the
  4228. # saml2_config.mxid_source_attribute option. If that is still
  4229. # defined, its value will be used instead.
  4230. #
  4231. #mxid_source_attribute: displayName
  4232. # The mapping system to use for mapping the saml attribute onto a
  4233. # matrix ID.
  4234. #
  4235. # Options include:
  4236. # * 'hexencode' (which maps unpermitted characters to '=xx')
  4237. # * 'dotreplace' (which replaces unpermitted characters with
  4238. # '.').
  4239. # The default is 'hexencode'.
  4240. #
  4241. # Note: This used to be configured by the
  4242. # saml2_config.mxid_mapping option. If that is still defined, its
  4243. # value will be used instead.
  4244. #
  4245. #mxid_mapping: dotreplace
  4246. # In previous versions of synapse, the mapping from SAML attribute to
  4247. # MXID was always calculated dynamically rather than stored in a
  4248. # table. For backwards- compatibility, we will look for user_ids
  4249. # matching such a pattern before creating a new account.
  4250. #
  4251. # This setting controls the SAML attribute which will be used for this
  4252. # backwards-compatibility lookup. Typically it should be 'uid', but if
  4253. # the attribute maps are changed, it may be necessary to change it.
  4254. #
  4255. # The default is 'uid'.
  4256. #
  4257. #grandfathered_mxid_source_attribute: upn
  4258. # It is possible to configure Synapse to only allow logins if SAML attributes
  4259. # match particular values. The requirements can be listed under
  4260. # `attribute_requirements` as shown below. All of the listed attributes must
  4261. # match for the login to be permitted.
  4262. #
  4263. #attribute_requirements:
  4264. # - attribute: userGroup
  4265. # value: &quot;staff&quot;
  4266. # - attribute: department
  4267. # value: &quot;sales&quot;
  4268. # If the metadata XML contains multiple IdP entities then the `idp_entityid`
  4269. # option must be set to the entity to redirect users to.
  4270. #
  4271. # Most deployments only have a single IdP entity and so should omit this
  4272. # option.
  4273. #
  4274. #idp_entityid: 'https://our_idp/entityid'
  4275. # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration
  4276. # and login.
  4277. #
  4278. # Options for each entry include:
  4279. #
  4280. # idp_id: a unique identifier for this identity provider. Used internally
  4281. # by Synapse; should be a single word such as 'github'.
  4282. #
  4283. # Note that, if this is changed, users authenticating via that provider
  4284. # will no longer be recognised as the same user!
  4285. #
  4286. # (Use &quot;oidc&quot; here if you are migrating from an old &quot;oidc_config&quot;
  4287. # configuration.)
  4288. #
  4289. # idp_name: A user-facing name for this identity provider, which is used to
  4290. # offer the user a choice of login mechanisms.
  4291. #
  4292. # idp_icon: An optional icon for this identity provider, which is presented
  4293. # by clients and Synapse's own IdP picker page. If given, must be an
  4294. # MXC URI of the format mxc://&lt;server-name&gt;/&lt;media-id&gt;. (An easy way to
  4295. # obtain such an MXC URI is to upload an image to an (unencrypted) room
  4296. # and then copy the &quot;url&quot; from the source of the event.)
  4297. #
  4298. # idp_brand: An optional brand for this identity provider, allowing clients
  4299. # to style the login flow according to the identity provider in question.
  4300. # See the spec for possible options here.
  4301. #
  4302. # discover: set to 'false' to disable the use of the OIDC discovery mechanism
  4303. # to discover endpoints. Defaults to true.
  4304. #
  4305. # issuer: Required. The OIDC issuer. Used to validate tokens and (if discovery
  4306. # is enabled) to discover the provider's endpoints.
  4307. #
  4308. # client_id: Required. oauth2 client id to use.
  4309. #
  4310. # client_secret: oauth2 client secret to use. May be omitted if
  4311. # client_secret_jwt_key is given, or if client_auth_method is 'none'.
  4312. #
  4313. # client_secret_jwt_key: Alternative to client_secret: details of a key used
  4314. # to create a JSON Web Token to be used as an OAuth2 client secret. If
  4315. # given, must be a dictionary with the following properties:
  4316. #
  4317. # key: a pem-encoded signing key. Must be a suitable key for the
  4318. # algorithm specified. Required unless 'key_file' is given.
  4319. #
  4320. # key_file: the path to file containing a pem-encoded signing key file.
  4321. # Required unless 'key' is given.
  4322. #
  4323. # jwt_header: a dictionary giving properties to include in the JWT
  4324. # header. Must include the key 'alg', giving the algorithm used to
  4325. # sign the JWT, such as &quot;ES256&quot;, using the JWA identifiers in
  4326. # RFC7518.
  4327. #
  4328. # jwt_payload: an optional dictionary giving properties to include in
  4329. # the JWT payload. Normally this should include an 'iss' key.
  4330. #
  4331. # client_auth_method: auth method to use when exchanging the token. Valid
  4332. # values are 'client_secret_basic' (default), 'client_secret_post' and
  4333. # 'none'.
  4334. #
  4335. # scopes: list of scopes to request. This should normally include the &quot;openid&quot;
  4336. # scope. Defaults to [&quot;openid&quot;].
  4337. #
  4338. # authorization_endpoint: the oauth2 authorization endpoint. Required if
  4339. # provider discovery is disabled.
  4340. #
  4341. # token_endpoint: the oauth2 token endpoint. Required if provider discovery is
  4342. # disabled.
  4343. #
  4344. # userinfo_endpoint: the OIDC userinfo endpoint. Required if discovery is
  4345. # disabled and the 'openid' scope is not requested.
  4346. #
  4347. # jwks_uri: URI where to fetch the JWKS. Required if discovery is disabled and
  4348. # the 'openid' scope is used.
  4349. #
  4350. # skip_verification: set to 'true' to skip metadata verification. Use this if
  4351. # you are connecting to a provider that is not OpenID Connect compliant.
  4352. # Defaults to false. Avoid this in production.
  4353. #
  4354. # user_profile_method: Whether to fetch the user profile from the userinfo
  4355. # endpoint. Valid values are: 'auto' or 'userinfo_endpoint'.
  4356. #
  4357. # Defaults to 'auto', which fetches the userinfo endpoint if 'openid' is
  4358. # included in 'scopes'. Set to 'userinfo_endpoint' to always fetch the
  4359. # userinfo endpoint.
  4360. #
  4361. # allow_existing_users: set to 'true' to allow a user logging in via OIDC to
  4362. # match a pre-existing account instead of failing. This could be used if
  4363. # switching from password logins to OIDC. Defaults to false.
  4364. #
  4365. # user_mapping_provider: Configuration for how attributes returned from a OIDC
  4366. # provider are mapped onto a matrix user. This setting has the following
  4367. # sub-properties:
  4368. #
  4369. # module: The class name of a custom mapping module. Default is
  4370. # 'synapse.handlers.oidc.JinjaOidcMappingProvider'.
  4371. # See https://matrix-org.github.io/synapse/latest/sso_mapping_providers.html#openid-mapping-providers
  4372. # for information on implementing a custom mapping provider.
  4373. #
  4374. # config: Configuration for the mapping provider module. This section will
  4375. # be passed as a Python dictionary to the user mapping provider
  4376. # module's `parse_config` method.
  4377. #
  4378. # For the default provider, the following settings are available:
  4379. #
  4380. # subject_claim: name of the claim containing a unique identifier
  4381. # for the user. Defaults to 'sub', which OpenID Connect
  4382. # compliant providers should provide.
  4383. #
  4384. # localpart_template: Jinja2 template for the localpart of the MXID.
  4385. # If this is not set, the user will be prompted to choose their
  4386. # own username (see 'sso_auth_account_details.html' in the 'sso'
  4387. # section of this file).
  4388. #
  4389. # display_name_template: Jinja2 template for the display name to set
  4390. # on first login. If unset, no displayname will be set.
  4391. #
  4392. # email_template: Jinja2 template for the email address of the user.
  4393. # If unset, no email address will be added to the account.
  4394. #
  4395. # extra_attributes: a map of Jinja2 templates for extra attributes
  4396. # to send back to the client during login.
  4397. # Note that these are non-standard and clients will ignore them
  4398. # without modifications.
  4399. #
  4400. # When rendering, the Jinja2 templates are given a 'user' variable,
  4401. # which is set to the claims returned by the UserInfo Endpoint and/or
  4402. # in the ID Token.
  4403. #
  4404. # It is possible to configure Synapse to only allow logins if certain attributes
  4405. # match particular values in the OIDC userinfo. The requirements can be listed under
  4406. # `attribute_requirements` as shown below. All of the listed attributes must
  4407. # match for the login to be permitted. Additional attributes can be added to
  4408. # userinfo by expanding the `scopes` section of the OIDC config to retrieve
  4409. # additional information from the OIDC provider.
  4410. #
  4411. # If the OIDC claim is a list, then the attribute must match any value in the list.
  4412. # Otherwise, it must exactly match the value of the claim. Using the example
  4413. # below, the `family_name` claim MUST be &quot;Stephensson&quot;, but the `groups`
  4414. # claim MUST contain &quot;admin&quot;.
  4415. #
  4416. # attribute_requirements:
  4417. # - attribute: family_name
  4418. # value: &quot;Stephensson&quot;
  4419. # - attribute: groups
  4420. # value: &quot;admin&quot;
  4421. #
  4422. # See https://matrix-org.github.io/synapse/latest/openid.html
  4423. # for information on how to configure these options.
  4424. #
  4425. # For backwards compatibility, it is also possible to configure a single OIDC
  4426. # provider via an 'oidc_config' setting. This is now deprecated and admins are
  4427. # advised to migrate to the 'oidc_providers' format. (When doing that migration,
  4428. # use 'oidc' for the idp_id to ensure that existing users continue to be
  4429. # recognised.)
  4430. #
  4431. oidc_providers:
  4432. # Generic example
  4433. #
  4434. #- idp_id: my_idp
  4435. # idp_name: &quot;My OpenID provider&quot;
  4436. # idp_icon: &quot;mxc://example.com/mediaid&quot;
  4437. # discover: false
  4438. # issuer: &quot;https://accounts.example.com/&quot;
  4439. # client_id: &quot;provided-by-your-issuer&quot;
  4440. # client_secret: &quot;provided-by-your-issuer&quot;
  4441. # client_auth_method: client_secret_post
  4442. # scopes: [&quot;openid&quot;, &quot;profile&quot;]
  4443. # authorization_endpoint: &quot;https://accounts.example.com/oauth2/auth&quot;
  4444. # token_endpoint: &quot;https://accounts.example.com/oauth2/token&quot;
  4445. # userinfo_endpoint: &quot;https://accounts.example.com/userinfo&quot;
  4446. # jwks_uri: &quot;https://accounts.example.com/.well-known/jwks.json&quot;
  4447. # skip_verification: true
  4448. # user_mapping_provider:
  4449. # config:
  4450. # subject_claim: &quot;id&quot;
  4451. # localpart_template: &quot;{{ user.login }}&quot;
  4452. # display_name_template: &quot;{{ user.name }}&quot;
  4453. # email_template: &quot;{{ user.email }}&quot;
  4454. # attribute_requirements:
  4455. # - attribute: userGroup
  4456. # value: &quot;synapseUsers&quot;
  4457. # Enable Central Authentication Service (CAS) for registration and login.
  4458. #
  4459. cas_config:
  4460. # Uncomment the following to enable authorization against a CAS server.
  4461. # Defaults to false.
  4462. #
  4463. #enabled: true
  4464. # The URL of the CAS authorization endpoint.
  4465. #
  4466. #server_url: &quot;https://cas-server.com&quot;
  4467. # The attribute of the CAS response to use as the display name.
  4468. #
  4469. # If unset, no displayname will be set.
  4470. #
  4471. #displayname_attribute: name
  4472. # It is possible to configure Synapse to only allow logins if CAS attributes
  4473. # match particular values. All of the keys in the mapping below must exist
  4474. # and the values must match the given value. Alternately if the given value
  4475. # is None then any value is allowed (the attribute just must exist).
  4476. # All of the listed attributes must match for the login to be permitted.
  4477. #
  4478. #required_attributes:
  4479. # userGroup: &quot;staff&quot;
  4480. # department: None
  4481. # Additional settings to use with single-sign on systems such as OpenID Connect,
  4482. # SAML2 and CAS.
  4483. #
  4484. sso:
  4485. # A list of client URLs which are whitelisted so that the user does not
  4486. # have to confirm giving access to their account to the URL. Any client
  4487. # whose URL starts with an entry in the following list will not be subject
  4488. # to an additional confirmation step after the SSO login is completed.
  4489. #
  4490. # WARNING: An entry such as &quot;https://my.client&quot; is insecure, because it
  4491. # will also match &quot;https://my.client.evil.site&quot;, exposing your users to
  4492. # phishing attacks from evil.site. To avoid this, include a slash after the
  4493. # hostname: &quot;https://my.client/&quot;.
  4494. #
  4495. # If public_baseurl is set, then the login fallback page (used by clients
  4496. # that don't natively support the required login flows) is whitelisted in
  4497. # addition to any URLs in this list.
  4498. #
  4499. # By default, this list is empty.
  4500. #
  4501. #client_whitelist:
  4502. # - https://riot.im/develop
  4503. # - https://my.custom.client/
  4504. # Uncomment to keep a user's profile fields in sync with information from
  4505. # the identity provider. Currently only syncing the displayname is
  4506. # supported. Fields are checked on every SSO login, and are updated
  4507. # if necessary.
  4508. #
  4509. # Note that enabling this option will override user profile information,
  4510. # regardless of whether users have opted-out of syncing that
  4511. # information when first signing in. Defaults to false.
  4512. #
  4513. #update_profile_information: true
  4514. # Directory in which Synapse will try to find the template files below.
  4515. # If not set, or the files named below are not found within the template
  4516. # directory, default templates from within the Synapse package will be used.
  4517. #
  4518. # Synapse will look for the following templates in this directory:
  4519. #
  4520. # * HTML page to prompt the user to choose an Identity Provider during
  4521. # login: 'sso_login_idp_picker.html'.
  4522. #
  4523. # This is only used if multiple SSO Identity Providers are configured.
  4524. #
  4525. # When rendering, this template is given the following variables:
  4526. # * redirect_url: the URL that the user will be redirected to after
  4527. # login.
  4528. #
  4529. # * server_name: the homeserver's name.
  4530. #
  4531. # * providers: a list of available Identity Providers. Each element is
  4532. # an object with the following attributes:
  4533. #
  4534. # * idp_id: unique identifier for the IdP
  4535. # * idp_name: user-facing name for the IdP
  4536. # * idp_icon: if specified in the IdP config, an MXC URI for an icon
  4537. # for the IdP
  4538. # * idp_brand: if specified in the IdP config, a textual identifier
  4539. # for the brand of the IdP
  4540. #
  4541. # The rendered HTML page should contain a form which submits its results
  4542. # back as a GET request, with the following query parameters:
  4543. #
  4544. # * redirectUrl: the client redirect URI (ie, the `redirect_url` passed
  4545. # to the template)
  4546. #
  4547. # * idp: the 'idp_id' of the chosen IDP.
  4548. #
  4549. # * HTML page to prompt new users to enter a userid and confirm other
  4550. # details: 'sso_auth_account_details.html'. This is only shown if the
  4551. # SSO implementation (with any user_mapping_provider) does not return
  4552. # a localpart.
  4553. #
  4554. # When rendering, this template is given the following variables:
  4555. #
  4556. # * server_name: the homeserver's name.
  4557. #
  4558. # * idp: details of the SSO Identity Provider that the user logged in
  4559. # with: an object with the following attributes:
  4560. #
  4561. # * idp_id: unique identifier for the IdP
  4562. # * idp_name: user-facing name for the IdP
  4563. # * idp_icon: if specified in the IdP config, an MXC URI for an icon
  4564. # for the IdP
  4565. # * idp_brand: if specified in the IdP config, a textual identifier
  4566. # for the brand of the IdP
  4567. #
  4568. # * user_attributes: an object containing details about the user that
  4569. # we received from the IdP. May have the following attributes:
  4570. #
  4571. # * display_name: the user's display_name
  4572. # * emails: a list of email addresses
  4573. #
  4574. # The template should render a form which submits the following fields:
  4575. #
  4576. # * username: the localpart of the user's chosen user id
  4577. #
  4578. # * HTML page allowing the user to consent to the server's terms and
  4579. # conditions. This is only shown for new users, and only if
  4580. # `user_consent.require_at_registration` is set.
  4581. #
  4582. # When rendering, this template is given the following variables:
  4583. #
  4584. # * server_name: the homeserver's name.
  4585. #
  4586. # * user_id: the user's matrix proposed ID.
  4587. #
  4588. # * user_profile.display_name: the user's proposed display name, if any.
  4589. #
  4590. # * consent_version: the version of the terms that the user will be
  4591. # shown
  4592. #
  4593. # * terms_url: a link to the page showing the terms.
  4594. #
  4595. # The template should render a form which submits the following fields:
  4596. #
  4597. # * accepted_version: the version of the terms accepted by the user
  4598. # (ie, 'consent_version' from the input variables).
  4599. #
  4600. # * HTML page for a confirmation step before redirecting back to the client
  4601. # with the login token: 'sso_redirect_confirm.html'.
  4602. #
  4603. # When rendering, this template is given the following variables:
  4604. #
  4605. # * redirect_url: the URL the user is about to be redirected to.
  4606. #
  4607. # * display_url: the same as `redirect_url`, but with the query
  4608. # parameters stripped. The intention is to have a
  4609. # human-readable URL to show to users, not to use it as
  4610. # the final address to redirect to.
  4611. #
  4612. # * server_name: the homeserver's name.
  4613. #
  4614. # * new_user: a boolean indicating whether this is the user's first time
  4615. # logging in.
  4616. #
  4617. # * user_id: the user's matrix ID.
  4618. #
  4619. # * user_profile.avatar_url: an MXC URI for the user's avatar, if any.
  4620. # None if the user has not set an avatar.
  4621. #
  4622. # * user_profile.display_name: the user's display name. None if the user
  4623. # has not set a display name.
  4624. #
  4625. # * HTML page which notifies the user that they are authenticating to confirm
  4626. # an operation on their account during the user interactive authentication
  4627. # process: 'sso_auth_confirm.html'.
  4628. #
  4629. # When rendering, this template is given the following variables:
  4630. # * redirect_url: the URL the user is about to be redirected to.
  4631. #
  4632. # * description: the operation which the user is being asked to confirm
  4633. #
  4634. # * idp: details of the Identity Provider that we will use to confirm
  4635. # the user's identity: an object with the following attributes:
  4636. #
  4637. # * idp_id: unique identifier for the IdP
  4638. # * idp_name: user-facing name for the IdP
  4639. # * idp_icon: if specified in the IdP config, an MXC URI for an icon
  4640. # for the IdP
  4641. # * idp_brand: if specified in the IdP config, a textual identifier
  4642. # for the brand of the IdP
  4643. #
  4644. # * HTML page shown after a successful user interactive authentication session:
  4645. # 'sso_auth_success.html'.
  4646. #
  4647. # Note that this page must include the JavaScript which notifies of a successful authentication
  4648. # (see https://matrix.org/docs/spec/client_server/r0.6.0#fallback).
  4649. #
  4650. # This template has no additional variables.
  4651. #
  4652. # * HTML page shown after a user-interactive authentication session which
  4653. # does not map correctly onto the expected user: 'sso_auth_bad_user.html'.
  4654. #
  4655. # When rendering, this template is given the following variables:
  4656. # * server_name: the homeserver's name.
  4657. # * user_id_to_verify: the MXID of the user that we are trying to
  4658. # validate.
  4659. #
  4660. # * HTML page shown during single sign-on if a deactivated user (according to Synapse's database)
  4661. # attempts to login: 'sso_account_deactivated.html'.
  4662. #
  4663. # This template has no additional variables.
  4664. #
  4665. # * HTML page to display to users if something goes wrong during the
  4666. # OpenID Connect authentication process: 'sso_error.html'.
  4667. #
  4668. # When rendering, this template is given two variables:
  4669. # * error: the technical name of the error
  4670. # * error_description: a human-readable message for the error
  4671. #
  4672. # You can see the default templates at:
  4673. # https://github.com/matrix-org/synapse/tree/master/synapse/res/templates
  4674. #
  4675. #template_dir: &quot;res/templates&quot;
  4676. # JSON web token integration. The following settings can be used to make
  4677. # Synapse JSON web tokens for authentication, instead of its internal
  4678. # password database.
  4679. #
  4680. # Each JSON Web Token needs to contain a &quot;sub&quot; (subject) claim, which is
  4681. # used as the localpart of the mxid.
  4682. #
  4683. # Additionally, the expiration time (&quot;exp&quot;), not before time (&quot;nbf&quot;),
  4684. # and issued at (&quot;iat&quot;) claims are validated if present.
  4685. #
  4686. # Note that this is a non-standard login type and client support is
  4687. # expected to be non-existent.
  4688. #
  4689. # See https://matrix-org.github.io/synapse/latest/jwt.html.
  4690. #
  4691. #jwt_config:
  4692. # Uncomment the following to enable authorization using JSON web
  4693. # tokens. Defaults to false.
  4694. #
  4695. #enabled: true
  4696. # This is either the private shared secret or the public key used to
  4697. # decode the contents of the JSON web token.
  4698. #
  4699. # Required if 'enabled' is true.
  4700. #
  4701. #secret: &quot;provided-by-your-issuer&quot;
  4702. # The algorithm used to sign the JSON web token.
  4703. #
  4704. # Supported algorithms are listed at
  4705. # https://pyjwt.readthedocs.io/en/latest/algorithms.html
  4706. #
  4707. # Required if 'enabled' is true.
  4708. #
  4709. #algorithm: &quot;provided-by-your-issuer&quot;
  4710. # The issuer to validate the &quot;iss&quot; claim against.
  4711. #
  4712. # Optional, if provided the &quot;iss&quot; claim will be required and
  4713. # validated for all JSON web tokens.
  4714. #
  4715. #issuer: &quot;provided-by-your-issuer&quot;
  4716. # A list of audiences to validate the &quot;aud&quot; claim against.
  4717. #
  4718. # Optional, if provided the &quot;aud&quot; claim will be required and
  4719. # validated for all JSON web tokens.
  4720. #
  4721. # Note that if the &quot;aud&quot; claim is included in a JSON web token then
  4722. # validation will fail without configuring audiences.
  4723. #
  4724. #audiences:
  4725. # - &quot;provided-by-your-issuer&quot;
  4726. password_config:
  4727. # Uncomment to disable password login
  4728. #
  4729. #enabled: false
  4730. # Uncomment to disable authentication against the local password
  4731. # database. This is ignored if `enabled` is false, and is only useful
  4732. # if you have other password_providers.
  4733. #
  4734. #localdb_enabled: false
  4735. # Uncomment and change to a secret random string for extra security.
  4736. # DO NOT CHANGE THIS AFTER INITIAL SETUP!
  4737. #
  4738. #pepper: &quot;EVEN_MORE_SECRET&quot;
  4739. # Define and enforce a password policy. Each parameter is optional.
  4740. # This is an implementation of MSC2000.
  4741. #
  4742. policy:
  4743. # Whether to enforce the password policy.
  4744. # Defaults to 'false'.
  4745. #
  4746. #enabled: true
  4747. # Minimum accepted length for a password.
  4748. # Defaults to 0.
  4749. #
  4750. #minimum_length: 15
  4751. # Whether a password must contain at least one digit.
  4752. # Defaults to 'false'.
  4753. #
  4754. #require_digit: true
  4755. # Whether a password must contain at least one symbol.
  4756. # A symbol is any character that's not a number or a letter.
  4757. # Defaults to 'false'.
  4758. #
  4759. #require_symbol: true
  4760. # Whether a password must contain at least one lowercase letter.
  4761. # Defaults to 'false'.
  4762. #
  4763. #require_lowercase: true
  4764. # Whether a password must contain at least one lowercase letter.
  4765. # Defaults to 'false'.
  4766. #
  4767. #require_uppercase: true
  4768. ui_auth:
  4769. # The amount of time to allow a user-interactive authentication session
  4770. # to be active.
  4771. #
  4772. # This defaults to 0, meaning the user is queried for their credentials
  4773. # before every action, but this can be overridden to allow a single
  4774. # validation to be re-used. This weakens the protections afforded by
  4775. # the user-interactive authentication process, by allowing for multiple
  4776. # (and potentially different) operations to use the same validation session.
  4777. #
  4778. # This is ignored for potentially &quot;dangerous&quot; operations (including
  4779. # deactivating an account, modifying an account password, and
  4780. # adding a 3PID).
  4781. #
  4782. # Uncomment below to allow for credential validation to last for 15
  4783. # seconds.
  4784. #
  4785. #session_timeout: &quot;15s&quot;
  4786. # Configuration for sending emails from Synapse.
  4787. #
  4788. email:
  4789. # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'.
  4790. #
  4791. #smtp_host: mail.server
  4792. # The port on the mail server for outgoing SMTP. Defaults to 25.
  4793. #
  4794. #smtp_port: 587
  4795. # Username/password for authentication to the SMTP server. By default, no
  4796. # authentication is attempted.
  4797. #
  4798. #smtp_user: &quot;exampleusername&quot;
  4799. #smtp_pass: &quot;examplepassword&quot;
  4800. # Uncomment the following to require TLS transport security for SMTP.
  4801. # By default, Synapse will connect over plain text, and will then switch to
  4802. # TLS via STARTTLS *if the SMTP server supports it*. If this option is set,
  4803. # Synapse will refuse to connect unless the server supports STARTTLS.
  4804. #
  4805. #require_transport_security: true
  4806. # notif_from defines the &quot;From&quot; address to use when sending emails.
  4807. # It must be set if email sending is enabled.
  4808. #
  4809. # The placeholder '%(app)s' will be replaced by the application name,
  4810. # which is normally 'app_name' (below), but may be overridden by the
  4811. # Matrix client application.
  4812. #
  4813. # Note that the placeholder must be written '%(app)s', including the
  4814. # trailing 's'.
  4815. #
  4816. #notif_from: &quot;Your Friendly %(app)s homeserver &lt;noreply@example.com&gt;&quot;
  4817. # app_name defines the default value for '%(app)s' in notif_from and email
  4818. # subjects. It defaults to 'Matrix'.
  4819. #
  4820. #app_name: my_branded_matrix_server
  4821. # Uncomment the following to enable sending emails for messages that the user
  4822. # has missed. Disabled by default.
  4823. #
  4824. #enable_notifs: true
  4825. # Uncomment the following to disable automatic subscription to email
  4826. # notifications for new users. Enabled by default.
  4827. #
  4828. #notif_for_new_users: false
  4829. # Custom URL for client links within the email notifications. By default
  4830. # links will be based on &quot;https://matrix.to&quot;.
  4831. #
  4832. # (This setting used to be called riot_base_url; the old name is still
  4833. # supported for backwards-compatibility but is now deprecated.)
  4834. #
  4835. #client_base_url: &quot;http://localhost/riot&quot;
  4836. # Configure the time that a validation email will expire after sending.
  4837. # Defaults to 1h.
  4838. #
  4839. #validation_token_lifetime: 15m
  4840. # The web client location to direct users to during an invite. This is passed
  4841. # to the identity server as the org.matrix.web_client_location key. Defaults
  4842. # to unset, giving no guidance to the identity server.
  4843. #
  4844. #invite_client_location: https://app.element.io
  4845. # Directory in which Synapse will try to find the template files below.
  4846. # If not set, or the files named below are not found within the template
  4847. # directory, default templates from within the Synapse package will be used.
  4848. #
  4849. # Synapse will look for the following templates in this directory:
  4850. #
  4851. # * The contents of email notifications of missed events: 'notif_mail.html' and
  4852. # 'notif_mail.txt'.
  4853. #
  4854. # * The contents of account expiry notice emails: 'notice_expiry.html' and
  4855. # 'notice_expiry.txt'.
  4856. #
  4857. # * The contents of password reset emails sent by the homeserver:
  4858. # 'password_reset.html' and 'password_reset.txt'
  4859. #
  4860. # * An HTML page that a user will see when they follow the link in the password
  4861. # reset email. The user will be asked to confirm the action before their
  4862. # password is reset: 'password_reset_confirmation.html'
  4863. #
  4864. # * HTML pages for success and failure that a user will see when they confirm
  4865. # the password reset flow using the page above: 'password_reset_success.html'
  4866. # and 'password_reset_failure.html'
  4867. #
  4868. # * The contents of address verification emails sent during registration:
  4869. # 'registration.html' and 'registration.txt'
  4870. #
  4871. # * HTML pages for success and failure that a user will see when they follow
  4872. # the link in an address verification email sent during registration:
  4873. # 'registration_success.html' and 'registration_failure.html'
  4874. #
  4875. # * The contents of address verification emails sent when an address is added
  4876. # to a Matrix account: 'add_threepid.html' and 'add_threepid.txt'
  4877. #
  4878. # * HTML pages for success and failure that a user will see when they follow
  4879. # the link in an address verification email sent when an address is added
  4880. # to a Matrix account: 'add_threepid_success.html' and
  4881. # 'add_threepid_failure.html'
  4882. #
  4883. # You can see the default templates at:
  4884. # https://github.com/matrix-org/synapse/tree/master/synapse/res/templates
  4885. #
  4886. #template_dir: &quot;res/templates&quot;
  4887. # Subjects to use when sending emails from Synapse.
  4888. #
  4889. # The placeholder '%(app)s' will be replaced with the value of the 'app_name'
  4890. # setting above, or by a value dictated by the Matrix client application.
  4891. #
  4892. # If a subject isn't overridden in this configuration file, the value used as
  4893. # its example will be used.
  4894. #
  4895. #subjects:
  4896. # Subjects for notification emails.
  4897. #
  4898. # On top of the '%(app)s' placeholder, these can use the following
  4899. # placeholders:
  4900. #
  4901. # * '%(person)s', which will be replaced by the display name of the user(s)
  4902. # that sent the message(s), e.g. &quot;Alice and Bob&quot;.
  4903. # * '%(room)s', which will be replaced by the name of the room the
  4904. # message(s) have been sent to, e.g. &quot;My super room&quot;.
  4905. #
  4906. # See the example provided for each setting to see which placeholder can be
  4907. # used and how to use them.
  4908. #
  4909. # Subject to use to notify about one message from one or more user(s) in a
  4910. # room which has a name.
  4911. #message_from_person_in_room: &quot;[%(app)s] You have a message on %(app)s from %(person)s in the %(room)s room...&quot;
  4912. #
  4913. # Subject to use to notify about one message from one or more user(s) in a
  4914. # room which doesn't have a name.
  4915. #message_from_person: &quot;[%(app)s] You have a message on %(app)s from %(person)s...&quot;
  4916. #
  4917. # Subject to use to notify about multiple messages from one or more users in
  4918. # a room which doesn't have a name.
  4919. #messages_from_person: &quot;[%(app)s] You have messages on %(app)s from %(person)s...&quot;
  4920. #
  4921. # Subject to use to notify about multiple messages in a room which has a
  4922. # name.
  4923. #messages_in_room: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room...&quot;
  4924. #
  4925. # Subject to use to notify about multiple messages in multiple rooms.
  4926. #messages_in_room_and_others: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room and others...&quot;
  4927. #
  4928. # Subject to use to notify about multiple messages from multiple persons in
  4929. # multiple rooms. This is similar to the setting above except it's used when
  4930. # the room in which the notification was triggered has no name.
  4931. #messages_from_person_and_others: &quot;[%(app)s] You have messages on %(app)s from %(person)s and others...&quot;
  4932. #
  4933. # Subject to use to notify about an invite to a room which has a name.
  4934. #invite_from_person_to_room: &quot;[%(app)s] %(person)s has invited you to join the %(room)s room on %(app)s...&quot;
  4935. #
  4936. # Subject to use to notify about an invite to a room which doesn't have a
  4937. # name.
  4938. #invite_from_person: &quot;[%(app)s] %(person)s has invited you to chat on %(app)s...&quot;
  4939. # Subject for emails related to account administration.
  4940. #
  4941. # On top of the '%(app)s' placeholder, these one can use the
  4942. # '%(server_name)s' placeholder, which will be replaced by the value of the
  4943. # 'server_name' setting in your Synapse configuration.
  4944. #
  4945. # Subject to use when sending a password reset email.
  4946. #password_reset: &quot;[%(server_name)s] Password reset&quot;
  4947. #
  4948. # Subject to use when sending a verification email to assert an address's
  4949. # ownership.
  4950. #email_validation: &quot;[%(server_name)s] Validate your email&quot;
  4951. # Password providers allow homeserver administrators to integrate
  4952. # their Synapse installation with existing authentication methods
  4953. # ex. LDAP, external tokens, etc.
  4954. #
  4955. # For more information and known implementations, please see
  4956. # https://matrix-org.github.io/synapse/latest/password_auth_providers.html
  4957. #
  4958. # Note: instances wishing to use SAML or CAS authentication should
  4959. # instead use the `saml2_config` or `cas_config` options,
  4960. # respectively.
  4961. #
  4962. password_providers:
  4963. # # Example config for an LDAP auth provider
  4964. # - module: &quot;ldap_auth_provider.LdapAuthProvider&quot;
  4965. # config:
  4966. # enabled: true
  4967. # uri: &quot;ldap://ldap.example.com:389&quot;
  4968. # start_tls: true
  4969. # base: &quot;ou=users,dc=example,dc=com&quot;
  4970. # attributes:
  4971. # uid: &quot;cn&quot;
  4972. # mail: &quot;email&quot;
  4973. # name: &quot;givenName&quot;
  4974. # #bind_dn:
  4975. # #bind_password:
  4976. # #filter: &quot;(objectClass=posixAccount)&quot;
  4977. ## Push ##
  4978. push:
  4979. # Clients requesting push notifications can either have the body of
  4980. # the message sent in the notification poke along with other details
  4981. # like the sender, or just the event ID and room ID (`event_id_only`).
  4982. # If clients choose the former, this option controls whether the
  4983. # notification request includes the content of the event (other details
  4984. # like the sender are still included). For `event_id_only` push, it
  4985. # has no effect.
  4986. #
  4987. # For modern android devices the notification content will still appear
  4988. # because it is loaded by the app. iPhone, however will send a
  4989. # notification saying only that a message arrived and who it came from.
  4990. #
  4991. # The default value is &quot;true&quot; to include message details. Uncomment to only
  4992. # include the event ID and room ID in push notification payloads.
  4993. #
  4994. #include_content: false
  4995. # When a push notification is received, an unread count is also sent.
  4996. # This number can either be calculated as the number of unread messages
  4997. # for the user, or the number of *rooms* the user has unread messages in.
  4998. #
  4999. # The default value is &quot;true&quot;, meaning push clients will see the number of
  5000. # rooms with unread messages in them. Uncomment to instead send the number
  5001. # of unread messages.
  5002. #
  5003. #group_unread_count_by_room: false
  5004. ## Rooms ##
  5005. # Controls whether locally-created rooms should be end-to-end encrypted by
  5006. # default.
  5007. #
  5008. # Possible options are &quot;all&quot;, &quot;invite&quot;, and &quot;off&quot;. They are defined as:
  5009. #
  5010. # * &quot;all&quot;: any locally-created room
  5011. # * &quot;invite&quot;: any room created with the &quot;private_chat&quot; or &quot;trusted_private_chat&quot;
  5012. # room creation presets
  5013. # * &quot;off&quot;: this option will take no effect
  5014. #
  5015. # The default value is &quot;off&quot;.
  5016. #
  5017. # Note that this option will only affect rooms created after it is set. It
  5018. # will also not affect rooms created by other servers.
  5019. #
  5020. #encryption_enabled_by_default_for_room_type: invite
  5021. # Uncomment to allow non-server-admin users to create groups on this server
  5022. #
  5023. #enable_group_creation: true
  5024. # If enabled, non server admins can only create groups with local parts
  5025. # starting with this prefix
  5026. #
  5027. #group_creation_prefix: &quot;unofficial_&quot;
  5028. # User Directory configuration
  5029. #
  5030. user_directory:
  5031. # Defines whether users can search the user directory. If false then
  5032. # empty responses are returned to all queries. Defaults to true.
  5033. #
  5034. # Uncomment to disable the user directory.
  5035. #
  5036. #enabled: false
  5037. # Defines whether to search all users visible to your HS when searching
  5038. # the user directory, rather than limiting to users visible in public
  5039. # rooms. Defaults to false.
  5040. #
  5041. # If you set it true, you'll have to rebuild the user_directory search
  5042. # indexes, see:
  5043. # https://matrix-org.github.io/synapse/latest/user_directory.html
  5044. #
  5045. # Uncomment to return search results containing all known users, even if that
  5046. # user does not share a room with the requester.
  5047. #
  5048. #search_all_users: true
  5049. # Defines whether to prefer local users in search query results.
  5050. # If True, local users are more likely to appear above remote users
  5051. # when searching the user directory. Defaults to false.
  5052. #
  5053. # Uncomment to prefer local over remote users in user directory search
  5054. # results.
  5055. #
  5056. #prefer_local_users: true
  5057. # User Consent configuration
  5058. #
  5059. # for detailed instructions, see
  5060. # https://matrix-org.github.io/synapse/latest/consent_tracking.html
  5061. #
  5062. # Parts of this section are required if enabling the 'consent' resource under
  5063. # 'listeners', in particular 'template_dir' and 'version'.
  5064. #
  5065. # 'template_dir' gives the location of the templates for the HTML forms.
  5066. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  5067. # and each language directory should contain the policy document (named as
  5068. # '&lt;version&gt;.html') and a success page (success.html).
  5069. #
  5070. # 'version' specifies the 'current' version of the policy document. It defines
  5071. # the version to be served by the consent resource if there is no 'v'
  5072. # parameter.
  5073. #
  5074. # 'server_notice_content', if enabled, will send a user a &quot;Server Notice&quot;
  5075. # asking them to consent to the privacy policy. The 'server_notices' section
  5076. # must also be configured for this to work. Notices will *not* be sent to
  5077. # guest users unless 'send_server_notice_to_guests' is set to true.
  5078. #
  5079. # 'block_events_error', if set, will block any attempts to send events
  5080. # until the user consents to the privacy policy. The value of the setting is
  5081. # used as the text of the error.
  5082. #
  5083. # 'require_at_registration', if enabled, will add a step to the registration
  5084. # process, similar to how captcha works. Users will be required to accept the
  5085. # policy before their account is created.
  5086. #
  5087. # 'policy_name' is the display name of the policy users will see when registering
  5088. # for an account. Has no effect unless `require_at_registration` is enabled.
  5089. # Defaults to &quot;Privacy Policy&quot;.
  5090. #
  5091. #user_consent:
  5092. # template_dir: res/templates/privacy
  5093. # version: 1.0
  5094. # server_notice_content:
  5095. # msgtype: m.text
  5096. # body: &gt;-
  5097. # To continue using this homeserver you must review and agree to the
  5098. # terms and conditions at %(consent_uri)s
  5099. # send_server_notice_to_guests: true
  5100. # block_events_error: &gt;-
  5101. # To continue using this homeserver you must review and agree to the
  5102. # terms and conditions at %(consent_uri)s
  5103. # require_at_registration: false
  5104. # policy_name: Privacy Policy
  5105. #
  5106. # Settings for local room and user statistics collection. See
  5107. # https://matrix-org.github.io/synapse/latest/room_and_user_statistics.html.
  5108. #
  5109. stats:
  5110. # Uncomment the following to disable room and user statistics. Note that doing
  5111. # so may cause certain features (such as the room directory) not to work
  5112. # correctly.
  5113. #
  5114. #enabled: false
  5115. # Server Notices room configuration
  5116. #
  5117. # Uncomment this section to enable a room which can be used to send notices
  5118. # from the server to users. It is a special room which cannot be left; notices
  5119. # come from a special &quot;notices&quot; user id.
  5120. #
  5121. # If you uncomment this section, you *must* define the system_mxid_localpart
  5122. # setting, which defines the id of the user which will be used to send the
  5123. # notices.
  5124. #
  5125. # It's also possible to override the room name, the display name of the
  5126. # &quot;notices&quot; user, and the avatar for the user.
  5127. #
  5128. #server_notices:
  5129. # system_mxid_localpart: notices
  5130. # system_mxid_display_name: &quot;Server Notices&quot;
  5131. # system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  5132. # room_name: &quot;Server Notices&quot;
  5133. # Uncomment to disable searching the public room list. When disabled
  5134. # blocks searching local and remote room lists for local and remote
  5135. # users by always returning an empty list for all queries.
  5136. #
  5137. #enable_room_list_search: false
  5138. # The `alias_creation` option controls who's allowed to create aliases
  5139. # on this server.
  5140. #
  5141. # The format of this option is a list of rules that contain globs that
  5142. # match against user_id, room_id and the new alias (fully qualified with
  5143. # server name). The action in the first rule that matches is taken,
  5144. # which can currently either be &quot;allow&quot; or &quot;deny&quot;.
  5145. #
  5146. # Missing user_id/room_id/alias fields default to &quot;*&quot;.
  5147. #
  5148. # If no rules match the request is denied. An empty list means no one
  5149. # can create aliases.
  5150. #
  5151. # Options for the rules include:
  5152. #
  5153. # user_id: Matches against the creator of the alias
  5154. # alias: Matches against the alias being created
  5155. # room_id: Matches against the room ID the alias is being pointed at
  5156. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5157. #
  5158. # The default is:
  5159. #
  5160. #alias_creation_rules:
  5161. # - user_id: &quot;*&quot;
  5162. # alias: &quot;*&quot;
  5163. # room_id: &quot;*&quot;
  5164. # action: allow
  5165. # The `room_list_publication_rules` option controls who can publish and
  5166. # which rooms can be published in the public room list.
  5167. #
  5168. # The format of this option is the same as that for
  5169. # `alias_creation_rules`.
  5170. #
  5171. # If the room has one or more aliases associated with it, only one of
  5172. # the aliases needs to match the alias rule. If there are no aliases
  5173. # then only rules with `alias: *` match.
  5174. #
  5175. # If no rules match the request is denied. An empty list means no one
  5176. # can publish rooms.
  5177. #
  5178. # Options for the rules include:
  5179. #
  5180. # user_id: Matches against the creator of the alias
  5181. # room_id: Matches against the room ID being published
  5182. # alias: Matches against any current local or canonical aliases
  5183. # associated with the room
  5184. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5185. #
  5186. # The default is:
  5187. #
  5188. #room_list_publication_rules:
  5189. # - user_id: &quot;*&quot;
  5190. # alias: &quot;*&quot;
  5191. # room_id: &quot;*&quot;
  5192. # action: allow
  5193. ## Opentracing ##
  5194. # These settings enable opentracing, which implements distributed tracing.
  5195. # This allows you to observe the causal chains of events across servers
  5196. # including requests, key lookups etc., across any server running
  5197. # synapse or any other other services which supports opentracing
  5198. # (specifically those implemented with Jaeger).
  5199. #
  5200. opentracing:
  5201. # tracing is disabled by default. Uncomment the following line to enable it.
  5202. #
  5203. #enabled: true
  5204. # The list of homeservers we wish to send and receive span contexts and span baggage.
  5205. # See https://matrix-org.github.io/synapse/latest/opentracing.html.
  5206. #
  5207. # This is a list of regexes which are matched against the server_name of the
  5208. # homeserver.
  5209. #
  5210. # By default, it is empty, so no servers are matched.
  5211. #
  5212. #homeserver_whitelist:
  5213. # - &quot;.*&quot;
  5214. # A list of the matrix IDs of users whose requests will always be traced,
  5215. # even if the tracing system would otherwise drop the traces due to
  5216. # probabilistic sampling.
  5217. #
  5218. # By default, the list is empty.
  5219. #
  5220. #force_tracing_for_users:
  5221. # - &quot;@user1:server_name&quot;
  5222. # - &quot;@user2:server_name&quot;
  5223. # Jaeger can be configured to sample traces at different rates.
  5224. # All configuration options provided by Jaeger can be set here.
  5225. # Jaeger's configuration is mostly related to trace sampling which
  5226. # is documented here:
  5227. # https://www.jaegertracing.io/docs/latest/sampling/.
  5228. #
  5229. #jaeger_config:
  5230. # sampler:
  5231. # type: const
  5232. # param: 1
  5233. # logging:
  5234. # false
  5235. ## Workers ##
  5236. # Disables sending of outbound federation transactions on the main process.
  5237. # Uncomment if using a federation sender worker.
  5238. #
  5239. #send_federation: false
  5240. # It is possible to run multiple federation sender workers, in which case the
  5241. # work is balanced across them.
  5242. #
  5243. # This configuration must be shared between all federation sender workers, and if
  5244. # changed all federation sender workers must be stopped at the same time and then
  5245. # started, to ensure that all instances are running with the same config (otherwise
  5246. # events may be dropped).
  5247. #
  5248. #federation_sender_instances:
  5249. # - federation_sender1
  5250. # When using workers this should be a map from `worker_name` to the
  5251. # HTTP replication listener of the worker, if configured.
  5252. #
  5253. #instance_map:
  5254. # worker1:
  5255. # host: localhost
  5256. # port: 8034
  5257. # Experimental: When using workers you can define which workers should
  5258. # handle event persistence and typing notifications. Any worker
  5259. # specified here must also be in the `instance_map`.
  5260. #
  5261. #stream_writers:
  5262. # events: worker1
  5263. # typing: worker1
  5264. # The worker that is used to run background tasks (e.g. cleaning up expired
  5265. # data). If not provided this defaults to the main process.
  5266. #
  5267. #run_background_tasks_on: worker1
  5268. # A shared secret used by the replication APIs to authenticate HTTP requests
  5269. # from workers.
  5270. #
  5271. # By default this is unused and traffic is not authenticated.
  5272. #
  5273. #worker_replication_secret: &quot;&quot;
  5274. # Configuration for Redis when using workers. This *must* be enabled when
  5275. # using workers (unless using old style direct TCP configuration).
  5276. #
  5277. redis:
  5278. # Uncomment the below to enable Redis support.
  5279. #
  5280. #enabled: true
  5281. # Optional host and port to use to connect to redis. Defaults to
  5282. # localhost and 6379
  5283. #
  5284. #host: localhost
  5285. #port: 6379
  5286. # Optional password if configured on the Redis instance
  5287. #
  5288. #password: &lt;secret_password&gt;
  5289. </code></pre>
  5290. <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>
  5291. <p>Below is a sample logging configuration file. This file can be tweaked to control how your
  5292. homeserver will output logs. A restart of the server is generally required to apply any
  5293. changes made to this file.</p>
  5294. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  5295. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  5296. a fresh config using Synapse by following the instructions in
  5297. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  5298. <pre><code class="language-yaml"># Log configuration for Synapse.
  5299. #
  5300. # This is a YAML file containing a standard Python logging configuration
  5301. # dictionary. See [1] for details on the valid settings.
  5302. #
  5303. # Synapse also supports structured logging for machine readable logs which can
  5304. # be ingested by ELK stacks. See [2] for details.
  5305. #
  5306. # [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  5307. # [2]: https://matrix-org.github.io/synapse/latest/structured_logging.html
  5308. version: 1
  5309. formatters:
  5310. precise:
  5311. format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
  5312. handlers:
  5313. file:
  5314. class: logging.handlers.TimedRotatingFileHandler
  5315. formatter: precise
  5316. filename: /var/log/matrix-synapse/homeserver.log
  5317. when: midnight
  5318. backupCount: 3 # Does not include the current log file.
  5319. encoding: utf8
  5320. # Default to buffering writes to log file for efficiency. This means that
  5321. # will be a delay for INFO/DEBUG logs to get written, but WARNING/ERROR
  5322. # logs will still be flushed immediately.
  5323. buffer:
  5324. class: logging.handlers.MemoryHandler
  5325. target: file
  5326. # The capacity is the number of log lines that are buffered before
  5327. # being written to disk. Increasing this will lead to better
  5328. # performance, at the expensive of it taking longer for log lines to
  5329. # be written to disk.
  5330. capacity: 10
  5331. flushLevel: 30 # Flush for WARNING logs as well
  5332. # A handler that writes logs to stderr. Unused by default, but can be used
  5333. # instead of &quot;buffer&quot; and &quot;file&quot; in the logger handlers.
  5334. console:
  5335. class: logging.StreamHandler
  5336. formatter: precise
  5337. loggers:
  5338. synapse.storage.SQL:
  5339. # beware: increasing this to DEBUG will make synapse log sensitive
  5340. # information such as access tokens.
  5341. level: INFO
  5342. twisted:
  5343. # We send the twisted logging directly to the file handler,
  5344. # to work around https://github.com/matrix-org/synapse/issues/3471
  5345. # when using &quot;buffer&quot; logger. Use &quot;console&quot; to log to stderr instead.
  5346. handlers: [file]
  5347. propagate: false
  5348. root:
  5349. level: INFO
  5350. # Write logs to the `buffer` handler, which will buffer them together in memory,
  5351. # then write them to a file.
  5352. #
  5353. # Replace &quot;buffer&quot; with &quot;console&quot; to log to stderr instead. (Note that you'll
  5354. # also need to update the configuration for the `twisted` logger above, in
  5355. # this case.)
  5356. #
  5357. handlers: [buffer]
  5358. disable_existing_loggers: false
  5359. </code></pre>
  5360. <div style="break-before: page; page-break-before: always;"></div><h1 id="structured-logging"><a class="header" href="#structured-logging">Structured Logging</a></h1>
  5361. <p>A structured logging system can be useful when your logs are destined for a
  5362. machine to parse and process. By maintaining its machine-readable characteristics,
  5363. it enables more efficient searching and aggregations when consumed by software
  5364. such as the &quot;ELK stack&quot;.</p>
  5365. <p>Synapse's structured logging system is configured via the file that Synapse's
  5366. <code>log_config</code> config option points to. The file should include a formatter which
  5367. uses the <code>synapse.logging.TerseJsonFormatter</code> class included with Synapse and a
  5368. handler which uses the above formatter.</p>
  5369. <p>There is also a <code>synapse.logging.JsonFormatter</code> option which does not include
  5370. a timestamp in the resulting JSON. This is useful if the log ingester adds its
  5371. own timestamp.</p>
  5372. <p>A structured logging configuration looks similar to the following:</p>
  5373. <pre><code class="language-yaml">version: 1
  5374. formatters:
  5375. structured:
  5376. class: synapse.logging.TerseJsonFormatter
  5377. handlers:
  5378. file:
  5379. class: logging.handlers.TimedRotatingFileHandler
  5380. formatter: structured
  5381. filename: /path/to/my/logs/homeserver.log
  5382. when: midnight
  5383. backupCount: 3 # Does not include the current log file.
  5384. encoding: utf8
  5385. loggers:
  5386. synapse:
  5387. level: INFO
  5388. handlers: [remote]
  5389. synapse.storage.SQL:
  5390. level: WARNING
  5391. </code></pre>
  5392. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5393. with the SQL layer at 'WARNING', and will log to a file, stored as JSON.</p>
  5394. <p>It is also possible to figure Synapse to log to a remote endpoint by using the
  5395. <code>synapse.logging.RemoteHandler</code> class included with Synapse. It takes the
  5396. following arguments:</p>
  5397. <ul>
  5398. <li><code>host</code>: Hostname or IP address of the log aggregator.</li>
  5399. <li><code>port</code>: Numerical port to contact on the host.</li>
  5400. <li><code>maximum_buffer</code>: (Optional, defaults to 1000) The maximum buffer size to allow.</li>
  5401. </ul>
  5402. <p>A remote structured logging configuration looks similar to the following:</p>
  5403. <pre><code class="language-yaml">version: 1
  5404. formatters:
  5405. structured:
  5406. class: synapse.logging.TerseJsonFormatter
  5407. handlers:
  5408. remote:
  5409. class: synapse.logging.RemoteHandler
  5410. formatter: structured
  5411. host: 10.1.2.3
  5412. port: 9999
  5413. loggers:
  5414. synapse:
  5415. level: INFO
  5416. handlers: [remote]
  5417. synapse.storage.SQL:
  5418. level: WARNING
  5419. </code></pre>
  5420. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5421. with the SQL layer at 'WARNING', and will log JSON formatted messages to a
  5422. remote endpoint at 10.1.2.3:9999.</p>
  5423. <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>
  5424. <p>Versions of Synapse prior to v1.23.0 included a custom structured logging
  5425. configuration which is deprecated. It used a <code>structured: true</code> flag and
  5426. configured <code>drains</code> instead of <code>handlers</code> and <code>formatters</code>.</p>
  5427. <p>Synapse currently automatically converts the old configuration to the new
  5428. configuration, but this will be removed in a future version of Synapse. The
  5429. following reference can be used to update your configuration. Based on the drain
  5430. <code>type</code>, we can pick a new handler:</p>
  5431. <ol>
  5432. <li>For a type of <code>console</code>, <code>console_json</code>, or <code>console_json_terse</code>: a handler
  5433. with a class of <code>logging.StreamHandler</code> and a <code>stream</code> of <code>ext://sys.stdout</code>
  5434. or <code>ext://sys.stderr</code> should be used.</li>
  5435. <li>For a type of <code>file</code> or <code>file_json</code>: a handler of <code>logging.FileHandler</code> with
  5436. a location of the file path should be used.</li>
  5437. <li>For a type of <code>network_json_terse</code>: a handler of <code>synapse.logging.RemoteHandler</code>
  5438. with the host and port should be used.</li>
  5439. </ol>
  5440. <p>Then based on the drain <code>type</code> we can pick a new formatter:</p>
  5441. <ol>
  5442. <li>For a type of <code>console</code> or <code>file</code> no formatter is necessary.</li>
  5443. <li>For a type of <code>console_json</code> or <code>file_json</code>: a formatter of
  5444. <code>synapse.logging.JsonFormatter</code> should be used.</li>
  5445. <li>For a type of <code>console_json_terse</code> or <code>network_json_terse</code>: a formatter of
  5446. <code>synapse.logging.TerseJsonFormatter</code> should be used.</li>
  5447. </ol>
  5448. <p>For each new handler and formatter they should be added to the logging configuration
  5449. and then assigned to either a logger or the root logger.</p>
  5450. <p>An example legacy configuration:</p>
  5451. <pre><code class="language-yaml">structured: true
  5452. loggers:
  5453. synapse:
  5454. level: INFO
  5455. synapse.storage.SQL:
  5456. level: WARNING
  5457. drains:
  5458. console:
  5459. type: console
  5460. location: stdout
  5461. file:
  5462. type: file_json
  5463. location: homeserver.log
  5464. </code></pre>
  5465. <p>Would be converted into a new configuration:</p>
  5466. <pre><code class="language-yaml">version: 1
  5467. formatters:
  5468. json:
  5469. class: synapse.logging.JsonFormatter
  5470. handlers:
  5471. console:
  5472. class: logging.StreamHandler
  5473. location: ext://sys.stdout
  5474. file:
  5475. class: logging.FileHandler
  5476. formatter: json
  5477. filename: homeserver.log
  5478. loggers:
  5479. synapse:
  5480. level: INFO
  5481. handlers: [console, file]
  5482. synapse.storage.SQL:
  5483. level: WARNING
  5484. </code></pre>
  5485. <p>The new logging configuration is a bit more verbose, but significantly more
  5486. flexible. It allows for configuration that were not previously possible, such as
  5487. sending plain logs over the network, or using different handlers for different
  5488. modules.</p>
  5489. <div style="break-before: page; page-break-before: always;"></div><h1 id="user-authentication"><a class="header" href="#user-authentication">User Authentication</a></h1>
  5490. <p>Synapse supports multiple methods of authenticating users, either out-of-the-box or through custom pluggable
  5491. authentication modules.</p>
  5492. <p>Included in Synapse is support for authenticating users via:</p>
  5493. <ul>
  5494. <li>A username and password.</li>
  5495. <li>An email address and password.</li>
  5496. <li>Single Sign-On through the SAML, Open ID Connect or CAS protocols.</li>
  5497. <li>JSON Web Tokens.</li>
  5498. <li>An administrator's shared secret.</li>
  5499. </ul>
  5500. <p>Synapse can additionally be extended to support custom authentication schemes through optional &quot;password auth provider&quot;
  5501. modules.</p>
  5502. <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>
  5503. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  5504. authentication, instead of its own local password database.</p>
  5505. <p>Any OP should work with Synapse, as long as it supports the authorization code
  5506. flow. There are a few options for that:</p>
  5507. <ul>
  5508. <li>
  5509. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  5510. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  5511. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  5512. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  5513. environment variable set to the path of the CA.</p>
  5514. </li>
  5515. <li>
  5516. <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
  5517. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  5518. </li>
  5519. </ul>
  5520. <p>It may also be possible to use other OAuth2 providers which provide the
  5521. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  5522. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  5523. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  5524. <p>The OpenID integration in Synapse uses the
  5525. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  5526. as follows:</p>
  5527. <ul>
  5528. <li>
  5529. <p>The relevant libraries are included in the Docker images and Debian packages
  5530. provided by <code>matrix.org</code> so no further action is needed.</p>
  5531. </li>
  5532. <li>
  5533. <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>
  5534. </li>
  5535. <li>
  5536. <p>For other installation mechanisms, see the documentation provided by the
  5537. maintainer.</p>
  5538. </li>
  5539. </ul>
  5540. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  5541. setting in your configuration file (or uncomment one of the existing examples).
  5542. See <a href="./sample_config.yaml">sample_config.yaml</a> for some sample settings, as well as
  5543. the text below for example configurations for specific providers.</p>
  5544. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  5545. <p>Here are a few configs for providers that should work with Synapse.</p>
  5546. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  5547. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  5548. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  5549. application should point to your matrix server:
  5550. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5551. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  5552. Directory (tenant) ID as it will be used in the Azure links.
  5553. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  5554. <pre><code class="language-yaml">oidc_providers:
  5555. - idp_id: microsoft
  5556. idp_name: Microsoft
  5557. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  5558. client_id: &quot;&lt;client id&gt;&quot;
  5559. client_secret: &quot;&lt;client secret&gt;&quot;
  5560. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5561. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  5562. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  5563. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  5564. user_mapping_provider:
  5565. config:
  5566. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  5567. display_name_template: &quot;{{ user.name }}&quot;
  5568. </code></pre>
  5569. <h3 id="dex"><a class="header" href="#dex"><a href="https://github.com/dexidp/dex">Dex</a></a></h3>
  5570. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source, certified OpenID Connect Provider.
  5571. Although it is designed to help building a full-blown provider with an
  5572. external database, it can be configured with static passwords in a config file.</p>
  5573. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  5574. to install Dex.</p>
  5575. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  5576. <pre><code class="language-yaml">staticClients:
  5577. - id: synapse
  5578. secret: secret
  5579. redirectURIs:
  5580. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  5581. name: 'Synapse'
  5582. </code></pre>
  5583. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  5584. <p>Synapse config:</p>
  5585. <pre><code class="language-yaml">oidc_providers:
  5586. - idp_id: dex
  5587. idp_name: &quot;My Dex server&quot;
  5588. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  5589. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  5590. client_id: &quot;synapse&quot;
  5591. client_secret: &quot;secret&quot;
  5592. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5593. user_mapping_provider:
  5594. config:
  5595. localpart_template: &quot;{{ user.name }}&quot;
  5596. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  5597. </code></pre>
  5598. <h3 id="keycloak"><a class="header" href="#keycloak"><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a></a></h3>
  5599. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  5600. <p>Follow the <a href="https://www.keycloak.org/getting-started">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  5601. <ol>
  5602. <li>
  5603. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  5604. </li>
  5605. <li>
  5606. <p>Fill in the fields as below:</p>
  5607. </li>
  5608. </ol>
  5609. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5610. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5611. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5612. </tbody></table>
  5613. <ol start="3">
  5614. <li>Click <code>Save</code></li>
  5615. <li>Fill in the fields as below:</li>
  5616. </ol>
  5617. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5618. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5619. <tr><td>Enabled</td><td><code>On</code></td></tr>
  5620. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5621. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  5622. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  5623. </tbody></table>
  5624. <ol start="5">
  5625. <li>Click <code>Save</code></li>
  5626. <li>On the Credentials tab, update the fields:</li>
  5627. </ol>
  5628. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5629. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  5630. </tbody></table>
  5631. <ol start="7">
  5632. <li>Click <code>Regenerate Secret</code></li>
  5633. <li>Copy Secret</li>
  5634. </ol>
  5635. <pre><code class="language-yaml">oidc_providers:
  5636. - idp_id: keycloak
  5637. idp_name: &quot;My KeyCloak server&quot;
  5638. issuer: &quot;https://127.0.0.1:8443/auth/realms/{realm_name}&quot;
  5639. client_id: &quot;synapse&quot;
  5640. client_secret: &quot;copy secret generated from above&quot;
  5641. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5642. user_mapping_provider:
  5643. config:
  5644. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5645. display_name_template: &quot;{{ user.name }}&quot;
  5646. </code></pre>
  5647. <h3 id="auth0"><a class="header" href="#auth0"><a href="https://auth0.com/">Auth0</a></a></h3>
  5648. <ol>
  5649. <li>
  5650. <p>Create a regular web application for Synapse</p>
  5651. </li>
  5652. <li>
  5653. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5654. </li>
  5655. <li>
  5656. <p>Add a rule to add the <code>preferred_username</code> claim.</p>
  5657. <details>
  5658. <summary>Code sample</summary>
  5659. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  5660. user.user_metadata = user.user_metadata || {};
  5661. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  5662. context.idToken.preferred_username = user.user_metadata.preferred_username;
  5663. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  5664. .then(function(){
  5665. callback(null, user, context);
  5666. })
  5667. .catch(function(err){
  5668. callback(err);
  5669. });
  5670. }
  5671. </code></pre>
  5672. </li>
  5673. </ol>
  5674. </details>
  5675. <p>Synapse config:</p>
  5676. <pre><code class="language-yaml">oidc_providers:
  5677. - idp_id: auth0
  5678. idp_name: Auth0
  5679. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  5680. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5681. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5682. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5683. user_mapping_provider:
  5684. config:
  5685. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5686. display_name_template: &quot;{{ user.name }}&quot;
  5687. </code></pre>
  5688. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  5689. <p>GitHub is a bit special as it is not an OpenID Connect compliant provider, but
  5690. just a regular OAuth2 provider.</p>
  5691. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  5692. can be used to retrieve information on the authenticated user. As the Synapse
  5693. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5694. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5695. <ol>
  5696. <li>Create a new OAuth application: https://github.com/settings/applications/new.</li>
  5697. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5698. </ol>
  5699. <p>Synapse config:</p>
  5700. <pre><code class="language-yaml">oidc_providers:
  5701. - idp_id: github
  5702. idp_name: Github
  5703. idp_brand: &quot;github&quot; # optional: styling hint for clients
  5704. discover: false
  5705. issuer: &quot;https://github.com/&quot;
  5706. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5707. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5708. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  5709. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  5710. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  5711. scopes: [&quot;read:user&quot;]
  5712. user_mapping_provider:
  5713. config:
  5714. subject_claim: &quot;id&quot;
  5715. localpart_template: &quot;{{ user.login }}&quot;
  5716. display_name_template: &quot;{{ user.name }}&quot;
  5717. </code></pre>
  5718. <h3 id="google"><a class="header" href="#google"><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a></a></h3>
  5719. <ol>
  5720. <li>Set up a project in the Google API Console (see
  5721. https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup).</li>
  5722. <li>add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  5723. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  5724. <pre><code class="language-yaml">oidc_providers:
  5725. - idp_id: google
  5726. idp_name: Google
  5727. idp_brand: &quot;google&quot; # optional: styling hint for clients
  5728. issuer: &quot;https://accounts.google.com/&quot;
  5729. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5730. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5731. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5732. user_mapping_provider:
  5733. config:
  5734. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  5735. display_name_template: &quot;{{ user.name }}&quot;
  5736. </code></pre>
  5737. </li>
  5738. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5739. </ol>
  5740. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  5741. <ol>
  5742. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  5743. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  5744. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5745. </ol>
  5746. <p>Synapse config:</p>
  5747. <pre><code class="language-yaml">oidc_providers:
  5748. - idp_id: twitch
  5749. idp_name: Twitch
  5750. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  5751. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5752. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5753. client_auth_method: &quot;client_secret_post&quot;
  5754. user_mapping_provider:
  5755. config:
  5756. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5757. display_name_template: &quot;{{ user.name }}&quot;
  5758. </code></pre>
  5759. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  5760. <ol>
  5761. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  5762. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  5763. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5764. </ol>
  5765. <p>Synapse config:</p>
  5766. <pre><code class="language-yaml">oidc_providers:
  5767. - idp_id: gitlab
  5768. idp_name: Gitlab
  5769. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  5770. issuer: &quot;https://gitlab.com/&quot;
  5771. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5772. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5773. client_auth_method: &quot;client_secret_post&quot;
  5774. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  5775. user_profile_method: &quot;userinfo_endpoint&quot;
  5776. user_mapping_provider:
  5777. config:
  5778. localpart_template: '{{ user.nickname }}'
  5779. display_name_template: '{{ user.name }}'
  5780. </code></pre>
  5781. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  5782. <p>Like Github, Facebook provide a custom OAuth2 API rather than an OIDC-compliant
  5783. one so requires a little more configuration.</p>
  5784. <ol start="0">
  5785. <li>You will need a Facebook developer account. You can register for one
  5786. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  5787. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  5788. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  5789. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  5790. need to go through the whole form here.</li>
  5791. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  5792. <ul>
  5793. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  5794. URL.</li>
  5795. </ul>
  5796. </li>
  5797. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  5798. and &quot;App Secret&quot; for use below.</li>
  5799. </ol>
  5800. <p>Synapse config:</p>
  5801. <pre><code class="language-yaml"> - idp_id: facebook
  5802. idp_name: Facebook
  5803. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  5804. discover: false
  5805. issuer: &quot;https://facebook.com&quot;
  5806. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5807. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5808. scopes: [&quot;openid&quot;, &quot;email&quot;]
  5809. authorization_endpoint: https://facebook.com/dialog/oauth
  5810. token_endpoint: https://graph.facebook.com/v9.0/oauth/access_token
  5811. user_profile_method: &quot;userinfo_endpoint&quot;
  5812. userinfo_endpoint: &quot;https://graph.facebook.com/v9.0/me?fields=id,name,email,picture&quot;
  5813. user_mapping_provider:
  5814. config:
  5815. subject_claim: &quot;id&quot;
  5816. display_name_template: &quot;{{ user.name }}&quot;
  5817. </code></pre>
  5818. <p>Relevant documents:</p>
  5819. <ul>
  5820. <li>https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow</li>
  5821. <li>Using Facebook's Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/</li>
  5822. <li>Reference to the User endpoint: https://developers.facebook.com/docs/graph-api/reference/user</li>
  5823. </ul>
  5824. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  5825. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  5826. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  5827. can be used to retrieve information on the authenticated user. As the Synapse
  5828. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5829. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5830. <ol>
  5831. <li>Create a new application.</li>
  5832. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5833. </ol>
  5834. <p>Synapse config:</p>
  5835. <pre><code class="language-yaml">oidc_providers:
  5836. - idp_id: gitea
  5837. idp_name: Gitea
  5838. discover: false
  5839. issuer: &quot;https://your-gitea.com/&quot;
  5840. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5841. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5842. client_auth_method: client_secret_post
  5843. scopes: [] # Gitea doesn't support Scopes
  5844. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  5845. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  5846. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  5847. user_mapping_provider:
  5848. config:
  5849. subject_claim: &quot;id&quot;
  5850. localpart_template: &quot;{{ user.login }}&quot;
  5851. display_name_template: &quot;{{ user.full_name }}&quot;
  5852. </code></pre>
  5853. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  5854. <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>
  5855. <p>Synapse config:</p>
  5856. <pre><code class="language-yaml">oidc_providers:
  5857. - idp_id: xwiki
  5858. idp_name: &quot;XWiki&quot;
  5859. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  5860. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5861. client_auth_method: none
  5862. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5863. user_profile_method: &quot;userinfo_endpoint&quot;
  5864. user_mapping_provider:
  5865. config:
  5866. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5867. display_name_template: &quot;{{ user.name }}&quot;
  5868. </code></pre>
  5869. <h2 id="apple"><a class="header" href="#apple">Apple</a></h2>
  5870. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  5871. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  5872. private key with &quot;SiWA&quot; enabled.</p>
  5873. <p>As well as the private key file, you will need:</p>
  5874. <ul>
  5875. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  5876. <li>Team ID: a 10-character ID associated with your developer account.</li>
  5877. <li>Key ID: the 10-character identifier for the key.</li>
  5878. </ul>
  5879. <p>https://help.apple.com/developer-account/?lang=en#/dev77c875b7e has more
  5880. documentation on setting up SiWA.</p>
  5881. <p>The synapse config will look like this:</p>
  5882. <pre><code class="language-yaml"> - idp_id: apple
  5883. idp_name: Apple
  5884. issuer: &quot;https://appleid.apple.com&quot;
  5885. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  5886. client_auth_method: &quot;client_secret_post&quot;
  5887. client_secret_jwt_key:
  5888. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  5889. jwt_header:
  5890. alg: ES256
  5891. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  5892. jwt_payload:
  5893. iss: TEAMIDCODE # Set to the 10-char Team ID
  5894. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  5895. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  5896. user_mapping_provider:
  5897. config:
  5898. email_template: &quot;{{ user.email }}&quot;
  5899. </code></pre>
  5900. <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>
  5901. <p>A mapping provider is a Python class (loaded via a Python module) that
  5902. works out how to map attributes of a SSO response to Matrix-specific
  5903. user attributes. Details such as user ID localpart, displayname, and even avatar
  5904. URLs are all things that can be mapped from talking to a SSO service.</p>
  5905. <p>As an example, a SSO service may return the email address
  5906. &quot;john.smith@example.com&quot; for a user, whereas Synapse will need to figure out how
  5907. to turn that into a displayname when creating a Matrix user for this individual.
  5908. It may choose <code>John Smith</code>, or <code>Smith, John [Example.com]</code> or any number of
  5909. variations. As each Synapse configuration may want something different, this is
  5910. where SAML mapping providers come into play.</p>
  5911. <p>SSO mapping providers are currently supported for OpenID and SAML SSO
  5912. configurations. Please see the details below for how to implement your own.</p>
  5913. <p>It is up to the mapping provider whether the user should be assigned a predefined
  5914. Matrix ID based on the SSO attributes, or if the user should be allowed to
  5915. choose their own username.</p>
  5916. <p>In the first case - where users are automatically allocated a Matrix ID - it is
  5917. the responsibility of the mapping provider to normalise the SSO attributes and
  5918. map them to a valid Matrix ID. The <a href="https://matrix.org/docs/spec/appendices#user-identifiers">specification for Matrix
  5919. IDs</a> has some
  5920. information about what is considered valid.</p>
  5921. <p>If the mapping provider does not assign a Matrix ID, then Synapse will
  5922. automatically serve an HTML page allowing the user to pick their own username.</p>
  5923. <p>External mapping providers are provided to Synapse in the form of an external
  5924. Python module. You can retrieve this module from <a href="https://pypi.org">PyPI</a> or elsewhere,
  5925. but it must be importable via Synapse (e.g. it must be in the same virtualenv
  5926. as Synapse). The Synapse config is then modified to point to the mapping provider
  5927. (and optionally provide additional configuration for it).</p>
  5928. <h2 id="openid-mapping-providers"><a class="header" href="#openid-mapping-providers">OpenID Mapping Providers</a></h2>
  5929. <p>The OpenID mapping provider can be customized by editing the
  5930. <code>oidc_config.user_mapping_provider.module</code> config option.</p>
  5931. <p><code>oidc_config.user_mapping_provider.config</code> allows you to provide custom
  5932. configuration options to the module. Check with the module's documentation for
  5933. what options it provides (if any). The options listed by default are for the
  5934. user mapping provider built in to Synapse. If using a custom module, you should
  5935. comment these options out and use those specified by the module instead.</p>
  5936. <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>
  5937. <p>A custom mapping provider must specify the following methods:</p>
  5938. <ul>
  5939. <li><code>__init__(self, parsed_config)</code>
  5940. <ul>
  5941. <li>Arguments:
  5942. <ul>
  5943. <li><code>parsed_config</code> - A configuration object that is the return value of the
  5944. <code>parse_config</code> method. You should set any configuration options needed by
  5945. the module here.</li>
  5946. </ul>
  5947. </li>
  5948. </ul>
  5949. </li>
  5950. <li><code>parse_config(config)</code>
  5951. <ul>
  5952. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  5953. <li>Arguments:
  5954. <ul>
  5955. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  5956. <code>oidc_config.user_mapping_provider.config</code> homeserver config option.
  5957. Runs on homeserver startup. Providers should extract and validate
  5958. any option values they need here.</li>
  5959. </ul>
  5960. </li>
  5961. <li>Whatever is returned will be passed back to the user mapping provider module's
  5962. <code>__init__</code> method during construction.</li>
  5963. </ul>
  5964. </li>
  5965. <li><code>get_remote_user_id(self, userinfo)</code>
  5966. <ul>
  5967. <li>Arguments:
  5968. <ul>
  5969. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  5970. information from.</li>
  5971. </ul>
  5972. </li>
  5973. <li>This method must return a string, which is the unique, immutable identifier
  5974. for the user. Commonly the <code>sub</code> claim of the response.</li>
  5975. </ul>
  5976. </li>
  5977. <li><code>map_user_attributes(self, userinfo, token, failures)</code>
  5978. <ul>
  5979. <li>This method must be async.</li>
  5980. <li>Arguments:
  5981. <ul>
  5982. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  5983. information from.</li>
  5984. <li><code>token</code> - A dictionary which includes information necessary to make
  5985. further requests to the OpenID provider.</li>
  5986. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  5987. mxid localpart mapping has failed. This should be used
  5988. to create a deduplicated mxid localpart which should be
  5989. returned instead. For example, if this method returns
  5990. <code>john.doe</code> as the value of <code>localpart</code> in the returned
  5991. dict, and that is already taken on the homeserver, this
  5992. method will be called again with the same parameters but
  5993. with failures=1. The method should then return a different
  5994. <code>localpart</code> value, such as <code>john.doe1</code>.</li>
  5995. </ul>
  5996. </li>
  5997. <li>Returns a dictionary with two keys:
  5998. <ul>
  5999. <li><code>localpart</code>: A string, used to generate the Matrix ID. If this is
  6000. <code>None</code>, the user is prompted to pick their own username. This is only used
  6001. during a user's first login. Once a localpart has been associated with a
  6002. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6003. <li><code>displayname</code>: An optional string, the display name for the user.</li>
  6004. </ul>
  6005. </li>
  6006. </ul>
  6007. </li>
  6008. <li><code>get_extra_attributes(self, userinfo, token)</code>
  6009. <ul>
  6010. <li>
  6011. <p>This method must be async.</p>
  6012. </li>
  6013. <li>
  6014. <p>Arguments:</p>
  6015. <ul>
  6016. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6017. information from.</li>
  6018. <li><code>token</code> - A dictionary which includes information necessary to make
  6019. further requests to the OpenID provider.</li>
  6020. </ul>
  6021. </li>
  6022. <li>
  6023. <p>Returns a dictionary that is suitable to be serialized to JSON. This
  6024. will be returned as part of the response during a successful login.</p>
  6025. <p>Note that care should be taken to not overwrite any of the parameters
  6026. 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>
  6027. </li>
  6028. </ul>
  6029. </li>
  6030. </ul>
  6031. <h3 id="default-openid-mapping-provider"><a class="header" href="#default-openid-mapping-provider">Default OpenID Mapping Provider</a></h3>
  6032. <p>Synapse has a built-in OpenID mapping provider if a custom provider isn't
  6033. specified in the config. It is located at
  6034. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/oidc.py"><code>synapse.handlers.oidc.JinjaOidcMappingProvider</code></a>.</p>
  6035. <h2 id="saml-mapping-providers"><a class="header" href="#saml-mapping-providers">SAML Mapping Providers</a></h2>
  6036. <p>The SAML mapping provider can be customized by editing the
  6037. <code>saml2_config.user_mapping_provider.module</code> config option.</p>
  6038. <p><code>saml2_config.user_mapping_provider.config</code> allows you to provide custom
  6039. configuration options to the module. Check with the module's documentation for
  6040. what options it provides (if any). The options listed by default are for the
  6041. user mapping provider built in to Synapse. If using a custom module, you should
  6042. comment these options out and use those specified by the module instead.</p>
  6043. <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>
  6044. <p>A custom mapping provider must specify the following methods:</p>
  6045. <ul>
  6046. <li><code>__init__(self, parsed_config, module_api)</code>
  6047. <ul>
  6048. <li>Arguments:
  6049. <ul>
  6050. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6051. <code>parse_config</code> method. You should set any configuration options needed by
  6052. the module here.</li>
  6053. <li><code>module_api</code> - a <code>synapse.module_api.ModuleApi</code> object which provides the
  6054. stable API available for extension modules.</li>
  6055. </ul>
  6056. </li>
  6057. </ul>
  6058. </li>
  6059. <li><code>parse_config(config)</code>
  6060. <ul>
  6061. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6062. <li>Arguments:
  6063. <ul>
  6064. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6065. <code>saml_config.user_mapping_provider.config</code> homeserver config option.
  6066. Runs on homeserver startup. Providers should extract and validate
  6067. any option values they need here.</li>
  6068. </ul>
  6069. </li>
  6070. <li>Whatever is returned will be passed back to the user mapping provider module's
  6071. <code>__init__</code> method during construction.</li>
  6072. </ul>
  6073. </li>
  6074. <li><code>get_saml_attributes(config)</code>
  6075. <ul>
  6076. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6077. <li>Arguments:
  6078. <ul>
  6079. <li><code>config</code> - A object resulting from a call to <code>parse_config</code>.</li>
  6080. </ul>
  6081. </li>
  6082. <li>Returns a tuple of two sets. The first set equates to the SAML auth
  6083. response attributes that are required for the module to function, whereas
  6084. the second set consists of those attributes which can be used if available,
  6085. but are not necessary.</li>
  6086. </ul>
  6087. </li>
  6088. <li><code>get_remote_user_id(self, saml_response, client_redirect_url)</code>
  6089. <ul>
  6090. <li>Arguments:
  6091. <ul>
  6092. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6093. information from.</li>
  6094. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6095. redirected to.</li>
  6096. </ul>
  6097. </li>
  6098. <li>This method must return a string, which is the unique, immutable identifier
  6099. for the user. Commonly the <code>uid</code> claim of the response.</li>
  6100. </ul>
  6101. </li>
  6102. <li><code>saml_response_to_user_attributes(self, saml_response, failures, client_redirect_url)</code>
  6103. <ul>
  6104. <li>
  6105. <p>Arguments:</p>
  6106. <ul>
  6107. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6108. information from.</li>
  6109. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6110. mxid localpart mapping has failed. This should be used
  6111. to create a deduplicated mxid localpart which should be
  6112. returned instead. For example, if this method returns
  6113. <code>john.doe</code> as the value of <code>mxid_localpart</code> in the returned
  6114. dict, and that is already taken on the homeserver, this
  6115. method will be called again with the same parameters but
  6116. with failures=1. The method should then return a different
  6117. <code>mxid_localpart</code> value, such as <code>john.doe1</code>.</li>
  6118. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6119. redirected to.</li>
  6120. </ul>
  6121. </li>
  6122. <li>
  6123. <p>This method must return a dictionary, which will then be used by Synapse
  6124. to build a new user. The following keys are allowed:</p>
  6125. <ul>
  6126. <li><code>mxid_localpart</code> - A string, the mxid localpart of the new user. If this is
  6127. <code>None</code>, the user is prompted to pick their own username. This is only used
  6128. during a user's first login. Once a localpart has been associated with a
  6129. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6130. <li><code>displayname</code> - The displayname of the new user. If not provided, will default to
  6131. the value of <code>mxid_localpart</code>.</li>
  6132. <li><code>emails</code> - A list of emails for the new user. If not provided, will
  6133. default to an empty list.</li>
  6134. </ul>
  6135. <p>Alternatively it can raise a <code>synapse.api.errors.RedirectException</code> to
  6136. redirect the user to another page. This is useful to prompt the user for
  6137. additional information, e.g. if you want them to provide their own username.
  6138. It is the responsibility of the mapping provider to either redirect back
  6139. to <code>client_redirect_url</code> (including any additional information) or to
  6140. complete registration using methods from the <code>ModuleApi</code>.</p>
  6141. </li>
  6142. </ul>
  6143. </li>
  6144. </ul>
  6145. <h3 id="default-saml-mapping-provider"><a class="header" href="#default-saml-mapping-provider">Default SAML Mapping Provider</a></h3>
  6146. <p>Synapse has a built-in SAML mapping provider if a custom provider isn't
  6147. specified in the config. It is located at
  6148. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/saml.py"><code>synapse.handlers.saml.DefaultSamlMappingProvider</code></a>.</p>
  6149. <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>
  6150. <p>Password auth providers offer a way for server administrators to
  6151. integrate their Synapse installation with an existing authentication
  6152. system.</p>
  6153. <p>A password auth provider is a Python class which is dynamically loaded
  6154. into Synapse, and provides a number of methods by which it can integrate
  6155. with the authentication system.</p>
  6156. <p>This document serves as a reference for those looking to implement their
  6157. own password auth providers. Additionally, here is a list of known
  6158. password auth provider module implementations:</p>
  6159. <ul>
  6160. <li><a href="https://github.com/matrix-org/matrix-synapse-ldap3/">matrix-synapse-ldap3</a></li>
  6161. <li><a href="https://github.com/devture/matrix-synapse-shared-secret-auth">matrix-synapse-shared-secret-auth</a></li>
  6162. <li><a href="https://github.com/ma1uta/matrix-synapse-rest-password-provider">matrix-synapse-rest-password-provider</a></li>
  6163. </ul>
  6164. <h2 id="required-methods"><a class="header" href="#required-methods">Required methods</a></h2>
  6165. <p>Password auth provider classes must provide the following methods:</p>
  6166. <ul>
  6167. <li>
  6168. <p><code>parse_config(config)</code>
  6169. This method is passed the <code>config</code> object for this module from the
  6170. homeserver configuration file.</p>
  6171. <p>It should perform any appropriate sanity checks on the provided
  6172. configuration, and return an object which is then passed into
  6173. <code>__init__</code>.</p>
  6174. <p>This method should have the <code>@staticmethod</code> decoration.</p>
  6175. </li>
  6176. <li>
  6177. <p><code>__init__(self, config, account_handler)</code></p>
  6178. <p>The constructor is passed the config object returned by
  6179. <code>parse_config</code>, and a <code>synapse.module_api.ModuleApi</code> object which
  6180. allows the password provider to check if accounts exist and/or create
  6181. new ones.</p>
  6182. </li>
  6183. </ul>
  6184. <h2 id="optional-methods"><a class="header" href="#optional-methods">Optional methods</a></h2>
  6185. <p>Password auth provider classes may optionally provide the following methods:</p>
  6186. <ul>
  6187. <li>
  6188. <p><code>get_db_schema_files(self)</code></p>
  6189. <p>This method, if implemented, should return an Iterable of
  6190. <code>(name, stream)</code> pairs of database schema files. Each file is applied
  6191. in turn at initialisation, and a record is then made in the database
  6192. so that it is not re-applied on the next start.</p>
  6193. </li>
  6194. <li>
  6195. <p><code>get_supported_login_types(self)</code></p>
  6196. <p>This method, if implemented, should return a <code>dict</code> mapping from a
  6197. login type identifier (such as <code>m.login.password</code>) to an iterable
  6198. giving the fields which must be provided by the user in the submission
  6199. to <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login">the <code>/login</code> API</a>.
  6200. These fields are passed in the <code>login_dict</code> dictionary to <code>check_auth</code>.</p>
  6201. <p>For example, if a password auth provider wants to implement a custom
  6202. login type of <code>com.example.custom_login</code>, where the client is expected
  6203. to pass the fields <code>secret1</code> and <code>secret2</code>, the provider should
  6204. implement this method and return the following dict:</p>
  6205. <pre><code class="language-python">{&quot;com.example.custom_login&quot;: (&quot;secret1&quot;, &quot;secret2&quot;)}
  6206. </code></pre>
  6207. </li>
  6208. <li>
  6209. <p><code>check_auth(self, username, login_type, login_dict)</code></p>
  6210. <p>This method does the real work. If implemented, it
  6211. will be called for each login attempt where the login type matches one
  6212. of the keys returned by <code>get_supported_login_types</code>.</p>
  6213. <p>It is passed the (possibly unqualified) <code>user</code> field provided by the client,
  6214. the login type, and a dictionary of login secrets passed by the
  6215. client.</p>
  6216. <p>The method should return an <code>Awaitable</code> object, which resolves
  6217. to the canonical <code>@localpart:domain</code> user ID if authentication is
  6218. successful, and <code>None</code> if not.</p>
  6219. <p>Alternatively, the <code>Awaitable</code> can resolve to a <code>(str, func)</code> tuple, in
  6220. which case the second field is a callback which will be called with
  6221. the result from the <code>/login</code> call (including <code>access_token</code>,
  6222. <code>device_id</code>, etc.)</p>
  6223. </li>
  6224. <li>
  6225. <p><code>check_3pid_auth(self, medium, address, password)</code></p>
  6226. <p>This method, if implemented, is called when a user attempts to
  6227. register or log in with a third party identifier, such as email. It is
  6228. passed the medium (ex. &quot;email&quot;), an address (ex.
  6229. &quot;<a href="mailto:jdoe@example.com">jdoe@example.com</a>&quot;) and the user's password.</p>
  6230. <p>The method should return an <code>Awaitable</code> object, which resolves
  6231. to a <code>str</code> containing the user's (canonical) User id if
  6232. authentication was successful, and <code>None</code> if not.</p>
  6233. <p>As with <code>check_auth</code>, the <code>Awaitable</code> may alternatively resolve to a
  6234. <code>(user_id, callback)</code> tuple.</p>
  6235. </li>
  6236. <li>
  6237. <p><code>check_password(self, user_id, password)</code></p>
  6238. <p>This method provides a simpler interface than
  6239. <code>get_supported_login_types</code> and <code>check_auth</code> for password auth
  6240. providers that just want to provide a mechanism for validating
  6241. <code>m.login.password</code> logins.</p>
  6242. <p>If implemented, it will be called to check logins with an
  6243. <code>m.login.password</code> login type. It is passed a qualified
  6244. <code>@localpart:domain</code> user id, and the password provided by the user.</p>
  6245. <p>The method should return an <code>Awaitable</code> object, which resolves
  6246. to <code>True</code> if authentication is successful, and <code>False</code> if not.</p>
  6247. </li>
  6248. <li>
  6249. <p><code>on_logged_out(self, user_id, device_id, access_token)</code></p>
  6250. <p>This method, if implemented, is called when a user logs out. It is
  6251. passed the qualified user ID, the ID of the deactivated device (if
  6252. any: access tokens are occasionally created without an associated
  6253. device ID), and the (now deactivated) access token.</p>
  6254. <p>It may return an <code>Awaitable</code> object; the logout request will
  6255. wait for the <code>Awaitable</code> to complete, but the result is ignored.</p>
  6256. </li>
  6257. </ul>
  6258. <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>
  6259. <p>Synapse comes with a non-standard login type to support
  6260. <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">JSON Web Tokens</a>. In general the
  6261. documentation for
  6262. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#login">the login endpoint</a>
  6263. is still valid (and the mechanism works similarly to the
  6264. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#token-based">token based login</a>).</p>
  6265. <p>To log in using a JSON Web Token, clients should submit a <code>/login</code> request as
  6266. follows:</p>
  6267. <pre><code class="language-json">{
  6268. &quot;type&quot;: &quot;org.matrix.login.jwt&quot;,
  6269. &quot;token&quot;: &quot;&lt;jwt&gt;&quot;
  6270. }
  6271. </code></pre>
  6272. <p>Note that the login type of <code>m.login.jwt</code> is supported, but is deprecated. This
  6273. will be removed in a future version of Synapse.</p>
  6274. <p>The <code>token</code> field should include the JSON web token with the following claims:</p>
  6275. <ul>
  6276. <li>The <code>sub</code> (subject) claim is required and should encode the local part of the
  6277. user ID.</li>
  6278. <li>The expiration time (<code>exp</code>), not before time (<code>nbf</code>), and issued at (<code>iat</code>)
  6279. claims are optional, but validated if present.</li>
  6280. <li>The issuer (<code>iss</code>) claim is optional, but required and validated if configured.</li>
  6281. <li>The audience (<code>aud</code>) claim is optional, but required and validated if configured.
  6282. Providing the audience claim when not configured will cause validation to fail.</li>
  6283. </ul>
  6284. <p>In the case that the token is not valid, the homeserver must respond with
  6285. <code>403 Forbidden</code> and an error code of <code>M_FORBIDDEN</code>.</p>
  6286. <p>As with other login types, there are additional fields (e.g. <code>device_id</code> and
  6287. <code>initial_device_display_name</code>) which can be included in the above request.</p>
  6288. <h2 id="preparing-synapse-1"><a class="header" href="#preparing-synapse-1">Preparing Synapse</a></h2>
  6289. <p>The JSON Web Token integration in Synapse uses the
  6290. <a href="https://pypi.org/project/pyjwt/"><code>PyJWT</code></a> library, which must be installed
  6291. as follows:</p>
  6292. <ul>
  6293. <li>
  6294. <p>The relevant libraries are included in the Docker images and Debian packages
  6295. provided by <code>matrix.org</code> so no further action is needed.</p>
  6296. </li>
  6297. <li>
  6298. <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>
  6299. </li>
  6300. <li>
  6301. <p>For other installation mechanisms, see the documentation provided by the
  6302. maintainer.</p>
  6303. </li>
  6304. </ul>
  6305. <p>To enable the JSON web token integration, you should then add an <code>jwt_config</code> section
  6306. to your configuration file (or uncomment the <code>enabled: true</code> line in the
  6307. existing section). See <a href="./sample_config.yaml">sample_config.yaml</a> for some
  6308. sample settings.</p>
  6309. <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>
  6310. <p>Although JSON Web Tokens are typically generated from an external server, the
  6311. examples below use <a href="https://pyjwt.readthedocs.io/en/latest/">PyJWT</a> directly.</p>
  6312. <ol>
  6313. <li>
  6314. <p>Configure Synapse with JWT logins, note that this example uses a pre-shared
  6315. secret and an algorithm of HS256:</p>
  6316. <pre><code class="language-yaml">jwt_config:
  6317. enabled: true
  6318. secret: &quot;my-secret-token&quot;
  6319. algorithm: &quot;HS256&quot;
  6320. </code></pre>
  6321. </li>
  6322. <li>
  6323. <p>Generate a JSON web token:</p>
  6324. <pre><code class="language-bash">$ pyjwt --key=my-secret-token --alg=HS256 encode sub=test-user
  6325. eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc
  6326. </code></pre>
  6327. </li>
  6328. <li>
  6329. <p>Query for the login types and ensure <code>org.matrix.login.jwt</code> is there:</p>
  6330. <pre><code class="language-bash">curl http://localhost:8080/_matrix/client/r0/login
  6331. </code></pre>
  6332. </li>
  6333. <li>
  6334. <p>Login used the generated JSON web token from above:</p>
  6335. <pre><code class="language-bash">$ curl http://localhost:8082/_matrix/client/r0/login -X POST \
  6336. --data '{&quot;type&quot;:&quot;org.matrix.login.jwt&quot;,&quot;token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc&quot;}'
  6337. {
  6338. &quot;access_token&quot;: &quot;&lt;access token&gt;&quot;,
  6339. &quot;device_id&quot;: &quot;ACBDEFGHI&quot;,
  6340. &quot;home_server&quot;: &quot;localhost:8080&quot;,
  6341. &quot;user_id&quot;: &quot;@test-user:localhost:8480&quot;
  6342. }
  6343. </code></pre>
  6344. </li>
  6345. </ol>
  6346. <p>You should now be able to use the returned access token to query the client API.</p>
  6347. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-2"><a class="header" href="#overview-2">Overview</a></h1>
  6348. <p>A captcha can be enabled on your homeserver to help prevent bots from registering
  6349. accounts. Synapse currently uses Google's reCAPTCHA service which requires API keys
  6350. from Google.</p>
  6351. <h2 id="getting-api-keys"><a class="header" href="#getting-api-keys">Getting API keys</a></h2>
  6352. <ol>
  6353. <li>Create a new site at <a href="https://www.google.com/recaptcha/admin/create">https://www.google.com/recaptcha/admin/create</a></li>
  6354. <li>Set the label to anything you want</li>
  6355. <li>Set the type to reCAPTCHA v2 using the &quot;I'm not a robot&quot; Checkbox option.
  6356. This is the only type of captcha that works with Synapse.</li>
  6357. <li>Add the public hostname for your server, as set in <code>public_baseurl</code>
  6358. in <code>homeserver.yaml</code>, to the list of authorized domains. If you have not set
  6359. <code>public_baseurl</code>, use <code>server_name</code>.</li>
  6360. <li>Agree to the terms of service and submit.</li>
  6361. <li>Copy your site key and secret key and add them to your <code>homeserver.yaml</code>
  6362. configuration file
  6363. <pre><code>recaptcha_public_key: YOUR_SITE_KEY
  6364. recaptcha_private_key: YOUR_SECRET_KEY
  6365. </code></pre>
  6366. </li>
  6367. <li>Enable the CAPTCHA for new registrations
  6368. <pre><code>enable_registration_captcha: true
  6369. </code></pre>
  6370. </li>
  6371. <li>Go to the settings page for the CAPTCHA you just created</li>
  6372. <li>Uncheck the &quot;Verify the origin of reCAPTCHA solutions&quot; checkbox so that the
  6373. captcha can be displayed in any client. If you do not disable this option then you
  6374. must specify the domains of every client that is allowed to display the CAPTCHA.</li>
  6375. </ol>
  6376. <h2 id="configuring-ip-used-for-auth"><a class="header" href="#configuring-ip-used-for-auth">Configuring IP used for auth</a></h2>
  6377. <p>The reCAPTCHA API requires that the IP address of the user who solved the
  6378. CAPTCHA is sent. If the client is connecting through a proxy or load balancer,
  6379. it may be required to use the <code>X-Forwarded-For</code> (XFF) header instead of the origin
  6380. IP address. This can be configured using the <code>x_forwarded</code> directive in the
  6381. listeners section of the <code>homeserver.yaml</code> configuration file.</p>
  6382. <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>
  6383. <p>The registration of new application services depends on the homeserver used.
  6384. In synapse, you need to create a new configuration file for your AS and add it
  6385. to the list specified under the <code>app_service_config_files</code> config
  6386. option in your synapse config.</p>
  6387. <p>For example:</p>
  6388. <pre><code class="language-yaml">app_service_config_files:
  6389. - /home/matrix/.synapse/&lt;your-AS&gt;.yaml
  6390. </code></pre>
  6391. <p>The format of the AS configuration file is as follows:</p>
  6392. <pre><code class="language-yaml">url: &lt;base url of AS&gt;
  6393. as_token: &lt;token AS will add to requests to HS&gt;
  6394. hs_token: &lt;token HS will add to requests to AS&gt;
  6395. sender_localpart: &lt;localpart of AS user&gt;
  6396. namespaces:
  6397. users: # List of users we're interested in
  6398. - exclusive: &lt;bool&gt;
  6399. regex: &lt;regex&gt;
  6400. group_id: &lt;group&gt;
  6401. - ...
  6402. aliases: [] # List of aliases we're interested in
  6403. rooms: [] # List of room ids we're interested in
  6404. </code></pre>
  6405. <p><code>exclusive</code>: If enabled, only this application service is allowed to register users in its namespace(s).
  6406. <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>
  6407. <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>
  6408. <div style="break-before: page; page-break-before: always;"></div><h1 id="server-notices"><a class="header" href="#server-notices">Server Notices</a></h1>
  6409. <p>'Server Notices' are a new feature introduced in Synapse 0.30. They provide a
  6410. channel whereby server administrators can send messages to users on the server.</p>
  6411. <p>They are used as part of communication of the server polices (see
  6412. <a href="consent_tracking.html">Consent Tracking</a>), however the intention is that
  6413. they may also find a use for features such as &quot;Message of the day&quot;.</p>
  6414. <p>This is a feature specific to Synapse, but it uses standard Matrix
  6415. communication mechanisms, so should work with any Matrix client.</p>
  6416. <h2 id="user-experience"><a class="header" href="#user-experience">User experience</a></h2>
  6417. <p>When the user is first sent a server notice, they will get an invitation to a
  6418. room (typically called 'Server Notices', though this is configurable in
  6419. <code>homeserver.yaml</code>). They will be <strong>unable to reject</strong> this invitation -
  6420. attempts to do so will receive an error.</p>
  6421. <p>Once they accept the invitation, they will see the notice message in the room
  6422. history; it will appear to have come from the 'server notices user' (see
  6423. below).</p>
  6424. <p>The user is prevented from sending any messages in this room by the power
  6425. levels.</p>
  6426. <p>Having joined the room, the user can leave the room if they want. Subsequent
  6427. server notices will then cause a new room to be created.</p>
  6428. <h2 id="synapse-configuration"><a class="header" href="#synapse-configuration">Synapse configuration</a></h2>
  6429. <p>Server notices come from a specific user id on the server. Server
  6430. administrators are free to choose the user id - something like <code>server</code> is
  6431. suggested, meaning the notices will come from
  6432. <code>@server:&lt;your_server_name&gt;</code>. Once the Server Notices user is configured, that
  6433. user id becomes a special, privileged user, so administrators should ensure
  6434. that <strong>it is not already allocated</strong>.</p>
  6435. <p>In order to support server notices, it is necessary to add some configuration
  6436. to the <code>homeserver.yaml</code> file. In particular, you should add a <code>server_notices</code>
  6437. section, which should look like this:</p>
  6438. <pre><code class="language-yaml">server_notices:
  6439. system_mxid_localpart: server
  6440. system_mxid_display_name: &quot;Server Notices&quot;
  6441. system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  6442. room_name: &quot;Server Notices&quot;
  6443. </code></pre>
  6444. <p>The only compulsory setting is <code>system_mxid_localpart</code>, which defines the user
  6445. id of the Server Notices user, as above. <code>room_name</code> defines the name of the
  6446. room which will be created.</p>
  6447. <p><code>system_mxid_display_name</code> and <code>system_mxid_avatar_url</code> can be used to set the
  6448. displayname and avatar of the Server Notices user.</p>
  6449. <h2 id="sending-notices"><a class="header" href="#sending-notices">Sending notices</a></h2>
  6450. <p>To send server notices to users you can use the
  6451. <a href="admin_api/server_notices.html">admin_api</a>.</p>
  6452. <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>
  6453. <p>Synapse 0.30 introduces support for tracking whether users have agreed to the
  6454. terms and conditions set by the administrator of a server - and blocking access
  6455. to the server until they have.</p>
  6456. <p>There are several parts to this functionality; each requires some specific
  6457. configuration in <code>homeserver.yaml</code> to be enabled.</p>
  6458. <p>Note that various parts of the configuation and this document refer to the
  6459. &quot;privacy policy&quot;: agreement with a privacy policy is one particular use of this
  6460. feature, but of course adminstrators can specify other terms and conditions
  6461. unrelated to &quot;privacy&quot; per se.</p>
  6462. <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>
  6463. <p>Synapse can be configured to serve the user a simple policy form with an
  6464. &quot;accept&quot; button. Clicking &quot;Accept&quot; records the user's acceptance in the
  6465. database and shows a success page.</p>
  6466. <p>To enable this, first create templates for the policy and success pages.
  6467. These should be stored on the local filesystem.</p>
  6468. <p>These templates use the <a href="http://jinja.pocoo.org">Jinja2</a> templating language,
  6469. and <a href="https://github.com/matrix-org/synapse/tree/develop/docs/privacy_policy_templates/">docs/privacy_policy_templates</a>
  6470. gives examples of the sort of thing that can be done.</p>
  6471. <p>Note that the templates must be stored under a name giving the language of the
  6472. template - currently this must always be <code>en</code> (for &quot;English&quot;);
  6473. internationalisation support is intended for the future.</p>
  6474. <p>The template for the policy itself should be versioned and named according to
  6475. the version: for example <code>1.0.html</code>. The version of the policy which the user
  6476. has agreed to is stored in the database.</p>
  6477. <p>Once the templates are in place, make the following changes to <code>homeserver.yaml</code>:</p>
  6478. <ol>
  6479. <li>
  6480. <p>Add a <code>user_consent</code> section, which should look like:</p>
  6481. <pre><code class="language-yaml">user_consent:
  6482. template_dir: privacy_policy_templates
  6483. version: 1.0
  6484. </code></pre>
  6485. <p><code>template_dir</code> points to the directory containing the policy
  6486. templates. <code>version</code> defines the version of the policy which will be served
  6487. to the user. In the example above, Synapse will serve
  6488. <code>privacy_policy_templates/en/1.0.html</code>.</p>
  6489. </li>
  6490. <li>
  6491. <p>Add a <code>form_secret</code> setting at the top level:</p>
  6492. <pre><code class="language-yaml">form_secret: &quot;&lt;unique secret&gt;&quot;
  6493. </code></pre>
  6494. <p>This should be set to an arbitrary secret string (try <code>pwgen -y 30</code> to
  6495. generate suitable secrets).</p>
  6496. <p>More on what this is used for below.</p>
  6497. </li>
  6498. <li>
  6499. <p>Add <code>consent</code> wherever the <code>client</code> resource is currently enabled in the
  6500. <code>listeners</code> configuration. For example:</p>
  6501. <pre><code class="language-yaml">listeners:
  6502. - port: 8008
  6503. resources:
  6504. - names:
  6505. - client
  6506. - consent
  6507. </code></pre>
  6508. </li>
  6509. </ol>
  6510. <p>Finally, ensure that <code>jinja2</code> is installed. If you are using a virtualenv, this
  6511. should be a matter of <code>pip install Jinja2</code>. On debian, try <code>apt-get install python-jinja2</code>.</p>
  6512. <p>Once this is complete, and the server has been restarted, try visiting
  6513. <code>https://&lt;server&gt;/_matrix/consent</code>. If correctly configured, this should give
  6514. an error &quot;Missing string query parameter 'u'&quot;. It is now possible to manually
  6515. construct URIs where users can give their consent.</p>
  6516. <h3 id="enabling-consent-tracking-at-registration"><a class="header" href="#enabling-consent-tracking-at-registration">Enabling consent tracking at registration</a></h3>
  6517. <ol>
  6518. <li>
  6519. <p>Add the following to your configuration:</p>
  6520. <pre><code class="language-yaml">user_consent:
  6521. require_at_registration: true
  6522. policy_name: &quot;Privacy Policy&quot; # or whatever you'd like to call the policy
  6523. </code></pre>
  6524. </li>
  6525. <li>
  6526. <p>In your consent templates, make use of the <code>public_version</code> variable to
  6527. see if an unauthenticated user is viewing the page. This is typically
  6528. wrapped around the form that would be used to actually agree to the document:</p>
  6529. <pre><code>{% if not public_version %}
  6530. &lt;!-- The variables used here are only provided when the 'u' param is given to the homeserver --&gt;
  6531. &lt;form method=&quot;post&quot; action=&quot;consent&quot;&gt;
  6532. &lt;input type=&quot;hidden&quot; name=&quot;v&quot; value=&quot;{{version}}&quot;/&gt;
  6533. &lt;input type=&quot;hidden&quot; name=&quot;u&quot; value=&quot;{{user}}&quot;/&gt;
  6534. &lt;input type=&quot;hidden&quot; name=&quot;h&quot; value=&quot;{{userhmac}}&quot;/&gt;
  6535. &lt;input type=&quot;submit&quot; value=&quot;Sure thing!&quot;/&gt;
  6536. &lt;/form&gt;
  6537. {% endif %}
  6538. </code></pre>
  6539. </li>
  6540. <li>
  6541. <p>Restart Synapse to apply the changes.</p>
  6542. </li>
  6543. </ol>
  6544. <p>Visiting <code>https://&lt;server&gt;/_matrix/consent</code> should now give you a view of the privacy
  6545. document. This is what users will be able to see when registering for accounts.</p>
  6546. <h3 id="constructing-the-consent-uri"><a class="header" href="#constructing-the-consent-uri">Constructing the consent URI</a></h3>
  6547. <p>It may be useful to manually construct the &quot;consent URI&quot; for a given user - for
  6548. instance, in order to send them an email asking them to consent. To do this,
  6549. take the base <code>https://&lt;server&gt;/_matrix/consent</code> URL and add the following
  6550. query parameters:</p>
  6551. <ul>
  6552. <li>
  6553. <p><code>u</code>: the user id of the user. This can either be a full MXID
  6554. (<code>@user:server.com</code>) or just the localpart (<code>user</code>).</p>
  6555. </li>
  6556. <li>
  6557. <p><code>h</code>: hex-encoded HMAC-SHA256 of <code>u</code> using the <code>form_secret</code> as a key. It is
  6558. possible to calculate this on the commandline with something like:</p>
  6559. <pre><code class="language-bash">echo -n '&lt;user&gt;' | openssl sha256 -hmac '&lt;form_secret&gt;'
  6560. </code></pre>
  6561. <p>This should result in a URI which looks something like:
  6562. <code>https://&lt;server&gt;/_matrix/consent?u=&lt;user&gt;&amp;h=68a152465a4d...</code>.</p>
  6563. </li>
  6564. </ul>
  6565. <p>Note that not providing a <code>u</code> parameter will be interpreted as wanting to view
  6566. the document from an unauthenticated perspective, such as prior to registration.
  6567. Therefore, the <code>h</code> parameter is not required in this scenario. To enable this
  6568. behaviour, set <code>require_at_registration</code> to <code>true</code> in your <code>user_consent</code> config.</p>
  6569. <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>
  6570. <p>It is possible to configure Synapse to send a <a href="server_notices.html">server
  6571. notice</a> to anybody who has not yet agreed to the current
  6572. version of the policy. To do so:</p>
  6573. <ul>
  6574. <li>
  6575. <p>ensure that the consent resource is configured, as in the previous section</p>
  6576. </li>
  6577. <li>
  6578. <p>ensure that server notices are configured, as in <a href="server_notices.html">the server notice documentation</a>.</p>
  6579. </li>
  6580. <li>
  6581. <p>Add <code>server_notice_content</code> under <code>user_consent</code> in <code>homeserver.yaml</code>. For
  6582. example:</p>
  6583. <pre><code class="language-yaml">user_consent:
  6584. server_notice_content:
  6585. msgtype: m.text
  6586. body: &gt;-
  6587. Please give your consent to the privacy policy at %(consent_uri)s.
  6588. </code></pre>
  6589. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6590. consent uri for that user.</p>
  6591. </li>
  6592. <li>
  6593. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6594. URI that clients use to connect to the server. (It is used to construct
  6595. <code>consent_uri</code> in the server notice.)</p>
  6596. </li>
  6597. </ul>
  6598. <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>
  6599. <p>Synapse can be configured to block any attempts to join rooms or send messages
  6600. until the user has given their agreement to the policy. (Joining the server
  6601. notices room is exempted from this).</p>
  6602. <p>To enable this, add <code>block_events_error</code> under <code>user_consent</code>. For example:</p>
  6603. <pre><code class="language-yaml">user_consent:
  6604. block_events_error: &gt;-
  6605. You can't send any messages until you consent to the privacy policy at
  6606. %(consent_uri)s.
  6607. </code></pre>
  6608. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6609. consent uri for that user.</p>
  6610. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6611. URI that clients use to connect to the server. (It is used to construct
  6612. <code>consent_uri</code> in the error.)</p>
  6613. <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>
  6614. <p>Design notes on a URL previewing service for Matrix:</p>
  6615. <p>Options are:</p>
  6616. <ol>
  6617. <li>Have an AS which listens for URLs, downloads them, and inserts an event that describes their metadata.</li>
  6618. </ol>
  6619. <ul>
  6620. <li>Pros:
  6621. <ul>
  6622. <li>Decouples the implementation entirely from Synapse.</li>
  6623. <li>Uses existing Matrix events &amp; content repo to store the metadata.</li>
  6624. </ul>
  6625. </li>
  6626. <li>Cons:
  6627. <ul>
  6628. <li>Which AS should provide this service for a room, and why should you trust it?</li>
  6629. <li>Doesn't work well with E2E; you'd have to cut the AS into every room</li>
  6630. <li>the AS would end up subscribing to every room anyway.</li>
  6631. </ul>
  6632. </li>
  6633. </ul>
  6634. <ol start="2">
  6635. <li>Have a generic preview API (nothing to do with Matrix) that provides a previewing service:</li>
  6636. </ol>
  6637. <ul>
  6638. <li>Pros:
  6639. <ul>
  6640. <li>Simple and flexible; can be used by any clients at any point</li>
  6641. </ul>
  6642. </li>
  6643. <li>Cons:
  6644. <ul>
  6645. <li>If each HS provides one of these independently, all the HSes in a room may needlessly DoS the target URI</li>
  6646. <li>We need somewhere to store the URL metadata rather than just using Matrix itself</li>
  6647. <li>We can't piggyback on matrix to distribute the metadata between HSes.</li>
  6648. </ul>
  6649. </li>
  6650. </ul>
  6651. <ol start="3">
  6652. <li>Make the synapse of the sending user responsible for spidering the URL and inserting an event asynchronously which describes the metadata.</li>
  6653. </ol>
  6654. <ul>
  6655. <li>Pros:
  6656. <ul>
  6657. <li>Works transparently for all clients</li>
  6658. <li>Piggy-backs nicely on using Matrix for distributing the metadata.</li>
  6659. <li>No confusion as to which AS</li>
  6660. </ul>
  6661. </li>
  6662. <li>Cons:
  6663. <ul>
  6664. <li>Doesn't work with E2E</li>
  6665. <li>We might want to decouple the implementation of the spider from the HS, given spider behaviour can be quite complicated and evolve much more rapidly than the HS. It's more like a bot than a core part of the server.</li>
  6666. </ul>
  6667. </li>
  6668. </ul>
  6669. <ol start="4">
  6670. <li>Make the sending client use the preview API and insert the event itself when successful.</li>
  6671. </ol>
  6672. <ul>
  6673. <li>Pros:
  6674. <ul>
  6675. <li>Works well with E2E</li>
  6676. <li>No custom server functionality</li>
  6677. <li>Lets the client customise the preview that they send (like on FB)</li>
  6678. </ul>
  6679. </li>
  6680. <li>Cons:
  6681. <ul>
  6682. <li>Entirely specific to the sending client, whereas it'd be nice if /any/ URL was correctly previewed if clients support it.</li>
  6683. </ul>
  6684. </li>
  6685. </ul>
  6686. <ol start="5">
  6687. <li>Have the option of specifying a shared (centralised) previewing service used by a room, to avoid all the different HSes in the room DoSing the target.</li>
  6688. </ol>
  6689. <p>Best solution is probably a combination of both 2 and 4.</p>
  6690. <ul>
  6691. <li>Sending clients do their best to create and send a preview at the point of sending the message, perhaps delaying the message until the preview is computed? (This also lets the user validate the preview before sending)</li>
  6692. <li>Receiving clients have the option of going and creating their own preview if one doesn't arrive soon enough (or if the original sender didn't create one)</li>
  6693. </ul>
  6694. <p>This is a bit magical though in that the preview could come from two entirely different sources - the sending HS or your local one. However, this can always be exposed to users: &quot;Generate your own URL previews if none are available?&quot;</p>
  6695. <p>This is tantamount also to senders calculating their own thumbnails for sending in advance of the main content - we are trusting the sender not to lie about the content in the thumbnail. Whereas currently thumbnails are calculated by the receiving homeserver to avoid this attack.</p>
  6696. <p>However, this kind of phishing attack does exist whether we let senders pick their thumbnails or not, in that a malicious sender can send normal text messages around the attachment claiming it to be legitimate. We could rely on (future) reputation/abuse management to punish users who phish (be it with bogus metadata or bogus descriptions). Bogus metadata is particularly bad though, especially if it's avoidable.</p>
  6697. <p>As a first cut, let's do #2 and have the receiver hit the API to calculate its own previews (as it does currently for image thumbnails). We can then extend/optimise this to option 4 as a special extra if needed.</p>
  6698. <h2 id="api"><a class="header" href="#api">API</a></h2>
  6699. <pre><code>GET /_matrix/media/r0/preview_url?url=http://wherever.com
  6700. 200 OK
  6701. {
  6702. &quot;og:type&quot; : &quot;article&quot;
  6703. &quot;og:url&quot; : &quot;https://twitter.com/matrixdotorg/status/684074366691356672&quot;
  6704. &quot;og:title&quot; : &quot;Matrix on Twitter&quot;
  6705. &quot;og:image&quot; : &quot;https://pbs.twimg.com/profile_images/500400952029888512/yI0qtFi7_400x400.png&quot;
  6706. &quot;og:description&quot; : &quot;“Synapse 0.12 is out! Lots of polishing, performance &amp;amp;amp; bugfixes: /sync API, /r0 prefix, fulltext search, 3PID invites https://t.co/5alhXLLEGP”&quot;
  6707. &quot;og:site_name&quot; : &quot;Twitter&quot;
  6708. }
  6709. </code></pre>
  6710. <ul>
  6711. <li>Downloads the URL
  6712. <ul>
  6713. <li>If HTML, just stores it in RAM and parses it for OG meta tags
  6714. <ul>
  6715. <li>Download any media OG meta tags to the media repo, and refer to them in the OG via mxc:// URIs.</li>
  6716. </ul>
  6717. </li>
  6718. <li>If a media filetype we know we can thumbnail: store it on disk, and hand it to the thumbnailer. Generate OG meta tags from the thumbnailer contents.</li>
  6719. <li>Otherwise, don't bother downloading further.</li>
  6720. </ul>
  6721. </li>
  6722. </ul>
  6723. <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>
  6724. <p>The user directory is currently maintained based on the 'visible' users
  6725. on this particular server - i.e. ones which your account shares a room with, or
  6726. who are present in a publicly viewable room present on the server.</p>
  6727. <p>The directory info is stored in various tables, which can (typically after
  6728. DB corruption) get stale or out of sync. If this happens, for now the
  6729. 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>
  6730. and then restart synapse. This should then start a background task to
  6731. flush the current tables and regenerate the directory.</p>
  6732. <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>
  6733. <p>Synapse admins can enable support for message retention policies on
  6734. their homeserver. Message retention policies exist at a room level,
  6735. follow the semantics described in
  6736. <a href="https://github.com/matrix-org/matrix-doc/blob/matthew/msc1763/proposals/1763-configurable-retention-periods.md">MSC1763</a>,
  6737. and allow server and room admins to configure how long messages should
  6738. be kept in a homeserver's database before being purged from it.
  6739. <strong>Please note that, as this feature isn't part of the Matrix
  6740. specification yet, this implementation is to be considered as
  6741. experimental.</strong> </p>
  6742. <p>A message retention policy is mainly defined by its <code>max_lifetime</code>
  6743. parameter, which defines how long a message can be kept around after
  6744. it was sent to the room. If a room doesn't have a message retention
  6745. policy, and there's no default one for a given server, then no message
  6746. sent in that room is ever purged on that server.</p>
  6747. <p>MSC1763 also specifies semantics for a <code>min_lifetime</code> parameter which
  6748. defines the amount of time after which an event <em>can</em> get purged (after
  6749. it was sent to the room), but Synapse doesn't currently support it
  6750. beyond registering it.</p>
  6751. <p>Both <code>max_lifetime</code> and <code>min_lifetime</code> are optional parameters.</p>
  6752. <p>Note that message retention policies don't apply to state events.</p>
  6753. <p>Once an event reaches its expiry date (defined as the time it was sent
  6754. plus the value for <code>max_lifetime</code> in the room), two things happen:</p>
  6755. <ul>
  6756. <li>Synapse stops serving the event to clients via any endpoint.</li>
  6757. <li>The message gets picked up by the next purge job (see the &quot;Purge jobs&quot;
  6758. section) and is removed from Synapse's database.</li>
  6759. </ul>
  6760. <p>Since purge jobs don't run continuously, this means that an event might
  6761. stay in a server's database for longer than the value for <code>max_lifetime</code>
  6762. in the room would allow, though hidden from clients.</p>
  6763. <p>Similarly, if a server (with support for message retention policies
  6764. enabled) receives from another server an event that should have been
  6765. purged according to its room's policy, then the receiving server will
  6766. process and store that event until it's picked up by the next purge job,
  6767. though it will always hide it from clients.</p>
  6768. <p>Synapse requires at least one message in each room, so it will never
  6769. delete the last message in a room. It will, however, hide it from
  6770. clients.</p>
  6771. <h2 id="server-configuration"><a class="header" href="#server-configuration">Server configuration</a></h2>
  6772. <p>Support for this feature can be enabled and configured in the
  6773. <code>retention</code> section of the Synapse configuration file (see the
  6774. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample file</a>).</p>
  6775. <p>To enable support for message retention policies, set the setting
  6776. <code>enabled</code> in this section to <code>true</code>.</p>
  6777. <h3 id="default-policy"><a class="header" href="#default-policy">Default policy</a></h3>
  6778. <p>A default message retention policy is a policy defined in Synapse's
  6779. configuration that is used by Synapse for every room that doesn't have a
  6780. message retention policy configured in its state. This allows server
  6781. admins to ensure that messages are never kept indefinitely in a server's
  6782. database. </p>
  6783. <p>A default policy can be defined as such, in the <code>retention</code> section of
  6784. the configuration file:</p>
  6785. <pre><code class="language-yaml"> default_policy:
  6786. min_lifetime: 1d
  6787. max_lifetime: 1y
  6788. </code></pre>
  6789. <p>Here, <code>min_lifetime</code> and <code>max_lifetime</code> have the same meaning and level
  6790. of support as previously described. They can be expressed either as a
  6791. duration (using the units <code>s</code> (seconds), <code>m</code> (minutes), <code>h</code> (hours),
  6792. <code>d</code> (days), <code>w</code> (weeks) and <code>y</code> (years)) or as a number of milliseconds.</p>
  6793. <h3 id="purge-jobs"><a class="header" href="#purge-jobs">Purge jobs</a></h3>
  6794. <p>Purge jobs are the jobs that Synapse runs in the background to purge
  6795. expired events from the database. They are only run if support for
  6796. message retention policies is enabled in the server's configuration. If
  6797. no configuration for purge jobs is configured by the server admin,
  6798. Synapse will use a default configuration, which is described in the
  6799. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample configuration file</a>.</p>
  6800. <p>Some server admins might want a finer control on when events are removed
  6801. depending on an event's room's policy. This can be done by setting the
  6802. <code>purge_jobs</code> sub-section in the <code>retention</code> section of the configuration
  6803. file. An example of such configuration could be:</p>
  6804. <pre><code class="language-yaml"> purge_jobs:
  6805. - longest_max_lifetime: 3d
  6806. interval: 12h
  6807. - shortest_max_lifetime: 3d
  6808. longest_max_lifetime: 1w
  6809. interval: 1d
  6810. - shortest_max_lifetime: 1w
  6811. interval: 2d
  6812. </code></pre>
  6813. <p>In this example, we define three jobs:</p>
  6814. <ul>
  6815. <li>one that runs twice a day (every 12 hours) and purges events in rooms
  6816. which policy's <code>max_lifetime</code> is lower or equal to 3 days.</li>
  6817. <li>one that runs once a day and purges events in rooms which policy's
  6818. <code>max_lifetime</code> is between 3 days and a week.</li>
  6819. <li>one that runs once every 2 days and purges events in rooms which
  6820. policy's <code>max_lifetime</code> is greater than a week.</li>
  6821. </ul>
  6822. <p>Note that this example is tailored to show different configurations and
  6823. features slightly more jobs than it's probably necessary (in practice, a
  6824. server admin would probably consider it better to replace the two last
  6825. jobs with one that runs once a day and handles rooms which which
  6826. policy's <code>max_lifetime</code> is greater than 3 days).</p>
  6827. <p>Keep in mind, when configuring these jobs, that a purge job can become
  6828. quite heavy on the server if it targets many rooms, therefore prefer
  6829. having jobs with a low interval that target a limited set of rooms. Also
  6830. make sure to include a job with no minimum and one with no maximum to
  6831. make sure your configuration handles every policy.</p>
  6832. <p>As previously mentioned in this documentation, while a purge job that
  6833. runs e.g. every day means that an expired event might stay in the
  6834. database for up to a day after its expiry, Synapse hides expired events
  6835. from clients as soon as they expire, so the event is not visible to
  6836. local users between its expiry date and the moment it gets purged from
  6837. the server's database.</p>
  6838. <h3 id="lifetime-limits"><a class="header" href="#lifetime-limits">Lifetime limits</a></h3>
  6839. <p>Server admins can set limits on the values of <code>max_lifetime</code> to use when
  6840. purging old events in a room. These limits can be defined as such in the
  6841. <code>retention</code> section of the configuration file:</p>
  6842. <pre><code class="language-yaml"> allowed_lifetime_min: 1d
  6843. allowed_lifetime_max: 1y
  6844. </code></pre>
  6845. <p>The limits are considered when running purge jobs. If necessary, the
  6846. effective value of <code>max_lifetime</code> will be brought between
  6847. <code>allowed_lifetime_min</code> and <code>allowed_lifetime_max</code> (inclusive).
  6848. This means that, if the value of <code>max_lifetime</code> defined in the room's state
  6849. is lower than <code>allowed_lifetime_min</code>, the value of <code>allowed_lifetime_min</code>
  6850. will be used instead. Likewise, if the value of <code>max_lifetime</code> is higher
  6851. than <code>allowed_lifetime_max</code>, the value of <code>allowed_lifetime_max</code> will be
  6852. used instead.</p>
  6853. <p>In the example above, we ensure Synapse never deletes events that are less
  6854. than one day old, and that it always deletes events that are over a year
  6855. old.</p>
  6856. <p>If a default policy is set, and its <code>max_lifetime</code> value is lower than
  6857. <code>allowed_lifetime_min</code> or higher than <code>allowed_lifetime_max</code>, the same
  6858. process applies.</p>
  6859. <p>Both parameters are optional; if one is omitted Synapse won't use it to
  6860. adjust the effective value of <code>max_lifetime</code>.</p>
  6861. <p>Like other settings in this section, these parameters can be expressed
  6862. either as a duration or as a number of milliseconds.</p>
  6863. <h2 id="room-configuration"><a class="header" href="#room-configuration">Room configuration</a></h2>
  6864. <p>To configure a room's message retention policy, a room's admin or
  6865. moderator needs to send a state event in that room with the type
  6866. <code>m.room.retention</code> and the following content:</p>
  6867. <pre><code class="language-json">{
  6868. &quot;max_lifetime&quot;: ...
  6869. }
  6870. </code></pre>
  6871. <p>In this event's content, the <code>max_lifetime</code> parameter has the same
  6872. meaning as previously described, and needs to be expressed in
  6873. milliseconds. The event's content can also include a <code>min_lifetime</code>
  6874. parameter, which has the same meaning and limited support as previously
  6875. described.</p>
  6876. <p>Note that over every server in the room, only the ones with support for
  6877. message retention policies will actually remove expired events. This
  6878. support is currently not enabled by default in Synapse.</p>
  6879. <h2 id="note-on-reclaiming-disk-space"><a class="header" href="#note-on-reclaiming-disk-space">Note on reclaiming disk space</a></h2>
  6880. <p>While purge jobs actually delete data from the database, the disk space
  6881. used by the database might not decrease immediately on the database's
  6882. host. However, even though the database engine won't free up the disk
  6883. space, it will start writing new data into where the purged data was.</p>
  6884. <p>If you want to reclaim the freed disk space anyway and return it to the
  6885. operating system, the server admin needs to run <code>VACUUM FULL;</code> (or
  6886. <code>VACUUM;</code> for SQLite databases) on Synapse's database (see the related
  6887. <a href="https://www.postgresql.org/docs/current/sql-vacuum.html">PostgreSQL documentation</a>).</p>
  6888. <div style="break-before: page; page-break-before: always;"></div><h1 id="modules"><a class="header" href="#modules">Modules</a></h1>
  6889. <p>Synapse supports extending its functionality by configuring external modules.</p>
  6890. <h2 id="using-modules"><a class="header" href="#using-modules">Using modules</a></h2>
  6891. <p>To use a module on Synapse, add it to the <code>modules</code> section of the configuration file:</p>
  6892. <pre><code class="language-yaml">modules:
  6893. - module: my_super_module.MySuperClass
  6894. config:
  6895. do_thing: true
  6896. - module: my_other_super_module.SomeClass
  6897. config: {}
  6898. </code></pre>
  6899. <p>Each module is defined by a path to a Python class as well as a configuration. This
  6900. information for a given module should be available in the module's own documentation.</p>
  6901. <p><strong>Note</strong>: When using third-party modules, you effectively allow someone else to run
  6902. custom code on your Synapse homeserver. Server admins are encouraged to verify the
  6903. provenance of the modules they use on their homeserver and make sure the modules aren't
  6904. running malicious code on their instance.</p>
  6905. <p>Also note that we are currently in the process of migrating module interfaces to this
  6906. system. While some interfaces might be compatible with it, others still require
  6907. configuring modules in another part of Synapse's configuration file. Currently, only the
  6908. spam checker interface is compatible with this new system.</p>
  6909. <h2 id="writing-a-module"><a class="header" href="#writing-a-module">Writing a module</a></h2>
  6910. <p>A module is a Python class that uses Synapse's module API to interact with the
  6911. homeserver. It can register callbacks that Synapse will call on specific operations, as
  6912. well as web resources to attach to Synapse's web server.</p>
  6913. <p>When instantiated, a module is given its parsed configuration as well as an instance of
  6914. the <code>synapse.module_api.ModuleApi</code> class. The configuration is a dictionary, and is
  6915. either the output of the module's <code>parse_config</code> static method (see below), or the
  6916. configuration associated with the module in Synapse's configuration file.</p>
  6917. <p>See the documentation for the <code>ModuleApi</code> class
  6918. <a href="https://github.com/matrix-org/synapse/blob/master/synapse/module_api/__init__.py">here</a>.</p>
  6919. <h3 id="handling-the-modules-configuration"><a class="header" href="#handling-the-modules-configuration">Handling the module's configuration</a></h3>
  6920. <p>A module can implement the following static method:</p>
  6921. <pre><code class="language-python">@staticmethod
  6922. def parse_config(config: dict) -&gt; dict
  6923. </code></pre>
  6924. <p>This method is given a dictionary resulting from parsing the YAML configuration for the
  6925. module. It may modify it (for example by parsing durations expressed as strings (e.g.
  6926. &quot;5d&quot;) into milliseconds, etc.), and return the modified dictionary. It may also verify
  6927. that the configuration is correct, and raise an instance of
  6928. <code>synapse.module_api.errors.ConfigError</code> if not.</p>
  6929. <h3 id="registering-a-web-resource"><a class="header" href="#registering-a-web-resource">Registering a web resource</a></h3>
  6930. <p>Modules can register web resources onto Synapse's web server using the following module
  6931. API method:</p>
  6932. <pre><code class="language-python">def ModuleApi.register_web_resource(path: str, resource: IResource) -&gt; None
  6933. </code></pre>
  6934. <p>The path is the full absolute path to register the resource at. For example, if you
  6935. register a resource for the path <code>/_synapse/client/my_super_module/say_hello</code>, Synapse
  6936. will serve it at <code>http(s)://[HS_URL]/_synapse/client/my_super_module/say_hello</code>. Note
  6937. that Synapse does not allow registering resources for several sub-paths in the <code>/_matrix</code>
  6938. namespace (such as anything under <code>/_matrix/client</code> for example). It is strongly
  6939. recommended that modules register their web resources under the <code>/_synapse/client</code>
  6940. namespace.</p>
  6941. <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>
  6942. interface (such as <a href="https://twistedmatrix.com/documents/current/api/twisted.web.resource.Resource.html">Resource</a>).</p>
  6943. <p>Only one resource can be registered for a given path. If several modules attempt to
  6944. register a resource for the same path, the module that appears first in Synapse's
  6945. configuration file takes priority.</p>
  6946. <p>Modules <strong>must</strong> register their web resources in their <code>__init__</code> method.</p>
  6947. <h3 id="registering-a-callback"><a class="header" href="#registering-a-callback">Registering a callback</a></h3>
  6948. <p>Modules can use Synapse's module API to register callbacks. Callbacks are functions that
  6949. Synapse will call when performing specific actions. Callbacks must be asynchronous, and
  6950. are split in categories. A single module may implement callbacks from multiple categories,
  6951. and is under no obligation to implement all callbacks from the categories it registers
  6952. callbacks for.</p>
  6953. <p>Modules can register callbacks using one of the module API's <code>register_[...]_callbacks</code>
  6954. methods. The callback functions are passed to these methods as keyword arguments, with
  6955. the callback name as the argument name and the function as its value. This is demonstrated
  6956. in the example below. A <code>register_[...]_callbacks</code> method exists for each module type
  6957. documented in this section.</p>
  6958. <h4 id="spam-checker-callbacks"><a class="header" href="#spam-checker-callbacks">Spam checker callbacks</a></h4>
  6959. <p>Spam checker callbacks allow module developers to implement spam mitigation actions for
  6960. Synapse instances. Spam checker callbacks can be registered using the module API's
  6961. <code>register_spam_checker_callbacks</code> method.</p>
  6962. <p>The available spam checker callbacks are:</p>
  6963. <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]
  6964. </code></pre>
  6965. <p>Called when receiving an event from a client or via federation. The module can return
  6966. either a <code>bool</code> to indicate whether the event must be rejected because of spam, or a <code>str</code>
  6967. to indicate the event must be rejected because of spam and to give a rejection reason to
  6968. forward to clients.</p>
  6969. <pre><code class="language-python">async def user_may_invite(inviter: str, invitee: str, room_id: str) -&gt; bool
  6970. </code></pre>
  6971. <p>Called when processing an invitation. The module must return a <code>bool</code> indicating whether
  6972. the inviter can invite the invitee to the given room. Both inviter and invitee are
  6973. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  6974. <pre><code class="language-python">async def user_may_create_room(user: str) -&gt; bool
  6975. </code></pre>
  6976. <p>Called when processing a room creation request. The module must return a <code>bool</code> indicating
  6977. whether the given user (represented by their Matrix user ID) is allowed to create a room.</p>
  6978. <pre><code class="language-python">async def user_may_create_room_alias(user: str, room_alias: &quot;synapse.types.RoomAlias&quot;) -&gt; bool
  6979. </code></pre>
  6980. <p>Called when trying to associate an alias with an existing room. The module must return a
  6981. <code>bool</code> indicating whether the given user (represented by their Matrix user ID) is allowed
  6982. to set the given alias.</p>
  6983. <pre><code class="language-python">async def user_may_publish_room(user: str, room_id: str) -&gt; bool
  6984. </code></pre>
  6985. <p>Called when trying to publish a room to the homeserver's public rooms directory. The
  6986. module must return a <code>bool</code> indicating whether the given user (represented by their
  6987. Matrix user ID) is allowed to publish the given room.</p>
  6988. <pre><code class="language-python">async def check_username_for_spam(user_profile: Dict[str, str]) -&gt; bool
  6989. </code></pre>
  6990. <p>Called when computing search results in the user directory. The module must return a
  6991. <code>bool</code> indicating whether the given user profile can appear in search results. The profile
  6992. is represented as a dictionary with the following keys:</p>
  6993. <ul>
  6994. <li><code>user_id</code>: The Matrix ID for this user.</li>
  6995. <li><code>display_name</code>: The user's display name.</li>
  6996. <li><code>avatar_url</code>: The <code>mxc://</code> URL to the user's avatar.</li>
  6997. </ul>
  6998. <p>The module is given a copy of the original dictionary, so modifying it from within the
  6999. module cannot modify a user's profile when included in user directory search results.</p>
  7000. <pre><code class="language-python">async def check_registration_for_spam(
  7001. email_threepid: Optional[dict],
  7002. username: Optional[str],
  7003. request_info: Collection[Tuple[str, str]],
  7004. auth_provider_id: Optional[str] = None,
  7005. ) -&gt; &quot;synapse.spam_checker_api.RegistrationBehaviour&quot;
  7006. </code></pre>
  7007. <p>Called when registering a new user. The module must return a <code>RegistrationBehaviour</code>
  7008. indicating whether the registration can go through or must be denied, or whether the user
  7009. may be allowed to register but will be shadow banned.</p>
  7010. <p>The arguments passed to this callback are:</p>
  7011. <ul>
  7012. <li><code>email_threepid</code>: The email address used for registering, if any.</li>
  7013. <li><code>username</code>: The username the user would like to register. Can be <code>None</code>, meaning that
  7014. Synapse will generate one later.</li>
  7015. <li><code>request_info</code>: A collection of tuples, which first item is a user agent, and which
  7016. second item is an IP address. These user agents and IP addresses are the ones that were
  7017. used during the registration process.</li>
  7018. <li><code>auth_provider_id</code>: The identifier of the SSO authentication provider, if any.</li>
  7019. </ul>
  7020. <pre><code class="language-python">async def check_media_file_for_spam(
  7021. file_wrapper: &quot;synapse.rest.media.v1.media_storage.ReadableFileWrapper&quot;,
  7022. file_info: &quot;synapse.rest.media.v1._base.FileInfo&quot;,
  7023. ) -&gt; bool
  7024. </code></pre>
  7025. <p>Called when storing a local or remote file. The module must return a boolean indicating
  7026. whether the given file can be stored in the homeserver's media store.</p>
  7027. <h4 id="account-validity-callbacks"><a class="header" href="#account-validity-callbacks">Account validity callbacks</a></h4>
  7028. <p>Account validity callbacks allow module developers to add extra steps to verify the
  7029. validity on an account, i.e. see if a user can be granted access to their account on the
  7030. Synapse instance. Account validity callbacks can be registered using the module API's
  7031. <code>register_account_validity_callbacks</code> method.</p>
  7032. <p>The available account validity callbacks are:</p>
  7033. <pre><code class="language-python">async def is_user_expired(user: str) -&gt; Optional[bool]
  7034. </code></pre>
  7035. <p>Called when processing any authenticated request (except for logout requests). The module
  7036. can return a <code>bool</code> to indicate whether the user has expired and should be locked out of
  7037. their account, or <code>None</code> if the module wasn't able to figure it out. The user is
  7038. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7039. <p>If the module returns <code>True</code>, the current request will be denied with the error code
  7040. <code>ORG_MATRIX_EXPIRED_ACCOUNT</code> and the HTTP status code 403. Note that this doesn't
  7041. invalidate the user's access token.</p>
  7042. <pre><code class="language-python">async def on_user_registration(user: str) -&gt; None
  7043. </code></pre>
  7044. <p>Called after successfully registering a user, in case the module needs to perform extra
  7045. operations to keep track of them. (e.g. add them to a database table). The user is
  7046. represented by their Matrix user ID.</p>
  7047. <h4 id="third-party-rules-callbacks"><a class="header" href="#third-party-rules-callbacks">Third party rules callbacks</a></h4>
  7048. <p>Third party rules callbacks allow module developers to add extra checks to verify the
  7049. validity of incoming events. Third party event rules callbacks can be registered using
  7050. the module API's <code>register_third_party_rules_callbacks</code> method.</p>
  7051. <p>The available third party rules callbacks are:</p>
  7052. <pre><code class="language-python">async def check_event_allowed(
  7053. event: &quot;synapse.events.EventBase&quot;,
  7054. state_events: &quot;synapse.types.StateMap&quot;,
  7055. ) -&gt; Tuple[bool, Optional[dict]]
  7056. </code></pre>
  7057. <p><strong><span style="color:red">
  7058. This callback is very experimental and can and will break without notice. Module developers
  7059. are encouraged to implement <code>check_event_for_spam</code> from the spam checker category instead.
  7060. </span></strong></p>
  7061. <p>Called when processing any incoming event, with the event and a <code>StateMap</code>
  7062. representing the current state of the room the event is being sent into. A <code>StateMap</code> is
  7063. a dictionary that maps tuples containing an event type and a state key to the
  7064. corresponding state event. For example retrieving the room's <code>m.room.create</code> event from
  7065. the <code>state_events</code> argument would look like this: <code>state_events.get((&quot;m.room.create&quot;, &quot;&quot;))</code>.
  7066. The module must return a boolean indicating whether the event can be allowed.</p>
  7067. <p>Note that this callback function processes incoming events coming via federation
  7068. traffic (on top of client traffic). This means denying an event might cause the local
  7069. copy of the room's history to diverge from that of remote servers. This may cause
  7070. federation issues in the room. It is strongly recommended to only deny events using this
  7071. callback function if the sender is a local user, or in a private federation in which all
  7072. servers are using the same module, with the same configuration.</p>
  7073. <p>If the boolean returned by the module is <code>True</code>, it may also tell Synapse to replace the
  7074. event with new data by returning the new event's data as a dictionary. In order to do
  7075. that, it is recommended the module calls <code>event.get_dict()</code> to get the current event as a
  7076. dictionary, and modify the returned dictionary accordingly.</p>
  7077. <p>Note that replacing the event only works for events sent by local users, not for events
  7078. received over federation.</p>
  7079. <pre><code class="language-python">async def on_create_room(
  7080. requester: &quot;synapse.types.Requester&quot;,
  7081. request_content: dict,
  7082. is_requester_admin: bool,
  7083. ) -&gt; None
  7084. </code></pre>
  7085. <p>Called when processing a room creation request, with the <code>Requester</code> object for the user
  7086. performing the request, a dictionary representing the room creation request's JSON body
  7087. (see <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom">the spec</a>
  7088. for a list of possible parameters), and a boolean indicating whether the user performing
  7089. the request is a server admin.</p>
  7090. <p>Modules can modify the <code>request_content</code> (by e.g. adding events to its <code>initial_state</code>),
  7091. or deny the room's creation by raising a <code>module_api.errors.SynapseError</code>.</p>
  7092. <h3 id="porting-an-existing-module-that-uses-the-old-interface"><a class="header" href="#porting-an-existing-module-that-uses-the-old-interface">Porting an existing module that uses the old interface</a></h3>
  7093. <p>In order to port a module that uses Synapse's old module interface, its author needs to:</p>
  7094. <ul>
  7095. <li>ensure the module's callbacks are all asynchronous.</li>
  7096. <li>register their callbacks using one or more of the <code>register_[...]_callbacks</code> methods
  7097. from the <code>ModuleApi</code> class in the module's <code>__init__</code> method (see <a href="modules.html#registering-a-callback">this section</a>
  7098. for more info).</li>
  7099. </ul>
  7100. <p>Additionally, if the module is packaged with an additional web resource, the module
  7101. should register this resource in its <code>__init__</code> method using the <code>register_web_resource</code>
  7102. method from the <code>ModuleApi</code> class (see <a href="modules.html#registering-a-web-resource">this section</a> for
  7103. more info).</p>
  7104. <p>The module's author should also update any example in the module's configuration to only
  7105. use the new <code>modules</code> section in Synapse's configuration file (see <a href="modules.html#using-modules">this section</a>
  7106. for more info).</p>
  7107. <h3 id="example"><a class="header" href="#example">Example</a></h3>
  7108. <p>The example below is a module that implements the spam checker callback
  7109. <code>user_may_create_room</code> to deny room creation to user <code>@evilguy:example.com</code>, and registers
  7110. a web resource to the path <code>/_synapse/client/demo/hello</code> that returns a JSON object.</p>
  7111. <pre><code class="language-python">import json
  7112. from twisted.web.resource import Resource
  7113. from twisted.web.server import Request
  7114. from synapse.module_api import ModuleApi
  7115. class DemoResource(Resource):
  7116. def __init__(self, config):
  7117. super(DemoResource, self).__init__()
  7118. self.config = config
  7119. def render_GET(self, request: Request):
  7120. name = request.args.get(b&quot;name&quot;)[0]
  7121. request.setHeader(b&quot;Content-Type&quot;, b&quot;application/json&quot;)
  7122. return json.dumps({&quot;hello&quot;: name})
  7123. class DemoModule:
  7124. def __init__(self, config: dict, api: ModuleApi):
  7125. self.config = config
  7126. self.api = api
  7127. self.api.register_web_resource(
  7128. path=&quot;/_synapse/client/demo/hello&quot;,
  7129. resource=DemoResource(self.config),
  7130. )
  7131. self.api.register_spam_checker_callbacks(
  7132. user_may_create_room=self.user_may_create_room,
  7133. )
  7134. @staticmethod
  7135. def parse_config(config):
  7136. return config
  7137. async def user_may_create_room(self, user: str) -&gt; bool:
  7138. if user == &quot;@evilguy:example.com&quot;:
  7139. return False
  7140. return True
  7141. </code></pre>
  7142. <div style="break-before: page; page-break-before: always;"></div><h2 style="color:red">
  7143. This page of the Synapse documentation is now deprecated. For up to date
  7144. documentation on setting up or writing a spam checker module, please see
  7145. <a href="modules.html">this page</a>.
  7146. </h2>
  7147. <h1 id="handling-spam-in-synapse"><a class="header" href="#handling-spam-in-synapse">Handling spam in Synapse</a></h1>
  7148. <p>Synapse has support to customize spam checking behavior. It can plug into a
  7149. variety of events and affect how they are presented to users on your homeserver.</p>
  7150. <p>The spam checking behavior is implemented as a Python class, which must be
  7151. able to be imported by the running Synapse.</p>
  7152. <h2 id="python-spam-checker-class"><a class="header" href="#python-spam-checker-class">Python spam checker class</a></h2>
  7153. <p>The Python class is instantiated with two objects:</p>
  7154. <ul>
  7155. <li>Any configuration (see below).</li>
  7156. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7157. </ul>
  7158. <p>It then implements methods which return a boolean to alter behavior in Synapse.
  7159. All the methods must be defined.</p>
  7160. <p>There's a generic method for checking every event (<code>check_event_for_spam</code>), as
  7161. well as some specific methods:</p>
  7162. <ul>
  7163. <li><code>user_may_invite</code></li>
  7164. <li><code>user_may_create_room</code></li>
  7165. <li><code>user_may_create_room_alias</code></li>
  7166. <li><code>user_may_publish_room</code></li>
  7167. <li><code>check_username_for_spam</code></li>
  7168. <li><code>check_registration_for_spam</code></li>
  7169. <li><code>check_media_file_for_spam</code></li>
  7170. </ul>
  7171. <p>The details of each of these methods (as well as their inputs and outputs)
  7172. are documented in the <code>synapse.events.spamcheck.SpamChecker</code> class.</p>
  7173. <p>The <code>ModuleApi</code> class provides a way for the custom spam checker class to
  7174. call back into the homeserver internals.</p>
  7175. <p>Additionally, a <code>parse_config</code> method is mandatory and receives the plugin config
  7176. dictionary. After parsing, It must return an object which will be
  7177. passed to <code>__init__</code> later.</p>
  7178. <h3 id="example-1"><a class="header" href="#example-1">Example</a></h3>
  7179. <pre><code class="language-python">from synapse.spam_checker_api import RegistrationBehaviour
  7180. class ExampleSpamChecker:
  7181. def __init__(self, config, api):
  7182. self.config = config
  7183. self.api = api
  7184. @staticmethod
  7185. def parse_config(config):
  7186. return config
  7187. async def check_event_for_spam(self, foo):
  7188. return False # allow all events
  7189. async def user_may_invite(self, inviter_userid, invitee_userid, room_id):
  7190. return True # allow all invites
  7191. async def user_may_create_room(self, userid):
  7192. return True # allow all room creations
  7193. async def user_may_create_room_alias(self, userid, room_alias):
  7194. return True # allow all room aliases
  7195. async def user_may_publish_room(self, userid, room_id):
  7196. return True # allow publishing of all rooms
  7197. async def check_username_for_spam(self, user_profile):
  7198. return False # allow all usernames
  7199. async def check_registration_for_spam(
  7200. self,
  7201. email_threepid,
  7202. username,
  7203. request_info,
  7204. auth_provider_id,
  7205. ):
  7206. return RegistrationBehaviour.ALLOW # allow all registrations
  7207. async def check_media_file_for_spam(self, file_wrapper, file_info):
  7208. return False # allow all media
  7209. </code></pre>
  7210. <h2 id="configuration-2"><a class="header" href="#configuration-2">Configuration</a></h2>
  7211. <p>Modify the <code>spam_checker</code> section of your <code>homeserver.yaml</code> in the following
  7212. manner:</p>
  7213. <p>Create a list entry with the keys <code>module</code> and <code>config</code>.</p>
  7214. <ul>
  7215. <li>
  7216. <p><code>module</code> should point to the fully qualified Python class that implements your
  7217. custom logic, e.g. <code>my_module.ExampleSpamChecker</code>.</p>
  7218. </li>
  7219. <li>
  7220. <p><code>config</code> is a dictionary that gets passed to the spam checker class.</p>
  7221. </li>
  7222. </ul>
  7223. <h3 id="example-2"><a class="header" href="#example-2">Example</a></h3>
  7224. <p>This section might look like:</p>
  7225. <pre><code class="language-yaml">spam_checker:
  7226. - module: my_module.ExampleSpamChecker
  7227. config:
  7228. # Enable or disable a specific option in ExampleSpamChecker.
  7229. my_custom_option: true
  7230. </code></pre>
  7231. <p>More spam checkers can be added in tandem by appending more items to the list. An
  7232. action is blocked when at least one of the configured spam checkers flags it.</p>
  7233. <h2 id="examples"><a class="header" href="#examples">Examples</a></h2>
  7234. <p>The <a href="https://github.com/matrix-org/mjolnir">Mjolnir</a> project is a full fledged
  7235. example using the Synapse spam checking API, including a bot for dynamic
  7236. configuration.</p>
  7237. <div style="break-before: page; page-break-before: always;"></div><h1 id="presence-router-module"><a class="header" href="#presence-router-module">Presence Router Module</a></h1>
  7238. <p>Synapse supports configuring a module that can specify additional users
  7239. (local or remote) to should receive certain presence updates from local
  7240. users.</p>
  7241. <p>Note that routing presence via Application Service transactions is not
  7242. currently supported.</p>
  7243. <p>The presence routing module is implemented as a Python class, which will
  7244. be imported by the running Synapse.</p>
  7245. <h2 id="python-presence-router-class"><a class="header" href="#python-presence-router-class">Python Presence Router Class</a></h2>
  7246. <p>The Python class is instantiated with two objects:</p>
  7247. <ul>
  7248. <li>A configuration object of some type (see below).</li>
  7249. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7250. </ul>
  7251. <p>It then implements methods related to presence routing.</p>
  7252. <p>Note that one method of <code>ModuleApi</code> that may be useful is:</p>
  7253. <pre><code class="language-python">async def ModuleApi.send_local_online_presence_to(users: Iterable[str]) -&gt; None
  7254. </code></pre>
  7255. <p>which can be given a list of local or remote MXIDs to broadcast known, online user
  7256. presence to (for those users that the receiving user is considered interested in).
  7257. It does not include state for users who are currently offline, and it can only be
  7258. called on workers that support sending federation. Additionally, this method must
  7259. only be called from the process that has been configured to write to the
  7260. the <a href="workers.html#stream-writers">presence stream</a>.
  7261. By default, this is the main process, but another worker can be configured to do
  7262. so.</p>
  7263. <h3 id="module-structure"><a class="header" href="#module-structure">Module structure</a></h3>
  7264. <p>Below is a list of possible methods that can be implemented, and whether they are
  7265. required.</p>
  7266. <h4 id="parse_config"><a class="header" href="#parse_config"><code>parse_config</code></a></h4>
  7267. <pre><code class="language-python">def parse_config(config_dict: dict) -&gt; Any
  7268. </code></pre>
  7269. <p><strong>Required.</strong> A static method that is passed a dictionary of config options, and
  7270. should return a validated config object. This method is described further in
  7271. <a href="presence_router_module.html#configuration">Configuration</a>.</p>
  7272. <h4 id="get_users_for_states"><a class="header" href="#get_users_for_states"><code>get_users_for_states</code></a></h4>
  7273. <pre><code class="language-python">async def get_users_for_states(
  7274. self,
  7275. state_updates: Iterable[UserPresenceState],
  7276. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7277. </code></pre>
  7278. <p><strong>Required.</strong> An asynchronous method that is passed an iterable of user presence
  7279. state. This method can determine whether a given presence update should be sent to certain
  7280. users. It does this by returning a dictionary with keys representing local or remote
  7281. Matrix User IDs, and values being a python set
  7282. of <code>synapse.handlers.presence.UserPresenceState</code> instances.</p>
  7283. <p>Synapse will then attempt to send the specified presence updates to each user when
  7284. possible.</p>
  7285. <h4 id="get_interested_users"><a class="header" href="#get_interested_users"><code>get_interested_users</code></a></h4>
  7286. <pre><code class="language-python">async def get_interested_users(self, user_id: str) -&gt; Union[Set[str], str]
  7287. </code></pre>
  7288. <p><strong>Required.</strong> An asynchronous method that is passed a single Matrix User ID. This
  7289. method is expected to return the users that the passed in user may be interested in the
  7290. presence of. Returned users may be local or remote. The presence routed as a result of
  7291. what this method returns is sent in addition to the updates already sent between users
  7292. that share a room together. Presence updates are deduplicated.</p>
  7293. <p>This method should return a python set of Matrix User IDs, or the object
  7294. <code>synapse.events.presence_router.PresenceRouter.ALL_USERS</code> to indicate that the passed
  7295. user should receive presence information for <em>all</em> known users.</p>
  7296. <p>For clarity, if the user <code>@alice:example.org</code> is passed to this method, and the Set
  7297. <code>{&quot;@bob:example.com&quot;, &quot;@charlie:somewhere.org&quot;}</code> is returned, this signifies that Alice
  7298. should receive presence updates sent by Bob and Charlie, regardless of whether these
  7299. users share a room.</p>
  7300. <h3 id="example-3"><a class="header" href="#example-3">Example</a></h3>
  7301. <p>Below is an example implementation of a presence router class.</p>
  7302. <pre><code class="language-python">from typing import Dict, Iterable, Set, Union
  7303. from synapse.events.presence_router import PresenceRouter
  7304. from synapse.handlers.presence import UserPresenceState
  7305. from synapse.module_api import ModuleApi
  7306. class PresenceRouterConfig:
  7307. def __init__(self):
  7308. # Config options with their defaults
  7309. # A list of users to always send all user presence updates to
  7310. self.always_send_to_users = [] # type: List[str]
  7311. # A list of users to ignore presence updates for. Does not affect
  7312. # shared-room presence relationships
  7313. self.blacklisted_users = [] # type: List[str]
  7314. class ExamplePresenceRouter:
  7315. &quot;&quot;&quot;An example implementation of synapse.presence_router.PresenceRouter.
  7316. Supports routing all presence to a configured set of users, or a subset
  7317. of presence from certain users to members of certain rooms.
  7318. Args:
  7319. config: A configuration object.
  7320. module_api: An instance of Synapse's ModuleApi.
  7321. &quot;&quot;&quot;
  7322. def __init__(self, config: PresenceRouterConfig, module_api: ModuleApi):
  7323. self._config = config
  7324. self._module_api = module_api
  7325. @staticmethod
  7326. def parse_config(config_dict: dict) -&gt; PresenceRouterConfig:
  7327. &quot;&quot;&quot;Parse a configuration dictionary from the homeserver config, do
  7328. some validation and return a typed PresenceRouterConfig.
  7329. Args:
  7330. config_dict: The configuration dictionary.
  7331. Returns:
  7332. A validated config object.
  7333. &quot;&quot;&quot;
  7334. # Initialise a typed config object
  7335. config = PresenceRouterConfig()
  7336. always_send_to_users = config_dict.get(&quot;always_send_to_users&quot;)
  7337. blacklisted_users = config_dict.get(&quot;blacklisted_users&quot;)
  7338. # Do some validation of config options... otherwise raise a
  7339. # synapse.config.ConfigError.
  7340. config.always_send_to_users = always_send_to_users
  7341. config.blacklisted_users = blacklisted_users
  7342. return config
  7343. async def get_users_for_states(
  7344. self,
  7345. state_updates: Iterable[UserPresenceState],
  7346. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7347. &quot;&quot;&quot;Given an iterable of user presence updates, determine where each one
  7348. needs to go. Returned results will not affect presence updates that are
  7349. sent between users who share a room.
  7350. Args:
  7351. state_updates: An iterable of user presence state updates.
  7352. Returns:
  7353. A dictionary of user_id -&gt; set of UserPresenceState that the user should
  7354. receive.
  7355. &quot;&quot;&quot;
  7356. destination_users = {} # type: Dict[str, Set[UserPresenceState]
  7357. # Ignore any updates for blacklisted users
  7358. desired_updates = set()
  7359. for update in state_updates:
  7360. if update.state_key not in self._config.blacklisted_users:
  7361. desired_updates.add(update)
  7362. # Send all presence updates to specific users
  7363. for user_id in self._config.always_send_to_users:
  7364. destination_users[user_id] = desired_updates
  7365. return destination_users
  7366. async def get_interested_users(
  7367. self,
  7368. user_id: str,
  7369. ) -&gt; Union[Set[str], PresenceRouter.ALL_USERS]:
  7370. &quot;&quot;&quot;
  7371. Retrieve a list of users that `user_id` is interested in receiving the
  7372. presence of. This will be in addition to those they share a room with.
  7373. Optionally, the object PresenceRouter.ALL_USERS can be returned to indicate
  7374. that this user should receive all incoming local and remote presence updates.
  7375. Note that this method will only be called for local users.
  7376. Args:
  7377. user_id: A user requesting presence updates.
  7378. Returns:
  7379. A set of user IDs to return additional presence updates for, or
  7380. PresenceRouter.ALL_USERS to return presence updates for all other users.
  7381. &quot;&quot;&quot;
  7382. if user_id in self._config.always_send_to_users:
  7383. return PresenceRouter.ALL_USERS
  7384. return set()
  7385. </code></pre>
  7386. <h4 id="a-note-on-get_users_for_states-and-get_interested_users"><a class="header" href="#a-note-on-get_users_for_states-and-get_interested_users">A note on <code>get_users_for_states</code> and <code>get_interested_users</code></a></h4>
  7387. <p>Both of these methods are effectively two different sides of the same coin. The logic
  7388. regarding which users should receive updates for other users should be the same
  7389. between them.</p>
  7390. <p><code>get_users_for_states</code> is called when presence updates come in from either federation
  7391. or local users, and is used to either direct local presence to remote users, or to
  7392. wake up the sync streams of local users to collect remote presence.</p>
  7393. <p>In contrast, <code>get_interested_users</code> is used to determine the users that presence should
  7394. be fetched for when a local user is syncing. This presence is then retrieved, before
  7395. being fed through <code>get_users_for_states</code> once again, with only the syncing user's
  7396. routing information pulled from the resulting dictionary.</p>
  7397. <p>Their routing logic should thus line up, else you may run into unintended behaviour.</p>
  7398. <h2 id="configuration-3"><a class="header" href="#configuration-3">Configuration</a></h2>
  7399. <p>Once you've crafted your module and installed it into the same Python environment as
  7400. Synapse, amend your homeserver config file with the following.</p>
  7401. <pre><code class="language-yaml">presence:
  7402. enabled: true
  7403. presence_router:
  7404. module: my_module.ExamplePresenceRouter
  7405. config:
  7406. # Any configuration options for your module. The below is an example.
  7407. # of setting options for ExamplePresenceRouter.
  7408. always_send_to_users: [&quot;@presence_gobbler:example.org&quot;]
  7409. blacklisted_users:
  7410. - &quot;@alice:example.com&quot;
  7411. - &quot;@bob:example.com&quot;
  7412. ...
  7413. </code></pre>
  7414. <p>The contents of <code>config</code> will be passed as a Python dictionary to the static
  7415. <code>parse_config</code> method of your class. The object returned by this method will
  7416. then be passed to the <code>__init__</code> method of your module as <code>config</code>.</p>
  7417. <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>
  7418. <p>For small instances it recommended to run Synapse in the default monolith mode.
  7419. For larger instances where performance is a concern it can be helpful to split
  7420. out functionality into multiple separate python processes. These processes are
  7421. called 'workers', and are (eventually) intended to scale horizontally
  7422. independently.</p>
  7423. <p>Synapse's worker support is under active development and subject to change as
  7424. we attempt to rapidly scale ever larger Synapse instances. However we are
  7425. documenting it here to help admins needing a highly scalable Synapse instance
  7426. similar to the one running <code>matrix.org</code>.</p>
  7427. <p>All processes continue to share the same database instance, and as such,
  7428. workers only work with PostgreSQL-based Synapse deployments. SQLite should only
  7429. be used for demo purposes and any admin considering workers should already be
  7430. running PostgreSQL.</p>
  7431. <p>See also <a href="https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability">Matrix.org blog post</a>
  7432. for a higher level overview.</p>
  7433. <h2 id="main-processworker-communication"><a class="header" href="#main-processworker-communication">Main process/worker communication</a></h2>
  7434. <p>The processes communicate with each other via a Synapse-specific protocol called
  7435. 'replication' (analogous to MySQL- or Postgres-style database replication) which
  7436. feeds streams of newly written data between processes so they can be kept in
  7437. sync with the database state.</p>
  7438. <p>When configured to do so, Synapse uses a
  7439. <a href="https://redis.io/topics/pubsub">Redis pub/sub channel</a> to send the replication
  7440. stream between all configured Synapse processes. Additionally, processes may
  7441. make HTTP requests to each other, primarily for operations which need to wait
  7442. for a reply ─ such as sending an event.</p>
  7443. <p>Redis support was added in v1.13.0 with it becoming the recommended method in
  7444. v1.18.0. It replaced the old direct TCP connections (which is deprecated as of
  7445. v1.18.0) to the main process. With Redis, rather than all the workers connecting
  7446. to the main process, all the workers and the main process connect to Redis,
  7447. which relays replication commands between processes. This can give a significant
  7448. cpu saving on the main process and will be a prerequisite for upcoming
  7449. performance improvements.</p>
  7450. <p>If Redis support is enabled Synapse will use it as a shared cache, as well as a
  7451. pub/sub mechanism.</p>
  7452. <p>See the <a href="workers.html#architectural-diagram">Architectural diagram</a> section at the end for
  7453. a visualisation of what this looks like.</p>
  7454. <h2 id="setting-up-workers"><a class="header" href="#setting-up-workers">Setting up workers</a></h2>
  7455. <p>A Redis server is required to manage the communication between the processes.
  7456. The Redis server should be installed following the normal procedure for your
  7457. distribution (e.g. <code>apt install redis-server</code> on Debian). It is safe to use an
  7458. existing Redis deployment if you have one.</p>
  7459. <p>Once installed, check that Redis is running and accessible from the host running
  7460. Synapse, for example by executing <code>echo PING | nc -q1 localhost 6379</code> and seeing
  7461. a response of <code>+PONG</code>.</p>
  7462. <p>The appropriate dependencies must also be installed for Synapse. If using a
  7463. virtualenv, these can be installed with:</p>
  7464. <pre><code class="language-sh">pip install &quot;matrix-synapse[redis]&quot;
  7465. </code></pre>
  7466. <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
  7467. <code>matrix.org</code> and in the docker images at
  7468. https://hub.docker.com/r/matrixdotorg/synapse/.</p>
  7469. <p>To make effective use of the workers, you will need to configure an HTTP
  7470. reverse-proxy such as nginx or haproxy, which will direct incoming requests to
  7471. the correct worker, or to the main synapse instance. See
  7472. <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a reverse
  7473. proxy.</p>
  7474. <p>When using workers, each worker process has its own configuration file which
  7475. contains settings specific to that worker, such as the HTTP listener that it
  7476. provides (if any), logging configuration, etc.</p>
  7477. <p>Normally, the worker processes are configured to read from a shared
  7478. configuration file as well as the worker-specific configuration files. This
  7479. makes it easier to keep common configuration settings synchronised across all
  7480. the processes.</p>
  7481. <p>The main process is somewhat special in this respect: it does not normally
  7482. need its own configuration file and can take all of its configuration from the
  7483. shared configuration file.</p>
  7484. <h3 id="shared-configuration"><a class="header" href="#shared-configuration">Shared configuration</a></h3>
  7485. <p>Normally, only a couple of changes are needed to make an existing configuration
  7486. file suitable for use with workers. First, you need to enable an &quot;HTTP replication
  7487. listener&quot; for the main process; and secondly, you need to enable redis-based
  7488. replication. Optionally, a shared secret can be used to authenticate HTTP
  7489. traffic between workers. For example:</p>
  7490. <pre><code class="language-yaml"># extend the existing `listeners` section. This defines the ports that the
  7491. # main process will listen on.
  7492. listeners:
  7493. # The HTTP replication port
  7494. - port: 9093
  7495. bind_address: '127.0.0.1'
  7496. type: http
  7497. resources:
  7498. - names: [replication]
  7499. # Add a random shared secret to authenticate traffic.
  7500. worker_replication_secret: &quot;&quot;
  7501. redis:
  7502. enabled: true
  7503. </code></pre>
  7504. <p>See the sample config for the full documentation of each option.</p>
  7505. <p>Under <strong>no circumstances</strong> should the replication listener be exposed to the
  7506. public internet; it has no authentication and is unencrypted.</p>
  7507. <h3 id="worker-configuration"><a class="header" href="#worker-configuration">Worker configuration</a></h3>
  7508. <p>In the config file for each worker, you must specify the type of worker
  7509. application (<code>worker_app</code>), and you should specify a unique name for the worker
  7510. (<code>worker_name</code>). The currently available worker applications are listed below.
  7511. You must also specify the HTTP replication endpoint that it should talk to on
  7512. the main synapse process. <code>worker_replication_host</code> should specify the host of
  7513. the main synapse and <code>worker_replication_http_port</code> should point to the HTTP
  7514. replication port. If the worker will handle HTTP requests then the
  7515. <code>worker_listeners</code> option should be set with a <code>http</code> listener, in the same way
  7516. as the <code>listeners</code> option in the shared config.</p>
  7517. <p>For example:</p>
  7518. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  7519. worker_name: worker1
  7520. # The replication listener on the main synapse process.
  7521. worker_replication_host: 127.0.0.1
  7522. worker_replication_http_port: 9093
  7523. worker_listeners:
  7524. - type: http
  7525. port: 8083
  7526. resources:
  7527. - names:
  7528. - client
  7529. - federation
  7530. worker_log_config: /home/matrix/synapse/config/worker1_log_config.yaml
  7531. </code></pre>
  7532. <p>...is a full configuration for a generic worker instance, which will expose a
  7533. plain HTTP endpoint on port 8083 separately serving various endpoints, e.g.
  7534. <code>/sync</code>, which are listed below.</p>
  7535. <p>Obviously you should configure your reverse-proxy to route the relevant
  7536. endpoints to the worker (<code>localhost:8083</code> in the above example).</p>
  7537. <h3 id="running-synapse-with-workers"><a class="header" href="#running-synapse-with-workers">Running Synapse with workers</a></h3>
  7538. <p>Finally, you need to start your worker processes. This can be done with either
  7539. <code>synctl</code> or your distribution's preferred service manager such as <code>systemd</code>. We
  7540. recommend the use of <code>systemd</code> where available: for information on setting up
  7541. <code>systemd</code> to start synapse workers, see
  7542. <a href="systemd-with-workers">Systemd with Workers</a>. To use <code>synctl</code>, see
  7543. <a href="synctl_workers.html">Using synctl with Workers</a>.</p>
  7544. <h2 id="available-worker-applications"><a class="header" href="#available-worker-applications">Available worker applications</a></h2>
  7545. <h3 id="synapseappgeneric_worker"><a class="header" href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a></h3>
  7546. <p>This worker can handle API requests matching the following regular
  7547. expressions:</p>
  7548. <pre><code># Sync requests
  7549. ^/_matrix/client/(v2_alpha|r0)/sync$
  7550. ^/_matrix/client/(api/v1|v2_alpha|r0)/events$
  7551. ^/_matrix/client/(api/v1|r0)/initialSync$
  7552. ^/_matrix/client/(api/v1|r0)/rooms/[^/]+/initialSync$
  7553. # Federation requests
  7554. ^/_matrix/federation/v1/event/
  7555. ^/_matrix/federation/v1/state/
  7556. ^/_matrix/federation/v1/state_ids/
  7557. ^/_matrix/federation/v1/backfill/
  7558. ^/_matrix/federation/v1/get_missing_events/
  7559. ^/_matrix/federation/v1/publicRooms
  7560. ^/_matrix/federation/v1/query/
  7561. ^/_matrix/federation/v1/make_join/
  7562. ^/_matrix/federation/v1/make_leave/
  7563. ^/_matrix/federation/v1/send_join/
  7564. ^/_matrix/federation/v2/send_join/
  7565. ^/_matrix/federation/v1/send_leave/
  7566. ^/_matrix/federation/v2/send_leave/
  7567. ^/_matrix/federation/v1/invite/
  7568. ^/_matrix/federation/v2/invite/
  7569. ^/_matrix/federation/v1/query_auth/
  7570. ^/_matrix/federation/v1/event_auth/
  7571. ^/_matrix/federation/v1/exchange_third_party_invite/
  7572. ^/_matrix/federation/v1/user/devices/
  7573. ^/_matrix/federation/v1/get_groups_publicised$
  7574. ^/_matrix/key/v2/query
  7575. # Inbound federation transaction request
  7576. ^/_matrix/federation/v1/send/
  7577. # Client API requests
  7578. ^/_matrix/client/(api/v1|r0|unstable)/publicRooms$
  7579. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/joined_members$
  7580. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/context/.*$
  7581. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/members$
  7582. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state$
  7583. ^/_matrix/client/(api/v1|r0|unstable)/account/3pid$
  7584. ^/_matrix/client/(api/v1|r0|unstable)/devices$
  7585. ^/_matrix/client/(api/v1|r0|unstable)/keys/query$
  7586. ^/_matrix/client/(api/v1|r0|unstable)/keys/changes$
  7587. ^/_matrix/client/versions$
  7588. ^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$
  7589. ^/_matrix/client/(api/v1|r0|unstable)/joined_groups$
  7590. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups$
  7591. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups/
  7592. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/event/
  7593. ^/_matrix/client/(api/v1|r0|unstable)/joined_rooms$
  7594. ^/_matrix/client/(api/v1|r0|unstable)/search$
  7595. # Registration/login requests
  7596. ^/_matrix/client/(api/v1|r0|unstable)/login$
  7597. ^/_matrix/client/(r0|unstable)/register$
  7598. # Event sending requests
  7599. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/redact
  7600. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/send
  7601. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state/
  7602. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
  7603. ^/_matrix/client/(api/v1|r0|unstable)/join/
  7604. ^/_matrix/client/(api/v1|r0|unstable)/profile/
  7605. </code></pre>
  7606. <p>Additionally, the following REST endpoints can be handled for GET requests:</p>
  7607. <pre><code>^/_matrix/federation/v1/groups/
  7608. </code></pre>
  7609. <p>Pagination requests can also be handled, but all requests for a given
  7610. room must be routed to the same instance. Additionally, care must be taken to
  7611. ensure that the purge history admin API is not used while pagination requests
  7612. for the room are in flight:</p>
  7613. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/messages$
  7614. </code></pre>
  7615. <p>Additionally, the following endpoints should be included if Synapse is configured
  7616. to use SSO (you only need to include the ones for whichever SSO provider you're
  7617. using):</p>
  7618. <pre><code># for all SSO providers
  7619. ^/_matrix/client/(api/v1|r0|unstable)/login/sso/redirect
  7620. ^/_synapse/client/pick_idp$
  7621. ^/_synapse/client/pick_username
  7622. ^/_synapse/client/new_user_consent$
  7623. ^/_synapse/client/sso_register$
  7624. # OpenID Connect requests.
  7625. ^/_synapse/client/oidc/callback$
  7626. # SAML requests.
  7627. ^/_synapse/client/saml2/authn_response$
  7628. # CAS requests.
  7629. ^/_matrix/client/(api/v1|r0|unstable)/login/cas/ticket$
  7630. </code></pre>
  7631. <p>Ensure that all SSO logins go to a single process.
  7632. For multiple workers not handling the SSO endpoints properly, see
  7633. <a href="https://github.com/matrix-org/synapse/issues/7530">#7530</a> and
  7634. <a href="https://github.com/matrix-org/synapse/issues/9427">#9427</a>.</p>
  7635. <p>Note that a HTTP listener with <code>client</code> and <code>federation</code> resources must be
  7636. configured in the <code>worker_listeners</code> option in the worker config.</p>
  7637. <h4 id="load-balancing"><a class="header" href="#load-balancing">Load balancing</a></h4>
  7638. <p>It is possible to run multiple instances of this worker app, with incoming requests
  7639. being load-balanced between them by the reverse-proxy. However, different endpoints
  7640. have different characteristics and so admins
  7641. may wish to run multiple groups of workers handling different endpoints so that
  7642. load balancing can be done in different ways.</p>
  7643. <p>For <code>/sync</code> and <code>/initialSync</code> requests it will be more efficient if all
  7644. requests from a particular user are routed to a single instance. Extracting a
  7645. user ID from the access token or <code>Authorization</code> header is currently left as an
  7646. exercise for the reader. Admins may additionally wish to separate out <code>/sync</code>
  7647. requests that have a <code>since</code> query parameter from those that don't (and
  7648. <code>/initialSync</code>), as requests that don't are known as &quot;initial sync&quot; that happens
  7649. when a user logs in on a new device and can be <em>very</em> resource intensive, so
  7650. isolating these requests will stop them from interfering with other users ongoing
  7651. syncs.</p>
  7652. <p>Federation and client requests can be balanced via simple round robin.</p>
  7653. <p>The inbound federation transaction request <code>^/_matrix/federation/v1/send/</code>
  7654. should be balanced by source IP so that transactions from the same remote server
  7655. go to the same process.</p>
  7656. <p>Registration/login requests can be handled separately purely to help ensure that
  7657. unexpected load doesn't affect new logins and sign ups.</p>
  7658. <p>Finally, event sending requests can be balanced by the room ID in the URI (or
  7659. the full URI, or even just round robin), the room ID is the path component after
  7660. <code>/rooms/</code>. If there is a large bridge connected that is sending or may send lots
  7661. of events, then a dedicated set of workers can be provisioned to limit the
  7662. effects of bursts of events from that bridge on events sent by normal users.</p>
  7663. <h4 id="stream-writers"><a class="header" href="#stream-writers">Stream writers</a></h4>
  7664. <p>Additionally, there is <em>experimental</em> support for moving writing of specific
  7665. streams (such as events) off of the main process to a particular worker. (This
  7666. is only supported with Redis-based replication.)</p>
  7667. <p>Currently supported streams are <code>events</code> and <code>typing</code>.</p>
  7668. <p>To enable this, the worker must have a HTTP replication listener configured,
  7669. have a <code>worker_name</code> and be listed in the <code>instance_map</code> config. For example to
  7670. move event persistence off to a dedicated worker, the shared configuration would
  7671. include:</p>
  7672. <pre><code class="language-yaml">instance_map:
  7673. event_persister1:
  7674. host: localhost
  7675. port: 8034
  7676. stream_writers:
  7677. events: event_persister1
  7678. </code></pre>
  7679. <p>The <code>events</code> stream also experimentally supports having multiple writers, where
  7680. work is sharded between them by room ID. Note that you <em>must</em> restart all worker
  7681. instances when adding or removing event persisters. An example <code>stream_writers</code>
  7682. configuration with multiple writers:</p>
  7683. <pre><code class="language-yaml">stream_writers:
  7684. events:
  7685. - event_persister1
  7686. - event_persister2
  7687. </code></pre>
  7688. <h4 id="background-tasks"><a class="header" href="#background-tasks">Background tasks</a></h4>
  7689. <p>There is also <em>experimental</em> support for moving background tasks to a separate
  7690. worker. Background tasks are run periodically or started via replication. Exactly
  7691. which tasks are configured to run depends on your Synapse configuration (e.g. if
  7692. stats is enabled).</p>
  7693. <p>To enable this, the worker must have a <code>worker_name</code> and can be configured to run
  7694. background tasks. For example, to move background tasks to a dedicated worker,
  7695. the shared configuration would include:</p>
  7696. <pre><code class="language-yaml">run_background_tasks_on: background_worker
  7697. </code></pre>
  7698. <p>You might also wish to investigate the <code>update_user_directory</code> and
  7699. <code>media_instance_running_background_jobs</code> settings.</p>
  7700. <h3 id="synapseapppusher"><a class="header" href="#synapseapppusher"><code>synapse.app.pusher</code></a></h3>
  7701. <p>Handles sending push notifications to sygnal and email. Doesn't handle any
  7702. REST endpoints itself, but you should set <code>start_pushers: False</code> in the
  7703. shared configuration file to stop the main synapse sending push notifications.</p>
  7704. <p>To run multiple instances at once the <code>pusher_instances</code> option should list all
  7705. pusher instances by their worker name, e.g.:</p>
  7706. <pre><code class="language-yaml">pusher_instances:
  7707. - pusher_worker1
  7708. - pusher_worker2
  7709. </code></pre>
  7710. <h3 id="synapseappappservice"><a class="header" href="#synapseappappservice"><code>synapse.app.appservice</code></a></h3>
  7711. <p>Handles sending output traffic to Application Services. Doesn't handle any
  7712. REST endpoints itself, but you should set <code>notify_appservices: False</code> in the
  7713. shared configuration file to stop the main synapse sending appservice notifications.</p>
  7714. <p>Note this worker cannot be load-balanced: only one instance should be active.</p>
  7715. <h3 id="synapseappfederation_sender"><a class="header" href="#synapseappfederation_sender"><code>synapse.app.federation_sender</code></a></h3>
  7716. <p>Handles sending federation traffic to other servers. Doesn't handle any
  7717. REST endpoints itself, but you should set <code>send_federation: False</code> in the
  7718. shared configuration file to stop the main synapse sending this traffic.</p>
  7719. <p>If running multiple federation senders then you must list each
  7720. instance in the <code>federation_sender_instances</code> option by their <code>worker_name</code>.
  7721. All instances must be stopped and started when adding or removing instances.
  7722. For example:</p>
  7723. <pre><code class="language-yaml">federation_sender_instances:
  7724. - federation_sender1
  7725. - federation_sender2
  7726. </code></pre>
  7727. <h3 id="synapseappmedia_repository"><a class="header" href="#synapseappmedia_repository"><code>synapse.app.media_repository</code></a></h3>
  7728. <p>Handles the media repository. It can handle all endpoints starting with:</p>
  7729. <pre><code>/_matrix/media/
  7730. </code></pre>
  7731. <p>... and the following regular expressions matching media-specific administration APIs:</p>
  7732. <pre><code>^/_synapse/admin/v1/purge_media_cache$
  7733. ^/_synapse/admin/v1/room/.*/media.*$
  7734. ^/_synapse/admin/v1/user/.*/media.*$
  7735. ^/_synapse/admin/v1/media/.*$
  7736. ^/_synapse/admin/v1/quarantine_media/.*$
  7737. </code></pre>
  7738. <p>You should also set <code>enable_media_repo: False</code> in the shared configuration
  7739. file to stop the main synapse running background jobs related to managing the
  7740. media repository.</p>
  7741. <p>In the <code>media_repository</code> worker configuration file, configure the http listener to
  7742. expose the <code>media</code> resource. For example:</p>
  7743. <pre><code class="language-yaml"> worker_listeners:
  7744. - type: http
  7745. port: 8085
  7746. resources:
  7747. - names:
  7748. - media
  7749. </code></pre>
  7750. <p>Note that if running multiple media repositories they must be on the same server
  7751. and you must configure a single instance to run the background tasks, e.g.:</p>
  7752. <pre><code class="language-yaml"> media_instance_running_background_jobs: &quot;media-repository-1&quot;
  7753. </code></pre>
  7754. <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>
  7755. <h3 id="synapseappuser_dir"><a class="header" href="#synapseappuser_dir"><code>synapse.app.user_dir</code></a></h3>
  7756. <p>Handles searches in the user directory. It can handle REST endpoints matching
  7757. the following regular expressions:</p>
  7758. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$
  7759. </code></pre>
  7760. <p>When using this worker you must also set <code>update_user_directory: False</code> in the
  7761. shared configuration file to stop the main synapse running background
  7762. jobs related to updating the user directory.</p>
  7763. <h3 id="synapseappfrontend_proxy"><a class="header" href="#synapseappfrontend_proxy"><code>synapse.app.frontend_proxy</code></a></h3>
  7764. <p>Proxies some frequently-requested client endpoints to add caching and remove
  7765. load from the main synapse. It can handle REST endpoints matching the following
  7766. regular expressions:</p>
  7767. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/keys/upload
  7768. </code></pre>
  7769. <p>If <code>use_presence</code> is False in the homeserver config, it can also handle REST
  7770. endpoints matching the following regular expressions:</p>
  7771. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/presence/[^/]+/status
  7772. </code></pre>
  7773. <p>This &quot;stub&quot; presence handler will pass through <code>GET</code> request but make the
  7774. <code>PUT</code> effectively a no-op.</p>
  7775. <p>It will proxy any requests it cannot handle to the main synapse instance. It
  7776. must therefore be configured with the location of the main instance, via
  7777. the <code>worker_main_http_uri</code> setting in the <code>frontend_proxy</code> worker configuration
  7778. file. For example:</p>
  7779. <pre><code>worker_main_http_uri: http://127.0.0.1:8008
  7780. </code></pre>
  7781. <h3 id="historical-apps"><a class="header" href="#historical-apps">Historical apps</a></h3>
  7782. <p><em>Note:</em> Historically there used to be more apps, however they have been
  7783. amalgamated into a single <code>synapse.app.generic_worker</code> app. The remaining apps
  7784. are ones that do specific processing unrelated to requests, e.g. the <code>pusher</code>
  7785. that handles sending out push notifications for new events. The intention is for
  7786. all these to be folded into the <code>generic_worker</code> app and to use config to define
  7787. which processes handle the various proccessing such as push notifications.</p>
  7788. <h2 id="migration-from-old-config"><a class="header" href="#migration-from-old-config">Migration from old config</a></h2>
  7789. <p>There are two main independent changes that have been made: introducing Redis
  7790. support and merging apps into <code>synapse.app.generic_worker</code>. Both these changes
  7791. are backwards compatible and so no changes to the config are required, however
  7792. server admins are encouraged to plan to migrate to Redis as the old style direct
  7793. TCP replication config is deprecated.</p>
  7794. <p>To migrate to Redis add the <code>redis</code> config as above, and optionally remove the
  7795. TCP <code>replication</code> listener from master and <code>worker_replication_port</code> from worker
  7796. config.</p>
  7797. <p>To migrate apps to use <code>synapse.app.generic_worker</code> simply update the
  7798. <code>worker_app</code> option in the worker configs, and where worker are started (e.g.
  7799. in systemd service files, but not required for synctl).</p>
  7800. <h2 id="architectural-diagram"><a class="header" href="#architectural-diagram">Architectural diagram</a></h2>
  7801. <p>The following shows an example setup using Redis and a reverse proxy:</p>
  7802. <pre><code> Clients &amp; Federation
  7803. |
  7804. v
  7805. +-----------+
  7806. | |
  7807. | Reverse |
  7808. | Proxy |
  7809. | |
  7810. +-----------+
  7811. | | |
  7812. | | | HTTP requests
  7813. +-------------------+ | +-----------+
  7814. | +---+ |
  7815. | | |
  7816. v v v
  7817. +--------------+ +--------------+ +--------------+ +--------------+
  7818. | Main | | Generic | | Generic | | Event |
  7819. | Process | | Worker 1 | | Worker 2 | | Persister |
  7820. +--------------+ +--------------+ +--------------+ +--------------+
  7821. ^ ^ | ^ | | ^ | ^ ^
  7822. | | | | | | | | | |
  7823. | | | | | HTTP | | | | |
  7824. | +----------+&lt;--|---|---------+ | | | |
  7825. | | +-------------|--&gt;+----------+ |
  7826. | | | |
  7827. | | | |
  7828. v v v v
  7829. ====================================================================
  7830. Redis pub/sub channel
  7831. </code></pre>
  7832. <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>
  7833. <p>If you want to use <code>synctl</code> to manage your synapse processes, you will need to
  7834. create an an additional configuration file for the main synapse process. That
  7835. configuration should look like this:</p>
  7836. <pre><code class="language-yaml">worker_app: synapse.app.homeserver
  7837. </code></pre>
  7838. <p>Additionally, each worker app must be configured with the name of a &quot;pid file&quot;,
  7839. to which it will write its process ID when it starts. For example, for a
  7840. synchrotron, you might write:</p>
  7841. <pre><code class="language-yaml">worker_pid_file: /home/matrix/synapse/worker1.pid
  7842. </code></pre>
  7843. <p>Finally, to actually run your worker-based synapse, you must pass synctl the <code>-a</code>
  7844. commandline option to tell it to operate on all the worker configurations found
  7845. in the given directory, e.g.:</p>
  7846. <pre><code>synctl -a $CONFIG/workers start
  7847. </code></pre>
  7848. <p>Currently one should always restart all workers when restarting or upgrading
  7849. synapse, unless you explicitly know it's safe not to. For instance, restarting
  7850. synapse without restarting all the synchrotrons may result in broken typing
  7851. notifications.</p>
  7852. <p>To manipulate a specific worker, you pass the -w option to synctl:</p>
  7853. <pre><code>synctl -w $CONFIG/workers/worker1.yaml restart
  7854. </code></pre>
  7855. <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>
  7856. <p>This is a setup for managing synapse with systemd, including support for
  7857. managing workers. It provides a <code>matrix-synapse</code> service for the master, as
  7858. well as a <code>matrix-synapse-worker@</code> service template for any workers you
  7859. require. Additionally, to group the required services, it sets up a
  7860. <code>matrix-synapse.target</code>.</p>
  7861. <p>See the folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/system/">system</a>
  7862. for the systemd unit files.</p>
  7863. <p>The folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/workers/">workers</a>
  7864. contains an example configuration for the <code>federation_reader</code> worker.</p>
  7865. <h2 id="synapse-configuration-files"><a class="header" href="#synapse-configuration-files">Synapse configuration files</a></h2>
  7866. <p>See <a href="systemd-with-workers/../workers.html">the worker documentation</a> for information on how to set up the
  7867. configuration files and reverse-proxy correctly.
  7868. Below is a sample <code>federation_reader</code> worker configuration file.</p>
  7869. <pre><code class="language-yaml">worker_app: synapse.app.federation_reader
  7870. worker_name: federation_reader1
  7871. worker_replication_host: 127.0.0.1
  7872. worker_replication_http_port: 9093
  7873. worker_listeners:
  7874. - type: http
  7875. port: 8011
  7876. resources:
  7877. - names: [federation]
  7878. worker_log_config: /etc/matrix-synapse/federation-reader-log.yaml
  7879. </code></pre>
  7880. <p>Systemd manages daemonization itself, so ensure that none of the configuration
  7881. files set either <code>daemonize</code> or <code>worker_daemonize</code>.</p>
  7882. <p>The config files of all workers are expected to be located in
  7883. <code>/etc/matrix-synapse/workers</code>. If you want to use a different location, edit
  7884. the provided <code>*.service</code> files accordingly.</p>
  7885. <p>There is no need for a separate configuration file for the master process.</p>
  7886. <h2 id="set-up"><a class="header" href="#set-up">Set up</a></h2>
  7887. <ol>
  7888. <li>Adjust synapse configuration files as above.</li>
  7889. <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>
  7890. to <code>/etc/systemd/system</code>.</li>
  7891. <li>Run <code>systemctl daemon-reload</code> to tell systemd to load the new unit files.</li>
  7892. <li>Run <code>systemctl enable matrix-synapse.service</code>. This will configure the
  7893. synapse master process to be started as part of the <code>matrix-synapse.target</code>
  7894. target.</li>
  7895. <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
  7896. should be a corresponding configuration file.
  7897. <code>/etc/matrix-synapse/workers/&lt;worker_name&gt;.yaml</code>.</li>
  7898. <li>Start all the synapse processes with <code>systemctl start matrix-synapse.target</code>.</li>
  7899. <li>Tell systemd to start synapse on boot with <code>systemctl enable matrix-synapse.target</code>.</li>
  7900. </ol>
  7901. <h2 id="usage"><a class="header" href="#usage">Usage</a></h2>
  7902. <p>Once the services are correctly set up, you can use the following commands
  7903. to manage your synapse installation:</p>
  7904. <pre><code class="language-sh"># Restart Synapse master and all workers
  7905. systemctl restart matrix-synapse.target
  7906. # Stop Synapse and all workers
  7907. systemctl stop matrix-synapse.target
  7908. # Restart the master alone
  7909. systemctl start matrix-synapse.service
  7910. # Restart a specific worker (eg. federation_reader); the master is
  7911. # unaffected by this.
  7912. systemctl restart matrix-synapse-worker@federation_reader.service
  7913. # Add a new worker (assuming all configs are set up already)
  7914. systemctl enable matrix-synapse-worker@federation_writer.service
  7915. systemctl restart matrix-synapse.target
  7916. </code></pre>
  7917. <h2 id="hardening"><a class="header" href="#hardening">Hardening</a></h2>
  7918. <p><strong>Optional:</strong> If further hardening is desired, the file
  7919. <code>override-hardened.conf</code> may be copied from
  7920. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/systemd/">contrib/systemd/override-hardened.conf</a>
  7921. in this repository to the location
  7922. <code>/etc/systemd/system/matrix-synapse.service.d/override-hardened.conf</code> (the
  7923. directory may have to be created). It enables certain sandboxing features in
  7924. systemd to further secure the synapse service. You may read the comments to
  7925. understand what the override file is doing. The same file will need to be copied to
  7926. <code>/etc/systemd/system/matrix-synapse-worker@.service.d/override-hardened-worker.conf</code>
  7927. (this directory may also have to be created) in order to apply the same
  7928. hardening options to any worker processes.</p>
  7929. <p>Once these files have been copied to their appropriate locations, simply reload
  7930. systemd's manager config files and restart all Synapse services to apply the hardening options. They will automatically
  7931. be applied at every restart as long as the override files are present at the
  7932. specified locations.</p>
  7933. <pre><code class="language-sh">systemctl daemon-reload
  7934. # Restart services
  7935. systemctl restart matrix-synapse.target
  7936. </code></pre>
  7937. <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
  7938. the changes being applied at a glance.</p>
  7939. <div style="break-before: page; page-break-before: always;"></div><h1 id="administration"><a class="header" href="#administration">Administration</a></h1>
  7940. <p>This section contains information on managing your Synapse homeserver. This includes:</p>
  7941. <ul>
  7942. <li>Managing users, rooms and media via the Admin API.</li>
  7943. <li>Setting up metrics and monitoring to give you insight into your homeserver's health.</li>
  7944. <li>Configuring structured logging.</li>
  7945. </ul>
  7946. <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>
  7947. <h2 id="authenticate-as-a-server-admin"><a class="header" href="#authenticate-as-a-server-admin">Authenticate as a server admin</a></h2>
  7948. <p>Many of the API calls in the admin api will require an <code>access_token</code> for a
  7949. server admin. (Note that a server admin is distinct from a room admin.)</p>
  7950. <p>A user can be marked as a server admin by updating the database directly, e.g.:</p>
  7951. <pre><code class="language-sql">UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
  7952. </code></pre>
  7953. <p>A new server admin user can also be created using the <code>register_new_matrix_user</code>
  7954. command. This is a script that is located in the <code>scripts/</code> directory, or possibly
  7955. already on your <code>$PATH</code> depending on how Synapse was installed.</p>
  7956. <p>Finding your user's <code>access_token</code> is client-dependent, but will usually be shown in the client's settings.</p>
  7957. <h2 id="making-an-admin-api-request"><a class="header" href="#making-an-admin-api-request">Making an Admin API request</a></h2>
  7958. <p>Once you have your <code>access_token</code>, you will need to authenticate each request to an Admin API endpoint by
  7959. providing the token as either a query parameter or a request header. To add it as a request header in cURL:</p>
  7960. <pre><code class="language-sh">curl --header &quot;Authorization: Bearer &lt;access_token&gt;&quot; &lt;the_rest_of_your_API_request&gt;
  7961. </code></pre>
  7962. <p>For more details on access tokens in Matrix, please refer to the complete
  7963. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#using-access-tokens">matrix spec documentation</a>.</p>
  7964. <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>
  7965. <p>This API allows a server administrator to manage the validity of an account. To
  7966. use it, you must enable the account validity feature (under
  7967. <code>account_validity</code>) in Synapse's configuration.</p>
  7968. <h2 id="renew-account"><a class="header" href="#renew-account">Renew account</a></h2>
  7969. <p>This API extends the validity of an account by as much time as configured in the
  7970. <code>period</code> parameter from the <code>account_validity</code> configuration.</p>
  7971. <p>The API is:</p>
  7972. <pre><code>POST /_synapse/admin/v1/account_validity/validity
  7973. </code></pre>
  7974. <p>with the following body:</p>
  7975. <pre><code class="language-json">{
  7976. &quot;user_id&quot;: &quot;&lt;user ID for the account to renew&gt;&quot;,
  7977. &quot;expiration_ts&quot;: 0,
  7978. &quot;enable_renewal_emails&quot;: true
  7979. }
  7980. </code></pre>
  7981. <p><code>expiration_ts</code> is an optional parameter and overrides the expiration date,
  7982. which otherwise defaults to now + validity period.</p>
  7983. <p><code>enable_renewal_emails</code> is also an optional parameter and enables/disables
  7984. sending renewal emails to the user. Defaults to true.</p>
  7985. <p>The API returns with the new expiration date for this account, as a timestamp in
  7986. milliseconds since epoch:</p>
  7987. <pre><code class="language-json">{
  7988. &quot;expiration_ts&quot;: 0
  7989. }
  7990. </code></pre>
  7991. <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>
  7992. <p>This API lets a server admin delete a local group. Doing so will kick all
  7993. users out of the group so that their clients will correctly handle the group
  7994. being deleted.</p>
  7995. <p>The API is:</p>
  7996. <pre><code>POST /_synapse/admin/v1/delete_group/&lt;group_id&gt;
  7997. </code></pre>
  7998. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  7999. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8000. <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>
  8001. <p>This API returns information about reported events.</p>
  8002. <p>The api is:</p>
  8003. <pre><code>GET /_synapse/admin/v1/event_reports?from=0&amp;limit=10
  8004. </code></pre>
  8005. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8006. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8007. <p>It returns a JSON body like the following:</p>
  8008. <pre><code class="language-json">{
  8009. &quot;event_reports&quot;: [
  8010. {
  8011. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8012. &quot;id&quot;: 2,
  8013. &quot;reason&quot;: &quot;foo&quot;,
  8014. &quot;score&quot;: -100,
  8015. &quot;received_ts&quot;: 1570897107409,
  8016. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8017. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8018. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8019. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8020. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8021. },
  8022. {
  8023. &quot;event_id&quot;: &quot;$3IcdZsDaN_En-S1DF4EMCy3v4gNRKeOJs8W5qTOKj4I&quot;,
  8024. &quot;id&quot;: 3,
  8025. &quot;reason&quot;: &quot;bar&quot;,
  8026. &quot;score&quot;: -100,
  8027. &quot;received_ts&quot;: 1598889612059,
  8028. &quot;canonical_alias&quot;: &quot;#alias2:matrix.org&quot;,
  8029. &quot;room_id&quot;: &quot;!eGvUQuTCkHGVwNMOjv:matrix.org&quot;,
  8030. &quot;name&quot;: &quot;Your room name here&quot;,
  8031. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8032. &quot;user_id&quot;: &quot;@bar:matrix.org&quot;
  8033. }
  8034. ],
  8035. &quot;next_token&quot;: 2,
  8036. &quot;total&quot;: 4
  8037. }
  8038. </code></pre>
  8039. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again with <code>from</code>
  8040. set to the value of <code>next_token</code>. This will return a new page.</p>
  8041. <p>If the endpoint does not return a <code>next_token</code> then there are no more reports to
  8042. paginate through.</p>
  8043. <p><strong>URL parameters:</strong></p>
  8044. <ul>
  8045. <li><code>limit</code>: integer - Is optional but is used for pagination, denoting the maximum number
  8046. of items to return in this call. Defaults to <code>100</code>.</li>
  8047. <li><code>from</code>: integer - Is optional but used for pagination, denoting the offset in the
  8048. returned results. This should be treated as an opaque value and not explicitly set to
  8049. anything other than the return value of <code>next_token</code> from a previous call. Defaults to <code>0</code>.</li>
  8050. <li><code>dir</code>: string - Direction of event report order. Whether to fetch the most recent
  8051. first (<code>b</code>) or the oldest first (<code>f</code>). Defaults to <code>b</code>.</li>
  8052. <li><code>user_id</code>: string - Is optional and filters to only return users with user IDs that
  8053. contain this value. This is the user who reported the event and wrote the reason.</li>
  8054. <li><code>room_id</code>: string - Is optional and filters to only return rooms with room IDs that
  8055. contain this value.</li>
  8056. </ul>
  8057. <p><strong>Response</strong></p>
  8058. <p>The following fields are returned in the JSON response body:</p>
  8059. <ul>
  8060. <li><code>id</code>: integer - ID of event report.</li>
  8061. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8062. report was sent.</li>
  8063. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8064. <li><code>name</code>: string - The name of the room.</li>
  8065. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8066. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8067. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank or <code>null</code>.</li>
  8068. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8069. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;. May be <code>null</code>.</li>
  8070. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8071. was reported.</li>
  8072. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8073. have a canonical alias set.</li>
  8074. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  8075. <li><code>total</code>: integer - Total number of event reports related to the query
  8076. (<code>user_id</code> and <code>room_id</code>).</li>
  8077. </ul>
  8078. <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>
  8079. <p>This API returns information about a specific event report.</p>
  8080. <p>The api is:</p>
  8081. <pre><code>GET /_synapse/admin/v1/event_reports/&lt;report_id&gt;
  8082. </code></pre>
  8083. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8084. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8085. <p>It returns a JSON body like the following:</p>
  8086. <pre><code class="language-jsonc">{
  8087. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8088. &quot;event_json&quot;: {
  8089. &quot;auth_events&quot;: [
  8090. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;,
  8091. &quot;$oggsNXxzPFRE3y53SUNd7nsj69-QzKv03a1RucHu-ws&quot;
  8092. ],
  8093. &quot;content&quot;: {
  8094. &quot;body&quot;: &quot;matrix.org: This Week in Matrix&quot;,
  8095. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  8096. &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;,
  8097. &quot;msgtype&quot;: &quot;m.notice&quot;
  8098. },
  8099. &quot;depth&quot;: 546,
  8100. &quot;hashes&quot;: {
  8101. &quot;sha256&quot;: &quot;xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw&quot;
  8102. },
  8103. &quot;origin&quot;: &quot;matrix.org&quot;,
  8104. &quot;origin_server_ts&quot;: 1592291711430,
  8105. &quot;prev_events&quot;: [
  8106. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;
  8107. ],
  8108. &quot;prev_state&quot;: [],
  8109. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8110. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8111. &quot;signatures&quot;: {
  8112. &quot;matrix.org&quot;: {
  8113. &quot;ed25519:a_JaEG&quot;: &quot;cs+OUKW/iHx5pEidbWxh0UiNNHwe46Ai9LwNz+Ah16aWDNszVIe2gaAcVZfvNsBhakQTew51tlKmL2kspXk/Dg&quot;
  8114. }
  8115. },
  8116. &quot;type&quot;: &quot;m.room.message&quot;,
  8117. &quot;unsigned&quot;: {
  8118. &quot;age_ts&quot;: 1592291711430,
  8119. }
  8120. },
  8121. &quot;id&quot;: &lt;report_id&gt;,
  8122. &quot;reason&quot;: &quot;foo&quot;,
  8123. &quot;score&quot;: -100,
  8124. &quot;received_ts&quot;: 1570897107409,
  8125. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8126. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8127. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8128. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8129. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8130. }
  8131. </code></pre>
  8132. <p><strong>URL parameters:</strong></p>
  8133. <ul>
  8134. <li><code>report_id</code>: string - The ID of the event report.</li>
  8135. </ul>
  8136. <p><strong>Response</strong></p>
  8137. <p>The following fields are returned in the JSON response body:</p>
  8138. <ul>
  8139. <li><code>id</code>: integer - ID of event report.</li>
  8140. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8141. report was sent.</li>
  8142. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8143. <li><code>name</code>: string - The name of the room.</li>
  8144. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8145. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8146. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank.</li>
  8147. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8148. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;.</li>
  8149. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8150. was reported.</li>
  8151. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8152. have a canonical alias set.</li>
  8153. <li><code>event_json</code>: object - Details of the original event that was reported.</li>
  8154. </ul>
  8155. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-1"><a class="header" href="#contents-1">Contents</a></h1>
  8156. <ul>
  8157. <li><a href="admin_api/media_admin_api.html#querying-media">Querying media</a>
  8158. <ul>
  8159. <li><a href="admin_api/media_admin_api.html#list-all-media-in-a-room">List all media in a room</a></li>
  8160. <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>
  8161. </ul>
  8162. </li>
  8163. <li><a href="admin_api/media_admin_api.html#quarantine-media">Quarantine media</a>
  8164. <ul>
  8165. <li><a href="admin_api/media_admin_api.html#quarantining-media-by-id">Quarantining media by ID</a></li>
  8166. <li><a href="admin_api/media_admin_api.html#remove-media-from-quarantine-by-id">Remove media from quarantine by ID</a></li>
  8167. <li><a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">Quarantining media in a room</a></li>
  8168. <li><a href="admin_api/media_admin_api.html#quarantining-all-media-of-a-user">Quarantining all media of a user</a></li>
  8169. <li><a href="admin_api/media_admin_api.html#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></li>
  8170. <li><a href="admin_api/media_admin_api.html#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></li>
  8171. </ul>
  8172. </li>
  8173. <li><a href="admin_api/media_admin_api.html#delete-local-media">Delete local media</a>
  8174. <ul>
  8175. <li><a href="admin_api/media_admin_api.html#delete-a-specific-local-media">Delete a specific local media</a></li>
  8176. <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>
  8177. </ul>
  8178. </li>
  8179. <li><a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a></li>
  8180. </ul>
  8181. <h1 id="querying-media"><a class="header" href="#querying-media">Querying media</a></h1>
  8182. <p>These APIs allow extracting media information from the homeserver.</p>
  8183. <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>
  8184. <p>This API gets a list of known media in a room.
  8185. However, it only shows media from unencrypted events or rooms.</p>
  8186. <p>The API is:</p>
  8187. <pre><code>GET /_synapse/admin/v1/room/&lt;room_id&gt;/media
  8188. </code></pre>
  8189. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8190. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8191. <p>The API returns a JSON body like the following:</p>
  8192. <pre><code class="language-json">{
  8193. &quot;local&quot;: [
  8194. &quot;mxc://localhost/xwvutsrqponmlkjihgfedcba&quot;,
  8195. &quot;mxc://localhost/abcdefghijklmnopqrstuvwx&quot;
  8196. ],
  8197. &quot;remote&quot;: [
  8198. &quot;mxc://matrix.org/xwvutsrqponmlkjihgfedcba&quot;,
  8199. &quot;mxc://matrix.org/abcdefghijklmnopqrstuvwx&quot;
  8200. ]
  8201. }
  8202. </code></pre>
  8203. <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>
  8204. <p>Listing all media that has been uploaded by a local user can be achieved through
  8205. the use of the <a href="admin_api/user_admin_api.html#list-media-of-a-user">List media of a user</a>
  8206. Admin API.</p>
  8207. <h1 id="quarantine-media"><a class="header" href="#quarantine-media">Quarantine media</a></h1>
  8208. <p>Quarantining media means that it is marked as inaccessible by users. It applies
  8209. to any local media, and any locally-cached copies of remote media.</p>
  8210. <p>The media file itself (and any thumbnails) is not deleted from the server.</p>
  8211. <h2 id="quarantining-media-by-id"><a class="header" href="#quarantining-media-by-id">Quarantining media by ID</a></h2>
  8212. <p>This API quarantines a single piece of local or remote media.</p>
  8213. <p>Request:</p>
  8214. <pre><code>POST /_synapse/admin/v1/media/quarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8215. {}
  8216. </code></pre>
  8217. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8218. form of <code>abcdefg12345...</code>.</p>
  8219. <p>Response:</p>
  8220. <pre><code class="language-json">{}
  8221. </code></pre>
  8222. <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>
  8223. <p>This API removes a single piece of local or remote media from quarantine.</p>
  8224. <p>Request:</p>
  8225. <pre><code>POST /_synapse/admin/v1/media/unquarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8226. {}
  8227. </code></pre>
  8228. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8229. form of <code>abcdefg12345...</code>.</p>
  8230. <p>Response:</p>
  8231. <pre><code class="language-json">{}
  8232. </code></pre>
  8233. <h2 id="quarantining-media-in-a-room"><a class="header" href="#quarantining-media-in-a-room">Quarantining media in a room</a></h2>
  8234. <p>This API quarantines all local and remote media in a room.</p>
  8235. <p>Request:</p>
  8236. <pre><code>POST /_synapse/admin/v1/room/&lt;room_id&gt;/media/quarantine
  8237. {}
  8238. </code></pre>
  8239. <p>Where <code>room_id</code> is in the form of <code>!roomid12345:example.org</code>.</p>
  8240. <p>Response:</p>
  8241. <pre><code class="language-json">{
  8242. &quot;num_quarantined&quot;: 10
  8243. }
  8244. </code></pre>
  8245. <p>The following fields are returned in the JSON response body:</p>
  8246. <ul>
  8247. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8248. </ul>
  8249. <p>Note that there is a legacy endpoint, <code>POST /_synapse/admin/v1/quarantine_media/&lt;room_id&gt;</code>, that operates the same.
  8250. However, it is deprecated and may be removed in a future release.</p>
  8251. <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>
  8252. <p>This API quarantines all <em>local</em> media that a <em>local</em> user has uploaded. That is to say, if
  8253. you would like to quarantine media uploaded by a user on a remote homeserver, you should
  8254. instead use one of the other APIs.</p>
  8255. <p>Request:</p>
  8256. <pre><code>POST /_synapse/admin/v1/user/&lt;user_id&gt;/media/quarantine
  8257. {}
  8258. </code></pre>
  8259. <p>URL Parameters</p>
  8260. <ul>
  8261. <li><code>user_id</code>: string - User ID in the form of <code>@bob:example.org</code></li>
  8262. </ul>
  8263. <p>Response:</p>
  8264. <pre><code class="language-json">{
  8265. &quot;num_quarantined&quot;: 10
  8266. }
  8267. </code></pre>
  8268. <p>The following fields are returned in the JSON response body:</p>
  8269. <ul>
  8270. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8271. </ul>
  8272. <h2 id="protecting-media-from-being-quarantined"><a class="header" href="#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></h2>
  8273. <p>This API protects a single piece of local media from being quarantined using the
  8274. above APIs. This is useful for sticker packs and other shared media which you do
  8275. not want to get quarantined, especially when
  8276. <a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">quarantining media in a room</a>.</p>
  8277. <p>Request:</p>
  8278. <pre><code>POST /_synapse/admin/v1/media/protect/&lt;media_id&gt;
  8279. {}
  8280. </code></pre>
  8281. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8282. <p>Response:</p>
  8283. <pre><code class="language-json">{}
  8284. </code></pre>
  8285. <h2 id="unprotecting-media-from-being-quarantined"><a class="header" href="#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></h2>
  8286. <p>This API reverts the protection of a media.</p>
  8287. <p>Request:</p>
  8288. <pre><code>POST /_synapse/admin/v1/media/unprotect/&lt;media_id&gt;
  8289. {}
  8290. </code></pre>
  8291. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8292. <p>Response:</p>
  8293. <pre><code class="language-json">{}
  8294. </code></pre>
  8295. <h1 id="delete-local-media"><a class="header" href="#delete-local-media">Delete local media</a></h1>
  8296. <p>This API deletes the <em>local</em> media from the disk of your own server.
  8297. This includes any local thumbnails and copies of media downloaded from
  8298. remote homeservers.
  8299. This API will not affect media that has been uploaded to external
  8300. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
  8301. See also <a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a>.</p>
  8302. <h2 id="delete-a-specific-local-media"><a class="header" href="#delete-a-specific-local-media">Delete a specific local media</a></h2>
  8303. <p>Delete a specific <code>media_id</code>.</p>
  8304. <p>Request:</p>
  8305. <pre><code>DELETE /_synapse/admin/v1/media/&lt;server_name&gt;/&lt;media_id&gt;
  8306. {}
  8307. </code></pre>
  8308. <p>URL Parameters</p>
  8309. <ul>
  8310. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>)</li>
  8311. <li><code>media_id</code>: string - The ID of the media (e.g <code>abcdefghijklmnopqrstuvwx</code>)</li>
  8312. </ul>
  8313. <p>Response:</p>
  8314. <pre><code class="language-json">{
  8315. &quot;deleted_media&quot;: [
  8316. &quot;abcdefghijklmnopqrstuvwx&quot;
  8317. ],
  8318. &quot;total&quot;: 1
  8319. }
  8320. </code></pre>
  8321. <p>The following fields are returned in the JSON response body:</p>
  8322. <ul>
  8323. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8324. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8325. </ul>
  8326. <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>
  8327. <p>Request:</p>
  8328. <pre><code>POST /_synapse/admin/v1/media/&lt;server_name&gt;/delete?before_ts=&lt;before_ts&gt;
  8329. {}
  8330. </code></pre>
  8331. <p>URL Parameters</p>
  8332. <ul>
  8333. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>).</li>
  8334. <li><code>before_ts</code>: string representing a positive integer - Unix timestamp in ms.
  8335. Files that were last used before this timestamp will be deleted. It is the timestamp of
  8336. last access and not the timestamp creation.</li>
  8337. <li><code>size_gt</code>: Optional - string representing a positive integer - Size of the media in bytes.
  8338. Files that are larger will be deleted. Defaults to <code>0</code>.</li>
  8339. <li><code>keep_profiles</code>: Optional - string representing a boolean - Switch to also delete files
  8340. that are still used in image data (e.g user profile, room avatar).
  8341. If <code>false</code> these files will be deleted. Defaults to <code>true</code>.</li>
  8342. </ul>
  8343. <p>Response:</p>
  8344. <pre><code class="language-json">{
  8345. &quot;deleted_media&quot;: [
  8346. &quot;abcdefghijklmnopqrstuvwx&quot;,
  8347. &quot;abcdefghijklmnopqrstuvwz&quot;
  8348. ],
  8349. &quot;total&quot;: 2
  8350. }
  8351. </code></pre>
  8352. <p>The following fields are returned in the JSON response body:</p>
  8353. <ul>
  8354. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8355. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8356. </ul>
  8357. <h1 id="purge-remote-media-api"><a class="header" href="#purge-remote-media-api">Purge Remote Media API</a></h1>
  8358. <p>The purge remote media API allows server admins to purge old cached remote media.</p>
  8359. <p>The API is:</p>
  8360. <pre><code>POST /_synapse/admin/v1/purge_media_cache?before_ts=&lt;unix_timestamp_in_ms&gt;
  8361. {}
  8362. </code></pre>
  8363. <p>URL Parameters</p>
  8364. <ul>
  8365. <li><code>unix_timestamp_in_ms</code>: string representing a positive integer - Unix timestamp in ms.
  8366. All cached media that was last accessed before this timestamp will be removed.</li>
  8367. </ul>
  8368. <p>Response:</p>
  8369. <pre><code class="language-json">{
  8370. &quot;deleted&quot;: 10
  8371. }
  8372. </code></pre>
  8373. <p>The following fields are returned in the JSON response body:</p>
  8374. <ul>
  8375. <li><code>deleted</code>: integer - The number of media items successfully deleted</li>
  8376. </ul>
  8377. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8378. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8379. <p>If the user re-requests purged remote media, synapse will re-request the media
  8380. from the originating server.</p>
  8381. <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>
  8382. <p>The purge history API allows server admins to purge historic events from their
  8383. database, reclaiming disk space.</p>
  8384. <p>Depending on the amount of history being purged a call to the API may take
  8385. several minutes or longer. During this period users will not be able to
  8386. paginate further back in the room from the point being purged from.</p>
  8387. <p>Note that Synapse requires at least one message in each room, so it will never
  8388. delete the last message in a room.</p>
  8389. <p>The API is:</p>
  8390. <pre><code>POST /_synapse/admin/v1/purge_history/&lt;room_id&gt;[/&lt;event_id&gt;]
  8391. </code></pre>
  8392. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8393. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  8394. <p>By default, events sent by local users are not deleted, as they may represent
  8395. the only copies of this content in existence. (Events sent by remote users are
  8396. deleted.)</p>
  8397. <p>Room state data (such as joins, leaves, topic) is always preserved.</p>
  8398. <p>To delete local message events as well, set <code>delete_local_events</code> in the body:</p>
  8399. <pre><code>{
  8400. &quot;delete_local_events&quot;: true
  8401. }
  8402. </code></pre>
  8403. <p>The caller must specify the point in the room to purge up to. This can be
  8404. specified by including an event_id in the URI, or by setting a
  8405. <code>purge_up_to_event_id</code> or <code>purge_up_to_ts</code> in the request body. If an event
  8406. id is given, that event (and others at the same graph depth) will be retained.
  8407. If <code>purge_up_to_ts</code> is given, it should be a timestamp since the unix epoch,
  8408. in milliseconds.</p>
  8409. <p>The API starts the purge running, and returns immediately with a JSON body with
  8410. a purge id:</p>
  8411. <pre><code class="language-json">{
  8412. &quot;purge_id&quot;: &quot;&lt;opaque id&gt;&quot;
  8413. }
  8414. </code></pre>
  8415. <h2 id="purge-status-query"><a class="header" href="#purge-status-query">Purge status query</a></h2>
  8416. <p>It is possible to poll for updates on recent purges with a second API;</p>
  8417. <pre><code>GET /_synapse/admin/v1/purge_history_status/&lt;purge_id&gt;
  8418. </code></pre>
  8419. <p>Again, you will need to authenticate by providing an <code>access_token</code> for a
  8420. server admin.</p>
  8421. <p>This API returns a JSON body like the following:</p>
  8422. <pre><code class="language-json">{
  8423. &quot;status&quot;: &quot;active&quot;
  8424. }
  8425. </code></pre>
  8426. <p>The status will be one of <code>active</code>, <code>complete</code>, or <code>failed</code>.</p>
  8427. <h2 id="reclaim-disk-space-postgres"><a class="header" href="#reclaim-disk-space-postgres">Reclaim disk space (Postgres)</a></h2>
  8428. <p>To reclaim the disk space and return it to the operating system, you need to run
  8429. <code>VACUUM FULL;</code> on the database.</p>
  8430. <p><a href="https://www.postgresql.org/docs/current/sql-vacuum.html">https://www.postgresql.org/docs/current/sql-vacuum.html</a></p>
  8431. <div style="break-before: page; page-break-before: always;"></div><h1 id="deprecated-purge-room-api"><a class="header" href="#deprecated-purge-room-api">Deprecated: Purge room API</a></h1>
  8432. <p><strong>The old Purge room API is deprecated and will be removed in a future release.
  8433. See the new <a href="admin_api/rooms.html#delete-room-api">Delete Room API</a> for more details.</strong></p>
  8434. <p>This API will remove all trace of a room from your database.</p>
  8435. <p>All local users must have left the room before it can be removed.</p>
  8436. <p>The API is:</p>
  8437. <pre><code>POST /_synapse/admin/v1/purge_room
  8438. {
  8439. &quot;room_id&quot;: &quot;!room:id&quot;
  8440. }
  8441. </code></pre>
  8442. <p>You must authenticate using the access token of an admin user.</p>
  8443. <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>
  8444. <p>This API allows for the creation of users in an administrative and
  8445. non-interactive way. This is generally used for bootstrapping a Synapse
  8446. instance with administrator accounts.</p>
  8447. <p>To authenticate yourself to the server, you will need both the shared secret
  8448. (<code>registration_shared_secret</code> in the homeserver configuration), and a
  8449. one-time nonce. If the registration shared secret is not configured, this API
  8450. is not enabled.</p>
  8451. <p>To fetch the nonce, you need to request one from the API:</p>
  8452. <pre><code>&gt; GET /_synapse/admin/v1/register
  8453. &lt; {&quot;nonce&quot;: &quot;thisisanonce&quot;}
  8454. </code></pre>
  8455. <p>Once you have the nonce, you can make a <code>POST</code> to the same URL with a JSON
  8456. body containing the nonce, username, password, whether they are an admin
  8457. (optional, False by default), and a HMAC digest of the content. Also you can
  8458. set the displayname (optional, <code>username</code> by default).</p>
  8459. <p>As an example:</p>
  8460. <pre><code>&gt; POST /_synapse/admin/v1/register
  8461. &gt; {
  8462. &quot;nonce&quot;: &quot;thisisanonce&quot;,
  8463. &quot;username&quot;: &quot;pepper_roni&quot;,
  8464. &quot;displayname&quot;: &quot;Pepper Roni&quot;,
  8465. &quot;password&quot;: &quot;pizza&quot;,
  8466. &quot;admin&quot;: true,
  8467. &quot;mac&quot;: &quot;mac_digest_here&quot;
  8468. }
  8469. &lt; {
  8470. &quot;access_token&quot;: &quot;token_here&quot;,
  8471. &quot;user_id&quot;: &quot;@pepper_roni:localhost&quot;,
  8472. &quot;home_server&quot;: &quot;test&quot;,
  8473. &quot;device_id&quot;: &quot;device_id_here&quot;
  8474. }
  8475. </code></pre>
  8476. <p>The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
  8477. the shared secret and the content being the nonce, user, password, either the
  8478. string &quot;admin&quot; or &quot;notadmin&quot;, and optionally the user_type
  8479. each separated by NULs. For an example of generation in Python:</p>
  8480. <pre><code class="language-python">import hmac, hashlib
  8481. def generate_mac(nonce, user, password, admin=False, user_type=None):
  8482. mac = hmac.new(
  8483. key=shared_secret,
  8484. digestmod=hashlib.sha1,
  8485. )
  8486. mac.update(nonce.encode('utf8'))
  8487. mac.update(b&quot;\x00&quot;)
  8488. mac.update(user.encode('utf8'))
  8489. mac.update(b&quot;\x00&quot;)
  8490. mac.update(password.encode('utf8'))
  8491. mac.update(b&quot;\x00&quot;)
  8492. mac.update(b&quot;admin&quot; if admin else b&quot;notadmin&quot;)
  8493. if user_type:
  8494. mac.update(b&quot;\x00&quot;)
  8495. mac.update(user_type.encode('utf8'))
  8496. return mac.hexdigest()
  8497. </code></pre>
  8498. <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>
  8499. <p>This API allows an administrator to join an user account with a given <code>user_id</code>
  8500. to a room with a given <code>room_id_or_alias</code>. You can only modify the membership of
  8501. local users. The server administrator must be in the room and have permission to
  8502. invite users.</p>
  8503. <h2 id="parameters"><a class="header" href="#parameters">Parameters</a></h2>
  8504. <p>The following parameters are available:</p>
  8505. <ul>
  8506. <li><code>user_id</code> - Fully qualified user: for example, <code>@user:server.com</code>.</li>
  8507. <li><code>room_id_or_alias</code> - The room identifier or alias to join: for example,
  8508. <code>!636q39766251:server.com</code>.</li>
  8509. </ul>
  8510. <h2 id="usage-1"><a class="header" href="#usage-1">Usage</a></h2>
  8511. <pre><code>POST /_synapse/admin/v1/join/&lt;room_id_or_alias&gt;
  8512. {
  8513. &quot;user_id&quot;: &quot;@user:server.com&quot;
  8514. }
  8515. </code></pre>
  8516. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8517. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8518. <p>Response:</p>
  8519. <pre><code>{
  8520. &quot;room_id&quot;: &quot;!636q39766251:server.com&quot;
  8521. }
  8522. </code></pre>
  8523. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-2"><a class="header" href="#contents-2">Contents</a></h1>
  8524. <ul>
  8525. <li><a href="admin_api/rooms.html#list-room-api">List Room API</a></li>
  8526. <li><a href="admin_api/rooms.html#room-details-api">Room Details API</a></li>
  8527. <li><a href="admin_api/rooms.html#room-members-api">Room Members API</a></li>
  8528. <li><a href="admin_api/rooms.html#room-state-api">Room State API</a></li>
  8529. <li><a href="admin_api/rooms.html#delete-room-api">Delete Room API</a>
  8530. <ul>
  8531. <li><a href="admin_api/rooms.html#undoing-room-shutdowns">Undoing room shutdowns</a></li>
  8532. </ul>
  8533. </li>
  8534. <li><a href="admin_api/rooms.html#make-room-admin-api">Make Room Admin API</a></li>
  8535. <li><a href="admin_api/rooms.html#forward-extremities-admin-api">Forward Extremities Admin API</a></li>
  8536. <li><a href="admin_api/rooms.html#event-context-api">Event Context API</a></li>
  8537. </ul>
  8538. <h1 id="list-room-api"><a class="header" href="#list-room-api">List Room API</a></h1>
  8539. <p>The List Room admin API allows server admins to get a list of rooms on their
  8540. server. There are various parameters available that allow for filtering and
  8541. sorting the returned list. This API supports pagination.</p>
  8542. <p><strong>Parameters</strong></p>
  8543. <p>The following query parameters are available:</p>
  8544. <ul>
  8545. <li><code>from</code> - Offset in the returned list. Defaults to <code>0</code>.</li>
  8546. <li><code>limit</code> - Maximum amount of rooms to return. Defaults to <code>100</code>.</li>
  8547. <li><code>order_by</code> - The method in which to sort the returned list of rooms. Valid values are:
  8548. <ul>
  8549. <li><code>alphabetical</code> - Same as <code>name</code>. This is deprecated.</li>
  8550. <li><code>size</code> - Same as <code>joined_members</code>. This is deprecated.</li>
  8551. <li><code>name</code> - Rooms are ordered alphabetically by room name. This is the default.</li>
  8552. <li><code>canonical_alias</code> - Rooms are ordered alphabetically by main alias address of the room.</li>
  8553. <li><code>joined_members</code> - Rooms are ordered by the number of members. Largest to smallest.</li>
  8554. <li><code>joined_local_members</code> - Rooms are ordered by the number of local members. Largest to smallest.</li>
  8555. <li><code>version</code> - Rooms are ordered by room version. Largest to smallest.</li>
  8556. <li><code>creator</code> - Rooms are ordered alphabetically by creator of the room.</li>
  8557. <li><code>encryption</code> - Rooms are ordered alphabetically by the end-to-end encryption algorithm.</li>
  8558. <li><code>federatable</code> - Rooms are ordered by whether the room is federatable.</li>
  8559. <li><code>public</code> - Rooms are ordered by visibility in room list.</li>
  8560. <li><code>join_rules</code> - Rooms are ordered alphabetically by join rules of the room.</li>
  8561. <li><code>guest_access</code> - Rooms are ordered alphabetically by guest access option of the room.</li>
  8562. <li><code>history_visibility</code> - Rooms are ordered alphabetically by visibility of history of the room.</li>
  8563. <li><code>state_events</code> - Rooms are ordered by number of state events. Largest to smallest.</li>
  8564. </ul>
  8565. </li>
  8566. <li><code>dir</code> - Direction of room order. Either <code>f</code> for forwards or <code>b</code> for backwards. Setting
  8567. this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  8568. <li><code>search_term</code> - Filter rooms by their room name. Search term can be contained in any
  8569. part of the room name. Defaults to no filtering.</li>
  8570. </ul>
  8571. <p><strong>Response</strong></p>
  8572. <p>The following fields are possible in the JSON response body:</p>
  8573. <ul>
  8574. <li><code>rooms</code> - An array of objects, each containing information about a room.
  8575. <ul>
  8576. <li>Room objects contain the following fields:
  8577. <ul>
  8578. <li><code>room_id</code> - The ID of the room.</li>
  8579. <li><code>name</code> - The name of the room.</li>
  8580. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  8581. <li><code>joined_members</code> - How many users are currently in the room.</li>
  8582. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  8583. <li><code>version</code> - The version of the room as a string.</li>
  8584. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  8585. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  8586. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  8587. <li><code>public</code> - Whether the room is visible in room directory.</li>
  8588. <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>
  8589. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  8590. <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>
  8591. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  8592. </ul>
  8593. </li>
  8594. </ul>
  8595. </li>
  8596. <li><code>offset</code> - The current pagination offset in rooms. This parameter should be
  8597. used instead of <code>next_token</code> for room offset as <code>next_token</code> is
  8598. not intended to be parsed.</li>
  8599. <li><code>total_rooms</code> - The total number of rooms this query can return. Using this
  8600. and <code>offset</code>, you have enough information to know the current
  8601. progression through the list.</li>
  8602. <li><code>next_batch</code> - If this field is present, we know that there are potentially
  8603. more rooms on the server that did not all fit into this response.
  8604. We can use <code>next_batch</code> to get the &quot;next page&quot; of results. To do
  8605. so, simply repeat your request, setting the <code>from</code> parameter to
  8606. the value of <code>next_batch</code>.</li>
  8607. <li><code>prev_batch</code> - If this field is present, it is possible to paginate backwards.
  8608. Use <code>prev_batch</code> for the <code>from</code> value in the next request to
  8609. get the &quot;previous page&quot; of results.</li>
  8610. </ul>
  8611. <p>The API is:</p>
  8612. <p>A standard request with no filtering:</p>
  8613. <pre><code>GET /_synapse/admin/v1/rooms
  8614. </code></pre>
  8615. <p>A response body like the following is returned:</p>
  8616. <pre><code class="language-jsonc">{
  8617. &quot;rooms&quot;: [
  8618. {
  8619. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  8620. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8621. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  8622. &quot;joined_members&quot;: 8326,
  8623. &quot;joined_local_members&quot;: 2,
  8624. &quot;version&quot;: &quot;1&quot;,
  8625. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8626. &quot;encryption&quot;: null,
  8627. &quot;federatable&quot;: true,
  8628. &quot;public&quot;: true,
  8629. &quot;join_rules&quot;: &quot;invite&quot;,
  8630. &quot;guest_access&quot;: null,
  8631. &quot;history_visibility&quot;: &quot;shared&quot;,
  8632. &quot;state_events&quot;: 93534
  8633. },
  8634. ... (8 hidden items) ...
  8635. {
  8636. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8637. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8638. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8639. &quot;joined_members&quot;: 314,
  8640. &quot;joined_local_members&quot;: 20,
  8641. &quot;version&quot;: &quot;4&quot;,
  8642. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8643. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8644. &quot;federatable&quot;: true,
  8645. &quot;public&quot;: false,
  8646. &quot;join_rules&quot;: &quot;invite&quot;,
  8647. &quot;guest_access&quot;: null,
  8648. &quot;history_visibility&quot;: &quot;shared&quot;,
  8649. &quot;state_events&quot;: 8345
  8650. }
  8651. ],
  8652. &quot;offset&quot;: 0,
  8653. &quot;total_rooms&quot;: 10
  8654. }
  8655. </code></pre>
  8656. <p>Filtering by room name:</p>
  8657. <pre><code>GET /_synapse/admin/v1/rooms?search_term=TWIM
  8658. </code></pre>
  8659. <p>A response body like the following is returned:</p>
  8660. <pre><code class="language-json">{
  8661. &quot;rooms&quot;: [
  8662. {
  8663. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8664. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8665. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8666. &quot;joined_members&quot;: 314,
  8667. &quot;joined_local_members&quot;: 20,
  8668. &quot;version&quot;: &quot;4&quot;,
  8669. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8670. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8671. &quot;federatable&quot;: true,
  8672. &quot;public&quot;: false,
  8673. &quot;join_rules&quot;: &quot;invite&quot;,
  8674. &quot;guest_access&quot;: null,
  8675. &quot;history_visibility&quot;: &quot;shared&quot;,
  8676. &quot;state_events&quot;: 8
  8677. }
  8678. ],
  8679. &quot;offset&quot;: 0,
  8680. &quot;total_rooms&quot;: 1
  8681. }
  8682. </code></pre>
  8683. <p>Paginating through a list of rooms:</p>
  8684. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size
  8685. </code></pre>
  8686. <p>A response body like the following is returned:</p>
  8687. <pre><code class="language-jsonc">{
  8688. &quot;rooms&quot;: [
  8689. {
  8690. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  8691. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8692. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  8693. &quot;joined_members&quot;: 8326,
  8694. &quot;joined_local_members&quot;: 2,
  8695. &quot;version&quot;: &quot;1&quot;,
  8696. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8697. &quot;encryption&quot;: null,
  8698. &quot;federatable&quot;: true,
  8699. &quot;public&quot;: true,
  8700. &quot;join_rules&quot;: &quot;invite&quot;,
  8701. &quot;guest_access&quot;: null,
  8702. &quot;history_visibility&quot;: &quot;shared&quot;,
  8703. &quot;state_events&quot;: 93534
  8704. },
  8705. ... (98 hidden items) ...
  8706. {
  8707. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8708. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8709. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8710. &quot;joined_members&quot;: 314,
  8711. &quot;joined_local_members&quot;: 20,
  8712. &quot;version&quot;: &quot;4&quot;,
  8713. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8714. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8715. &quot;federatable&quot;: true,
  8716. &quot;public&quot;: false,
  8717. &quot;join_rules&quot;: &quot;invite&quot;,
  8718. &quot;guest_access&quot;: null,
  8719. &quot;history_visibility&quot;: &quot;shared&quot;,
  8720. &quot;state_events&quot;: 8345
  8721. }
  8722. ],
  8723. &quot;offset&quot;: 0,
  8724. &quot;total_rooms&quot;: 150
  8725. &quot;next_token&quot;: 100
  8726. }
  8727. </code></pre>
  8728. <p>The presence of the <code>next_token</code> parameter tells us that there are more rooms
  8729. than returned in this request, and we need to make another request to get them.
  8730. To get the next batch of room results, we repeat our request, setting the <code>from</code>
  8731. parameter to the value of <code>next_token</code>.</p>
  8732. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size&amp;from=100
  8733. </code></pre>
  8734. <p>A response body like the following is returned:</p>
  8735. <pre><code class="language-jsonc">{
  8736. &quot;rooms&quot;: [
  8737. {
  8738. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  8739. &quot;name&quot;: &quot;Music Theory&quot;,
  8740. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  8741. &quot;joined_members&quot;: 127,
  8742. &quot;joined_local_members&quot;: 2,
  8743. &quot;version&quot;: &quot;1&quot;,
  8744. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8745. &quot;encryption&quot;: null,
  8746. &quot;federatable&quot;: true,
  8747. &quot;public&quot;: true,
  8748. &quot;join_rules&quot;: &quot;invite&quot;,
  8749. &quot;guest_access&quot;: null,
  8750. &quot;history_visibility&quot;: &quot;shared&quot;,
  8751. &quot;state_events&quot;: 93534
  8752. },
  8753. ... (48 hidden items) ...
  8754. {
  8755. &quot;room_id&quot;: &quot;!twcBhHVdZlQWuuxBhN:termina.org.uk&quot;,
  8756. &quot;name&quot;: &quot;weechat-matrix&quot;,
  8757. &quot;canonical_alias&quot;: &quot;#weechat-matrix:termina.org.uk&quot;,
  8758. &quot;joined_members&quot;: 137,
  8759. &quot;joined_local_members&quot;: 20,
  8760. &quot;version&quot;: &quot;4&quot;,
  8761. &quot;creator&quot;: &quot;@foo:termina.org.uk&quot;,
  8762. &quot;encryption&quot;: null,
  8763. &quot;federatable&quot;: true,
  8764. &quot;public&quot;: true,
  8765. &quot;join_rules&quot;: &quot;invite&quot;,
  8766. &quot;guest_access&quot;: null,
  8767. &quot;history_visibility&quot;: &quot;shared&quot;,
  8768. &quot;state_events&quot;: 8345
  8769. }
  8770. ],
  8771. &quot;offset&quot;: 100,
  8772. &quot;prev_batch&quot;: 0,
  8773. &quot;total_rooms&quot;: 150
  8774. }
  8775. </code></pre>
  8776. <p>Once the <code>next_token</code> parameter is no longer present, we know we've reached the
  8777. end of the list.</p>
  8778. <h1 id="room-details-api"><a class="header" href="#room-details-api">Room Details API</a></h1>
  8779. <p>The Room Details admin API allows server admins to get all details of a room.</p>
  8780. <p>The following fields are possible in the JSON response body:</p>
  8781. <ul>
  8782. <li><code>room_id</code> - The ID of the room.</li>
  8783. <li><code>name</code> - The name of the room.</li>
  8784. <li><code>topic</code> - The topic of the room.</li>
  8785. <li><code>avatar</code> - The <code>mxc</code> URI to the avatar of the room.</li>
  8786. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  8787. <li><code>joined_members</code> - How many users are currently in the room.</li>
  8788. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  8789. <li><code>joined_local_devices</code> - How many local devices are currently in the room.</li>
  8790. <li><code>version</code> - The version of the room as a string.</li>
  8791. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  8792. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  8793. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  8794. <li><code>public</code> - Whether the room is visible in room directory.</li>
  8795. <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>
  8796. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  8797. <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>
  8798. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  8799. </ul>
  8800. <p>The API is:</p>
  8801. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;
  8802. </code></pre>
  8803. <p>A response body like the following is returned:</p>
  8804. <pre><code class="language-json">{
  8805. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  8806. &quot;name&quot;: &quot;Music Theory&quot;,
  8807. &quot;avatar&quot;: &quot;mxc://matrix.org/AQDaVFlbkQoErdOgqWRgiGSV&quot;,
  8808. &quot;topic&quot;: &quot;Theory, Composition, Notation, Analysis&quot;,
  8809. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  8810. &quot;joined_members&quot;: 127,
  8811. &quot;joined_local_members&quot;: 2,
  8812. &quot;joined_local_devices&quot;: 2,
  8813. &quot;version&quot;: &quot;1&quot;,
  8814. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8815. &quot;encryption&quot;: null,
  8816. &quot;federatable&quot;: true,
  8817. &quot;public&quot;: true,
  8818. &quot;join_rules&quot;: &quot;invite&quot;,
  8819. &quot;guest_access&quot;: null,
  8820. &quot;history_visibility&quot;: &quot;shared&quot;,
  8821. &quot;state_events&quot;: 93534
  8822. }
  8823. </code></pre>
  8824. <h1 id="room-members-api"><a class="header" href="#room-members-api">Room Members API</a></h1>
  8825. <p>The Room Members admin API allows server admins to get a list of all members of a room.</p>
  8826. <p>The response includes the following fields:</p>
  8827. <ul>
  8828. <li><code>members</code> - A list of all the members that are present in the room, represented by their ids.</li>
  8829. <li><code>total</code> - Total number of members in the room.</li>
  8830. </ul>
  8831. <p>The API is:</p>
  8832. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/members
  8833. </code></pre>
  8834. <p>A response body like the following is returned:</p>
  8835. <pre><code class="language-json">{
  8836. &quot;members&quot;: [
  8837. &quot;@foo:matrix.org&quot;,
  8838. &quot;@bar:matrix.org&quot;,
  8839. &quot;@foobar:matrix.org&quot;
  8840. ],
  8841. &quot;total&quot;: 3
  8842. }
  8843. </code></pre>
  8844. <h1 id="room-state-api"><a class="header" href="#room-state-api">Room State API</a></h1>
  8845. <p>The Room State admin API allows server admins to get a list of all state events in a room.</p>
  8846. <p>The response includes the following fields:</p>
  8847. <ul>
  8848. <li><code>state</code> - The current state of the room at the time of request.</li>
  8849. </ul>
  8850. <p>The API is:</p>
  8851. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/state
  8852. </code></pre>
  8853. <p>A response body like the following is returned:</p>
  8854. <pre><code class="language-json">{
  8855. &quot;state&quot;: [
  8856. {&quot;type&quot;: &quot;m.room.create&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  8857. {&quot;type&quot;: &quot;m.room.power_levels&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  8858. {&quot;type&quot;: &quot;m.room.name&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true}
  8859. ]
  8860. }
  8861. </code></pre>
  8862. <h1 id="delete-room-api"><a class="header" href="#delete-room-api">Delete Room API</a></h1>
  8863. <p>The Delete Room admin API allows server admins to remove rooms from server
  8864. and block these rooms.</p>
  8865. <p>Shuts down a room. Moves all local users and room aliases automatically to a
  8866. new room if <code>new_room_user_id</code> is set. Otherwise local users only
  8867. leave the room without any information.</p>
  8868. <p>The new room will be created with the user specified by the <code>new_room_user_id</code> parameter
  8869. as room administrator and will contain a message explaining what happened. Users invited
  8870. to the new room will have power level <code>-10</code> by default, and thus be unable to speak.</p>
  8871. <p>If <code>block</code> is <code>True</code> it prevents new joins to the old room.</p>
  8872. <p>This API will remove all trace of the old room from your database after removing
  8873. all local users. If <code>purge</code> is <code>true</code> (the default), all traces of the old room will
  8874. be removed from your database after removing all local users. If you do not want
  8875. this to happen, set <code>purge</code> to <code>false</code>.
  8876. Depending on the amount of history being purged a call to the API may take
  8877. several minutes or longer.</p>
  8878. <p>The local server will only have the power to move local user and room aliases to
  8879. the new room. Users on other servers will be unaffected.</p>
  8880. <p>The API is:</p>
  8881. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id&gt;
  8882. </code></pre>
  8883. <p>with a body of:</p>
  8884. <pre><code class="language-json">{
  8885. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  8886. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  8887. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;,
  8888. &quot;block&quot;: true,
  8889. &quot;purge&quot;: true
  8890. }
  8891. </code></pre>
  8892. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8893. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8894. <p>A response body like the following is returned:</p>
  8895. <pre><code class="language-json">{
  8896. &quot;kicked_users&quot;: [
  8897. &quot;@foobar:example.com&quot;
  8898. ],
  8899. &quot;failed_to_kick_users&quot;: [],
  8900. &quot;local_aliases&quot;: [
  8901. &quot;#badroom:example.com&quot;,
  8902. &quot;#evilsaloon:example.com&quot;
  8903. ],
  8904. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;
  8905. }
  8906. </code></pre>
  8907. <p><strong>Parameters</strong></p>
  8908. <p>The following parameters should be set in the URL:</p>
  8909. <ul>
  8910. <li><code>room_id</code> - The ID of the room.</li>
  8911. </ul>
  8912. <p>The following JSON body parameters are available:</p>
  8913. <ul>
  8914. <li><code>new_room_user_id</code> - Optional. If set, a new room will be created with this user ID
  8915. as the creator and admin, and all users in the old room will be moved into that
  8916. room. If not set, no new room will be created and the users will just be removed
  8917. from the old room. The user ID must be on the local server, but does not necessarily
  8918. have to belong to a registered user.</li>
  8919. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  8920. invited to. Defaults to <code>Content Violation Notification</code></li>
  8921. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  8922. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  8923. 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>
  8924. <li><code>block</code> - Optional. If set to <code>true</code>, this room will be added to a blocking list, preventing
  8925. future attempts to join the room. Defaults to <code>false</code>.</li>
  8926. <li><code>purge</code> - Optional. If set to <code>true</code>, it will remove all traces of the room from your database.
  8927. Defaults to <code>true</code>.</li>
  8928. <li><code>force_purge</code> - Optional, and ignored unless <code>purge</code> is <code>true</code>. If set to <code>true</code>, it
  8929. will force a purge to go ahead even if there are local users still in the room. Do not
  8930. use this unless a regular <code>purge</code> operation fails, as it could leave those users'
  8931. clients in a confused state.</li>
  8932. </ul>
  8933. <p>The JSON body must not be empty. The body must be at least <code>{}</code>.</p>
  8934. <p><strong>Response</strong></p>
  8935. <p>The following fields are returned in the JSON response body:</p>
  8936. <ul>
  8937. <li><code>kicked_users</code> - An array of users (<code>user_id</code>) that were kicked.</li>
  8938. <li><code>failed_to_kick_users</code> - An array of users (<code>user_id</code>) that that were not kicked.</li>
  8939. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  8940. the old room to the new.</li>
  8941. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  8942. </ul>
  8943. <h2 id="undoing-room-shutdowns"><a class="header" href="#undoing-room-shutdowns">Undoing room shutdowns</a></h2>
  8944. <p><em>Note</em>: This guide may be outdated by the time you read it. By nature of room shutdowns being performed at the database level,
  8945. the structure can and does change without notice.</p>
  8946. <p>First, it's important to understand that a room shutdown is very destructive. Undoing a shutdown is not as simple as pretending it
  8947. 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
  8948. to recover at all:</p>
  8949. <ul>
  8950. <li>If the room was invite-only, your users will need to be re-invited.</li>
  8951. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  8952. <li>The first user to rejoin will have to do so via an alias on a different server.</li>
  8953. </ul>
  8954. <p>With all that being said, if you still want to try and recover the room:</p>
  8955. <ol>
  8956. <li>For safety reasons, shut down Synapse.</li>
  8957. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  8958. <ul>
  8959. <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>
  8960. <li>The room ID is the same one supplied to the shutdown room API, not the Content Violation room.</li>
  8961. </ul>
  8962. </li>
  8963. <li>Restart Synapse.</li>
  8964. </ol>
  8965. <p>You will have to manually handle, if you so choose, the following:</p>
  8966. <ul>
  8967. <li>Aliases that would have been redirected to the Content Violation room.</li>
  8968. <li>Users that would have been booted from the room (and will have been force-joined to the Content Violation room).</li>
  8969. <li>Removal of the Content Violation room if desired.</li>
  8970. </ul>
  8971. <h2 id="deprecated-endpoint"><a class="header" href="#deprecated-endpoint">Deprecated endpoint</a></h2>
  8972. <p>The previous deprecated API will be removed in a future release, it was:</p>
  8973. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id&gt;/delete
  8974. </code></pre>
  8975. <p>It behaves the same way than the current endpoint except the path and the method.</p>
  8976. <h1 id="make-room-admin-api"><a class="header" href="#make-room-admin-api">Make Room Admin API</a></h1>
  8977. <p>Grants another user the highest power available to a local user who is in the room.
  8978. If the user is not in the room, and it is not publicly joinable, then invite the user.</p>
  8979. <p>By default the server admin (the caller) is granted power, but another user can
  8980. optionally be specified, e.g.:</p>
  8981. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/make_room_admin
  8982. {
  8983. &quot;user_id&quot;: &quot;@foo:example.com&quot;
  8984. }
  8985. </code></pre>
  8986. <h1 id="forward-extremities-admin-api"><a class="header" href="#forward-extremities-admin-api">Forward Extremities Admin API</a></h1>
  8987. <p>Enables querying and deleting forward extremities from rooms. When a lot of forward
  8988. extremities accumulate in a room, performance can become degraded. For details, see
  8989. <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.</p>
  8990. <h2 id="check-for-forward-extremities"><a class="header" href="#check-for-forward-extremities">Check for forward extremities</a></h2>
  8991. <p>To check the status of forward extremities for a room:</p>
  8992. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  8993. </code></pre>
  8994. <p>A response as follows will be returned:</p>
  8995. <pre><code class="language-json">{
  8996. &quot;count&quot;: 1,
  8997. &quot;results&quot;: [
  8998. {
  8999. &quot;event_id&quot;: &quot;$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdefgh&quot;,
  9000. &quot;state_group&quot;: 439,
  9001. &quot;depth&quot;: 123,
  9002. &quot;received_ts&quot;: 1611263016761
  9003. }
  9004. ]
  9005. }
  9006. </code></pre>
  9007. <h2 id="deleting-forward-extremities"><a class="header" href="#deleting-forward-extremities">Deleting forward extremities</a></h2>
  9008. <p><strong>WARNING</strong>: Please ensure you know what you're doing and have read
  9009. the related issue <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.
  9010. Under no situations should this API be executed as an automated maintenance task!</p>
  9011. <p>If a room has lots of forward extremities, the extra can be
  9012. deleted as follows:</p>
  9013. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9014. </code></pre>
  9015. <p>A response as follows will be returned, indicating the amount of forward extremities
  9016. that were deleted.</p>
  9017. <pre><code class="language-json">{
  9018. &quot;deleted&quot;: 1
  9019. }
  9020. </code></pre>
  9021. <h1 id="event-context-api"><a class="header" href="#event-context-api">Event Context API</a></h1>
  9022. <p>This API lets a client find the context of an event. This is designed primarily to investigate abuse reports.</p>
  9023. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/context/&lt;event_id&gt;
  9024. </code></pre>
  9025. <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>
  9026. <p>Example response:</p>
  9027. <pre><code class="language-json">{
  9028. &quot;end&quot;: &quot;t29-57_2_0_2&quot;,
  9029. &quot;events_after&quot;: [
  9030. {
  9031. &quot;content&quot;: {
  9032. &quot;body&quot;: &quot;This is an example text message&quot;,
  9033. &quot;msgtype&quot;: &quot;m.text&quot;,
  9034. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  9035. &quot;formatted_body&quot;: &quot;&lt;b&gt;This is an example text message&lt;/b&gt;&quot;
  9036. },
  9037. &quot;type&quot;: &quot;m.room.message&quot;,
  9038. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9039. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9040. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9041. &quot;origin_server_ts&quot;: 1432735824653,
  9042. &quot;unsigned&quot;: {
  9043. &quot;age&quot;: 1234
  9044. }
  9045. }
  9046. ],
  9047. &quot;event&quot;: {
  9048. &quot;content&quot;: {
  9049. &quot;body&quot;: &quot;filename.jpg&quot;,
  9050. &quot;info&quot;: {
  9051. &quot;h&quot;: 398,
  9052. &quot;w&quot;: 394,
  9053. &quot;mimetype&quot;: &quot;image/jpeg&quot;,
  9054. &quot;size&quot;: 31037
  9055. },
  9056. &quot;url&quot;: &quot;mxc://example.org/JWEIFJgwEIhweiWJE&quot;,
  9057. &quot;msgtype&quot;: &quot;m.image&quot;
  9058. },
  9059. &quot;type&quot;: &quot;m.room.message&quot;,
  9060. &quot;event_id&quot;: &quot;$f3h4d129462ha:example.com&quot;,
  9061. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9062. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9063. &quot;origin_server_ts&quot;: 1432735824653,
  9064. &quot;unsigned&quot;: {
  9065. &quot;age&quot;: 1234
  9066. }
  9067. },
  9068. &quot;events_before&quot;: [
  9069. {
  9070. &quot;content&quot;: {
  9071. &quot;body&quot;: &quot;something-important.doc&quot;,
  9072. &quot;filename&quot;: &quot;something-important.doc&quot;,
  9073. &quot;info&quot;: {
  9074. &quot;mimetype&quot;: &quot;application/msword&quot;,
  9075. &quot;size&quot;: 46144
  9076. },
  9077. &quot;msgtype&quot;: &quot;m.file&quot;,
  9078. &quot;url&quot;: &quot;mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe&quot;
  9079. },
  9080. &quot;type&quot;: &quot;m.room.message&quot;,
  9081. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9082. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9083. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9084. &quot;origin_server_ts&quot;: 1432735824653,
  9085. &quot;unsigned&quot;: {
  9086. &quot;age&quot;: 1234
  9087. }
  9088. }
  9089. ],
  9090. &quot;start&quot;: &quot;t27-54_2_0_2&quot;,
  9091. &quot;state&quot;: [
  9092. {
  9093. &quot;content&quot;: {
  9094. &quot;creator&quot;: &quot;@example:example.org&quot;,
  9095. &quot;room_version&quot;: &quot;1&quot;,
  9096. &quot;m.federate&quot;: true,
  9097. &quot;predecessor&quot;: {
  9098. &quot;event_id&quot;: &quot;$something:example.org&quot;,
  9099. &quot;room_id&quot;: &quot;!oldroom:example.org&quot;
  9100. }
  9101. },
  9102. &quot;type&quot;: &quot;m.room.create&quot;,
  9103. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9104. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9105. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9106. &quot;origin_server_ts&quot;: 1432735824653,
  9107. &quot;unsigned&quot;: {
  9108. &quot;age&quot;: 1234
  9109. },
  9110. &quot;state_key&quot;: &quot;&quot;
  9111. },
  9112. {
  9113. &quot;content&quot;: {
  9114. &quot;membership&quot;: &quot;join&quot;,
  9115. &quot;avatar_url&quot;: &quot;mxc://example.org/SEsfnsuifSDFSSEF&quot;,
  9116. &quot;displayname&quot;: &quot;Alice Margatroid&quot;
  9117. },
  9118. &quot;type&quot;: &quot;m.room.member&quot;,
  9119. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9120. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9121. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9122. &quot;origin_server_ts&quot;: 1432735824653,
  9123. &quot;unsigned&quot;: {
  9124. &quot;age&quot;: 1234
  9125. },
  9126. &quot;state_key&quot;: &quot;@alice:example.org&quot;
  9127. }
  9128. ]
  9129. }
  9130. </code></pre>
  9131. <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>
  9132. <p>The API to send notices is as follows:</p>
  9133. <pre><code>POST /_synapse/admin/v1/send_server_notice
  9134. </code></pre>
  9135. <p>or:</p>
  9136. <pre><code>PUT /_synapse/admin/v1/send_server_notice/{txnId}
  9137. </code></pre>
  9138. <p>You will need to authenticate with an access token for an admin user.</p>
  9139. <p>When using the <code>PUT</code> form, retransmissions with the same transaction ID will be
  9140. ignored in the same way as with <code>PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}</code>.</p>
  9141. <p>The request body should look something like the following:</p>
  9142. <pre><code class="language-json">{
  9143. &quot;user_id&quot;: &quot;@target_user:server_name&quot;,
  9144. &quot;content&quot;: {
  9145. &quot;msgtype&quot;: &quot;m.text&quot;,
  9146. &quot;body&quot;: &quot;This is my message&quot;
  9147. }
  9148. }
  9149. </code></pre>
  9150. <p>You can optionally include the following additional parameters:</p>
  9151. <ul>
  9152. <li><code>type</code>: the type of event. Defaults to <code>m.room.message</code>.</li>
  9153. <li><code>state_key</code>: Setting this will result in a state event being sent.</li>
  9154. </ul>
  9155. <p>Once the notice has been sent, the API will return the following response:</p>
  9156. <pre><code class="language-json">{
  9157. &quot;event_id&quot;: &quot;&lt;event_id&gt;&quot;
  9158. }
  9159. </code></pre>
  9160. <p>Note that server notices must be enabled in <code>homeserver.yaml</code> before this API
  9161. can be used. See <a href="admin_api/../server_notices.html">the server notices documentation</a> for more information.</p>
  9162. <div style="break-before: page; page-break-before: always;"></div><h1 id="deprecated-shutdown-room-api"><a class="header" href="#deprecated-shutdown-room-api">Deprecated: Shutdown room API</a></h1>
  9163. <p><strong>The old Shutdown room API is deprecated and will be removed in a future release.
  9164. See the new <a href="admin_api/rooms.html#delete-room-api">Delete Room API</a> for more details.</strong></p>
  9165. <p>Shuts down a room, preventing new joins and moves local users and room aliases automatically
  9166. to a new room. The new room will be created with the user specified by the
  9167. <code>new_room_user_id</code> parameter as room administrator and will contain a message
  9168. explaining what happened. Users invited to the new room will have power level
  9169. -10 by default, and thus be unable to speak. The old room's power levels will be changed to
  9170. disallow any further invites or joins.</p>
  9171. <p>The local server will only have the power to move local user and room aliases to
  9172. the new room. Users on other servers will be unaffected.</p>
  9173. <h2 id="api-1"><a class="header" href="#api-1">API</a></h2>
  9174. <p>You will need to authenticate with an access token for an admin user.</p>
  9175. <h3 id="url"><a class="header" href="#url">URL</a></h3>
  9176. <p><code>POST /_synapse/admin/v1/shutdown_room/{room_id}</code></p>
  9177. <h3 id="url-parameters"><a class="header" href="#url-parameters">URL Parameters</a></h3>
  9178. <ul>
  9179. <li><code>room_id</code> - The ID of the room (e.g <code>!someroom:example.com</code>)</li>
  9180. </ul>
  9181. <h3 id="json-body-parameters"><a class="header" href="#json-body-parameters">JSON Body Parameters</a></h3>
  9182. <ul>
  9183. <li><code>new_room_user_id</code> - Required. A string representing the user ID of the user that will admin
  9184. the new room that all users in the old room will be moved to.</li>
  9185. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  9186. invited to.</li>
  9187. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  9188. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  9189. original room was shut down.</li>
  9190. </ul>
  9191. <p>If not specified, the default value of <code>room_name</code> is &quot;Content Violation
  9192. Notification&quot;. The default value of <code>message</code> is &quot;Sharing illegal content on
  9193. othis server is not permitted and rooms in violation will be blocked.&quot;</p>
  9194. <h3 id="response-parameters"><a class="header" href="#response-parameters">Response Parameters</a></h3>
  9195. <ul>
  9196. <li><code>kicked_users</code> - An integer number representing the number of users that
  9197. were kicked.</li>
  9198. <li><code>failed_to_kick_users</code> - An integer number representing the number of users
  9199. that were not kicked.</li>
  9200. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  9201. the old room to the new.</li>
  9202. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  9203. </ul>
  9204. <h2 id="example-4"><a class="header" href="#example-4">Example</a></h2>
  9205. <p>Request:</p>
  9206. <pre><code>POST /_synapse/admin/v1/shutdown_room/!somebadroom%3Aexample.com
  9207. {
  9208. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  9209. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  9210. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;
  9211. }
  9212. </code></pre>
  9213. <p>Response:</p>
  9214. <pre><code>{
  9215. &quot;kicked_users&quot;: 5,
  9216. &quot;failed_to_kick_users&quot;: 0,
  9217. &quot;local_aliases&quot;: [&quot;#badroom:example.com&quot;, &quot;#evilsaloon:example.com],
  9218. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;,
  9219. },
  9220. </code></pre>
  9221. <h2 id="undoing-room-shutdowns-1"><a class="header" href="#undoing-room-shutdowns-1">Undoing room shutdowns</a></h2>
  9222. <p><em>Note</em>: This guide may be outdated by the time you read it. By nature of room shutdowns being performed at the database level,
  9223. the structure can and does change without notice.</p>
  9224. <p>First, it's important to understand that a room shutdown is very destructive. Undoing a shutdown is not as simple as pretending it
  9225. 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
  9226. to recover at all:</p>
  9227. <ul>
  9228. <li>If the room was invite-only, your users will need to be re-invited.</li>
  9229. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  9230. <li>The first user to rejoin will have to do so via an alias on a different server.</li>
  9231. </ul>
  9232. <p>With all that being said, if you still want to try and recover the room:</p>
  9233. <ol>
  9234. <li>For safety reasons, shut down Synapse.</li>
  9235. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  9236. <ul>
  9237. <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>
  9238. <li>The room ID is the same one supplied to the shutdown room API, not the Content Violation room.</li>
  9239. </ul>
  9240. </li>
  9241. <li>Restart Synapse.</li>
  9242. </ol>
  9243. <p>You will have to manually handle, if you so choose, the following:</p>
  9244. <ul>
  9245. <li>Aliases that would have been redirected to the Content Violation room.</li>
  9246. <li>Users that would have been booted from the room (and will have been force-joined to the Content Violation room).</li>
  9247. <li>Removal of the Content Violation room if desired.</li>
  9248. </ul>
  9249. <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>
  9250. <p>Returns information about all local media usage of users. Gives the
  9251. possibility to filter them by time and user.</p>
  9252. <p>The API is:</p>
  9253. <pre><code>GET /_synapse/admin/v1/statistics/users/media
  9254. </code></pre>
  9255. <p>To use it, you will need to authenticate by providing an <code>access_token</code>
  9256. for a server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9257. <p>A response body like the following is returned:</p>
  9258. <pre><code class="language-json">{
  9259. &quot;users&quot;: [
  9260. {
  9261. &quot;displayname&quot;: &quot;foo_user_0&quot;,
  9262. &quot;media_count&quot;: 2,
  9263. &quot;media_length&quot;: 134,
  9264. &quot;user_id&quot;: &quot;@foo_user_0:test&quot;
  9265. },
  9266. {
  9267. &quot;displayname&quot;: &quot;foo_user_1&quot;,
  9268. &quot;media_count&quot;: 2,
  9269. &quot;media_length&quot;: 134,
  9270. &quot;user_id&quot;: &quot;@foo_user_1:test&quot;
  9271. }
  9272. ],
  9273. &quot;next_token&quot;: 3,
  9274. &quot;total&quot;: 10
  9275. }
  9276. </code></pre>
  9277. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint
  9278. again with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9279. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9280. reports to paginate through.</p>
  9281. <p><strong>Parameters</strong></p>
  9282. <p>The following parameters should be set in the URL:</p>
  9283. <ul>
  9284. <li><code>limit</code>: string representing a positive integer - Is optional but is
  9285. used for pagination, denoting the maximum number of items to return
  9286. in this call. Defaults to <code>100</code>.</li>
  9287. <li><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9288. denoting the offset in the returned results. This should be treated as an opaque value
  9289. and not explicitly set to anything other than the return value of <code>next_token</code> from a
  9290. previous call. Defaults to <code>0</code>.</li>
  9291. <li><code>order_by</code> - string - The method in which to sort the returned list of users. Valid values are:
  9292. <ul>
  9293. <li><code>user_id</code> - Users are ordered alphabetically by <code>user_id</code>. This is the default.</li>
  9294. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9295. <li><code>media_length</code> - Users are ordered by the total size of uploaded media in bytes.
  9296. Smallest to largest.</li>
  9297. <li><code>media_count</code> - Users are ordered by number of uploaded media. Smallest to largest.</li>
  9298. </ul>
  9299. </li>
  9300. <li><code>from_ts</code> - string representing a positive integer - Considers only
  9301. files created at this timestamp or later. Unix timestamp in ms.</li>
  9302. <li><code>until_ts</code> - string representing a positive integer - Considers only
  9303. files created at this timestamp or earlier. Unix timestamp in ms.</li>
  9304. <li><code>search_term</code> - string - Filter users by their user ID localpart <strong>or</strong> displayname.
  9305. The search term can be found in any part of the string.
  9306. Defaults to no filtering.</li>
  9307. <li><code>dir</code> - string - Direction of order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9308. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  9309. </ul>
  9310. <p><strong>Response</strong></p>
  9311. <p>The following fields are returned in the JSON response body:</p>
  9312. <ul>
  9313. <li><code>users</code> - An array of objects, each containing information
  9314. about the user and their local media. Objects contain the following fields:
  9315. <ul>
  9316. <li><code>displayname</code> - string - Displayname of this user.</li>
  9317. <li><code>media_count</code> - integer - Number of uploaded media by this user.</li>
  9318. <li><code>media_length</code> - integer - Size of uploaded media in bytes by this user.</li>
  9319. <li><code>user_id</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9320. </ul>
  9321. </li>
  9322. <li><code>next_token</code> - integer - Opaque value used for pagination. See above.</li>
  9323. <li><code>total</code> - integer - Total number of users after filtering.</li>
  9324. </ul>
  9325. <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>
  9326. <h2 id="query-user-account"><a class="header" href="#query-user-account">Query User Account</a></h2>
  9327. <p>This API returns information about a specific user account.</p>
  9328. <p>The api is:</p>
  9329. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;
  9330. </code></pre>
  9331. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9332. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9333. <p>It returns a JSON body like the following:</p>
  9334. <pre><code class="language-json">{
  9335. &quot;displayname&quot;: &quot;User&quot;,
  9336. &quot;threepids&quot;: [
  9337. {
  9338. &quot;medium&quot;: &quot;email&quot;,
  9339. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9340. },
  9341. {
  9342. &quot;medium&quot;: &quot;email&quot;,
  9343. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9344. }
  9345. ],
  9346. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9347. &quot;admin&quot;: 0,
  9348. &quot;deactivated&quot;: 0,
  9349. &quot;shadow_banned&quot;: 0,
  9350. &quot;password_hash&quot;: &quot;$2b$12$p9B4GkqYdRTPGD&quot;,
  9351. &quot;creation_ts&quot;: 1560432506,
  9352. &quot;appservice_id&quot;: null,
  9353. &quot;consent_server_notice_sent&quot;: null,
  9354. &quot;consent_version&quot;: null,
  9355. &quot;external_ids&quot;: [
  9356. {
  9357. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9358. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9359. },
  9360. {
  9361. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9362. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9363. }
  9364. ]
  9365. }
  9366. </code></pre>
  9367. <p>URL parameters:</p>
  9368. <ul>
  9369. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9370. </ul>
  9371. <h2 id="create-or-modify-account"><a class="header" href="#create-or-modify-account">Create or modify Account</a></h2>
  9372. <p>This API allows an administrator to create or modify a user account with a
  9373. specific <code>user_id</code>.</p>
  9374. <p>This api is:</p>
  9375. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;
  9376. </code></pre>
  9377. <p>with a body of:</p>
  9378. <pre><code class="language-json">{
  9379. &quot;password&quot;: &quot;user_password&quot;,
  9380. &quot;displayname&quot;: &quot;User&quot;,
  9381. &quot;threepids&quot;: [
  9382. {
  9383. &quot;medium&quot;: &quot;email&quot;,
  9384. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9385. },
  9386. {
  9387. &quot;medium&quot;: &quot;email&quot;,
  9388. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9389. }
  9390. ],
  9391. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9392. &quot;admin&quot;: false,
  9393. &quot;deactivated&quot;: false
  9394. }
  9395. </code></pre>
  9396. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9397. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9398. <p>URL parameters:</p>
  9399. <ul>
  9400. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9401. </ul>
  9402. <p>Body parameters:</p>
  9403. <ul>
  9404. <li>
  9405. <p><code>password</code>, optional. If provided, the user's password is updated and all
  9406. devices are logged out.</p>
  9407. </li>
  9408. <li>
  9409. <p><code>displayname</code>, optional, defaults to the value of <code>user_id</code>.</p>
  9410. </li>
  9411. <li>
  9412. <p><code>threepids</code>, optional, allows setting the third-party IDs (email, msisdn)
  9413. belonging to a user.</p>
  9414. </li>
  9415. <li>
  9416. <p><code>avatar_url</code>, optional, must be a
  9417. <a href="https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris">MXC URI</a>.</p>
  9418. </li>
  9419. <li>
  9420. <p><code>admin</code>, optional, defaults to <code>false</code>.</p>
  9421. </li>
  9422. <li>
  9423. <p><code>deactivated</code>, optional. If unspecified, deactivation state will be left
  9424. unchanged on existing accounts and set to <code>false</code> for new accounts.
  9425. A user cannot be erased by deactivating with this API. For details on
  9426. deactivating users see <a href="admin_api/user_admin_api.html#deactivate-account">Deactivate Account</a>.</p>
  9427. </li>
  9428. </ul>
  9429. <p>If the user already exists then optional parameters default to the current value.</p>
  9430. <p>In order to re-activate an account <code>deactivated</code> must be set to <code>false</code>. If
  9431. users do not login via single-sign-on, a new <code>password</code> must be provided.</p>
  9432. <h2 id="list-accounts"><a class="header" href="#list-accounts">List Accounts</a></h2>
  9433. <p>This API returns all local user accounts.
  9434. By default, the response is ordered by ascending user ID.</p>
  9435. <pre><code>GET /_synapse/admin/v2/users?from=0&amp;limit=10&amp;guests=false
  9436. </code></pre>
  9437. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9438. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9439. <p>A response body like the following is returned:</p>
  9440. <pre><code class="language-json">{
  9441. &quot;users&quot;: [
  9442. {
  9443. &quot;name&quot;: &quot;&lt;user_id1&gt;&quot;,
  9444. &quot;is_guest&quot;: 0,
  9445. &quot;admin&quot;: 0,
  9446. &quot;user_type&quot;: null,
  9447. &quot;deactivated&quot;: 0,
  9448. &quot;shadow_banned&quot;: 0,
  9449. &quot;displayname&quot;: &quot;&lt;User One&gt;&quot;,
  9450. &quot;avatar_url&quot;: null
  9451. }, {
  9452. &quot;name&quot;: &quot;&lt;user_id2&gt;&quot;,
  9453. &quot;is_guest&quot;: 0,
  9454. &quot;admin&quot;: 1,
  9455. &quot;user_type&quot;: null,
  9456. &quot;deactivated&quot;: 0,
  9457. &quot;shadow_banned&quot;: 0,
  9458. &quot;displayname&quot;: &quot;&lt;User Two&gt;&quot;,
  9459. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;
  9460. }
  9461. ],
  9462. &quot;next_token&quot;: &quot;100&quot;,
  9463. &quot;total&quot;: 200
  9464. }
  9465. </code></pre>
  9466. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9467. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9468. <p>If the endpoint does not return a <code>next_token</code> then there are no more users
  9469. to paginate through.</p>
  9470. <p><strong>Parameters</strong></p>
  9471. <p>The following parameters should be set in the URL:</p>
  9472. <ul>
  9473. <li>
  9474. <p><code>user_id</code> - Is optional and filters to only return users with user IDs
  9475. that contain this value. This parameter is ignored when using the <code>name</code> parameter.</p>
  9476. </li>
  9477. <li>
  9478. <p><code>name</code> - Is optional and filters to only return users with user ID localparts
  9479. <strong>or</strong> displaynames that contain this value.</p>
  9480. </li>
  9481. <li>
  9482. <p><code>guests</code> - string representing a bool - Is optional and if <code>false</code> will <strong>exclude</strong> guest users.
  9483. Defaults to <code>true</code> to include guest users.</p>
  9484. </li>
  9485. <li>
  9486. <p><code>deactivated</code> - string representing a bool - Is optional and if <code>true</code> will <strong>include</strong> deactivated users.
  9487. Defaults to <code>false</code> to exclude deactivated users.</p>
  9488. </li>
  9489. <li>
  9490. <p><code>limit</code> - string representing a positive integer - Is optional but is used for pagination,
  9491. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9492. </li>
  9493. <li>
  9494. <p><code>from</code> - string representing a positive integer - Is optional but used for pagination,
  9495. denoting the offset in the returned results. This should be treated as an opaque value and
  9496. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9497. Defaults to <code>0</code>.</p>
  9498. </li>
  9499. <li>
  9500. <p><code>order_by</code> - The method by which to sort the returned list of users.
  9501. If the ordered field has duplicates, the second order is always by ascending <code>name</code>,
  9502. which guarantees a stable ordering. Valid values are:</p>
  9503. <ul>
  9504. <li><code>name</code> - Users are ordered alphabetically by <code>name</code>. This is the default.</li>
  9505. <li><code>is_guest</code> - Users are ordered by <code>is_guest</code> status.</li>
  9506. <li><code>admin</code> - Users are ordered by <code>admin</code> status.</li>
  9507. <li><code>user_type</code> - Users are ordered alphabetically by <code>user_type</code>.</li>
  9508. <li><code>deactivated</code> - Users are ordered by <code>deactivated</code> status.</li>
  9509. <li><code>shadow_banned</code> - Users are ordered by <code>shadow_banned</code> status.</li>
  9510. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9511. <li><code>avatar_url</code> - Users are ordered alphabetically by avatar URL.</li>
  9512. </ul>
  9513. </li>
  9514. <li>
  9515. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9516. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  9517. </li>
  9518. </ul>
  9519. <p>Caution. The database only has indexes on the columns <code>name</code> and <code>created_ts</code>.
  9520. This means that if a different sort order is used (<code>is_guest</code>, <code>admin</code>,
  9521. <code>user_type</code>, <code>deactivated</code>, <code>shadow_banned</code>, <code>avatar_url</code> or <code>displayname</code>),
  9522. this can cause a large load on the database, especially for large environments.</p>
  9523. <p><strong>Response</strong></p>
  9524. <p>The following fields are returned in the JSON response body:</p>
  9525. <ul>
  9526. <li>
  9527. <p><code>users</code> - An array of objects, each containing information about an user.
  9528. User objects contain the following fields:</p>
  9529. <ul>
  9530. <li><code>name</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9531. <li><code>is_guest</code> - bool - Status if that user is a guest account.</li>
  9532. <li><code>admin</code> - bool - Status if that user is a server administrator.</li>
  9533. <li><code>user_type</code> - string - Type of the user. Normal users are type <code>None</code>.
  9534. This allows user type specific behaviour. There are also types <code>support</code> and <code>bot</code>. </li>
  9535. <li><code>deactivated</code> - bool - Status if that user has been marked as deactivated.</li>
  9536. <li><code>shadow_banned</code> - bool - Status if that user has been marked as shadow banned.</li>
  9537. <li><code>displayname</code> - string - The user's display name if they have set one.</li>
  9538. <li><code>avatar_url</code> - string - The user's avatar URL if they have set one.</li>
  9539. </ul>
  9540. </li>
  9541. <li>
  9542. <p><code>next_token</code>: string representing a positive integer - Indication for pagination. See above.</p>
  9543. </li>
  9544. <li>
  9545. <p><code>total</code> - integer - Total number of media.</p>
  9546. </li>
  9547. </ul>
  9548. <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>
  9549. <p>This API returns information about the active sessions for a specific user.</p>
  9550. <p>The endpoints are:</p>
  9551. <pre><code>GET /_synapse/admin/v1/whois/&lt;user_id&gt;
  9552. </code></pre>
  9553. <p>and:</p>
  9554. <pre><code>GET /_matrix/client/r0/admin/whois/&lt;userId&gt;
  9555. </code></pre>
  9556. <p>See also: <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid">Client Server
  9557. API Whois</a>.</p>
  9558. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9559. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9560. <p>It returns a JSON body like the following:</p>
  9561. <pre><code class="language-json">{
  9562. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;,
  9563. &quot;devices&quot;: {
  9564. &quot;&quot;: {
  9565. &quot;sessions&quot;: [
  9566. {
  9567. &quot;connections&quot;: [
  9568. {
  9569. &quot;ip&quot;: &quot;1.2.3.4&quot;,
  9570. &quot;last_seen&quot;: 1417222374433,
  9571. &quot;user_agent&quot;: &quot;Mozilla/5.0 ...&quot;
  9572. },
  9573. {
  9574. &quot;ip&quot;: &quot;1.2.3.10&quot;,
  9575. &quot;last_seen&quot;: 1417222374500,
  9576. &quot;user_agent&quot;: &quot;Dalvik/2.1.0 ...&quot;
  9577. }
  9578. ]
  9579. }
  9580. ]
  9581. }
  9582. }
  9583. }
  9584. </code></pre>
  9585. <p><code>last_seen</code> is measured in milliseconds since the Unix epoch.</p>
  9586. <h2 id="deactivate-account"><a class="header" href="#deactivate-account">Deactivate Account</a></h2>
  9587. <p>This API deactivates an account. It removes active access tokens, resets the
  9588. password, and deletes third-party IDs (to prevent the user requesting a
  9589. password reset).</p>
  9590. <p>It can also mark the user as GDPR-erased. This means messages sent by the
  9591. user will still be visible by anyone that was in the room when these messages
  9592. were sent, but hidden from users joining the room afterwards.</p>
  9593. <p>The api is:</p>
  9594. <pre><code>POST /_synapse/admin/v1/deactivate/&lt;user_id&gt;
  9595. </code></pre>
  9596. <p>with a body of:</p>
  9597. <pre><code class="language-json">{
  9598. &quot;erase&quot;: true
  9599. }
  9600. </code></pre>
  9601. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9602. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9603. <p>The erase parameter is optional and defaults to <code>false</code>.
  9604. An empty body may be passed for backwards compatibility.</p>
  9605. <p>The following actions are performed when deactivating an user:</p>
  9606. <ul>
  9607. <li>Try to unpind 3PIDs from the identity server</li>
  9608. <li>Remove all 3PIDs from the homeserver</li>
  9609. <li>Delete all devices and E2EE keys</li>
  9610. <li>Delete all access tokens</li>
  9611. <li>Delete the password hash</li>
  9612. <li>Removal from all rooms the user is a member of</li>
  9613. <li>Remove the user from the user directory</li>
  9614. <li>Reject all pending invites</li>
  9615. <li>Remove all account validity information related to the user</li>
  9616. </ul>
  9617. <p>The following additional actions are performed during deactivation if <code>erase</code>
  9618. is set to <code>true</code>:</p>
  9619. <ul>
  9620. <li>Remove the user's display name</li>
  9621. <li>Remove the user's avatar URL</li>
  9622. <li>Mark the user as erased</li>
  9623. </ul>
  9624. <h2 id="reset-password"><a class="header" href="#reset-password">Reset password</a></h2>
  9625. <p>Changes the password of another user. This will automatically log the user out of all their devices.</p>
  9626. <p>The api is:</p>
  9627. <pre><code>POST /_synapse/admin/v1/reset_password/&lt;user_id&gt;
  9628. </code></pre>
  9629. <p>with a body of:</p>
  9630. <pre><code class="language-json">{
  9631. &quot;new_password&quot;: &quot;&lt;secret&gt;&quot;,
  9632. &quot;logout_devices&quot;: true
  9633. }
  9634. </code></pre>
  9635. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9636. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9637. <p>The parameter <code>new_password</code> is required.
  9638. The parameter <code>logout_devices</code> is optional and defaults to <code>true</code>.</p>
  9639. <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>
  9640. <p>The api is:</p>
  9641. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  9642. </code></pre>
  9643. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9644. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9645. <p>A response body like the following is returned:</p>
  9646. <pre><code class="language-json">{
  9647. &quot;admin&quot;: true
  9648. }
  9649. </code></pre>
  9650. <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>
  9651. <p>Note that you cannot demote yourself.</p>
  9652. <p>The api is:</p>
  9653. <pre><code>PUT /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  9654. </code></pre>
  9655. <p>with a body of:</p>
  9656. <pre><code class="language-json">{
  9657. &quot;admin&quot;: true
  9658. }
  9659. </code></pre>
  9660. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9661. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9662. <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>
  9663. <p>Gets a list of all <code>room_id</code> that a specific <code>user_id</code> is member.</p>
  9664. <p>The API is:</p>
  9665. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/joined_rooms
  9666. </code></pre>
  9667. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9668. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9669. <p>A response body like the following is returned:</p>
  9670. <pre><code class="language-json"> {
  9671. &quot;joined_rooms&quot;: [
  9672. &quot;!DuGcnbhHGaSZQoNQR:matrix.org&quot;,
  9673. &quot;!ZtSaPCawyWtxfWiIy:matrix.org&quot;
  9674. ],
  9675. &quot;total&quot;: 2
  9676. }
  9677. </code></pre>
  9678. <p>The server returns the list of rooms of which the user and the server
  9679. are member. If the user is local, all the rooms of which the user is
  9680. member are returned.</p>
  9681. <p><strong>Parameters</strong></p>
  9682. <p>The following parameters should be set in the URL:</p>
  9683. <ul>
  9684. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9685. </ul>
  9686. <p><strong>Response</strong></p>
  9687. <p>The following fields are returned in the JSON response body:</p>
  9688. <ul>
  9689. <li><code>joined_rooms</code> - An array of <code>room_id</code>.</li>
  9690. <li><code>total</code> - Number of rooms.</li>
  9691. </ul>
  9692. <h2 id="list-media-of-a-user"><a class="header" href="#list-media-of-a-user">List media of a user</a></h2>
  9693. <p>Gets a list of all local media that a specific <code>user_id</code> has created.
  9694. By default, the response is ordered by descending creation date and ascending media ID.
  9695. The newest media is on top. You can change the order with parameters
  9696. <code>order_by</code> and <code>dir</code>.</p>
  9697. <p>The API is:</p>
  9698. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/media
  9699. </code></pre>
  9700. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9701. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9702. <p>A response body like the following is returned:</p>
  9703. <pre><code class="language-json">{
  9704. &quot;media&quot;: [
  9705. {
  9706. &quot;created_ts&quot;: 100400,
  9707. &quot;last_access_ts&quot;: null,
  9708. &quot;media_id&quot;: &quot;qXhyRzulkwLsNHTbpHreuEgo&quot;,
  9709. &quot;media_length&quot;: 67,
  9710. &quot;media_type&quot;: &quot;image/png&quot;,
  9711. &quot;quarantined_by&quot;: null,
  9712. &quot;safe_from_quarantine&quot;: false,
  9713. &quot;upload_name&quot;: &quot;test1.png&quot;
  9714. },
  9715. {
  9716. &quot;created_ts&quot;: 200400,
  9717. &quot;last_access_ts&quot;: null,
  9718. &quot;media_id&quot;: &quot;FHfiSnzoINDatrXHQIXBtahw&quot;,
  9719. &quot;media_length&quot;: 67,
  9720. &quot;media_type&quot;: &quot;image/png&quot;,
  9721. &quot;quarantined_by&quot;: null,
  9722. &quot;safe_from_quarantine&quot;: false,
  9723. &quot;upload_name&quot;: &quot;test2.png&quot;
  9724. }
  9725. ],
  9726. &quot;next_token&quot;: 3,
  9727. &quot;total&quot;: 2
  9728. }
  9729. </code></pre>
  9730. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9731. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9732. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9733. reports to paginate through.</p>
  9734. <p><strong>Parameters</strong></p>
  9735. <p>The following parameters should be set in the URL:</p>
  9736. <ul>
  9737. <li>
  9738. <p><code>user_id</code> - string - fully qualified: for example, <code>@user:server.com</code>.</p>
  9739. </li>
  9740. <li>
  9741. <p><code>limit</code>: string representing a positive integer - Is optional but is used for pagination,
  9742. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9743. </li>
  9744. <li>
  9745. <p><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9746. denoting the offset in the returned results. This should be treated as an opaque value and
  9747. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9748. Defaults to <code>0</code>.</p>
  9749. </li>
  9750. <li>
  9751. <p><code>order_by</code> - The method by which to sort the returned list of media.
  9752. If the ordered field has duplicates, the second order is always by ascending <code>media_id</code>,
  9753. which guarantees a stable ordering. Valid values are:</p>
  9754. <ul>
  9755. <li><code>media_id</code> - Media are ordered alphabetically by <code>media_id</code>.</li>
  9756. <li><code>upload_name</code> - Media are ordered alphabetically by name the media was uploaded with.</li>
  9757. <li><code>created_ts</code> - Media are ordered by when the content was uploaded in ms.
  9758. Smallest to largest. This is the default.</li>
  9759. <li><code>last_access_ts</code> - Media are ordered by when the content was last accessed in ms.
  9760. Smallest to largest.</li>
  9761. <li><code>media_length</code> - Media are ordered by length of the media in bytes.
  9762. Smallest to largest.</li>
  9763. <li><code>media_type</code> - Media are ordered alphabetically by MIME-type.</li>
  9764. <li><code>quarantined_by</code> - Media are ordered alphabetically by the user ID that
  9765. initiated the quarantine request for this media.</li>
  9766. <li><code>safe_from_quarantine</code> - Media are ordered by the status if this media is safe
  9767. from quarantining.</li>
  9768. </ul>
  9769. </li>
  9770. <li>
  9771. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9772. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  9773. </li>
  9774. </ul>
  9775. <p>If neither <code>order_by</code> nor <code>dir</code> is set, the default order is newest media on top
  9776. (corresponds to <code>order_by</code> = <code>created_ts</code> and <code>dir</code> = <code>b</code>).</p>
  9777. <p>Caution. The database only has indexes on the columns <code>media_id</code>,
  9778. <code>user_id</code> and <code>created_ts</code>. This means that if a different sort order is used
  9779. (<code>upload_name</code>, <code>last_access_ts</code>, <code>media_length</code>, <code>media_type</code>,
  9780. <code>quarantined_by</code> or <code>safe_from_quarantine</code>), this can cause a large load on the
  9781. database, especially for large environments.</p>
  9782. <p><strong>Response</strong></p>
  9783. <p>The following fields are returned in the JSON response body:</p>
  9784. <ul>
  9785. <li>
  9786. <p><code>media</code> - An array of objects, each containing information about a media.
  9787. Media objects contain the following fields:</p>
  9788. <ul>
  9789. <li>
  9790. <p><code>created_ts</code> - integer - Timestamp when the content was uploaded in ms.</p>
  9791. </li>
  9792. <li>
  9793. <p><code>last_access_ts</code> - integer - Timestamp when the content was last accessed in ms.</p>
  9794. </li>
  9795. <li>
  9796. <p><code>media_id</code> - string - The id used to refer to the media.</p>
  9797. </li>
  9798. <li>
  9799. <p><code>media_length</code> - integer - Length of the media in bytes.</p>
  9800. </li>
  9801. <li>
  9802. <p><code>media_type</code> - string - The MIME-type of the media.</p>
  9803. </li>
  9804. <li>
  9805. <p><code>quarantined_by</code> - string - The user ID that initiated the quarantine request
  9806. for this media.</p>
  9807. </li>
  9808. <li>
  9809. <p><code>safe_from_quarantine</code> - bool - Status if this media is safe from quarantining.</p>
  9810. </li>
  9811. <li>
  9812. <p><code>upload_name</code> - string - The name the media was uploaded with.</p>
  9813. </li>
  9814. </ul>
  9815. </li>
  9816. <li>
  9817. <p><code>next_token</code>: integer - Indication for pagination. See above.</p>
  9818. </li>
  9819. <li>
  9820. <p><code>total</code> - integer - Total number of media.</p>
  9821. </li>
  9822. </ul>
  9823. <h2 id="login-as-a-user"><a class="header" href="#login-as-a-user">Login as a user</a></h2>
  9824. <p>Get an access token that can be used to authenticate as that user. Useful for
  9825. when admins wish to do actions on behalf of a user.</p>
  9826. <p>The API is:</p>
  9827. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/login
  9828. {}
  9829. </code></pre>
  9830. <p>An optional <code>valid_until_ms</code> field can be specified in the request body as an
  9831. integer timestamp that specifies when the token should expire. By default tokens
  9832. do not expire.</p>
  9833. <p>A response body like the following is returned:</p>
  9834. <pre><code class="language-json">{
  9835. &quot;access_token&quot;: &quot;&lt;opaque_access_token_string&gt;&quot;
  9836. }
  9837. </code></pre>
  9838. <p>This API does <em>not</em> generate a new device for the user, and so will not appear
  9839. their <code>/devices</code> list, and in general the target user should not be able to
  9840. tell they have been logged in as.</p>
  9841. <p>To expire the token call the standard <code>/logout</code> API with the token.</p>
  9842. <p>Note: The token will expire if the <em>admin</em> user calls <code>/logout/all</code> from any
  9843. of their devices, but the token will <em>not</em> expire if the target user does the
  9844. same.</p>
  9845. <h2 id="user-devices"><a class="header" href="#user-devices">User devices</a></h2>
  9846. <h3 id="list-all-devices"><a class="header" href="#list-all-devices">List all devices</a></h3>
  9847. <p>Gets information about all devices for a specific <code>user_id</code>.</p>
  9848. <p>The API is:</p>
  9849. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices
  9850. </code></pre>
  9851. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9852. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9853. <p>A response body like the following is returned:</p>
  9854. <pre><code class="language-json">{
  9855. &quot;devices&quot;: [
  9856. {
  9857. &quot;device_id&quot;: &quot;QBUAZIFURK&quot;,
  9858. &quot;display_name&quot;: &quot;android&quot;,
  9859. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  9860. &quot;last_seen_ts&quot;: 1474491775024,
  9861. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  9862. },
  9863. {
  9864. &quot;device_id&quot;: &quot;AUIECTSRND&quot;,
  9865. &quot;display_name&quot;: &quot;ios&quot;,
  9866. &quot;last_seen_ip&quot;: &quot;1.2.3.5&quot;,
  9867. &quot;last_seen_ts&quot;: 1474491775025,
  9868. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  9869. }
  9870. ],
  9871. &quot;total&quot;: 2
  9872. }
  9873. </code></pre>
  9874. <p><strong>Parameters</strong></p>
  9875. <p>The following parameters should be set in the URL:</p>
  9876. <ul>
  9877. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9878. </ul>
  9879. <p><strong>Response</strong></p>
  9880. <p>The following fields are returned in the JSON response body:</p>
  9881. <ul>
  9882. <li>
  9883. <p><code>devices</code> - An array of objects, each containing information about a device.
  9884. Device objects contain the following fields:</p>
  9885. <ul>
  9886. <li><code>device_id</code> - Identifier of device.</li>
  9887. <li><code>display_name</code> - Display name set by the user for this device.
  9888. Absent if no name has been set.</li>
  9889. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  9890. (May be a few minutes out of date, for efficiency reasons).</li>
  9891. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  9892. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  9893. <li><code>user_id</code> - Owner of device.</li>
  9894. </ul>
  9895. </li>
  9896. <li>
  9897. <p><code>total</code> - Total number of user's devices.</p>
  9898. </li>
  9899. </ul>
  9900. <h3 id="delete-multiple-devices"><a class="header" href="#delete-multiple-devices">Delete multiple devices</a></h3>
  9901. <p>Deletes the given devices for a specific <code>user_id</code>, and invalidates
  9902. any access token associated with them.</p>
  9903. <p>The API is:</p>
  9904. <pre><code>POST /_synapse/admin/v2/users/&lt;user_id&gt;/delete_devices
  9905. {
  9906. &quot;devices&quot;: [
  9907. &quot;QBUAZIFURK&quot;,
  9908. &quot;AUIECTSRND&quot;
  9909. ],
  9910. }
  9911. </code></pre>
  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>An empty JSON dict is returned.</p>
  9915. <p><strong>Parameters</strong></p>
  9916. <p>The following parameters should be set in the URL:</p>
  9917. <ul>
  9918. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9919. </ul>
  9920. <p>The following fields are required in the JSON request body:</p>
  9921. <ul>
  9922. <li><code>devices</code> - The list of device IDs to delete.</li>
  9923. </ul>
  9924. <h3 id="show-a-device"><a class="header" href="#show-a-device">Show a device</a></h3>
  9925. <p>Gets information on a single device, by <code>device_id</code> for a specific <code>user_id</code>.</p>
  9926. <p>The API is:</p>
  9927. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  9928. </code></pre>
  9929. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9930. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9931. <p>A response body like the following is returned:</p>
  9932. <pre><code class="language-json">{
  9933. &quot;device_id&quot;: &quot;&lt;device_id&gt;&quot;,
  9934. &quot;display_name&quot;: &quot;android&quot;,
  9935. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  9936. &quot;last_seen_ts&quot;: 1474491775024,
  9937. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  9938. }
  9939. </code></pre>
  9940. <p><strong>Parameters</strong></p>
  9941. <p>The following parameters should be set in the URL:</p>
  9942. <ul>
  9943. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9944. <li><code>device_id</code> - The device to retrieve.</li>
  9945. </ul>
  9946. <p><strong>Response</strong></p>
  9947. <p>The following fields are returned in the JSON response body:</p>
  9948. <ul>
  9949. <li><code>device_id</code> - Identifier of device.</li>
  9950. <li><code>display_name</code> - Display name set by the user for this device.
  9951. Absent if no name has been set.</li>
  9952. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  9953. (May be a few minutes out of date, for efficiency reasons).</li>
  9954. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  9955. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  9956. <li><code>user_id</code> - Owner of device.</li>
  9957. </ul>
  9958. <h3 id="update-a-device"><a class="header" href="#update-a-device">Update a device</a></h3>
  9959. <p>Updates the metadata on the given <code>device_id</code> for a specific <code>user_id</code>.</p>
  9960. <p>The API is:</p>
  9961. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  9962. {
  9963. &quot;display_name&quot;: &quot;My other phone&quot;
  9964. }
  9965. </code></pre>
  9966. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9967. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9968. <p>An empty JSON dict is returned.</p>
  9969. <p><strong>Parameters</strong></p>
  9970. <p>The following parameters should be set in the URL:</p>
  9971. <ul>
  9972. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9973. <li><code>device_id</code> - The device to update.</li>
  9974. </ul>
  9975. <p>The following fields are required in the JSON request body:</p>
  9976. <ul>
  9977. <li><code>display_name</code> - The new display name for this device. If not given,
  9978. the display name is unchanged.</li>
  9979. </ul>
  9980. <h3 id="delete-a-device"><a class="header" href="#delete-a-device">Delete a device</a></h3>
  9981. <p>Deletes the given <code>device_id</code> for a specific <code>user_id</code>,
  9982. and invalidates any access token associated with it.</p>
  9983. <p>The API is:</p>
  9984. <pre><code>DELETE /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  9985. {}
  9986. </code></pre>
  9987. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9988. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9989. <p>An empty JSON dict is returned.</p>
  9990. <p><strong>Parameters</strong></p>
  9991. <p>The following parameters should be set in the URL:</p>
  9992. <ul>
  9993. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9994. <li><code>device_id</code> - The device to delete.</li>
  9995. </ul>
  9996. <h2 id="list-all-pushers"><a class="header" href="#list-all-pushers">List all pushers</a></h2>
  9997. <p>Gets information about all pushers for a specific <code>user_id</code>.</p>
  9998. <p>The API is:</p>
  9999. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/pushers
  10000. </code></pre>
  10001. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10002. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10003. <p>A response body like the following is returned:</p>
  10004. <pre><code class="language-json">{
  10005. &quot;pushers&quot;: [
  10006. {
  10007. &quot;app_display_name&quot;:&quot;HTTP Push Notifications&quot;,
  10008. &quot;app_id&quot;:&quot;m.http&quot;,
  10009. &quot;data&quot;: {
  10010. &quot;url&quot;:&quot;example.com&quot;
  10011. },
  10012. &quot;device_display_name&quot;:&quot;pushy push&quot;,
  10013. &quot;kind&quot;:&quot;http&quot;,
  10014. &quot;lang&quot;:&quot;None&quot;,
  10015. &quot;profile_tag&quot;:&quot;&quot;,
  10016. &quot;pushkey&quot;:&quot;a@example.com&quot;
  10017. }
  10018. ],
  10019. &quot;total&quot;: 1
  10020. }
  10021. </code></pre>
  10022. <p><strong>Parameters</strong></p>
  10023. <p>The following parameters should be set in the URL:</p>
  10024. <ul>
  10025. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10026. </ul>
  10027. <p><strong>Response</strong></p>
  10028. <p>The following fields are returned in the JSON response body:</p>
  10029. <ul>
  10030. <li>
  10031. <p><code>pushers</code> - An array containing the current pushers for the user</p>
  10032. <ul>
  10033. <li>
  10034. <p><code>app_display_name</code> - string - A string that will allow the user to identify
  10035. what application owns this pusher.</p>
  10036. </li>
  10037. <li>
  10038. <p><code>app_id</code> - string - This is a reverse-DNS style identifier for the application.
  10039. Max length, 64 chars.</p>
  10040. </li>
  10041. <li>
  10042. <p><code>data</code> - A dictionary of information for the pusher implementation itself.</p>
  10043. <ul>
  10044. <li>
  10045. <p><code>url</code> - string - Required if <code>kind</code> is <code>http</code>. The URL to use to send
  10046. notifications to.</p>
  10047. </li>
  10048. <li>
  10049. <p><code>format</code> - string - The format to use when sending notifications to the
  10050. Push Gateway.</p>
  10051. </li>
  10052. </ul>
  10053. </li>
  10054. <li>
  10055. <p><code>device_display_name</code> - string - A string that will allow the user to identify
  10056. what device owns this pusher.</p>
  10057. </li>
  10058. <li>
  10059. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10060. this pusher executes.</p>
  10061. </li>
  10062. <li>
  10063. <p><code>kind</code> - string - The kind of pusher. &quot;http&quot; is a pusher that sends HTTP pokes.</p>
  10064. </li>
  10065. <li>
  10066. <p><code>lang</code> - string - The preferred language for receiving notifications
  10067. (e.g. 'en' or 'en-US')</p>
  10068. </li>
  10069. <li>
  10070. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10071. this pusher executes.</p>
  10072. </li>
  10073. <li>
  10074. <p><code>pushkey</code> - string - This is a unique identifier for this pusher.
  10075. Max length, 512 bytes.</p>
  10076. </li>
  10077. </ul>
  10078. </li>
  10079. <li>
  10080. <p><code>total</code> - integer - Number of pushers.</p>
  10081. </li>
  10082. </ul>
  10083. <p>See also the
  10084. <a href="https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers">Client-Server API Spec on pushers</a>.</p>
  10085. <h2 id="shadow-banning-users"><a class="header" href="#shadow-banning-users">Shadow-banning users</a></h2>
  10086. <p>Shadow-banning is a useful tool for moderating malicious or egregiously abusive users.
  10087. A shadow-banned users receives successful responses to their client-server API requests,
  10088. but the events are not propagated into rooms. This can be an effective tool as it
  10089. (hopefully) takes longer for the user to realise they are being moderated before
  10090. pivoting to another account.</p>
  10091. <p>Shadow-banning a user should be used as a tool of last resort and may lead to confusing
  10092. or broken behaviour for the client. A shadow-banned user will not receive any
  10093. notification and it is generally more appropriate to ban or kick abusive users.
  10094. A shadow-banned user will be unable to contact anyone on the server.</p>
  10095. <p>The API is:</p>
  10096. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/shadow_ban
  10097. </code></pre>
  10098. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10099. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10100. <p>An empty JSON dict is returned.</p>
  10101. <p><strong>Parameters</strong></p>
  10102. <p>The following parameters should be set in the URL:</p>
  10103. <ul>
  10104. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10105. be local.</li>
  10106. </ul>
  10107. <h2 id="override-ratelimiting-for-users"><a class="header" href="#override-ratelimiting-for-users">Override ratelimiting for users</a></h2>
  10108. <p>This API allows to override or disable ratelimiting for a specific user.
  10109. There are specific APIs to set, get and delete a ratelimit.</p>
  10110. <h3 id="get-status-of-ratelimit"><a class="header" href="#get-status-of-ratelimit">Get status of ratelimit</a></h3>
  10111. <p>The API is:</p>
  10112. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10113. </code></pre>
  10114. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10115. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10116. <p>A response body like the following is returned:</p>
  10117. <pre><code class="language-json">{
  10118. &quot;messages_per_second&quot;: 0,
  10119. &quot;burst_count&quot;: 0
  10120. }
  10121. </code></pre>
  10122. <p><strong>Parameters</strong></p>
  10123. <p>The following parameters should be set in the URL:</p>
  10124. <ul>
  10125. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10126. be local.</li>
  10127. </ul>
  10128. <p><strong>Response</strong></p>
  10129. <p>The following fields are returned in the JSON response body:</p>
  10130. <ul>
  10131. <li><code>messages_per_second</code> - integer - The number of actions that can
  10132. be performed in a second. <code>0</code> mean that ratelimiting is disabled for this user.</li>
  10133. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10134. being limited.</li>
  10135. </ul>
  10136. <p>If <strong>no</strong> custom ratelimit is set, an empty JSON dict is returned.</p>
  10137. <pre><code class="language-json">{}
  10138. </code></pre>
  10139. <h3 id="set-ratelimit"><a class="header" href="#set-ratelimit">Set ratelimit</a></h3>
  10140. <p>The API is:</p>
  10141. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10142. </code></pre>
  10143. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10144. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10145. <p>A response body like the following is returned:</p>
  10146. <pre><code class="language-json">{
  10147. &quot;messages_per_second&quot;: 0,
  10148. &quot;burst_count&quot;: 0
  10149. }
  10150. </code></pre>
  10151. <p><strong>Parameters</strong></p>
  10152. <p>The following parameters should be set in the URL:</p>
  10153. <ul>
  10154. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10155. be local.</li>
  10156. </ul>
  10157. <p>Body parameters:</p>
  10158. <ul>
  10159. <li><code>messages_per_second</code> - positive integer, optional. The number of actions that can
  10160. be performed in a second. Defaults to <code>0</code>.</li>
  10161. <li><code>burst_count</code> - positive integer, optional. How many actions that can be performed
  10162. before being limited. Defaults to <code>0</code>.</li>
  10163. </ul>
  10164. <p>To disable users' ratelimit set both values to <code>0</code>.</p>
  10165. <p><strong>Response</strong></p>
  10166. <p>The following fields are returned in the JSON response body:</p>
  10167. <ul>
  10168. <li><code>messages_per_second</code> - integer - The number of actions that can
  10169. be performed in a second.</li>
  10170. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10171. being limited.</li>
  10172. </ul>
  10173. <h3 id="delete-ratelimit"><a class="header" href="#delete-ratelimit">Delete ratelimit</a></h3>
  10174. <p>The API is:</p>
  10175. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10176. </code></pre>
  10177. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10178. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10179. <p>An empty JSON dict is returned.</p>
  10180. <pre><code class="language-json">{}
  10181. </code></pre>
  10182. <p><strong>Parameters</strong></p>
  10183. <p>The following parameters should be set in the URL:</p>
  10184. <ul>
  10185. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10186. be local.</li>
  10187. </ul>
  10188. <div style="break-before: page; page-break-before: always;"></div><h1 id="version-api"><a class="header" href="#version-api">Version API</a></h1>
  10189. <p>This API returns the running Synapse version and the Python version
  10190. on which Synapse is being run. This is useful when a Synapse instance
  10191. is behind a proxy that does not forward the 'Server' header (which also
  10192. contains Synapse version information).</p>
  10193. <p>The api is:</p>
  10194. <pre><code>GET /_synapse/admin/v1/server_version
  10195. </code></pre>
  10196. <p>It returns a JSON body like the following:</p>
  10197. <pre><code class="language-json">{
  10198. &quot;server_version&quot;: &quot;0.99.2rc1 (b=develop, abcdef123)&quot;,
  10199. &quot;python_version&quot;: &quot;3.6.8&quot;
  10200. }
  10201. </code></pre>
  10202. <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>
  10203. <p>The &quot;manhole&quot; allows server administrators to access a Python shell on a running
  10204. Synapse installation. This is a very powerful mechanism for administration and
  10205. debugging.</p>
  10206. <p><strong><em>Security Warning</em></strong></p>
  10207. <p>Note that this will give administrative access to synapse to <strong>all users</strong> with
  10208. shell access to the server. It should therefore <strong>not</strong> be enabled in
  10209. environments where untrusted users have shell access.</p>
  10210. <hr />
  10211. <p>To enable it, first uncomment the <code>manhole</code> listener configuration in
  10212. <code>homeserver.yaml</code>. The configuration is slightly different if you're using docker.</p>
  10213. <h4 id="docker-config"><a class="header" href="#docker-config">Docker config</a></h4>
  10214. <p>If you are using Docker, set <code>bind_addresses</code> to <code>['0.0.0.0']</code> as shown:</p>
  10215. <pre><code class="language-yaml">listeners:
  10216. - port: 9000
  10217. bind_addresses: ['0.0.0.0']
  10218. type: manhole
  10219. </code></pre>
  10220. <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
  10221. <code>manhole</code> port forwarding. The <code>-p 127.0.0.1:9000:9000</code> below is important: it
  10222. ensures that access to the <code>manhole</code> is only possible for local users.</p>
  10223. <pre><code class="language-bash">docker run -d --name synapse \
  10224. --mount type=volume,src=synapse-data,dst=/data \
  10225. -p 8008:8008 \
  10226. -p 127.0.0.1:9000:9000 \
  10227. matrixdotorg/synapse:latest
  10228. </code></pre>
  10229. <h4 id="native-config"><a class="header" href="#native-config">Native config</a></h4>
  10230. <p>If you are not using docker, set <code>bind_addresses</code> to <code>['::1', '127.0.0.1']</code> as shown.
  10231. The <code>bind_addresses</code> in the example below is important: it ensures that access to the
  10232. <code>manhole</code> is only possible for local users).</p>
  10233. <pre><code class="language-yaml">listeners:
  10234. - port: 9000
  10235. bind_addresses: ['::1', '127.0.0.1']
  10236. type: manhole
  10237. </code></pre>
  10238. <h4 id="accessing-synapse-manhole"><a class="header" href="#accessing-synapse-manhole">Accessing synapse manhole</a></h4>
  10239. <p>Then restart synapse, and point an ssh client at port 9000 on localhost, using
  10240. the username <code>matrix</code>:</p>
  10241. <pre><code class="language-bash">ssh -p9000 matrix@localhost
  10242. </code></pre>
  10243. <p>The password is <code>rabbithole</code>.</p>
  10244. <p>This gives a Python REPL in which <code>hs</code> gives access to the
  10245. <code>synapse.server.HomeServer</code> object - which in turn gives access to many other
  10246. parts of the process.</p>
  10247. <p>Note that any call which returns a coroutine will need to be wrapped in <code>ensureDeferred</code>.</p>
  10248. <p>As a simple example, retrieving an event from the database:</p>
  10249. <pre><code class="language-pycon">&gt;&gt;&gt; from twisted.internet import defer
  10250. &gt;&gt;&gt; defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
  10251. &lt;Deferred at 0x7ff253fc6998 current result: &lt;FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''&gt;&gt;
  10252. </code></pre>
  10253. <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>
  10254. <ol>
  10255. <li>
  10256. <p>Install Prometheus:</p>
  10257. <p>Follow instructions at
  10258. <a href="http://prometheus.io/docs/introduction/install/">http://prometheus.io/docs/introduction/install/</a></p>
  10259. </li>
  10260. <li>
  10261. <p>Enable Synapse metrics:</p>
  10262. <p>There are two methods of enabling metrics in Synapse.</p>
  10263. <p>The first serves the metrics as a part of the usual web server and
  10264. can be enabled by adding the &quot;metrics&quot; resource to the existing
  10265. listener as such:</p>
  10266. <pre><code class="language-yaml"> resources:
  10267. - names:
  10268. - client
  10269. - metrics
  10270. </code></pre>
  10271. <p>This provides a simple way of adding metrics to your Synapse
  10272. installation, and serves under <code>/_synapse/metrics</code>. If you do not
  10273. wish your metrics be publicly exposed, you will need to either
  10274. filter it out at your load balancer, or use the second method.</p>
  10275. <p>The second method runs the metrics server on a different port, in a
  10276. different thread to Synapse. This can make it more resilient to
  10277. heavy load meaning metrics cannot be retrieved, and can be exposed
  10278. to just internal networks easier. The served metrics are available
  10279. over HTTP only, and will be available at <code>/_synapse/metrics</code>.</p>
  10280. <p>Add a new listener to homeserver.yaml:</p>
  10281. <pre><code class="language-yaml"> listeners:
  10282. - type: metrics
  10283. port: 9000
  10284. bind_addresses:
  10285. - '0.0.0.0'
  10286. </code></pre>
  10287. <p>For both options, you will need to ensure that <code>enable_metrics</code> is
  10288. set to <code>True</code>.</p>
  10289. </li>
  10290. <li>
  10291. <p>Restart Synapse.</p>
  10292. </li>
  10293. <li>
  10294. <p>Add a Prometheus target for Synapse.</p>
  10295. <p>It needs to set the <code>metrics_path</code> to a non-default value (under
  10296. <code>scrape_configs</code>):</p>
  10297. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10298. scrape_interval: 15s
  10299. metrics_path: &quot;/_synapse/metrics&quot;
  10300. static_configs:
  10301. - targets: [&quot;my.server.here:port&quot;]
  10302. </code></pre>
  10303. <p>where <code>my.server.here</code> is the IP address of Synapse, and <code>port</code> is
  10304. the listener port configured with the <code>metrics</code> resource.</p>
  10305. <p>If your prometheus is older than 1.5.2, you will need to replace
  10306. <code>static_configs</code> in the above with <code>target_groups</code>.</p>
  10307. </li>
  10308. <li>
  10309. <p>Restart Prometheus.</p>
  10310. </li>
  10311. <li>
  10312. <p>Consider using the <a href="https://github.com/matrix-org/synapse/tree/master/contrib/grafana/">grafana dashboard</a>
  10313. and required <a href="https://github.com/matrix-org/synapse/tree/master/contrib/prometheus/">recording rules</a> </p>
  10314. </li>
  10315. </ol>
  10316. <h2 id="monitoring-workers"><a class="header" href="#monitoring-workers">Monitoring workers</a></h2>
  10317. <p>To monitor a Synapse installation using <a href="workers.html">workers</a>,
  10318. every worker needs to be monitored independently, in addition to
  10319. the main homeserver process. This is because workers don't send
  10320. their metrics to the main homeserver process, but expose them
  10321. directly (if they are configured to do so).</p>
  10322. <p>To allow collecting metrics from a worker, you need to add a
  10323. <code>metrics</code> listener to its configuration, by adding the following
  10324. under <code>worker_listeners</code>:</p>
  10325. <pre><code class="language-yaml"> - type: metrics
  10326. bind_address: ''
  10327. port: 9101
  10328. </code></pre>
  10329. <p>The <code>bind_address</code> and <code>port</code> parameters should be set so that
  10330. the resulting listener can be reached by prometheus, and they
  10331. don't clash with an existing worker.
  10332. With this example, the worker's metrics would then be available
  10333. on <code>http://127.0.0.1:9101</code>.</p>
  10334. <p>Example Prometheus target for Synapse with workers:</p>
  10335. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10336. scrape_interval: 15s
  10337. metrics_path: &quot;/_synapse/metrics&quot;
  10338. static_configs:
  10339. - targets: [&quot;my.server.here:port&quot;]
  10340. labels:
  10341. instance: &quot;my.server&quot;
  10342. job: &quot;master&quot;
  10343. index: 1
  10344. - targets: [&quot;my.workerserver.here:port&quot;]
  10345. labels:
  10346. instance: &quot;my.server&quot;
  10347. job: &quot;generic_worker&quot;
  10348. index: 1
  10349. - targets: [&quot;my.workerserver.here:port&quot;]
  10350. labels:
  10351. instance: &quot;my.server&quot;
  10352. job: &quot;generic_worker&quot;
  10353. index: 2
  10354. - targets: [&quot;my.workerserver.here:port&quot;]
  10355. labels:
  10356. instance: &quot;my.server&quot;
  10357. job: &quot;media_repository&quot;
  10358. index: 1
  10359. </code></pre>
  10360. <p>Labels (<code>instance</code>, <code>job</code>, <code>index</code>) can be defined as anything.
  10361. The labels are used to group graphs in grafana.</p>
  10362. <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>
  10363. <p>Synapse 1.2 updates the Prometheus metrics to match the naming
  10364. convention of the upstream <code>prometheus_client</code>. The old names are
  10365. considered deprecated and will be removed in a future version of
  10366. Synapse.</p>
  10367. <table><thead><tr><th>New Name</th><th>Old Name</th></tr></thead><tbody>
  10368. <tr><td>python_gc_objects_collected_total</td><td>python_gc_objects_collected</td></tr>
  10369. <tr><td>python_gc_objects_uncollectable_total</td><td>python_gc_objects_uncollectable</td></tr>
  10370. <tr><td>python_gc_collections_total</td><td>python_gc_collections</td></tr>
  10371. <tr><td>process_cpu_seconds_total</td><td>process_cpu_seconds</td></tr>
  10372. <tr><td>synapse_federation_client_sent_transactions_total</td><td>synapse_federation_client_sent_transactions</td></tr>
  10373. <tr><td>synapse_federation_client_events_processed_total</td><td>synapse_federation_client_events_processed</td></tr>
  10374. <tr><td>synapse_event_processing_loop_count_total</td><td>synapse_event_processing_loop_count</td></tr>
  10375. <tr><td>synapse_event_processing_loop_room_count_total</td><td>synapse_event_processing_loop_room_count</td></tr>
  10376. <tr><td>synapse_util_metrics_block_count_total</td><td>synapse_util_metrics_block_count</td></tr>
  10377. <tr><td>synapse_util_metrics_block_time_seconds_total</td><td>synapse_util_metrics_block_time_seconds</td></tr>
  10378. <tr><td>synapse_util_metrics_block_ru_utime_seconds_total</td><td>synapse_util_metrics_block_ru_utime_seconds</td></tr>
  10379. <tr><td>synapse_util_metrics_block_ru_stime_seconds_total</td><td>synapse_util_metrics_block_ru_stime_seconds</td></tr>
  10380. <tr><td>synapse_util_metrics_block_db_txn_count_total</td><td>synapse_util_metrics_block_db_txn_count</td></tr>
  10381. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds_total</td><td>synapse_util_metrics_block_db_txn_duration_seconds</td></tr>
  10382. <tr><td>synapse_util_metrics_block_db_sched_duration_seconds_total</td><td>synapse_util_metrics_block_db_sched_duration_seconds</td></tr>
  10383. <tr><td>synapse_background_process_start_count_total</td><td>synapse_background_process_start_count</td></tr>
  10384. <tr><td>synapse_background_process_ru_utime_seconds_total</td><td>synapse_background_process_ru_utime_seconds</td></tr>
  10385. <tr><td>synapse_background_process_ru_stime_seconds_total</td><td>synapse_background_process_ru_stime_seconds</td></tr>
  10386. <tr><td>synapse_background_process_db_txn_count_total</td><td>synapse_background_process_db_txn_count</td></tr>
  10387. <tr><td>synapse_background_process_db_txn_duration_seconds_total</td><td>synapse_background_process_db_txn_duration_seconds</td></tr>
  10388. <tr><td>synapse_background_process_db_sched_duration_seconds_total</td><td>synapse_background_process_db_sched_duration_seconds</td></tr>
  10389. <tr><td>synapse_storage_events_persisted_events_total</td><td>synapse_storage_events_persisted_events</td></tr>
  10390. <tr><td>synapse_storage_events_persisted_events_sep_total</td><td>synapse_storage_events_persisted_events_sep</td></tr>
  10391. <tr><td>synapse_storage_events_state_delta_total</td><td>synapse_storage_events_state_delta</td></tr>
  10392. <tr><td>synapse_storage_events_state_delta_single_event_total</td><td>synapse_storage_events_state_delta_single_event</td></tr>
  10393. <tr><td>synapse_storage_events_state_delta_reuse_delta_total</td><td>synapse_storage_events_state_delta_reuse_delta</td></tr>
  10394. <tr><td>synapse_federation_server_received_pdus_total</td><td>synapse_federation_server_received_pdus</td></tr>
  10395. <tr><td>synapse_federation_server_received_edus_total</td><td>synapse_federation_server_received_edus</td></tr>
  10396. <tr><td>synapse_handler_presence_notified_presence_total</td><td>synapse_handler_presence_notified_presence</td></tr>
  10397. <tr><td>synapse_handler_presence_federation_presence_out_total</td><td>synapse_handler_presence_federation_presence_out</td></tr>
  10398. <tr><td>synapse_handler_presence_presence_updates_total</td><td>synapse_handler_presence_presence_updates</td></tr>
  10399. <tr><td>synapse_handler_presence_timers_fired_total</td><td>synapse_handler_presence_timers_fired</td></tr>
  10400. <tr><td>synapse_handler_presence_federation_presence_total</td><td>synapse_handler_presence_federation_presence</td></tr>
  10401. <tr><td>synapse_handler_presence_bump_active_time_total</td><td>synapse_handler_presence_bump_active_time</td></tr>
  10402. <tr><td>synapse_federation_client_sent_edus_total</td><td>synapse_federation_client_sent_edus</td></tr>
  10403. <tr><td>synapse_federation_client_sent_pdu_destinations_count_total</td><td>synapse_federation_client_sent_pdu_destinations:count</td></tr>
  10404. <tr><td>synapse_federation_client_sent_pdu_destinations_total</td><td>synapse_federation_client_sent_pdu_destinations:total</td></tr>
  10405. <tr><td>synapse_handlers_appservice_events_processed_total</td><td>synapse_handlers_appservice_events_processed</td></tr>
  10406. <tr><td>synapse_notifier_notified_events_total</td><td>synapse_notifier_notified_events</td></tr>
  10407. <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>
  10408. <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>
  10409. <tr><td>synapse_http_httppusher_http_pushes_processed_total</td><td>synapse_http_httppusher_http_pushes_processed</td></tr>
  10410. <tr><td>synapse_http_httppusher_http_pushes_failed_total</td><td>synapse_http_httppusher_http_pushes_failed</td></tr>
  10411. <tr><td>synapse_http_httppusher_badge_updates_processed_total</td><td>synapse_http_httppusher_badge_updates_processed</td></tr>
  10412. <tr><td>synapse_http_httppusher_badge_updates_failed_total</td><td>synapse_http_httppusher_badge_updates_failed</td></tr>
  10413. </tbody></table>
  10414. <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>
  10415. <p>The duplicated metrics deprecated in Synapse 0.27.0 have been removed.</p>
  10416. <p>All time duration-based metrics have been changed to be seconds. This
  10417. affects:</p>
  10418. <table><thead><tr><th>msec -&gt; sec metrics</th></tr></thead><tbody>
  10419. <tr><td>python_gc_time</td></tr>
  10420. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10421. <tr><td>synapse_storage_query_time</td></tr>
  10422. <tr><td>synapse_storage_schedule_time</td></tr>
  10423. <tr><td>synapse_storage_transaction_time</td></tr>
  10424. </tbody></table>
  10425. <p>Several metrics have been changed to be histograms, which sort entries
  10426. into buckets and allow better analysis. The following metrics are now
  10427. histograms:</p>
  10428. <table><thead><tr><th>Altered metrics</th></tr></thead><tbody>
  10429. <tr><td>python_gc_time</td></tr>
  10430. <tr><td>python_twisted_reactor_pending_calls</td></tr>
  10431. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10432. <tr><td>synapse_http_server_response_time_seconds</td></tr>
  10433. <tr><td>synapse_storage_query_time</td></tr>
  10434. <tr><td>synapse_storage_schedule_time</td></tr>
  10435. <tr><td>synapse_storage_transaction_time</td></tr>
  10436. </tbody></table>
  10437. <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>
  10438. <p>Synapse 0.27.0 begins the process of rationalising the duplicate
  10439. <code>*:count</code> metrics reported for the resource tracking for code blocks and
  10440. HTTP requests.</p>
  10441. <p>At the same time, the corresponding <code>*:total</code> metrics are being renamed,
  10442. as the <code>:total</code> suffix no longer makes sense in the absence of a
  10443. corresponding <code>:count</code> metric.</p>
  10444. <p>To enable a graceful migration path, this release just adds new names
  10445. for the metrics being renamed. A future release will remove the old
  10446. ones.</p>
  10447. <p>The following table shows the new metrics, and the old metrics which
  10448. they are replacing.</p>
  10449. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10450. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_timer:count</td></tr>
  10451. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_utime:count</td></tr>
  10452. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_stime:count</td></tr>
  10453. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_count:count</td></tr>
  10454. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_duration:count</td></tr>
  10455. <tr><td>synapse_util_metrics_block_time_seconds</td><td>synapse_util_metrics_block_timer:total</td></tr>
  10456. <tr><td>synapse_util_metrics_block_ru_utime_seconds</td><td>synapse_util_metrics_block_ru_utime:total</td></tr>
  10457. <tr><td>synapse_util_metrics_block_ru_stime_seconds</td><td>synapse_util_metrics_block_ru_stime:total</td></tr>
  10458. <tr><td>synapse_util_metrics_block_db_txn_count</td><td>synapse_util_metrics_block_db_txn_count:total</td></tr>
  10459. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds</td><td>synapse_util_metrics_block_db_txn_duration:total</td></tr>
  10460. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_requests</td></tr>
  10461. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_time:count</td></tr>
  10462. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_utime:count</td></tr>
  10463. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_stime:count</td></tr>
  10464. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_count:count</td></tr>
  10465. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_duration:count</td></tr>
  10466. <tr><td>synapse_http_server_response_time_seconds</td><td>synapse_http_server_response_time:total</td></tr>
  10467. <tr><td>synapse_http_server_response_ru_utime_seconds</td><td>synapse_http_server_response_ru_utime:total</td></tr>
  10468. <tr><td>synapse_http_server_response_ru_stime_seconds</td><td>synapse_http_server_response_ru_stime:total</td></tr>
  10469. <tr><td>synapse_http_server_response_db_txn_count</td><td>synapse_http_server_response_db_txn_count:total</td></tr>
  10470. <tr><td>synapse_http_server_response_db_txn_duration_seconds</td><td>synapse_http_server_response_db_txn_duration:total</td></tr>
  10471. </tbody></table>
  10472. <h2 id="standard-metric-names"><a class="header" href="#standard-metric-names">Standard Metric Names</a></h2>
  10473. <p>As of synapse version 0.18.2, the format of the process-wide metrics has
  10474. been changed to fit prometheus standard naming conventions. Additionally
  10475. the units have been changed to seconds, from miliseconds.</p>
  10476. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10477. <tr><td>process_cpu_user_seconds_total</td><td>process_resource_utime / 1000</td></tr>
  10478. <tr><td>process_cpu_system_seconds_total</td><td>process_resource_stime / 1000</td></tr>
  10479. <tr><td>process_open_fds (no 'type' label)</td><td>process_fds</td></tr>
  10480. </tbody></table>
  10481. <p>The python-specific counts of garbage collector performance have been
  10482. renamed.</p>
  10483. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10484. <tr><td>python_gc_time</td><td>reactor_gc_time</td></tr>
  10485. <tr><td>python_gc_unreachable_total</td><td>reactor_gc_unreachable</td></tr>
  10486. <tr><td>python_gc_counts</td><td>reactor_gc_counts</td></tr>
  10487. </tbody></table>
  10488. <p>The twisted-specific reactor metrics have been renamed.</p>
  10489. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10490. <tr><td>python_twisted_reactor_pending_calls</td><td>reactor_pending_calls</td></tr>
  10491. <tr><td>python_twisted_reactor_tick_time</td><td>reactor_tick_time</td></tr>
  10492. </tbody></table>
  10493. <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>
  10494. <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>
  10495. <p>See the following for how to decode the dense data available from the default logging configuration.</p>
  10496. <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]
  10497. -AAAAAAAAAAAAAAAAAAAAA- -BBBBBBBBBBBBBBBBBBBBBB- -C- -DD- -EEEEEE- -FFFFFFFFF- -GG- -HHHHHHHHHHHHHHHHHHHHHHH- -IIIIII- -JJJJJJJ- -KKKKKK-, -LLLLLL- -MMMMMMM- -NNNNNN- O -P- -QQ- -RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR- -SSSSSSSSSSSS- -TTTTTT-
  10498. </code></pre>
  10499. <table><thead><tr><th>Part</th><th>Explanation</th></tr></thead><tbody>
  10500. <tr><td>AAAA</td><td>Timestamp request was logged (not recieved)</td></tr>
  10501. <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>
  10502. <tr><td>CCCC</td><td>Line number in code</td></tr>
  10503. <tr><td>DDDD</td><td>Log Level</td></tr>
  10504. <tr><td>EEEE</td><td>Request Identifier (This identifier is shared by related log lines)</td></tr>
  10505. <tr><td>FFFF</td><td>Source IP (Or X-Forwarded-For if enabled)</td></tr>
  10506. <tr><td>GGGG</td><td>Server Port</td></tr>
  10507. <tr><td>HHHH</td><td>Federated Server or Local User making request (blank if unauthenticated or not supplied)</td></tr>
  10508. <tr><td>IIII</td><td>Total Time to process the request</td></tr>
  10509. <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>
  10510. <tr><td>KKKK</td><td>Userland CPU time</td></tr>
  10511. <tr><td>LLLL</td><td>System CPU time</td></tr>
  10512. <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>
  10513. <tr><td>NNNN</td><td>Total time waiting for response to DB queries across all parallel DB work from this request</td></tr>
  10514. <tr><td>OOOO</td><td>Count of DB transactions performed</td></tr>
  10515. <tr><td>PPPP</td><td>Response body size</td></tr>
  10516. <tr><td>QQQQ</td><td>Response status code (prefixed with ! if the socket was closed before the response was generated)</td></tr>
  10517. <tr><td>RRRR</td><td>Request</td></tr>
  10518. <tr><td>SSSS</td><td>User-agent</td></tr>
  10519. <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>
  10520. </tbody></table>
  10521. <p>MMMM / NNNN can be greater than IIII if there are multiple slow database queries
  10522. running in parallel.</p>
  10523. <p>Some actions can result in multiple identical http requests, which will return
  10524. the same data, but only the first request will report time/transactions in
  10525. <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
  10526. response and will simultaneously return with the first request, but with very
  10527. small processing times.</p>
  10528. <div style="break-before: page; page-break-before: always;"></div><!--
  10529. Include the contents of CONTRIBUTING.md from the project root (where GitHub likes it
  10530. to be)
  10531. -->
  10532. <h1 id="contributing"><a class="header" href="#contributing">Contributing</a></h1>
  10533. <p>Welcome to Synapse</p>
  10534. <p>This document aims to get you started with contributing to this repo! </p>
  10535. <ul>
  10536. <li><a href="development/contributing_guide.html#1-who-can-contribute-to-synapse">1. Who can contribute to Synapse?</a></li>
  10537. <li><a href="development/contributing_guide.html#2-what-do-i-need">2. What do I need?</a></li>
  10538. <li><a href="development/contributing_guide.html#3-get-the-source">3. Get the source.</a></li>
  10539. <li><a href="development/contributing_guide.html#4-install-the-dependencies">4. Install the dependencies</a>
  10540. <ul>
  10541. <li><a href="development/contributing_guide.html#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></li>
  10542. <li><a href="development/contributing_guide.html#under-windows">Under Windows</a></li>
  10543. </ul>
  10544. </li>
  10545. <li><a href="development/contributing_guide.html#5-get-in-touch">5. Get in touch.</a></li>
  10546. <li><a href="development/contributing_guide.html#6-pick-an-issue">6. Pick an issue.</a></li>
  10547. <li><a href="development/contributing_guide.html#7-turn-coffee-and-documentation-into-code-and-documentation">7. Turn coffee and documentation into code and documentation!</a></li>
  10548. <li><a href="development/contributing_guide.html#8-test-test-test">8. Test, test, test!</a>
  10549. <ul>
  10550. <li><a href="development/contributing_guide.html#run-the-linters">Run the linters.</a></li>
  10551. <li><a href="development/contributing_guide.html#run-the-unit-tests">Run the unit tests.</a></li>
  10552. <li><a href="development/contributing_guide.html#run-the-integration-tests">Run the integration tests.</a></li>
  10553. </ul>
  10554. </li>
  10555. <li><a href="development/contributing_guide.html#9-submit-your-patch">9. Submit your patch.</a>
  10556. <ul>
  10557. <li><a href="development/contributing_guide.html#changelog">Changelog</a>
  10558. <ul>
  10559. <li><a href="development/contributing_guide.html#how-do-i-know-what-to-call-the-changelog-file-before-i-create-the-pr">How do I know what to call the changelog file before I create the PR?</a></li>
  10560. <li><a href="development/contributing_guide.html#debian-changelog">Debian changelog</a></li>
  10561. </ul>
  10562. </li>
  10563. <li><a href="development/contributing_guide.html#sign-off">Sign off</a></li>
  10564. </ul>
  10565. </li>
  10566. <li><a href="development/contributing_guide.html#10-turn-feedback-into-better-code">10. Turn feedback into better code.</a></li>
  10567. <li><a href="development/contributing_guide.html#11-find-a-new-issue">11. Find a new issue.</a></li>
  10568. <li><a href="development/contributing_guide.html#notes-for-maintainers-on-merging-prs-etc">Notes for maintainers on merging PRs etc</a></li>
  10569. <li><a href="development/contributing_guide.html#conclusion">Conclusion</a></li>
  10570. </ul>
  10571. <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>
  10572. <p>Everyone is welcome to contribute code to <a href="https://github.com/matrix-org">matrix.org
  10573. projects</a>, provided that they are willing to
  10574. license their contributions under the same license as the project itself. We
  10575. follow a simple 'inbound=outbound' model for contributions: the act of
  10576. submitting an 'inbound' contribution means that the contributor agrees to
  10577. license the code under the same terms as the project's overall 'outbound'
  10578. license - in our case, this is almost always Apache Software License v2 (see
  10579. <a href="development/LICENSE">LICENSE</a>).</p>
  10580. <h1 id="2-what-do-i-need"><a class="header" href="#2-what-do-i-need">2. What do I need?</a></h1>
  10581. <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>
  10582. <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>
  10583. <p>For some tests, you will need <a href="https://docs.docker.com/get-docker/">a recent version of Docker</a>.</p>
  10584. <h1 id="3-get-the-source"><a class="header" href="#3-get-the-source">3. Get the source.</a></h1>
  10585. <p>The preferred and easiest way to contribute changes is to fork the relevant
  10586. 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
  10587. changes into our repo.</p>
  10588. <p>Please base your changes on the <code>develop</code> branch.</p>
  10589. <pre><code class="language-sh">git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git
  10590. git checkout develop
  10591. </code></pre>
  10592. <p>If you need help getting started with git, this is beyond the scope of the document, but you
  10593. can find many good git tutorials on the web.</p>
  10594. <h1 id="4-install-the-dependencies"><a class="header" href="#4-install-the-dependencies">4. Install the dependencies</a></h1>
  10595. <h2 id="under-unix-macos-linux-bsd-"><a class="header" href="#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></h2>
  10596. <p>Once you have installed Python 3 and added the source, please open a terminal and
  10597. setup a <em>virtualenv</em>, as follows:</p>
  10598. <pre><code class="language-sh">cd path/where/you/have/cloned/the/repository
  10599. python3 -m venv ./env
  10600. source ./env/bin/activate
  10601. pip install -e &quot;.[all,lint,mypy,test]&quot;
  10602. pip install tox
  10603. </code></pre>
  10604. <p>This will install the developer dependencies for the project.</p>
  10605. <h2 id="under-windows"><a class="header" href="#under-windows">Under Windows</a></h2>
  10606. <p>TBD</p>
  10607. <h1 id="5-get-in-touch"><a class="header" href="#5-get-in-touch">5. Get in touch.</a></h1>
  10608. <p>Join our developer community on Matrix: #synapse-dev:matrix.org !</p>
  10609. <h1 id="6-pick-an-issue"><a class="header" href="#6-pick-an-issue">6. Pick an issue.</a></h1>
  10610. <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>
  10611. to work on.</p>
  10612. <h1 id="7-turn-coffee-and-documentation-into-code-and-documentation"><a class="header" href="#7-turn-coffee-and-documentation-into-code-and-documentation">7. Turn coffee and documentation into code and documentation!</a></h1>
  10613. <p>Synapse's code style is documented <a href="development/docs/code_style.html">here</a>. Please follow
  10614. it, including the conventions for the <a href="development/docs/code_style.html#configuration-file-format">sample configuration
  10615. file</a>.</p>
  10616. <p>There is a growing amount of documentation located in the <a href="development/docs">docs</a>
  10617. directory. This documentation is intended primarily for sysadmins running their
  10618. own Synapse instance, as well as developers interacting externally with
  10619. Synapse. <a href="development/docs/dev">docs/dev</a> exists primarily to house documentation for
  10620. Synapse developers. <a href="development/docs/admin_api">docs/admin_api</a> houses documentation
  10621. regarding Synapse's Admin API, which is used mostly by sysadmins and external
  10622. service developers.</p>
  10623. <p>If you add new files added to either of these folders, please use <a href="https://guides.github.com/features/mastering-markdown/">GitHub-Flavoured
  10624. Markdown</a>.</p>
  10625. <p>Some documentation also exists in <a href="https://github.com/matrix-org/synapse/wiki">Synapse's GitHub
  10626. Wiki</a>, although this is primarily
  10627. contributed to by community authors.</p>
  10628. <h1 id="8-test-test-test"><a class="header" href="#8-test-test-test">8. Test, test, test!</a></h1>
  10629. <p><a name="test-test-test"></a></p>
  10630. <p>While you're developing and before submitting a patch, you'll
  10631. want to test your code.</p>
  10632. <h2 id="run-the-linters"><a class="header" href="#run-the-linters">Run the linters.</a></h2>
  10633. <p>The linters look at your code and do two things:</p>
  10634. <ul>
  10635. <li>ensure that your code follows the coding style adopted by the project;</li>
  10636. <li>catch a number of errors in your code.</li>
  10637. </ul>
  10638. <p>They're pretty fast, don't hesitate!</p>
  10639. <pre><code class="language-sh">source ./env/bin/activate
  10640. ./scripts-dev/lint.sh
  10641. </code></pre>
  10642. <p>Note that this script <em>will modify your files</em> to fix styling errors.
  10643. Make sure that you have saved all your files.</p>
  10644. <p>If you wish to restrict the linters to only the files changed since the last commit
  10645. (much faster!), you can instead run:</p>
  10646. <pre><code class="language-sh">source ./env/bin/activate
  10647. ./scripts-dev/lint.sh -d
  10648. </code></pre>
  10649. <p>Or if you know exactly which files you wish to lint, you can instead run:</p>
  10650. <pre><code class="language-sh">source ./env/bin/activate
  10651. ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
  10652. </code></pre>
  10653. <h2 id="run-the-unit-tests"><a class="header" href="#run-the-unit-tests">Run the unit tests.</a></h2>
  10654. <p>The unit tests run parts of Synapse, including your changes, to see if anything
  10655. was broken. They are slower than the linters but will typically catch more errors.</p>
  10656. <pre><code class="language-sh">source ./env/bin/activate
  10657. trial tests
  10658. </code></pre>
  10659. <p>If you wish to only run <em>some</em> unit tests, you may specify
  10660. another module instead of <code>tests</code> - or a test class or a method:</p>
  10661. <pre><code class="language-sh">source ./env/bin/activate
  10662. trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
  10663. </code></pre>
  10664. <p>If your tests fail, you may wish to look at the logs (the default log level is <code>ERROR</code>):</p>
  10665. <pre><code class="language-sh">less _trial_temp/test.log
  10666. </code></pre>
  10667. <p>To increase the log level for the tests, set <code>SYNAPSE_TEST_LOG_LEVEL</code>:</p>
  10668. <pre><code class="language-sh">SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
  10669. </code></pre>
  10670. <h2 id="run-the-integration-tests"><a class="header" href="#run-the-integration-tests">Run the integration tests.</a></h2>
  10671. <p>The integration tests are a more comprehensive suite of tests. They
  10672. run a full version of Synapse, including your changes, to check if
  10673. anything was broken. They are slower than the unit tests but will
  10674. typically catch more errors.</p>
  10675. <p>The following command will let you run the integration test with the most common
  10676. configuration:</p>
  10677. <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:py37
  10678. </code></pre>
  10679. <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>
  10680. <h1 id="9-submit-your-patch"><a class="header" href="#9-submit-your-patch">9. Submit your patch.</a></h1>
  10681. <p>Once you're happy with your patch, it's time to prepare a Pull Request.</p>
  10682. <p>To prepare a Pull Request, please:</p>
  10683. <ol>
  10684. <li>verify that <a href="development/contributing_guide.html#test-test-test">all the tests pass</a>, including the coding style;</li>
  10685. <li><a href="development/contributing_guide.html#sign-off">sign off</a> your contribution;</li>
  10686. <li><code>git push</code> your commit to your fork of Synapse;</li>
  10687. <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>
  10688. <li>add a <a href="development/contributing_guide.html#changelog">changelog entry</a> and push it to your Pull Request;</li>
  10689. <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>
  10690. </ol>
  10691. <h2 id="changelog"><a class="header" href="#changelog">Changelog</a></h2>
  10692. <p>All changes, even minor ones, need a corresponding changelog / newsfragment
  10693. entry. These are managed by <a href="https://github.com/hawkowl/towncrier">Towncrier</a>.</p>
  10694. <p>To create a changelog entry, make a new file in the <code>changelog.d</code> directory named
  10695. in the format of <code>PRnumber.type</code>. The type can be one of the following:</p>
  10696. <ul>
  10697. <li><code>feature</code></li>
  10698. <li><code>bugfix</code></li>
  10699. <li><code>docker</code> (for updates to the Docker image)</li>
  10700. <li><code>doc</code> (for updates to the documentation)</li>
  10701. <li><code>removal</code> (also used for deprecations)</li>
  10702. <li><code>misc</code> (for internal-only changes)</li>
  10703. </ul>
  10704. <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
  10705. release, so the content of the file should be a short description of your
  10706. change in the same style as the rest of the changelog. The file can contain Markdown
  10707. formatting, and should end with a full stop (.) or an exclamation mark (!) for
  10708. consistency.</p>
  10709. <p>Adding credits to the changelog is encouraged, we value your
  10710. contributions and would like to have you shouted out in the release notes!</p>
  10711. <p>For example, a fix in PR #1234 would have its changelog entry in
  10712. <code>changelog.d/1234.bugfix</code>, and contain content like:</p>
  10713. <blockquote>
  10714. <p>The security levels of Florbs are now validated when received
  10715. via the <code>/federation/florb</code> endpoint. Contributed by Jane Matrix.</p>
  10716. </blockquote>
  10717. <p>If there are multiple pull requests involved in a single bugfix/feature/etc,
  10718. then the content for each <code>changelog.d</code> file should be the same. Towncrier will
  10719. merge the matching files together into a single changelog entry when we come to
  10720. release.</p>
  10721. <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>
  10722. <p>Obviously, you don't know if you should call your newsfile
  10723. <code>1234.bugfix</code> or <code>5678.bugfix</code> until you create the PR, which leads to a
  10724. chicken-and-egg problem.</p>
  10725. <p>There are two options for solving this:</p>
  10726. <ol>
  10727. <li>
  10728. <p>Open the PR without a changelog file, see what number you got, and <em>then</em>
  10729. add the changelog file to your branch (see <a href="development/contributing_guide.html#updating-your-pull-request">Updating your pull
  10730. request</a>), or:</p>
  10731. </li>
  10732. <li>
  10733. <p>Look at the <a href="https://github.com/matrix-org/synapse/issues?q=">list of all
  10734. issues/PRs</a>, add one to the
  10735. highest number you see, and quickly open the PR before somebody else claims
  10736. your number.</p>
  10737. <p><a href="https://github.com/richvdh/scripts/blob/master/next_github_number.sh">This
  10738. script</a>
  10739. might be helpful if you find yourself doing this a lot.</p>
  10740. </li>
  10741. </ol>
  10742. <p>Sorry, we know it's a bit fiddly, but it's <em>really</em> helpful for us when we come
  10743. to put together a release!</p>
  10744. <h3 id="debian-changelog"><a class="header" href="#debian-changelog">Debian changelog</a></h3>
  10745. <p>Changes which affect the debian packaging files (in <code>debian</code>) are an
  10746. exception to the rule that all changes require a <code>changelog.d</code> file.</p>
  10747. <p>In this case, you will need to add an entry to the debian changelog for the
  10748. next release. For this, run the following command:</p>
  10749. <pre><code>dch
  10750. </code></pre>
  10751. <p>This will make up a new version number (if there isn't already an unreleased
  10752. version in flight), and open an editor where you can add a new changelog entry.
  10753. (Our release process will ensure that the version number and maintainer name is
  10754. corrected for the release.)</p>
  10755. <p>If your change affects both the debian packaging <em>and</em> files outside the debian
  10756. directory, you will need both a regular newsfragment <em>and</em> an entry in the
  10757. debian changelog. (Though typically such changes should be submitted as two
  10758. separate pull requests.)</p>
  10759. <h2 id="sign-off"><a class="header" href="#sign-off">Sign off</a></h2>
  10760. <p>In order to have a concrete record that your contribution is intentional
  10761. and you agree to license it under the same terms as the project's license, we've adopted the
  10762. same lightweight approach that the Linux Kernel
  10763. <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>,
  10764. <a href="https://github.com/docker/docker/blob/master/CONTRIBUTING.md">Docker</a>, and many other
  10765. projects use: the DCO (Developer Certificate of Origin:
  10766. http://developercertificate.org/). This is a simple declaration that you wrote
  10767. the contribution or otherwise have the right to contribute it to Matrix:</p>
  10768. <pre><code>Developer Certificate of Origin
  10769. Version 1.1
  10770. Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
  10771. 660 York Street, Suite 102,
  10772. San Francisco, CA 94110 USA
  10773. Everyone is permitted to copy and distribute verbatim copies of this
  10774. license document, but changing it is not allowed.
  10775. Developer's Certificate of Origin 1.1
  10776. By making a contribution to this project, I certify that:
  10777. (a) The contribution was created in whole or in part by me and I
  10778. have the right to submit it under the open source license
  10779. indicated in the file; or
  10780. (b) The contribution is based upon previous work that, to the best
  10781. of my knowledge, is covered under an appropriate open source
  10782. license and I have the right under that license to submit that
  10783. work with modifications, whether created in whole or in part
  10784. by me, under the same open source license (unless I am
  10785. permitted to submit under a different license), as indicated
  10786. in the file; or
  10787. (c) The contribution was provided directly to me by some other
  10788. person who certified (a), (b) or (c) and I have not modified
  10789. it.
  10790. (d) I understand and agree that this project and the contribution
  10791. are public and that a record of the contribution (including all
  10792. personal information I submit with it, including my sign-off) is
  10793. maintained indefinitely and may be redistributed consistent with
  10794. this project or the open source license(s) involved.
  10795. </code></pre>
  10796. <p>If you agree to this for your contribution, then all that's needed is to
  10797. include the line in your commit or pull request comment:</p>
  10798. <pre><code>Signed-off-by: Your Name &lt;your@email.example.org&gt;
  10799. </code></pre>
  10800. <p>We accept contributions under a legally identifiable name, such as
  10801. your name on government documentation or common-law names (names
  10802. claimed by legitimate usage or repute). Unfortunately, we cannot
  10803. accept anonymous contributions at this time.</p>
  10804. <p>Git allows you to add this signoff automatically when using the <code>-s</code>
  10805. flag to <code>git commit</code>, which uses the name and email set in your
  10806. <code>user.name</code> and <code>user.email</code> git configs.</p>
  10807. <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>
  10808. <p>Once the Pull Request is opened, you will see a few things:</p>
  10809. <ol>
  10810. <li>our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;</li>
  10811. <li>one or more of the developers will take a look at your Pull Request and offer feedback.</li>
  10812. </ol>
  10813. <p>From this point, you should:</p>
  10814. <ol>
  10815. <li>Look at the results of the CI pipeline.
  10816. <ul>
  10817. <li>If there is any error, fix the error.</li>
  10818. </ul>
  10819. </li>
  10820. <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>
  10821. <li>Create a new commit with the changes.
  10822. <ul>
  10823. <li>Please do NOT overwrite the history. New commits make the reviewer's life easier.</li>
  10824. <li>Push this commits to your Pull Request.</li>
  10825. </ul>
  10826. </li>
  10827. <li>Back to 1.</li>
  10828. </ol>
  10829. <p>Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!</p>
  10830. <h1 id="11-find-a-new-issue"><a class="header" href="#11-find-a-new-issue">11. Find a new issue.</a></h1>
  10831. <p>By now, you know the drill!</p>
  10832. <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>
  10833. <p>There are some notes for those with commit access to the project on how we
  10834. manage git <a href="development/docs/dev/git.html">here</a>.</p>
  10835. <h1 id="conclusion"><a class="header" href="#conclusion">Conclusion</a></h1>
  10836. <p>That's it! Matrix is a very open and collaborative project as you might expect
  10837. given our obsession with open communication. If we're going to successfully
  10838. matrix together all the fragmented communication technologies out there we are
  10839. reliant on contributions and collaboration from the community to do so. So
  10840. please get involved - and we hope you have as much fun hacking on Matrix as we
  10841. do!</p>
  10842. <div style="break-before: page; page-break-before: always;"></div><h1 id="code-style"><a class="header" href="#code-style">Code Style</a></h1>
  10843. <h2 id="formatting-tools"><a class="header" href="#formatting-tools">Formatting tools</a></h2>
  10844. <p>The Synapse codebase uses a number of code formatting tools in order to
  10845. quickly and automatically check for formatting (and sometimes logical)
  10846. errors in code.</p>
  10847. <p>The necessary tools are detailed below.</p>
  10848. <p>First install them with:</p>
  10849. <pre><code>pip install -e &quot;.[lint,mypy]&quot;
  10850. </code></pre>
  10851. <ul>
  10852. <li>
  10853. <p><strong>black</strong></p>
  10854. <p>The Synapse codebase uses <a href="https://pypi.org/project/black/">black</a>
  10855. as an opinionated code formatter, ensuring all comitted code is
  10856. properly formatted.</p>
  10857. <p>Have <code>black</code> auto-format your code (it shouldn't change any
  10858. functionality) with:</p>
  10859. <pre><code>black . --exclude=&quot;\.tox|build|env&quot;
  10860. </code></pre>
  10861. </li>
  10862. <li>
  10863. <p><strong>flake8</strong></p>
  10864. <p><code>flake8</code> is a code checking tool. We require code to pass <code>flake8</code>
  10865. before being merged into the codebase.</p>
  10866. <p>Check all application and test code with:</p>
  10867. <pre><code>flake8 synapse tests
  10868. </code></pre>
  10869. </li>
  10870. <li>
  10871. <p><strong>isort</strong></p>
  10872. <p><code>isort</code> ensures imports are nicely formatted, and can suggest and
  10873. auto-fix issues such as double-importing.</p>
  10874. <p>Auto-fix imports with:</p>
  10875. <pre><code>isort -rc synapse tests
  10876. </code></pre>
  10877. <p><code>-rc</code> means to recursively search the given directories.</p>
  10878. </li>
  10879. </ul>
  10880. <p>It's worth noting that modern IDEs and text editors can run these tools
  10881. automatically on save. It may be worth looking into whether this
  10882. functionality is supported in your editor for a more convenient
  10883. development workflow. It is not, however, recommended to run <code>flake8</code> on
  10884. save as it takes a while and is very resource intensive.</p>
  10885. <h2 id="general-rules"><a class="header" href="#general-rules">General rules</a></h2>
  10886. <ul>
  10887. <li><strong>Naming</strong>:
  10888. <ul>
  10889. <li>Use camel case for class and type names</li>
  10890. <li>Use underscores for functions and variables.</li>
  10891. </ul>
  10892. </li>
  10893. <li><strong>Docstrings</strong>: should follow the <a href="https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings">google code
  10894. style</a>.
  10895. See the
  10896. <a href="http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html">examples</a>
  10897. in the sphinx documentation.</li>
  10898. <li><strong>Imports</strong>:
  10899. <ul>
  10900. <li>
  10901. <p>Imports should be sorted by <code>isort</code> as described above.</p>
  10902. </li>
  10903. <li>
  10904. <p>Prefer to import classes and functions rather than packages or
  10905. modules.</p>
  10906. <p>Example:</p>
  10907. <pre><code>from synapse.types import UserID
  10908. ...
  10909. user_id = UserID(local, server)
  10910. </code></pre>
  10911. <p>is preferred over:</p>
  10912. <pre><code>from synapse import types
  10913. ...
  10914. user_id = types.UserID(local, server)
  10915. </code></pre>
  10916. <p>(or any other variant).</p>
  10917. <p>This goes against the advice in the Google style guide, but it
  10918. means that errors in the name are caught early (at import time).</p>
  10919. </li>
  10920. <li>
  10921. <p>Avoid wildcard imports (<code>from synapse.types import *</code>) and
  10922. relative imports (<code>from .types import UserID</code>).</p>
  10923. </li>
  10924. </ul>
  10925. </li>
  10926. </ul>
  10927. <h2 id="configuration-file-format"><a class="header" href="#configuration-file-format">Configuration file format</a></h2>
  10928. <p>The <a href="./sample_config.yaml">sample configuration file</a> acts as a
  10929. reference to Synapse's configuration options for server administrators.
  10930. Remember that many readers will be unfamiliar with YAML and server
  10931. administration in general, so that it is important that the file be as
  10932. easy to understand as possible, which includes following a consistent
  10933. format.</p>
  10934. <p>Some guidelines follow:</p>
  10935. <ul>
  10936. <li>
  10937. <p>Sections should be separated with a heading consisting of a single
  10938. line prefixed and suffixed with <code>##</code>. There should be <strong>two</strong> blank
  10939. lines before the section header, and <strong>one</strong> after.</p>
  10940. </li>
  10941. <li>
  10942. <p>Each option should be listed in the file with the following format:</p>
  10943. <ul>
  10944. <li>
  10945. <p>A comment describing the setting. Each line of this comment
  10946. should be prefixed with a hash (<code>#</code>) and a space.</p>
  10947. <p>The comment should describe the default behaviour (ie, what
  10948. happens if the setting is omitted), as well as what the effect
  10949. will be if the setting is changed.</p>
  10950. <p>Often, the comment end with something like &quot;uncomment the
  10951. following to <do action>&quot;.</p>
  10952. </li>
  10953. <li>
  10954. <p>A line consisting of only <code>#</code>.</p>
  10955. </li>
  10956. <li>
  10957. <p>A commented-out example setting, prefixed with only <code>#</code>.</p>
  10958. <p>For boolean (on/off) options, convention is that this example
  10959. should be the <em>opposite</em> to the default (so the comment will end
  10960. with &quot;Uncomment the following to enable [or disable]
  10961. <feature>.&quot; For other options, the example should give some
  10962. non-default value which is likely to be useful to the reader.</p>
  10963. </li>
  10964. </ul>
  10965. </li>
  10966. <li>
  10967. <p>There should be a blank line between each option.</p>
  10968. </li>
  10969. <li>
  10970. <p>Where several settings are grouped into a single dict, <em>avoid</em> the
  10971. convention where the whole block is commented out, resulting in
  10972. comment lines starting <code># #</code>, as this is hard to read and confusing
  10973. to edit. Instead, leave the top-level config option uncommented, and
  10974. follow the conventions above for sub-options. Ensure that your code
  10975. correctly handles the top-level option being set to <code>None</code> (as it
  10976. will be if no sub-options are enabled).</p>
  10977. </li>
  10978. <li>
  10979. <p>Lines should be wrapped at 80 characters.</p>
  10980. </li>
  10981. <li>
  10982. <p>Use two-space indents.</p>
  10983. </li>
  10984. <li>
  10985. <p><code>true</code> and <code>false</code> are spelt thus (as opposed to <code>True</code>, etc.)</p>
  10986. </li>
  10987. <li>
  10988. <p>Use single quotes (<code>'</code>) rather than double-quotes (<code>&quot;</code>) or backticks
  10989. (<code>`</code>) to refer to configuration options.</p>
  10990. </li>
  10991. </ul>
  10992. <p>Example:</p>
  10993. <pre><code>## Frobnication ##
  10994. # The frobnicator will ensure that all requests are fully frobnicated.
  10995. # To enable it, uncomment the following.
  10996. #
  10997. #frobnicator_enabled: true
  10998. # By default, the frobnicator will frobnicate with the default frobber.
  10999. # The following will make it use an alternative frobber.
  11000. #
  11001. #frobincator_frobber: special_frobber
  11002. # Settings for the frobber
  11003. #
  11004. frobber:
  11005. # frobbing speed. Defaults to 1.
  11006. #
  11007. #speed: 10
  11008. # frobbing distance. Defaults to 1000.
  11009. #
  11010. #distance: 100
  11011. </code></pre>
  11012. <p>Note that the sample configuration is generated from the synapse code
  11013. and is maintained by a script, <code>scripts-dev/generate_sample_config</code>.
  11014. Making sure that the output from this script matches the desired format
  11015. is left as an exercise for the reader!</p>
  11016. <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>
  11017. <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>
  11018. <p>In an ideal world, our git commit history would be a linear progression of
  11019. commits each of which contains a single change building on what came
  11020. before. Here, by way of an arbitrary example, is the top of <code>git log --graph b2dba0607</code>:</p>
  11021. <img src="dev/git/clean.png" alt="clean git graph" width="500px">
  11022. <p>Note how the commit comment explains clearly what is changing and why. Also
  11023. note the <em>absence</em> of merge commits, as well as the absence of commits called
  11024. things like (to pick a few culprits):
  11025. <a href="https://github.com/matrix-org/synapse/commit/84691da6c">“pep8”</a>, <a href="https://github.com/matrix-org/synapse/commit/474810d9d">“fix broken
  11026. test”</a>,
  11027. <a href="https://github.com/matrix-org/synapse/commit/c9d72e457">“oops”</a>,
  11028. <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
  11029. the president?”</a>.</p>
  11030. <p>There are a number of reasons why keeping a clean commit history is a good
  11031. thing:</p>
  11032. <ul>
  11033. <li>
  11034. <p>From time to time, after a change lands, it turns out to be necessary to
  11035. revert it, or to backport it to a release branch. Those operations are
  11036. <em>much</em> easier when the change is contained in a single commit.</p>
  11037. </li>
  11038. <li>
  11039. <p>Similarly, it's much easier to answer questions like “is the fix for
  11040. <code>/publicRooms</code> on the release branch?” if that change consists of a single
  11041. commit.</p>
  11042. </li>
  11043. <li>
  11044. <p>Likewise: “what has changed on this branch in the last week?” is much
  11045. clearer without merges and “pep8” commits everywhere.</p>
  11046. </li>
  11047. <li>
  11048. <p>Sometimes we need to figure out where a bug got introduced, or some
  11049. behaviour changed. One way of doing that is with <code>git bisect</code>: pick an
  11050. arbitrary commit between the known good point and the known bad point, and
  11051. see how the code behaves. However, that strategy fails if the commit you
  11052. chose is the middle of someone's epic branch in which they broke the world
  11053. before putting it back together again.</p>
  11054. </li>
  11055. </ul>
  11056. <p>One counterargument is that it is sometimes useful to see how a PR evolved as
  11057. it went through review cycles. This is true, but that information is always
  11058. 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
  11059. namespace</a>).</p>
  11060. <p>Of course, in reality, things are more complicated than that. We have release
  11061. branches as well as <code>develop</code> and <code>master</code>, and we deliberately merge changes
  11062. between them. Bugs often slip through and have to be fixed later. That's all
  11063. fine: this not a cast-iron rule which must be obeyed, but an ideal to aim
  11064. towards.</p>
  11065. <h2 id="merges-squashes-rebases-wtf"><a class="header" href="#merges-squashes-rebases-wtf">Merges, squashes, rebases: wtf?</a></h2>
  11066. <p>Ok, so that's what we'd like to achieve. How do we achieve it?</p>
  11067. <p>The TL;DR is: when you come to merge a pull request, you <em>probably</em> want to
  11068. “squash and merge”:</p>
  11069. <p><img src="dev/git/squash.png" alt="squash and merge" />.</p>
  11070. <p>(This applies whether you are merging your own PR, or that of another
  11071. contributor.)</p>
  11072. <p>“Squash and merge”<sup id="a1"><a href="dev/git.html#f1">1</a></sup> takes all of the changes in the
  11073. PR, and bundles them into a single commit. GitHub gives you the opportunity to
  11074. edit the commit message before you confirm, and normally you should do so,
  11075. because the default will be useless (again: <code>* woops typo</code> is not a useful
  11076. thing to keep in the historical record).</p>
  11077. <p>The main problem with this approach comes when you have a series of pull
  11078. requests which build on top of one another: as soon as you squash-merge the
  11079. first PR, you'll end up with a stack of conflicts to resolve in all of the
  11080. others. In general, it's best to avoid this situation in the first place by
  11081. trying not to have multiple related PRs in flight at the same time. Still,
  11082. sometimes that's not possible and doing a regular merge is the lesser evil.</p>
  11083. <p>Another occasion in which a regular merge makes more sense is a PR where you've
  11084. deliberately created a series of commits each of which makes sense in its own
  11085. right. For example: <a href="https://github.com/matrix-org/synapse/pull/6837">a PR which gradually propagates a refactoring operation
  11086. through the codebase</a>, or <a href="https://github.com/matrix-org/synapse/pull/5987">a
  11087. PR which is the culmination of several other
  11088. PRs</a>. In this case the ability
  11089. to figure out when a particular change/bug was introduced could be very useful.</p>
  11090. <p>Ultimately: <strong>this is not a hard-and-fast-rule</strong>. If in doubt, ask yourself “do
  11091. each of the commits I am about to merge make sense in their own right”, but
  11092. remember that we're just doing our best to balance “keeping the commit history
  11093. clean” with other factors.</p>
  11094. <h2 id="git-branching-model"><a class="header" href="#git-branching-model">Git branching model</a></h2>
  11095. <p>A <a href="https://nvie.com/posts/a-successful-git-branching-model/">lot</a>
  11096. <a href="http://scottchacon.com/2011/08/31/github-flow.html">of</a>
  11097. <a href="https://www.endoflineblog.com/gitflow-considered-harmful">words</a> have been
  11098. written in the past about git branching models (no really, <a href="https://martinfowler.com/articles/branching-patterns.html">a
  11099. lot</a>). I tend to
  11100. think the whole thing is overblown. Fundamentally, it's not that
  11101. complicated. Here's how we do it.</p>
  11102. <p>Let's start with a picture:</p>
  11103. <p><img src="dev/git/branches.jpg" alt="branching model" /></p>
  11104. <p>It looks complicated, but it's really not. There's one basic rule: <em>anyone</em> is
  11105. free to merge from <em>any</em> more-stable branch to <em>any</em> less-stable branch at
  11106. <em>any</em> time<sup id="a2"><a href="dev/git.html#f2">2</a></sup>. (The principle behind this is that if a
  11107. change is good enough for the more-stable branch, then it's also good enough go
  11108. put in a less-stable branch.)</p>
  11109. <p>Meanwhile, merging (or squashing, as per the above) from a less-stable to a
  11110. more-stable branch is a deliberate action in which you want to publish a change
  11111. or a set of changes to (some subset of) the world: for example, this happens
  11112. when a PR is landed, or as part of our release process.</p>
  11113. <p>So, what counts as a more- or less-stable branch? A little reflection will show
  11114. that our active branches are ordered thus, from more-stable to less-stable:</p>
  11115. <ul>
  11116. <li><code>master</code> (tracks our last release).</li>
  11117. <li><code>release-vX.Y</code> (the branch where we prepare the next release)<sup
  11118. id="a3"><a href="dev/git.html#f3">3</a></sup>.</li>
  11119. <li>PR branches which are targeting the release.</li>
  11120. <li><code>develop</code> (our &quot;mainline&quot; branch containing our bleeding-edge).</li>
  11121. <li>regular PR branches.</li>
  11122. </ul>
  11123. <p>The corollary is: if you have a bugfix that needs to land in both
  11124. <code>release-vX.Y</code> <em>and</em> <code>develop</code>, then you should base your PR on
  11125. <code>release-vX.Y</code>, get it merged there, and then merge from <code>release-vX.Y</code> to
  11126. <code>develop</code>. (If a fix lands in <code>develop</code> and we later need it in a
  11127. release-branch, we can of course cherry-pick it, but landing it in the release
  11128. branch first helps reduce the chance of annoying conflicts.)</p>
  11129. <hr />
  11130. <p><b id="f1">[1]</b>: “Squash and merge” is GitHub's term for this
  11131. operation. Given that there is no merge involved, I'm not convinced it's the
  11132. most intuitive name. <a href="dev/git.html#a1">^</a></p>
  11133. <p><b id="f2">[2]</b>: Well, anyone with commit access.<a href="dev/git.html#a2">^</a></p>
  11134. <p><b id="f3">[3]</b>: Very, very occasionally (I think this has happened once in
  11135. the history of Synapse), we've had two releases in flight at once. Obviously,
  11136. <code>release-v1.2</code> is more-stable than <code>release-v1.3</code>. <a href="dev/git.html#a3">^</a></p>
  11137. <div style="break-before: page; page-break-before: always;"></div><h1 id="opentracing"><a class="header" href="#opentracing">OpenTracing</a></h1>
  11138. <h2 id="background"><a class="header" href="#background">Background</a></h2>
  11139. <p>OpenTracing is a semi-standard being adopted by a number of distributed
  11140. tracing platforms. It is a common api for facilitating vendor-agnostic
  11141. tracing instrumentation. That is, we can use the OpenTracing api and
  11142. select one of a number of tracer implementations to do the heavy lifting
  11143. in the background. Our current selected implementation is Jaeger.</p>
  11144. <p>OpenTracing is a tool which gives an insight into the causal
  11145. relationship of work done in and between servers. The servers each track
  11146. events and report them to a centralised server - in Synapse's case:
  11147. Jaeger. The basic unit used to represent events is the span. The span
  11148. roughly represents a single piece of work that was done and the time at
  11149. which it occurred. A span can have child spans, meaning that the work of
  11150. the child had to be completed for the parent span to complete, or it can
  11151. have follow-on spans which represent work that is undertaken as a result
  11152. of the parent but is not depended on by the parent to in order to
  11153. finish.</p>
  11154. <p>Since this is undertaken in a distributed environment a request to
  11155. another server, such as an RPC or a simple GET, can be considered a span
  11156. (a unit or work) for the local server. This causal link is what
  11157. OpenTracing aims to capture and visualise. In order to do this metadata
  11158. about the local server's span, i.e the 'span context', needs to be
  11159. included with the request to the remote.</p>
  11160. <p>It is up to the remote server to decide what it does with the spans it
  11161. creates. This is called the sampling policy and it can be configured
  11162. through Jaeger's settings.</p>
  11163. <p>For OpenTracing concepts see
  11164. <a href="https://opentracing.io/docs/overview/what-is-tracing/">https://opentracing.io/docs/overview/what-is-tracing/</a>.</p>
  11165. <p>For more information about Jaeger's implementation see
  11166. <a href="https://www.jaegertracing.io/docs/">https://www.jaegertracing.io/docs/</a></p>
  11167. <h2 id="setting-up-opentracing"><a class="header" href="#setting-up-opentracing">Setting up OpenTracing</a></h2>
  11168. <p>To receive OpenTracing spans, start up a Jaeger server. This can be done
  11169. using docker like so:</p>
  11170. <pre><code class="language-sh">docker run -d --name jaeger \
  11171. -p 6831:6831/udp \
  11172. -p 6832:6832/udp \
  11173. -p 5778:5778 \
  11174. -p 16686:16686 \
  11175. -p 14268:14268 \
  11176. jaegertracing/all-in-one:1
  11177. </code></pre>
  11178. <p>Latest documentation is probably at
  11179. https://www.jaegertracing.io/docs/latest/getting-started.</p>
  11180. <h2 id="enable-opentracing-in-synapse"><a class="header" href="#enable-opentracing-in-synapse">Enable OpenTracing in Synapse</a></h2>
  11181. <p>OpenTracing is not enabled by default. It must be enabled in the
  11182. homeserver config by uncommenting the config options under <code>opentracing</code>
  11183. as shown in the <a href="./sample_config.yaml">sample config</a>. For example:</p>
  11184. <pre><code class="language-yaml">opentracing:
  11185. enabled: true
  11186. homeserver_whitelist:
  11187. - &quot;mytrustedhomeserver.org&quot;
  11188. - &quot;*.myotherhomeservers.com&quot;
  11189. </code></pre>
  11190. <h2 id="homeserver-whitelisting"><a class="header" href="#homeserver-whitelisting">Homeserver whitelisting</a></h2>
  11191. <p>The homeserver whitelist is configured using regular expressions. A list
  11192. of regular expressions can be given and their union will be compared
  11193. when propagating any spans contexts to another homeserver.</p>
  11194. <p>Though it's mostly safe to send and receive span contexts to and from
  11195. untrusted users since span contexts are usually opaque ids it can lead
  11196. to two problems, namely:</p>
  11197. <ul>
  11198. <li>If the span context is marked as sampled by the sending homeserver
  11199. the receiver will sample it. Therefore two homeservers with wildly
  11200. different sampling policies could incur higher sampling counts than
  11201. intended.</li>
  11202. <li>Sending servers can attach arbitrary data to spans, known as
  11203. 'baggage'. For safety this has been disabled in Synapse but that
  11204. doesn't prevent another server sending you baggage which will be
  11205. logged to OpenTracing's logs.</li>
  11206. </ul>
  11207. <h2 id="configuring-jaeger"><a class="header" href="#configuring-jaeger">Configuring Jaeger</a></h2>
  11208. <p>Sampling strategies can be set as in this document:
  11209. <a href="https://www.jaegertracing.io/docs/latest/sampling/">https://www.jaegertracing.io/docs/latest/sampling/</a>.</p>
  11210. <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>
  11211. <p>Synapse's database schema is stored in the <code>synapse.storage.schema</code> module.</p>
  11212. <h2 id="logical-databases"><a class="header" href="#logical-databases">Logical databases</a></h2>
  11213. <p>Synapse supports splitting its datastore across multiple physical databases (which can
  11214. be useful for large installations), and the schema files are therefore split according
  11215. to the logical database they apply to.</p>
  11216. <p>At the time of writing, the following &quot;logical&quot; databases are supported:</p>
  11217. <ul>
  11218. <li><code>state</code> - used to store Matrix room state (more specifically, <code>state_groups</code>,
  11219. their relationships and contents).</li>
  11220. <li><code>main</code> - stores everything else.</li>
  11221. </ul>
  11222. <p>Additionally, the <code>common</code> directory contains schema files for tables which must be
  11223. present on <em>all</em> physical databases.</p>
  11224. <h2 id="synapse-schema-versions"><a class="header" href="#synapse-schema-versions">Synapse schema versions</a></h2>
  11225. <p>Synapse manages its database schema via &quot;schema versions&quot;. These are mainly used to
  11226. help avoid confusion if the Synapse codebase is rolled back after the database is
  11227. updated. They work as follows:</p>
  11228. <ul>
  11229. <li>
  11230. <p>The Synapse codebase defines a constant <code>synapse.storage.schema.SCHEMA_VERSION</code>
  11231. which represents the expectations made about the database by that version. For
  11232. example, as of Synapse v1.36, this is <code>59</code>.</p>
  11233. </li>
  11234. <li>
  11235. <p>The database stores a &quot;compatibility version&quot; in
  11236. <code>schema_compat_version.compat_version</code> which defines the <code>SCHEMA_VERSION</code> of the
  11237. oldest version of Synapse which will work with the database. On startup, if
  11238. <code>compat_version</code> is found to be newer than <code>SCHEMA_VERSION</code>, Synapse will refuse to
  11239. start.</p>
  11240. <p>Synapse automatically updates this field from
  11241. <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code>.</p>
  11242. </li>
  11243. <li>
  11244. <p>Whenever a backwards-incompatible change is made to the database format (normally
  11245. via a <code>delta</code> file), <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code> is also updated
  11246. so that administrators can not accidentally roll back to a too-old version of Synapse.</p>
  11247. </li>
  11248. </ul>
  11249. <p>Generally, the goal is to maintain compatibility with at least one or two previous
  11250. releases of Synapse, so any substantial change tends to require multiple releases and a
  11251. bit of forward-planning to get right.</p>
  11252. <p>As a worked example: we want to remove the <code>room_stats_historical</code> table. Here is how it
  11253. might pan out.</p>
  11254. <ol>
  11255. <li>
  11256. <p>Replace any code that <em>reads</em> from <code>room_stats_historical</code> with alternative
  11257. implementations, but keep writing to it in case of rollback to an earlier version.
  11258. Also, increase <code>synapse.storage.schema.SCHEMA_VERSION</code>. In this
  11259. instance, there is no existing code which reads from <code>room_stats_historical</code>, so
  11260. our starting point is:</p>
  11261. <p>v1.36.0: <code>SCHEMA_VERSION=59</code>, <code>SCHEMA_COMPAT_VERSION=59</code></p>
  11262. </li>
  11263. <li>
  11264. <p>Next (say in Synapse v1.37.0): remove the code that <em>writes</em> to
  11265. <code>room_stats_historical</code>, but don’t yet remove the table in case of rollback to
  11266. v1.36.0. Again, we increase <code>synapse.storage.schema.SCHEMA_VERSION</code>, but
  11267. because we have not broken compatibility with v1.36, we do not yet update
  11268. <code>SCHEMA_COMPAT_VERSION</code>. We now have:</p>
  11269. <p>v1.37.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=59</code>.</p>
  11270. </li>
  11271. <li>
  11272. <p>Later (say in Synapse v1.38.0): we can remove the table altogether. This will
  11273. break compatibility with v1.36.0, so we must update <code>SCHEMA_COMPAT_VERSION</code> accordingly.
  11274. There is no need to update <code>synapse.storage.schema.SCHEMA_VERSION</code>, since there is no
  11275. change to the Synapse codebase here. So we end up with:</p>
  11276. <p>v1.38.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=60</code>.</p>
  11277. </li>
  11278. </ol>
  11279. <p>If in doubt about whether to update <code>SCHEMA_VERSION</code> or not, it is generally best to
  11280. lean towards doing so.</p>
  11281. <h2 id="full-schema-dumps"><a class="header" href="#full-schema-dumps">Full schema dumps</a></h2>
  11282. <p>In the <code>full_schemas</code> directories, only the most recently-numbered snapshot is used
  11283. (<code>54</code> at the time of writing). Older snapshots (eg, <code>16</code>) are present for historical
  11284. reference only.</p>
  11285. <h3 id="building-full-schema-dumps"><a class="header" href="#building-full-schema-dumps">Building full schema dumps</a></h3>
  11286. <p>If you want to recreate these schemas, they need to be made from a database that
  11287. has had all background updates run.</p>
  11288. <p>To do so, use <code>scripts-dev/make_full_schema.sh</code>. This will produce new
  11289. <code>full.sql.postgres</code> and <code>full.sql.sqlite</code> files.</p>
  11290. <p>Ensure postgres is installed, then run:</p>
  11291. <pre><code>./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
  11292. </code></pre>
  11293. <p>NB at the time of writing, this script predates the split into separate <code>state</code>/<code>main</code>
  11294. databases so will require updates to handle that correctly.</p>
  11295. <h2 id="boolean-columns"><a class="header" href="#boolean-columns">Boolean columns</a></h2>
  11296. <p>Boolean columns require special treatment, since SQLite treats booleans the
  11297. same as integers.</p>
  11298. <p>There are three separate aspects to this:</p>
  11299. <ul>
  11300. <li>
  11301. <p>Any new boolean column must be added to the <code>BOOLEAN_COLUMNS</code> list in
  11302. <code>scripts/synapse_port_db</code>. This tells the port script to cast the integer
  11303. value from SQLite to a boolean before writing the value to the postgres
  11304. database.</p>
  11305. </li>
  11306. <li>
  11307. <p>Before SQLite 3.23, <code>TRUE</code> and <code>FALSE</code> were not recognised as constants by
  11308. SQLite, and the <code>IS [NOT] TRUE</code>/<code>IS [NOT] FALSE</code> operators were not
  11309. supported. This makes it necessary to avoid using <code>TRUE</code> and <code>FALSE</code>
  11310. constants in SQL commands.</p>
  11311. <p>For example, to insert a <code>TRUE</code> value into the database, write:</p>
  11312. <pre><code class="language-python">txn.execute(&quot;INSERT INTO tbl(col) VALUES (?)&quot;, (True, ))
  11313. </code></pre>
  11314. </li>
  11315. <li>
  11316. <p>Default values for new boolean columns present a particular
  11317. difficulty. Generally it is best to create separate schema files for
  11318. Postgres and SQLite. For example:</p>
  11319. <pre><code class="language-sql"># in 00delta.sql.postgres:
  11320. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT FALSE;
  11321. </code></pre>
  11322. <pre><code class="language-sql"># in 00delta.sql.sqlite:
  11323. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT 0;
  11324. </code></pre>
  11325. <p>Note that there is a particularly insidious failure mode here: the Postgres
  11326. flavour will be accepted by SQLite 3.22, but will give a column whose
  11327. default value is the <strong>string</strong> <code>&quot;FALSE&quot;</code> - which, when cast back to a boolean
  11328. in Python, evaluates to <code>True</code>.</p>
  11329. </li>
  11330. </ul>
  11331. <div style="break-before: page; page-break-before: always;"></div><h1 id="log-contexts"><a class="header" href="#log-contexts">Log Contexts</a></h1>
  11332. <p>To help track the processing of individual requests, synapse uses a
  11333. '<code>log context</code>' to track which request it is handling at any given
  11334. moment. This is done via a thread-local variable; a <code>logging.Filter</code> is
  11335. then used to fish the information back out of the thread-local variable
  11336. and add it to each log record.</p>
  11337. <p>Logcontexts are also used for CPU and database accounting, so that we
  11338. can track which requests were responsible for high CPU use or database
  11339. activity.</p>
  11340. <p>The <code>synapse.logging.context</code> module provides a facilities for managing
  11341. the current log context (as well as providing the <code>LoggingContextFilter</code>
  11342. class).</p>
  11343. <p>Asynchronous functions make the whole thing complicated, so this document describes
  11344. how it all works, and how to write code which follows the rules.</p>
  11345. <p>In this document, &quot;awaitable&quot; refers to any object which can be <code>await</code>ed. In the context of
  11346. Synapse, that normally means either a coroutine or a Twisted
  11347. <a href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html"><code>Deferred</code></a>.</p>
  11348. <h2 id="logcontexts-without-asynchronous-code"><a class="header" href="#logcontexts-without-asynchronous-code">Logcontexts without asynchronous code</a></h2>
  11349. <p>In the absence of any asynchronous voodoo, things are simple enough. As with
  11350. any code of this nature, the rule is that our function should leave
  11351. things as it found them:</p>
  11352. <pre><code class="language-python">from synapse.logging import context # omitted from future snippets
  11353. def handle_request(request_id):
  11354. request_context = context.LoggingContext()
  11355. calling_context = context.set_current_context(request_context)
  11356. try:
  11357. request_context.request = request_id
  11358. do_request_handling()
  11359. logger.debug(&quot;finished&quot;)
  11360. finally:
  11361. context.set_current_context(calling_context)
  11362. def do_request_handling():
  11363. logger.debug(&quot;phew&quot;) # this will be logged against request_id
  11364. </code></pre>
  11365. <p>LoggingContext implements the context management methods, so the above
  11366. can be written much more succinctly as:</p>
  11367. <pre><code class="language-python">def handle_request(request_id):
  11368. with context.LoggingContext() as request_context:
  11369. request_context.request = request_id
  11370. do_request_handling()
  11371. logger.debug(&quot;finished&quot;)
  11372. def do_request_handling():
  11373. logger.debug(&quot;phew&quot;)
  11374. </code></pre>
  11375. <h2 id="using-logcontexts-with-awaitables"><a class="header" href="#using-logcontexts-with-awaitables">Using logcontexts with awaitables</a></h2>
  11376. <p>Awaitables break the linear flow of code so that there is no longer a single entry point
  11377. where we should set the logcontext and a single exit point where we should remove it.</p>
  11378. <p>Consider the example above, where <code>do_request_handling</code> needs to do some
  11379. blocking operation, and returns an awaitable:</p>
  11380. <pre><code class="language-python">async def handle_request(request_id):
  11381. with context.LoggingContext() as request_context:
  11382. request_context.request = request_id
  11383. await do_request_handling()
  11384. logger.debug(&quot;finished&quot;)
  11385. </code></pre>
  11386. <p>In the above flow:</p>
  11387. <ul>
  11388. <li>The logcontext is set</li>
  11389. <li><code>do_request_handling</code> is called, and returns an awaitable</li>
  11390. <li><code>handle_request</code> awaits the awaitable</li>
  11391. <li>Execution of <code>handle_request</code> is suspended</li>
  11392. </ul>
  11393. <p>So we have stopped processing the request (and will probably go on to
  11394. start processing the next), without clearing the logcontext.</p>
  11395. <p>To circumvent this problem, synapse code assumes that, wherever you have
  11396. an awaitable, you will want to <code>await</code> it. To that end, whereever
  11397. functions return awaitables, we adopt the following conventions:</p>
  11398. <p><strong>Rules for functions returning awaitables:</strong></p>
  11399. <blockquote>
  11400. <ul>
  11401. <li>If the awaitable is already complete, the function returns with the
  11402. same logcontext it started with.</li>
  11403. <li>If the awaitable is incomplete, the function clears the logcontext
  11404. before returning; when the awaitable completes, it restores the
  11405. logcontext before running any callbacks.</li>
  11406. </ul>
  11407. </blockquote>
  11408. <p>That sounds complicated, but actually it means a lot of code (including
  11409. the example above) &quot;just works&quot;. There are two cases:</p>
  11410. <ul>
  11411. <li>
  11412. <p>If <code>do_request_handling</code> returns a completed awaitable, then the
  11413. logcontext will still be in place. In this case, execution will
  11414. continue immediately after the <code>await</code>; the &quot;finished&quot; line will
  11415. be logged against the right context, and the <code>with</code> block restores
  11416. the original context before we return to the caller.</p>
  11417. </li>
  11418. <li>
  11419. <p>If the returned awaitable is incomplete, <code>do_request_handling</code> clears
  11420. the logcontext before returning. The logcontext is therefore clear
  11421. when <code>handle_request</code> <code>await</code>s the awaitable.</p>
  11422. <p>Once <code>do_request_handling</code>'s awaitable completes, it will reinstate
  11423. the logcontext, before running the second half of <code>handle_request</code>,
  11424. so again the &quot;finished&quot; line will be logged against the right context,
  11425. and the <code>with</code> block restores the original context.</p>
  11426. </li>
  11427. </ul>
  11428. <p>As an aside, it's worth noting that <code>handle_request</code> follows our rules</p>
  11429. <ul>
  11430. <li>though that only matters if the caller has its own logcontext which it
  11431. cares about.</li>
  11432. </ul>
  11433. <p>The following sections describe pitfalls and helpful patterns when
  11434. implementing these rules.</p>
  11435. <h2 id="always-await-your-awaitables"><a class="header" href="#always-await-your-awaitables">Always await your awaitables</a></h2>
  11436. <p>Whenever you get an awaitable back from a function, you should <code>await</code> on
  11437. it as soon as possible. Do not pass go; do not do any logging; do not
  11438. call any other functions.</p>
  11439. <pre><code class="language-python">async def fun():
  11440. logger.debug(&quot;starting&quot;)
  11441. await do_some_stuff() # just like this
  11442. coro = more_stuff()
  11443. result = await coro # also fine, of course
  11444. return result
  11445. </code></pre>
  11446. <p>Provided this pattern is followed all the way back up to the callchain
  11447. to where the logcontext was set, this will make things work out ok:
  11448. provided <code>do_some_stuff</code> and <code>more_stuff</code> follow the rules above, then
  11449. so will <code>fun</code>.</p>
  11450. <p>It's all too easy to forget to <code>await</code>: for instance if we forgot that
  11451. <code>do_some_stuff</code> returned an awaitable, we might plough on regardless. This
  11452. leads to a mess; it will probably work itself out eventually, but not
  11453. before a load of stuff has been logged against the wrong context.
  11454. (Normally, other things will break, more obviously, if you forget to
  11455. <code>await</code>, so this tends not to be a major problem in practice.)</p>
  11456. <p>Of course sometimes you need to do something a bit fancier with your
  11457. awaitable - not all code follows the linear A-then-B-then-C pattern.
  11458. Notes on implementing more complex patterns are in later sections.</p>
  11459. <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>
  11460. <p>Most of the time, an awaitable comes from another synapse function.
  11461. Sometimes, though, we need to make up a new awaitable, or we get an awaitable
  11462. back from external code. We need to make it follow our rules.</p>
  11463. <p>The easy way to do it is by using <code>context.make_deferred_yieldable</code>. Suppose we want to implement
  11464. <code>sleep</code>, which returns a deferred which will run its callbacks after a
  11465. given number of seconds. That might look like:</p>
  11466. <pre><code class="language-python"># not a logcontext-rules-compliant function
  11467. def get_sleep_deferred(seconds):
  11468. d = defer.Deferred()
  11469. reactor.callLater(seconds, d.callback, None)
  11470. return d
  11471. </code></pre>
  11472. <p>That doesn't follow the rules, but we can fix it by calling it through
  11473. <code>context.make_deferred_yieldable</code>:</p>
  11474. <pre><code class="language-python">async def sleep(seconds):
  11475. return await context.make_deferred_yieldable(get_sleep_deferred(seconds))
  11476. </code></pre>
  11477. <h2 id="fire-and-forget"><a class="header" href="#fire-and-forget">Fire-and-forget</a></h2>
  11478. <p>Sometimes you want to fire off a chain of execution, but not wait for
  11479. its result. That might look a bit like this:</p>
  11480. <pre><code class="language-python">async def do_request_handling():
  11481. await foreground_operation()
  11482. # *don't* do this
  11483. background_operation()
  11484. logger.debug(&quot;Request handling complete&quot;)
  11485. async def background_operation():
  11486. await first_background_step()
  11487. logger.debug(&quot;Completed first step&quot;)
  11488. await second_background_step()
  11489. logger.debug(&quot;Completed second step&quot;)
  11490. </code></pre>
  11491. <p>The above code does a couple of steps in the background after
  11492. <code>do_request_handling</code> has finished. The log lines are still logged
  11493. against the <code>request_context</code> logcontext, which may or may not be
  11494. desirable. There are two big problems with the above, however. The first
  11495. problem is that, if <code>background_operation</code> returns an incomplete
  11496. awaitable, it will expect its caller to <code>await</code> immediately, so will have
  11497. cleared the logcontext. In this example, that means that 'Request
  11498. handling complete' will be logged without any context.</p>
  11499. <p>The second problem, which is potentially even worse, is that when the
  11500. awaitable returned by <code>background_operation</code> completes, it will restore
  11501. the original logcontext. There is nothing waiting on that awaitable, so
  11502. the logcontext will leak into the reactor and possibly get attached to
  11503. some arbitrary future operation.</p>
  11504. <p>There are two potential solutions to this.</p>
  11505. <p>One option is to surround the call to <code>background_operation</code> with a
  11506. <code>PreserveLoggingContext</code> call. That will reset the logcontext before
  11507. starting <code>background_operation</code> (so the context restored when the
  11508. deferred completes will be the empty logcontext), and will restore the
  11509. current logcontext before continuing the foreground process:</p>
  11510. <pre><code class="language-python">async def do_request_handling():
  11511. await foreground_operation()
  11512. # start background_operation off in the empty logcontext, to
  11513. # avoid leaking the current context into the reactor.
  11514. with PreserveLoggingContext():
  11515. background_operation()
  11516. # this will now be logged against the request context
  11517. logger.debug(&quot;Request handling complete&quot;)
  11518. </code></pre>
  11519. <p>Obviously that option means that the operations done in
  11520. <code>background_operation</code> would be not be logged against a logcontext
  11521. (though that might be fixed by setting a different logcontext via a
  11522. <code>with LoggingContext(...)</code> in <code>background_operation</code>).</p>
  11523. <p>The second option is to use <code>context.run_in_background</code>, which wraps a
  11524. function so that it doesn't reset the logcontext even when it returns
  11525. an incomplete awaitable, and adds a callback to the returned awaitable to
  11526. reset the logcontext. In other words, it turns a function that follows
  11527. the Synapse rules about logcontexts and awaitables into one which behaves
  11528. more like an external function --- the opposite operation to that
  11529. described in the previous section. It can be used like this:</p>
  11530. <pre><code class="language-python">async def do_request_handling():
  11531. await foreground_operation()
  11532. context.run_in_background(background_operation)
  11533. # this will now be logged against the request context
  11534. logger.debug(&quot;Request handling complete&quot;)
  11535. </code></pre>
  11536. <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>
  11537. <p>A typical example of this is where we want to collect together two or
  11538. more awaitables via <code>defer.gatherResults</code>:</p>
  11539. <pre><code class="language-python">a1 = operation1()
  11540. a2 = operation2()
  11541. a3 = defer.gatherResults([a1, a2])
  11542. </code></pre>
  11543. <p>This is really a variation of the fire-and-forget problem above, in that
  11544. we are firing off <code>a1</code> and <code>a2</code> without awaiting on them. The difference
  11545. is that we now have third-party code attached to their callbacks. Anyway
  11546. either technique given in the <a href="log_contexts.html#fire-and-forget">Fire-and-forget</a>
  11547. section will work.</p>
  11548. <p>Of course, the new awaitable returned by <code>gather</code> needs to be
  11549. wrapped in order to make it follow the logcontext rules before we can
  11550. 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
  11551. follow the
  11552. rules</a>.</p>
  11553. <p>So, option one: reset the logcontext before starting the operations to
  11554. be gathered:</p>
  11555. <pre><code class="language-python">async def do_request_handling():
  11556. with PreserveLoggingContext():
  11557. a1 = operation1()
  11558. a2 = operation2()
  11559. result = await defer.gatherResults([a1, a2])
  11560. </code></pre>
  11561. <p>In this case particularly, though, option two, of using
  11562. <code>context.run_in_background</code> almost certainly makes more sense, so that
  11563. <code>operation1</code> and <code>operation2</code> are both logged against the original
  11564. logcontext. This looks like:</p>
  11565. <pre><code class="language-python">async def do_request_handling():
  11566. a1 = context.run_in_background(operation1)
  11567. a2 = context.run_in_background(operation2)
  11568. result = await make_deferred_yieldable(defer.gatherResults([a1, a2]))
  11569. </code></pre>
  11570. <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>
  11571. <p>It turns out that our logcontext rules do not play nicely with awaitable
  11572. chains which get orphaned and garbage-collected.</p>
  11573. <p>Imagine we have some code that looks like this:</p>
  11574. <pre><code class="language-python">listener_queue = []
  11575. def on_something_interesting():
  11576. for d in listener_queue:
  11577. d.callback(&quot;foo&quot;)
  11578. async def await_something_interesting():
  11579. new_awaitable = defer.Deferred()
  11580. listener_queue.append(new_awaitable)
  11581. with PreserveLoggingContext():
  11582. await new_awaitable
  11583. </code></pre>
  11584. <p>Obviously, the idea here is that we have a bunch of things which are
  11585. waiting for an event. (It's just an example of the problem here, but a
  11586. relatively common one.)</p>
  11587. <p>Now let's imagine two further things happen. First of all, whatever was
  11588. waiting for the interesting thing goes away. (Perhaps the request times
  11589. out, or something <em>even more</em> interesting happens.)</p>
  11590. <p>Secondly, let's suppose that we decide that the interesting thing is
  11591. never going to happen, and we reset the listener queue:</p>
  11592. <pre><code class="language-python">def reset_listener_queue():
  11593. listener_queue.clear()
  11594. </code></pre>
  11595. <p>So, both ends of the awaitable chain have now dropped their references,
  11596. and the awaitable chain is now orphaned, and will be garbage-collected at
  11597. some point. Note that <code>await_something_interesting</code> is a coroutine,
  11598. which Python implements as a generator function. When Python
  11599. garbage-collects generator functions, it gives them a chance to
  11600. clean up by making the <code>async</code> (or <code>yield</code>) raise a <code>GeneratorExit</code>
  11601. exception. In our case, that means that the <code>__exit__</code> handler of
  11602. <code>PreserveLoggingContext</code> will carefully restore the request context, but
  11603. there is now nothing waiting for its return, so the request context is
  11604. never cleared.</p>
  11605. <p>To reiterate, this problem only arises when <em>both</em> ends of a awaitable
  11606. chain are dropped. Dropping the the reference to an awaitable you're
  11607. supposed to be awaiting is bad practice, so this doesn't
  11608. actually happen too much. Unfortunately, when it does happen, it will
  11609. lead to leaked logcontexts which are incredibly hard to track down.</p>
  11610. <div style="break-before: page; page-break-before: always;"></div><h1 id="replication-architecture"><a class="header" href="#replication-architecture">Replication Architecture</a></h1>
  11611. <h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
  11612. <p>We'd like to be able to split some of the work that synapse does into
  11613. multiple python processes. In theory multiple synapse processes could
  11614. share a single postgresql database and we'd scale up by running more
  11615. synapse processes. However much of synapse assumes that only one process
  11616. is interacting with the database, both for assigning unique identifiers
  11617. when inserting into tables, notifying components about new updates, and
  11618. for invalidating its caches.</p>
  11619. <p>So running multiple copies of the current code isn't an option. One way
  11620. to run multiple processes would be to have a single writer process and
  11621. multiple reader processes connected to the same database. In order to do
  11622. this we'd need a way for the reader process to invalidate its in-memory
  11623. caches when an update happens on the writer. One way to do this is for
  11624. the writer to present an append-only log of updates which the readers
  11625. can consume to invalidate their caches and to push updates to listening
  11626. clients or pushers.</p>
  11627. <p>Synapse already stores much of its data as an append-only log so that it
  11628. can correctly respond to <code>/sync</code> requests so the amount of code changes
  11629. needed to expose the append-only log to the readers should be fairly
  11630. minimal.</p>
  11631. <h2 id="architecture"><a class="header" href="#architecture">Architecture</a></h2>
  11632. <h3 id="the-replication-protocol"><a class="header" href="#the-replication-protocol">The Replication Protocol</a></h3>
  11633. <p>See <a href="tcp_replication.html">the TCP replication documentation</a>.</p>
  11634. <h3 id="the-slaved-datastore"><a class="header" href="#the-slaved-datastore">The Slaved DataStore</a></h3>
  11635. <p>There are read-only version of the synapse storage layer in
  11636. <code>synapse/replication/slave/storage</code> that use the response of the
  11637. replication API to invalidate their caches.</p>
  11638. <div style="break-before: page; page-break-before: always;"></div><h1 id="tcp-replication"><a class="header" href="#tcp-replication">TCP Replication</a></h1>
  11639. <h2 id="motivation-1"><a class="header" href="#motivation-1">Motivation</a></h2>
  11640. <p>Previously the workers used an HTTP long poll mechanism to get updates
  11641. from the master, which had the problem of causing a lot of duplicate
  11642. work on the server. This TCP protocol replaces those APIs with the aim
  11643. of increased efficiency.</p>
  11644. <h2 id="overview-3"><a class="header" href="#overview-3">Overview</a></h2>
  11645. <p>The protocol is based on fire and forget, line based commands. An
  11646. example flow would be (where '&gt;' indicates master to worker and
  11647. '&lt;' worker to master flows):</p>
  11648. <pre><code>&gt; SERVER example.com
  11649. &lt; REPLICATE
  11650. &gt; POSITION events master 53 53
  11651. &gt; RDATA events master 54 [&quot;$foo1:bar.com&quot;, ...]
  11652. &gt; RDATA events master 55 [&quot;$foo4:bar.com&quot;, ...]
  11653. </code></pre>
  11654. <p>The example shows the server accepting a new connection and sending its identity
  11655. with the <code>SERVER</code> command, followed by the client server to respond with the
  11656. position of all streams. The server then periodically sends <code>RDATA</code> commands
  11657. which have the format <code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row&gt;</code>, where
  11658. the format of <code>&lt;row&gt;</code> is defined by the individual streams. The
  11659. <code>&lt;instance_name&gt;</code> is the name of the Synapse process that generated the data
  11660. (usually &quot;master&quot;).</p>
  11661. <p>Error reporting happens by either the client or server sending an ERROR
  11662. command, and usually the connection will be closed.</p>
  11663. <p>Since the protocol is a simple line based, its possible to manually
  11664. connect to the server using a tool like netcat. A few things should be
  11665. noted when manually using the protocol:</p>
  11666. <ul>
  11667. <li>The federation stream is only available if federation sending has
  11668. been disabled on the main process.</li>
  11669. <li>The server will only time connections out that have sent a <code>PING</code>
  11670. command. If a ping is sent then the connection will be closed if no
  11671. further commands are receieved within 15s. Both the client and
  11672. server protocol implementations will send an initial PING on
  11673. connection and ensure at least one command every 5s is sent (not
  11674. necessarily <code>PING</code>).</li>
  11675. <li><code>RDATA</code> commands <em>usually</em> include a numeric token, however if the
  11676. stream has multiple rows to replicate per token the server will send
  11677. multiple <code>RDATA</code> commands, with all but the last having a token of
  11678. <code>batch</code>. See the documentation on <code>commands.RdataCommand</code> for
  11679. further details.</li>
  11680. </ul>
  11681. <h2 id="architecture-1"><a class="header" href="#architecture-1">Architecture</a></h2>
  11682. <p>The basic structure of the protocol is line based, where the initial
  11683. word of each line specifies the command. The rest of the line is parsed
  11684. based on the command. For example, the RDATA command is defined as:</p>
  11685. <pre><code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row_json&gt;
  11686. </code></pre>
  11687. <p>(Note that &lt;row_json&gt; may contains spaces, but cannot contain
  11688. newlines.)</p>
  11689. <p>Blank lines are ignored.</p>
  11690. <h3 id="keep-alives"><a class="header" href="#keep-alives">Keep alives</a></h3>
  11691. <p>Both sides are expected to send at least one command every 5s or so, and
  11692. should send a <code>PING</code> command if necessary. If either side do not receive
  11693. a command within e.g. 15s then the connection should be closed.</p>
  11694. <p>Because the server may be connected to manually using e.g. netcat, the
  11695. timeouts aren't enabled until an initial <code>PING</code> command is seen. Both
  11696. the client and server implementations below send a <code>PING</code> command
  11697. immediately on connection to ensure the timeouts are enabled.</p>
  11698. <p>This ensures that both sides can quickly realize if the tcp connection
  11699. has gone and handle the situation appropriately.</p>
  11700. <h3 id="start-up"><a class="header" href="#start-up">Start up</a></h3>
  11701. <p>When a new connection is made, the server:</p>
  11702. <ul>
  11703. <li>Sends a <code>SERVER</code> command, which includes the identity of the server,
  11704. allowing the client to detect if its connected to the expected
  11705. server</li>
  11706. <li>Sends a <code>PING</code> command as above, to enable the client to time out
  11707. connections promptly.</li>
  11708. </ul>
  11709. <p>The client:</p>
  11710. <ul>
  11711. <li>Sends a <code>NAME</code> command, allowing the server to associate a human
  11712. friendly name with the connection. This is optional.</li>
  11713. <li>Sends a <code>PING</code> as above</li>
  11714. <li>Sends a <code>REPLICATE</code> to get the current position of all streams.</li>
  11715. <li>On receipt of a <code>SERVER</code> command, checks that the server name
  11716. matches the expected server name.</li>
  11717. </ul>
  11718. <h3 id="error-handling"><a class="header" href="#error-handling">Error handling</a></h3>
  11719. <p>If either side detects an error it can send an <code>ERROR</code> command and close
  11720. the connection.</p>
  11721. <p>If the client side loses the connection to the server it should
  11722. reconnect, following the steps above.</p>
  11723. <h3 id="congestion"><a class="header" href="#congestion">Congestion</a></h3>
  11724. <p>If the server sends messages faster than the client can consume them the
  11725. server will first buffer a (fairly large) number of commands and then
  11726. disconnect the client. This ensures that we don't queue up an unbounded
  11727. number of commands in memory and gives us a potential oppurtunity to
  11728. squawk loudly. When/if the client recovers it can reconnect to the
  11729. server and ask for missed messages.</p>
  11730. <h3 id="reliability"><a class="header" href="#reliability">Reliability</a></h3>
  11731. <p>In general the replication stream should be considered an unreliable
  11732. transport since e.g. commands are not resent if the connection
  11733. disappears.</p>
  11734. <p>The exception to that are the replication streams, i.e. RDATA commands,
  11735. since these include tokens which can be used to restart the stream on
  11736. connection errors.</p>
  11737. <p>The client should keep track of the token in the last RDATA command
  11738. received for each stream so that on reconneciton it can start streaming
  11739. from the correct place. Note: not all RDATA have valid tokens due to
  11740. batching. See <code>RdataCommand</code> for more details.</p>
  11741. <h3 id="example-5"><a class="header" href="#example-5">Example</a></h3>
  11742. <p>An example iteraction is shown below. Each line is prefixed with '&gt;'
  11743. or '&lt;' to indicate which side is sending, these are <em>not</em> included on
  11744. the wire:</p>
  11745. <pre><code>* connection established *
  11746. &gt; SERVER localhost:8823
  11747. &gt; PING 1490197665618
  11748. &lt; NAME synapse.app.appservice
  11749. &lt; PING 1490197665618
  11750. &lt; REPLICATE
  11751. &gt; POSITION events master 1 1
  11752. &gt; POSITION backfill master 1 1
  11753. &gt; POSITION caches master 1 1
  11754. &gt; RDATA caches master 2 [&quot;get_user_by_id&quot;,[&quot;@01register-user:localhost:8823&quot;],1490197670513]
  11755. &gt; RDATA events master 14 [&quot;$149019767112vOHxz:localhost:8823&quot;,
  11756. &quot;!AFDCvgApUmpdfVjIXm:localhost:8823&quot;,&quot;m.room.guest_access&quot;,&quot;&quot;,null]
  11757. &lt; PING 1490197675618
  11758. &gt; ERROR server stopping
  11759. * connection closed by server *
  11760. </code></pre>
  11761. <p>The <code>POSITION</code> command sent by the server is used to set the clients
  11762. position without needing to send data with the <code>RDATA</code> command.</p>
  11763. <p>An example of a batched set of <code>RDATA</code> is:</p>
  11764. <pre><code>&gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test:localhost:8823&quot;],1490197670513]
  11765. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test2:localhost:8823&quot;],1490197670513]
  11766. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test3:localhost:8823&quot;],1490197670513]
  11767. &gt; RDATA caches master 54 [&quot;get_user_by_id&quot;,[&quot;@test4:localhost:8823&quot;],1490197670513]
  11768. </code></pre>
  11769. <p>In this case the client shouldn't advance their caches token until it
  11770. sees the the last <code>RDATA</code>.</p>
  11771. <h3 id="list-of-commands"><a class="header" href="#list-of-commands">List of commands</a></h3>
  11772. <p>The list of valid commands, with which side can send it: server (S) or
  11773. client (C):</p>
  11774. <h4 id="server-s"><a class="header" href="#server-s">SERVER (S)</a></h4>
  11775. <p>Sent at the start to identify which server the client is talking to</p>
  11776. <h4 id="rdata-s"><a class="header" href="#rdata-s">RDATA (S)</a></h4>
  11777. <p>A single update in a stream</p>
  11778. <h4 id="position-s"><a class="header" href="#position-s">POSITION (S)</a></h4>
  11779. <p>On receipt of a POSITION command clients should check if they have missed any
  11780. updates, and if so then fetch them out of band. Sent in response to a
  11781. REPLICATE command (but can happen at any time).</p>
  11782. <p>The POSITION command includes the source of the stream. Currently all streams
  11783. are written by a single process (usually &quot;master&quot;). If fetching missing
  11784. updates via HTTP API, rather than via the DB, then processes should make the
  11785. request to the appropriate process.</p>
  11786. <p>Two positions are included, the &quot;new&quot; position and the last position sent respectively.
  11787. This allows servers to tell instances that the positions have advanced but no
  11788. data has been written, without clients needlessly checking to see if they
  11789. have missed any updates.</p>
  11790. <h4 id="error-s-c"><a class="header" href="#error-s-c">ERROR (S, C)</a></h4>
  11791. <p>There was an error</p>
  11792. <h4 id="ping-s-c"><a class="header" href="#ping-s-c">PING (S, C)</a></h4>
  11793. <p>Sent periodically to ensure the connection is still alive</p>
  11794. <h4 id="name-c"><a class="header" href="#name-c">NAME (C)</a></h4>
  11795. <p>Sent at the start by client to inform the server who they are</p>
  11796. <h4 id="replicate-c"><a class="header" href="#replicate-c">REPLICATE (C)</a></h4>
  11797. <p>Asks the server for the current position of all streams.</p>
  11798. <h4 id="user_sync-c"><a class="header" href="#user_sync-c">USER_SYNC (C)</a></h4>
  11799. <p>A user has started or stopped syncing on this process.</p>
  11800. <h4 id="clear_user_sync-c"><a class="header" href="#clear_user_sync-c">CLEAR_USER_SYNC (C)</a></h4>
  11801. <p>The server should clear all associated user sync data from the worker.</p>
  11802. <p>This is used when a worker is shutting down.</p>
  11803. <h4 id="federation_ack-c"><a class="header" href="#federation_ack-c">FEDERATION_ACK (C)</a></h4>
  11804. <p>Acknowledge receipt of some federation data</p>
  11805. <h3 id="remote_server_up-s-c"><a class="header" href="#remote_server_up-s-c">REMOTE_SERVER_UP (S, C)</a></h3>
  11806. <p>Inform other processes that a remote server may have come back online.</p>
  11807. <p>See <code>synapse/replication/tcp/commands.py</code> for a detailed description and
  11808. the format of each command.</p>
  11809. <h3 id="cache-invalidation-stream"><a class="header" href="#cache-invalidation-stream">Cache Invalidation Stream</a></h3>
  11810. <p>The cache invalidation stream is used to inform workers when they need
  11811. to invalidate any of their caches in the data store. This is done by
  11812. streaming all cache invalidations done on master down to the workers,
  11813. assuming that any caches on the workers also exist on the master.</p>
  11814. <p>Each individual cache invalidation results in a row being sent down
  11815. replication, which includes the cache name (the name of the function)
  11816. and they key to invalidate. For example:</p>
  11817. <pre><code>&gt; RDATA caches master 550953771 [&quot;get_user_by_id&quot;, [&quot;@bob:example.com&quot;], 1550574873251]
  11818. </code></pre>
  11819. <p>Alternatively, an entire cache can be invalidated by sending down a <code>null</code>
  11820. instead of the key. For example:</p>
  11821. <pre><code>&gt; RDATA caches master 550953772 [&quot;get_user_by_id&quot;, null, 1550574873252]
  11822. </code></pre>
  11823. <p>However, there are times when a number of caches need to be invalidated
  11824. at the same time with the same key. To reduce traffic we batch those
  11825. invalidations into a single poke by defining a special cache name that
  11826. workers understand to mean to expand to invalidate the correct caches.</p>
  11827. <p>Currently the special cache names are declared in
  11828. <code>synapse/storage/_base.py</code> and are:</p>
  11829. <ol>
  11830. <li><code>cs_cache_fake</code> ─ invalidates caches that depend on the current
  11831. state</li>
  11832. </ol>
  11833. <div style="break-before: page; page-break-before: always;"></div><h1 id="internal-documentation"><a class="header" href="#internal-documentation">Internal Documentation</a></h1>
  11834. <p>This section covers implementation documentation for various parts of Synapse.</p>
  11835. <p>If a developer is planning to make a change to a feature of Synapse, it can be useful for
  11836. general documentation of how that feature is implemented to be available. This saves the
  11837. developer time in place of needing to understand how the feature works by reading the
  11838. code.</p>
  11839. <p>Documentation that would be more useful for the perspective of a system administrator,
  11840. rather than a developer who's intending to change to code, should instead be placed
  11841. under the Usage section of the documentation.</p>
  11842. <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>
  11843. <p>https://capriza.github.io/samling/samling.html (https://github.com/capriza/samling) is a great
  11844. resource for being able to tinker with the SAML options within Synapse without needing to
  11845. deploy and configure a complicated software stack.</p>
  11846. <p>To make Synapse (and therefore Riot) use it:</p>
  11847. <ol>
  11848. <li>Use the samling.html URL above or deploy your own and visit the IdP Metadata tab.</li>
  11849. <li>Copy the XML to your clipboard.</li>
  11850. <li>On your Synapse server, create a new file <code>samling.xml</code> next to your <code>homeserver.yaml</code> with
  11851. the XML from step 2 as the contents.</li>
  11852. <li>Edit your <code>homeserver.yaml</code> to include:
  11853. <pre><code class="language-yaml">saml2_config:
  11854. sp_config:
  11855. allow_unknown_attributes: true # Works around a bug with AVA Hashes: https://github.com/IdentityPython/pysaml2/issues/388
  11856. metadata:
  11857. local: [&quot;samling.xml&quot;]
  11858. </code></pre>
  11859. </li>
  11860. <li>Ensure that your <code>homeserver.yaml</code> has a setting for <code>public_baseurl</code>:
  11861. <pre><code class="language-yaml">public_baseurl: http://localhost:8080/
  11862. </code></pre>
  11863. </li>
  11864. <li>Run <code>apt-get install xmlsec1</code> and <code>pip install --upgrade --force 'pysaml2&gt;=4.5.0'</code> to ensure
  11865. the dependencies are installed and ready to go.</li>
  11866. <li>Restart Synapse.</li>
  11867. </ol>
  11868. <p>Then in Riot:</p>
  11869. <ol>
  11870. <li>Visit the login page with a Riot pointing at your homeserver.</li>
  11871. <li>Click the Single Sign-On button.</li>
  11872. <li>On the samling page, enter a Name Identifier and add a SAML Attribute for <code>uid=your_localpart</code>.
  11873. The response must also be signed.</li>
  11874. <li>Click &quot;Next&quot;.</li>
  11875. <li>Click &quot;Post Response&quot; (change nothing).</li>
  11876. <li>You should be logged in.</li>
  11877. </ol>
  11878. <p>If you try and repeat this process, you may be automatically logged in using the information you
  11879. gave previously. To fix this, open your developer console (<code>F12</code> or <code>Ctrl+Shift+I</code>) while on the
  11880. samling page and clear the site data. In Chrome, this will be a button on the Application tab.</p>
  11881. <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>
  11882. <p>The <a href="https://github.com/jbittel/django-mama-cas">django-mama-cas</a> project is an
  11883. easy to run CAS implementation built on top of Django.</p>
  11884. <h2 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h2>
  11885. <ol>
  11886. <li>Create a new virtualenv: <code>python3 -m venv &lt;your virtualenv&gt;</code></li>
  11887. <li>Activate your virtualenv: <code>source /path/to/your/virtualenv/bin/activate</code></li>
  11888. <li>Install Django and django-mama-cas:
  11889. <pre><code>python -m pip install &quot;django&lt;3&quot; &quot;django-mama-cas==2.4.0&quot;
  11890. </code></pre>
  11891. </li>
  11892. <li>Create a Django project in the current directory:
  11893. <pre><code>django-admin startproject cas_test .
  11894. </code></pre>
  11895. </li>
  11896. <li>Follow the <a href="https://django-mama-cas.readthedocs.io/en/latest/installation.html#configuring">install directions</a> for django-mama-cas</li>
  11897. <li>Setup the SQLite database: <code>python manage.py migrate</code></li>
  11898. <li>Create a user:
  11899. <pre><code>python manage.py createsuperuser
  11900. </code></pre>
  11901. <ol>
  11902. <li>Use whatever you want as the username and password.</li>
  11903. <li>Leave the other fields blank.</li>
  11904. </ol>
  11905. </li>
  11906. <li>Use the built-in Django test server to serve the CAS endpoints on port 8000:
  11907. <pre><code>python manage.py runserver
  11908. </code></pre>
  11909. </li>
  11910. </ol>
  11911. <p>You should now have a Django project configured to serve CAS authentication with
  11912. a single user created.</p>
  11913. <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>
  11914. <ol>
  11915. <li>Modify your <code>homeserver.yaml</code> to enable CAS and point it to your locally
  11916. running Django test server:
  11917. <pre><code class="language-yaml">cas_config:
  11918. enabled: true
  11919. server_url: &quot;http://localhost:8000&quot;
  11920. service_url: &quot;http://localhost:8081&quot;
  11921. #displayname_attribute: name
  11922. #required_attributes:
  11923. # name: value
  11924. </code></pre>
  11925. </li>
  11926. <li>Restart Synapse.</li>
  11927. </ol>
  11928. <p>Note that the above configuration assumes the homeserver is running on port 8081
  11929. and that the CAS server is on port 8000, both on localhost.</p>
  11930. <h2 id="testing-the-configuration"><a class="header" href="#testing-the-configuration">Testing the configuration</a></h2>
  11931. <p>Then in Element:</p>
  11932. <ol>
  11933. <li>Visit the login page with a Element pointing at your homeserver.</li>
  11934. <li>Click the Single Sign-On button.</li>
  11935. <li>Login using the credentials created with <code>createsuperuser</code>.</li>
  11936. <li>You should be logged in.</li>
  11937. </ol>
  11938. <p>If you want to repeat this process you'll need to manually logout first:</p>
  11939. <ol>
  11940. <li>http://localhost:8000/admin/</li>
  11941. <li>Click &quot;logout&quot; in the top right.</li>
  11942. </ol>
  11943. <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>
  11944. <p>The auth chain difference algorithm is used by V2 state resolution, where a
  11945. naive implementation can be a significant source of CPU and DB usage.</p>
  11946. <h3 id="definitions"><a class="header" href="#definitions">Definitions</a></h3>
  11947. <p>A <em>state set</em> is a set of state events; e.g. the input of a state resolution
  11948. algorithm is a collection of state sets.</p>
  11949. <p>The <em>auth chain</em> of a set of events are all the events' auth events and <em>their</em>
  11950. auth events, recursively (i.e. the events reachable by walking the graph induced
  11951. by an event's auth events links).</p>
  11952. <p>The <em>auth chain difference</em> of a collection of state sets is the union minus the
  11953. intersection of the sets of auth chains corresponding to the state sets, i.e an
  11954. event is in the auth chain difference if it is reachable by walking the auth
  11955. event graph from at least one of the state sets but not from <em>all</em> of the state
  11956. sets.</p>
  11957. <h2 id="breadth-first-walk-algorithm"><a class="header" href="#breadth-first-walk-algorithm">Breadth First Walk Algorithm</a></h2>
  11958. <p>A way of calculating the auth chain difference without calculating the full auth
  11959. chains for each state set is to do a parallel breadth first walk (ordered by
  11960. depth) of each state set's auth chain. By tracking which events are reachable
  11961. from each state set we can finish early if every pending event is reachable from
  11962. every state set.</p>
  11963. <p>This can work well for state sets that have a small auth chain difference, but
  11964. can be very inefficient for larger differences. However, this algorithm is still
  11965. used if we don't have a chain cover index for the room (e.g. because we're in
  11966. the process of indexing it).</p>
  11967. <h2 id="chain-cover-index"><a class="header" href="#chain-cover-index">Chain Cover Index</a></h2>
  11968. <p>Synapse computes auth chain differences by pre-computing a &quot;chain cover&quot; index
  11969. for the auth chain in a room, allowing efficient reachability queries like &quot;is
  11970. event A in the auth chain of event B&quot;. This is done by assigning every event a
  11971. <em>chain ID</em> and <em>sequence number</em> (e.g. <code>(5,3)</code>), and having a map of <em>links</em>
  11972. between chains (e.g. <code>(5,3) -&gt; (2,4)</code>) such that A is reachable by B (i.e. <code>A</code>
  11973. is in the auth chain of <code>B</code>) if and only if either:</p>
  11974. <ol>
  11975. <li>A and B have the same chain ID and <code>A</code>'s sequence number is less than <code>B</code>'s
  11976. sequence number; or</li>
  11977. <li>there is a link <code>L</code> between <code>B</code>'s chain ID and <code>A</code>'s chain ID such that
  11978. <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>
  11979. </ol>
  11980. <p>There are actually two potential implementations, one where we store links from
  11981. each chain to every other reachable chain (the transitive closure of the links
  11982. graph), and one where we remove redundant links (the transitive reduction of the
  11983. links graph) e.g. if we have chains <code>C3 -&gt; C2 -&gt; C1</code> then the link <code>C3 -&gt; C1</code>
  11984. would not be stored. Synapse uses the former implementations so that it doesn't
  11985. need to recurse to test reachability between chains.</p>
  11986. <h3 id="example-6"><a class="header" href="#example-6">Example</a></h3>
  11987. <p>An example auth graph would look like the following, where chains have been
  11988. formed based on type/state_key and are denoted by colour and are labelled with
  11989. <code>(chain ID, sequence number)</code>. Links are denoted by the arrows (links in grey
  11990. are those that would be remove in the second implementation described above).</p>
  11991. <p><img src="auth_chain_diff.dot.png" alt="Example" /></p>
  11992. <p>Note that we don't include all links between events and their auth events, as
  11993. most of those links would be redundant. For example, all events point to the
  11994. create event, but each chain only needs the one link from it's base to the
  11995. create event.</p>
  11996. <h2 id="using-the-index"><a class="header" href="#using-the-index">Using the Index</a></h2>
  11997. <p>This index can be used to calculate the auth chain difference of the state sets
  11998. by looking at the chain ID and sequence numbers reachable from each state set:</p>
  11999. <ol>
  12000. <li>For every state set lookup the chain ID/sequence numbers of each state event</li>
  12001. <li>Use the index to find all chains and the maximum sequence number reachable
  12002. from each state set.</li>
  12003. <li>The auth chain difference is then all events in each chain that have sequence
  12004. numbers between the maximum sequence number reachable from <em>any</em> state set and
  12005. the minimum reachable by <em>all</em> state sets (if any).</li>
  12006. </ol>
  12007. <p>Note that steps 2 is effectively calculating the auth chain for each state set
  12008. (in terms of chain IDs and sequence numbers), and step 3 is calculating the
  12009. difference between the union and intersection of the auth chains.</p>
  12010. <h3 id="worked-example"><a class="header" href="#worked-example">Worked Example</a></h3>
  12011. <p>For example, given the above graph, we can calculate the difference between
  12012. state sets consisting of:</p>
  12013. <ol>
  12014. <li><code>S1</code>: Alice's invite <code>(4,1)</code> and Bob's second join <code>(2,2)</code>; and</li>
  12015. <li><code>S2</code>: Alice's second join <code>(4,3)</code> and Bob's first join <code>(2,1)</code>.</li>
  12016. </ol>
  12017. <p>Using the index we see that the following auth chains are reachable from each
  12018. state set:</p>
  12019. <ol>
  12020. <li><code>S1</code>: <code>(1,1)</code>, <code>(2,2)</code>, <code>(3,1)</code> &amp; <code>(4,1)</code></li>
  12021. <li><code>S2</code>: <code>(1,1)</code>, <code>(2,1)</code>, <code>(3,2)</code> &amp; <code>(4,3)</code></li>
  12022. </ol>
  12023. <p>And so, for each the ranges that are in the auth chain difference:</p>
  12024. <ol>
  12025. <li>Chain 1: None, (since everything can reach the create event).</li>
  12026. <li>Chain 2: The range <code>(1, 2]</code> (i.e. just <code>2</code>), as <code>1</code> is reachable by all state
  12027. sets and the maximum reachable is <code>2</code> (corresponding to Bob's second join).</li>
  12028. <li>Chain 3: Similarly the range <code>(1, 2]</code> (corresponding to the second power
  12029. level).</li>
  12030. <li>Chain 4: The range <code>(1, 3]</code> (corresponding to both of Alice's joins).</li>
  12031. </ol>
  12032. <p>So the final result is: Bob's second join <code>(2,2)</code>, the second power level
  12033. <code>(3,2)</code> and both of Alice's joins <code>(4,2)</code> &amp; <code>(4,3)</code>.</p>
  12034. <div style="break-before: page; page-break-before: always;"></div><h1 id="media-repository"><a class="header" href="#media-repository">Media Repository</a></h1>
  12035. <p><em>Synapse implementation-specific details for the media repository</em></p>
  12036. <p>The media repository is where attachments and avatar photos are stored.
  12037. It stores attachment content and thumbnails for media uploaded by local users.
  12038. It caches attachment content and thumbnails for media uploaded by remote users.</p>
  12039. <h2 id="storage"><a class="header" href="#storage">Storage</a></h2>
  12040. <p>Each item of media is assigned a <code>media_id</code> when it is uploaded.
  12041. The <code>media_id</code> is a randomly chosen, URL safe 24 character string.</p>
  12042. <p>Metadata such as the MIME type, upload time and length are stored in the
  12043. sqlite3 database indexed by <code>media_id</code>.</p>
  12044. <p>Content is stored on the filesystem under a <code>&quot;local_content&quot;</code> directory.</p>
  12045. <p>Thumbnails are stored under a <code>&quot;local_thumbnails&quot;</code> directory.</p>
  12046. <p>The item with <code>media_id</code> <code>&quot;aabbccccccccdddddddddddd&quot;</code> is stored under
  12047. <code>&quot;local_content/aa/bb/ccccccccdddddddddddd&quot;</code>. Its thumbnail with width
  12048. <code>128</code> and height <code>96</code> and type <code>&quot;image/jpeg&quot;</code> is stored under
  12049. <code>&quot;local_thumbnails/aa/bb/ccccccccdddddddddddd/128-96-image-jpeg&quot;</code></p>
  12050. <p>Remote content is cached under <code>&quot;remote_content&quot;</code> directory. Each item of
  12051. remote content is assigned a local <code>&quot;filesystem_id&quot;</code> to ensure that the
  12052. directory structure <code>&quot;remote_content/server_name/aa/bb/ccccccccdddddddddddd&quot;</code>
  12053. is appropriate. Thumbnails for remote content are stored under
  12054. <code>&quot;remote_thumbnails/server_name/...&quot;</code></p>
  12055. <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>
  12056. <p>Synapse maintains room and user statistics in various tables. These can be used
  12057. for administrative purposes but are also used when generating the public room
  12058. directory.</p>
  12059. <h1 id="synapse-developer-documentation"><a class="header" href="#synapse-developer-documentation">Synapse Developer Documentation</a></h1>
  12060. <h2 id="high-level-concepts"><a class="header" href="#high-level-concepts">High-Level Concepts</a></h2>
  12061. <h3 id="definitions-1"><a class="header" href="#definitions-1">Definitions</a></h3>
  12062. <ul>
  12063. <li><strong>subject</strong>: Something we are tracking stats about – currently a room or user.</li>
  12064. <li><strong>current row</strong>: An entry for a subject in the appropriate current statistics
  12065. table. Each subject can have only one.</li>
  12066. </ul>
  12067. <h3 id="overview-4"><a class="header" href="#overview-4">Overview</a></h3>
  12068. <p>Stats correspond to the present values. Current rows contain the most up-to-date
  12069. statistics for a room. Each subject can only have one entry.</p>
  12070. <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>
  12071. <p>Synapse has a number of platform dependencies, including Python and PostgreSQL.
  12072. This document outlines the policy towards which versions we support, and when we
  12073. drop support for versions in the future.</p>
  12074. <h2 id="policy"><a class="header" href="#policy">Policy</a></h2>
  12075. <p>Synapse follows the upstream support life cycles for Python and PostgreSQL,
  12076. i.e. when a version reaches End of Life Synapse will withdraw support for that
  12077. version in future releases.</p>
  12078. <p>Details on the upstream support life cycles for Python and PostgreSQL are
  12079. documented at https://endoflife.date/python and
  12080. https://endoflife.date/postgresql.</p>
  12081. <h2 id="context"><a class="header" href="#context">Context</a></h2>
  12082. <p>It is important for system admins to have a clear understanding of the platform
  12083. requirements of Synapse and its deprecation policies so that they can
  12084. effectively plan upgrading their infrastructure ahead of time. This is
  12085. especially important in contexts where upgrading the infrastructure requires
  12086. auditing and approval from a security team, or where otherwise upgrading is a
  12087. long process.</p>
  12088. <p>By following the upstream support life cycles Synapse can ensure that its
  12089. dependencies continue to get security patches, while not requiring system admins
  12090. to constantly update their platform dependencies to the latest versions.</p>
  12091. </main>
  12092. <nav class="nav-wrapper" aria-label="Page navigation">
  12093. <!-- Mobile navigation buttons -->
  12094. <div style="clear: both"></div>
  12095. </nav>
  12096. </div>
  12097. </div>
  12098. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  12099. </nav>
  12100. </div>
  12101. <script type="text/javascript">
  12102. window.playground_copyable = true;
  12103. </script>
  12104. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  12105. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  12106. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  12107. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  12108. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  12109. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  12110. <!-- Custom JS scripts -->
  12111. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  12112. <script type="text/javascript" src="docs/website_files/version-picker.js"></script>
  12113. <script type="text/javascript" src="docs/website_files/version.js"></script>
  12114. <script type="text/javascript">
  12115. window.addEventListener('load', function() {
  12116. window.setTimeout(window.print, 100);
  12117. });
  12118. </script>
  12119. </body>
  12120. </html>