print.html 653 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790
  1. <!DOCTYPE HTML>
  2. <html lang="en" class="sidebar-visible no-js light">
  3. <head>
  4. <!-- Book generated using mdBook -->
  5. <meta charset="UTF-8">
  6. <title>Synapse</title>
  7. <meta name="robots" content="noindex" />
  8. <!-- Custom HTML head -->
  9. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  10. <meta name="description" content="">
  11. <meta name="viewport" content="width=device-width, initial-scale=1">
  12. <meta name="theme-color" content="#ffffff" />
  13. <link rel="icon" href="favicon.svg">
  14. <link rel="shortcut icon" href="favicon.png">
  15. <link rel="stylesheet" href="css/variables.css">
  16. <link rel="stylesheet" href="css/general.css">
  17. <link rel="stylesheet" href="css/chrome.css">
  18. <link rel="stylesheet" href="css/print.css" media="print">
  19. <!-- Fonts -->
  20. <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
  21. <link rel="stylesheet" href="fonts/fonts.css">
  22. <!-- Highlight.js Stylesheets -->
  23. <link rel="stylesheet" href="highlight.css">
  24. <link rel="stylesheet" href="tomorrow-night.css">
  25. <link rel="stylesheet" href="ayu-highlight.css">
  26. <!-- Custom theme stylesheets -->
  27. <link rel="stylesheet" href="docs/website_files/table-of-contents.css">
  28. <link rel="stylesheet" href="docs/website_files/remove-nav-buttons.css">
  29. <link rel="stylesheet" href="docs/website_files/indent-section-headers.css">
  30. </head>
  31. <body>
  32. <!-- Provide site root to javascript -->
  33. <script type="text/javascript">
  34. var path_to_root = "";
  35. var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
  36. </script>
  37. <!-- Work around some values being stored in localStorage wrapped in quotes -->
  38. <script type="text/javascript">
  39. try {
  40. var theme = localStorage.getItem('mdbook-theme');
  41. var sidebar = localStorage.getItem('mdbook-sidebar');
  42. if (theme.startsWith('"') && theme.endsWith('"')) {
  43. localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
  44. }
  45. if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
  46. localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
  47. }
  48. } catch (e) { }
  49. </script>
  50. <!-- Set the theme before any content is loaded, prevents flash -->
  51. <script type="text/javascript">
  52. var theme;
  53. try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
  54. if (theme === null || theme === undefined) { theme = default_theme; }
  55. var html = document.querySelector('html');
  56. html.classList.remove('no-js')
  57. html.classList.remove('light')
  58. html.classList.add(theme);
  59. html.classList.add('js');
  60. </script>
  61. <!-- Hide / unhide sidebar before it is displayed -->
  62. <script type="text/javascript">
  63. var html = document.querySelector('html');
  64. var sidebar = 'hidden';
  65. if (document.body.clientWidth >= 1080) {
  66. try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
  67. sidebar = sidebar || 'visible';
  68. }
  69. html.classList.remove('sidebar-visible');
  70. html.classList.add("sidebar-" + sidebar);
  71. </script>
  72. <nav id="sidebar" class="sidebar" aria-label="Table of contents">
  73. <div class="sidebar-scrollbox">
  74. <ol class="chapter"><li class="chapter-item expanded affix "><li class="part-title">Introduction</li><li class="chapter-item expanded "><a href="welcome_and_overview.html">Welcome and Overview</a></li><li class="chapter-item expanded affix "><li class="part-title">Setup</li><li class="chapter-item expanded "><a href="setup/installation.html">Installation</a></li><li class="chapter-item expanded "><a href="postgres.html">Using Postgres</a></li><li class="chapter-item expanded "><a href="reverse_proxy.html">Configuring a Reverse Proxy</a></li><li class="chapter-item expanded "><a href="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>
  75. </div>
  76. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  77. </nav>
  78. <div id="page-wrapper" class="page-wrapper">
  79. <div class="page">
  80. <div id="menu-bar-hover-placeholder"></div>
  81. <div id="menu-bar" class="menu-bar sticky bordered">
  82. <div class="left-buttons">
  83. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  84. <i class="fa fa-bars"></i>
  85. </button>
  86. <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
  87. <i class="fa fa-paint-brush"></i>
  88. </button>
  89. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  90. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  91. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  94. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  95. </ul>
  96. <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
  97. <i class="fa fa-search"></i>
  98. </button>
  99. </div>
  100. <h1 class="menu-title">Synapse</h1>
  101. <div class="right-buttons">
  102. <a href="print.html" title="Print this book" aria-label="Print this book">
  103. <i id="print-button" class="fa fa-print"></i>
  104. </a>
  105. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  106. <i id="git-repository-button" class="fa fa-github"></i>
  107. </a>
  108. </div>
  109. </div>
  110. <div id="search-wrapper" class="hidden">
  111. <form id="searchbar-outer" class="searchbar-outer">
  112. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  113. </form>
  114. <div id="searchresults-outer" class="searchresults-outer hidden">
  115. <div id="searchresults-header" class="searchresults-header"></div>
  116. <ul id="searchresults">
  117. </ul>
  118. </div>
  119. </div>
  120. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  121. <script type="text/javascript">
  122. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  123. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  124. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  125. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  126. });
  127. </script>
  128. <div id="content" class="content">
  129. <main>
  130. <!-- Page table of contents -->
  131. <div class="sidetoc">
  132. <nav class="pagetoc"></nav>
  133. </div>
  134. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="introduction"><a class="header" href="#introduction">Introduction</a></h1>
  135. <p>Welcome to the documentation repository for Synapse, the reference
  136. <a href="https://matrix.org">Matrix</a> homeserver implementation.</p>
  137. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="installation-instructions"><a class="header" href="#installation-instructions">Installation Instructions</a></h1>
  138. <p>There are 3 steps to follow under <strong>Installation Instructions</strong>.</p>
  139. <ul>
  140. <li><a href="setup/installation.html#installation-instructions">Installation Instructions</a>
  141. <ul>
  142. <li><a href="setup/installation.html#choosing-your-server-name">Choosing your server name</a></li>
  143. <li><a href="setup/installation.html#installing-synapse">Installing Synapse</a>
  144. <ul>
  145. <li><a href="setup/installation.html#installing-from-source">Installing from source</a>
  146. <ul>
  147. <li><a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a>
  148. <ul>
  149. <li><a href="setup/installation.html#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></li>
  150. <li><a href="setup/installation.html#archlinux">ArchLinux</a></li>
  151. <li><a href="setup/installation.html#centosfedora">CentOS/Fedora</a></li>
  152. <li><a href="setup/installation.html#macos">macOS</a></li>
  153. <li><a href="setup/installation.html#opensuse">OpenSUSE</a></li>
  154. <li><a href="setup/installation.html#openbsd">OpenBSD</a></li>
  155. <li><a href="setup/installation.html#windows">Windows</a></li>
  156. </ul>
  157. </li>
  158. </ul>
  159. </li>
  160. <li><a href="setup/installation.html#prebuilt-packages">Prebuilt packages</a>
  161. <ul>
  162. <li><a href="setup/installation.html#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></li>
  163. <li><a href="setup/installation.html#debianubuntu">Debian/Ubuntu</a>
  164. <ul>
  165. <li><a href="setup/installation.html#matrixorg-packages">Matrix.org packages</a></li>
  166. <li><a href="setup/installation.html#downstream-debian-packages">Downstream Debian packages</a></li>
  167. <li><a href="setup/installation.html#downstream-ubuntu-packages">Downstream Ubuntu packages</a></li>
  168. </ul>
  169. </li>
  170. <li><a href="setup/installation.html#fedora">Fedora</a></li>
  171. <li><a href="setup/installation.html#opensuse-1">OpenSUSE</a></li>
  172. <li><a href="setup/installation.html#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></li>
  173. <li><a href="setup/installation.html#archlinux-1">ArchLinux</a></li>
  174. <li><a href="setup/installation.html#void-linux">Void Linux</a></li>
  175. <li><a href="setup/installation.html#freebsd">FreeBSD</a></li>
  176. <li><a href="setup/installation.html#openbsd-1">OpenBSD</a></li>
  177. <li><a href="setup/installation.html#nixos">NixOS</a></li>
  178. </ul>
  179. </li>
  180. </ul>
  181. </li>
  182. <li><a href="setup/installation.html#setting-up-synapse">Setting up Synapse</a>
  183. <ul>
  184. <li><a href="setup/installation.html#using-postgresql">Using PostgreSQL</a></li>
  185. <li><a href="setup/installation.html#tls-certificates">TLS certificates</a></li>
  186. <li><a href="setup/installation.html#client-well-known-uri">Client Well-Known URI</a></li>
  187. <li><a href="setup/installation.html#email">Email</a></li>
  188. <li><a href="setup/installation.html#registering-a-user">Registering a user</a></li>
  189. <li><a href="setup/installation.html#setting-up-a-turn-server">Setting up a TURN server</a></li>
  190. <li><a href="setup/installation.html#url-previews">URL previews</a></li>
  191. <li><a href="setup/installation.html#troubleshooting-installation">Troubleshooting Installation</a></li>
  192. </ul>
  193. </li>
  194. </ul>
  195. </li>
  196. </ul>
  197. <h2 id="choosing-your-server-name"><a class="header" href="#choosing-your-server-name">Choosing your server name</a></h2>
  198. <p>It is important to choose the name for your server before you install Synapse,
  199. because it cannot be changed later.</p>
  200. <p>The server name determines the &quot;domain&quot; part of user-ids for users on your
  201. server: these will all be of the format <code>@user:my.domain.name</code>. It also
  202. determines how other matrix servers will reach yours for federation.</p>
  203. <p>For a test configuration, set this to the hostname of your server. For a more
  204. production-ready setup, you will probably want to specify your domain
  205. (<code>example.com</code>) rather than a matrix-specific hostname here (in the same way
  206. that your email address is probably <code>user@example.com</code> rather than
  207. <code>user@email.example.com</code>) - but doing so may require more advanced setup: see
  208. <a href="setup/../federate.html">Setting up Federation</a>.</p>
  209. <h2 id="installing-synapse"><a class="header" href="#installing-synapse">Installing Synapse</a></h2>
  210. <h3 id="installing-from-source"><a class="header" href="#installing-from-source">Installing from source</a></h3>
  211. <p>(Prebuilt packages are available for some platforms - see <a href="setup/installation.html#prebuilt-packages">Prebuilt packages</a>.)</p>
  212. <p>When installing from source please make sure that the <a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a> are already installed.</p>
  213. <p>System requirements:</p>
  214. <ul>
  215. <li>POSIX-compliant system (tested on Linux &amp; OS X)</li>
  216. <li>Python 3.5.2 or later, up to Python 3.9.</li>
  217. <li>At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org</li>
  218. </ul>
  219. <p>To install the Synapse homeserver run:</p>
  220. <pre><code class="language-sh">mkdir -p ~/synapse
  221. virtualenv -p python3 ~/synapse/env
  222. source ~/synapse/env/bin/activate
  223. pip install --upgrade pip
  224. pip install --upgrade setuptools
  225. pip install matrix-synapse
  226. </code></pre>
  227. <p>This will download Synapse from <a href="https://pypi.org/project/matrix-synapse">PyPI</a>
  228. and install it, along with the python libraries it uses, into a virtual environment
  229. under <code>~/synapse/env</code>. Feel free to pick a different directory if you
  230. prefer.</p>
  231. <p>This Synapse installation can then be later upgraded by using pip again with the
  232. update flag:</p>
  233. <pre><code class="language-sh">source ~/synapse/env/bin/activate
  234. pip install -U matrix-synapse
  235. </code></pre>
  236. <p>Before you can start Synapse, you will need to generate a configuration
  237. file. To do this, run (in your virtualenv, as before):</p>
  238. <pre><code class="language-sh">cd ~/synapse
  239. python -m synapse.app.homeserver \
  240. --server-name my.domain.name \
  241. --config-path homeserver.yaml \
  242. --generate-config \
  243. --report-stats=[yes|no]
  244. </code></pre>
  245. <p>... substituting an appropriate value for <code>--server-name</code>.</p>
  246. <p>This command will generate you a config file that you can then customise, but it will
  247. also generate a set of keys for you. These keys will allow your homeserver to
  248. identify itself to other homeserver, so don't lose or delete them. It would be
  249. wise to back them up somewhere safe. (If, for whatever reason, you do need to
  250. change your homeserver's keys, you may find that other homeserver have the
  251. old key cached. If you update the signing key, you should change the name of the
  252. key in the <code>&lt;server name&gt;.signing.key</code> file (the second word) to something
  253. different. See the <a href="https://matrix.org/docs/spec/server_server/latest.html#retrieving-server-keys">spec</a> for more information on key management).</p>
  254. <p>To actually run your new homeserver, pick a working directory for Synapse to
  255. run (e.g. <code>~/synapse</code>), and:</p>
  256. <pre><code class="language-sh">cd ~/synapse
  257. source env/bin/activate
  258. synctl start
  259. </code></pre>
  260. <h4 id="platform-specific-prerequisites"><a class="header" href="#platform-specific-prerequisites">Platform-specific prerequisites</a></h4>
  261. <p>Synapse is written in Python but some of the libraries it uses are written in
  262. C. So before we can install Synapse itself we need a working C compiler and the
  263. header files for Python C extensions.</p>
  264. <h5 id="debianubunturaspbian"><a class="header" href="#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></h5>
  265. <p>Installing prerequisites on Ubuntu or Debian:</p>
  266. <pre><code class="language-sh">sudo apt install build-essential python3-dev libffi-dev \
  267. python3-pip python3-setuptools sqlite3 \
  268. libssl-dev virtualenv libjpeg-dev libxslt1-dev
  269. </code></pre>
  270. <h5 id="archlinux"><a class="header" href="#archlinux">ArchLinux</a></h5>
  271. <p>Installing prerequisites on ArchLinux:</p>
  272. <pre><code class="language-sh">sudo pacman -S base-devel python python-pip \
  273. python-setuptools python-virtualenv sqlite3
  274. </code></pre>
  275. <h5 id="centosfedora"><a class="header" href="#centosfedora">CentOS/Fedora</a></h5>
  276. <p>Installing prerequisites on CentOS or Fedora Linux:</p>
  277. <pre><code class="language-sh">sudo dnf install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
  278. libwebp-devel libxml2-devel libxslt-devel libpq-devel \
  279. python3-virtualenv libffi-devel openssl-devel python3-devel
  280. sudo dnf groupinstall &quot;Development Tools&quot;
  281. </code></pre>
  282. <h5 id="macos"><a class="header" href="#macos">macOS</a></h5>
  283. <p>Installing prerequisites on macOS:</p>
  284. <pre><code class="language-sh">xcode-select --install
  285. sudo easy_install pip
  286. sudo pip install virtualenv
  287. brew install pkg-config libffi
  288. </code></pre>
  289. <p>On macOS Catalina (10.15) you may need to explicitly install OpenSSL
  290. via brew and inform <code>pip</code> about it so that <code>psycopg2</code> builds:</p>
  291. <pre><code class="language-sh">brew install openssl@1.1
  292. export LDFLAGS=&quot;-L/usr/local/opt/openssl/lib&quot;
  293. export CPPFLAGS=&quot;-I/usr/local/opt/openssl/include&quot;
  294. </code></pre>
  295. <h5 id="opensuse"><a class="header" href="#opensuse">OpenSUSE</a></h5>
  296. <p>Installing prerequisites on openSUSE:</p>
  297. <pre><code class="language-sh">sudo zypper in -t pattern devel_basis
  298. sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
  299. python-devel libffi-devel libopenssl-devel libjpeg62-devel
  300. </code></pre>
  301. <h5 id="openbsd"><a class="header" href="#openbsd">OpenBSD</a></h5>
  302. <p>A port of Synapse is available under <code>net/synapse</code>. The filesystem
  303. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  304. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  305. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  306. <p>To be able to build Synapse's dependency on python the <code>WRKOBJDIR</code>
  307. (cf. <code>bsd.port.mk(5)</code>) for building python, too, needs to be on a filesystem
  308. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>).</p>
  309. <p>Creating a <code>WRKOBJDIR</code> for building python under <code>/usr/local</code> (which on a
  310. default OpenBSD installation is mounted with <code>wxallowed</code>):</p>
  311. <pre><code class="language-sh">doas mkdir /usr/local/pobj_wxallowed
  312. </code></pre>
  313. <p>Assuming <code>PORTS_PRIVSEP=Yes</code> (cf. <code>bsd.port.mk(5)</code>) and <code>SUDO=doas</code> are
  314. configured in <code>/etc/mk.conf</code>:</p>
  315. <pre><code class="language-sh">doas chown _pbuild:_pbuild /usr/local/pobj_wxallowed
  316. </code></pre>
  317. <p>Setting the <code>WRKOBJDIR</code> for building python:</p>
  318. <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
  319. </code></pre>
  320. <p>Building Synapse:</p>
  321. <pre><code class="language-sh">cd /usr/ports/net/synapse
  322. make install
  323. </code></pre>
  324. <h5 id="windows"><a class="header" href="#windows">Windows</a></h5>
  325. <p>If you wish to run or develop Synapse on Windows, the Windows Subsystem For
  326. Linux provides a Linux environment on Windows 10 which is capable of using the
  327. Debian, Fedora, or source installation methods. More information about WSL can
  328. 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
  329. 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>
  330. for Windows Server.</p>
  331. <h3 id="prebuilt-packages"><a class="header" href="#prebuilt-packages">Prebuilt packages</a></h3>
  332. <p>As an alternative to installing from source, prebuilt packages are available
  333. for a number of platforms.</p>
  334. <h4 id="docker-images-and-ansible-playbooks"><a class="header" href="#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></h4>
  335. <p>There is an official synapse image available at
  336. <a href="https://hub.docker.com/r/matrixdotorg/synapse">https://hub.docker.com/r/matrixdotorg/synapse</a> which can be used with
  337. the docker-compose file available at
  338. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/docker">contrib/docker</a>.
  339. Further information on this including configuration options is available in the README
  340. on hub.docker.com.</p>
  341. <p>Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a
  342. Dockerfile to automate a synapse server in a single Docker image, at
  343. <a href="https://hub.docker.com/r/avhost/docker-matrix/tags/">https://hub.docker.com/r/avhost/docker-matrix/tags/</a></p>
  344. <p>Slavi Pantaleev has created an Ansible playbook,
  345. which installs the offical Docker image of Matrix Synapse
  346. along with many other Matrix-related services (Postgres database, Element, coturn,
  347. ma1sd, SSL support, etc.).
  348. For more details, see
  349. <a href="https://github.com/spantaleev/matrix-docker-ansible-deploy">https://github.com/spantaleev/matrix-docker-ansible-deploy</a></p>
  350. <h4 id="debianubuntu"><a class="header" href="#debianubuntu">Debian/Ubuntu</a></h4>
  351. <h5 id="matrixorg-packages"><a class="header" href="#matrixorg-packages">Matrix.org packages</a></h5>
  352. <p>Matrix.org provides Debian/Ubuntu packages of the latest stable version of
  353. Synapse via <a href="https://packages.matrix.org/debian/">https://packages.matrix.org/debian/</a>. They are available for Debian
  354. 9 (Stretch), Ubuntu 16.04 (Xenial), and later. To use them:</p>
  355. <pre><code class="language-sh">sudo apt install -y lsb-release wget apt-transport-https
  356. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  357. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main&quot; |
  358. sudo tee /etc/apt/sources.list.d/matrix-org.list
  359. sudo apt update
  360. sudo apt install matrix-synapse-py3
  361. </code></pre>
  362. <p><strong>Note</strong>: if you followed a previous version of these instructions which
  363. recommended using <code>apt-key add</code> to add an old key from
  364. <code>https://matrix.org/packages/debian/</code>, you should note that this key has been
  365. revoked. You should remove the old key with <code>sudo apt-key remove C35EB17E1EAE708E6603A9B3AD0592FE47F0DF61</code>, and follow the above instructions to
  366. update your configuration.</p>
  367. <p>The fingerprint of the repository signing key (as shown by <code>gpg /usr/share/keyrings/matrix-org-archive-keyring.gpg</code>) is
  368. <code>AAF9AE843A7584B5A3E4CD2BCF45A512DE2DA058</code>.</p>
  369. <h5 id="downstream-debian-packages"><a class="header" href="#downstream-debian-packages">Downstream Debian packages</a></h5>
  370. <p>We do not recommend using the packages from the default Debian <code>buster</code>
  371. repository at this time, as they are old and suffer from known security
  372. vulnerabilities. You can install the latest version of Synapse from
  373. <a href="setup/installation.html#matrixorg-packages">our repository</a> or from <code>buster-backports</code>. Please
  374. see the <a href="https://backports.debian.org/Instructions/">Debian documentation</a>
  375. for information on how to use backports.</p>
  376. <p>If you are using Debian <code>sid</code> or testing, Synapse is available in the default
  377. repositories and it should be possible to install it simply with:</p>
  378. <pre><code class="language-sh">sudo apt install matrix-synapse
  379. </code></pre>
  380. <h5 id="downstream-ubuntu-packages"><a class="header" href="#downstream-ubuntu-packages">Downstream Ubuntu packages</a></h5>
  381. <p>We do not recommend using the packages in the default Ubuntu repository
  382. at this time, as they are old and suffer from known security vulnerabilities.
  383. The latest version of Synapse can be installed from <a href="setup/installation.html#matrixorg-packages">our repository</a>.</p>
  384. <h4 id="fedora"><a class="header" href="#fedora">Fedora</a></h4>
  385. <p>Synapse is in the Fedora repositories as <code>matrix-synapse</code>:</p>
  386. <pre><code class="language-sh">sudo dnf install matrix-synapse
  387. </code></pre>
  388. <p>Oleg Girko provides Fedora RPMs at
  389. <a href="https://obs.infoserver.lv/project/monitor/matrix-synapse">https://obs.infoserver.lv/project/monitor/matrix-synapse</a></p>
  390. <h4 id="opensuse-1"><a class="header" href="#opensuse-1">OpenSUSE</a></h4>
  391. <p>Synapse is in the OpenSUSE repositories as <code>matrix-synapse</code>:</p>
  392. <pre><code class="language-sh">sudo zypper install matrix-synapse
  393. </code></pre>
  394. <h4 id="suse-linux-enterprise-server"><a class="header" href="#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></h4>
  395. <p>Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at
  396. <a href="https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/">https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/</a></p>
  397. <h4 id="archlinux-1"><a class="header" href="#archlinux-1">ArchLinux</a></h4>
  398. <p>The quickest way to get up and running with ArchLinux is probably with the community package
  399. <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
  400. the necessary dependencies.</p>
  401. <p>pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):</p>
  402. <pre><code class="language-sh">sudo pip install --upgrade pip
  403. </code></pre>
  404. <p>If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  405. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  406. compile it under the right architecture. (This should not be needed if
  407. installing under virtualenv):</p>
  408. <pre><code class="language-sh">sudo pip uninstall py-bcrypt
  409. sudo pip install py-bcrypt
  410. </code></pre>
  411. <h4 id="void-linux"><a class="header" href="#void-linux">Void Linux</a></h4>
  412. <p>Synapse can be found in the void repositories as 'synapse':</p>
  413. <pre><code class="language-sh">xbps-install -Su
  414. xbps-install -S synapse
  415. </code></pre>
  416. <h4 id="freebsd"><a class="header" href="#freebsd">FreeBSD</a></h4>
  417. <p>Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:</p>
  418. <ul>
  419. <li>Ports: <code>cd /usr/ports/net-im/py-matrix-synapse &amp;&amp; make install clean</code></li>
  420. <li>Packages: <code>pkg install py37-matrix-synapse</code></li>
  421. </ul>
  422. <h4 id="openbsd-1"><a class="header" href="#openbsd-1">OpenBSD</a></h4>
  423. <p>As of OpenBSD 6.7 Synapse is available as a pre-compiled binary. The filesystem
  424. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  425. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  426. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  427. <p>Installing Synapse:</p>
  428. <pre><code class="language-sh">doas pkg_add synapse
  429. </code></pre>
  430. <h4 id="nixos"><a class="header" href="#nixos">NixOS</a></h4>
  431. <p>Robin Lambertz has packaged Synapse for NixOS at:
  432. <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>
  433. <h2 id="setting-up-synapse"><a class="header" href="#setting-up-synapse">Setting up Synapse</a></h2>
  434. <p>Once you have installed synapse as above, you will need to configure it.</p>
  435. <h3 id="using-postgresql"><a class="header" href="#using-postgresql">Using PostgreSQL</a></h3>
  436. <p>By default Synapse uses an <a href="https://sqlite.org/">SQLite</a> database and in doing so trades
  437. performance for convenience. Almost all installations should opt to use <a href="https://www.postgresql.org">PostgreSQL</a>
  438. instead. Advantages include:</p>
  439. <ul>
  440. <li>significant performance improvements due to the superior threading and
  441. caching model, smarter query optimiser</li>
  442. <li>allowing the DB to be run on separate hardware</li>
  443. </ul>
  444. <p>For information on how to install and use PostgreSQL in Synapse, please see
  445. <a href="setup/../postgres.html">docs/postgres.md</a></p>
  446. <p>SQLite is only acceptable for testing purposes. SQLite should not be used in
  447. a production server. Synapse will perform poorly when using
  448. SQLite, especially when participating in large rooms.</p>
  449. <h3 id="tls-certificates"><a class="header" href="#tls-certificates">TLS certificates</a></h3>
  450. <p>The default configuration exposes a single HTTP port on the local
  451. interface: <code>http://localhost:8008</code>. It is suitable for local testing,
  452. but for any practical use, you will need Synapse's APIs to be served
  453. over HTTPS.</p>
  454. <p>The recommended way to do so is to set up a reverse proxy on port
  455. <code>8448</code>. You can find documentation on doing so in
  456. <a href="setup/../reverse_proxy.html">docs/reverse_proxy.md</a>.</p>
  457. <p>Alternatively, you can configure Synapse to expose an HTTPS port. To do
  458. so, you will need to edit <code>homeserver.yaml</code>, as follows:</p>
  459. <ul>
  460. <li>First, under the <code>listeners</code> section, uncomment the configuration for the
  461. TLS-enabled listener. (Remove the hash sign (<code>#</code>) at the start of
  462. each line). The relevant lines are like this:</li>
  463. </ul>
  464. <pre><code class="language-yaml"> - port: 8448
  465. type: http
  466. tls: true
  467. resources:
  468. - names: [client, federation]
  469. </code></pre>
  470. <ul>
  471. <li>
  472. <p>You will also need to uncomment the <code>tls_certificate_path</code> and
  473. <code>tls_private_key_path</code> lines under the <code>TLS</code> section. You will need to manage
  474. provisioning of these certificates yourself.</p>
  475. <p>If you are using your own certificate, be sure to use a <code>.pem</code> file that
  476. includes the full certificate chain including any intermediate certificates
  477. (for instance, if using certbot, use <code>fullchain.pem</code> as your certificate, not
  478. <code>cert.pem</code>).</p>
  479. </li>
  480. </ul>
  481. <p>For a more detailed guide to configuring your server for federation, see
  482. <a href="setup/../federate.html">federate.md</a>.</p>
  483. <h3 id="client-well-known-uri"><a class="header" href="#client-well-known-uri">Client Well-Known URI</a></h3>
  484. <p>Setting up the client Well-Known URI is optional but if you set it up, it will
  485. allow users to enter their full username (e.g. <code>@user:&lt;server_name&gt;</code>) into clients
  486. which support well-known lookup to automatically configure the homeserver and
  487. identity server URLs. This is useful so that users don't have to memorize or think
  488. about the actual homeserver URL you are using.</p>
  489. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/client</code> should return JSON in
  490. the following format.</p>
  491. <pre><code class="language-json">{
  492. &quot;m.homeserver&quot;: {
  493. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  494. }
  495. }
  496. </code></pre>
  497. <p>It can optionally contain identity server information as well.</p>
  498. <pre><code class="language-json">{
  499. &quot;m.homeserver&quot;: {
  500. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  501. },
  502. &quot;m.identity_server&quot;: {
  503. &quot;base_url&quot;: &quot;https://&lt;identity.example.com&gt;&quot;
  504. }
  505. }
  506. </code></pre>
  507. <p>To work in browser based clients, the file must be served with the appropriate
  508. Cross-Origin Resource Sharing (CORS) headers. A recommended value would be
  509. <code>Access-Control-Allow-Origin: *</code> which would allow all browser based clients to
  510. view it.</p>
  511. <p>In nginx this would be something like:</p>
  512. <pre><code class="language-nginx">location /.well-known/matrix/client {
  513. return 200 '{&quot;m.homeserver&quot;: {&quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;}}';
  514. default_type application/json;
  515. add_header Access-Control-Allow-Origin *;
  516. }
  517. </code></pre>
  518. <p>You should also ensure the <code>public_baseurl</code> option in <code>homeserver.yaml</code> is set
  519. correctly. <code>public_baseurl</code> should be set to the URL that clients will use to
  520. connect to your server. This is the same URL you put for the <code>m.homeserver</code>
  521. <code>base_url</code> above.</p>
  522. <pre><code class="language-yaml">public_baseurl: &quot;https://&lt;matrix.example.com&gt;&quot;
  523. </code></pre>
  524. <h3 id="email"><a class="header" href="#email">Email</a></h3>
  525. <p>It is desirable for Synapse to have the capability to send email. This allows
  526. Synapse to send password reset emails, send verifications when an email address
  527. is added to a user's account, and send email notifications to users when they
  528. receive new messages.</p>
  529. <p>To configure an SMTP server for Synapse, modify the configuration section
  530. headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>, <code>smtp_port</code>
  531. and <code>notif_from</code> fields filled out. You may also need to set <code>smtp_user</code>,
  532. <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  533. <p>If email is not configured, password reset, registration and notifications via
  534. email will be disabled.</p>
  535. <h3 id="registering-a-user"><a class="header" href="#registering-a-user">Registering a user</a></h3>
  536. <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>
  537. <p>Alternatively, you can do so from the command line. This can be done as follows:</p>
  538. <ol>
  539. <li>If synapse was installed via pip, activate the virtualenv as follows (if Synapse was
  540. installed via a prebuilt package, <code>register_new_matrix_user</code> should already be
  541. on the search path):
  542. <pre><code class="language-sh">cd ~/synapse
  543. source env/bin/activate
  544. synctl start # if not already running
  545. </code></pre>
  546. </li>
  547. <li>Run the following command:
  548. <pre><code class="language-sh">register_new_matrix_user -c homeserver.yaml http://localhost:8008
  549. </code></pre>
  550. </li>
  551. </ol>
  552. <p>This will prompt you to add details for the new user, and will then connect to
  553. the running Synapse to create the new user. For example:</p>
  554. <pre><code>New user localpart: erikj
  555. Password:
  556. Confirm password:
  557. Make admin [no]:
  558. Success!
  559. </code></pre>
  560. <p>This process uses a setting <code>registration_shared_secret</code> in
  561. <code>homeserver.yaml</code>, which is shared between Synapse itself and the
  562. <code>register_new_matrix_user</code> script. It doesn't matter what it is (a random
  563. value is generated by <code>--generate-config</code>), but it should be kept secret, as
  564. anyone with knowledge of it can register users, including admin accounts,
  565. on your server even if <code>enable_registration</code> is <code>false</code>.</p>
  566. <h3 id="setting-up-a-turn-server"><a class="header" href="#setting-up-a-turn-server">Setting up a TURN server</a></h3>
  567. <p>For reliable VoIP calls to be routed via this homeserver, you MUST configure
  568. a TURN server. See
  569. <a href="setup/../turn-howto.html">docs/turn-howto.md</a>
  570. for details.</p>
  571. <h3 id="url-previews"><a class="header" href="#url-previews">URL previews</a></h3>
  572. <p>Synapse includes support for previewing URLs, which is disabled by default. To
  573. turn it on you must enable the <code>url_preview_enabled: True</code> config parameter
  574. and explicitly specify the IP ranges that Synapse is not allowed to spider for
  575. previewing in the <code>url_preview_ip_range_blacklist</code> configuration parameter.
  576. This is critical from a security perspective to stop arbitrary Matrix users
  577. spidering 'internal' URLs on your network. At the very least we recommend that
  578. your loopback and RFC1918 IP addresses are blacklisted.</p>
  579. <p>This also requires the optional <code>lxml</code> python dependency to be installed. This
  580. in turn requires the <code>libxml2</code> library to be available - on Debian/Ubuntu this
  581. means <code>apt-get install libxml2-dev</code>, or equivalent for your OS.</p>
  582. <h3 id="troubleshooting-installation"><a class="header" href="#troubleshooting-installation">Troubleshooting Installation</a></h3>
  583. <p><code>pip</code> seems to leak <em>lots</em> of memory during installation. For instance, a Linux
  584. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  585. happens, you will have to individually install the dependencies which are
  586. failing, e.g.:</p>
  587. <pre><code class="language-sh">pip install twisted
  588. </code></pre>
  589. <p>If you have any other problems, feel free to ask in
  590. <a href="https://matrix.to/#/#synapse:matrix.org">#synapse:matrix.org</a>.</p>
  591. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="using-postgres"><a class="header" href="#using-postgres">Using Postgres</a></h1>
  592. <p>Synapse supports PostgreSQL versions 9.6 or later.</p>
  593. <h2 id="install-postgres-client-libraries"><a class="header" href="#install-postgres-client-libraries">Install postgres client libraries</a></h2>
  594. <p>Synapse will require the python postgres client library in order to
  595. connect to a postgres database.</p>
  596. <ul>
  597. <li>
  598. <p>If you are using the <a href="setup/installation.html#matrixorg-packages">matrix.org debian/ubuntu
  599. packages</a>, the necessary python
  600. library will already be installed, but you will need to ensure the
  601. low-level postgres library is installed, which you can do with
  602. <code>apt install libpq5</code>.</p>
  603. </li>
  604. <li>
  605. <p>For other pre-built packages, please consult the documentation from
  606. the relevant package.</p>
  607. </li>
  608. <li>
  609. <p>If you installed synapse <a href="setup/installation.html#installing-from-source">in a
  610. virtualenv</a>, you can install
  611. the library with:</p>
  612. <pre><code>~/synapse/env/bin/pip install &quot;matrix-synapse[postgres]&quot;
  613. </code></pre>
  614. <p>(substituting the path to your virtualenv for <code>~/synapse/env</code>, if
  615. you used a different path). You will require the postgres
  616. development files. These are in the <code>libpq-dev</code> package on
  617. Debian-derived distributions.</p>
  618. </li>
  619. </ul>
  620. <h2 id="set-up-database"><a class="header" href="#set-up-database">Set up database</a></h2>
  621. <p>Assuming your PostgreSQL database user is called <code>postgres</code>, first authenticate as the database user with:</p>
  622. <pre><code>su - postgres
  623. # Or, if your system uses sudo to get administrative rights
  624. sudo -u postgres bash
  625. </code></pre>
  626. <p>Then, create a postgres user and a database with:</p>
  627. <pre><code># this will prompt for a password for the new user
  628. createuser --pwprompt synapse_user
  629. createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse
  630. </code></pre>
  631. <p>The above will create a user called <code>synapse_user</code>, and a database called
  632. <code>synapse</code>.</p>
  633. <p>Note that the PostgreSQL database <em>must</em> have the correct encoding set
  634. (as shown above), otherwise it will not be able to store UTF8 strings.</p>
  635. <p>You may need to enable password authentication so <code>synapse_user</code> can
  636. connect to the database. See
  637. <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>
  638. <h2 id="synapse-config"><a class="header" href="#synapse-config">Synapse config</a></h2>
  639. <p>When you are ready to start using PostgreSQL, edit the <code>database</code>
  640. section in your config file to match the following lines:</p>
  641. <pre><code class="language-yaml">database:
  642. name: psycopg2
  643. args:
  644. user: &lt;user&gt;
  645. password: &lt;pass&gt;
  646. database: &lt;db&gt;
  647. host: &lt;host&gt;
  648. cp_min: 5
  649. cp_max: 10
  650. </code></pre>
  651. <p>All key, values in <code>args</code> are passed to the <code>psycopg2.connect(..)</code>
  652. function, except keys beginning with <code>cp_</code>, which are consumed by the
  653. twisted adbapi connection pool. See the <a href="https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS">libpq
  654. documentation</a>
  655. for a list of options which can be passed.</p>
  656. <p>You should consider tuning the <code>args.keepalives_*</code> options if there is any danger of
  657. the connection between your homeserver and database dropping, otherwise Synapse
  658. may block for an extended period while it waits for a response from the
  659. database server. Example values might be:</p>
  660. <pre><code class="language-yaml">database:
  661. args:
  662. # ... as above
  663. # seconds of inactivity after which TCP should send a keepalive message to the server
  664. keepalives_idle: 10
  665. # the number of seconds after which a TCP keepalive message that is not
  666. # acknowledged by the server should be retransmitted
  667. keepalives_interval: 10
  668. # the number of TCP keepalives that can be lost before the client's connection
  669. # to the server is considered dead
  670. keepalives_count: 3
  671. </code></pre>
  672. <h2 id="tuning-postgres"><a class="header" href="#tuning-postgres">Tuning Postgres</a></h2>
  673. <p>The default settings should be fine for most deployments. For larger
  674. scale deployments tuning some of the settings is recommended, details of
  675. which can be found at
  676. <a href="https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server">https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server</a>.</p>
  677. <p>In particular, we've found tuning the following values helpful for
  678. performance:</p>
  679. <ul>
  680. <li><code>shared_buffers</code></li>
  681. <li><code>effective_cache_size</code></li>
  682. <li><code>work_mem</code></li>
  683. <li><code>maintenance_work_mem</code></li>
  684. <li><code>autovacuum_work_mem</code></li>
  685. </ul>
  686. <p>Note that the appropriate values for those fields depend on the amount
  687. of free memory the database host has available.</p>
  688. <h2 id="porting-from-sqlite"><a class="header" href="#porting-from-sqlite">Porting from SQLite</a></h2>
  689. <h3 id="overview"><a class="header" href="#overview">Overview</a></h3>
  690. <p>The script <code>synapse_port_db</code> allows porting an existing synapse server
  691. backed by SQLite to using PostgreSQL. This is done in as a two phase
  692. process:</p>
  693. <ol>
  694. <li>Copy the existing SQLite database to a separate location and run
  695. the port script against that offline database.</li>
  696. <li>Shut down the server. Rerun the port script to port any data that
  697. has come in since taking the first snapshot. Restart server against
  698. the PostgreSQL database.</li>
  699. </ol>
  700. <p>The port script is designed to be run repeatedly against newer snapshots
  701. of the SQLite database file. This makes it safe to repeat step 1 if
  702. there was a delay between taking the previous snapshot and being ready
  703. to do step 2.</p>
  704. <p>It is safe to at any time kill the port script and restart it.</p>
  705. <p>Note that the database may take up significantly more (25% - 100% more)
  706. space on disk after porting to Postgres.</p>
  707. <h3 id="using-the-port-script"><a class="header" href="#using-the-port-script">Using the port script</a></h3>
  708. <p>Firstly, shut down the currently running synapse server and copy its
  709. database file (typically <code>homeserver.db</code>) to another location. Once the
  710. copy is complete, restart synapse. For instance:</p>
  711. <pre><code>./synctl stop
  712. cp homeserver.db homeserver.db.snapshot
  713. ./synctl start
  714. </code></pre>
  715. <p>Copy the old config file into a new config file:</p>
  716. <pre><code>cp homeserver.yaml homeserver-postgres.yaml
  717. </code></pre>
  718. <p>Edit the database section as described in the section <em>Synapse config</em>
  719. above and with the SQLite snapshot located at <code>homeserver.db.snapshot</code>
  720. simply run:</p>
  721. <pre><code>synapse_port_db --sqlite-database homeserver.db.snapshot \
  722. --postgres-config homeserver-postgres.yaml
  723. </code></pre>
  724. <p>The flag <code>--curses</code> displays a coloured curses progress UI.</p>
  725. <p>If the script took a long time to complete, or time has otherwise passed
  726. since the original snapshot was taken, repeat the previous steps with a
  727. newer snapshot.</p>
  728. <p>To complete the conversion shut down the synapse server and run the port
  729. script one last time, e.g. if the SQLite database is at <code>homeserver.db</code>
  730. run:</p>
  731. <pre><code>synapse_port_db --sqlite-database homeserver.db \
  732. --postgres-config homeserver-postgres.yaml
  733. </code></pre>
  734. <p>Once that has completed, change the synapse config to point at the
  735. PostgreSQL database configuration file <code>homeserver-postgres.yaml</code>:</p>
  736. <pre><code>./synctl stop
  737. mv homeserver.yaml homeserver-old-sqlite.yaml
  738. mv homeserver-postgres.yaml homeserver.yaml
  739. ./synctl start
  740. </code></pre>
  741. <p>Synapse should now be running against PostgreSQL.</p>
  742. <h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
  743. <h3 id="alternative-auth-methods"><a class="header" href="#alternative-auth-methods">Alternative auth methods</a></h3>
  744. <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
  745. <code>ident</code>:</p>
  746. <ul>
  747. <li>
  748. <p>If the <code>synapse_user</code> user has a password, add the password to the <code>database:</code>
  749. section of <code>homeserver.yaml</code>. Then add the following to <code>pg_hba.conf</code>:</p>
  750. <pre><code>host synapse synapse_user ::1/128 md5 # or `scram-sha-256` instead of `md5` if you use that
  751. </code></pre>
  752. </li>
  753. <li>
  754. <p>If the <code>synapse_user</code> user does not have a password, then a password doesn't
  755. have to be added to <code>homeserver.yaml</code>. But the following does need to be added
  756. to <code>pg_hba.conf</code>:</p>
  757. <pre><code>host synapse synapse_user ::1/128 trust
  758. </code></pre>
  759. </li>
  760. </ul>
  761. <p>Note that line order matters in <code>pg_hba.conf</code>, so make sure that if you do add a
  762. new line, it is inserted before:</p>
  763. <pre><code>host all all ::1/128 ident
  764. </code></pre>
  765. <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>
  766. <p>Synapse will refuse to set up a new database if it has the wrong values of
  767. <code>COLLATE</code> and <code>CTYPE</code> set, and will log warnings on existing databases. Using
  768. different locales can cause issues if the locale library is updated from
  769. underneath the database, or if a different version of the locale is used on any
  770. replicas.</p>
  771. <p>The safest way to fix the issue is to dump the database and recreate it with
  772. the correct locale parameter (as shown above). It is also possible to change the
  773. parameters on a live database and run a <code>REINDEX</code> on the entire database,
  774. however extreme care must be taken to avoid database corruption.</p>
  775. <p>Note that the above may fail with an error about duplicate rows if corruption
  776. has already occurred, and such duplicate rows will need to be manually removed.</p>
  777. <h3 id="fixing-inconsistent-sequences-error"><a class="header" href="#fixing-inconsistent-sequences-error">Fixing inconsistent sequences error</a></h3>
  778. <p>Synapse uses Postgres sequences to generate IDs for various tables. A sequence
  779. and associated table can get out of sync if, for example, Synapse has been
  780. downgraded and then upgraded again.</p>
  781. <p>To fix the issue shut down Synapse (including any and all workers) and run the
  782. SQL command included in the error message. Once done Synapse should start
  783. successfully.</p>
  784. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="using-a-reverse-proxy-with-synapse"><a class="header" href="#using-a-reverse-proxy-with-synapse">Using a reverse proxy with Synapse</a></h1>
  785. <p>It is recommended to put a reverse proxy such as
  786. <a href="https://nginx.org/en/docs/http/ngx_http_proxy_module.html">nginx</a>,
  787. <a href="https://httpd.apache.org/docs/current/mod/mod_proxy_http.html">Apache</a>,
  788. <a href="https://caddyserver.com/docs/quick-starts/reverse-proxy">Caddy</a>,
  789. <a href="https://www.haproxy.org/">HAProxy</a> or
  790. <a href="https://man.openbsd.org/relayd.8">relayd</a> in front of Synapse. One advantage
  791. of doing so is that it means that you can expose the default https port
  792. (443) to Matrix clients without needing to run Synapse with root
  793. privileges.</p>
  794. <p>You should configure your reverse proxy to forward requests to <code>/_matrix</code> or
  795. <code>/_synapse/client</code> to Synapse, and have it set the <code>X-Forwarded-For</code> and
  796. <code>X-Forwarded-Proto</code> request headers.</p>
  797. <p>You should remember that Matrix clients and other Matrix servers do not
  798. necessarily need to connect to your server via the same server name or
  799. port. Indeed, clients will use port 443 by default, whereas servers default to
  800. port 8448. Where these are different, we refer to the 'client port' and the
  801. 'federation port'. See <a href="https://matrix.org/docs/spec/server_server/latest#resolving-server-names">the Matrix
  802. specification</a>
  803. for more details of the algorithm used for federation connections, and
  804. <a href="delegate.html">delegate.md</a> for instructions on setting up delegation.</p>
  805. <p><strong>NOTE</strong>: Your reverse proxy must not <code>canonicalise</code> or <code>normalise</code>
  806. the requested URI in any way (for example, by decoding <code>%xx</code> escapes).
  807. Beware that Apache <em>will</em> canonicalise URIs unless you specify
  808. <code>nocanon</code>.</p>
  809. <p>Let's assume that we expect clients to connect to our server at
  810. <code>https://matrix.example.com</code>, and other servers to connect at
  811. <code>https://example.com:8448</code>. The following sections detail the configuration of
  812. the reverse proxy and the homeserver.</p>
  813. <h2 id="reverse-proxy-configuration-examples"><a class="header" href="#reverse-proxy-configuration-examples">Reverse-proxy configuration examples</a></h2>
  814. <p><strong>NOTE</strong>: You only need one of these.</p>
  815. <h3 id="nginx"><a class="header" href="#nginx">nginx</a></h3>
  816. <pre><code>server {
  817. listen 443 ssl http2;
  818. listen [::]:443 ssl http2;
  819. # For the federation port
  820. listen 8448 ssl http2 default_server;
  821. listen [::]:8448 ssl http2 default_server;
  822. server_name matrix.example.com;
  823. location ~* ^(\/_matrix|\/_synapse\/client) {
  824. proxy_pass http://localhost:8008;
  825. proxy_set_header X-Forwarded-For $remote_addr;
  826. proxy_set_header X-Forwarded-Proto $scheme;
  827. proxy_set_header Host $host;
  828. # Nginx by default only allows file uploads up to 1M in size
  829. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  830. client_max_body_size 50M;
  831. }
  832. }
  833. </code></pre>
  834. <p><strong>NOTE</strong>: Do not add a path after the port in <code>proxy_pass</code>, otherwise nginx will
  835. canonicalise/normalise the URI.</p>
  836. <h3 id="caddy-1"><a class="header" href="#caddy-1">Caddy 1</a></h3>
  837. <pre><code>matrix.example.com {
  838. proxy /_matrix http://localhost:8008 {
  839. transparent
  840. }
  841. proxy /_synapse/client http://localhost:8008 {
  842. transparent
  843. }
  844. }
  845. example.com:8448 {
  846. proxy / http://localhost:8008 {
  847. transparent
  848. }
  849. }
  850. </code></pre>
  851. <h3 id="caddy-2"><a class="header" href="#caddy-2">Caddy 2</a></h3>
  852. <pre><code>matrix.example.com {
  853. reverse_proxy /_matrix/* http://localhost:8008
  854. reverse_proxy /_synapse/client/* http://localhost:8008
  855. }
  856. example.com:8448 {
  857. reverse_proxy http://localhost:8008
  858. }
  859. </code></pre>
  860. <h3 id="apache"><a class="header" href="#apache">Apache</a></h3>
  861. <pre><code>&lt;VirtualHost *:443&gt;
  862. SSLEngine on
  863. ServerName matrix.example.com
  864. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  865. AllowEncodedSlashes NoDecode
  866. ProxyPreserveHost on
  867. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  868. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  869. ProxyPass /_synapse/client http://127.0.0.1:8008/_synapse/client nocanon
  870. ProxyPassReverse /_synapse/client http://127.0.0.1:8008/_synapse/client
  871. &lt;/VirtualHost&gt;
  872. &lt;VirtualHost *:8448&gt;
  873. SSLEngine on
  874. ServerName example.com
  875. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  876. AllowEncodedSlashes NoDecode
  877. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  878. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  879. &lt;/VirtualHost&gt;
  880. </code></pre>
  881. <p><strong>NOTE</strong>: ensure the <code>nocanon</code> options are included.</p>
  882. <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>
  883. <pre><code>&lt;IfModule security2_module&gt;
  884. SecRuleEngine off
  885. &lt;/IfModule&gt;
  886. </code></pre>
  887. <p><strong>NOTE 3</strong>: Missing <code>ProxyPreserveHost on</code> can lead to a redirect loop.</p>
  888. <h3 id="haproxy"><a class="header" href="#haproxy">HAProxy</a></h3>
  889. <pre><code>frontend https
  890. bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
  891. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  892. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  893. http-request set-header X-Forwarded-For %[src]
  894. # Matrix client traffic
  895. acl matrix-host hdr(host) -i matrix.example.com
  896. acl matrix-path path_beg /_matrix
  897. acl matrix-path path_beg /_synapse/client
  898. use_backend matrix if matrix-host matrix-path
  899. frontend matrix-federation
  900. bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
  901. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  902. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  903. http-request set-header X-Forwarded-For %[src]
  904. default_backend matrix
  905. backend matrix
  906. server matrix 127.0.0.1:8008
  907. </code></pre>
  908. <h3 id="relayd"><a class="header" href="#relayd">Relayd</a></h3>
  909. <pre><code>table &lt;webserver&gt; { 127.0.0.1 }
  910. table &lt;matrixserver&gt; { 127.0.0.1 }
  911. http protocol &quot;https&quot; {
  912. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  913. tls keypair &quot;example.com&quot;
  914. match header set &quot;X-Forwarded-For&quot; value &quot;$REMOTE_ADDR&quot;
  915. match header set &quot;X-Forwarded-Proto&quot; value &quot;https&quot;
  916. # set CORS header for .well-known/matrix/server, .well-known/matrix/client
  917. # httpd does not support setting headers, so do it here
  918. match request path &quot;/.well-known/matrix/*&quot; tag &quot;matrix-cors&quot;
  919. match response tagged &quot;matrix-cors&quot; header set &quot;Access-Control-Allow-Origin&quot; value &quot;*&quot;
  920. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  921. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  922. # pass on non-matrix traffic to webserver
  923. pass forward to &lt;webserver&gt;
  924. }
  925. relay &quot;https_traffic&quot; {
  926. listen on egress port 443 tls
  927. protocol &quot;https&quot;
  928. forward to &lt;matrixserver&gt; port 8008 check tcp
  929. forward to &lt;webserver&gt; port 8080 check tcp
  930. }
  931. http protocol &quot;matrix&quot; {
  932. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  933. tls keypair &quot;example.com&quot;
  934. block
  935. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  936. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  937. }
  938. relay &quot;matrix_federation&quot; {
  939. listen on egress port 8448 tls
  940. protocol &quot;matrix&quot;
  941. forward to &lt;matrixserver&gt; port 8008 check tcp
  942. }
  943. </code></pre>
  944. <h2 id="homeserver-configuration"><a class="header" href="#homeserver-configuration">Homeserver Configuration</a></h2>
  945. <p>You will also want to set <code>bind_addresses: ['127.0.0.1']</code> and
  946. <code>x_forwarded: true</code> for port 8008 in <code>homeserver.yaml</code> to ensure that
  947. client IP addresses are recorded correctly.</p>
  948. <p>Having done so, you can then use <code>https://matrix.example.com</code> (instead
  949. of <code>https://matrix.example.com:8448</code>) as the &quot;Custom server&quot; when
  950. connecting to Synapse from a client.</p>
  951. <h2 id="health-check-endpoint"><a class="header" href="#health-check-endpoint">Health check endpoint</a></h2>
  952. <p>Synapse exposes a health check endpoint for use by reverse proxies.
  953. Each configured HTTP listener has a <code>/health</code> endpoint which always returns
  954. 200 OK (and doesn't get logged).</p>
  955. <h2 id="synapse-administration-endpoints"><a class="header" href="#synapse-administration-endpoints">Synapse administration endpoints</a></h2>
  956. <p>Endpoints for administering your Synapse instance are placed under
  957. <code>/_synapse/admin</code>. These require authentication through an access token of an
  958. admin user. However as access to these endpoints grants the caller a lot of power,
  959. we do not recommend exposing them to the public internet without good reason.</p>
  960. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="overview-1"><a class="header" href="#overview-1">Overview</a></h1>
  961. <p>This document explains how to enable VoIP relaying on your Home Server with
  962. TURN.</p>
  963. <p>The synapse Matrix Home Server supports integration with TURN server via the
  964. <a href="https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00">TURN server REST API</a>. This
  965. allows the Home Server to generate credentials that are valid for use on the
  966. TURN server through the use of a secret shared between the Home Server and the
  967. TURN server.</p>
  968. <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>
  969. <h2 id="requirements"><a class="header" href="#requirements">Requirements</a></h2>
  970. <p>For TURN relaying with <code>coturn</code> to work, it must be hosted on a server/endpoint with a public IP.</p>
  971. <p>Hosting TURN behind a NAT (even with appropriate port forwarding) is known to cause issues
  972. and to often not work.</p>
  973. <h2 id="coturn-setup"><a class="header" href="#coturn-setup"><code>coturn</code> setup</a></h2>
  974. <h3 id="initial-installation"><a class="header" href="#initial-installation">Initial installation</a></h3>
  975. <p>The TURN daemon <code>coturn</code> is available from a variety of sources such as native package managers, or installation from source.</p>
  976. <h4 id="debian-installation"><a class="header" href="#debian-installation">Debian installation</a></h4>
  977. <p>Just install the debian package:</p>
  978. <pre><code class="language-sh">apt install coturn
  979. </code></pre>
  980. <p>This will install and start a systemd service called <code>coturn</code>.</p>
  981. <h4 id="source-installation"><a class="header" href="#source-installation">Source installation</a></h4>
  982. <ol>
  983. <li>
  984. <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>
  985. </li>
  986. <li>
  987. <p>Configure it:</p>
  988. <pre><code>./configure
  989. </code></pre>
  990. <p>You may need to install <code>libevent2</code>: if so, you should do so in
  991. the way recommended by your operating system. You can ignore
  992. warnings about lack of database support: a database is unnecessary
  993. for this purpose.</p>
  994. </li>
  995. <li>
  996. <p>Build and install it:</p>
  997. <pre><code>make
  998. make install
  999. </code></pre>
  1000. </li>
  1001. </ol>
  1002. <h3 id="configuration"><a class="header" href="#configuration">Configuration</a></h3>
  1003. <ol>
  1004. <li>
  1005. <p>Create or edit the config file in <code>/etc/turnserver.conf</code>. The relevant
  1006. lines, with example values, are:</p>
  1007. <pre><code>use-auth-secret
  1008. static-auth-secret=[your secret key here]
  1009. realm=turn.myserver.org
  1010. </code></pre>
  1011. <p>See <code>turnserver.conf</code> for explanations of the options. One way to generate
  1012. the <code>static-auth-secret</code> is with <code>pwgen</code>:</p>
  1013. <pre><code>pwgen -s 64 1
  1014. </code></pre>
  1015. <p>A <code>realm</code> must be specified, but its value is somewhat arbitrary. (It is
  1016. sent to clients as part of the authentication flow.) It is conventional to
  1017. set it to be your server name.</p>
  1018. </li>
  1019. <li>
  1020. <p>You will most likely want to configure coturn to write logs somewhere. The
  1021. easiest way is normally to send them to the syslog:</p>
  1022. <pre><code>syslog
  1023. </code></pre>
  1024. <p>(in which case, the logs will be available via <code>journalctl -u coturn</code> on a
  1025. systemd system). Alternatively, coturn can be configured to write to a
  1026. logfile - check the example config file supplied with coturn.</p>
  1027. </li>
  1028. <li>
  1029. <p>Consider your security settings. TURN lets users request a relay which will
  1030. connect to arbitrary IP addresses and ports. The following configuration is
  1031. suggested as a minimum starting point:</p>
  1032. <pre><code># VoIP traffic is all UDP. There is no reason to let users connect to arbitrary TCP endpoints via the relay.
  1033. no-tcp-relay
  1034. # don't let the relay ever try to connect to private IP address ranges within your network (if any)
  1035. # given the turn server is likely behind your firewall, remember to include any privileged public IPs too.
  1036. denied-peer-ip=10.0.0.0-10.255.255.255
  1037. denied-peer-ip=192.168.0.0-192.168.255.255
  1038. denied-peer-ip=172.16.0.0-172.31.255.255
  1039. # special case the turn server itself so that client-&gt;TURN-&gt;TURN-&gt;client flows work
  1040. allowed-peer-ip=10.0.0.1
  1041. # consider whether you want to limit the quota of relayed streams per user (or total) to avoid risk of DoS.
  1042. user-quota=12 # 4 streams per video call, so 12 streams = 3 simultaneous relayed calls per user.
  1043. total-quota=1200
  1044. </code></pre>
  1045. </li>
  1046. <li>
  1047. <p>Also consider supporting TLS/DTLS. To do this, add the following settings
  1048. to <code>turnserver.conf</code>:</p>
  1049. <pre><code># TLS certificates, including intermediate certs.
  1050. # For Let's Encrypt certificates, use `fullchain.pem` here.
  1051. cert=/path/to/fullchain.pem
  1052. # TLS private key file
  1053. pkey=/path/to/privkey.pem
  1054. </code></pre>
  1055. <p>In this case, replace the <code>turn:</code> schemes in the <code>turn_uri</code> settings below
  1056. with <code>turns:</code>.</p>
  1057. <p>We recommend that you only try to set up TLS/DTLS once you have set up a
  1058. basic installation and got it working.</p>
  1059. </li>
  1060. <li>
  1061. <p>Ensure your firewall allows traffic into the TURN server on the ports
  1062. you've configured it to listen on (By default: 3478 and 5349 for TURN
  1063. traffic (remember to allow both TCP and UDP traffic), and ports 49152-65535
  1064. for the UDP relay.)</p>
  1065. </li>
  1066. <li>
  1067. <p>We do not recommend running a TURN server behind NAT, and are not aware of
  1068. anyone doing so successfully.</p>
  1069. <p>If you want to try it anyway, you will at least need to tell coturn its
  1070. external IP address:</p>
  1071. <pre><code>external-ip=192.88.99.1
  1072. </code></pre>
  1073. <p>... and your NAT gateway must forward all of the relayed ports directly
  1074. (eg, port 56789 on the external IP must be always be forwarded to port
  1075. 56789 on the internal IP).</p>
  1076. <p>If you get this working, let us know!</p>
  1077. </li>
  1078. <li>
  1079. <p>(Re)start the turn server:</p>
  1080. <ul>
  1081. <li>
  1082. <p>If you used the Debian package (or have set up a systemd unit yourself):</p>
  1083. <pre><code class="language-sh">systemctl restart coturn
  1084. </code></pre>
  1085. </li>
  1086. <li>
  1087. <p>If you installed from source:</p>
  1088. <pre><code class="language-sh">bin/turnserver -o
  1089. </code></pre>
  1090. </li>
  1091. </ul>
  1092. </li>
  1093. </ol>
  1094. <h2 id="synapse-setup"><a class="header" href="#synapse-setup">Synapse setup</a></h2>
  1095. <p>Your home server configuration file needs the following extra keys:</p>
  1096. <ol>
  1097. <li>&quot;<code>turn_uris</code>&quot;: This needs to be a yaml list of public-facing URIs
  1098. for your TURN server to be given out to your clients. Add separate
  1099. entries for each transport your TURN server supports.</li>
  1100. <li>&quot;<code>turn_shared_secret</code>&quot;: This is the secret shared between your
  1101. Home server and your TURN server, so you should set it to the same
  1102. string you used in turnserver.conf.</li>
  1103. <li>&quot;<code>turn_user_lifetime</code>&quot;: This is the amount of time credentials
  1104. generated by your Home Server are valid for (in milliseconds).
  1105. Shorter times offer less potential for abuse at the expense of
  1106. increased traffic between web clients and your home server to
  1107. refresh credentials. The TURN REST API specification recommends
  1108. one day (86400000).</li>
  1109. <li>&quot;<code>turn_allow_guests</code>&quot;: Whether to allow guest users to use the
  1110. TURN server. This is enabled by default, as otherwise VoIP will
  1111. not work reliably for guests. However, it does introduce a
  1112. security risk as it lets guests connect to arbitrary endpoints
  1113. without having gone through a CAPTCHA or similar to register a
  1114. real account.</li>
  1115. </ol>
  1116. <p>As an example, here is the relevant section of the config file for <code>matrix.org</code>. The
  1117. <code>turn_uris</code> are appropriate for TURN servers listening on the default ports, with no TLS.</p>
  1118. <pre><code>turn_uris: [ &quot;turn:turn.matrix.org?transport=udp&quot;, &quot;turn:turn.matrix.org?transport=tcp&quot; ]
  1119. turn_shared_secret: &quot;n0t4ctuAllymatr1Xd0TorgSshar3d5ecret4obvIousreAsons&quot;
  1120. turn_user_lifetime: 86400000
  1121. turn_allow_guests: True
  1122. </code></pre>
  1123. <p>After updating the homeserver configuration, you must restart synapse:</p>
  1124. <ul>
  1125. <li>If you use synctl:
  1126. <pre><code class="language-sh">cd /where/you/run/synapse
  1127. ./synctl restart
  1128. </code></pre>
  1129. </li>
  1130. <li>If you use systemd:
  1131. <pre><code>systemctl restart matrix-synapse.service
  1132. </code></pre>
  1133. </li>
  1134. </ul>
  1135. <p>... and then reload any clients (or wait an hour for them to refresh their
  1136. settings).</p>
  1137. <h2 id="troubleshooting-1"><a class="header" href="#troubleshooting-1">Troubleshooting</a></h2>
  1138. <p>The normal symptoms of a misconfigured TURN server are that calls between
  1139. devices on different networks ring, but get stuck at &quot;call
  1140. connecting&quot;. Unfortunately, troubleshooting this can be tricky.</p>
  1141. <p>Here are a few things to try:</p>
  1142. <ul>
  1143. <li>
  1144. <p>Check that your TURN server is not behind NAT. As above, we're not aware of
  1145. anyone who has successfully set this up.</p>
  1146. </li>
  1147. <li>
  1148. <p>Check that you have opened your firewall to allow TCP and UDP traffic to the
  1149. TURN ports (normally 3478 and 5479).</p>
  1150. </li>
  1151. <li>
  1152. <p>Check that you have opened your firewall to allow UDP traffic to the UDP
  1153. relay ports (49152-65535 by default).</p>
  1154. </li>
  1155. <li>
  1156. <p>Some WebRTC implementations (notably, that of Google Chrome) appear to get
  1157. confused by TURN servers which are reachable over IPv6 (this appears to be
  1158. an unexpected side-effect of its handling of multiple IP addresses as
  1159. defined by
  1160. <a href="https://tools.ietf.org/html/draft-ietf-rtcweb-ip-handling-12"><code>draft-ietf-rtcweb-ip-handling</code></a>).</p>
  1161. <p>Try removing any AAAA records for your TURN server, so that it is only
  1162. reachable over IPv4.</p>
  1163. </li>
  1164. <li>
  1165. <p>Enable more verbose logging in coturn via the <code>verbose</code> setting:</p>
  1166. <pre><code>verbose
  1167. </code></pre>
  1168. <p>... and then see if there are any clues in its logs.</p>
  1169. </li>
  1170. <li>
  1171. <p>If you are using a browser-based client under Chrome, check
  1172. <code>chrome://webrtc-internals/</code> for insights into the internals of the
  1173. negotiation. On Firefox, check the &quot;Connection Log&quot; on <code>about:webrtc</code>.</p>
  1174. <p>(Understanding the output is beyond the scope of this document!)</p>
  1175. </li>
  1176. <li>
  1177. <p>You can test your Matrix homeserver TURN setup with https://test.voip.librepush.net/.
  1178. Note that this test is not fully reliable yet, so don't be discouraged if
  1179. the test fails.
  1180. <a href="https://github.com/matrix-org/voip-tester">Here</a> is the github repo of the
  1181. source of the tester, where you can file bug reports.</p>
  1182. </li>
  1183. <li>
  1184. <p>There is a WebRTC test tool at
  1185. https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/. To
  1186. use it, you will need a username/password for your TURN server. You can
  1187. either:</p>
  1188. <ul>
  1189. <li>
  1190. <p>look for the <code>GET /_matrix/client/r0/voip/turnServer</code> request made by a
  1191. matrix client to your homeserver in your browser's network inspector. In
  1192. the response you should see <code>username</code> and <code>password</code>. Or:</p>
  1193. </li>
  1194. <li>
  1195. <p>Use the following shell commands:</p>
  1196. <pre><code class="language-sh">secret=staticAuthSecretHere
  1197. u=$((`date +%s` + 3600)):test
  1198. p=$(echo -n $u | openssl dgst -hmac $secret -sha1 -binary | base64)
  1199. echo -e &quot;username: $u\npassword: $p&quot;
  1200. </code></pre>
  1201. <p>Or:</p>
  1202. </li>
  1203. <li>
  1204. <p>Temporarily configure coturn to accept a static username/password. To do
  1205. this, comment out <code>use-auth-secret</code> and <code>static-auth-secret</code> and add the
  1206. following:</p>
  1207. <pre><code>lt-cred-mech
  1208. user=username:password
  1209. </code></pre>
  1210. <p><strong>Note</strong>: these settings will not take effect unless <code>use-auth-secret</code>
  1211. and <code>static-auth-secret</code> are disabled.</p>
  1212. <p>Restart coturn after changing the configuration file.</p>
  1213. <p>Remember to restore the original settings to go back to testing with
  1214. Matrix clients!</p>
  1215. </li>
  1216. </ul>
  1217. <p>If the TURN server is working correctly, you should see at least one <code>relay</code>
  1218. entry in the results.</p>
  1219. </li>
  1220. </ul>
  1221. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="delegation"><a class="header" href="#delegation">Delegation</a></h1>
  1222. <p>By default, other homeservers will expect to be able to reach yours via
  1223. your <code>server_name</code>, on port 8448. For example, if you set your <code>server_name</code>
  1224. to <code>example.com</code> (so that your user names look like <code>@user:example.com</code>),
  1225. other servers will try to connect to yours at <code>https://example.com:8448/</code>.</p>
  1226. <p>Delegation is a Matrix feature allowing a homeserver admin to retain a
  1227. <code>server_name</code> of <code>example.com</code> so that user IDs, room aliases, etc continue
  1228. to look like <code>*:example.com</code>, whilst having federation traffic routed
  1229. to a different server and/or port (e.g. <code>synapse.example.com:443</code>).</p>
  1230. <h2 id="well-known-delegation"><a class="header" href="#well-known-delegation">.well-known delegation</a></h2>
  1231. <p>To use this method, you need to be able to alter the
  1232. <code>server_name</code> 's https server to serve the <code>/.well-known/matrix/server</code>
  1233. URL. Having an active server (with a valid TLS certificate) serving your
  1234. <code>server_name</code> domain is out of the scope of this documentation.</p>
  1235. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> should
  1236. return a JSON structure containing the key <code>m.server</code> like so:</p>
  1237. <pre><code class="language-json">{
  1238. &quot;m.server&quot;: &quot;&lt;synapse.server.name&gt;[:&lt;yourport&gt;]&quot;
  1239. }
  1240. </code></pre>
  1241. <p>In our example, this would mean that URL <code>https://example.com/.well-known/matrix/server</code>
  1242. should return:</p>
  1243. <pre><code class="language-json">{
  1244. &quot;m.server&quot;: &quot;synapse.example.com:443&quot;
  1245. }
  1246. </code></pre>
  1247. <p>Note, specifying a port is optional. If no port is specified, then it defaults
  1248. to 8448.</p>
  1249. <p>With .well-known delegation, federating servers will check for a valid TLS
  1250. certificate for the delegated hostname (in our example: <code>synapse.example.com</code>).</p>
  1251. <h2 id="srv-dns-record-delegation"><a class="header" href="#srv-dns-record-delegation">SRV DNS record delegation</a></h2>
  1252. <p>It is also possible to do delegation using a SRV DNS record. However, that is
  1253. considered an advanced topic since it's a bit complex to set up, and <code>.well-known</code>
  1254. delegation is already enough in most cases.</p>
  1255. <p>However, if you really need it, you can find some documentation on how such a
  1256. 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
  1257. specification</a>.</p>
  1258. <h2 id="delegation-faq"><a class="header" href="#delegation-faq">Delegation FAQ</a></h2>
  1259. <h3 id="when-do-i-need-delegation"><a class="header" href="#when-do-i-need-delegation">When do I need delegation?</a></h3>
  1260. <p>If your homeserver's APIs are accessible on the default federation port (8448)
  1261. and the domain your <code>server_name</code> points to, you do not need any delegation.</p>
  1262. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  1263. fresh server, you could install Synapse on that host, giving it a <code>server_name</code>
  1264. of <code>example.com</code>, and once a reverse proxy has been set up to proxy all requests
  1265. sent to the port <code>8448</code> and serve TLS certificates for <code>example.com</code>, you
  1266. wouldn't need any delegation set up.</p>
  1267. <p><strong>However</strong>, if your homeserver's APIs aren't accessible on port 8448 and on the
  1268. domain <code>server_name</code> points to, you will need to let other servers know how to
  1269. find it using delegation.</p>
  1270. <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>
  1271. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  1272. find it easier to direct federation traffic to a reverse proxy and manage their
  1273. own TLS certificates, and this is a supported configuration.</p>
  1274. <p>See <a href="reverse_proxy.html">reverse_proxy.md</a> for information on setting up a
  1275. reverse proxy.</p>
  1276. <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>
  1277. <p>This is no longer necessary. If you are using a reverse proxy for all of your
  1278. TLS traffic, then you can set <code>no_tls: True</code> in the Synapse config.</p>
  1279. <p>In that case, the only reason Synapse needs the certificate is to populate a legacy
  1280. <code>tls_fingerprints</code> field in the federation API. This is ignored by Synapse 0.99.0
  1281. and later, and the only time pre-0.99 Synapses will check it is when attempting to
  1282. fetch the server keys - and generally this is delegated via <code>matrix.org</code>, which
  1283. is running a modern version of Synapse.</p>
  1284. <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>
  1285. <p>No. There is nothing stopping you from using different certificates,
  1286. particularly if you are using a reverse proxy.</p>
  1287. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="upgrading-synapse"><a class="header" href="#upgrading-synapse">Upgrading Synapse</a></h1>
  1288. <p>Before upgrading check if any special steps are required to upgrade from
  1289. the version you currently have installed to the current version of
  1290. Synapse. The extra instructions that may be required are listed later in
  1291. this document.</p>
  1292. <ul>
  1293. <li>
  1294. <p>Check that your versions of Python and PostgreSQL are still
  1295. supported.</p>
  1296. <p>Synapse follows upstream lifecycles for <a href="https://endoflife.date/python">Python</a> and
  1297. <a href="https://endoflife.date/postgresql">PostgreSQL</a>, and removes support for versions
  1298. which are no longer maintained.</p>
  1299. <p>The website <a href="https://endoflife.date">https://endoflife.date</a> also offers convenient
  1300. summaries.</p>
  1301. </li>
  1302. <li>
  1303. <p>If Synapse was installed using <a href="setup/installation.html#prebuilt-packages">prebuilt
  1304. packages</a>, you will need to follow the
  1305. normal process for upgrading those packages.</p>
  1306. </li>
  1307. <li>
  1308. <p>If Synapse was installed from source, then:</p>
  1309. <ol>
  1310. <li>
  1311. <p>Activate the virtualenv before upgrading. For example, if
  1312. Synapse is installed in a virtualenv in <code>~/synapse/env</code> then
  1313. run:</p>
  1314. <pre><code class="language-bash">source ~/synapse/env/bin/activate
  1315. </code></pre>
  1316. </li>
  1317. <li>
  1318. <p>If Synapse was installed using pip then upgrade to the latest
  1319. version by running:</p>
  1320. <pre><code class="language-bash">pip install --upgrade matrix-synapse
  1321. </code></pre>
  1322. <p>If Synapse was installed using git then upgrade to the latest
  1323. version by running:</p>
  1324. <pre><code class="language-bash">git pull
  1325. pip install --upgrade .
  1326. </code></pre>
  1327. </li>
  1328. <li>
  1329. <p>Restart Synapse:</p>
  1330. <pre><code class="language-bash">./synctl restart
  1331. </code></pre>
  1332. </li>
  1333. </ol>
  1334. </li>
  1335. </ul>
  1336. <p>To check whether your update was successful, you can check the running
  1337. server version with:</p>
  1338. <pre><code class="language-bash"># you may need to replace 'localhost:8008' if synapse is not configured
  1339. # to listen on port 8008.
  1340. curl http://localhost:8008/_synapse/admin/v1/server_version
  1341. </code></pre>
  1342. <h2 id="rolling-back-to-older-versions"><a class="header" href="#rolling-back-to-older-versions">Rolling back to older versions</a></h2>
  1343. <p>Rolling back to previous releases can be difficult, due to database
  1344. schema changes between releases. Where we have been able to test the
  1345. rollback process, this will be noted below.</p>
  1346. <p>In general, you will need to undo any changes made during the upgrade
  1347. process, for example:</p>
  1348. <ul>
  1349. <li>
  1350. <p>pip:</p>
  1351. <pre><code class="language-bash">source env/bin/activate
  1352. # replace `1.3.0` accordingly:
  1353. pip install matrix-synapse==1.3.0
  1354. </code></pre>
  1355. </li>
  1356. <li>
  1357. <p>Debian:</p>
  1358. <pre><code class="language-bash"># replace `1.3.0` and `stretch` accordingly:
  1359. wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1360. dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1361. </code></pre>
  1362. </li>
  1363. </ul>
  1364. <h1 id="upgrading-to-v1380"><a class="header" href="#upgrading-to-v1380">Upgrading to v1.38.0</a></h1>
  1365. <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>
  1366. <p>This release includes a database schema update which requires re-indexing one of
  1367. the larger tables in the database, <code>events</code>. This could result in increased
  1368. disk I/O for several hours or days after upgrading while the migration
  1369. completes. Furthermore, because we have to keep the old indexes until the new
  1370. indexes are ready, it could result in a significant, temporary, increase in
  1371. disk space.</p>
  1372. <p>To get a rough idea of the disk space required, check the current size of one
  1373. of the indexes. For example, from a <code>psql</code> shell, run the following sql:</p>
  1374. <pre><code class="language-sql">SELECT pg_size_pretty(pg_relation_size('events_order_room'));
  1375. </code></pre>
  1376. <p>We need to rebuild <strong>four</strong> indexes, so you will need to multiply this result
  1377. by four to give an estimate of the disk space required. For example, on one
  1378. particular server:</p>
  1379. <pre><code>synapse=# select pg_size_pretty(pg_relation_size('events_order_room'));
  1380. pg_size_pretty
  1381. ----------------
  1382. 288 MB
  1383. (1 row)
  1384. </code></pre>
  1385. <p>On this server, it would be wise to ensure that at least 1152MB are free.</p>
  1386. <p>The additional disk space will be freed once the migration completes.</p>
  1387. <p>SQLite databases are unaffected by this change.</p>
  1388. <h1 id="upgrading-to-v1370"><a class="header" href="#upgrading-to-v1370">Upgrading to v1.37.0</a></h1>
  1389. <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>
  1390. <p>The current spam checker interface is deprecated in favour of a new generic modules system.
  1391. 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
  1392. documentation</a>
  1393. to update their modules. Synapse administrators can refer to <a href="https://matrix-org.github.io/synapse/develop/modules.html#using-modules">this
  1394. documentation</a>
  1395. to update their configuration once the modules they are using have been updated.</p>
  1396. <p>We plan to remove support for the current spam checker interface in August 2021.</p>
  1397. <p>More module interfaces will be ported over to this new generic system in future versions
  1398. of Synapse.</p>
  1399. <h1 id="upgrading-to-v1340"><a class="header" href="#upgrading-to-v1340">Upgrading to v1.34.0</a></h1>
  1400. <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>
  1401. <p>The <code>room_invite_state_types</code> configuration setting has been deprecated
  1402. 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
  1403. file</a>.</p>
  1404. <p>If you have set <code>room_invite_state_types</code> to the default value you
  1405. should simply remove it from your configuration file. The default value
  1406. used to be:</p>
  1407. <pre><code class="language-yaml">room_invite_state_types:
  1408. - &quot;m.room.join_rules&quot;
  1409. - &quot;m.room.canonical_alias&quot;
  1410. - &quot;m.room.avatar&quot;
  1411. - &quot;m.room.encryption&quot;
  1412. - &quot;m.room.name&quot;
  1413. </code></pre>
  1414. <p>If you have customised this value, you should remove
  1415. <code>room_invite_state_types</code> and configure <code>room_prejoin_state</code> instead.</p>
  1416. <h1 id="upgrading-to-v1330"><a class="header" href="#upgrading-to-v1330">Upgrading to v1.33.0</a></h1>
  1417. <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>
  1418. <p>This may affect you if you have enabled the account validity feature,
  1419. and have made use of a custom HTML template specified by the
  1420. <code>account_validity.template_dir</code> or
  1421. <code>account_validity.account_renewed_html_path</code> Synapse config options.</p>
  1422. <p>The template can now accept an <code>expiration_ts</code> variable, which
  1423. represents the unix timestamp in milliseconds for the future date of
  1424. 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
  1425. template</a>
  1426. for an example of usage.</p>
  1427. <p>ALso note that a new HTML template, <code>account_previously_renewed.html</code>,
  1428. has been added. This is is shown to users when they attempt to renew
  1429. their account with a valid renewal token that has already been used
  1430. before. The default template contents can been found
  1431. <a href="https://github.com/matrix-org/synapse/blob/release-v1.33.0/synapse/res/templates/account_previously_renewed.html">here</a>,
  1432. and can also accept an <code>expiration_ts</code> variable. This template replaces
  1433. the error message users would previously see upon attempting to use a
  1434. valid renewal token more than once.</p>
  1435. <h1 id="upgrading-to-v1320"><a class="header" href="#upgrading-to-v1320">Upgrading to v1.32.0</a></h1>
  1436. <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>
  1437. <p>This release introduces <a href="https://github.com/matrix-org/synapse/issues/9853">a
  1438. regression</a> that can
  1439. overwhelm connected Prometheus instances. This issue is not present in
  1440. Synapse v1.32.0rc1.</p>
  1441. <p>If you have been affected, please downgrade to 1.31.0. You then may need
  1442. to remove excess writeahead logs in order for Prometheus to recover.
  1443. Instructions for doing so are provided
  1444. <a href="https://github.com/matrix-org/synapse/pull/9854#issuecomment-823472183">here</a>.</p>
  1445. <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>
  1446. <p>In line with our <a href="https://github.com/matrix-org/synapse/blob/release-v1.32.0/docs/deprecation_policy.md">deprecation
  1447. policy</a>,
  1448. we've dropped support for Python 3.5 and PostgreSQL 9.5, as they are no
  1449. longer supported upstream.</p>
  1450. <p>This release of Synapse requires Python 3.6+ and PostgresSQL 9.6+ or
  1451. SQLite 3.22+.</p>
  1452. <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>
  1453. <p>The deprecated v1 &quot;list accounts&quot; admin API
  1454. (<code>GET /_synapse/admin/v1/users/&lt;user_id&gt;</code>) has been removed in this
  1455. version.</p>
  1456. <p>The <a href="https://github.com/matrix-org/synapse/blob/master/docs/admin_api/user_admin_api.rst#list-accounts">v2 list accounts
  1457. API</a>
  1458. has been available since Synapse 1.7.0 (2019-12-13), and is accessible
  1459. under <code>GET /_synapse/admin/v2/users</code>.</p>
  1460. <p>The deprecation of the old endpoint was announced with Synapse 1.28.0
  1461. (released on 2021-02-25).</p>
  1462. <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>
  1463. <p>In compliance with the <a href="https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions">Application Service
  1464. spec</a>,
  1465. Application Services are now required to use the
  1466. <code>m.login.application_service</code> type when registering users via the
  1467. <code>/_matrix/client/r0/register</code> endpoint. This behaviour was deprecated in
  1468. Synapse v1.30.0.</p>
  1469. <p>Please ensure your Application Services are up to date.</p>
  1470. <h1 id="upgrading-to-v1290"><a class="header" href="#upgrading-to-v1290">Upgrading to v1.29.0</a></h1>
  1471. <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>
  1472. <p>When using Synapse with a reverse proxy (in particular, when using the
  1473. [x_forwarded]{.title-ref} option on an HTTP listener), Synapse now
  1474. expects to receive an [X-Forwarded-Proto]{.title-ref} header on incoming
  1475. HTTP requests. If it is not set, Synapse will log a warning on each
  1476. received request.</p>
  1477. <p>To avoid the warning, administrators using a reverse proxy should ensure
  1478. that the reverse proxy sets [X-Forwarded-Proto]{.title-ref} header to
  1479. [https]{.title-ref} or [http]{.title-ref} to indicate the protocol used
  1480. by the client.</p>
  1481. <p>Synapse also requires the [Host]{.title-ref} header to be preserved.</p>
  1482. <p>See the <a href="../reverse_proxy.html">reverse proxy documentation</a>, where the
  1483. example configurations have been updated to show how to set these
  1484. headers.</p>
  1485. <p>(Users of <a href="https://caddyserver.com/">Caddy</a> are unaffected, since we
  1486. believe it sets [X-Forwarded-Proto]{.title-ref} by default.)</p>
  1487. <h1 id="upgrading-to-v1270"><a class="header" href="#upgrading-to-v1270">Upgrading to v1.27.0</a></h1>
  1488. <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>
  1489. <p>This version changes the URI used for callbacks from OAuth2 and SAML2
  1490. identity providers:</p>
  1491. <ul>
  1492. <li>
  1493. <p>If your server is configured for single sign-on via an OpenID
  1494. Connect or OAuth2 identity provider, you will need to add
  1495. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> to the list
  1496. of permitted &quot;redirect URIs&quot; at the identity provider.</p>
  1497. <p>See the <a href="../openid.html">OpenID docs</a> for more information on setting
  1498. up OpenID Connect.</p>
  1499. </li>
  1500. <li>
  1501. <p>If your server is configured for single sign-on via a SAML2 identity
  1502. provider, you will need to add
  1503. <code>[synapse public baseurl]/_synapse/client/saml2/authn_response</code> as a
  1504. permitted &quot;ACS location&quot; (also known as &quot;allowed callback URLs&quot;)
  1505. at the identity provider.</p>
  1506. <p>The &quot;Issuer&quot; in the &quot;AuthnRequest&quot; to the SAML2 identity
  1507. provider is also updated to
  1508. <code>[synapse public baseurl]/_synapse/client/saml2/metadata.xml</code>. If
  1509. your SAML2 identity provider uses this property to validate or
  1510. otherwise identify Synapse, its configuration will need to be
  1511. updated to use the new URL. Alternatively you could create a new,
  1512. separate &quot;EntityDescriptor&quot; in your SAML2 identity provider with
  1513. the new URLs and leave the URLs in the existing &quot;EntityDescriptor&quot;
  1514. as they were.</p>
  1515. </li>
  1516. </ul>
  1517. <h2 id="changes-to-html-templates"><a class="header" href="#changes-to-html-templates">Changes to HTML templates</a></h2>
  1518. <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
  1519. autoescape</a>
  1520. enabled for files ending in <code>.html</code>, <code>.htm</code>, and <code>.xml</code>. If you have
  1521. customised these templates and see issues when viewing them you might
  1522. need to update them. It is expected that most configurations will need
  1523. no changes.</p>
  1524. <p>If you have customised the templates <em>names</em> for these templates, it is
  1525. recommended to verify they end in <code>.html</code> to ensure autoescape is
  1526. enabled.</p>
  1527. <p>The above applies to the following templates:</p>
  1528. <ul>
  1529. <li><code>add_threepid.html</code></li>
  1530. <li><code>add_threepid_failure.html</code></li>
  1531. <li><code>add_threepid_success.html</code></li>
  1532. <li><code>notice_expiry.html</code></li>
  1533. <li><code>notice_expiry.html</code></li>
  1534. <li><code>notif_mail.html</code> (which, by default, includes <code>room.html</code> and
  1535. <code>notif.html</code>)</li>
  1536. <li><code>password_reset.html</code></li>
  1537. <li><code>password_reset_confirmation.html</code></li>
  1538. <li><code>password_reset_failure.html</code></li>
  1539. <li><code>password_reset_success.html</code></li>
  1540. <li><code>registration.html</code></li>
  1541. <li><code>registration_failure.html</code></li>
  1542. <li><code>registration_success.html</code></li>
  1543. <li><code>sso_account_deactivated.html</code></li>
  1544. <li><code>sso_auth_bad_user.html</code></li>
  1545. <li><code>sso_auth_confirm.html</code></li>
  1546. <li><code>sso_auth_success.html</code></li>
  1547. <li><code>sso_error.html</code></li>
  1548. <li><code>sso_login_idp_picker.html</code></li>
  1549. <li><code>sso_redirect_confirm.html</code></li>
  1550. </ul>
  1551. <h1 id="upgrading-to-v1260"><a class="header" href="#upgrading-to-v1260">Upgrading to v1.26.0</a></h1>
  1552. <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>
  1553. <p>v1.26.0 includes a lot of large changes. If something problematic
  1554. occurs, you may want to roll-back to a previous version of Synapse.
  1555. Because v1.26.0 also includes a new database schema version, reverting
  1556. that version is also required alongside the generic rollback
  1557. instructions mentioned above. In short, to roll back to v1.25.0 you need
  1558. to:</p>
  1559. <ol>
  1560. <li>
  1561. <p>Stop the server</p>
  1562. </li>
  1563. <li>
  1564. <p>Decrease the schema version in the database:</p>
  1565. <pre><code class="language-sql">UPDATE schema_version SET version = 58;
  1566. </code></pre>
  1567. </li>
  1568. <li>
  1569. <p>Delete the ignored users &amp; chain cover data:</p>
  1570. <pre><code class="language-sql">DROP TABLE IF EXISTS ignored_users;
  1571. UPDATE rooms SET has_auth_chain_index = false;
  1572. </code></pre>
  1573. <p>For PostgreSQL run:</p>
  1574. <pre><code class="language-sql">TRUNCATE event_auth_chain_links;
  1575. TRUNCATE event_auth_chains;
  1576. </code></pre>
  1577. <p>For SQLite run:</p>
  1578. <pre><code class="language-sql">DELETE FROM event_auth_chain_links;
  1579. DELETE FROM event_auth_chains;
  1580. </code></pre>
  1581. </li>
  1582. <li>
  1583. <p>Mark the deltas as not run (so they will re-run on upgrade).</p>
  1584. <pre><code class="language-sql">DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/01ignored_user.py&quot;;
  1585. DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/06chain_cover_index.sql&quot;;
  1586. </code></pre>
  1587. </li>
  1588. <li>
  1589. <p>Downgrade Synapse by following the instructions for your
  1590. installation method in the &quot;Rolling back to older versions&quot;
  1591. section above.</p>
  1592. </li>
  1593. </ol>
  1594. <h1 id="upgrading-to-v1250"><a class="header" href="#upgrading-to-v1250">Upgrading to v1.25.0</a></h1>
  1595. <h2 id="last-release-supporting-python-35"><a class="header" href="#last-release-supporting-python-35">Last release supporting Python 3.5</a></h2>
  1596. <p>This is the last release of Synapse which guarantees support with Python
  1597. 3.5, which passed its upstream End of Life date several months ago.</p>
  1598. <p>We will attempt to maintain support through March 2021, but without
  1599. guarantees.</p>
  1600. <p>In the future, Synapse will follow upstream schedules for ending support
  1601. of older versions of Python and PostgreSQL. Please upgrade to at least
  1602. Python 3.6 and PostgreSQL 9.6 as soon as possible.</p>
  1603. <h2 id="blacklisting-ip-ranges"><a class="header" href="#blacklisting-ip-ranges">Blacklisting IP ranges</a></h2>
  1604. <p>Synapse v1.25.0 includes new settings, <code>ip_range_blacklist</code> and
  1605. <code>ip_range_whitelist</code>, for controlling outgoing requests from Synapse for
  1606. federation, identity servers, push, and for checking key validity for
  1607. third-party invite events. The previous setting,
  1608. <code>federation_ip_range_blacklist</code>, is deprecated. The new
  1609. <code>ip_range_blacklist</code> defaults to private IP ranges if it is not defined.</p>
  1610. <p>If you have never customised <code>federation_ip_range_blacklist</code> it is
  1611. recommended that you remove that setting.</p>
  1612. <p>If you have customised <code>federation_ip_range_blacklist</code> you should update
  1613. the setting name to <code>ip_range_blacklist</code>.</p>
  1614. <p>If you have a custom push server that is reached via private IP space
  1615. you may need to customise <code>ip_range_blacklist</code> or <code>ip_range_whitelist</code>.</p>
  1616. <h1 id="upgrading-to-v1240"><a class="header" href="#upgrading-to-v1240">Upgrading to v1.24.0</a></h1>
  1617. <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>
  1618. <p>This release allows the OpenID Connect mapping provider to perform
  1619. normalisation of the localpart of the Matrix ID. This allows for the
  1620. mapping provider to specify different algorithms, instead of the
  1621. <a href="https://matrix.org/docs/spec/appendices#mapping-from-other-character-sets">default
  1622. way</a>.</p>
  1623. <p>If your Synapse configuration uses a custom mapping provider
  1624. ([oidc_config.user_mapping_provider.module]{.title-ref} is specified and
  1625. not equal to
  1626. [synapse.handlers.oidc_handler.JinjaOidcMappingProvider]{.title-ref})
  1627. then you <em>must</em> ensure that [map_user_attributes]{.title-ref} of the
  1628. mapping provider performs some normalisation of the
  1629. [localpart]{.title-ref} returned. To match previous behaviour you can
  1630. use the [map_username_to_mxid_localpart]{.title-ref} function provided
  1631. by Synapse. An example is shown below:</p>
  1632. <pre><code class="language-python">from synapse.types import map_username_to_mxid_localpart
  1633. class MyMappingProvider:
  1634. def map_user_attributes(self, userinfo, token):
  1635. # ... your custom logic ...
  1636. sso_user_id = ...
  1637. localpart = map_username_to_mxid_localpart(sso_user_id)
  1638. return {&quot;localpart&quot;: localpart}
  1639. </code></pre>
  1640. <h2 id="removal-historical-synapse-admin-api"><a class="header" href="#removal-historical-synapse-admin-api">Removal historical Synapse Admin API</a></h2>
  1641. <p>Historically, the Synapse Admin API has been accessible under:</p>
  1642. <ul>
  1643. <li><code>/_matrix/client/api/v1/admin</code></li>
  1644. <li><code>/_matrix/client/unstable/admin</code></li>
  1645. <li><code>/_matrix/client/r0/admin</code></li>
  1646. <li><code>/_synapse/admin/v1</code></li>
  1647. </ul>
  1648. <p>The endpoints with <code>/_matrix/client/*</code> prefixes have been removed as of
  1649. v1.24.0. The Admin API is now only accessible under:</p>
  1650. <ul>
  1651. <li><code>/_synapse/admin/v1</code></li>
  1652. </ul>
  1653. <p>The only exception is the [/admin/whois]{.title-ref} endpoint, which is
  1654. <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
  1655. API</a>.</p>
  1656. <p>The deprecation of the old endpoints was announced with Synapse 1.20.0
  1657. (released on 2020-09-22) and makes it easier for homeserver admins to
  1658. lock down external access to the Admin API endpoints.</p>
  1659. <h1 id="upgrading-to-v1230"><a class="header" href="#upgrading-to-v1230">Upgrading to v1.23.0</a></h1>
  1660. <h2 id="structured-logging-configuration-breaking-changes"><a class="header" href="#structured-logging-configuration-breaking-changes">Structured logging configuration breaking changes</a></h2>
  1661. <p>This release deprecates use of the <code>structured: true</code> logging
  1662. configuration for structured logging. If your logging configuration
  1663. contains <code>structured: true</code> then it should be modified based on the
  1664. <a href="../structured_logging.html">structured logging
  1665. documentation</a>.</p>
  1666. <p>The <code>structured</code> and <code>drains</code> logging options are now deprecated and
  1667. should be replaced by standard logging configuration of <code>handlers</code> and
  1668. <code>formatters</code>.</p>
  1669. <p>A future will release of Synapse will make using <code>structured: true</code> an
  1670. error.</p>
  1671. <h1 id="upgrading-to-v1220"><a class="header" href="#upgrading-to-v1220">Upgrading to v1.22.0</a></h1>
  1672. <h2 id="thirdpartyeventrules-breaking-changes"><a class="header" href="#thirdpartyeventrules-breaking-changes">ThirdPartyEventRules breaking changes</a></h2>
  1673. <p>This release introduces a backwards-incompatible change to modules
  1674. making use of <code>ThirdPartyEventRules</code> in Synapse. If you make use of a
  1675. module defined under the <code>third_party_event_rules</code> config option, please
  1676. make sure it is updated to handle the below change:</p>
  1677. <p>The <code>http_client</code> argument is no longer passed to modules as they are
  1678. initialised. Instead, modules are expected to make use of the
  1679. <code>http_client</code> property on the <code>ModuleApi</code> class. Modules are now passed
  1680. a <code>module_api</code> argument during initialisation, which is an instance of
  1681. <code>ModuleApi</code>. <code>ModuleApi</code> instances have a <code>http_client</code> property which
  1682. acts the same as the <code>http_client</code> argument previously passed to
  1683. <code>ThirdPartyEventRules</code> modules.</p>
  1684. <h1 id="upgrading-to-v1210"><a class="header" href="#upgrading-to-v1210">Upgrading to v1.21.0</a></h1>
  1685. <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>
  1686. <p>The <a href="https://github.com/matrix-org/synapse/blob/develop/docs/reverse_proxy.md">reverse proxy
  1687. documentation</a>
  1688. has been updated to include reverse proxy directives for
  1689. <code>/_synapse/client/*</code> endpoints. As the user password reset flow now uses
  1690. endpoints under this prefix, <strong>you must update your reverse proxy
  1691. configurations for user password reset to work</strong>.</p>
  1692. <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>
  1693. <p>: state that the <code>/_synapse/client/password_reset/email/submit_token</code>
  1694. endpoint can be handled</p>
  1695. <p>by all workers. If you make use of Synapse's worker feature, please
  1696. update your reverse proxy configuration to reflect this change.</p>
  1697. <h2 id="new-html-templates"><a class="header" href="#new-html-templates">New HTML templates</a></h2>
  1698. <p>A new HTML template,
  1699. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/res/templates/password_reset_confirmation.html">password_reset_confirmation.html</a>,
  1700. has been added to the <code>synapse/res/templates</code> directory. If you are
  1701. using a custom template directory, you may want to copy the template
  1702. over and modify it.</p>
  1703. <p>Note that as of v1.20.0, templates do not need to be included in custom
  1704. template directories for Synapse to start. The default templates will be
  1705. used if a custom template cannot be found.</p>
  1706. <p>This page will appear to the user after clicking a password reset link
  1707. that has been emailed to them.</p>
  1708. <p>To complete password reset, the page must include a way to make a
  1709. [POST]{.title-ref} request to
  1710. <code>/_synapse/client/password_reset/{medium}/submit_token</code> with the query
  1711. parameters from the original link, presented as a URL-encoded form. See
  1712. the file itself for more details.</p>
  1713. <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>
  1714. <p>The <code>saml_error.html</code> template was removed from Synapse and replaced
  1715. with the <code>sso_error.html</code> template. If your Synapse is configured to use
  1716. SAML and a custom <code>sso_redirect_confirm_template_dir</code> configuration then
  1717. any customisations of the <code>saml_error.html</code> template will need to be
  1718. merged into the <code>sso_error.html</code> template. These templates are similar,
  1719. but the parameters are slightly different:</p>
  1720. <ul>
  1721. <li>The <code>msg</code> parameter should be renamed to <code>error_description</code>.</li>
  1722. <li>There is no longer a <code>code</code> parameter for the response code.</li>
  1723. <li>A string <code>error</code> parameter is available that includes a short hint
  1724. of why a user is seeing the error page.</li>
  1725. </ul>
  1726. <h1 id="upgrading-to-v1180"><a class="header" href="#upgrading-to-v1180">Upgrading to v1.18.0</a></h1>
  1727. <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>
  1728. <p>From 10th August 2020, we will no longer publish Docker images with the
  1729. [-py3]{.title-ref} tag suffix. The images tagged with the
  1730. [-py3]{.title-ref} suffix have been identical to the non-suffixed tags
  1731. since release 0.99.0, and the suffix is obsolete.</p>
  1732. <p>On 10th August, we will remove the [latest-py3]{.title-ref} tag.
  1733. Existing per-release tags (such as [v1.18.0-py3]{.title-ref}) will not
  1734. be removed, but no new [-py3]{.title-ref} tags will be added.</p>
  1735. <p>Scripts relying on the [-py3]{.title-ref} suffix will need to be
  1736. updated.</p>
  1737. <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>
  1738. <p>When setting up worker processes, we now recommend the use of a Redis
  1739. server for replication. <strong>The old direct TCP connection method is
  1740. deprecated and will be removed in a future release.</strong> See
  1741. <a href="../workers.html">workers</a> for more details.</p>
  1742. <h1 id="upgrading-to-v1140"><a class="header" href="#upgrading-to-v1140">Upgrading to v1.14.0</a></h1>
  1743. <p>This version includes a database update which is run as part of the
  1744. upgrade, and which may take a couple of minutes in the case of a large
  1745. server. Synapse will not respond to HTTP requests while this update is
  1746. taking place.</p>
  1747. <h1 id="upgrading-to-v1130"><a class="header" href="#upgrading-to-v1130">Upgrading to v1.13.0</a></h1>
  1748. <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>
  1749. <p>A bug was introduced in Synapse 1.4.0 which could cause the room
  1750. directory to be incomplete or empty if Synapse was upgraded directly
  1751. from v1.2.1 or earlier, to versions between v1.4.0 and v1.12.x.</p>
  1752. <p>This will <em>not</em> be a problem for Synapse installations which were:</p>
  1753. <p>: - created at v1.4.0 or later,
  1754. - upgraded via v1.3.x, or
  1755. - upgraded straight from v1.2.1 or earlier to v1.13.0 or later.</p>
  1756. <p>If completeness of the room directory is a concern, installations which
  1757. are affected can be repaired as follows:</p>
  1758. <ol>
  1759. <li>
  1760. <p>Run the following sql from a [psql]{.title-ref} or
  1761. [sqlite3]{.title-ref} console:</p>
  1762. <pre><code class="language-sql">INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1763. ('populate_stats_process_rooms', '{}', 'current_state_events_membership');
  1764. INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1765. ('populate_stats_process_users', '{}', 'populate_stats_process_rooms');
  1766. </code></pre>
  1767. </li>
  1768. <li>
  1769. <p>Restart synapse.</p>
  1770. </li>
  1771. </ol>
  1772. <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>
  1773. <p>New templates (<code>sso_auth_confirm.html</code>, <code>sso_auth_success.html</code>, and
  1774. <code>sso_account_deactivated.html</code>) were added to Synapse. If your Synapse
  1775. is configured to use SSO and a custom
  1776. <code>sso_redirect_confirm_template_dir</code> configuration then these templates
  1777. will need to be copied from
  1778. <a href="synapse/res/templates">synapse/res/templates</a> into that directory.</p>
  1779. <h2 id="synapse-sso-plugins-method-deprecation"><a class="header" href="#synapse-sso-plugins-method-deprecation">Synapse SSO Plugins Method Deprecation</a></h2>
  1780. <p>Plugins using the <code>complete_sso_login</code> method of
  1781. <code>synapse.module_api.ModuleApi</code> should update to using the async/await
  1782. version <code>complete_sso_login_async</code> which includes additional checks. The
  1783. non-async version is considered deprecated.</p>
  1784. <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>
  1785. <p>v1.13.0 includes a lot of large changes. If something problematic
  1786. occurs, you may want to roll-back to a previous version of Synapse.
  1787. Because v1.13.0 also includes a new database schema version, reverting
  1788. that version is also required alongside the generic rollback
  1789. instructions mentioned above. In short, to roll back to v1.12.4 you need
  1790. to:</p>
  1791. <ol>
  1792. <li>
  1793. <p>Stop the server</p>
  1794. </li>
  1795. <li>
  1796. <p>Decrease the schema version in the database:</p>
  1797. <pre><code class="language-sql">UPDATE schema_version SET version = 57;
  1798. </code></pre>
  1799. </li>
  1800. <li>
  1801. <p>Downgrade Synapse by following the instructions for your
  1802. installation method in the &quot;Rolling back to older versions&quot;
  1803. section above.</p>
  1804. </li>
  1805. </ol>
  1806. <h1 id="upgrading-to-v1120"><a class="header" href="#upgrading-to-v1120">Upgrading to v1.12.0</a></h1>
  1807. <p>This version includes a database update which is run as part of the
  1808. upgrade, and which may take some time (several hours in the case of a
  1809. large server). Synapse will not respond to HTTP requests while this
  1810. update is taking place.</p>
  1811. <p>This is only likely to be a problem in the case of a server which is
  1812. participating in many rooms.</p>
  1813. <ol start="0">
  1814. <li>
  1815. <p>As with all upgrades, it is recommended that you have a recent
  1816. backup of your database which can be used for recovery in the event
  1817. of any problems.</p>
  1818. </li>
  1819. <li>
  1820. <p>As an initial check to see if you will be affected, you can try
  1821. running the following query from the [psql]{.title-ref} or
  1822. [sqlite3]{.title-ref} console. It is safe to run it while Synapse is
  1823. still running.</p>
  1824. <pre><code class="language-sql">SELECT MAX(q.v) FROM (
  1825. SELECT (
  1826. SELECT ej.json AS v
  1827. FROM state_events se INNER JOIN event_json ej USING (event_id)
  1828. WHERE se.room_id=rooms.room_id AND se.type='m.room.create' AND se.state_key=''
  1829. LIMIT 1
  1830. ) FROM rooms WHERE rooms.room_version IS NULL
  1831. ) q;
  1832. </code></pre>
  1833. <p>This query will take about the same amount of time as the upgrade
  1834. process: ie, if it takes 5 minutes, then it is likely that Synapse
  1835. will be unresponsive for 5 minutes during the upgrade.</p>
  1836. <p>If you consider an outage of this duration to be acceptable, no
  1837. further action is necessary and you can simply start Synapse 1.12.0.</p>
  1838. <p>If you would prefer to reduce the downtime, continue with the steps
  1839. below.</p>
  1840. </li>
  1841. <li>
  1842. <p>The easiest workaround for this issue is to manually create a new
  1843. index before upgrading. On PostgreSQL, his can be done as follows:</p>
  1844. <pre><code class="language-sql">CREATE INDEX CONCURRENTLY tmp_upgrade_1_12_0_index
  1845. ON state_events(room_id) WHERE type = 'm.room.create';
  1846. </code></pre>
  1847. <p>The above query may take some time, but is also safe to run while
  1848. Synapse is running.</p>
  1849. <p>We assume that no SQLite users have databases large enough to be
  1850. affected. If you <em>are</em> affected, you can run a similar query,
  1851. omitting the <code>CONCURRENTLY</code> keyword. Note however that this
  1852. operation may in itself cause Synapse to stop running for some time.
  1853. 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
  1854. outside a test
  1855. environment</a>.</p>
  1856. </li>
  1857. <li>
  1858. <p>Once the index has been created, the <code>SELECT</code> query in step 1 above
  1859. should complete quickly. It is therefore safe to upgrade to Synapse
  1860. 1.12.0.</p>
  1861. </li>
  1862. <li>
  1863. <p>Once Synapse 1.12.0 has successfully started and is responding to
  1864. HTTP requests, the temporary index can be removed:</p>
  1865. <pre><code class="language-sql">DROP INDEX tmp_upgrade_1_12_0_index;
  1866. </code></pre>
  1867. </li>
  1868. </ol>
  1869. <h1 id="upgrading-to-v1100"><a class="header" href="#upgrading-to-v1100">Upgrading to v1.10.0</a></h1>
  1870. <p>Synapse will now log a warning on start up if used with a PostgreSQL
  1871. database that has a non-recommended locale set.</p>
  1872. <p>See <a href="../postgres.html">Postgres</a> for details.</p>
  1873. <h1 id="upgrading-to-v180"><a class="header" href="#upgrading-to-v180">Upgrading to v1.8.0</a></h1>
  1874. <p>Specifying a <code>log_file</code> config option will now cause Synapse to refuse
  1875. to start, and should be replaced by with the <code>log_config</code> option.
  1876. Support for the <code>log_file</code> option was removed in v1.3.0 and has since
  1877. had no effect.</p>
  1878. <h1 id="upgrading-to-v170"><a class="header" href="#upgrading-to-v170">Upgrading to v1.7.0</a></h1>
  1879. <p>In an attempt to configure Synapse in a privacy preserving way, the
  1880. default behaviours of <code>allow_public_rooms_without_auth</code> and
  1881. <code>allow_public_rooms_over_federation</code> have been inverted. This means that
  1882. by default, only authenticated users querying the Client/Server API will
  1883. be able to query the room directory, and relatedly that the server will
  1884. not share room directory information with other servers over federation.</p>
  1885. <p>If your installation does not explicitly set these settings one way or
  1886. the other and you want either setting to be <code>true</code> then it will
  1887. necessary to update your homeserver configuration file accordingly.</p>
  1888. <p>For more details on the surrounding context see our
  1889. <a href="https://matrix.org/blog/2019/11/09/avoiding-unwelcome-visitors-on-private-matrix-servers">explainer</a>.</p>
  1890. <h1 id="upgrading-to-v150"><a class="header" href="#upgrading-to-v150">Upgrading to v1.5.0</a></h1>
  1891. <p>This release includes a database migration which may take several
  1892. minutes to complete if there are a large number (more than a million or
  1893. so) of entries in the <code>devices</code> table. This is only likely to a be a
  1894. problem on very large installations.</p>
  1895. <h1 id="upgrading-to-v140"><a class="header" href="#upgrading-to-v140">Upgrading to v1.4.0</a></h1>
  1896. <h2 id="new-custom-templates"><a class="header" href="#new-custom-templates">New custom templates</a></h2>
  1897. <p>If you have configured a custom template directory with the
  1898. <code>email.template_dir</code> option, be aware that there are new templates
  1899. regarding registration and threepid management (see below) that must be
  1900. included.</p>
  1901. <ul>
  1902. <li><code>registration.html</code> and <code>registration.txt</code></li>
  1903. <li><code>registration_success.html</code> and <code>registration_failure.html</code></li>
  1904. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code></li>
  1905. <li><code>add_threepid_failure.html</code> and <code>add_threepid_success.html</code></li>
  1906. </ul>
  1907. <p>Synapse will expect these files to exist inside the configured template
  1908. directory, and <strong>will fail to start</strong> if they are absent. To view the
  1909. default templates, see
  1910. <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">synapse/res/templates</a>.</p>
  1911. <h2 id="3pid-verification-changes"><a class="header" href="#3pid-verification-changes">3pid verification changes</a></h2>
  1912. <p><strong>Note: As of this release, users will be unable to add phone numbers or
  1913. email addresses to their accounts, without changes to the Synapse
  1914. configuration. This includes adding an email address during
  1915. registration.</strong></p>
  1916. <p>It is possible for a user to associate an email address or phone number
  1917. with their account, for a number of reasons:</p>
  1918. <ul>
  1919. <li>for use when logging in, as an alternative to the user id.</li>
  1920. <li>in the case of email, as an alternative contact to help with account
  1921. recovery.</li>
  1922. <li>in the case of email, to receive notifications of missed messages.</li>
  1923. </ul>
  1924. <p>Before an email address or phone number can be added to a user's
  1925. account, or before such an address is used to carry out a
  1926. password-reset, Synapse must confirm the operation with the owner of the
  1927. email address or phone number. It does this by sending an email or text
  1928. giving the user a link or token to confirm receipt. This process is
  1929. known as '3pid verification'. ('3pid', or 'threepid', stands for
  1930. third-party identifier, and we use it to refer to external identifiers
  1931. such as email addresses and phone numbers.)</p>
  1932. <p>Previous versions of Synapse delegated the task of 3pid verification to
  1933. an identity server by default. In most cases this server is <code>vector.im</code>
  1934. or <code>matrix.org</code>.</p>
  1935. <p>In Synapse 1.4.0, for security and privacy reasons, the homeserver will
  1936. no longer delegate this task to an identity server by default. Instead,
  1937. the server administrator will need to explicitly decide how they would
  1938. like the verification messages to be sent.</p>
  1939. <p>In the medium term, the <code>vector.im</code> and <code>matrix.org</code> identity servers
  1940. will disable support for delegated 3pid verification entirely. However,
  1941. in order to ease the transition, they will retain the capability for a
  1942. limited period. Delegated email verification will be disabled on Monday
  1943. 2nd December 2019 (giving roughly 2 months notice). Disabling delegated
  1944. SMS verification will follow some time after that once SMS verification
  1945. support lands in Synapse.</p>
  1946. <p>Once delegated 3pid verification support has been disabled in the
  1947. <code>vector.im</code> and <code>matrix.org</code> identity servers, all Synapse versions that
  1948. depend on those instances will be unable to verify email and phone
  1949. numbers through them. There are no imminent plans to remove delegated
  1950. 3pid verification from Sydent generally. (Sydent is the identity server
  1951. project that backs the <code>vector.im</code> and <code>matrix.org</code> instances).</p>
  1952. <h3 id="email-1"><a class="header" href="#email-1">Email</a></h3>
  1953. <p>Following upgrade, to continue verifying email (e.g. as part of the
  1954. registration process), admins can either:-</p>
  1955. <ul>
  1956. <li>Configure Synapse to use an email server.</li>
  1957. <li>Run or choose an identity server which allows delegated email
  1958. verification and delegate to it.</li>
  1959. </ul>
  1960. <h4 id="configure-smtp-in-synapse"><a class="header" href="#configure-smtp-in-synapse">Configure SMTP in Synapse</a></h4>
  1961. <p>To configure an SMTP server for Synapse, modify the configuration
  1962. section headed <code>email</code>, and be sure to have at least the
  1963. <code>smtp_host, smtp_port</code> and <code>notif_from</code> fields filled out.</p>
  1964. <p>You may also need to set <code>smtp_user</code>, <code>smtp_pass</code>, and
  1965. <code>require_transport_security</code>.</p>
  1966. <p>See the <a href="docs/sample_config.yaml">sample configuration file</a> for more
  1967. details on these settings.</p>
  1968. <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>
  1969. <p>Some admins will wish to continue using email verification as part of
  1970. the registration process, but will not immediately have an appropriate
  1971. SMTP server at hand.</p>
  1972. <p>To this end, we will continue to support email verification delegation
  1973. via the <code>vector.im</code> and <code>matrix.org</code> identity servers for two months.
  1974. Support for delegated email verification will be disabled on Monday 2nd
  1975. December.</p>
  1976. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  1977. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  1978. server</a>) to handle
  1979. sending confirmation messages via email and SMS.</p>
  1980. <p>So to delegate email verification, in <code>homeserver.yaml</code>, set
  1981. <code>account_threepid_delegates.email</code> to the base URL of an identity
  1982. server. For example:</p>
  1983. <pre><code class="language-yaml">account_threepid_delegates:
  1984. email: https://example.com # Delegate email sending to example.com
  1985. </code></pre>
  1986. <p>Note that <code>account_threepid_delegates.email</code> replaces the deprecated
  1987. <code>email.trust_identity_server_for_password_resets</code>: if
  1988. <code>email.trust_identity_server_for_password_resets</code> is set to <code>true</code>, and
  1989. <code>account_threepid_delegates.email</code> is not set, then the first entry in
  1990. <code>trusted_third_party_id_servers</code> will be used as the
  1991. <code>account_threepid_delegate</code> for email. This is to ensure compatibility
  1992. with existing Synapse installs that set up external server handling for
  1993. these tasks before v1.4.0. If
  1994. <code>email.trust_identity_server_for_password_resets</code> is <code>true</code> and no
  1995. trusted identity server domains are configured, Synapse will report an
  1996. error and refuse to start.</p>
  1997. <p>If <code>email.trust_identity_server_for_password_resets</code> is <code>false</code> or
  1998. absent and no <code>email</code> delegate is configured in
  1999. <code>account_threepid_delegates</code>, then Synapse will send email verification
  2000. messages itself, using the configured SMTP server (see above). that
  2001. type.</p>
  2002. <h3 id="phone-numbers"><a class="header" href="#phone-numbers">Phone numbers</a></h3>
  2003. <p>Synapse does not support phone-number verification itself, so the only
  2004. way to maintain the ability for users to add phone numbers to their
  2005. accounts will be by continuing to delegate phone number verification to
  2006. the <code>matrix.org</code> and <code>vector.im</code> identity servers (or another identity
  2007. server that supports SMS sending).</p>
  2008. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2009. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2010. server</a>) to handle
  2011. sending confirmation messages via email and SMS.</p>
  2012. <p>So to delegate phone number verification, in <code>homeserver.yaml</code>, set
  2013. <code>account_threepid_delegates.msisdn</code> to the base URL of an identity
  2014. server. For example:</p>
  2015. <pre><code class="language-yaml">account_threepid_delegates:
  2016. msisdn: https://example.com # Delegate sms sending to example.com
  2017. </code></pre>
  2018. <p>The <code>matrix.org</code> and <code>vector.im</code> identity servers will continue to
  2019. support delegated phone number verification via SMS until such time as
  2020. it is possible for admins to configure their servers to perform phone
  2021. number verification directly. More details will follow in a future
  2022. release.</p>
  2023. <h2 id="rolling-back-to-v131"><a class="header" href="#rolling-back-to-v131">Rolling back to v1.3.1</a></h2>
  2024. <p>If you encounter problems with v1.4.0, it should be possible to roll
  2025. back to v1.3.1, subject to the following:</p>
  2026. <ul>
  2027. <li>
  2028. <p>The 'room statistics' engine was heavily reworked in this release
  2029. (see <a href="https://github.com/matrix-org/synapse/pull/5971">#5971</a>),
  2030. including significant changes to the database schema, which are not
  2031. easily reverted. This will cause the room statistics engine to stop
  2032. updating when you downgrade.</p>
  2033. <p>The room statistics are essentially unused in v1.3.1 (in future
  2034. versions of Synapse, they will be used to populate the room
  2035. directory), so there should be no loss of functionality. However,
  2036. the statistics engine will write errors to the logs, which can be
  2037. avoided by setting the following in <code>homeserver.yaml</code>:</p>
  2038. <pre><code class="language-yaml">stats:
  2039. enabled: false
  2040. </code></pre>
  2041. <p>Don't forget to re-enable it when you upgrade again, in preparation
  2042. for its use in the room directory!</p>
  2043. </li>
  2044. </ul>
  2045. <h1 id="upgrading-to-v120"><a class="header" href="#upgrading-to-v120">Upgrading to v1.2.0</a></h1>
  2046. <p>Some counter metrics have been renamed, with the old names deprecated.
  2047. See <a href="../metrics-howto.html#renaming-of-metrics--deprecation-of-old-names-in-12">the metrics
  2048. documentation</a>
  2049. for details.</p>
  2050. <h1 id="upgrading-to-v110"><a class="header" href="#upgrading-to-v110">Upgrading to v1.1.0</a></h1>
  2051. <p>Synapse v1.1.0 removes support for older Python and PostgreSQL versions,
  2052. as outlined in <a href="https://matrix.org/blog/2019/04/08/synapse-deprecating-postgres-9-4-and-python-2-x">our deprecation
  2053. notice</a>.</p>
  2054. <h2 id="minimum-python-version"><a class="header" href="#minimum-python-version">Minimum Python Version</a></h2>
  2055. <p>Synapse v1.1.0 has a minimum Python requirement of Python 3.5. Python
  2056. 3.6 or Python 3.7 are recommended as they have improved internal string
  2057. handling, significantly reducing memory usage.</p>
  2058. <p>If you use current versions of the Matrix.org-distributed Debian
  2059. packages or Docker images, action is not required.</p>
  2060. <p>If you install Synapse in a Python virtual environment, please see
  2061. &quot;Upgrading to v0.34.0&quot; for notes on setting up a new virtualenv under
  2062. Python 3.</p>
  2063. <h2 id="minimum-postgresql-version"><a class="header" href="#minimum-postgresql-version">Minimum PostgreSQL Version</a></h2>
  2064. <p>If using PostgreSQL under Synapse, you will need to use PostgreSQL 9.5
  2065. or above. Please see the <a href="https://www.postgresql.org/docs/11/upgrading.html">PostgreSQL
  2066. documentation</a> for
  2067. more details on upgrading your database.</p>
  2068. <h1 id="upgrading-to-v10"><a class="header" href="#upgrading-to-v10">Upgrading to v1.0</a></h1>
  2069. <h2 id="validation-of-tls-certificates"><a class="header" href="#validation-of-tls-certificates">Validation of TLS certificates</a></h2>
  2070. <p>Synapse v1.0 is the first release to enforce validation of TLS
  2071. certificates for the federation API. It is therefore essential that your
  2072. certificates are correctly configured. See the
  2073. <a href="../MSC1711_certificates_FAQ.html">FAQ</a> for more information.</p>
  2074. <p>Note, v1.0 installations will also no longer be able to federate with
  2075. servers that have not correctly configured their certificates.</p>
  2076. <p>In rare cases, it may be desirable to disable certificate checking: for
  2077. example, it might be essential to be able to federate with a given
  2078. legacy server in a closed federation. This can be done in one of two
  2079. ways:-</p>
  2080. <ul>
  2081. <li>Configure the global switch <code>federation_verify_certificates</code> to
  2082. <code>false</code>.</li>
  2083. <li>Configure a whitelist of server domains to trust via
  2084. <code>federation_certificate_verification_whitelist</code>.</li>
  2085. </ul>
  2086. <p>See the <a href="docs/sample_config.yaml">sample configuration file</a> for more
  2087. details on these settings.</p>
  2088. <h2 id="email-2"><a class="header" href="#email-2">Email</a></h2>
  2089. <p>When a user requests a password reset, Synapse will send an email to the
  2090. user to confirm the request.</p>
  2091. <p>Previous versions of Synapse delegated the job of sending this email to
  2092. an identity server. If the identity server was somehow malicious or
  2093. became compromised, it would be theoretically possible to hijack an
  2094. account through this means.</p>
  2095. <p>Therefore, by default, Synapse v1.0 will send the confirmation email
  2096. itself. If Synapse is not configured with an SMTP server, password reset
  2097. via email will be disabled.</p>
  2098. <p>To configure an SMTP server for Synapse, modify the configuration
  2099. section headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>,
  2100. <code>smtp_port</code> and <code>notif_from</code> fields filled out. You may also need to set
  2101. <code>smtp_user</code>, <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  2102. <p>If you are absolutely certain that you wish to continue using an
  2103. identity server for password resets, set
  2104. <code>trust_identity_server_for_password_resets</code> to <code>true</code>.</p>
  2105. <p>See the <a href="docs/sample_config.yaml">sample configuration file</a> for more
  2106. details on these settings.</p>
  2107. <h2 id="new-email-templates"><a class="header" href="#new-email-templates">New email templates</a></h2>
  2108. <p>Some new templates have been added to the default template directory for the purpose of
  2109. the homeserver sending its own password reset emails. If you have configured a
  2110. custom <code>template_dir</code> in your Synapse config, these files will need to be added.</p>
  2111. <p><code>password_reset.html</code> and <code>password_reset.txt</code> are HTML and plain text
  2112. templates respectively that contain the contents of what will be emailed
  2113. to the user upon attempting to reset their password via email.
  2114. <code>password_reset_success.html</code> and <code>password_reset_failure.html</code> are HTML
  2115. files that the content of which (assuming no redirect URL is set) will
  2116. be shown to the user after they attempt to click the link in the email
  2117. sent to them.</p>
  2118. <h1 id="upgrading-to-v0990"><a class="header" href="#upgrading-to-v0990">Upgrading to v0.99.0</a></h1>
  2119. <p>Please be aware that, before Synapse v1.0 is released around March 2019,
  2120. you will need to replace any self-signed certificates with those
  2121. verified by a root CA. Information on how to do so can be found at <a href="../ACME.html">the
  2122. ACME docs</a>.</p>
  2123. <p>For more information on configuring TLS certificates see the
  2124. <a href="../MSC1711_certificates_FAQ.html">FAQ</a>.</p>
  2125. <h1 id="upgrading-to-v0340"><a class="header" href="#upgrading-to-v0340">Upgrading to v0.34.0</a></h1>
  2126. <ol>
  2127. <li>
  2128. <p>This release is the first to fully support Python 3. Synapse will
  2129. now run on Python versions 3.5, or 3.6 (as well as 2.7). We
  2130. recommend switching to Python 3, as it has been shown to give
  2131. performance improvements.</p>
  2132. <p>For users who have installed Synapse into a virtualenv, we recommend
  2133. doing this by creating a new virtualenv. For example:</p>
  2134. <pre><code>virtualenv -p python3 ~/synapse/env3
  2135. source ~/synapse/env3/bin/activate
  2136. pip install matrix-synapse
  2137. </code></pre>
  2138. <p>You can then start synapse as normal, having activated the new
  2139. virtualenv:</p>
  2140. <pre><code>cd ~/synapse
  2141. source env3/bin/activate
  2142. synctl start
  2143. </code></pre>
  2144. <p>Users who have installed from distribution packages should see the
  2145. relevant package documentation. See below for notes on Debian
  2146. packages.</p>
  2147. <ul>
  2148. <li>
  2149. <p>When upgrading to Python 3, you <strong>must</strong> make sure that your log
  2150. files are configured as UTF-8, by adding <code>encoding: utf8</code> to the
  2151. <code>RotatingFileHandler</code> configuration (if you have one) in your
  2152. <code>&lt;server&gt;.log.config</code> file. For example, if your <code>log.config</code>
  2153. file contains:</p>
  2154. <pre><code>handlers:
  2155. file:
  2156. class: logging.handlers.RotatingFileHandler
  2157. formatter: precise
  2158. filename: homeserver.log
  2159. maxBytes: 104857600
  2160. backupCount: 10
  2161. filters: [context]
  2162. console:
  2163. class: logging.StreamHandler
  2164. formatter: precise
  2165. filters: [context]
  2166. </code></pre>
  2167. <p>Then you should update this to be:</p>
  2168. <pre><code>handlers:
  2169. file:
  2170. class: logging.handlers.RotatingFileHandler
  2171. formatter: precise
  2172. filename: homeserver.log
  2173. maxBytes: 104857600
  2174. backupCount: 10
  2175. filters: [context]
  2176. encoding: utf8
  2177. console:
  2178. class: logging.StreamHandler
  2179. formatter: precise
  2180. filters: [context]
  2181. </code></pre>
  2182. <p>There is no need to revert this change if downgrading to
  2183. Python 2.</p>
  2184. </li>
  2185. </ul>
  2186. <p>We are also making available Debian packages which will run Synapse
  2187. on Python 3. You can switch to these packages with
  2188. <code>apt-get install matrix-synapse-py3</code>, however, please read
  2189. <a href="https://github.com/matrix-org/synapse/blob/release-v0.34.0/debian/NEWS">debian/NEWS</a>
  2190. before doing so. The existing <code>matrix-synapse</code> packages will
  2191. continue to use Python 2 for the time being.</p>
  2192. </li>
  2193. <li>
  2194. <p>This release removes the <code>riot.im</code> from the default list of trusted
  2195. identity servers.</p>
  2196. <p>If <code>riot.im</code> is in your homeserver's list of
  2197. <code>trusted_third_party_id_servers</code>, you should remove it. It was added
  2198. in case a hypothetical future identity server was put there. If you
  2199. don't remove it, users may be unable to deactivate their accounts.</p>
  2200. </li>
  2201. <li>
  2202. <p>This release no longer installs the (unmaintained) Matrix Console
  2203. web client as part of the default installation. It is possible to
  2204. re-enable it by installing it separately and setting the
  2205. <code>web_client_location</code> config option, but please consider switching
  2206. to another client.</p>
  2207. </li>
  2208. </ol>
  2209. <h1 id="upgrading-to-v0337"><a class="header" href="#upgrading-to-v0337">Upgrading to v0.33.7</a></h1>
  2210. <p>This release removes the example email notification templates from
  2211. <code>res/templates</code> (they are now internal to the python package). This
  2212. should only affect you if you (a) deploy your Synapse instance from a
  2213. git checkout or a github snapshot URL, and (b) have email notifications
  2214. enabled.</p>
  2215. <p>If you have email notifications enabled, you should ensure that
  2216. <code>email.template_dir</code> is either configured to point at a directory where
  2217. you have installed customised templates, or leave it unset to use the
  2218. default templates.</p>
  2219. <h1 id="upgrading-to-v0273"><a class="header" href="#upgrading-to-v0273">Upgrading to v0.27.3</a></h1>
  2220. <p>This release expands the anonymous usage stats sent if the opt-in
  2221. <code>report_stats</code> configuration is set to <code>true</code>. We now capture RSS memory
  2222. and cpu use at a very coarse level. This requires administrators to
  2223. install the optional <code>psutil</code> python module.</p>
  2224. <p>We would appreciate it if you could assist by ensuring this module is
  2225. available and <code>report_stats</code> is enabled. This will let us see if
  2226. performance changes to synapse are having an impact to the general
  2227. community.</p>
  2228. <h1 id="upgrading-to-v0150"><a class="header" href="#upgrading-to-v0150">Upgrading to v0.15.0</a></h1>
  2229. <p>If you want to use the new URL previewing API
  2230. (<code>/_matrix/media/r0/preview_url</code>) then you have to explicitly enable it
  2231. in the config and update your dependencies dependencies. See README.rst
  2232. for details.</p>
  2233. <h1 id="upgrading-to-v0110"><a class="header" href="#upgrading-to-v0110">Upgrading to v0.11.0</a></h1>
  2234. <p>This release includes the option to send anonymous usage stats to
  2235. matrix.org, and requires that administrators explictly opt in or out by
  2236. setting the <code>report_stats</code> option to either <code>true</code> or <code>false</code>.</p>
  2237. <p>We would really appreciate it if you could help our project out by
  2238. reporting anonymized usage statistics from your homeserver. Only very
  2239. basic aggregate data (e.g. number of users) will be reported, but it
  2240. helps us to track the growth of the Matrix community, and helps us to
  2241. make Matrix a success, as well as to convince other networks that they
  2242. should peer with us.</p>
  2243. <h1 id="upgrading-to-v090"><a class="header" href="#upgrading-to-v090">Upgrading to v0.9.0</a></h1>
  2244. <p>Application services have had a breaking API change in this version.</p>
  2245. <p>They can no longer register themselves with a home server using the AS
  2246. HTTP API. This decision was made because a compromised application
  2247. service with free reign to register any regex in effect grants full
  2248. read/write access to the home server if a regex of <code>.*</code> is used. An
  2249. attack where a compromised AS re-registers itself with <code>.*</code> was deemed
  2250. too big of a security risk to ignore, and so the ability to register
  2251. with the HS remotely has been removed.</p>
  2252. <p>It has been replaced by specifying a list of application service
  2253. registrations in <code>homeserver.yaml</code>:</p>
  2254. <pre><code>app_service_config_files: [&quot;registration-01.yaml&quot;, &quot;registration-02.yaml&quot;]
  2255. </code></pre>
  2256. <p>Where <code>registration-01.yaml</code> looks like:</p>
  2257. <pre><code>url: &lt;String&gt; # e.g. &quot;https://my.application.service.com&quot;
  2258. as_token: &lt;String&gt;
  2259. hs_token: &lt;String&gt;
  2260. sender_localpart: &lt;String&gt; # This is a new field which denotes the user_id localpart when using the AS token
  2261. namespaces:
  2262. users:
  2263. - exclusive: &lt;Boolean&gt;
  2264. regex: &lt;String&gt; # e.g. &quot;@prefix_.*&quot;
  2265. aliases:
  2266. - exclusive: &lt;Boolean&gt;
  2267. regex: &lt;String&gt;
  2268. rooms:
  2269. - exclusive: &lt;Boolean&gt;
  2270. regex: &lt;String&gt;
  2271. </code></pre>
  2272. <h1 id="upgrading-to-v080"><a class="header" href="#upgrading-to-v080">Upgrading to v0.8.0</a></h1>
  2273. <p>Servers which use captchas will need to add their public key to:</p>
  2274. <pre><code>static/client/register/register_config.js
  2275. window.matrixRegistrationConfig = {
  2276. recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  2277. };
  2278. </code></pre>
  2279. <p>This is required in order to support registration fallback (typically
  2280. used on mobile devices).</p>
  2281. <h1 id="upgrading-to-v070"><a class="header" href="#upgrading-to-v070">Upgrading to v0.7.0</a></h1>
  2282. <p>New dependencies are:</p>
  2283. <ul>
  2284. <li>pydenticon</li>
  2285. <li>simplejson</li>
  2286. <li>syutil</li>
  2287. <li>matrix-angular-sdk</li>
  2288. </ul>
  2289. <p>To pull in these dependencies in a virtual env, run:</p>
  2290. <pre><code>python synapse/python_dependencies.py | xargs -n 1 pip install
  2291. </code></pre>
  2292. <h1 id="upgrading-to-v060"><a class="header" href="#upgrading-to-v060">Upgrading to v0.6.0</a></h1>
  2293. <p>To pull in new dependencies, run:</p>
  2294. <pre><code>python setup.py develop --user
  2295. </code></pre>
  2296. <p>This update includes a change to the database schema. To upgrade you
  2297. first need to upgrade the database by running:</p>
  2298. <pre><code>python scripts/upgrade_db_to_v0.6.0.py &lt;db&gt; &lt;server_name&gt; &lt;signing_key&gt;
  2299. </code></pre>
  2300. <p>Where [<db>]{.title-ref} is the location of the database,
  2301. [&lt;server_name&gt;]{.title-ref} is the server name as specified in the
  2302. synapse configuration, and [&lt;signing_key&gt;]{.title-ref} is the location
  2303. of the signing key as specified in the synapse configuration.</p>
  2304. <p>This may take some time to complete. Failures of signatures and content
  2305. hashes can safely be ignored.</p>
  2306. <h1 id="upgrading-to-v051"><a class="header" href="#upgrading-to-v051">Upgrading to v0.5.1</a></h1>
  2307. <p>Depending on precisely when you installed v0.5.0 you may have ended up
  2308. with a stale release of the reference matrix webclient installed as a
  2309. python module. To uninstall it and ensure you are depending on the
  2310. latest module, please run:</p>
  2311. <pre><code>$ pip uninstall syweb
  2312. </code></pre>
  2313. <h1 id="upgrading-to-v050"><a class="header" href="#upgrading-to-v050">Upgrading to v0.5.0</a></h1>
  2314. <p>The webclient has been split out into a seperate repository/pacakage in
  2315. this release. Before you restart your homeserver you will need to pull
  2316. in the webclient package by running:</p>
  2317. <pre><code>python setup.py develop --user
  2318. </code></pre>
  2319. <p>This release completely changes the database schema and so requires
  2320. upgrading it before starting the new version of the homeserver.</p>
  2321. <p>The script &quot;database-prepare-for-0.5.0.sh&quot; should be used to upgrade
  2322. the database. This will save all user information, such as logins and
  2323. profiles, but will otherwise purge the database. This includes messages,
  2324. which rooms the home server was a member of and room alias mappings.</p>
  2325. <p>If you would like to keep your history, please take a copy of your
  2326. database file and ask for help in #matrix:matrix.org. The upgrade
  2327. process is, unfortunately, non trivial and requires human intervention
  2328. to resolve any resulting conflicts during the upgrade process.</p>
  2329. <p>Before running the command the homeserver should be first completely
  2330. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2331. <blockquote>
  2332. <p>./scripts/database-prepare-for-0.5.0.sh &quot;homeserver.db&quot;</p>
  2333. </blockquote>
  2334. <p>Once this has successfully completed it will be safe to restart the
  2335. homeserver. You may notice that the homeserver takes a few seconds
  2336. longer to restart than usual as it reinitializes the database.</p>
  2337. <p>On startup of the new version, users can either rejoin remote rooms
  2338. using room aliases or by being reinvited. Alternatively, if any other
  2339. homeserver sends a message to a room that the homeserver was previously
  2340. in the local HS will automatically rejoin the room.</p>
  2341. <h1 id="upgrading-to-v040"><a class="header" href="#upgrading-to-v040">Upgrading to v0.4.0</a></h1>
  2342. <p>This release needs an updated syutil version. Run:</p>
  2343. <pre><code>python setup.py develop
  2344. </code></pre>
  2345. <p>You will also need to upgrade your configuration as the signing key
  2346. format has changed. Run:</p>
  2347. <pre><code>python -m synapse.app.homeserver --config-path &lt;CONFIG&gt; --generate-config
  2348. </code></pre>
  2349. <h1 id="upgrading-to-v030"><a class="header" href="#upgrading-to-v030">Upgrading to v0.3.0</a></h1>
  2350. <p>This registration API now closely matches the login API. This introduces
  2351. a bit more backwards and forwards between the HS and the client, but
  2352. this improves the overall flexibility of the API. You can now GET on
  2353. /register to retrieve a list of valid registration flows. Upon choosing
  2354. one, they are submitted in the same way as login, e.g:</p>
  2355. <pre><code>{
  2356. type: m.login.password,
  2357. user: foo,
  2358. password: bar
  2359. }
  2360. </code></pre>
  2361. <p>The default HS supports 2 flows, with and without Identity Server email
  2362. authentication. Enabling captcha on the HS will add in an extra step to
  2363. all flows: <code>m.login.recaptcha</code> which must be completed before you can
  2364. transition to the next stage. There is a new login type:
  2365. <code>m.login.email.identity</code> which contains the <code>threepidCreds</code> key which
  2366. were previously sent in the original register request. For more
  2367. information on this, see the specification.</p>
  2368. <h2 id="web-client"><a class="header" href="#web-client">Web Client</a></h2>
  2369. <p>The VoIP specification has changed between v0.2.0 and v0.3.0. Users
  2370. should refresh any browser tabs to get the latest web client code. Users
  2371. on v0.2.0 of the web client will not be able to call those on v0.3.0 and
  2372. vice versa.</p>
  2373. <h1 id="upgrading-to-v020"><a class="header" href="#upgrading-to-v020">Upgrading to v0.2.0</a></h1>
  2374. <p>The home server now requires setting up of SSL config before it can run.
  2375. To automatically generate default config use:</p>
  2376. <pre><code>$ python synapse/app/homeserver.py \
  2377. --server-name machine.my.domain.name \
  2378. --bind-port 8448 \
  2379. --config-path homeserver.config \
  2380. --generate-config
  2381. </code></pre>
  2382. <p>This config can be edited if desired, for example to specify a different
  2383. SSL certificate to use. Once done you can run the home server using:</p>
  2384. <pre><code>$ python synapse/app/homeserver.py --config-path homeserver.config
  2385. </code></pre>
  2386. <p>See the README.rst for more information.</p>
  2387. <p>Also note that some config options have been renamed, including:</p>
  2388. <ul>
  2389. <li>&quot;host&quot; to &quot;server-name&quot;</li>
  2390. <li>&quot;database&quot; to &quot;database-path&quot;</li>
  2391. <li>&quot;port&quot; to &quot;bind-port&quot; and &quot;unsecure-port&quot;</li>
  2392. </ul>
  2393. <h1 id="upgrading-to-v001"><a class="header" href="#upgrading-to-v001">Upgrading to v0.0.1</a></h1>
  2394. <p>This release completely changes the database schema and so requires
  2395. upgrading it before starting the new version of the homeserver.</p>
  2396. <p>The script &quot;database-prepare-for-0.0.1.sh&quot; should be used to upgrade
  2397. the database. This will save all user information, such as logins and
  2398. profiles, but will otherwise purge the database. This includes messages,
  2399. which rooms the home server was a member of and room alias mappings.</p>
  2400. <p>Before running the command the homeserver should be first completely
  2401. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2402. <blockquote>
  2403. <p>./scripts/database-prepare-for-0.0.1.sh &quot;homeserver.db&quot;</p>
  2404. </blockquote>
  2405. <p>Once this has successfully completed it will be safe to restart the
  2406. homeserver. You may notice that the homeserver takes a few seconds
  2407. longer to restart than usual as it reinitializes the database.</p>
  2408. <p>On startup of the new version, users can either rejoin remote rooms
  2409. using room aliases or by being reinvited. Alternatively, if any other
  2410. homeserver sends a message to a room that the homeserver was previously
  2411. in the local HS will automatically rejoin the room.</p>
  2412. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="msc1711-certificates-faq"><a class="header" href="#msc1711-certificates-faq">MSC1711 Certificates FAQ</a></h1>
  2413. <h2 id="historical-note"><a class="header" href="#historical-note">Historical Note</a></h2>
  2414. <p>This document was originally written to guide server admins through the upgrade
  2415. path towards Synapse 1.0. Specifically,
  2416. <a href="https://github.com/matrix-org/matrix-doc/blob/master/proposals/1711-x509-for-federation.md">MSC1711</a>
  2417. required that all servers present valid TLS certificates on their federation
  2418. API. Admins were encouraged to achieve compliance from version 0.99.0 (released
  2419. in February 2019) ahead of version 1.0 (released June 2019) enforcing the
  2420. certificate checks.</p>
  2421. <p>Much of what follows is now outdated since most admins will have already
  2422. upgraded, however it may be of use to those with old installs returning to the
  2423. project.</p>
  2424. <p>If you are setting up a server from scratch you almost certainly should look at
  2425. the <a href="setup/installation.html">installation guide</a> instead.</p>
  2426. <h2 id="introduction-1"><a class="header" href="#introduction-1">Introduction</a></h2>
  2427. <p>The goal of Synapse 0.99.0 is to act as a stepping stone to Synapse 1.0.0. It
  2428. supports the r0.1 release of the server to server specification, but is
  2429. compatible with both the legacy Matrix federation behaviour (pre-r0.1) as well
  2430. as post-r0.1 behaviour, in order to allow for a smooth upgrade across the
  2431. federation.</p>
  2432. <p>The most important thing to know is that Synapse 1.0.0 will require a valid TLS
  2433. certificate on federation endpoints. Self signed certificates will not be
  2434. sufficient.</p>
  2435. <p>Synapse 0.99.0 makes it easy to configure TLS certificates and will
  2436. interoperate with both &gt;= 1.0.0 servers as well as existing servers yet to
  2437. upgrade.</p>
  2438. <p><strong>It is critical that all admins upgrade to 0.99.0 and configure a valid TLS
  2439. certificate.</strong> Admins will have 1 month to do so, after which 1.0.0 will be
  2440. released and those servers without a valid certificate will not longer be able
  2441. to federate with &gt;= 1.0.0 servers.</p>
  2442. <p>Full details on how to carry out this configuration change is given
  2443. <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">below</a>. A
  2444. timeline and some frequently asked questions are also given below.</p>
  2445. <p>For more details and context on the release of the r0.1 Server/Server API and
  2446. imminent Matrix 1.0 release, you can also see our
  2447. <a href="https://matrix.org/blog/2019/02/04/matrix-at-fosdem-2019/">main talk from FOSDEM 2019</a>.</p>
  2448. <h2 id="contents"><a class="header" href="#contents">Contents</a></h2>
  2449. <ul>
  2450. <li>Timeline</li>
  2451. <li>Configuring certificates for compatibility with Synapse 1.0</li>
  2452. <li>FAQ
  2453. <ul>
  2454. <li>Synapse 0.99.0 has just been released, what do I need to do right now?</li>
  2455. <li>How do I upgrade?</li>
  2456. <li>What will happen if I do not set up a valid federation certificate
  2457. immediately?</li>
  2458. <li>What will happen if I do nothing at all?</li>
  2459. <li>When do I need a SRV record or .well-known URI?</li>
  2460. <li>Can I still use an SRV record?</li>
  2461. <li>I have created a .well-known URI. Do I still need an SRV record?</li>
  2462. <li>It used to work just fine, why are you breaking everything?</li>
  2463. <li>Can I manage my own certificates rather than having Synapse renew
  2464. certificates itself?</li>
  2465. <li>Do you still recommend against using a reverse proxy on the federation port?</li>
  2466. <li>Do I still need to give my TLS certificates to Synapse if I am using a
  2467. reverse proxy?</li>
  2468. <li>Do I need the same certificate for the client and federation port?</li>
  2469. <li>How do I tell Synapse to reload my keys/certificates after I replace them?</li>
  2470. </ul>
  2471. </li>
  2472. </ul>
  2473. <h2 id="timeline"><a class="header" href="#timeline">Timeline</a></h2>
  2474. <p><strong>5th Feb 2019 - Synapse 0.99.0 is released.</strong></p>
  2475. <p>All server admins are encouraged to upgrade.</p>
  2476. <p>0.99.0:</p>
  2477. <ul>
  2478. <li>
  2479. <p>provides support for ACME to make setting up Let's Encrypt certs easy, as
  2480. well as .well-known support.</p>
  2481. </li>
  2482. <li>
  2483. <p>does not enforce that a valid CA cert is present on the federation API, but
  2484. rather makes it easy to set one up.</p>
  2485. </li>
  2486. <li>
  2487. <p>provides support for .well-known</p>
  2488. </li>
  2489. </ul>
  2490. <p>Admins should upgrade and configure a valid CA cert. Homeservers that require a
  2491. .well-known entry (see below), should retain their SRV record and use it
  2492. alongside their .well-known record.</p>
  2493. <p><strong>10th June 2019 - Synapse 1.0.0 is released</strong></p>
  2494. <p>1.0.0 is scheduled for release on 10th June. In
  2495. accordance with the the <a href="https://matrix.org/docs/spec/server_server/r0.1.0.html">S2S spec</a>
  2496. 1.0.0 will enforce certificate validity. This means that any homeserver without a
  2497. valid certificate after this point will no longer be able to federate with
  2498. 1.0.0 servers.</p>
  2499. <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>
  2500. <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>
  2501. <p>In this case, your <code>server_name</code> points to the host where your Synapse is
  2502. running. There is no need to create a <code>.well-known</code> URI or an SRV record, but
  2503. you will need to give Synapse a valid, signed, certificate.</p>
  2504. <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>
  2505. <p>If you are using an SRV record, your matrix domain (<code>server_name</code>) may not
  2506. point to the same host that your Synapse is running on (the 'target
  2507. domain'). (If it does, you can follow the recommendation above; otherwise, read
  2508. on.)</p>
  2509. <p>Let's assume that your <code>server_name</code> is <code>example.com</code>, and your Synapse is
  2510. hosted at a target domain of <code>customer.example.net</code>. Currently you should have
  2511. an SRV record which looks like:</p>
  2512. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 8000 customer.example.net.
  2513. </code></pre>
  2514. <p>In this situation, you have three choices for how to proceed:</p>
  2515. <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>
  2516. <p>Synapse 1.0 will expect your server to present a TLS certificate for your
  2517. <code>server_name</code> (<code>example.com</code> in the above example). You can achieve this by acquiring a
  2518. certificate for the <code>server_name</code> yourself (for example, using <code>certbot</code>), and giving it
  2519. and the key to Synapse via <code>tls_certificate_path</code> and <code>tls_private_key_path</code>.</p>
  2520. <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>
  2521. <p>If you have an existing reverse proxy set up with correct TLS certificates for
  2522. your domain, you can simply route all traffic through the reverse proxy by
  2523. updating the SRV record appropriately (or removing it, if the proxy listens on
  2524. 8448).</p>
  2525. <p>See <a href="reverse_proxy.html">reverse_proxy.md</a> for information on setting up a
  2526. reverse proxy.</p>
  2527. <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>
  2528. <p>This will allow you to keep Synapse on a separate domain, without having to
  2529. give it a certificate for the matrix domain.</p>
  2530. <p>You can do this with a <code>.well-known</code> file as follows:</p>
  2531. <ol>
  2532. <li>
  2533. <p>Keep the SRV record in place - it is needed for backwards compatibility
  2534. with Synapse 0.34 and earlier.</p>
  2535. </li>
  2536. <li>
  2537. <p>Give Synapse a certificate corresponding to the target domain
  2538. (<code>customer.example.net</code> in the above example). You can do this by acquire a
  2539. certificate for the target domain and giving it to Synapse via <code>tls_certificate_path</code>
  2540. and <code>tls_private_key_path</code>.</p>
  2541. </li>
  2542. <li>
  2543. <p>Restart Synapse to ensure the new certificate is loaded.</p>
  2544. </li>
  2545. <li>
  2546. <p>Arrange for a <code>.well-known</code> file at
  2547. <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> with contents:</p>
  2548. <pre><code class="language-json">{&quot;m.server&quot;: &quot;&lt;target server name&gt;&quot;}
  2549. </code></pre>
  2550. <p>where the target server name is resolved as usual (i.e. SRV lookup, falling
  2551. back to talking to port 8448).</p>
  2552. <p>In the above example, where synapse is listening on port 8000,
  2553. <code>https://example.com/.well-known/matrix/server</code> should have <code>m.server</code> set to one of:</p>
  2554. <ol>
  2555. <li>
  2556. <p><code>customer.example.net</code> ─ with a SRV record on
  2557. <code>_matrix._tcp.customer.example.com</code> pointing to port 8000, or:</p>
  2558. </li>
  2559. <li>
  2560. <p><code>customer.example.net</code> ─ updating synapse to listen on the default port
  2561. 8448, or:</p>
  2562. </li>
  2563. <li>
  2564. <p><code>customer.example.net:8000</code> ─ ensuring that if there is a reverse proxy
  2565. on <code>customer.example.net:8000</code> it correctly handles HTTP requests with
  2566. Host header set to <code>customer.example.net:8000</code>.</p>
  2567. </li>
  2568. </ol>
  2569. </li>
  2570. </ol>
  2571. <h2 id="faq"><a class="header" href="#faq">FAQ</a></h2>
  2572. <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>
  2573. <p>Upgrade as soon as you can in preparation for Synapse 1.0.0, and update your
  2574. TLS certificates as <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">above</a>.</p>
  2575. <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>
  2576. <p>Nothing initially, but once 1.0.0 is in the wild it will not be possible to
  2577. federate with 1.0.0 servers.</p>
  2578. <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>
  2579. <p>If the admin takes no action at all, and remains on a Synapse &lt; 0.99.0 then the
  2580. homeserver will be unable to federate with those who have implemented
  2581. .well-known. Then, as above, once the month upgrade window has expired the
  2582. homeserver will not be able to federate with any Synapse &gt;= 1.0.0</p>
  2583. <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>
  2584. <p>If your homeserver listens on the default federation port (8448), and your
  2585. <code>server_name</code> points to the host that your homeserver runs on, you do not need an
  2586. SRV record or <code>.well-known/matrix/server</code> URI.</p>
  2587. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  2588. fresh Upcloud VPS or similar, you could install Synapse 0.99 on that host,
  2589. giving it a server_name of <code>example.com</code>, and it would automatically generate a
  2590. valid TLS certificate for you via Let's Encrypt and no SRV record or
  2591. <code>.well-known</code> URI would be needed.</p>
  2592. <p>This is the common case, although you can add an SRV record or
  2593. <code>.well-known/matrix/server</code> URI for completeness if you wish.</p>
  2594. <p><strong>However</strong>, if your server does not listen on port 8448, or if your <code>server_name</code>
  2595. does not point to the host that your homeserver runs on, you will need to let
  2596. other servers know how to find it.</p>
  2597. <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
  2598. currently&quot;</a> above.</p>
  2599. <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>
  2600. <p>Firstly, if you didn't need an SRV record before (because your server is
  2601. listening on port 8448 of your server_name), you certainly don't need one now:
  2602. the defaults are still the same.</p>
  2603. <p>If you previously had an SRV record, you can keep using it provided you are
  2604. able to give Synapse a TLS certificate corresponding to your server name. For
  2605. example, suppose you had the following SRV record, which directs matrix traffic
  2606. for example.com to matrix.example.com:443:</p>
  2607. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 443 matrix.example.com
  2608. </code></pre>
  2609. <p>In this case, Synapse must be given a certificate for example.com - or be
  2610. configured to acquire one from Let's Encrypt.</p>
  2611. <p>If you are unable to give Synapse a certificate for your server_name, you will
  2612. also need to use a .well-known URI instead. However, see also &quot;I have created a
  2613. .well-known URI. Do I still need an SRV record?&quot;.</p>
  2614. <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>
  2615. <p>As of Synapse 0.99, Synapse will first check for the existence of a <code>.well-known</code>
  2616. URI and follow any delegation it suggests. It will only then check for the
  2617. existence of an SRV record.</p>
  2618. <p>That means that the SRV record will often be redundant. However, you should
  2619. remember that there may still be older versions of Synapse in the federation
  2620. which do not understand <code>.well-known</code> URIs, so if you removed your SRV record you
  2621. would no longer be able to federate with them.</p>
  2622. <p>It is therefore best to leave the SRV record in place for now. Synapse 0.34 and
  2623. earlier will follow the SRV record (and not care about the invalid
  2624. certificate). Synapse 0.99 and later will follow the .well-known URI, with the
  2625. correct certificate chain.</p>
  2626. <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>
  2627. <p>We have always wanted Matrix servers to be as easy to set up as possible, and
  2628. so back when we started federation in 2014 we didn't want admins to have to go
  2629. through the cumbersome process of buying a valid TLS certificate to run a
  2630. server. This was before Let's Encrypt came along and made getting a free and
  2631. valid TLS certificate straightforward. So instead, we adopted a system based on
  2632. <a href="https://en.wikipedia.org/wiki/Convergence_(SSL)">Perspectives</a>: an approach
  2633. where you check a set of &quot;notary servers&quot; (in practice, homeservers) to vouch
  2634. for the validity of a certificate rather than having it signed by a CA. As long
  2635. as enough different notaries agree on the certificate's validity, then it is
  2636. trusted.</p>
  2637. <p>However, in practice this has never worked properly. Most people only use the
  2638. default notary server (matrix.org), leading to inadvertent centralisation which
  2639. we want to eliminate. Meanwhile, we never implemented the full consensus
  2640. algorithm to query the servers participating in a room to determine consensus
  2641. on whether a given certificate is valid. This is fiddly to get right
  2642. (especially in face of sybil attacks), and we found ourselves questioning
  2643. whether it was worth the effort to finish the work and commit to maintaining a
  2644. secure certificate validation system as opposed to focusing on core Matrix
  2645. development.</p>
  2646. <p>Meanwhile, Let's Encrypt came along in 2016, and put the final nail in the
  2647. coffin of the Perspectives project (which was already pretty dead). So, the
  2648. Spec Core Team decided that a better approach would be to mandate valid TLS
  2649. certificates for federation alongside the rest of the Web. More details can be
  2650. found in
  2651. <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>
  2652. <p>This results in a breaking change, which is disruptive, but absolutely critical
  2653. for the security model. However, the existence of Let's Encrypt as a trivial
  2654. way to replace the old self-signed certificates with valid CA-signed ones helps
  2655. smooth things over massively, especially as Synapse can now automate Let's
  2656. Encrypt certificate generation if needed.</p>
  2657. <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>
  2658. <p>Yes, you are welcome to manage your certificates yourself. Synapse will only
  2659. attempt to obtain certificates from Let's Encrypt if you configure it to do
  2660. so.The only requirement is that there is a valid TLS cert present for
  2661. federation end points.</p>
  2662. <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>
  2663. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  2664. find it easier to direct federation traffic to a reverse proxy and manage their
  2665. own TLS certificates, and this is a supported configuration.</p>
  2666. <p>See <a href="reverse_proxy.html">reverse_proxy.md</a> for information on setting up a
  2667. reverse proxy.</p>
  2668. <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>
  2669. <p>Practically speaking, this is no longer necessary.</p>
  2670. <p>If you are using a reverse proxy for all of your TLS traffic, then you can set
  2671. <code>no_tls: True</code>. In that case, the only reason Synapse needs the certificate is
  2672. to populate a legacy 'tls_fingerprints' field in the federation API. This is
  2673. ignored by Synapse 0.99.0 and later, and the only time pre-0.99 Synapses will
  2674. check it is when attempting to fetch the server keys - and generally this is
  2675. delegated via <code>matrix.org</code>, which is on 0.99.0.</p>
  2676. <p>However, there is a bug in Synapse 0.99.0
  2677. <a href="https://github.com/matrix-org/synapse/issues/4554">4554</a> which prevents
  2678. Synapse from starting if you do not give it a TLS certificate. To work around
  2679. this, you can give it any TLS certificate at all. This will be fixed soon.</p>
  2680. <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>
  2681. <p>No. There is nothing stopping you from using different certificates,
  2682. particularly if you are using a reverse proxy. However, Synapse will use the
  2683. same certificate on any ports where TLS is configured.</p>
  2684. <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>
  2685. <p>Synapse will reload the keys and certificates when it receives a SIGHUP - for
  2686. example <code>kill -HUP $(cat homeserver.pid)</code>. Alternatively, simply restart
  2687. Synapse, though this will result in downtime while it restarts.</p>
  2688. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="setting-up-federation"><a class="header" href="#setting-up-federation">Setting up federation</a></h1>
  2689. <p>Federation is the process by which users on different servers can participate
  2690. in the same room. For this to work, those other servers must be able to contact
  2691. yours to send messages.</p>
  2692. <p>The <code>server_name</code> configured in the Synapse configuration file (often
  2693. <code>homeserver.yaml</code>) defines how resources (users, rooms, etc.) will be
  2694. identified (eg: <code>@user:example.com</code>, <code>#room:example.com</code>). By default,
  2695. it is also the domain that other servers will use to try to reach your
  2696. server (via port 8448). This is easy to set up and will work provided
  2697. you set the <code>server_name</code> to match your machine's public DNS hostname.</p>
  2698. <p>For this default configuration to work, you will need to listen for TLS
  2699. connections on port 8448. The preferred way to do that is by using a
  2700. reverse proxy: see <a href="reverse_proxy.html">reverse_proxy.md</a> for instructions
  2701. on how to correctly set one up.</p>
  2702. <p>In some cases you might not want to run Synapse on the machine that has
  2703. the <code>server_name</code> as its public DNS hostname, or you might want federation
  2704. traffic to use a different port than 8448. For example, you might want to
  2705. have your user names look like <code>@user:example.com</code>, but you want to run
  2706. Synapse on <code>synapse.example.com</code> on port 443. This can be done using
  2707. delegation, which allows an admin to control where federation traffic should
  2708. be sent. See <a href="delegate.html">delegate.md</a> for instructions on how to set this up.</p>
  2709. <p>Once federation has been configured, you should be able to join a room over
  2710. federation. A good place to start is <code>#synapse:matrix.org</code> - a room for
  2711. Synapse admins.</p>
  2712. <h2 id="troubleshooting-2"><a class="header" href="#troubleshooting-2">Troubleshooting</a></h2>
  2713. <p>You can use the <a href="https://matrix.org/federationtester">federation tester</a>
  2714. to check if your homeserver is configured correctly. Alternatively try the
  2715. <a href="https://matrix.org/federationtester/api/report?server_name=DOMAIN">JSON API used by the federation tester</a>.
  2716. Note that you'll have to modify this URL to replace <code>DOMAIN</code> with your
  2717. <code>server_name</code>. Hitting the API directly provides extra detail.</p>
  2718. <p>The typical failure mode for federation is that when the server tries to join
  2719. a room, it is rejected with &quot;401: Unauthorized&quot;. Generally this means that other
  2720. servers in the room could not access yours. (Joining a room over federation is
  2721. a complicated dance which requires connections in both directions).</p>
  2722. <p>Another common problem is that people on other servers can't join rooms that
  2723. you invite them to. This can be caused by an incorrectly-configured reverse
  2724. proxy: see <a href="reverse_proxy.html">reverse_proxy.md</a> for instructions on how to correctly
  2725. configure a reverse proxy.</p>
  2726. <h3 id="known-issues"><a class="header" href="#known-issues">Known issues</a></h3>
  2727. <p><strong>HTTP <code>308 Permanent Redirect</code> redirects are not followed</strong>: Due to missing features
  2728. in the HTTP library used by Synapse, 308 redirects are currently not followed by
  2729. federating servers, which can cause <code>M_UNKNOWN</code> or <code>401 Unauthorized</code> errors. This
  2730. may affect users who are redirecting apex-to-www (e.g. <code>example.com</code> -&gt; <code>www.example.com</code>),
  2731. and especially users of the Kubernetes <em>Nginx Ingress</em> module, which uses 308 redirect
  2732. codes by default. For those Kubernetes users, <a href="https://stackoverflow.com/a/52617528/5096871">this Stackoverflow post</a>
  2733. might be helpful. For other users, switching to a <code>301 Moved Permanently</code> code may be
  2734. an option. 308 redirect codes will be supported properly in a future
  2735. release of Synapse.</p>
  2736. <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>
  2737. <p>If you want to get up and running quickly with a trio of homeservers in a
  2738. private federation, there is a script in the <code>demo</code> directory. This is mainly
  2739. useful just for development purposes. See <a href="https://github.com/matrix-org/synapse/tree/develop/demo/">demo/README</a>.</p>
  2740. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="configuration-1"><a class="header" href="#configuration-1">Configuration</a></h1>
  2741. <p>This section contains information on tweaking Synapse via the various options in the configuration file. A configuration
  2742. file should have been generated when you <a href="usage/configuration/../../setup/installation.html">installed Synapse</a>.</p>
  2743. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="homeserver-sample-configuration-file"><a class="header" href="#homeserver-sample-configuration-file">Homeserver Sample Configuration File</a></h1>
  2744. <p>Below is a sample homeserver configuration file. The homeserver configuration file
  2745. can be tweaked to change the behaviour of your homeserver. A restart of the server is
  2746. generally required to apply any changes made to this file.</p>
  2747. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  2748. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  2749. a fresh config using Synapse by following the instructions in
  2750. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  2751. <pre><code class="language-yaml"># This file is maintained as an up-to-date snapshot of the default
  2752. # homeserver.yaml configuration generated by Synapse.
  2753. #
  2754. # It is intended to act as a reference for the default configuration,
  2755. # helping admins keep track of new options and other changes, and compare
  2756. # their configs with the current default. As such, many of the actual
  2757. # config values shown are placeholders.
  2758. #
  2759. # It is *not* intended to be copied and used as the basis for a real
  2760. # homeserver.yaml. Instead, if you are starting from scratch, please generate
  2761. # a fresh config using Synapse by following the instructions in
  2762. # https://matrix-org.github.io/synapse/latest/setup/installation.html.
  2763. # Configuration options that take a time period can be set using a number
  2764. # followed by a letter. Letters have the following meanings:
  2765. # s = second
  2766. # m = minute
  2767. # h = hour
  2768. # d = day
  2769. # w = week
  2770. # y = year
  2771. # For example, setting redaction_retention_period: 5m would remove redacted
  2772. # messages from the database after 5 minutes, rather than 5 months.
  2773. ################################################################################
  2774. # Configuration file for Synapse.
  2775. #
  2776. # This is a YAML file: see [1] for a quick introduction. Note in particular
  2777. # that *indentation is important*: all the elements of a list or dictionary
  2778. # should have the same indentation.
  2779. #
  2780. # [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  2781. ## Modules ##
  2782. # Server admins can expand Synapse's functionality with external modules.
  2783. #
  2784. # See https://matrix-org.github.io/synapse/latest/modules.html for more
  2785. # documentation on how to configure or create custom modules for Synapse.
  2786. #
  2787. modules:
  2788. # - module: my_super_module.MySuperClass
  2789. # config:
  2790. # do_thing: true
  2791. # - module: my_other_super_module.SomeClass
  2792. # config: {}
  2793. ## Server ##
  2794. # The public-facing domain of the server
  2795. #
  2796. # The server_name name will appear at the end of usernames and room addresses
  2797. # created on this server. For example if the server_name was example.com,
  2798. # usernames on this server would be in the format @user:example.com
  2799. #
  2800. # In most cases you should avoid using a matrix specific subdomain such as
  2801. # matrix.example.com or synapse.example.com as the server_name for the same
  2802. # reasons you wouldn't use user@email.example.com as your email address.
  2803. # See https://matrix-org.github.io/synapse/latest/delegate.html
  2804. # for information on how to host Synapse on a subdomain while preserving
  2805. # a clean server_name.
  2806. #
  2807. # The server_name cannot be changed later so it is important to
  2808. # configure this correctly before you start Synapse. It should be all
  2809. # lowercase and may contain an explicit port.
  2810. # Examples: matrix.org, localhost:8080
  2811. #
  2812. server_name: &quot;SERVERNAME&quot;
  2813. # When running as a daemon, the file to store the pid in
  2814. #
  2815. pid_file: DATADIR/homeserver.pid
  2816. # The absolute URL to the web client which /_matrix/client will redirect
  2817. # to if 'webclient' is configured under the 'listeners' configuration.
  2818. #
  2819. # This option can be also set to the filesystem path to the web client
  2820. # which will be served at /_matrix/client/ if 'webclient' is configured
  2821. # under the 'listeners' configuration, however this is a security risk:
  2822. # https://github.com/matrix-org/synapse#security-note
  2823. #
  2824. #web_client_location: https://riot.example.com/
  2825. # The public-facing base URL that clients use to access this Homeserver (not
  2826. # including _matrix/...). This is the same URL a user might enter into the
  2827. # 'Custom Homeserver URL' field on their client. If you use Synapse with a
  2828. # reverse proxy, this should be the URL to reach Synapse via the proxy.
  2829. # Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
  2830. # 'listeners' below).
  2831. #
  2832. #public_baseurl: https://example.com/
  2833. # Set the soft limit on the number of file descriptors synapse can use
  2834. # Zero is used to indicate synapse should set the soft limit to the
  2835. # hard limit.
  2836. #
  2837. #soft_file_limit: 0
  2838. # Presence tracking allows users to see the state (e.g online/offline)
  2839. # of other local and remote users.
  2840. #
  2841. presence:
  2842. # Uncomment to disable presence tracking on this homeserver. This option
  2843. # replaces the previous top-level 'use_presence' option.
  2844. #
  2845. #enabled: false
  2846. # Presence routers are third-party modules that can specify additional logic
  2847. # to where presence updates from users are routed.
  2848. #
  2849. presence_router:
  2850. # The custom module's class. Uncomment to use a custom presence router module.
  2851. #
  2852. #module: &quot;my_custom_router.PresenceRouter&quot;
  2853. # Configuration options of the custom module. Refer to your module's
  2854. # documentation for available options.
  2855. #
  2856. #config:
  2857. # example_option: 'something'
  2858. # Whether to require authentication to retrieve profile data (avatars,
  2859. # display names) of other users through the client API. Defaults to
  2860. # 'false'. Note that profile data is also available via the federation
  2861. # API, unless allow_profile_lookup_over_federation is set to false.
  2862. #
  2863. #require_auth_for_profile_requests: true
  2864. # Uncomment to require a user to share a room with another user in order
  2865. # to retrieve their profile information. Only checked on Client-Server
  2866. # requests. Profile requests from other servers should be checked by the
  2867. # requesting server. Defaults to 'false'.
  2868. #
  2869. #limit_profile_requests_to_users_who_share_rooms: true
  2870. # Uncomment to prevent a user's profile data from being retrieved and
  2871. # displayed in a room until they have joined it. By default, a user's
  2872. # profile data is included in an invite event, regardless of the values
  2873. # of the above two settings, and whether or not the users share a server.
  2874. # Defaults to 'true'.
  2875. #
  2876. #include_profile_data_on_invite: false
  2877. # If set to 'true', removes the need for authentication to access the server's
  2878. # public rooms directory through the client API, meaning that anyone can
  2879. # query the room directory. Defaults to 'false'.
  2880. #
  2881. #allow_public_rooms_without_auth: true
  2882. # If set to 'true', allows any other homeserver to fetch the server's public
  2883. # rooms directory via federation. Defaults to 'false'.
  2884. #
  2885. #allow_public_rooms_over_federation: true
  2886. # The default room version for newly created rooms.
  2887. #
  2888. # Known room versions are listed here:
  2889. # https://matrix.org/docs/spec/#complete-list-of-room-versions
  2890. #
  2891. # For example, for room version 1, default_room_version should be set
  2892. # to &quot;1&quot;.
  2893. #
  2894. #default_room_version: &quot;6&quot;
  2895. # The GC threshold parameters to pass to `gc.set_threshold`, if defined
  2896. #
  2897. #gc_thresholds: [700, 10, 10]
  2898. # The minimum time in seconds between each GC for a generation, regardless of
  2899. # the GC thresholds. This ensures that we don't do GC too frequently.
  2900. #
  2901. # A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
  2902. # generation 0 GCs, etc.
  2903. #
  2904. # Defaults to `[1s, 10s, 30s]`.
  2905. #
  2906. #gc_min_interval: [0.5s, 30s, 1m]
  2907. # Set the limit on the returned events in the timeline in the get
  2908. # and sync operations. The default value is 100. -1 means no upper limit.
  2909. #
  2910. # Uncomment the following to increase the limit to 5000.
  2911. #
  2912. #filter_timeline_limit: 5000
  2913. # Whether room invites to users on this server should be blocked
  2914. # (except those sent by local server admins). The default is False.
  2915. #
  2916. #block_non_admin_invites: true
  2917. # Room searching
  2918. #
  2919. # If disabled, new messages will not be indexed for searching and users
  2920. # will receive errors when searching for messages. Defaults to enabled.
  2921. #
  2922. #enable_search: false
  2923. # Prevent outgoing requests from being sent to the following blacklisted IP address
  2924. # CIDR ranges. If this option is not specified then it defaults to private IP
  2925. # address ranges (see the example below).
  2926. #
  2927. # The blacklist applies to the outbound requests for federation, identity servers,
  2928. # push servers, and for checking key validity for third-party invite events.
  2929. #
  2930. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  2931. # listed here, since they correspond to unroutable addresses.)
  2932. #
  2933. # This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
  2934. #
  2935. #ip_range_blacklist:
  2936. # - '127.0.0.0/8'
  2937. # - '10.0.0.0/8'
  2938. # - '172.16.0.0/12'
  2939. # - '192.168.0.0/16'
  2940. # - '100.64.0.0/10'
  2941. # - '192.0.0.0/24'
  2942. # - '169.254.0.0/16'
  2943. # - '192.88.99.0/24'
  2944. # - '198.18.0.0/15'
  2945. # - '192.0.2.0/24'
  2946. # - '198.51.100.0/24'
  2947. # - '203.0.113.0/24'
  2948. # - '224.0.0.0/4'
  2949. # - '::1/128'
  2950. # - 'fe80::/10'
  2951. # - 'fc00::/7'
  2952. # - '2001:db8::/32'
  2953. # - 'ff00::/8'
  2954. # - 'fec0::/10'
  2955. # List of IP address CIDR ranges that should be allowed for federation,
  2956. # identity servers, push servers, and for checking key validity for
  2957. # third-party invite events. This is useful for specifying exceptions to
  2958. # wide-ranging blacklisted target IP ranges - e.g. for communication with
  2959. # a push server only visible in your network.
  2960. #
  2961. # This whitelist overrides ip_range_blacklist and defaults to an empty
  2962. # list.
  2963. #
  2964. #ip_range_whitelist:
  2965. # - '192.168.1.1'
  2966. # List of ports that Synapse should listen on, their purpose and their
  2967. # configuration.
  2968. #
  2969. # Options for each listener include:
  2970. #
  2971. # port: the TCP port to bind to
  2972. #
  2973. # bind_addresses: a list of local addresses to listen on. The default is
  2974. # 'all local interfaces'.
  2975. #
  2976. # type: the type of listener. Normally 'http', but other valid options are:
  2977. # 'manhole' (see https://matrix-org.github.io/synapse/latest/manhole.html),
  2978. # 'metrics' (see https://matrix-org.github.io/synapse/latest/metrics-howto.html),
  2979. # 'replication' (see https://matrix-org.github.io/synapse/latest/workers.html).
  2980. #
  2981. # tls: set to true to enable TLS for this listener. Will use the TLS
  2982. # key/cert specified in tls_private_key_path / tls_certificate_path.
  2983. #
  2984. # x_forwarded: Only valid for an 'http' listener. Set to true to use the
  2985. # X-Forwarded-For header as the client IP. Useful when Synapse is
  2986. # behind a reverse-proxy.
  2987. #
  2988. # resources: Only valid for an 'http' listener. A list of resources to host
  2989. # on this port. Options for each resource are:
  2990. #
  2991. # names: a list of names of HTTP resources. See below for a list of
  2992. # valid resource names.
  2993. #
  2994. # compress: set to true to enable HTTP compression for this resource.
  2995. #
  2996. # additional_resources: Only valid for an 'http' listener. A map of
  2997. # additional endpoints which should be loaded via dynamic modules.
  2998. #
  2999. # Valid resource names are:
  3000. #
  3001. # client: the client-server API (/_matrix/client), and the synapse admin
  3002. # API (/_synapse/admin). Also implies 'media' and 'static'.
  3003. #
  3004. # consent: user consent forms (/_matrix/consent).
  3005. # See https://matrix-org.github.io/synapse/latest/consent_tracking.html.
  3006. #
  3007. # federation: the server-server API (/_matrix/federation). Also implies
  3008. # 'media', 'keys', 'openid'
  3009. #
  3010. # keys: the key discovery API (/_matrix/keys).
  3011. #
  3012. # media: the media API (/_matrix/media).
  3013. #
  3014. # metrics: the metrics interface.
  3015. # See https://matrix-org.github.io/synapse/latest/metrics-howto.html.
  3016. #
  3017. # openid: OpenID authentication.
  3018. #
  3019. # replication: the HTTP replication API (/_synapse/replication).
  3020. # See https://matrix-org.github.io/synapse/latest/workers.html.
  3021. #
  3022. # static: static resources under synapse/static (/_matrix/static). (Mostly
  3023. # useful for 'fallback authentication'.)
  3024. #
  3025. # webclient: A web client. Requires web_client_location to be set.
  3026. #
  3027. listeners:
  3028. # TLS-enabled listener: for when matrix traffic is sent directly to synapse.
  3029. #
  3030. # Disabled by default. To enable it, uncomment the following. (Note that you
  3031. # will also need to give Synapse a TLS key and certificate: see the TLS section
  3032. # below.)
  3033. #
  3034. #- port: 8448
  3035. # type: http
  3036. # tls: true
  3037. # resources:
  3038. # - names: [client, federation]
  3039. # Unsecure HTTP listener: for when matrix traffic passes through a reverse proxy
  3040. # that unwraps TLS.
  3041. #
  3042. # If you plan to use a reverse proxy, please see
  3043. # https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3044. #
  3045. - port: 8008
  3046. tls: false
  3047. type: http
  3048. x_forwarded: true
  3049. bind_addresses: ['::1', '127.0.0.1']
  3050. resources:
  3051. - names: [client, federation]
  3052. compress: false
  3053. # example additional_resources:
  3054. #
  3055. #additional_resources:
  3056. # &quot;/_matrix/my/custom/endpoint&quot;:
  3057. # module: my_module.CustomRequestHandler
  3058. # config: {}
  3059. # Turn on the twisted ssh manhole service on localhost on the given
  3060. # port.
  3061. #
  3062. #- port: 9000
  3063. # bind_addresses: ['::1', '127.0.0.1']
  3064. # type: manhole
  3065. # Forward extremities can build up in a room due to networking delays between
  3066. # homeservers. Once this happens in a large room, calculation of the state of
  3067. # that room can become quite expensive. To mitigate this, once the number of
  3068. # forward extremities reaches a given threshold, Synapse will send an
  3069. # org.matrix.dummy_event event, which will reduce the forward extremities
  3070. # in the room.
  3071. #
  3072. # This setting defines the threshold (i.e. number of forward extremities in the
  3073. # room) at which dummy events are sent. The default value is 10.
  3074. #
  3075. #dummy_events_threshold: 5
  3076. ## Homeserver blocking ##
  3077. # How to reach the server admin, used in ResourceLimitError
  3078. #
  3079. #admin_contact: 'mailto:admin@server.com'
  3080. # Global blocking
  3081. #
  3082. #hs_disabled: false
  3083. #hs_disabled_message: 'Human readable reason for why the HS is blocked'
  3084. # Monthly Active User Blocking
  3085. #
  3086. # Used in cases where the admin or server owner wants to limit to the
  3087. # number of monthly active users.
  3088. #
  3089. # 'limit_usage_by_mau' disables/enables monthly active user blocking. When
  3090. # enabled and a limit is reached the server returns a 'ResourceLimitError'
  3091. # with error type Codes.RESOURCE_LIMIT_EXCEEDED
  3092. #
  3093. # 'max_mau_value' is the hard limit of monthly active users above which
  3094. # the server will start blocking user actions.
  3095. #
  3096. # 'mau_trial_days' is a means to add a grace period for active users. It
  3097. # means that users must be active for this number of days before they
  3098. # can be considered active and guards against the case where lots of users
  3099. # sign up in a short space of time never to return after their initial
  3100. # session.
  3101. #
  3102. # 'mau_limit_alerting' is a means of limiting client side alerting
  3103. # should the mau limit be reached. This is useful for small instances
  3104. # where the admin has 5 mau seats (say) for 5 specific people and no
  3105. # interest increasing the mau limit further. Defaults to True, which
  3106. # means that alerting is enabled
  3107. #
  3108. #limit_usage_by_mau: false
  3109. #max_mau_value: 50
  3110. #mau_trial_days: 2
  3111. #mau_limit_alerting: false
  3112. # If enabled, the metrics for the number of monthly active users will
  3113. # be populated, however no one will be limited. If limit_usage_by_mau
  3114. # is true, this is implied to be true.
  3115. #
  3116. #mau_stats_only: false
  3117. # Sometimes the server admin will want to ensure certain accounts are
  3118. # never blocked by mau checking. These accounts are specified here.
  3119. #
  3120. #mau_limit_reserved_threepids:
  3121. # - medium: 'email'
  3122. # address: 'reserved_user@example.com'
  3123. # Used by phonehome stats to group together related servers.
  3124. #server_context: context
  3125. # Resource-constrained homeserver settings
  3126. #
  3127. # When this is enabled, the room &quot;complexity&quot; will be checked before a user
  3128. # joins a new remote room. If it is above the complexity limit, the server will
  3129. # disallow joining, or will instantly leave.
  3130. #
  3131. # Room complexity is an arbitrary measure based on factors such as the number of
  3132. # users in the room.
  3133. #
  3134. limit_remote_rooms:
  3135. # Uncomment to enable room complexity checking.
  3136. #
  3137. #enabled: true
  3138. # the limit above which rooms cannot be joined. The default is 1.0.
  3139. #
  3140. #complexity: 0.5
  3141. # override the error which is returned when the room is too complex.
  3142. #
  3143. #complexity_error: &quot;This room is too complex.&quot;
  3144. # allow server admins to join complex rooms. Default is false.
  3145. #
  3146. #admins_can_join: true
  3147. # Whether to require a user to be in the room to add an alias to it.
  3148. # Defaults to 'true'.
  3149. #
  3150. #require_membership_for_aliases: false
  3151. # Whether to allow per-room membership profiles through the send of membership
  3152. # events with profile information that differ from the target's global profile.
  3153. # Defaults to 'true'.
  3154. #
  3155. #allow_per_room_profiles: false
  3156. # How long to keep redacted events in unredacted form in the database. After
  3157. # this period redacted events get replaced with their redacted form in the DB.
  3158. #
  3159. # Defaults to `7d`. Set to `null` to disable.
  3160. #
  3161. #redaction_retention_period: 28d
  3162. # How long to track users' last seen time and IPs in the database.
  3163. #
  3164. # Defaults to `28d`. Set to `null` to disable clearing out of old rows.
  3165. #
  3166. #user_ips_max_age: 14d
  3167. # Message retention policy at the server level.
  3168. #
  3169. # Room admins and mods can define a retention period for their rooms using the
  3170. # 'm.room.retention' state event, and server admins can cap this period by setting
  3171. # the 'allowed_lifetime_min' and 'allowed_lifetime_max' config options.
  3172. #
  3173. # If this feature is enabled, Synapse will regularly look for and purge events
  3174. # which are older than the room's maximum retention period. Synapse will also
  3175. # filter events received over federation so that events that should have been
  3176. # purged are ignored and not stored again.
  3177. #
  3178. retention:
  3179. # The message retention policies feature is disabled by default. Uncomment the
  3180. # following line to enable it.
  3181. #
  3182. #enabled: true
  3183. # Default retention policy. If set, Synapse will apply it to rooms that lack the
  3184. # 'm.room.retention' state event. Currently, the value of 'min_lifetime' doesn't
  3185. # matter much because Synapse doesn't take it into account yet.
  3186. #
  3187. #default_policy:
  3188. # min_lifetime: 1d
  3189. # max_lifetime: 1y
  3190. # Retention policy limits. If set, and the state of a room contains a
  3191. # 'm.room.retention' event in its state which contains a 'min_lifetime' or a
  3192. # 'max_lifetime' that's out of these bounds, Synapse will cap the room's policy
  3193. # to these limits when running purge jobs.
  3194. #
  3195. #allowed_lifetime_min: 1d
  3196. #allowed_lifetime_max: 1y
  3197. # Server admins can define the settings of the background jobs purging the
  3198. # events which lifetime has expired under the 'purge_jobs' section.
  3199. #
  3200. # If no configuration is provided, a single job will be set up to delete expired
  3201. # events in every room daily.
  3202. #
  3203. # Each job's configuration defines which range of message lifetimes the job
  3204. # takes care of. For example, if 'shortest_max_lifetime' is '2d' and
  3205. # 'longest_max_lifetime' is '3d', the job will handle purging expired events in
  3206. # rooms whose state defines a 'max_lifetime' that's both higher than 2 days, and
  3207. # lower than or equal to 3 days. Both the minimum and the maximum value of a
  3208. # range are optional, e.g. a job with no 'shortest_max_lifetime' and a
  3209. # 'longest_max_lifetime' of '3d' will handle every room with a retention policy
  3210. # which 'max_lifetime' is lower than or equal to three days.
  3211. #
  3212. # The rationale for this per-job configuration is that some rooms might have a
  3213. # retention policy with a low 'max_lifetime', where history needs to be purged
  3214. # of outdated messages on a more frequent basis than for the rest of the rooms
  3215. # (e.g. every 12h), but not want that purge to be performed by a job that's
  3216. # iterating over every room it knows, which could be heavy on the server.
  3217. #
  3218. # If any purge job is configured, it is strongly recommended to have at least
  3219. # a single job with neither 'shortest_max_lifetime' nor 'longest_max_lifetime'
  3220. # set, or one job without 'shortest_max_lifetime' and one job without
  3221. # 'longest_max_lifetime' set. Otherwise some rooms might be ignored, even if
  3222. # 'allowed_lifetime_min' and 'allowed_lifetime_max' are set, because capping a
  3223. # room's policy to these values is done after the policies are retrieved from
  3224. # Synapse's database (which is done using the range specified in a purge job's
  3225. # configuration).
  3226. #
  3227. #purge_jobs:
  3228. # - longest_max_lifetime: 3d
  3229. # interval: 12h
  3230. # - shortest_max_lifetime: 3d
  3231. # interval: 1d
  3232. # Inhibits the /requestToken endpoints from returning an error that might leak
  3233. # information about whether an e-mail address is in use or not on this
  3234. # homeserver.
  3235. # Note that for some endpoints the error situation is the e-mail already being
  3236. # used, and for others the error is entering the e-mail being unused.
  3237. # If this option is enabled, instead of returning an error, these endpoints will
  3238. # act as if no error happened and return a fake session ID ('sid') to clients.
  3239. #
  3240. #request_token_inhibit_3pid_errors: true
  3241. # A list of domains that the domain portion of 'next_link' parameters
  3242. # must match.
  3243. #
  3244. # This parameter is optionally provided by clients while requesting
  3245. # validation of an email or phone number, and maps to a link that
  3246. # users will be automatically redirected to after validation
  3247. # succeeds. Clients can make use this parameter to aid the validation
  3248. # process.
  3249. #
  3250. # The whitelist is applied whether the homeserver or an
  3251. # identity server is handling validation.
  3252. #
  3253. # The default value is no whitelist functionality; all domains are
  3254. # allowed. Setting this value to an empty list will instead disallow
  3255. # all domains.
  3256. #
  3257. #next_link_domain_whitelist: [&quot;matrix.org&quot;]
  3258. ## TLS ##
  3259. # PEM-encoded X509 certificate for TLS.
  3260. # This certificate, as of Synapse 1.0, will need to be a valid and verifiable
  3261. # certificate, signed by a recognised Certificate Authority.
  3262. #
  3263. # Be sure to use a `.pem` file that includes the full certificate chain including
  3264. # any intermediate certificates (for instance, if using certbot, use
  3265. # `fullchain.pem` as your certificate, not `cert.pem`).
  3266. #
  3267. #tls_certificate_path: &quot;CONFDIR/SERVERNAME.tls.crt&quot;
  3268. # PEM-encoded private key for TLS
  3269. #
  3270. #tls_private_key_path: &quot;CONFDIR/SERVERNAME.tls.key&quot;
  3271. # Whether to verify TLS server certificates for outbound federation requests.
  3272. #
  3273. # Defaults to `true`. To disable certificate verification, uncomment the
  3274. # following line.
  3275. #
  3276. #federation_verify_certificates: false
  3277. # The minimum TLS version that will be used for outbound federation requests.
  3278. #
  3279. # Defaults to `1`. Configurable to `1`, `1.1`, `1.2`, or `1.3`. Note
  3280. # that setting this value higher than `1.2` will prevent federation to most
  3281. # of the public Matrix network: only configure it to `1.3` if you have an
  3282. # entirely private federation setup and you can ensure TLS 1.3 support.
  3283. #
  3284. #federation_client_minimum_tls_version: 1.2
  3285. # Skip federation certificate verification on the following whitelist
  3286. # of domains.
  3287. #
  3288. # This setting should only be used in very specific cases, such as
  3289. # federation over Tor hidden services and similar. For private networks
  3290. # of homeservers, you likely want to use a private CA instead.
  3291. #
  3292. # Only effective if federation_verify_certicates is `true`.
  3293. #
  3294. #federation_certificate_verification_whitelist:
  3295. # - lon.example.com
  3296. # - *.domain.com
  3297. # - *.onion
  3298. # List of custom certificate authorities for federation traffic.
  3299. #
  3300. # This setting should only normally be used within a private network of
  3301. # homeservers.
  3302. #
  3303. # Note that this list will replace those that are provided by your
  3304. # operating environment. Certificates must be in PEM format.
  3305. #
  3306. #federation_custom_ca_list:
  3307. # - myCA1.pem
  3308. # - myCA2.pem
  3309. # - myCA3.pem
  3310. ## Federation ##
  3311. # Restrict federation to the following whitelist of domains.
  3312. # N.B. we recommend also firewalling your federation listener to limit
  3313. # inbound federation traffic as early as possible, rather than relying
  3314. # purely on this application-layer restriction. If not specified, the
  3315. # default is to whitelist everything.
  3316. #
  3317. #federation_domain_whitelist:
  3318. # - lon.example.com
  3319. # - nyc.example.com
  3320. # - syd.example.com
  3321. # Report prometheus metrics on the age of PDUs being sent to and received from
  3322. # the following domains. This can be used to give an idea of &quot;delay&quot; on inbound
  3323. # and outbound federation, though be aware that any delay can be due to problems
  3324. # at either end or with the intermediate network.
  3325. #
  3326. # By default, no domains are monitored in this way.
  3327. #
  3328. #federation_metrics_domains:
  3329. # - matrix.org
  3330. # - example.com
  3331. # Uncomment to disable profile lookup over federation. By default, the
  3332. # Federation API allows other homeservers to obtain profile data of any user
  3333. # on this homeserver. Defaults to 'true'.
  3334. #
  3335. #allow_profile_lookup_over_federation: false
  3336. # Uncomment to disable device display name lookup over federation. By default, the
  3337. # Federation API allows other homeservers to obtain device display names of any user
  3338. # on this homeserver. Defaults to 'true'.
  3339. #
  3340. #allow_device_name_lookup_over_federation: false
  3341. ## Caching ##
  3342. # Caching can be configured through the following options.
  3343. #
  3344. # A cache 'factor' is a multiplier that can be applied to each of
  3345. # Synapse's caches in order to increase or decrease the maximum
  3346. # number of entries that can be stored.
  3347. # The number of events to cache in memory. Not affected by
  3348. # caches.global_factor.
  3349. #
  3350. #event_cache_size: 10K
  3351. caches:
  3352. # Controls the global cache factor, which is the default cache factor
  3353. # for all caches if a specific factor for that cache is not otherwise
  3354. # set.
  3355. #
  3356. # This can also be set by the &quot;SYNAPSE_CACHE_FACTOR&quot; environment
  3357. # variable. Setting by environment variable takes priority over
  3358. # setting through the config file.
  3359. #
  3360. # Defaults to 0.5, which will half the size of all caches.
  3361. #
  3362. #global_factor: 1.0
  3363. # A dictionary of cache name to cache factor for that individual
  3364. # cache. Overrides the global cache factor for a given cache.
  3365. #
  3366. # These can also be set through environment variables comprised
  3367. # of &quot;SYNAPSE_CACHE_FACTOR_&quot; + the name of the cache in capital
  3368. # letters and underscores. Setting by environment variable
  3369. # takes priority over setting through the config file.
  3370. # Ex. SYNAPSE_CACHE_FACTOR_GET_USERS_WHO_SHARE_ROOM_WITH_USER=2.0
  3371. #
  3372. # Some caches have '*' and other characters that are not
  3373. # alphanumeric or underscores. These caches can be named with or
  3374. # without the special characters stripped. For example, to specify
  3375. # the cache factor for `*stateGroupCache*` via an environment
  3376. # variable would be `SYNAPSE_CACHE_FACTOR_STATEGROUPCACHE=2.0`.
  3377. #
  3378. per_cache_factors:
  3379. #get_users_who_share_room_with_user: 2.0
  3380. # Controls how long an entry can be in a cache without having been
  3381. # accessed before being evicted. Defaults to None, which means
  3382. # entries are never evicted based on time.
  3383. #
  3384. #expiry_time: 30m
  3385. ## Database ##
  3386. # The 'database' setting defines the database that synapse uses to store all of
  3387. # its data.
  3388. #
  3389. # 'name' gives the database engine to use: either 'sqlite3' (for SQLite) or
  3390. # 'psycopg2' (for PostgreSQL).
  3391. #
  3392. # 'args' gives options which are passed through to the database engine,
  3393. # except for options starting 'cp_', which are used to configure the Twisted
  3394. # connection pool. For a reference to valid arguments, see:
  3395. # * for sqlite: https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
  3396. # * for postgres: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
  3397. # * for the connection pool: https://twistedmatrix.com/documents/current/api/twisted.enterprise.adbapi.ConnectionPool.html#__init__
  3398. #
  3399. #
  3400. # Example SQLite configuration:
  3401. #
  3402. #database:
  3403. # name: sqlite3
  3404. # args:
  3405. # database: /path/to/homeserver.db
  3406. #
  3407. #
  3408. # Example Postgres configuration:
  3409. #
  3410. #database:
  3411. # name: psycopg2
  3412. # args:
  3413. # user: synapse_user
  3414. # password: secretpassword
  3415. # database: synapse
  3416. # host: localhost
  3417. # port: 5432
  3418. # cp_min: 5
  3419. # cp_max: 10
  3420. #
  3421. # For more information on using Synapse with Postgres,
  3422. # see https://matrix-org.github.io/synapse/latest/postgres.html.
  3423. #
  3424. database:
  3425. name: sqlite3
  3426. args:
  3427. database: DATADIR/homeserver.db
  3428. ## Logging ##
  3429. # A yaml python logging config file as described by
  3430. # https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  3431. #
  3432. log_config: &quot;CONFDIR/SERVERNAME.log.config&quot;
  3433. ## Ratelimiting ##
  3434. # Ratelimiting settings for client actions (registration, login, messaging).
  3435. #
  3436. # Each ratelimiting configuration is made of two parameters:
  3437. # - per_second: number of requests a client can send per second.
  3438. # - burst_count: number of requests a client can send before being throttled.
  3439. #
  3440. # Synapse currently uses the following configurations:
  3441. # - one for messages that ratelimits sending based on the account the client
  3442. # is using
  3443. # - one for registration that ratelimits registration requests based on the
  3444. # client's IP address.
  3445. # - one for login that ratelimits login requests based on the client's IP
  3446. # address.
  3447. # - one for login that ratelimits login requests based on the account the
  3448. # client is attempting to log into.
  3449. # - one for login that ratelimits login requests based on the account the
  3450. # client is attempting to log into, based on the amount of failed login
  3451. # attempts for this account.
  3452. # - one for ratelimiting redactions by room admins. If this is not explicitly
  3453. # set then it uses the same ratelimiting as per rc_message. This is useful
  3454. # to allow room admins to deal with abuse quickly.
  3455. # - two for ratelimiting number of rooms a user can join, &quot;local&quot; for when
  3456. # users are joining rooms the server is already in (this is cheap) vs
  3457. # &quot;remote&quot; for when users are trying to join rooms not on the server (which
  3458. # can be more expensive)
  3459. # - one for ratelimiting how often a user or IP can attempt to validate a 3PID.
  3460. # - two for ratelimiting how often invites can be sent in a room or to a
  3461. # specific user.
  3462. #
  3463. # The defaults are as shown below.
  3464. #
  3465. #rc_message:
  3466. # per_second: 0.2
  3467. # burst_count: 10
  3468. #
  3469. #rc_registration:
  3470. # per_second: 0.17
  3471. # burst_count: 3
  3472. #
  3473. #rc_login:
  3474. # address:
  3475. # per_second: 0.17
  3476. # burst_count: 3
  3477. # account:
  3478. # per_second: 0.17
  3479. # burst_count: 3
  3480. # failed_attempts:
  3481. # per_second: 0.17
  3482. # burst_count: 3
  3483. #
  3484. #rc_admin_redaction:
  3485. # per_second: 1
  3486. # burst_count: 50
  3487. #
  3488. #rc_joins:
  3489. # local:
  3490. # per_second: 0.1
  3491. # burst_count: 10
  3492. # remote:
  3493. # per_second: 0.01
  3494. # burst_count: 10
  3495. #
  3496. #rc_3pid_validation:
  3497. # per_second: 0.003
  3498. # burst_count: 5
  3499. #
  3500. #rc_invites:
  3501. # per_room:
  3502. # per_second: 0.3
  3503. # burst_count: 10
  3504. # per_user:
  3505. # per_second: 0.003
  3506. # burst_count: 5
  3507. # Ratelimiting settings for incoming federation
  3508. #
  3509. # The rc_federation configuration is made up of the following settings:
  3510. # - window_size: window size in milliseconds
  3511. # - sleep_limit: number of federation requests from a single server in
  3512. # a window before the server will delay processing the request.
  3513. # - sleep_delay: duration in milliseconds to delay processing events
  3514. # from remote servers by if they go over the sleep limit.
  3515. # - reject_limit: maximum number of concurrent federation requests
  3516. # allowed from a single server
  3517. # - concurrent: number of federation requests to concurrently process
  3518. # from a single server
  3519. #
  3520. # The defaults are as shown below.
  3521. #
  3522. #rc_federation:
  3523. # window_size: 1000
  3524. # sleep_limit: 10
  3525. # sleep_delay: 500
  3526. # reject_limit: 50
  3527. # concurrent: 3
  3528. # Target outgoing federation transaction frequency for sending read-receipts,
  3529. # per-room.
  3530. #
  3531. # If we end up trying to send out more read-receipts, they will get buffered up
  3532. # into fewer transactions.
  3533. #
  3534. #federation_rr_transactions_per_room_per_second: 50
  3535. ## Media Store ##
  3536. # Enable the media store service in the Synapse master. Uncomment the
  3537. # following if you are using a separate media store worker.
  3538. #
  3539. #enable_media_repo: false
  3540. # Directory where uploaded images and attachments are stored.
  3541. #
  3542. media_store_path: &quot;DATADIR/media_store&quot;
  3543. # Media storage providers allow media to be stored in different
  3544. # locations.
  3545. #
  3546. #media_storage_providers:
  3547. # - module: file_system
  3548. # # Whether to store newly uploaded local files
  3549. # store_local: false
  3550. # # Whether to store newly downloaded remote files
  3551. # store_remote: false
  3552. # # Whether to wait for successful storage for local uploads
  3553. # store_synchronous: false
  3554. # config:
  3555. # directory: /mnt/some/other/directory
  3556. # The largest allowed upload size in bytes
  3557. #
  3558. # If you are using a reverse proxy you may also need to set this value in
  3559. # your reverse proxy's config. Notably Nginx has a small max body size by default.
  3560. # See https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3561. #
  3562. #max_upload_size: 50M
  3563. # Maximum number of pixels that will be thumbnailed
  3564. #
  3565. #max_image_pixels: 32M
  3566. # Whether to generate new thumbnails on the fly to precisely match
  3567. # the resolution requested by the client. If true then whenever
  3568. # a new resolution is requested by the client the server will
  3569. # generate a new thumbnail. If false the server will pick a thumbnail
  3570. # from a precalculated list.
  3571. #
  3572. #dynamic_thumbnails: false
  3573. # List of thumbnails to precalculate when an image is uploaded.
  3574. #
  3575. #thumbnail_sizes:
  3576. # - width: 32
  3577. # height: 32
  3578. # method: crop
  3579. # - width: 96
  3580. # height: 96
  3581. # method: crop
  3582. # - width: 320
  3583. # height: 240
  3584. # method: scale
  3585. # - width: 640
  3586. # height: 480
  3587. # method: scale
  3588. # - width: 800
  3589. # height: 600
  3590. # method: scale
  3591. # Is the preview URL API enabled?
  3592. #
  3593. # 'false' by default: uncomment the following to enable it (and specify a
  3594. # url_preview_ip_range_blacklist blacklist).
  3595. #
  3596. #url_preview_enabled: true
  3597. # List of IP address CIDR ranges that the URL preview spider is denied
  3598. # from accessing. There are no defaults: you must explicitly
  3599. # specify a list for URL previewing to work. You should specify any
  3600. # internal services in your network that you do not want synapse to try
  3601. # to connect to, otherwise anyone in any Matrix room could cause your
  3602. # synapse to issue arbitrary GET requests to your internal services,
  3603. # causing serious security issues.
  3604. #
  3605. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3606. # listed here, since they correspond to unroutable addresses.)
  3607. #
  3608. # This must be specified if url_preview_enabled is set. It is recommended that
  3609. # you uncomment the following list as a starting point.
  3610. #
  3611. #url_preview_ip_range_blacklist:
  3612. # - '127.0.0.0/8'
  3613. # - '10.0.0.0/8'
  3614. # - '172.16.0.0/12'
  3615. # - '192.168.0.0/16'
  3616. # - '100.64.0.0/10'
  3617. # - '192.0.0.0/24'
  3618. # - '169.254.0.0/16'
  3619. # - '192.88.99.0/24'
  3620. # - '198.18.0.0/15'
  3621. # - '192.0.2.0/24'
  3622. # - '198.51.100.0/24'
  3623. # - '203.0.113.0/24'
  3624. # - '224.0.0.0/4'
  3625. # - '::1/128'
  3626. # - 'fe80::/10'
  3627. # - 'fc00::/7'
  3628. # - '2001:db8::/32'
  3629. # - 'ff00::/8'
  3630. # - 'fec0::/10'
  3631. # List of IP address CIDR ranges that the URL preview spider is allowed
  3632. # to access even if they are specified in url_preview_ip_range_blacklist.
  3633. # This is useful for specifying exceptions to wide-ranging blacklisted
  3634. # target IP ranges - e.g. for enabling URL previews for a specific private
  3635. # website only visible in your network.
  3636. #
  3637. #url_preview_ip_range_whitelist:
  3638. # - '192.168.1.1'
  3639. # Optional list of URL matches that the URL preview spider is
  3640. # denied from accessing. You should use url_preview_ip_range_blacklist
  3641. # in preference to this, otherwise someone could define a public DNS
  3642. # entry that points to a private IP address and circumvent the blacklist.
  3643. # This is more useful if you know there is an entire shape of URL that
  3644. # you know that will never want synapse to try to spider.
  3645. #
  3646. # Each list entry is a dictionary of url component attributes as returned
  3647. # by urlparse.urlsplit as applied to the absolute form of the URL. See
  3648. # https://docs.python.org/2/library/urlparse.html#urlparse.urlsplit
  3649. # The values of the dictionary are treated as an filename match pattern
  3650. # applied to that component of URLs, unless they start with a ^ in which
  3651. # case they are treated as a regular expression match. If all the
  3652. # specified component matches for a given list item succeed, the URL is
  3653. # blacklisted.
  3654. #
  3655. #url_preview_url_blacklist:
  3656. # # blacklist any URL with a username in its URI
  3657. # - username: '*'
  3658. #
  3659. # # blacklist all *.google.com URLs
  3660. # - netloc: 'google.com'
  3661. # - netloc: '*.google.com'
  3662. #
  3663. # # blacklist all plain HTTP URLs
  3664. # - scheme: 'http'
  3665. #
  3666. # # blacklist http(s)://www.acme.com/foo
  3667. # - netloc: 'www.acme.com'
  3668. # path: '/foo'
  3669. #
  3670. # # blacklist any URL with a literal IPv4 address
  3671. # - netloc: '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  3672. # The largest allowed URL preview spidering size in bytes
  3673. #
  3674. #max_spider_size: 10M
  3675. # A list of values for the Accept-Language HTTP header used when
  3676. # downloading webpages during URL preview generation. This allows
  3677. # Synapse to specify the preferred languages that URL previews should
  3678. # be in when communicating with remote servers.
  3679. #
  3680. # Each value is a IETF language tag; a 2-3 letter identifier for a
  3681. # language, optionally followed by subtags separated by '-', specifying
  3682. # a country or region variant.
  3683. #
  3684. # Multiple values can be provided, and a weight can be added to each by
  3685. # using quality value syntax (;q=). '*' translates to any language.
  3686. #
  3687. # Defaults to &quot;en&quot;.
  3688. #
  3689. # Example:
  3690. #
  3691. # url_preview_accept_language:
  3692. # - en-UK
  3693. # - en-US;q=0.9
  3694. # - fr;q=0.8
  3695. # - *;q=0.7
  3696. #
  3697. url_preview_accept_language:
  3698. # - en
  3699. ## Captcha ##
  3700. # See docs/CAPTCHA_SETUP.md for full details of configuring this.
  3701. # This homeserver's ReCAPTCHA public key. Must be specified if
  3702. # enable_registration_captcha is enabled.
  3703. #
  3704. #recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  3705. # This homeserver's ReCAPTCHA private key. Must be specified if
  3706. # enable_registration_captcha is enabled.
  3707. #
  3708. #recaptcha_private_key: &quot;YOUR_PRIVATE_KEY&quot;
  3709. # Uncomment to enable ReCaptcha checks when registering, preventing signup
  3710. # unless a captcha is answered. Requires a valid ReCaptcha
  3711. # public/private key. Defaults to 'false'.
  3712. #
  3713. #enable_registration_captcha: true
  3714. # The API endpoint to use for verifying m.login.recaptcha responses.
  3715. # Defaults to &quot;https://www.recaptcha.net/recaptcha/api/siteverify&quot;.
  3716. #
  3717. #recaptcha_siteverify_api: &quot;https://my.recaptcha.site&quot;
  3718. ## TURN ##
  3719. # The public URIs of the TURN server to give to clients
  3720. #
  3721. #turn_uris: []
  3722. # The shared secret used to compute passwords for the TURN server
  3723. #
  3724. #turn_shared_secret: &quot;YOUR_SHARED_SECRET&quot;
  3725. # The Username and password if the TURN server needs them and
  3726. # does not use a token
  3727. #
  3728. #turn_username: &quot;TURNSERVER_USERNAME&quot;
  3729. #turn_password: &quot;TURNSERVER_PASSWORD&quot;
  3730. # How long generated TURN credentials last
  3731. #
  3732. #turn_user_lifetime: 1h
  3733. # Whether guests should be allowed to use the TURN server.
  3734. # This defaults to True, otherwise VoIP will be unreliable for guests.
  3735. # However, it does introduce a slight security risk as it allows users to
  3736. # connect to arbitrary endpoints without having first signed up for a
  3737. # valid account (e.g. by passing a CAPTCHA).
  3738. #
  3739. #turn_allow_guests: true
  3740. ## Registration ##
  3741. #
  3742. # Registration can be rate-limited using the parameters in the &quot;Ratelimiting&quot;
  3743. # section of this file.
  3744. # Enable registration for new users.
  3745. #
  3746. #enable_registration: false
  3747. # Time that a user's session remains valid for, after they log in.
  3748. #
  3749. # Note that this is not currently compatible with guest logins.
  3750. #
  3751. # Note also that this is calculated at login time: changes are not applied
  3752. # retrospectively to users who have already logged in.
  3753. #
  3754. # By default, this is infinite.
  3755. #
  3756. #session_lifetime: 24h
  3757. # The user must provide all of the below types of 3PID when registering.
  3758. #
  3759. #registrations_require_3pid:
  3760. # - email
  3761. # - msisdn
  3762. # Explicitly disable asking for MSISDNs from the registration
  3763. # flow (overrides registrations_require_3pid if MSISDNs are set as required)
  3764. #
  3765. #disable_msisdn_registration: true
  3766. # Mandate that users are only allowed to associate certain formats of
  3767. # 3PIDs with accounts on this server.
  3768. #
  3769. #allowed_local_3pids:
  3770. # - medium: email
  3771. # pattern: '^[^@]+@matrix\.org$'
  3772. # - medium: email
  3773. # pattern: '^[^@]+@vector\.im$'
  3774. # - medium: msisdn
  3775. # pattern: '\+44'
  3776. # Enable 3PIDs lookup requests to identity servers from this server.
  3777. #
  3778. #enable_3pid_lookup: true
  3779. # If set, allows registration of standard or admin accounts by anyone who
  3780. # has the shared secret, even if registration is otherwise disabled.
  3781. #
  3782. #registration_shared_secret: &lt;PRIVATE STRING&gt;
  3783. # Set the number of bcrypt rounds used to generate password hash.
  3784. # Larger numbers increase the work factor needed to generate the hash.
  3785. # The default number is 12 (which equates to 2^12 rounds).
  3786. # N.B. that increasing this will exponentially increase the time required
  3787. # to register or login - e.g. 24 =&gt; 2^24 rounds which will take &gt;20 mins.
  3788. #
  3789. #bcrypt_rounds: 12
  3790. # Allows users to register as guests without a password/email/etc, and
  3791. # participate in rooms hosted on this server which have been made
  3792. # accessible to anonymous users.
  3793. #
  3794. #allow_guest_access: false
  3795. # The identity server which we suggest that clients should use when users log
  3796. # in on this server.
  3797. #
  3798. # (By default, no suggestion is made, so it is left up to the client.
  3799. # This setting is ignored unless public_baseurl is also set.)
  3800. #
  3801. #default_identity_server: https://matrix.org
  3802. # Handle threepid (email/phone etc) registration and password resets through a set of
  3803. # *trusted* identity servers. Note that this allows the configured identity server to
  3804. # reset passwords for accounts!
  3805. #
  3806. # Be aware that if `email` is not set, and SMTP options have not been
  3807. # configured in the email config block, registration and user password resets via
  3808. # email will be globally disabled.
  3809. #
  3810. # Additionally, if `msisdn` is not set, registration and password resets via msisdn
  3811. # will be disabled regardless, and users will not be able to associate an msisdn
  3812. # identifier to their account. This is due to Synapse currently not supporting
  3813. # any method of sending SMS messages on its own.
  3814. #
  3815. # To enable using an identity server for operations regarding a particular third-party
  3816. # identifier type, set the value to the URL of that identity server as shown in the
  3817. # examples below.
  3818. #
  3819. # Servers handling the these requests must answer the `/requestToken` endpoints defined
  3820. # by the Matrix Identity Service API specification:
  3821. # https://matrix.org/docs/spec/identity_service/latest
  3822. #
  3823. # If a delegate is specified, the config option public_baseurl must also be filled out.
  3824. #
  3825. account_threepid_delegates:
  3826. #email: https://example.com # Delegate email sending to example.com
  3827. #msisdn: http://localhost:8090 # Delegate SMS sending to this local process
  3828. # Whether users are allowed to change their displayname after it has
  3829. # been initially set. Useful when provisioning users based on the
  3830. # contents of a third-party directory.
  3831. #
  3832. # Does not apply to server administrators. Defaults to 'true'
  3833. #
  3834. #enable_set_displayname: false
  3835. # Whether users are allowed to change their avatar after it has been
  3836. # initially set. Useful when provisioning users based on the contents
  3837. # of a third-party directory.
  3838. #
  3839. # Does not apply to server administrators. Defaults to 'true'
  3840. #
  3841. #enable_set_avatar_url: false
  3842. # Whether users can change the 3PIDs associated with their accounts
  3843. # (email address and msisdn).
  3844. #
  3845. # Defaults to 'true'
  3846. #
  3847. #enable_3pid_changes: false
  3848. # Users who register on this homeserver will automatically be joined
  3849. # to these rooms.
  3850. #
  3851. # By default, any room aliases included in this list will be created
  3852. # as a publicly joinable room when the first user registers for the
  3853. # homeserver. This behaviour can be customised with the settings below.
  3854. # If the room already exists, make certain it is a publicly joinable
  3855. # room. The join rule of the room must be set to 'public'.
  3856. #
  3857. #auto_join_rooms:
  3858. # - &quot;#example:example.com&quot;
  3859. # Where auto_join_rooms are specified, setting this flag ensures that the
  3860. # the rooms exist by creating them when the first user on the
  3861. # homeserver registers.
  3862. #
  3863. # By default the auto-created rooms are publicly joinable from any federated
  3864. # server. Use the autocreate_auto_join_rooms_federated and
  3865. # autocreate_auto_join_room_preset settings below to customise this behaviour.
  3866. #
  3867. # Setting to false means that if the rooms are not manually created,
  3868. # users cannot be auto-joined since they do not exist.
  3869. #
  3870. # Defaults to true. Uncomment the following line to disable automatically
  3871. # creating auto-join rooms.
  3872. #
  3873. #autocreate_auto_join_rooms: false
  3874. # Whether the auto_join_rooms that are auto-created are available via
  3875. # federation. Only has an effect if autocreate_auto_join_rooms is true.
  3876. #
  3877. # Note that whether a room is federated cannot be modified after
  3878. # creation.
  3879. #
  3880. # Defaults to true: the room will be joinable from other servers.
  3881. # Uncomment the following to prevent users from other homeservers from
  3882. # joining these rooms.
  3883. #
  3884. #autocreate_auto_join_rooms_federated: false
  3885. # The room preset to use when auto-creating one of auto_join_rooms. Only has an
  3886. # effect if autocreate_auto_join_rooms is true.
  3887. #
  3888. # This can be one of &quot;public_chat&quot;, &quot;private_chat&quot;, or &quot;trusted_private_chat&quot;.
  3889. # If a value of &quot;private_chat&quot; or &quot;trusted_private_chat&quot; is used then
  3890. # auto_join_mxid_localpart must also be configured.
  3891. #
  3892. # Defaults to &quot;public_chat&quot;, meaning that the room is joinable by anyone, including
  3893. # federated servers if autocreate_auto_join_rooms_federated is true (the default).
  3894. # Uncomment the following to require an invitation to join these rooms.
  3895. #
  3896. #autocreate_auto_join_room_preset: private_chat
  3897. # The local part of the user id which is used to create auto_join_rooms if
  3898. # autocreate_auto_join_rooms is true. If this is not provided then the
  3899. # initial user account that registers will be used to create the rooms.
  3900. #
  3901. # The user id is also used to invite new users to any auto-join rooms which
  3902. # are set to invite-only.
  3903. #
  3904. # It *must* be configured if autocreate_auto_join_room_preset is set to
  3905. # &quot;private_chat&quot; or &quot;trusted_private_chat&quot;.
  3906. #
  3907. # Note that this must be specified in order for new users to be correctly
  3908. # invited to any auto-join rooms which have been set to invite-only (either
  3909. # at the time of creation or subsequently).
  3910. #
  3911. # Note that, if the room already exists, this user must be joined and
  3912. # have the appropriate permissions to invite new members.
  3913. #
  3914. #auto_join_mxid_localpart: system
  3915. # When auto_join_rooms is specified, setting this flag to false prevents
  3916. # guest accounts from being automatically joined to the rooms.
  3917. #
  3918. # Defaults to true.
  3919. #
  3920. #auto_join_rooms_for_guests: false
  3921. ## Account Validity ##
  3922. # Optional account validity configuration. This allows for accounts to be denied
  3923. # any request after a given period.
  3924. #
  3925. # Once this feature is enabled, Synapse will look for registered users without an
  3926. # expiration date at startup and will add one to every account it found using the
  3927. # current settings at that time.
  3928. # This means that, if a validity period is set, and Synapse is restarted (it will
  3929. # then derive an expiration date from the current validity period), and some time
  3930. # after that the validity period changes and Synapse is restarted, the users'
  3931. # expiration dates won't be updated unless their account is manually renewed. This
  3932. # date will be randomly selected within a range [now + period - d ; now + period],
  3933. # where d is equal to 10% of the validity period.
  3934. #
  3935. account_validity:
  3936. # The account validity feature is disabled by default. Uncomment the
  3937. # following line to enable it.
  3938. #
  3939. #enabled: true
  3940. # The period after which an account is valid after its registration. When
  3941. # renewing the account, its validity period will be extended by this amount
  3942. # of time. This parameter is required when using the account validity
  3943. # feature.
  3944. #
  3945. #period: 6w
  3946. # The amount of time before an account's expiry date at which Synapse will
  3947. # send an email to the account's email address with a renewal link. By
  3948. # default, no such emails are sent.
  3949. #
  3950. # If you enable this setting, you will also need to fill out the 'email' and
  3951. # 'public_baseurl' configuration sections.
  3952. #
  3953. #renew_at: 1w
  3954. # The subject of the email sent out with the renewal link. '%(app)s' can be
  3955. # used as a placeholder for the 'app_name' parameter from the 'email'
  3956. # section.
  3957. #
  3958. # Note that the placeholder must be written '%(app)s', including the
  3959. # trailing 's'.
  3960. #
  3961. # If this is not set, a default value is used.
  3962. #
  3963. #renew_email_subject: &quot;Renew your %(app)s account&quot;
  3964. # Directory in which Synapse will try to find templates for the HTML files to
  3965. # serve to the user when trying to renew an account. If not set, default
  3966. # templates from within the Synapse package will be used.
  3967. #
  3968. # The currently available templates are:
  3969. #
  3970. # * account_renewed.html: Displayed to the user after they have successfully
  3971. # renewed their account.
  3972. #
  3973. # * account_previously_renewed.html: Displayed to the user if they attempt to
  3974. # renew their account with a token that is valid, but that has already
  3975. # been used. In this case the account is not renewed again.
  3976. #
  3977. # * invalid_token.html: Displayed to the user when they try to renew an account
  3978. # with an unknown or invalid renewal token.
  3979. #
  3980. # See https://github.com/matrix-org/synapse/tree/master/synapse/res/templates for
  3981. # default template contents.
  3982. #
  3983. # The file name of some of these templates can be configured below for legacy
  3984. # reasons.
  3985. #
  3986. #template_dir: &quot;res/templates&quot;
  3987. # A custom file name for the 'account_renewed.html' template.
  3988. #
  3989. # If not set, the file is assumed to be named &quot;account_renewed.html&quot;.
  3990. #
  3991. #account_renewed_html_path: &quot;account_renewed.html&quot;
  3992. # A custom file name for the 'invalid_token.html' template.
  3993. #
  3994. # If not set, the file is assumed to be named &quot;invalid_token.html&quot;.
  3995. #
  3996. #invalid_token_html_path: &quot;invalid_token.html&quot;
  3997. ## Metrics ###
  3998. # Enable collection and rendering of performance metrics
  3999. #
  4000. #enable_metrics: false
  4001. # Enable sentry integration
  4002. # NOTE: While attempts are made to ensure that the logs don't contain
  4003. # any sensitive information, this cannot be guaranteed. By enabling
  4004. # this option the sentry server may therefore receive sensitive
  4005. # information, and it in turn may then diseminate sensitive information
  4006. # through insecure notification channels if so configured.
  4007. #
  4008. #sentry:
  4009. # dsn: &quot;...&quot;
  4010. # Flags to enable Prometheus metrics which are not suitable to be
  4011. # enabled by default, either for performance reasons or limited use.
  4012. #
  4013. metrics_flags:
  4014. # Publish synapse_federation_known_servers, a gauge of the number of
  4015. # servers this homeserver knows about, including itself. May cause
  4016. # performance problems on large homeservers.
  4017. #
  4018. #known_servers: true
  4019. # Whether or not to report anonymized homeserver usage statistics.
  4020. #
  4021. #report_stats: true|false
  4022. # The endpoint to report the anonymized homeserver usage statistics to.
  4023. # Defaults to https://matrix.org/report-usage-stats/push
  4024. #
  4025. #report_stats_endpoint: https://example.com/report-usage-stats/push
  4026. ## API Configuration ##
  4027. # Controls for the state that is shared with users who receive an invite
  4028. # to a room
  4029. #
  4030. room_prejoin_state:
  4031. # By default, the following state event types are shared with users who
  4032. # receive invites to the room:
  4033. #
  4034. # - m.room.join_rules
  4035. # - m.room.canonical_alias
  4036. # - m.room.avatar
  4037. # - m.room.encryption
  4038. # - m.room.name
  4039. # - m.room.create
  4040. #
  4041. # Uncomment the following to disable these defaults (so that only the event
  4042. # types listed in 'additional_event_types' are shared). Defaults to 'false'.
  4043. #
  4044. #disable_default_event_types: true
  4045. # Additional state event types to share with users when they are invited
  4046. # to a room.
  4047. #
  4048. # By default, this list is empty (so only the default event types are shared).
  4049. #
  4050. #additional_event_types:
  4051. # - org.example.custom.event.type
  4052. # A list of application service config files to use
  4053. #
  4054. #app_service_config_files:
  4055. # - app_service_1.yaml
  4056. # - app_service_2.yaml
  4057. # Uncomment to enable tracking of application service IP addresses. Implicitly
  4058. # enables MAU tracking for application service users.
  4059. #
  4060. #track_appservice_user_ips: true
  4061. # a secret which is used to sign access tokens. If none is specified,
  4062. # the registration_shared_secret is used, if one is given; otherwise,
  4063. # a secret key is derived from the signing key.
  4064. #
  4065. #macaroon_secret_key: &lt;PRIVATE STRING&gt;
  4066. # a secret which is used to calculate HMACs for form values, to stop
  4067. # falsification of values. Must be specified for the User Consent
  4068. # forms to work.
  4069. #
  4070. #form_secret: &lt;PRIVATE STRING&gt;
  4071. ## Signing Keys ##
  4072. # Path to the signing key to sign messages with
  4073. #
  4074. signing_key_path: &quot;CONFDIR/SERVERNAME.signing.key&quot;
  4075. # The keys that the server used to sign messages with but won't use
  4076. # to sign new messages.
  4077. #
  4078. old_signing_keys:
  4079. # For each key, `key` should be the base64-encoded public key, and
  4080. # `expired_ts`should be the time (in milliseconds since the unix epoch) that
  4081. # it was last used.
  4082. #
  4083. # It is possible to build an entry from an old signing.key file using the
  4084. # `export_signing_key` script which is provided with synapse.
  4085. #
  4086. # For example:
  4087. #
  4088. #&quot;ed25519:id&quot;: { key: &quot;base64string&quot;, expired_ts: 123456789123 }
  4089. # How long key response published by this server is valid for.
  4090. # Used to set the valid_until_ts in /key/v2 APIs.
  4091. # Determines how quickly servers will query to check which keys
  4092. # are still valid.
  4093. #
  4094. #key_refresh_interval: 1d
  4095. # The trusted servers to download signing keys from.
  4096. #
  4097. # When we need to fetch a signing key, each server is tried in parallel.
  4098. #
  4099. # Normally, the connection to the key server is validated via TLS certificates.
  4100. # Additional security can be provided by configuring a `verify key`, which
  4101. # will make synapse check that the response is signed by that key.
  4102. #
  4103. # This setting supercedes an older setting named `perspectives`. The old format
  4104. # is still supported for backwards-compatibility, but it is deprecated.
  4105. #
  4106. # 'trusted_key_servers' defaults to matrix.org, but using it will generate a
  4107. # warning on start-up. To suppress this warning, set
  4108. # 'suppress_key_server_warning' to true.
  4109. #
  4110. # Options for each entry in the list include:
  4111. #
  4112. # server_name: the name of the server. required.
  4113. #
  4114. # verify_keys: an optional map from key id to base64-encoded public key.
  4115. # If specified, we will check that the response is signed by at least
  4116. # one of the given keys.
  4117. #
  4118. # accept_keys_insecurely: a boolean. Normally, if `verify_keys` is unset,
  4119. # and federation_verify_certificates is not `true`, synapse will refuse
  4120. # to start, because this would allow anyone who can spoof DNS responses
  4121. # to masquerade as the trusted key server. If you know what you are doing
  4122. # and are sure that your network environment provides a secure connection
  4123. # to the key server, you can set this to `true` to override this
  4124. # behaviour.
  4125. #
  4126. # An example configuration might look like:
  4127. #
  4128. #trusted_key_servers:
  4129. # - server_name: &quot;my_trusted_server.example.com&quot;
  4130. # verify_keys:
  4131. # &quot;ed25519:auto&quot;: &quot;abcdefghijklmnopqrstuvwxyzabcdefghijklmopqr&quot;
  4132. # - server_name: &quot;my_other_trusted_server.example.com&quot;
  4133. #
  4134. trusted_key_servers:
  4135. - server_name: &quot;matrix.org&quot;
  4136. # Uncomment the following to disable the warning that is emitted when the
  4137. # trusted_key_servers include 'matrix.org'. See above.
  4138. #
  4139. #suppress_key_server_warning: true
  4140. # The signing keys to use when acting as a trusted key server. If not specified
  4141. # defaults to the server signing key.
  4142. #
  4143. # Can contain multiple keys, one per line.
  4144. #
  4145. #key_server_signing_keys_path: &quot;key_server_signing_keys.key&quot;
  4146. ## Single sign-on integration ##
  4147. # The following settings can be used to make Synapse use a single sign-on
  4148. # provider for authentication, instead of its internal password database.
  4149. #
  4150. # You will probably also want to set the following options to `false` to
  4151. # disable the regular login/registration flows:
  4152. # * enable_registration
  4153. # * password_config.enabled
  4154. #
  4155. # You will also want to investigate the settings under the &quot;sso&quot; configuration
  4156. # section below.
  4157. # Enable SAML2 for registration and login. Uses pysaml2.
  4158. #
  4159. # At least one of `sp_config` or `config_path` must be set in this section to
  4160. # enable SAML login.
  4161. #
  4162. # Once SAML support is enabled, a metadata file will be exposed at
  4163. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/metadata.xml, which you may be able to
  4164. # use to configure your SAML IdP with. Alternatively, you can manually configure
  4165. # the IdP to use an ACS location of
  4166. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/authn_response.
  4167. #
  4168. saml2_config:
  4169. # `sp_config` is the configuration for the pysaml2 Service Provider.
  4170. # See pysaml2 docs for format of config.
  4171. #
  4172. # Default values will be used for the 'entityid' and 'service' settings,
  4173. # so it is not normally necessary to specify them unless you need to
  4174. # override them.
  4175. #
  4176. sp_config:
  4177. # Point this to the IdP's metadata. You must provide either a local
  4178. # file via the `local` attribute or (preferably) a URL via the
  4179. # `remote` attribute.
  4180. #
  4181. #metadata:
  4182. # local: [&quot;saml2/idp.xml&quot;]
  4183. # remote:
  4184. # - url: https://our_idp/metadata.xml
  4185. # Allowed clock difference in seconds between the homeserver and IdP.
  4186. #
  4187. # Uncomment the below to increase the accepted time difference from 0 to 3 seconds.
  4188. #
  4189. #accepted_time_diff: 3
  4190. # By default, the user has to go to our login page first. If you'd like
  4191. # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
  4192. # 'service.sp' section:
  4193. #
  4194. #service:
  4195. # sp:
  4196. # allow_unsolicited: true
  4197. # The examples below are just used to generate our metadata xml, and you
  4198. # may well not need them, depending on your setup. Alternatively you
  4199. # may need a whole lot more detail - see the pysaml2 docs!
  4200. #description: [&quot;My awesome SP&quot;, &quot;en&quot;]
  4201. #name: [&quot;Test SP&quot;, &quot;en&quot;]
  4202. #ui_info:
  4203. # display_name:
  4204. # - lang: en
  4205. # text: &quot;Display Name is the descriptive name of your service.&quot;
  4206. # description:
  4207. # - lang: en
  4208. # text: &quot;Description should be a short paragraph explaining the purpose of the service.&quot;
  4209. # information_url:
  4210. # - lang: en
  4211. # text: &quot;https://example.com/terms-of-service&quot;
  4212. # privacy_statement_url:
  4213. # - lang: en
  4214. # text: &quot;https://example.com/privacy-policy&quot;
  4215. # keywords:
  4216. # - lang: en
  4217. # text: [&quot;Matrix&quot;, &quot;Element&quot;]
  4218. # logo:
  4219. # - lang: en
  4220. # text: &quot;https://example.com/logo.svg&quot;
  4221. # width: &quot;200&quot;
  4222. # height: &quot;80&quot;
  4223. #organization:
  4224. # name: Example com
  4225. # display_name:
  4226. # - [&quot;Example co&quot;, &quot;en&quot;]
  4227. # url: &quot;http://example.com&quot;
  4228. #contact_person:
  4229. # - given_name: Bob
  4230. # sur_name: &quot;the Sysadmin&quot;
  4231. # email_address&quot;: [&quot;admin@example.com&quot;]
  4232. # contact_type&quot;: technical
  4233. # Instead of putting the config inline as above, you can specify a
  4234. # separate pysaml2 configuration file:
  4235. #
  4236. #config_path: &quot;CONFDIR/sp_conf.py&quot;
  4237. # The lifetime of a SAML session. This defines how long a user has to
  4238. # complete the authentication process, if allow_unsolicited is unset.
  4239. # The default is 15 minutes.
  4240. #
  4241. #saml_session_lifetime: 5m
  4242. # An external module can be provided here as a custom solution to
  4243. # mapping attributes returned from a saml provider onto a matrix user.
  4244. #
  4245. user_mapping_provider:
  4246. # The custom module's class. Uncomment to use a custom module.
  4247. #
  4248. #module: mapping_provider.SamlMappingProvider
  4249. # Custom configuration values for the module. Below options are
  4250. # intended for the built-in provider, they should be changed if
  4251. # using a custom module. This section will be passed as a Python
  4252. # dictionary to the module's `parse_config` method.
  4253. #
  4254. config:
  4255. # The SAML attribute (after mapping via the attribute maps) to use
  4256. # to derive the Matrix ID from. 'uid' by default.
  4257. #
  4258. # Note: This used to be configured by the
  4259. # saml2_config.mxid_source_attribute option. If that is still
  4260. # defined, its value will be used instead.
  4261. #
  4262. #mxid_source_attribute: displayName
  4263. # The mapping system to use for mapping the saml attribute onto a
  4264. # matrix ID.
  4265. #
  4266. # Options include:
  4267. # * 'hexencode' (which maps unpermitted characters to '=xx')
  4268. # * 'dotreplace' (which replaces unpermitted characters with
  4269. # '.').
  4270. # The default is 'hexencode'.
  4271. #
  4272. # Note: This used to be configured by the
  4273. # saml2_config.mxid_mapping option. If that is still defined, its
  4274. # value will be used instead.
  4275. #
  4276. #mxid_mapping: dotreplace
  4277. # In previous versions of synapse, the mapping from SAML attribute to
  4278. # MXID was always calculated dynamically rather than stored in a
  4279. # table. For backwards- compatibility, we will look for user_ids
  4280. # matching such a pattern before creating a new account.
  4281. #
  4282. # This setting controls the SAML attribute which will be used for this
  4283. # backwards-compatibility lookup. Typically it should be 'uid', but if
  4284. # the attribute maps are changed, it may be necessary to change it.
  4285. #
  4286. # The default is 'uid'.
  4287. #
  4288. #grandfathered_mxid_source_attribute: upn
  4289. # It is possible to configure Synapse to only allow logins if SAML attributes
  4290. # match particular values. The requirements can be listed under
  4291. # `attribute_requirements` as shown below. All of the listed attributes must
  4292. # match for the login to be permitted.
  4293. #
  4294. #attribute_requirements:
  4295. # - attribute: userGroup
  4296. # value: &quot;staff&quot;
  4297. # - attribute: department
  4298. # value: &quot;sales&quot;
  4299. # If the metadata XML contains multiple IdP entities then the `idp_entityid`
  4300. # option must be set to the entity to redirect users to.
  4301. #
  4302. # Most deployments only have a single IdP entity and so should omit this
  4303. # option.
  4304. #
  4305. #idp_entityid: 'https://our_idp/entityid'
  4306. # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration
  4307. # and login.
  4308. #
  4309. # Options for each entry include:
  4310. #
  4311. # idp_id: a unique identifier for this identity provider. Used internally
  4312. # by Synapse; should be a single word such as 'github'.
  4313. #
  4314. # Note that, if this is changed, users authenticating via that provider
  4315. # will no longer be recognised as the same user!
  4316. #
  4317. # (Use &quot;oidc&quot; here if you are migrating from an old &quot;oidc_config&quot;
  4318. # configuration.)
  4319. #
  4320. # idp_name: A user-facing name for this identity provider, which is used to
  4321. # offer the user a choice of login mechanisms.
  4322. #
  4323. # idp_icon: An optional icon for this identity provider, which is presented
  4324. # by clients and Synapse's own IdP picker page. If given, must be an
  4325. # MXC URI of the format mxc://&lt;server-name&gt;/&lt;media-id&gt;. (An easy way to
  4326. # obtain such an MXC URI is to upload an image to an (unencrypted) room
  4327. # and then copy the &quot;url&quot; from the source of the event.)
  4328. #
  4329. # idp_brand: An optional brand for this identity provider, allowing clients
  4330. # to style the login flow according to the identity provider in question.
  4331. # See the spec for possible options here.
  4332. #
  4333. # discover: set to 'false' to disable the use of the OIDC discovery mechanism
  4334. # to discover endpoints. Defaults to true.
  4335. #
  4336. # issuer: Required. The OIDC issuer. Used to validate tokens and (if discovery
  4337. # is enabled) to discover the provider's endpoints.
  4338. #
  4339. # client_id: Required. oauth2 client id to use.
  4340. #
  4341. # client_secret: oauth2 client secret to use. May be omitted if
  4342. # client_secret_jwt_key is given, or if client_auth_method is 'none'.
  4343. #
  4344. # client_secret_jwt_key: Alternative to client_secret: details of a key used
  4345. # to create a JSON Web Token to be used as an OAuth2 client secret. If
  4346. # given, must be a dictionary with the following properties:
  4347. #
  4348. # key: a pem-encoded signing key. Must be a suitable key for the
  4349. # algorithm specified. Required unless 'key_file' is given.
  4350. #
  4351. # key_file: the path to file containing a pem-encoded signing key file.
  4352. # Required unless 'key' is given.
  4353. #
  4354. # jwt_header: a dictionary giving properties to include in the JWT
  4355. # header. Must include the key 'alg', giving the algorithm used to
  4356. # sign the JWT, such as &quot;ES256&quot;, using the JWA identifiers in
  4357. # RFC7518.
  4358. #
  4359. # jwt_payload: an optional dictionary giving properties to include in
  4360. # the JWT payload. Normally this should include an 'iss' key.
  4361. #
  4362. # client_auth_method: auth method to use when exchanging the token. Valid
  4363. # values are 'client_secret_basic' (default), 'client_secret_post' and
  4364. # 'none'.
  4365. #
  4366. # scopes: list of scopes to request. This should normally include the &quot;openid&quot;
  4367. # scope. Defaults to [&quot;openid&quot;].
  4368. #
  4369. # authorization_endpoint: the oauth2 authorization endpoint. Required if
  4370. # provider discovery is disabled.
  4371. #
  4372. # token_endpoint: the oauth2 token endpoint. Required if provider discovery is
  4373. # disabled.
  4374. #
  4375. # userinfo_endpoint: the OIDC userinfo endpoint. Required if discovery is
  4376. # disabled and the 'openid' scope is not requested.
  4377. #
  4378. # jwks_uri: URI where to fetch the JWKS. Required if discovery is disabled and
  4379. # the 'openid' scope is used.
  4380. #
  4381. # skip_verification: set to 'true' to skip metadata verification. Use this if
  4382. # you are connecting to a provider that is not OpenID Connect compliant.
  4383. # Defaults to false. Avoid this in production.
  4384. #
  4385. # user_profile_method: Whether to fetch the user profile from the userinfo
  4386. # endpoint. Valid values are: 'auto' or 'userinfo_endpoint'.
  4387. #
  4388. # Defaults to 'auto', which fetches the userinfo endpoint if 'openid' is
  4389. # included in 'scopes'. Set to 'userinfo_endpoint' to always fetch the
  4390. # userinfo endpoint.
  4391. #
  4392. # allow_existing_users: set to 'true' to allow a user logging in via OIDC to
  4393. # match a pre-existing account instead of failing. This could be used if
  4394. # switching from password logins to OIDC. Defaults to false.
  4395. #
  4396. # user_mapping_provider: Configuration for how attributes returned from a OIDC
  4397. # provider are mapped onto a matrix user. This setting has the following
  4398. # sub-properties:
  4399. #
  4400. # module: The class name of a custom mapping module. Default is
  4401. # 'synapse.handlers.oidc.JinjaOidcMappingProvider'.
  4402. # See https://matrix-org.github.io/synapse/latest/sso_mapping_providers.html#openid-mapping-providers
  4403. # for information on implementing a custom mapping provider.
  4404. #
  4405. # config: Configuration for the mapping provider module. This section will
  4406. # be passed as a Python dictionary to the user mapping provider
  4407. # module's `parse_config` method.
  4408. #
  4409. # For the default provider, the following settings are available:
  4410. #
  4411. # subject_claim: name of the claim containing a unique identifier
  4412. # for the user. Defaults to 'sub', which OpenID Connect
  4413. # compliant providers should provide.
  4414. #
  4415. # localpart_template: Jinja2 template for the localpart of the MXID.
  4416. # If this is not set, the user will be prompted to choose their
  4417. # own username (see 'sso_auth_account_details.html' in the 'sso'
  4418. # section of this file).
  4419. #
  4420. # display_name_template: Jinja2 template for the display name to set
  4421. # on first login. If unset, no displayname will be set.
  4422. #
  4423. # email_template: Jinja2 template for the email address of the user.
  4424. # If unset, no email address will be added to the account.
  4425. #
  4426. # extra_attributes: a map of Jinja2 templates for extra attributes
  4427. # to send back to the client during login.
  4428. # Note that these are non-standard and clients will ignore them
  4429. # without modifications.
  4430. #
  4431. # When rendering, the Jinja2 templates are given a 'user' variable,
  4432. # which is set to the claims returned by the UserInfo Endpoint and/or
  4433. # in the ID Token.
  4434. #
  4435. # It is possible to configure Synapse to only allow logins if certain attributes
  4436. # match particular values in the OIDC userinfo. The requirements can be listed under
  4437. # `attribute_requirements` as shown below. All of the listed attributes must
  4438. # match for the login to be permitted. Additional attributes can be added to
  4439. # userinfo by expanding the `scopes` section of the OIDC config to retrieve
  4440. # additional information from the OIDC provider.
  4441. #
  4442. # If the OIDC claim is a list, then the attribute must match any value in the list.
  4443. # Otherwise, it must exactly match the value of the claim. Using the example
  4444. # below, the `family_name` claim MUST be &quot;Stephensson&quot;, but the `groups`
  4445. # claim MUST contain &quot;admin&quot;.
  4446. #
  4447. # attribute_requirements:
  4448. # - attribute: family_name
  4449. # value: &quot;Stephensson&quot;
  4450. # - attribute: groups
  4451. # value: &quot;admin&quot;
  4452. #
  4453. # See https://matrix-org.github.io/synapse/latest/openid.html
  4454. # for information on how to configure these options.
  4455. #
  4456. # For backwards compatibility, it is also possible to configure a single OIDC
  4457. # provider via an 'oidc_config' setting. This is now deprecated and admins are
  4458. # advised to migrate to the 'oidc_providers' format. (When doing that migration,
  4459. # use 'oidc' for the idp_id to ensure that existing users continue to be
  4460. # recognised.)
  4461. #
  4462. oidc_providers:
  4463. # Generic example
  4464. #
  4465. #- idp_id: my_idp
  4466. # idp_name: &quot;My OpenID provider&quot;
  4467. # idp_icon: &quot;mxc://example.com/mediaid&quot;
  4468. # discover: false
  4469. # issuer: &quot;https://accounts.example.com/&quot;
  4470. # client_id: &quot;provided-by-your-issuer&quot;
  4471. # client_secret: &quot;provided-by-your-issuer&quot;
  4472. # client_auth_method: client_secret_post
  4473. # scopes: [&quot;openid&quot;, &quot;profile&quot;]
  4474. # authorization_endpoint: &quot;https://accounts.example.com/oauth2/auth&quot;
  4475. # token_endpoint: &quot;https://accounts.example.com/oauth2/token&quot;
  4476. # userinfo_endpoint: &quot;https://accounts.example.com/userinfo&quot;
  4477. # jwks_uri: &quot;https://accounts.example.com/.well-known/jwks.json&quot;
  4478. # skip_verification: true
  4479. # user_mapping_provider:
  4480. # config:
  4481. # subject_claim: &quot;id&quot;
  4482. # localpart_template: &quot;{{ user.login }}&quot;
  4483. # display_name_template: &quot;{{ user.name }}&quot;
  4484. # email_template: &quot;{{ user.email }}&quot;
  4485. # attribute_requirements:
  4486. # - attribute: userGroup
  4487. # value: &quot;synapseUsers&quot;
  4488. # Enable Central Authentication Service (CAS) for registration and login.
  4489. #
  4490. cas_config:
  4491. # Uncomment the following to enable authorization against a CAS server.
  4492. # Defaults to false.
  4493. #
  4494. #enabled: true
  4495. # The URL of the CAS authorization endpoint.
  4496. #
  4497. #server_url: &quot;https://cas-server.com&quot;
  4498. # The attribute of the CAS response to use as the display name.
  4499. #
  4500. # If unset, no displayname will be set.
  4501. #
  4502. #displayname_attribute: name
  4503. # It is possible to configure Synapse to only allow logins if CAS attributes
  4504. # match particular values. All of the keys in the mapping below must exist
  4505. # and the values must match the given value. Alternately if the given value
  4506. # is None then any value is allowed (the attribute just must exist).
  4507. # All of the listed attributes must match for the login to be permitted.
  4508. #
  4509. #required_attributes:
  4510. # userGroup: &quot;staff&quot;
  4511. # department: None
  4512. # Additional settings to use with single-sign on systems such as OpenID Connect,
  4513. # SAML2 and CAS.
  4514. #
  4515. sso:
  4516. # A list of client URLs which are whitelisted so that the user does not
  4517. # have to confirm giving access to their account to the URL. Any client
  4518. # whose URL starts with an entry in the following list will not be subject
  4519. # to an additional confirmation step after the SSO login is completed.
  4520. #
  4521. # WARNING: An entry such as &quot;https://my.client&quot; is insecure, because it
  4522. # will also match &quot;https://my.client.evil.site&quot;, exposing your users to
  4523. # phishing attacks from evil.site. To avoid this, include a slash after the
  4524. # hostname: &quot;https://my.client/&quot;.
  4525. #
  4526. # If public_baseurl is set, then the login fallback page (used by clients
  4527. # that don't natively support the required login flows) is whitelisted in
  4528. # addition to any URLs in this list.
  4529. #
  4530. # By default, this list is empty.
  4531. #
  4532. #client_whitelist:
  4533. # - https://riot.im/develop
  4534. # - https://my.custom.client/
  4535. # Uncomment to keep a user's profile fields in sync with information from
  4536. # the identity provider. Currently only syncing the displayname is
  4537. # supported. Fields are checked on every SSO login, and are updated
  4538. # if necessary.
  4539. #
  4540. # Note that enabling this option will override user profile information,
  4541. # regardless of whether users have opted-out of syncing that
  4542. # information when first signing in. Defaults to false.
  4543. #
  4544. #update_profile_information: true
  4545. # Directory in which Synapse will try to find the template files below.
  4546. # If not set, or the files named below are not found within the template
  4547. # directory, default templates from within the Synapse package will be used.
  4548. #
  4549. # Synapse will look for the following templates in this directory:
  4550. #
  4551. # * HTML page to prompt the user to choose an Identity Provider during
  4552. # login: 'sso_login_idp_picker.html'.
  4553. #
  4554. # This is only used if multiple SSO Identity Providers are configured.
  4555. #
  4556. # When rendering, this template is given the following variables:
  4557. # * redirect_url: the URL that the user will be redirected to after
  4558. # login.
  4559. #
  4560. # * server_name: the homeserver's name.
  4561. #
  4562. # * providers: a list of available Identity Providers. Each element is
  4563. # an object with the following attributes:
  4564. #
  4565. # * idp_id: unique identifier for the IdP
  4566. # * idp_name: user-facing name for the IdP
  4567. # * idp_icon: if specified in the IdP config, an MXC URI for an icon
  4568. # for the IdP
  4569. # * idp_brand: if specified in the IdP config, a textual identifier
  4570. # for the brand of the IdP
  4571. #
  4572. # The rendered HTML page should contain a form which submits its results
  4573. # back as a GET request, with the following query parameters:
  4574. #
  4575. # * redirectUrl: the client redirect URI (ie, the `redirect_url` passed
  4576. # to the template)
  4577. #
  4578. # * idp: the 'idp_id' of the chosen IDP.
  4579. #
  4580. # * HTML page to prompt new users to enter a userid and confirm other
  4581. # details: 'sso_auth_account_details.html'. This is only shown if the
  4582. # SSO implementation (with any user_mapping_provider) does not return
  4583. # a localpart.
  4584. #
  4585. # When rendering, this template is given the following variables:
  4586. #
  4587. # * server_name: the homeserver's name.
  4588. #
  4589. # * idp: details of the SSO Identity Provider that the user logged in
  4590. # with: an object with the following attributes:
  4591. #
  4592. # * idp_id: unique identifier for the IdP
  4593. # * idp_name: user-facing name for the IdP
  4594. # * idp_icon: if specified in the IdP config, an MXC URI for an icon
  4595. # for the IdP
  4596. # * idp_brand: if specified in the IdP config, a textual identifier
  4597. # for the brand of the IdP
  4598. #
  4599. # * user_attributes: an object containing details about the user that
  4600. # we received from the IdP. May have the following attributes:
  4601. #
  4602. # * display_name: the user's display_name
  4603. # * emails: a list of email addresses
  4604. #
  4605. # The template should render a form which submits the following fields:
  4606. #
  4607. # * username: the localpart of the user's chosen user id
  4608. #
  4609. # * HTML page allowing the user to consent to the server's terms and
  4610. # conditions. This is only shown for new users, and only if
  4611. # `user_consent.require_at_registration` is set.
  4612. #
  4613. # When rendering, this template is given the following variables:
  4614. #
  4615. # * server_name: the homeserver's name.
  4616. #
  4617. # * user_id: the user's matrix proposed ID.
  4618. #
  4619. # * user_profile.display_name: the user's proposed display name, if any.
  4620. #
  4621. # * consent_version: the version of the terms that the user will be
  4622. # shown
  4623. #
  4624. # * terms_url: a link to the page showing the terms.
  4625. #
  4626. # The template should render a form which submits the following fields:
  4627. #
  4628. # * accepted_version: the version of the terms accepted by the user
  4629. # (ie, 'consent_version' from the input variables).
  4630. #
  4631. # * HTML page for a confirmation step before redirecting back to the client
  4632. # with the login token: 'sso_redirect_confirm.html'.
  4633. #
  4634. # When rendering, this template is given the following variables:
  4635. #
  4636. # * redirect_url: the URL the user is about to be redirected to.
  4637. #
  4638. # * display_url: the same as `redirect_url`, but with the query
  4639. # parameters stripped. The intention is to have a
  4640. # human-readable URL to show to users, not to use it as
  4641. # the final address to redirect to.
  4642. #
  4643. # * server_name: the homeserver's name.
  4644. #
  4645. # * new_user: a boolean indicating whether this is the user's first time
  4646. # logging in.
  4647. #
  4648. # * user_id: the user's matrix ID.
  4649. #
  4650. # * user_profile.avatar_url: an MXC URI for the user's avatar, if any.
  4651. # None if the user has not set an avatar.
  4652. #
  4653. # * user_profile.display_name: the user's display name. None if the user
  4654. # has not set a display name.
  4655. #
  4656. # * HTML page which notifies the user that they are authenticating to confirm
  4657. # an operation on their account during the user interactive authentication
  4658. # process: 'sso_auth_confirm.html'.
  4659. #
  4660. # When rendering, this template is given the following variables:
  4661. # * redirect_url: the URL the user is about to be redirected to.
  4662. #
  4663. # * description: the operation which the user is being asked to confirm
  4664. #
  4665. # * idp: details of the Identity Provider that we will use to confirm
  4666. # the user's identity: an object with the following attributes:
  4667. #
  4668. # * idp_id: unique identifier for the IdP
  4669. # * idp_name: user-facing name for the IdP
  4670. # * idp_icon: if specified in the IdP config, an MXC URI for an icon
  4671. # for the IdP
  4672. # * idp_brand: if specified in the IdP config, a textual identifier
  4673. # for the brand of the IdP
  4674. #
  4675. # * HTML page shown after a successful user interactive authentication session:
  4676. # 'sso_auth_success.html'.
  4677. #
  4678. # Note that this page must include the JavaScript which notifies of a successful authentication
  4679. # (see https://matrix.org/docs/spec/client_server/r0.6.0#fallback).
  4680. #
  4681. # This template has no additional variables.
  4682. #
  4683. # * HTML page shown after a user-interactive authentication session which
  4684. # does not map correctly onto the expected user: 'sso_auth_bad_user.html'.
  4685. #
  4686. # When rendering, this template is given the following variables:
  4687. # * server_name: the homeserver's name.
  4688. # * user_id_to_verify: the MXID of the user that we are trying to
  4689. # validate.
  4690. #
  4691. # * HTML page shown during single sign-on if a deactivated user (according to Synapse's database)
  4692. # attempts to login: 'sso_account_deactivated.html'.
  4693. #
  4694. # This template has no additional variables.
  4695. #
  4696. # * HTML page to display to users if something goes wrong during the
  4697. # OpenID Connect authentication process: 'sso_error.html'.
  4698. #
  4699. # When rendering, this template is given two variables:
  4700. # * error: the technical name of the error
  4701. # * error_description: a human-readable message for the error
  4702. #
  4703. # You can see the default templates at:
  4704. # https://github.com/matrix-org/synapse/tree/master/synapse/res/templates
  4705. #
  4706. #template_dir: &quot;res/templates&quot;
  4707. # JSON web token integration. The following settings can be used to make
  4708. # Synapse JSON web tokens for authentication, instead of its internal
  4709. # password database.
  4710. #
  4711. # Each JSON Web Token needs to contain a &quot;sub&quot; (subject) claim, which is
  4712. # used as the localpart of the mxid.
  4713. #
  4714. # Additionally, the expiration time (&quot;exp&quot;), not before time (&quot;nbf&quot;),
  4715. # and issued at (&quot;iat&quot;) claims are validated if present.
  4716. #
  4717. # Note that this is a non-standard login type and client support is
  4718. # expected to be non-existent.
  4719. #
  4720. # See https://matrix-org.github.io/synapse/latest/jwt.html.
  4721. #
  4722. #jwt_config:
  4723. # Uncomment the following to enable authorization using JSON web
  4724. # tokens. Defaults to false.
  4725. #
  4726. #enabled: true
  4727. # This is either the private shared secret or the public key used to
  4728. # decode the contents of the JSON web token.
  4729. #
  4730. # Required if 'enabled' is true.
  4731. #
  4732. #secret: &quot;provided-by-your-issuer&quot;
  4733. # The algorithm used to sign the JSON web token.
  4734. #
  4735. # Supported algorithms are listed at
  4736. # https://pyjwt.readthedocs.io/en/latest/algorithms.html
  4737. #
  4738. # Required if 'enabled' is true.
  4739. #
  4740. #algorithm: &quot;provided-by-your-issuer&quot;
  4741. # The issuer to validate the &quot;iss&quot; claim against.
  4742. #
  4743. # Optional, if provided the &quot;iss&quot; claim will be required and
  4744. # validated for all JSON web tokens.
  4745. #
  4746. #issuer: &quot;provided-by-your-issuer&quot;
  4747. # A list of audiences to validate the &quot;aud&quot; claim against.
  4748. #
  4749. # Optional, if provided the &quot;aud&quot; claim will be required and
  4750. # validated for all JSON web tokens.
  4751. #
  4752. # Note that if the &quot;aud&quot; claim is included in a JSON web token then
  4753. # validation will fail without configuring audiences.
  4754. #
  4755. #audiences:
  4756. # - &quot;provided-by-your-issuer&quot;
  4757. password_config:
  4758. # Uncomment to disable password login
  4759. #
  4760. #enabled: false
  4761. # Uncomment to disable authentication against the local password
  4762. # database. This is ignored if `enabled` is false, and is only useful
  4763. # if you have other password_providers.
  4764. #
  4765. #localdb_enabled: false
  4766. # Uncomment and change to a secret random string for extra security.
  4767. # DO NOT CHANGE THIS AFTER INITIAL SETUP!
  4768. #
  4769. #pepper: &quot;EVEN_MORE_SECRET&quot;
  4770. # Define and enforce a password policy. Each parameter is optional.
  4771. # This is an implementation of MSC2000.
  4772. #
  4773. policy:
  4774. # Whether to enforce the password policy.
  4775. # Defaults to 'false'.
  4776. #
  4777. #enabled: true
  4778. # Minimum accepted length for a password.
  4779. # Defaults to 0.
  4780. #
  4781. #minimum_length: 15
  4782. # Whether a password must contain at least one digit.
  4783. # Defaults to 'false'.
  4784. #
  4785. #require_digit: true
  4786. # Whether a password must contain at least one symbol.
  4787. # A symbol is any character that's not a number or a letter.
  4788. # Defaults to 'false'.
  4789. #
  4790. #require_symbol: true
  4791. # Whether a password must contain at least one lowercase letter.
  4792. # Defaults to 'false'.
  4793. #
  4794. #require_lowercase: true
  4795. # Whether a password must contain at least one lowercase letter.
  4796. # Defaults to 'false'.
  4797. #
  4798. #require_uppercase: true
  4799. ui_auth:
  4800. # The amount of time to allow a user-interactive authentication session
  4801. # to be active.
  4802. #
  4803. # This defaults to 0, meaning the user is queried for their credentials
  4804. # before every action, but this can be overridden to allow a single
  4805. # validation to be re-used. This weakens the protections afforded by
  4806. # the user-interactive authentication process, by allowing for multiple
  4807. # (and potentially different) operations to use the same validation session.
  4808. #
  4809. # This is ignored for potentially &quot;dangerous&quot; operations (including
  4810. # deactivating an account, modifying an account password, and
  4811. # adding a 3PID).
  4812. #
  4813. # Uncomment below to allow for credential validation to last for 15
  4814. # seconds.
  4815. #
  4816. #session_timeout: &quot;15s&quot;
  4817. # Configuration for sending emails from Synapse.
  4818. #
  4819. email:
  4820. # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'.
  4821. #
  4822. #smtp_host: mail.server
  4823. # The port on the mail server for outgoing SMTP. Defaults to 25.
  4824. #
  4825. #smtp_port: 587
  4826. # Username/password for authentication to the SMTP server. By default, no
  4827. # authentication is attempted.
  4828. #
  4829. #smtp_user: &quot;exampleusername&quot;
  4830. #smtp_pass: &quot;examplepassword&quot;
  4831. # Uncomment the following to require TLS transport security for SMTP.
  4832. # By default, Synapse will connect over plain text, and will then switch to
  4833. # TLS via STARTTLS *if the SMTP server supports it*. If this option is set,
  4834. # Synapse will refuse to connect unless the server supports STARTTLS.
  4835. #
  4836. #require_transport_security: true
  4837. # notif_from defines the &quot;From&quot; address to use when sending emails.
  4838. # It must be set if email sending is enabled.
  4839. #
  4840. # The placeholder '%(app)s' will be replaced by the application name,
  4841. # which is normally 'app_name' (below), but may be overridden by the
  4842. # Matrix client application.
  4843. #
  4844. # Note that the placeholder must be written '%(app)s', including the
  4845. # trailing 's'.
  4846. #
  4847. #notif_from: &quot;Your Friendly %(app)s homeserver &lt;noreply@example.com&gt;&quot;
  4848. # app_name defines the default value for '%(app)s' in notif_from and email
  4849. # subjects. It defaults to 'Matrix'.
  4850. #
  4851. #app_name: my_branded_matrix_server
  4852. # Uncomment the following to enable sending emails for messages that the user
  4853. # has missed. Disabled by default.
  4854. #
  4855. #enable_notifs: true
  4856. # Uncomment the following to disable automatic subscription to email
  4857. # notifications for new users. Enabled by default.
  4858. #
  4859. #notif_for_new_users: false
  4860. # Custom URL for client links within the email notifications. By default
  4861. # links will be based on &quot;https://matrix.to&quot;.
  4862. #
  4863. # (This setting used to be called riot_base_url; the old name is still
  4864. # supported for backwards-compatibility but is now deprecated.)
  4865. #
  4866. #client_base_url: &quot;http://localhost/riot&quot;
  4867. # Configure the time that a validation email will expire after sending.
  4868. # Defaults to 1h.
  4869. #
  4870. #validation_token_lifetime: 15m
  4871. # The web client location to direct users to during an invite. This is passed
  4872. # to the identity server as the org.matrix.web_client_location key. Defaults
  4873. # to unset, giving no guidance to the identity server.
  4874. #
  4875. #invite_client_location: https://app.element.io
  4876. # Directory in which Synapse will try to find the template files below.
  4877. # If not set, or the files named below are not found within the template
  4878. # directory, default templates from within the Synapse package will be used.
  4879. #
  4880. # Synapse will look for the following templates in this directory:
  4881. #
  4882. # * The contents of email notifications of missed events: 'notif_mail.html' and
  4883. # 'notif_mail.txt'.
  4884. #
  4885. # * The contents of account expiry notice emails: 'notice_expiry.html' and
  4886. # 'notice_expiry.txt'.
  4887. #
  4888. # * The contents of password reset emails sent by the homeserver:
  4889. # 'password_reset.html' and 'password_reset.txt'
  4890. #
  4891. # * An HTML page that a user will see when they follow the link in the password
  4892. # reset email. The user will be asked to confirm the action before their
  4893. # password is reset: 'password_reset_confirmation.html'
  4894. #
  4895. # * HTML pages for success and failure that a user will see when they confirm
  4896. # the password reset flow using the page above: 'password_reset_success.html'
  4897. # and 'password_reset_failure.html'
  4898. #
  4899. # * The contents of address verification emails sent during registration:
  4900. # 'registration.html' and 'registration.txt'
  4901. #
  4902. # * HTML pages for success and failure that a user will see when they follow
  4903. # the link in an address verification email sent during registration:
  4904. # 'registration_success.html' and 'registration_failure.html'
  4905. #
  4906. # * The contents of address verification emails sent when an address is added
  4907. # to a Matrix account: 'add_threepid.html' and 'add_threepid.txt'
  4908. #
  4909. # * HTML pages for success and failure that a user will see when they follow
  4910. # the link in an address verification email sent when an address is added
  4911. # to a Matrix account: 'add_threepid_success.html' and
  4912. # 'add_threepid_failure.html'
  4913. #
  4914. # You can see the default templates at:
  4915. # https://github.com/matrix-org/synapse/tree/master/synapse/res/templates
  4916. #
  4917. #template_dir: &quot;res/templates&quot;
  4918. # Subjects to use when sending emails from Synapse.
  4919. #
  4920. # The placeholder '%(app)s' will be replaced with the value of the 'app_name'
  4921. # setting above, or by a value dictated by the Matrix client application.
  4922. #
  4923. # If a subject isn't overridden in this configuration file, the value used as
  4924. # its example will be used.
  4925. #
  4926. #subjects:
  4927. # Subjects for notification emails.
  4928. #
  4929. # On top of the '%(app)s' placeholder, these can use the following
  4930. # placeholders:
  4931. #
  4932. # * '%(person)s', which will be replaced by the display name of the user(s)
  4933. # that sent the message(s), e.g. &quot;Alice and Bob&quot;.
  4934. # * '%(room)s', which will be replaced by the name of the room the
  4935. # message(s) have been sent to, e.g. &quot;My super room&quot;.
  4936. #
  4937. # See the example provided for each setting to see which placeholder can be
  4938. # used and how to use them.
  4939. #
  4940. # Subject to use to notify about one message from one or more user(s) in a
  4941. # room which has a name.
  4942. #message_from_person_in_room: &quot;[%(app)s] You have a message on %(app)s from %(person)s in the %(room)s room...&quot;
  4943. #
  4944. # Subject to use to notify about one message from one or more user(s) in a
  4945. # room which doesn't have a name.
  4946. #message_from_person: &quot;[%(app)s] You have a message on %(app)s from %(person)s...&quot;
  4947. #
  4948. # Subject to use to notify about multiple messages from one or more users in
  4949. # a room which doesn't have a name.
  4950. #messages_from_person: &quot;[%(app)s] You have messages on %(app)s from %(person)s...&quot;
  4951. #
  4952. # Subject to use to notify about multiple messages in a room which has a
  4953. # name.
  4954. #messages_in_room: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room...&quot;
  4955. #
  4956. # Subject to use to notify about multiple messages in multiple rooms.
  4957. #messages_in_room_and_others: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room and others...&quot;
  4958. #
  4959. # Subject to use to notify about multiple messages from multiple persons in
  4960. # multiple rooms. This is similar to the setting above except it's used when
  4961. # the room in which the notification was triggered has no name.
  4962. #messages_from_person_and_others: &quot;[%(app)s] You have messages on %(app)s from %(person)s and others...&quot;
  4963. #
  4964. # Subject to use to notify about an invite to a room which has a name.
  4965. #invite_from_person_to_room: &quot;[%(app)s] %(person)s has invited you to join the %(room)s room on %(app)s...&quot;
  4966. #
  4967. # Subject to use to notify about an invite to a room which doesn't have a
  4968. # name.
  4969. #invite_from_person: &quot;[%(app)s] %(person)s has invited you to chat on %(app)s...&quot;
  4970. # Subject for emails related to account administration.
  4971. #
  4972. # On top of the '%(app)s' placeholder, these one can use the
  4973. # '%(server_name)s' placeholder, which will be replaced by the value of the
  4974. # 'server_name' setting in your Synapse configuration.
  4975. #
  4976. # Subject to use when sending a password reset email.
  4977. #password_reset: &quot;[%(server_name)s] Password reset&quot;
  4978. #
  4979. # Subject to use when sending a verification email to assert an address's
  4980. # ownership.
  4981. #email_validation: &quot;[%(server_name)s] Validate your email&quot;
  4982. # Password providers allow homeserver administrators to integrate
  4983. # their Synapse installation with existing authentication methods
  4984. # ex. LDAP, external tokens, etc.
  4985. #
  4986. # For more information and known implementations, please see
  4987. # https://matrix-org.github.io/synapse/latest/password_auth_providers.html
  4988. #
  4989. # Note: instances wishing to use SAML or CAS authentication should
  4990. # instead use the `saml2_config` or `cas_config` options,
  4991. # respectively.
  4992. #
  4993. password_providers:
  4994. # # Example config for an LDAP auth provider
  4995. # - module: &quot;ldap_auth_provider.LdapAuthProvider&quot;
  4996. # config:
  4997. # enabled: true
  4998. # uri: &quot;ldap://ldap.example.com:389&quot;
  4999. # start_tls: true
  5000. # base: &quot;ou=users,dc=example,dc=com&quot;
  5001. # attributes:
  5002. # uid: &quot;cn&quot;
  5003. # mail: &quot;email&quot;
  5004. # name: &quot;givenName&quot;
  5005. # #bind_dn:
  5006. # #bind_password:
  5007. # #filter: &quot;(objectClass=posixAccount)&quot;
  5008. ## Push ##
  5009. push:
  5010. # Clients requesting push notifications can either have the body of
  5011. # the message sent in the notification poke along with other details
  5012. # like the sender, or just the event ID and room ID (`event_id_only`).
  5013. # If clients choose the former, this option controls whether the
  5014. # notification request includes the content of the event (other details
  5015. # like the sender are still included). For `event_id_only` push, it
  5016. # has no effect.
  5017. #
  5018. # For modern android devices the notification content will still appear
  5019. # because it is loaded by the app. iPhone, however will send a
  5020. # notification saying only that a message arrived and who it came from.
  5021. #
  5022. # The default value is &quot;true&quot; to include message details. Uncomment to only
  5023. # include the event ID and room ID in push notification payloads.
  5024. #
  5025. #include_content: false
  5026. # When a push notification is received, an unread count is also sent.
  5027. # This number can either be calculated as the number of unread messages
  5028. # for the user, or the number of *rooms* the user has unread messages in.
  5029. #
  5030. # The default value is &quot;true&quot;, meaning push clients will see the number of
  5031. # rooms with unread messages in them. Uncomment to instead send the number
  5032. # of unread messages.
  5033. #
  5034. #group_unread_count_by_room: false
  5035. ## Rooms ##
  5036. # Controls whether locally-created rooms should be end-to-end encrypted by
  5037. # default.
  5038. #
  5039. # Possible options are &quot;all&quot;, &quot;invite&quot;, and &quot;off&quot;. They are defined as:
  5040. #
  5041. # * &quot;all&quot;: any locally-created room
  5042. # * &quot;invite&quot;: any room created with the &quot;private_chat&quot; or &quot;trusted_private_chat&quot;
  5043. # room creation presets
  5044. # * &quot;off&quot;: this option will take no effect
  5045. #
  5046. # The default value is &quot;off&quot;.
  5047. #
  5048. # Note that this option will only affect rooms created after it is set. It
  5049. # will also not affect rooms created by other servers.
  5050. #
  5051. #encryption_enabled_by_default_for_room_type: invite
  5052. # Uncomment to allow non-server-admin users to create groups on this server
  5053. #
  5054. #enable_group_creation: true
  5055. # If enabled, non server admins can only create groups with local parts
  5056. # starting with this prefix
  5057. #
  5058. #group_creation_prefix: &quot;unofficial_&quot;
  5059. # User Directory configuration
  5060. #
  5061. user_directory:
  5062. # Defines whether users can search the user directory. If false then
  5063. # empty responses are returned to all queries. Defaults to true.
  5064. #
  5065. # Uncomment to disable the user directory.
  5066. #
  5067. #enabled: false
  5068. # Defines whether to search all users visible to your HS when searching
  5069. # the user directory, rather than limiting to users visible in public
  5070. # rooms. Defaults to false.
  5071. #
  5072. # If you set it true, you'll have to rebuild the user_directory search
  5073. # indexes, see:
  5074. # https://matrix-org.github.io/synapse/latest/user_directory.html
  5075. #
  5076. # Uncomment to return search results containing all known users, even if that
  5077. # user does not share a room with the requester.
  5078. #
  5079. #search_all_users: true
  5080. # Defines whether to prefer local users in search query results.
  5081. # If True, local users are more likely to appear above remote users
  5082. # when searching the user directory. Defaults to false.
  5083. #
  5084. # Uncomment to prefer local over remote users in user directory search
  5085. # results.
  5086. #
  5087. #prefer_local_users: true
  5088. # User Consent configuration
  5089. #
  5090. # for detailed instructions, see
  5091. # https://matrix-org.github.io/synapse/latest/consent_tracking.html
  5092. #
  5093. # Parts of this section are required if enabling the 'consent' resource under
  5094. # 'listeners', in particular 'template_dir' and 'version'.
  5095. #
  5096. # 'template_dir' gives the location of the templates for the HTML forms.
  5097. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  5098. # and each language directory should contain the policy document (named as
  5099. # '&lt;version&gt;.html') and a success page (success.html).
  5100. #
  5101. # 'version' specifies the 'current' version of the policy document. It defines
  5102. # the version to be served by the consent resource if there is no 'v'
  5103. # parameter.
  5104. #
  5105. # 'server_notice_content', if enabled, will send a user a &quot;Server Notice&quot;
  5106. # asking them to consent to the privacy policy. The 'server_notices' section
  5107. # must also be configured for this to work. Notices will *not* be sent to
  5108. # guest users unless 'send_server_notice_to_guests' is set to true.
  5109. #
  5110. # 'block_events_error', if set, will block any attempts to send events
  5111. # until the user consents to the privacy policy. The value of the setting is
  5112. # used as the text of the error.
  5113. #
  5114. # 'require_at_registration', if enabled, will add a step to the registration
  5115. # process, similar to how captcha works. Users will be required to accept the
  5116. # policy before their account is created.
  5117. #
  5118. # 'policy_name' is the display name of the policy users will see when registering
  5119. # for an account. Has no effect unless `require_at_registration` is enabled.
  5120. # Defaults to &quot;Privacy Policy&quot;.
  5121. #
  5122. #user_consent:
  5123. # template_dir: res/templates/privacy
  5124. # version: 1.0
  5125. # server_notice_content:
  5126. # msgtype: m.text
  5127. # body: &gt;-
  5128. # To continue using this homeserver you must review and agree to the
  5129. # terms and conditions at %(consent_uri)s
  5130. # send_server_notice_to_guests: true
  5131. # block_events_error: &gt;-
  5132. # To continue using this homeserver you must review and agree to the
  5133. # terms and conditions at %(consent_uri)s
  5134. # require_at_registration: false
  5135. # policy_name: Privacy Policy
  5136. #
  5137. # Settings for local room and user statistics collection. See
  5138. # https://matrix-org.github.io/synapse/latest/room_and_user_statistics.html.
  5139. #
  5140. stats:
  5141. # Uncomment the following to disable room and user statistics. Note that doing
  5142. # so may cause certain features (such as the room directory) not to work
  5143. # correctly.
  5144. #
  5145. #enabled: false
  5146. # The size of each timeslice in the room_stats_historical and
  5147. # user_stats_historical tables, as a time period. Defaults to &quot;1d&quot;.
  5148. #
  5149. #bucket_size: 1h
  5150. # Server Notices room configuration
  5151. #
  5152. # Uncomment this section to enable a room which can be used to send notices
  5153. # from the server to users. It is a special room which cannot be left; notices
  5154. # come from a special &quot;notices&quot; user id.
  5155. #
  5156. # If you uncomment this section, you *must* define the system_mxid_localpart
  5157. # setting, which defines the id of the user which will be used to send the
  5158. # notices.
  5159. #
  5160. # It's also possible to override the room name, the display name of the
  5161. # &quot;notices&quot; user, and the avatar for the user.
  5162. #
  5163. #server_notices:
  5164. # system_mxid_localpart: notices
  5165. # system_mxid_display_name: &quot;Server Notices&quot;
  5166. # system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  5167. # room_name: &quot;Server Notices&quot;
  5168. # Uncomment to disable searching the public room list. When disabled
  5169. # blocks searching local and remote room lists for local and remote
  5170. # users by always returning an empty list for all queries.
  5171. #
  5172. #enable_room_list_search: false
  5173. # The `alias_creation` option controls who's allowed to create aliases
  5174. # on this server.
  5175. #
  5176. # The format of this option is a list of rules that contain globs that
  5177. # match against user_id, room_id and the new alias (fully qualified with
  5178. # server name). The action in the first rule that matches is taken,
  5179. # which can currently either be &quot;allow&quot; or &quot;deny&quot;.
  5180. #
  5181. # Missing user_id/room_id/alias fields default to &quot;*&quot;.
  5182. #
  5183. # If no rules match the request is denied. An empty list means no one
  5184. # can create aliases.
  5185. #
  5186. # Options for the rules include:
  5187. #
  5188. # user_id: Matches against the creator of the alias
  5189. # alias: Matches against the alias being created
  5190. # room_id: Matches against the room ID the alias is being pointed at
  5191. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5192. #
  5193. # The default is:
  5194. #
  5195. #alias_creation_rules:
  5196. # - user_id: &quot;*&quot;
  5197. # alias: &quot;*&quot;
  5198. # room_id: &quot;*&quot;
  5199. # action: allow
  5200. # The `room_list_publication_rules` option controls who can publish and
  5201. # which rooms can be published in the public room list.
  5202. #
  5203. # The format of this option is the same as that for
  5204. # `alias_creation_rules`.
  5205. #
  5206. # If the room has one or more aliases associated with it, only one of
  5207. # the aliases needs to match the alias rule. If there are no aliases
  5208. # then only rules with `alias: *` match.
  5209. #
  5210. # If no rules match the request is denied. An empty list means no one
  5211. # can publish rooms.
  5212. #
  5213. # Options for the rules include:
  5214. #
  5215. # user_id: Matches against the creator of the alias
  5216. # room_id: Matches against the room ID being published
  5217. # alias: Matches against any current local or canonical aliases
  5218. # associated with the room
  5219. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5220. #
  5221. # The default is:
  5222. #
  5223. #room_list_publication_rules:
  5224. # - user_id: &quot;*&quot;
  5225. # alias: &quot;*&quot;
  5226. # room_id: &quot;*&quot;
  5227. # action: allow
  5228. # Server admins can define a Python module that implements extra rules for
  5229. # allowing or denying incoming events. In order to work, this module needs to
  5230. # override the methods defined in synapse/events/third_party_rules.py.
  5231. #
  5232. # This feature is designed to be used in closed federations only, where each
  5233. # participating server enforces the same rules.
  5234. #
  5235. #third_party_event_rules:
  5236. # module: &quot;my_custom_project.SuperRulesSet&quot;
  5237. # config:
  5238. # example_option: 'things'
  5239. ## Opentracing ##
  5240. # These settings enable opentracing, which implements distributed tracing.
  5241. # This allows you to observe the causal chains of events across servers
  5242. # including requests, key lookups etc., across any server running
  5243. # synapse or any other other services which supports opentracing
  5244. # (specifically those implemented with Jaeger).
  5245. #
  5246. opentracing:
  5247. # tracing is disabled by default. Uncomment the following line to enable it.
  5248. #
  5249. #enabled: true
  5250. # The list of homeservers we wish to send and receive span contexts and span baggage.
  5251. # See https://matrix-org.github.io/synapse/latest/opentracing.html.
  5252. #
  5253. # This is a list of regexes which are matched against the server_name of the
  5254. # homeserver.
  5255. #
  5256. # By default, it is empty, so no servers are matched.
  5257. #
  5258. #homeserver_whitelist:
  5259. # - &quot;.*&quot;
  5260. # A list of the matrix IDs of users whose requests will always be traced,
  5261. # even if the tracing system would otherwise drop the traces due to
  5262. # probabilistic sampling.
  5263. #
  5264. # By default, the list is empty.
  5265. #
  5266. #force_tracing_for_users:
  5267. # - &quot;@user1:server_name&quot;
  5268. # - &quot;@user2:server_name&quot;
  5269. # Jaeger can be configured to sample traces at different rates.
  5270. # All configuration options provided by Jaeger can be set here.
  5271. # Jaeger's configuration is mostly related to trace sampling which
  5272. # is documented here:
  5273. # https://www.jaegertracing.io/docs/latest/sampling/.
  5274. #
  5275. #jaeger_config:
  5276. # sampler:
  5277. # type: const
  5278. # param: 1
  5279. # logging:
  5280. # false
  5281. ## Workers ##
  5282. # Disables sending of outbound federation transactions on the main process.
  5283. # Uncomment if using a federation sender worker.
  5284. #
  5285. #send_federation: false
  5286. # It is possible to run multiple federation sender workers, in which case the
  5287. # work is balanced across them.
  5288. #
  5289. # This configuration must be shared between all federation sender workers, and if
  5290. # changed all federation sender workers must be stopped at the same time and then
  5291. # started, to ensure that all instances are running with the same config (otherwise
  5292. # events may be dropped).
  5293. #
  5294. #federation_sender_instances:
  5295. # - federation_sender1
  5296. # When using workers this should be a map from `worker_name` to the
  5297. # HTTP replication listener of the worker, if configured.
  5298. #
  5299. #instance_map:
  5300. # worker1:
  5301. # host: localhost
  5302. # port: 8034
  5303. # Experimental: When using workers you can define which workers should
  5304. # handle event persistence and typing notifications. Any worker
  5305. # specified here must also be in the `instance_map`.
  5306. #
  5307. #stream_writers:
  5308. # events: worker1
  5309. # typing: worker1
  5310. # The worker that is used to run background tasks (e.g. cleaning up expired
  5311. # data). If not provided this defaults to the main process.
  5312. #
  5313. #run_background_tasks_on: worker1
  5314. # A shared secret used by the replication APIs to authenticate HTTP requests
  5315. # from workers.
  5316. #
  5317. # By default this is unused and traffic is not authenticated.
  5318. #
  5319. #worker_replication_secret: &quot;&quot;
  5320. # Configuration for Redis when using workers. This *must* be enabled when
  5321. # using workers (unless using old style direct TCP configuration).
  5322. #
  5323. redis:
  5324. # Uncomment the below to enable Redis support.
  5325. #
  5326. #enabled: true
  5327. # Optional host and port to use to connect to redis. Defaults to
  5328. # localhost and 6379
  5329. #
  5330. #host: localhost
  5331. #port: 6379
  5332. # Optional password if configured on the Redis instance
  5333. #
  5334. #password: &lt;secret_password&gt;
  5335. </code></pre>
  5336. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="logging-sample-configuration-file"><a class="header" href="#logging-sample-configuration-file">Logging Sample Configuration File</a></h1>
  5337. <p>Below is a sample logging configuration file. This file can be tweaked to control how your
  5338. homeserver will output logs. A restart of the server is generally required to apply any
  5339. changes made to this file.</p>
  5340. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  5341. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  5342. a fresh config using Synapse by following the instructions in
  5343. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  5344. <pre><code class="language-yaml"># Log configuration for Synapse.
  5345. #
  5346. # This is a YAML file containing a standard Python logging configuration
  5347. # dictionary. See [1] for details on the valid settings.
  5348. #
  5349. # Synapse also supports structured logging for machine readable logs which can
  5350. # be ingested by ELK stacks. See [2] for details.
  5351. #
  5352. # [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  5353. # [2]: https://matrix-org.github.io/synapse/latest/structured_logging.html
  5354. version: 1
  5355. formatters:
  5356. precise:
  5357. format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
  5358. handlers:
  5359. file:
  5360. class: logging.handlers.TimedRotatingFileHandler
  5361. formatter: precise
  5362. filename: /var/log/matrix-synapse/homeserver.log
  5363. when: midnight
  5364. backupCount: 3 # Does not include the current log file.
  5365. encoding: utf8
  5366. # Default to buffering writes to log file for efficiency. This means that
  5367. # will be a delay for INFO/DEBUG logs to get written, but WARNING/ERROR
  5368. # logs will still be flushed immediately.
  5369. buffer:
  5370. class: logging.handlers.MemoryHandler
  5371. target: file
  5372. # The capacity is the number of log lines that are buffered before
  5373. # being written to disk. Increasing this will lead to better
  5374. # performance, at the expensive of it taking longer for log lines to
  5375. # be written to disk.
  5376. capacity: 10
  5377. flushLevel: 30 # Flush for WARNING logs as well
  5378. # A handler that writes logs to stderr. Unused by default, but can be used
  5379. # instead of &quot;buffer&quot; and &quot;file&quot; in the logger handlers.
  5380. console:
  5381. class: logging.StreamHandler
  5382. formatter: precise
  5383. loggers:
  5384. synapse.storage.SQL:
  5385. # beware: increasing this to DEBUG will make synapse log sensitive
  5386. # information such as access tokens.
  5387. level: INFO
  5388. twisted:
  5389. # We send the twisted logging directly to the file handler,
  5390. # to work around https://github.com/matrix-org/synapse/issues/3471
  5391. # when using &quot;buffer&quot; logger. Use &quot;console&quot; to log to stderr instead.
  5392. handlers: [file]
  5393. propagate: false
  5394. root:
  5395. level: INFO
  5396. # Write logs to the `buffer` handler, which will buffer them together in memory,
  5397. # then write them to a file.
  5398. #
  5399. # Replace &quot;buffer&quot; with &quot;console&quot; to log to stderr instead. (Note that you'll
  5400. # also need to update the configuration for the `twisted` logger above, in
  5401. # this case.)
  5402. #
  5403. handlers: [buffer]
  5404. disable_existing_loggers: false
  5405. ``__`</code></pre>
  5406. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="structured-logging"><a class="header" href="#structured-logging">Structured Logging</a></h1>
  5407. <p>A structured logging system can be useful when your logs are destined for a
  5408. machine to parse and process. By maintaining its machine-readable characteristics,
  5409. it enables more efficient searching and aggregations when consumed by software
  5410. such as the &quot;ELK stack&quot;.</p>
  5411. <p>Synapse's structured logging system is configured via the file that Synapse's
  5412. <code>log_config</code> config option points to. The file should include a formatter which
  5413. uses the <code>synapse.logging.TerseJsonFormatter</code> class included with Synapse and a
  5414. handler which uses the above formatter.</p>
  5415. <p>There is also a <code>synapse.logging.JsonFormatter</code> option which does not include
  5416. a timestamp in the resulting JSON. This is useful if the log ingester adds its
  5417. own timestamp.</p>
  5418. <p>A structured logging configuration looks similar to the following:</p>
  5419. <pre><code class="language-yaml">version: 1
  5420. formatters:
  5421. structured:
  5422. class: synapse.logging.TerseJsonFormatter
  5423. handlers:
  5424. file:
  5425. class: logging.handlers.TimedRotatingFileHandler
  5426. formatter: structured
  5427. filename: /path/to/my/logs/homeserver.log
  5428. when: midnight
  5429. backupCount: 3 # Does not include the current log file.
  5430. encoding: utf8
  5431. loggers:
  5432. synapse:
  5433. level: INFO
  5434. handlers: [remote]
  5435. synapse.storage.SQL:
  5436. level: WARNING
  5437. </code></pre>
  5438. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5439. with the SQL layer at 'WARNING', and will log to a file, stored as JSON.</p>
  5440. <p>It is also possible to figure Synapse to log to a remote endpoint by using the
  5441. <code>synapse.logging.RemoteHandler</code> class included with Synapse. It takes the
  5442. following arguments:</p>
  5443. <ul>
  5444. <li><code>host</code>: Hostname or IP address of the log aggregator.</li>
  5445. <li><code>port</code>: Numerical port to contact on the host.</li>
  5446. <li><code>maximum_buffer</code>: (Optional, defaults to 1000) The maximum buffer size to allow.</li>
  5447. </ul>
  5448. <p>A remote structured logging configuration looks similar to the following:</p>
  5449. <pre><code class="language-yaml">version: 1
  5450. formatters:
  5451. structured:
  5452. class: synapse.logging.TerseJsonFormatter
  5453. handlers:
  5454. remote:
  5455. class: synapse.logging.RemoteHandler
  5456. formatter: structured
  5457. host: 10.1.2.3
  5458. port: 9999
  5459. loggers:
  5460. synapse:
  5461. level: INFO
  5462. handlers: [remote]
  5463. synapse.storage.SQL:
  5464. level: WARNING
  5465. </code></pre>
  5466. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5467. with the SQL layer at 'WARNING', and will log JSON formatted messages to a
  5468. remote endpoint at 10.1.2.3:9999.</p>
  5469. <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>
  5470. <p>Versions of Synapse prior to v1.23.0 included a custom structured logging
  5471. configuration which is deprecated. It used a <code>structured: true</code> flag and
  5472. configured <code>drains</code> instead of <code>handlers</code> and <code>formatters</code>.</p>
  5473. <p>Synapse currently automatically converts the old configuration to the new
  5474. configuration, but this will be removed in a future version of Synapse. The
  5475. following reference can be used to update your configuration. Based on the drain
  5476. <code>type</code>, we can pick a new handler:</p>
  5477. <ol>
  5478. <li>For a type of <code>console</code>, <code>console_json</code>, or <code>console_json_terse</code>: a handler
  5479. with a class of <code>logging.StreamHandler</code> and a <code>stream</code> of <code>ext://sys.stdout</code>
  5480. or <code>ext://sys.stderr</code> should be used.</li>
  5481. <li>For a type of <code>file</code> or <code>file_json</code>: a handler of <code>logging.FileHandler</code> with
  5482. a location of the file path should be used.</li>
  5483. <li>For a type of <code>network_json_terse</code>: a handler of <code>synapse.logging.RemoteHandler</code>
  5484. with the host and port should be used.</li>
  5485. </ol>
  5486. <p>Then based on the drain <code>type</code> we can pick a new formatter:</p>
  5487. <ol>
  5488. <li>For a type of <code>console</code> or <code>file</code> no formatter is necessary.</li>
  5489. <li>For a type of <code>console_json</code> or <code>file_json</code>: a formatter of
  5490. <code>synapse.logging.JsonFormatter</code> should be used.</li>
  5491. <li>For a type of <code>console_json_terse</code> or <code>network_json_terse</code>: a formatter of
  5492. <code>synapse.logging.TerseJsonFormatter</code> should be used.</li>
  5493. </ol>
  5494. <p>For each new handler and formatter they should be added to the logging configuration
  5495. and then assigned to either a logger or the root logger.</p>
  5496. <p>An example legacy configuration:</p>
  5497. <pre><code class="language-yaml">structured: true
  5498. loggers:
  5499. synapse:
  5500. level: INFO
  5501. synapse.storage.SQL:
  5502. level: WARNING
  5503. drains:
  5504. console:
  5505. type: console
  5506. location: stdout
  5507. file:
  5508. type: file_json
  5509. location: homeserver.log
  5510. </code></pre>
  5511. <p>Would be converted into a new configuration:</p>
  5512. <pre><code class="language-yaml">version: 1
  5513. formatters:
  5514. json:
  5515. class: synapse.logging.JsonFormatter
  5516. handlers:
  5517. console:
  5518. class: logging.StreamHandler
  5519. location: ext://sys.stdout
  5520. file:
  5521. class: logging.FileHandler
  5522. formatter: json
  5523. filename: homeserver.log
  5524. loggers:
  5525. synapse:
  5526. level: INFO
  5527. handlers: [console, file]
  5528. synapse.storage.SQL:
  5529. level: WARNING
  5530. </code></pre>
  5531. <p>The new logging configuration is a bit more verbose, but significantly more
  5532. flexible. It allows for configuration that were not previously possible, such as
  5533. sending plain logs over the network, or using different handlers for different
  5534. modules.</p>
  5535. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="user-authentication"><a class="header" href="#user-authentication">User Authentication</a></h1>
  5536. <p>Synapse supports multiple methods of authenticating users, either out-of-the-box or through custom pluggable
  5537. authentication modules.</p>
  5538. <p>Included in Synapse is support for authenticating users via:</p>
  5539. <ul>
  5540. <li>A username and password.</li>
  5541. <li>An email address and password.</li>
  5542. <li>Single Sign-On through the SAML, Open ID Connect or CAS protocols.</li>
  5543. <li>JSON Web Tokens.</li>
  5544. <li>An administrator's shared secret.</li>
  5545. </ul>
  5546. <p>Synapse can additionally be extended to support custom authentication schemes through optional &quot;password auth provider&quot;
  5547. modules.</p>
  5548. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="configuring-synapse-to-authenticate-against-an-openid-connect-provider"><a class="header" href="#configuring-synapse-to-authenticate-against-an-openid-connect-provider">Configuring Synapse to authenticate against an OpenID Connect provider</a></h1>
  5549. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  5550. authentication, instead of its own local password database.</p>
  5551. <p>Any OP should work with Synapse, as long as it supports the authorization code
  5552. flow. There are a few options for that:</p>
  5553. <ul>
  5554. <li>
  5555. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  5556. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  5557. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  5558. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  5559. environment variable set to the path of the CA.</p>
  5560. </li>
  5561. <li>
  5562. <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
  5563. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  5564. </li>
  5565. </ul>
  5566. <p>It may also be possible to use other OAuth2 providers which provide the
  5567. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  5568. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  5569. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  5570. <p>The OpenID integration in Synapse uses the
  5571. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  5572. as follows:</p>
  5573. <ul>
  5574. <li>
  5575. <p>The relevant libraries are included in the Docker images and Debian packages
  5576. provided by <code>matrix.org</code> so no further action is needed.</p>
  5577. </li>
  5578. <li>
  5579. <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>
  5580. </li>
  5581. <li>
  5582. <p>For other installation mechanisms, see the documentation provided by the
  5583. maintainer.</p>
  5584. </li>
  5585. </ul>
  5586. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  5587. setting in your configuration file (or uncomment one of the existing examples).
  5588. See <a href="./sample_config.yaml">sample_config.yaml</a> for some sample settings, as well as
  5589. the text below for example configurations for specific providers.</p>
  5590. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  5591. <p>Here are a few configs for providers that should work with Synapse.</p>
  5592. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  5593. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  5594. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  5595. application should point to your matrix server:
  5596. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5597. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  5598. Directory (tenant) ID as it will be used in the Azure links.
  5599. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  5600. <pre><code class="language-yaml">oidc_providers:
  5601. - idp_id: microsoft
  5602. idp_name: Microsoft
  5603. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  5604. client_id: &quot;&lt;client id&gt;&quot;
  5605. client_secret: &quot;&lt;client secret&gt;&quot;
  5606. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5607. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  5608. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  5609. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  5610. user_mapping_provider:
  5611. config:
  5612. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  5613. display_name_template: &quot;{{ user.name }}&quot;
  5614. </code></pre>
  5615. <h3 id="a-hrefhttpsgithubcomdexidpdexdexa"><a class="header" href="#a-hrefhttpsgithubcomdexidpdexdexa"><a href="https://github.com/dexidp/dex">Dex</a></a></h3>
  5616. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source, certified OpenID Connect Provider.
  5617. Although it is designed to help building a full-blown provider with an
  5618. external database, it can be configured with static passwords in a config file.</p>
  5619. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  5620. to install Dex.</p>
  5621. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  5622. <pre><code class="language-yaml">staticClients:
  5623. - id: synapse
  5624. secret: secret
  5625. redirectURIs:
  5626. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  5627. name: 'Synapse'
  5628. </code></pre>
  5629. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  5630. <p>Synapse config:</p>
  5631. <pre><code class="language-yaml">oidc_providers:
  5632. - idp_id: dex
  5633. idp_name: &quot;My Dex server&quot;
  5634. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  5635. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  5636. client_id: &quot;synapse&quot;
  5637. client_secret: &quot;secret&quot;
  5638. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5639. user_mapping_provider:
  5640. config:
  5641. localpart_template: &quot;{{ user.name }}&quot;
  5642. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  5643. </code></pre>
  5644. <h3 id="a-hrefhttpswwwkeycloakorgdocslatestserver_adminsso-protocolskeycloaka"><a class="header" href="#a-hrefhttpswwwkeycloakorgdocslatestserver_adminsso-protocolskeycloaka"><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a></a></h3>
  5645. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  5646. <p>Follow the <a href="https://www.keycloak.org/getting-started">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  5647. <ol>
  5648. <li>
  5649. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  5650. </li>
  5651. <li>
  5652. <p>Fill in the fields as below:</p>
  5653. </li>
  5654. </ol>
  5655. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5656. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5657. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5658. </tbody></table>
  5659. <ol start="3">
  5660. <li>Click <code>Save</code></li>
  5661. <li>Fill in the fields as below:</li>
  5662. </ol>
  5663. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5664. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5665. <tr><td>Enabled</td><td><code>On</code></td></tr>
  5666. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5667. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  5668. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  5669. </tbody></table>
  5670. <ol start="5">
  5671. <li>Click <code>Save</code></li>
  5672. <li>On the Credentials tab, update the fields:</li>
  5673. </ol>
  5674. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5675. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  5676. </tbody></table>
  5677. <ol start="7">
  5678. <li>Click <code>Regenerate Secret</code></li>
  5679. <li>Copy Secret</li>
  5680. </ol>
  5681. <pre><code class="language-yaml">oidc_providers:
  5682. - idp_id: keycloak
  5683. idp_name: &quot;My KeyCloak server&quot;
  5684. issuer: &quot;https://127.0.0.1:8443/auth/realms/{realm_name}&quot;
  5685. client_id: &quot;synapse&quot;
  5686. client_secret: &quot;copy secret generated from above&quot;
  5687. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5688. user_mapping_provider:
  5689. config:
  5690. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5691. display_name_template: &quot;{{ user.name }}&quot;
  5692. </code></pre>
  5693. <h3 id="a-hrefhttpsauth0comauth0a"><a class="header" href="#a-hrefhttpsauth0comauth0a"><a href="https://auth0.com/">Auth0</a></a></h3>
  5694. <ol>
  5695. <li>
  5696. <p>Create a regular web application for Synapse</p>
  5697. </li>
  5698. <li>
  5699. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5700. </li>
  5701. <li>
  5702. <p>Add a rule to add the <code>preferred_username</code> claim.</p>
  5703. <details>
  5704. <summary>Code sample</summary>
  5705. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  5706. user.user_metadata = user.user_metadata || {};
  5707. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  5708. context.idToken.preferred_username = user.user_metadata.preferred_username;
  5709. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  5710. .then(function(){
  5711. callback(null, user, context);
  5712. })
  5713. .catch(function(err){
  5714. callback(err);
  5715. });
  5716. }
  5717. </code></pre>
  5718. </li>
  5719. </ol>
  5720. </details>
  5721. <p>Synapse config:</p>
  5722. <pre><code class="language-yaml">oidc_providers:
  5723. - idp_id: auth0
  5724. idp_name: Auth0
  5725. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  5726. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5727. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5728. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5729. user_mapping_provider:
  5730. config:
  5731. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5732. display_name_template: &quot;{{ user.name }}&quot;
  5733. </code></pre>
  5734. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  5735. <p>GitHub is a bit special as it is not an OpenID Connect compliant provider, but
  5736. just a regular OAuth2 provider.</p>
  5737. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  5738. can be used to retrieve information on the authenticated user. As the Synapse
  5739. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5740. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5741. <ol>
  5742. <li>Create a new OAuth application: https://github.com/settings/applications/new.</li>
  5743. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5744. </ol>
  5745. <p>Synapse config:</p>
  5746. <pre><code class="language-yaml">oidc_providers:
  5747. - idp_id: github
  5748. idp_name: Github
  5749. idp_brand: &quot;github&quot; # optional: styling hint for clients
  5750. discover: false
  5751. issuer: &quot;https://github.com/&quot;
  5752. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5753. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5754. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  5755. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  5756. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  5757. scopes: [&quot;read:user&quot;]
  5758. user_mapping_provider:
  5759. config:
  5760. subject_claim: &quot;id&quot;
  5761. localpart_template: &quot;{{ user.login }}&quot;
  5762. display_name_template: &quot;{{ user.name }}&quot;
  5763. </code></pre>
  5764. <h3 id="a-hrefhttpsdevelopersgooglecomidentityprotocolsoauth2openid-connectgooglea"><a class="header" href="#a-hrefhttpsdevelopersgooglecomidentityprotocolsoauth2openid-connectgooglea"><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a></a></h3>
  5765. <ol>
  5766. <li>Set up a project in the Google API Console (see
  5767. https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup).</li>
  5768. <li>add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  5769. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  5770. <pre><code class="language-yaml">oidc_providers:
  5771. - idp_id: google
  5772. idp_name: Google
  5773. idp_brand: &quot;google&quot; # optional: styling hint for clients
  5774. issuer: &quot;https://accounts.google.com/&quot;
  5775. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5776. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5777. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5778. user_mapping_provider:
  5779. config:
  5780. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  5781. display_name_template: &quot;{{ user.name }}&quot;
  5782. </code></pre>
  5783. </li>
  5784. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5785. </ol>
  5786. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  5787. <ol>
  5788. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  5789. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  5790. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5791. </ol>
  5792. <p>Synapse config:</p>
  5793. <pre><code class="language-yaml">oidc_providers:
  5794. - idp_id: twitch
  5795. idp_name: Twitch
  5796. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  5797. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5798. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5799. client_auth_method: &quot;client_secret_post&quot;
  5800. user_mapping_provider:
  5801. config:
  5802. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5803. display_name_template: &quot;{{ user.name }}&quot;
  5804. </code></pre>
  5805. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  5806. <ol>
  5807. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  5808. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  5809. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5810. </ol>
  5811. <p>Synapse config:</p>
  5812. <pre><code class="language-yaml">oidc_providers:
  5813. - idp_id: gitlab
  5814. idp_name: Gitlab
  5815. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  5816. issuer: &quot;https://gitlab.com/&quot;
  5817. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5818. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5819. client_auth_method: &quot;client_secret_post&quot;
  5820. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  5821. user_profile_method: &quot;userinfo_endpoint&quot;
  5822. user_mapping_provider:
  5823. config:
  5824. localpart_template: '{{ user.nickname }}'
  5825. display_name_template: '{{ user.name }}'
  5826. </code></pre>
  5827. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  5828. <p>Like Github, Facebook provide a custom OAuth2 API rather than an OIDC-compliant
  5829. one so requires a little more configuration.</p>
  5830. <ol start="0">
  5831. <li>You will need a Facebook developer account. You can register for one
  5832. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  5833. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  5834. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  5835. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  5836. need to go through the whole form here.</li>
  5837. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  5838. <ul>
  5839. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  5840. URL.</li>
  5841. </ul>
  5842. </li>
  5843. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  5844. and &quot;App Secret&quot; for use below.</li>
  5845. </ol>
  5846. <p>Synapse config:</p>
  5847. <pre><code class="language-yaml"> - idp_id: facebook
  5848. idp_name: Facebook
  5849. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  5850. discover: false
  5851. issuer: &quot;https://facebook.com&quot;
  5852. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5853. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5854. scopes: [&quot;openid&quot;, &quot;email&quot;]
  5855. authorization_endpoint: https://facebook.com/dialog/oauth
  5856. token_endpoint: https://graph.facebook.com/v9.0/oauth/access_token
  5857. user_profile_method: &quot;userinfo_endpoint&quot;
  5858. userinfo_endpoint: &quot;https://graph.facebook.com/v9.0/me?fields=id,name,email,picture&quot;
  5859. user_mapping_provider:
  5860. config:
  5861. subject_claim: &quot;id&quot;
  5862. display_name_template: &quot;{{ user.name }}&quot;
  5863. </code></pre>
  5864. <p>Relevant documents:</p>
  5865. <ul>
  5866. <li>https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow</li>
  5867. <li>Using Facebook's Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/</li>
  5868. <li>Reference to the User endpoint: https://developers.facebook.com/docs/graph-api/reference/user</li>
  5869. </ul>
  5870. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  5871. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  5872. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  5873. can be used to retrieve information on the authenticated user. As the Synapse
  5874. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5875. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5876. <ol>
  5877. <li>Create a new application.</li>
  5878. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5879. </ol>
  5880. <p>Synapse config:</p>
  5881. <pre><code class="language-yaml">oidc_providers:
  5882. - idp_id: gitea
  5883. idp_name: Gitea
  5884. discover: false
  5885. issuer: &quot;https://your-gitea.com/&quot;
  5886. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5887. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5888. client_auth_method: client_secret_post
  5889. scopes: [] # Gitea doesn't support Scopes
  5890. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  5891. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  5892. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  5893. user_mapping_provider:
  5894. config:
  5895. subject_claim: &quot;id&quot;
  5896. localpart_template: &quot;{{ user.login }}&quot;
  5897. display_name_template: &quot;{{ user.full_name }}&quot;
  5898. </code></pre>
  5899. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  5900. <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>
  5901. <p>Synapse config:</p>
  5902. <pre><code class="language-yaml">oidc_providers:
  5903. - idp_id: xwiki
  5904. idp_name: &quot;XWiki&quot;
  5905. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  5906. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5907. client_auth_method: none
  5908. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5909. user_profile_method: &quot;userinfo_endpoint&quot;
  5910. user_mapping_provider:
  5911. config:
  5912. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5913. display_name_template: &quot;{{ user.name }}&quot;
  5914. </code></pre>
  5915. <h2 id="apple"><a class="header" href="#apple">Apple</a></h2>
  5916. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  5917. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  5918. private key with &quot;SiWA&quot; enabled.</p>
  5919. <p>As well as the private key file, you will need:</p>
  5920. <ul>
  5921. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  5922. <li>Team ID: a 10-character ID associated with your developer account.</li>
  5923. <li>Key ID: the 10-character identifier for the key.</li>
  5924. </ul>
  5925. <p>https://help.apple.com/developer-account/?lang=en#/dev77c875b7e has more
  5926. documentation on setting up SiWA.</p>
  5927. <p>The synapse config will look like this:</p>
  5928. <pre><code class="language-yaml"> - idp_id: apple
  5929. idp_name: Apple
  5930. issuer: &quot;https://appleid.apple.com&quot;
  5931. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  5932. client_auth_method: &quot;client_secret_post&quot;
  5933. client_secret_jwt_key:
  5934. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  5935. jwt_header:
  5936. alg: ES256
  5937. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  5938. jwt_payload:
  5939. iss: TEAMIDCODE # Set to the 10-char Team ID
  5940. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  5941. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  5942. user_mapping_provider:
  5943. config:
  5944. email_template: &quot;{{ user.email }}&quot;
  5945. </code></pre>
  5946. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="sso-mapping-providers"><a class="header" href="#sso-mapping-providers">SSO Mapping Providers</a></h1>
  5947. <p>A mapping provider is a Python class (loaded via a Python module) that
  5948. works out how to map attributes of a SSO response to Matrix-specific
  5949. user attributes. Details such as user ID localpart, displayname, and even avatar
  5950. URLs are all things that can be mapped from talking to a SSO service.</p>
  5951. <p>As an example, a SSO service may return the email address
  5952. &quot;john.smith@example.com&quot; for a user, whereas Synapse will need to figure out how
  5953. to turn that into a displayname when creating a Matrix user for this individual.
  5954. It may choose <code>John Smith</code>, or <code>Smith, John [Example.com]</code> or any number of
  5955. variations. As each Synapse configuration may want something different, this is
  5956. where SAML mapping providers come into play.</p>
  5957. <p>SSO mapping providers are currently supported for OpenID and SAML SSO
  5958. configurations. Please see the details below for how to implement your own.</p>
  5959. <p>It is up to the mapping provider whether the user should be assigned a predefined
  5960. Matrix ID based on the SSO attributes, or if the user should be allowed to
  5961. choose their own username.</p>
  5962. <p>In the first case - where users are automatically allocated a Matrix ID - it is
  5963. the responsibility of the mapping provider to normalise the SSO attributes and
  5964. map them to a valid Matrix ID. The <a href="https://matrix.org/docs/spec/appendices#user-identifiers">specification for Matrix
  5965. IDs</a> has some
  5966. information about what is considered valid.</p>
  5967. <p>If the mapping provider does not assign a Matrix ID, then Synapse will
  5968. automatically serve an HTML page allowing the user to pick their own username.</p>
  5969. <p>External mapping providers are provided to Synapse in the form of an external
  5970. Python module. You can retrieve this module from <a href="https://pypi.org">PyPI</a> or elsewhere,
  5971. but it must be importable via Synapse (e.g. it must be in the same virtualenv
  5972. as Synapse). The Synapse config is then modified to point to the mapping provider
  5973. (and optionally provide additional configuration for it).</p>
  5974. <h2 id="openid-mapping-providers"><a class="header" href="#openid-mapping-providers">OpenID Mapping Providers</a></h2>
  5975. <p>The OpenID mapping provider can be customized by editing the
  5976. <code>oidc_config.user_mapping_provider.module</code> config option.</p>
  5977. <p><code>oidc_config.user_mapping_provider.config</code> allows you to provide custom
  5978. configuration options to the module. Check with the module's documentation for
  5979. what options it provides (if any). The options listed by default are for the
  5980. user mapping provider built in to Synapse. If using a custom module, you should
  5981. comment these options out and use those specified by the module instead.</p>
  5982. <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>
  5983. <p>A custom mapping provider must specify the following methods:</p>
  5984. <ul>
  5985. <li><code>__init__(self, parsed_config)</code>
  5986. <ul>
  5987. <li>Arguments:
  5988. <ul>
  5989. <li><code>parsed_config</code> - A configuration object that is the return value of the
  5990. <code>parse_config</code> method. You should set any configuration options needed by
  5991. the module here.</li>
  5992. </ul>
  5993. </li>
  5994. </ul>
  5995. </li>
  5996. <li><code>parse_config(config)</code>
  5997. <ul>
  5998. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  5999. <li>Arguments:
  6000. <ul>
  6001. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6002. <code>oidc_config.user_mapping_provider.config</code> homeserver config option.
  6003. Runs on homeserver startup. Providers should extract and validate
  6004. any option values they need here.</li>
  6005. </ul>
  6006. </li>
  6007. <li>Whatever is returned will be passed back to the user mapping provider module's
  6008. <code>__init__</code> method during construction.</li>
  6009. </ul>
  6010. </li>
  6011. <li><code>get_remote_user_id(self, userinfo)</code>
  6012. <ul>
  6013. <li>Arguments:
  6014. <ul>
  6015. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6016. information from.</li>
  6017. </ul>
  6018. </li>
  6019. <li>This method must return a string, which is the unique, immutable identifier
  6020. for the user. Commonly the <code>sub</code> claim of the response.</li>
  6021. </ul>
  6022. </li>
  6023. <li><code>map_user_attributes(self, userinfo, token, failures)</code>
  6024. <ul>
  6025. <li>This method must be async.</li>
  6026. <li>Arguments:
  6027. <ul>
  6028. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6029. information from.</li>
  6030. <li><code>token</code> - A dictionary which includes information necessary to make
  6031. further requests to the OpenID provider.</li>
  6032. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6033. mxid localpart mapping has failed. This should be used
  6034. to create a deduplicated mxid localpart which should be
  6035. returned instead. For example, if this method returns
  6036. <code>john.doe</code> as the value of <code>localpart</code> in the returned
  6037. dict, and that is already taken on the homeserver, this
  6038. method will be called again with the same parameters but
  6039. with failures=1. The method should then return a different
  6040. <code>localpart</code> value, such as <code>john.doe1</code>.</li>
  6041. </ul>
  6042. </li>
  6043. <li>Returns a dictionary with two keys:
  6044. <ul>
  6045. <li><code>localpart</code>: A string, used to generate the Matrix ID. If this is
  6046. <code>None</code>, the user is prompted to pick their own username. This is only used
  6047. during a user's first login. Once a localpart has been associated with a
  6048. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6049. <li><code>displayname</code>: An optional string, the display name for the user.</li>
  6050. </ul>
  6051. </li>
  6052. </ul>
  6053. </li>
  6054. <li><code>get_extra_attributes(self, userinfo, token)</code>
  6055. <ul>
  6056. <li>
  6057. <p>This method must be async.</p>
  6058. </li>
  6059. <li>
  6060. <p>Arguments:</p>
  6061. <ul>
  6062. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6063. information from.</li>
  6064. <li><code>token</code> - A dictionary which includes information necessary to make
  6065. further requests to the OpenID provider.</li>
  6066. </ul>
  6067. </li>
  6068. <li>
  6069. <p>Returns a dictionary that is suitable to be serialized to JSON. This
  6070. will be returned as part of the response during a successful login.</p>
  6071. <p>Note that care should be taken to not overwrite any of the parameters
  6072. 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>
  6073. </li>
  6074. </ul>
  6075. </li>
  6076. </ul>
  6077. <h3 id="default-openid-mapping-provider"><a class="header" href="#default-openid-mapping-provider">Default OpenID Mapping Provider</a></h3>
  6078. <p>Synapse has a built-in OpenID mapping provider if a custom provider isn't
  6079. specified in the config. It is located at
  6080. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/oidc.py"><code>synapse.handlers.oidc.JinjaOidcMappingProvider</code></a>.</p>
  6081. <h2 id="saml-mapping-providers"><a class="header" href="#saml-mapping-providers">SAML Mapping Providers</a></h2>
  6082. <p>The SAML mapping provider can be customized by editing the
  6083. <code>saml2_config.user_mapping_provider.module</code> config option.</p>
  6084. <p><code>saml2_config.user_mapping_provider.config</code> allows you to provide custom
  6085. configuration options to the module. Check with the module's documentation for
  6086. what options it provides (if any). The options listed by default are for the
  6087. user mapping provider built in to Synapse. If using a custom module, you should
  6088. comment these options out and use those specified by the module instead.</p>
  6089. <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>
  6090. <p>A custom mapping provider must specify the following methods:</p>
  6091. <ul>
  6092. <li><code>__init__(self, parsed_config, module_api)</code>
  6093. <ul>
  6094. <li>Arguments:
  6095. <ul>
  6096. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6097. <code>parse_config</code> method. You should set any configuration options needed by
  6098. the module here.</li>
  6099. <li><code>module_api</code> - a <code>synapse.module_api.ModuleApi</code> object which provides the
  6100. stable API available for extension modules.</li>
  6101. </ul>
  6102. </li>
  6103. </ul>
  6104. </li>
  6105. <li><code>parse_config(config)</code>
  6106. <ul>
  6107. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6108. <li>Arguments:
  6109. <ul>
  6110. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6111. <code>saml_config.user_mapping_provider.config</code> homeserver config option.
  6112. Runs on homeserver startup. Providers should extract and validate
  6113. any option values they need here.</li>
  6114. </ul>
  6115. </li>
  6116. <li>Whatever is returned will be passed back to the user mapping provider module's
  6117. <code>__init__</code> method during construction.</li>
  6118. </ul>
  6119. </li>
  6120. <li><code>get_saml_attributes(config)</code>
  6121. <ul>
  6122. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6123. <li>Arguments:
  6124. <ul>
  6125. <li><code>config</code> - A object resulting from a call to <code>parse_config</code>.</li>
  6126. </ul>
  6127. </li>
  6128. <li>Returns a tuple of two sets. The first set equates to the SAML auth
  6129. response attributes that are required for the module to function, whereas
  6130. the second set consists of those attributes which can be used if available,
  6131. but are not necessary.</li>
  6132. </ul>
  6133. </li>
  6134. <li><code>get_remote_user_id(self, saml_response, client_redirect_url)</code>
  6135. <ul>
  6136. <li>Arguments:
  6137. <ul>
  6138. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6139. information from.</li>
  6140. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6141. redirected to.</li>
  6142. </ul>
  6143. </li>
  6144. <li>This method must return a string, which is the unique, immutable identifier
  6145. for the user. Commonly the <code>uid</code> claim of the response.</li>
  6146. </ul>
  6147. </li>
  6148. <li><code>saml_response_to_user_attributes(self, saml_response, failures, client_redirect_url)</code>
  6149. <ul>
  6150. <li>
  6151. <p>Arguments:</p>
  6152. <ul>
  6153. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6154. information from.</li>
  6155. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6156. mxid localpart mapping has failed. This should be used
  6157. to create a deduplicated mxid localpart which should be
  6158. returned instead. For example, if this method returns
  6159. <code>john.doe</code> as the value of <code>mxid_localpart</code> in the returned
  6160. dict, and that is already taken on the homeserver, this
  6161. method will be called again with the same parameters but
  6162. with failures=1. The method should then return a different
  6163. <code>mxid_localpart</code> value, such as <code>john.doe1</code>.</li>
  6164. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6165. redirected to.</li>
  6166. </ul>
  6167. </li>
  6168. <li>
  6169. <p>This method must return a dictionary, which will then be used by Synapse
  6170. to build a new user. The following keys are allowed:</p>
  6171. <ul>
  6172. <li><code>mxid_localpart</code> - A string, the mxid localpart of the new user. If this is
  6173. <code>None</code>, the user is prompted to pick their own username. This is only used
  6174. during a user's first login. Once a localpart has been associated with a
  6175. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6176. <li><code>displayname</code> - The displayname of the new user. If not provided, will default to
  6177. the value of <code>mxid_localpart</code>.</li>
  6178. <li><code>emails</code> - A list of emails for the new user. If not provided, will
  6179. default to an empty list.</li>
  6180. </ul>
  6181. <p>Alternatively it can raise a <code>synapse.api.errors.RedirectException</code> to
  6182. redirect the user to another page. This is useful to prompt the user for
  6183. additional information, e.g. if you want them to provide their own username.
  6184. It is the responsibility of the mapping provider to either redirect back
  6185. to <code>client_redirect_url</code> (including any additional information) or to
  6186. complete registration using methods from the <code>ModuleApi</code>.</p>
  6187. </li>
  6188. </ul>
  6189. </li>
  6190. </ul>
  6191. <h3 id="default-saml-mapping-provider"><a class="header" href="#default-saml-mapping-provider">Default SAML Mapping Provider</a></h3>
  6192. <p>Synapse has a built-in SAML mapping provider if a custom provider isn't
  6193. specified in the config. It is located at
  6194. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/saml.py"><code>synapse.handlers.saml.DefaultSamlMappingProvider</code></a>.</p>
  6195. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="password-auth-provider-modules"><a class="header" href="#password-auth-provider-modules">Password auth provider modules</a></h1>
  6196. <p>Password auth providers offer a way for server administrators to
  6197. integrate their Synapse installation with an existing authentication
  6198. system.</p>
  6199. <p>A password auth provider is a Python class which is dynamically loaded
  6200. into Synapse, and provides a number of methods by which it can integrate
  6201. with the authentication system.</p>
  6202. <p>This document serves as a reference for those looking to implement their
  6203. own password auth providers. Additionally, here is a list of known
  6204. password auth provider module implementations:</p>
  6205. <ul>
  6206. <li><a href="https://github.com/matrix-org/matrix-synapse-ldap3/">matrix-synapse-ldap3</a></li>
  6207. <li><a href="https://github.com/devture/matrix-synapse-shared-secret-auth">matrix-synapse-shared-secret-auth</a></li>
  6208. <li><a href="https://github.com/ma1uta/matrix-synapse-rest-password-provider">matrix-synapse-rest-password-provider</a></li>
  6209. </ul>
  6210. <h2 id="required-methods"><a class="header" href="#required-methods">Required methods</a></h2>
  6211. <p>Password auth provider classes must provide the following methods:</p>
  6212. <ul>
  6213. <li>
  6214. <p><code>parse_config(config)</code>
  6215. This method is passed the <code>config</code> object for this module from the
  6216. homeserver configuration file.</p>
  6217. <p>It should perform any appropriate sanity checks on the provided
  6218. configuration, and return an object which is then passed into
  6219. <code>__init__</code>.</p>
  6220. <p>This method should have the <code>@staticmethod</code> decoration.</p>
  6221. </li>
  6222. <li>
  6223. <p><code>__init__(self, config, account_handler)</code></p>
  6224. <p>The constructor is passed the config object returned by
  6225. <code>parse_config</code>, and a <code>synapse.module_api.ModuleApi</code> object which
  6226. allows the password provider to check if accounts exist and/or create
  6227. new ones.</p>
  6228. </li>
  6229. </ul>
  6230. <h2 id="optional-methods"><a class="header" href="#optional-methods">Optional methods</a></h2>
  6231. <p>Password auth provider classes may optionally provide the following methods:</p>
  6232. <ul>
  6233. <li>
  6234. <p><code>get_db_schema_files(self)</code></p>
  6235. <p>This method, if implemented, should return an Iterable of
  6236. <code>(name, stream)</code> pairs of database schema files. Each file is applied
  6237. in turn at initialisation, and a record is then made in the database
  6238. so that it is not re-applied on the next start.</p>
  6239. </li>
  6240. <li>
  6241. <p><code>get_supported_login_types(self)</code></p>
  6242. <p>This method, if implemented, should return a <code>dict</code> mapping from a
  6243. login type identifier (such as <code>m.login.password</code>) to an iterable
  6244. giving the fields which must be provided by the user in the submission
  6245. to <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login">the <code>/login</code> API</a>.
  6246. These fields are passed in the <code>login_dict</code> dictionary to <code>check_auth</code>.</p>
  6247. <p>For example, if a password auth provider wants to implement a custom
  6248. login type of <code>com.example.custom_login</code>, where the client is expected
  6249. to pass the fields <code>secret1</code> and <code>secret2</code>, the provider should
  6250. implement this method and return the following dict:</p>
  6251. <pre><code class="language-python">{&quot;com.example.custom_login&quot;: (&quot;secret1&quot;, &quot;secret2&quot;)}
  6252. </code></pre>
  6253. </li>
  6254. <li>
  6255. <p><code>check_auth(self, username, login_type, login_dict)</code></p>
  6256. <p>This method does the real work. If implemented, it
  6257. will be called for each login attempt where the login type matches one
  6258. of the keys returned by <code>get_supported_login_types</code>.</p>
  6259. <p>It is passed the (possibly unqualified) <code>user</code> field provided by the client,
  6260. the login type, and a dictionary of login secrets passed by the
  6261. client.</p>
  6262. <p>The method should return an <code>Awaitable</code> object, which resolves
  6263. to the canonical <code>@localpart:domain</code> user ID if authentication is
  6264. successful, and <code>None</code> if not.</p>
  6265. <p>Alternatively, the <code>Awaitable</code> can resolve to a <code>(str, func)</code> tuple, in
  6266. which case the second field is a callback which will be called with
  6267. the result from the <code>/login</code> call (including <code>access_token</code>,
  6268. <code>device_id</code>, etc.)</p>
  6269. </li>
  6270. <li>
  6271. <p><code>check_3pid_auth(self, medium, address, password)</code></p>
  6272. <p>This method, if implemented, is called when a user attempts to
  6273. register or log in with a third party identifier, such as email. It is
  6274. passed the medium (ex. &quot;email&quot;), an address (ex.
  6275. &quot;<a href="mailto:jdoe@example.com">jdoe@example.com</a>&quot;) and the user's password.</p>
  6276. <p>The method should return an <code>Awaitable</code> object, which resolves
  6277. to a <code>str</code> containing the user's (canonical) User id if
  6278. authentication was successful, and <code>None</code> if not.</p>
  6279. <p>As with <code>check_auth</code>, the <code>Awaitable</code> may alternatively resolve to a
  6280. <code>(user_id, callback)</code> tuple.</p>
  6281. </li>
  6282. <li>
  6283. <p><code>check_password(self, user_id, password)</code></p>
  6284. <p>This method provides a simpler interface than
  6285. <code>get_supported_login_types</code> and <code>check_auth</code> for password auth
  6286. providers that just want to provide a mechanism for validating
  6287. <code>m.login.password</code> logins.</p>
  6288. <p>If implemented, it will be called to check logins with an
  6289. <code>m.login.password</code> login type. It is passed a qualified
  6290. <code>@localpart:domain</code> user id, and the password provided by the user.</p>
  6291. <p>The method should return an <code>Awaitable</code> object, which resolves
  6292. to <code>True</code> if authentication is successful, and <code>False</code> if not.</p>
  6293. </li>
  6294. <li>
  6295. <p><code>on_logged_out(self, user_id, device_id, access_token)</code></p>
  6296. <p>This method, if implemented, is called when a user logs out. It is
  6297. passed the qualified user ID, the ID of the deactivated device (if
  6298. any: access tokens are occasionally created without an associated
  6299. device ID), and the (now deactivated) access token.</p>
  6300. <p>It may return an <code>Awaitable</code> object; the logout request will
  6301. wait for the <code>Awaitable</code> to complete, but the result is ignored.</p>
  6302. </li>
  6303. </ul>
  6304. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="jwt-login-type"><a class="header" href="#jwt-login-type">JWT Login Type</a></h1>
  6305. <p>Synapse comes with a non-standard login type to support
  6306. <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">JSON Web Tokens</a>. In general the
  6307. documentation for
  6308. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#login">the login endpoint</a>
  6309. is still valid (and the mechanism works similarly to the
  6310. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#token-based">token based login</a>).</p>
  6311. <p>To log in using a JSON Web Token, clients should submit a <code>/login</code> request as
  6312. follows:</p>
  6313. <pre><code class="language-json">{
  6314. &quot;type&quot;: &quot;org.matrix.login.jwt&quot;,
  6315. &quot;token&quot;: &quot;&lt;jwt&gt;&quot;
  6316. }
  6317. </code></pre>
  6318. <p>Note that the login type of <code>m.login.jwt</code> is supported, but is deprecated. This
  6319. will be removed in a future version of Synapse.</p>
  6320. <p>The <code>token</code> field should include the JSON web token with the following claims:</p>
  6321. <ul>
  6322. <li>The <code>sub</code> (subject) claim is required and should encode the local part of the
  6323. user ID.</li>
  6324. <li>The expiration time (<code>exp</code>), not before time (<code>nbf</code>), and issued at (<code>iat</code>)
  6325. claims are optional, but validated if present.</li>
  6326. <li>The issuer (<code>iss</code>) claim is optional, but required and validated if configured.</li>
  6327. <li>The audience (<code>aud</code>) claim is optional, but required and validated if configured.
  6328. Providing the audience claim when not configured will cause validation to fail.</li>
  6329. </ul>
  6330. <p>In the case that the token is not valid, the homeserver must respond with
  6331. <code>403 Forbidden</code> and an error code of <code>M_FORBIDDEN</code>.</p>
  6332. <p>As with other login types, there are additional fields (e.g. <code>device_id</code> and
  6333. <code>initial_device_display_name</code>) which can be included in the above request.</p>
  6334. <h2 id="preparing-synapse-1"><a class="header" href="#preparing-synapse-1">Preparing Synapse</a></h2>
  6335. <p>The JSON Web Token integration in Synapse uses the
  6336. <a href="https://pypi.org/project/pyjwt/"><code>PyJWT</code></a> library, which must be installed
  6337. as follows:</p>
  6338. <ul>
  6339. <li>
  6340. <p>The relevant libraries are included in the Docker images and Debian packages
  6341. provided by <code>matrix.org</code> so no further action is needed.</p>
  6342. </li>
  6343. <li>
  6344. <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>
  6345. </li>
  6346. <li>
  6347. <p>For other installation mechanisms, see the documentation provided by the
  6348. maintainer.</p>
  6349. </li>
  6350. </ul>
  6351. <p>To enable the JSON web token integration, you should then add an <code>jwt_config</code> section
  6352. to your configuration file (or uncomment the <code>enabled: true</code> line in the
  6353. existing section). See <a href="./sample_config.yaml">sample_config.yaml</a> for some
  6354. sample settings.</p>
  6355. <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>
  6356. <p>Although JSON Web Tokens are typically generated from an external server, the
  6357. examples below use <a href="https://pyjwt.readthedocs.io/en/latest/">PyJWT</a> directly.</p>
  6358. <ol>
  6359. <li>
  6360. <p>Configure Synapse with JWT logins, note that this example uses a pre-shared
  6361. secret and an algorithm of HS256:</p>
  6362. <pre><code class="language-yaml">jwt_config:
  6363. enabled: true
  6364. secret: &quot;my-secret-token&quot;
  6365. algorithm: &quot;HS256&quot;
  6366. </code></pre>
  6367. </li>
  6368. <li>
  6369. <p>Generate a JSON web token:</p>
  6370. <pre><code class="language-bash">$ pyjwt --key=my-secret-token --alg=HS256 encode sub=test-user
  6371. eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc
  6372. </code></pre>
  6373. </li>
  6374. <li>
  6375. <p>Query for the login types and ensure <code>org.matrix.login.jwt</code> is there:</p>
  6376. <pre><code class="language-bash">curl http://localhost:8080/_matrix/client/r0/login
  6377. </code></pre>
  6378. </li>
  6379. <li>
  6380. <p>Login used the generated JSON web token from above:</p>
  6381. <pre><code class="language-bash">$ curl http://localhost:8082/_matrix/client/r0/login -X POST \
  6382. --data '{&quot;type&quot;:&quot;org.matrix.login.jwt&quot;,&quot;token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc&quot;}'
  6383. {
  6384. &quot;access_token&quot;: &quot;&lt;access token&gt;&quot;,
  6385. &quot;device_id&quot;: &quot;ACBDEFGHI&quot;,
  6386. &quot;home_server&quot;: &quot;localhost:8080&quot;,
  6387. &quot;user_id&quot;: &quot;@test-user:localhost:8480&quot;
  6388. }
  6389. </code></pre>
  6390. </li>
  6391. </ol>
  6392. <p>You should now be able to use the returned access token to query the client API.</p>
  6393. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="overview-2"><a class="header" href="#overview-2">Overview</a></h1>
  6394. <p>A captcha can be enabled on your homeserver to help prevent bots from registering
  6395. accounts. Synapse currently uses Google's reCAPTCHA service which requires API keys
  6396. from Google.</p>
  6397. <h2 id="getting-api-keys"><a class="header" href="#getting-api-keys">Getting API keys</a></h2>
  6398. <ol>
  6399. <li>Create a new site at <a href="https://www.google.com/recaptcha/admin/create">https://www.google.com/recaptcha/admin/create</a></li>
  6400. <li>Set the label to anything you want</li>
  6401. <li>Set the type to reCAPTCHA v2 using the &quot;I'm not a robot&quot; Checkbox option.
  6402. This is the only type of captcha that works with Synapse.</li>
  6403. <li>Add the public hostname for your server, as set in <code>public_baseurl</code>
  6404. in <code>homeserver.yaml</code>, to the list of authorized domains. If you have not set
  6405. <code>public_baseurl</code>, use <code>server_name</code>.</li>
  6406. <li>Agree to the terms of service and submit.</li>
  6407. <li>Copy your site key and secret key and add them to your <code>homeserver.yaml</code>
  6408. configuration file
  6409. <pre><code>recaptcha_public_key: YOUR_SITE_KEY
  6410. recaptcha_private_key: YOUR_SECRET_KEY
  6411. </code></pre>
  6412. </li>
  6413. <li>Enable the CAPTCHA for new registrations
  6414. <pre><code>enable_registration_captcha: true
  6415. </code></pre>
  6416. </li>
  6417. <li>Go to the settings page for the CAPTCHA you just created</li>
  6418. <li>Uncheck the &quot;Verify the origin of reCAPTCHA solutions&quot; checkbox so that the
  6419. captcha can be displayed in any client. If you do not disable this option then you
  6420. must specify the domains of every client that is allowed to display the CAPTCHA.</li>
  6421. </ol>
  6422. <h2 id="configuring-ip-used-for-auth"><a class="header" href="#configuring-ip-used-for-auth">Configuring IP used for auth</a></h2>
  6423. <p>The reCAPTCHA API requires that the IP address of the user who solved the
  6424. CAPTCHA is sent. If the client is connecting through a proxy or load balancer,
  6425. it may be required to use the <code>X-Forwarded-For</code> (XFF) header instead of the origin
  6426. IP address. This can be configured using the <code>x_forwarded</code> directive in the
  6427. listeners section of the <code>homeserver.yaml</code> configuration file.</p>
  6428. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="registering-an-application-service"><a class="header" href="#registering-an-application-service">Registering an Application Service</a></h1>
  6429. <p>The registration of new application services depends on the homeserver used.
  6430. In synapse, you need to create a new configuration file for your AS and add it
  6431. to the list specified under the <code>app_service_config_files</code> config
  6432. option in your synapse config.</p>
  6433. <p>For example:</p>
  6434. <pre><code class="language-yaml">app_service_config_files:
  6435. - /home/matrix/.synapse/&lt;your-AS&gt;.yaml
  6436. </code></pre>
  6437. <p>The format of the AS configuration file is as follows:</p>
  6438. <pre><code class="language-yaml">url: &lt;base url of AS&gt;
  6439. as_token: &lt;token AS will add to requests to HS&gt;
  6440. hs_token: &lt;token HS will add to requests to AS&gt;
  6441. sender_localpart: &lt;localpart of AS user&gt;
  6442. namespaces:
  6443. users: # List of users we're interested in
  6444. - exclusive: &lt;bool&gt;
  6445. regex: &lt;regex&gt;
  6446. group_id: &lt;group&gt;
  6447. - ...
  6448. aliases: [] # List of aliases we're interested in
  6449. rooms: [] # List of room ids we're interested in
  6450. </code></pre>
  6451. <p><code>exclusive</code>: If enabled, only this application service is allowed to register users in its namespace(s).
  6452. <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>
  6453. <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>
  6454. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="server-notices"><a class="header" href="#server-notices">Server Notices</a></h1>
  6455. <p>'Server Notices' are a new feature introduced in Synapse 0.30. They provide a
  6456. channel whereby server administrators can send messages to users on the server.</p>
  6457. <p>They are used as part of communication of the server polices(see
  6458. <a href="consent_tracking.html">consent_tracking.md</a>), however the intention is that
  6459. they may also find a use for features such as &quot;Message of the day&quot;.</p>
  6460. <p>This is a feature specific to Synapse, but it uses standard Matrix
  6461. communication mechanisms, so should work with any Matrix client.</p>
  6462. <h2 id="user-experience"><a class="header" href="#user-experience">User experience</a></h2>
  6463. <p>When the user is first sent a server notice, they will get an invitation to a
  6464. room (typically called 'Server Notices', though this is configurable in
  6465. <code>homeserver.yaml</code>). They will be <strong>unable to reject</strong> this invitation -
  6466. attempts to do so will receive an error.</p>
  6467. <p>Once they accept the invitation, they will see the notice message in the room
  6468. history; it will appear to have come from the 'server notices user' (see
  6469. below).</p>
  6470. <p>The user is prevented from sending any messages in this room by the power
  6471. levels.</p>
  6472. <p>Having joined the room, the user can leave the room if they want. Subsequent
  6473. server notices will then cause a new room to be created.</p>
  6474. <h2 id="synapse-configuration"><a class="header" href="#synapse-configuration">Synapse configuration</a></h2>
  6475. <p>Server notices come from a specific user id on the server. Server
  6476. administrators are free to choose the user id - something like <code>server</code> is
  6477. suggested, meaning the notices will come from
  6478. <code>@server:&lt;your_server_name&gt;</code>. Once the Server Notices user is configured, that
  6479. user id becomes a special, privileged user, so administrators should ensure
  6480. that <strong>it is not already allocated</strong>.</p>
  6481. <p>In order to support server notices, it is necessary to add some configuration
  6482. to the <code>homeserver.yaml</code> file. In particular, you should add a <code>server_notices</code>
  6483. section, which should look like this:</p>
  6484. <pre><code class="language-yaml">server_notices:
  6485. system_mxid_localpart: server
  6486. system_mxid_display_name: &quot;Server Notices&quot;
  6487. system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  6488. room_name: &quot;Server Notices&quot;
  6489. </code></pre>
  6490. <p>The only compulsory setting is <code>system_mxid_localpart</code>, which defines the user
  6491. id of the Server Notices user, as above. <code>room_name</code> defines the name of the
  6492. room which will be created.</p>
  6493. <p><code>system_mxid_display_name</code> and <code>system_mxid_avatar_url</code> can be used to set the
  6494. displayname and avatar of the Server Notices user.</p>
  6495. <h2 id="sending-notices"><a class="header" href="#sending-notices">Sending notices</a></h2>
  6496. <p>To send server notices to users you can use the
  6497. <a href="admin_api/server_notices.html">admin_api</a>.</p>
  6498. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions"><a class="header" href="#support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions">Support in Synapse for tracking agreement to server terms and conditions</a></h1>
  6499. <p>Synapse 0.30 introduces support for tracking whether users have agreed to the
  6500. terms and conditions set by the administrator of a server - and blocking access
  6501. to the server until they have.</p>
  6502. <p>There are several parts to this functionality; each requires some specific
  6503. configuration in <code>homeserver.yaml</code> to be enabled.</p>
  6504. <p>Note that various parts of the configuation and this document refer to the
  6505. &quot;privacy policy&quot;: agreement with a privacy policy is one particular use of this
  6506. feature, but of course adminstrators can specify other terms and conditions
  6507. unrelated to &quot;privacy&quot; per se.</p>
  6508. <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>
  6509. <p>Synapse can be configured to serve the user a simple policy form with an
  6510. &quot;accept&quot; button. Clicking &quot;Accept&quot; records the user's acceptance in the
  6511. database and shows a success page.</p>
  6512. <p>To enable this, first create templates for the policy and success pages.
  6513. These should be stored on the local filesystem.</p>
  6514. <p>These templates use the <a href="http://jinja.pocoo.org">Jinja2</a> templating language,
  6515. and <a href="https://github.com/matrix-org/synapse/tree/develop/docs/privacy_policy_templates/">docs/privacy_policy_templates</a>
  6516. gives examples of the sort of thing that can be done.</p>
  6517. <p>Note that the templates must be stored under a name giving the language of the
  6518. template - currently this must always be <code>en</code> (for &quot;English&quot;);
  6519. internationalisation support is intended for the future.</p>
  6520. <p>The template for the policy itself should be versioned and named according to
  6521. the version: for example <code>1.0.html</code>. The version of the policy which the user
  6522. has agreed to is stored in the database.</p>
  6523. <p>Once the templates are in place, make the following changes to <code>homeserver.yaml</code>:</p>
  6524. <ol>
  6525. <li>
  6526. <p>Add a <code>user_consent</code> section, which should look like:</p>
  6527. <pre><code class="language-yaml">user_consent:
  6528. template_dir: privacy_policy_templates
  6529. version: 1.0
  6530. </code></pre>
  6531. <p><code>template_dir</code> points to the directory containing the policy
  6532. templates. <code>version</code> defines the version of the policy which will be served
  6533. to the user. In the example above, Synapse will serve
  6534. <code>privacy_policy_templates/en/1.0.html</code>.</p>
  6535. </li>
  6536. <li>
  6537. <p>Add a <code>form_secret</code> setting at the top level:</p>
  6538. <pre><code class="language-yaml">form_secret: &quot;&lt;unique secret&gt;&quot;
  6539. </code></pre>
  6540. <p>This should be set to an arbitrary secret string (try <code>pwgen -y 30</code> to
  6541. generate suitable secrets).</p>
  6542. <p>More on what this is used for below.</p>
  6543. </li>
  6544. <li>
  6545. <p>Add <code>consent</code> wherever the <code>client</code> resource is currently enabled in the
  6546. <code>listeners</code> configuration. For example:</p>
  6547. <pre><code class="language-yaml">listeners:
  6548. - port: 8008
  6549. resources:
  6550. - names:
  6551. - client
  6552. - consent
  6553. </code></pre>
  6554. </li>
  6555. </ol>
  6556. <p>Finally, ensure that <code>jinja2</code> is installed. If you are using a virtualenv, this
  6557. should be a matter of <code>pip install Jinja2</code>. On debian, try <code>apt-get install python-jinja2</code>.</p>
  6558. <p>Once this is complete, and the server has been restarted, try visiting
  6559. <code>https://&lt;server&gt;/_matrix/consent</code>. If correctly configured, this should give
  6560. an error &quot;Missing string query parameter 'u'&quot;. It is now possible to manually
  6561. construct URIs where users can give their consent.</p>
  6562. <h3 id="enabling-consent-tracking-at-registration"><a class="header" href="#enabling-consent-tracking-at-registration">Enabling consent tracking at registration</a></h3>
  6563. <ol>
  6564. <li>
  6565. <p>Add the following to your configuration:</p>
  6566. <pre><code class="language-yaml">user_consent:
  6567. require_at_registration: true
  6568. policy_name: &quot;Privacy Policy&quot; # or whatever you'd like to call the policy
  6569. </code></pre>
  6570. </li>
  6571. <li>
  6572. <p>In your consent templates, make use of the <code>public_version</code> variable to
  6573. see if an unauthenticated user is viewing the page. This is typically
  6574. wrapped around the form that would be used to actually agree to the document:</p>
  6575. <pre><code>{% if not public_version %}
  6576. &lt;!-- The variables used here are only provided when the 'u' param is given to the homeserver --&gt;
  6577. &lt;form method=&quot;post&quot; action=&quot;consent&quot;&gt;
  6578. &lt;input type=&quot;hidden&quot; name=&quot;v&quot; value=&quot;{{version}}&quot;/&gt;
  6579. &lt;input type=&quot;hidden&quot; name=&quot;u&quot; value=&quot;{{user}}&quot;/&gt;
  6580. &lt;input type=&quot;hidden&quot; name=&quot;h&quot; value=&quot;{{userhmac}}&quot;/&gt;
  6581. &lt;input type=&quot;submit&quot; value=&quot;Sure thing!&quot;/&gt;
  6582. &lt;/form&gt;
  6583. {% endif %}
  6584. </code></pre>
  6585. </li>
  6586. <li>
  6587. <p>Restart Synapse to apply the changes.</p>
  6588. </li>
  6589. </ol>
  6590. <p>Visiting <code>https://&lt;server&gt;/_matrix/consent</code> should now give you a view of the privacy
  6591. document. This is what users will be able to see when registering for accounts.</p>
  6592. <h3 id="constructing-the-consent-uri"><a class="header" href="#constructing-the-consent-uri">Constructing the consent URI</a></h3>
  6593. <p>It may be useful to manually construct the &quot;consent URI&quot; for a given user - for
  6594. instance, in order to send them an email asking them to consent. To do this,
  6595. take the base <code>https://&lt;server&gt;/_matrix/consent</code> URL and add the following
  6596. query parameters:</p>
  6597. <ul>
  6598. <li>
  6599. <p><code>u</code>: the user id of the user. This can either be a full MXID
  6600. (<code>@user:server.com</code>) or just the localpart (<code>user</code>).</p>
  6601. </li>
  6602. <li>
  6603. <p><code>h</code>: hex-encoded HMAC-SHA256 of <code>u</code> using the <code>form_secret</code> as a key. It is
  6604. possible to calculate this on the commandline with something like:</p>
  6605. <pre><code class="language-bash">echo -n '&lt;user&gt;' | openssl sha256 -hmac '&lt;form_secret&gt;'
  6606. </code></pre>
  6607. <p>This should result in a URI which looks something like:
  6608. <code>https://&lt;server&gt;/_matrix/consent?u=&lt;user&gt;&amp;h=68a152465a4d...</code>.</p>
  6609. </li>
  6610. </ul>
  6611. <p>Note that not providing a <code>u</code> parameter will be interpreted as wanting to view
  6612. the document from an unauthenticated perspective, such as prior to registration.
  6613. Therefore, the <code>h</code> parameter is not required in this scenario. To enable this
  6614. behaviour, set <code>require_at_registration</code> to <code>true</code> in your <code>user_consent</code> config.</p>
  6615. <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>
  6616. <p>It is possible to configure Synapse to send a <a href="server_notices.html">server
  6617. notice</a> to anybody who has not yet agreed to the current
  6618. version of the policy. To do so:</p>
  6619. <ul>
  6620. <li>
  6621. <p>ensure that the consent resource is configured, as in the previous section</p>
  6622. </li>
  6623. <li>
  6624. <p>ensure that server notices are configured, as in <a href="server_notices.html">server_notices.md</a>.</p>
  6625. </li>
  6626. <li>
  6627. <p>Add <code>server_notice_content</code> under <code>user_consent</code> in <code>homeserver.yaml</code>. For
  6628. example:</p>
  6629. <pre><code class="language-yaml">user_consent:
  6630. server_notice_content:
  6631. msgtype: m.text
  6632. body: &gt;-
  6633. Please give your consent to the privacy policy at %(consent_uri)s.
  6634. </code></pre>
  6635. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6636. consent uri for that user.</p>
  6637. </li>
  6638. <li>
  6639. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6640. URI that clients use to connect to the server. (It is used to construct
  6641. <code>consent_uri</code> in the server notice.)</p>
  6642. </li>
  6643. </ul>
  6644. <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>
  6645. <p>Synapse can be configured to block any attempts to join rooms or send messages
  6646. until the user has given their agreement to the policy. (Joining the server
  6647. notices room is exempted from this).</p>
  6648. <p>To enable this, add <code>block_events_error</code> under <code>user_consent</code>. For example:</p>
  6649. <pre><code class="language-yaml">user_consent:
  6650. block_events_error: &gt;-
  6651. You can't send any messages until you consent to the privacy policy at
  6652. %(consent_uri)s.
  6653. </code></pre>
  6654. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6655. consent uri for that user.</p>
  6656. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6657. URI that clients use to connect to the server. (It is used to construct
  6658. <code>consent_uri</code> in the error.)</p>
  6659. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="url-previews-1"><a class="header" href="#url-previews-1">URL Previews</a></h1>
  6660. <p>Design notes on a URL previewing service for Matrix:</p>
  6661. <p>Options are:</p>
  6662. <ol>
  6663. <li>Have an AS which listens for URLs, downloads them, and inserts an event that describes their metadata.</li>
  6664. </ol>
  6665. <ul>
  6666. <li>Pros:
  6667. <ul>
  6668. <li>Decouples the implementation entirely from Synapse.</li>
  6669. <li>Uses existing Matrix events &amp; content repo to store the metadata.</li>
  6670. </ul>
  6671. </li>
  6672. <li>Cons:
  6673. <ul>
  6674. <li>Which AS should provide this service for a room, and why should you trust it?</li>
  6675. <li>Doesn't work well with E2E; you'd have to cut the AS into every room</li>
  6676. <li>the AS would end up subscribing to every room anyway.</li>
  6677. </ul>
  6678. </li>
  6679. </ul>
  6680. <ol start="2">
  6681. <li>Have a generic preview API (nothing to do with Matrix) that provides a previewing service:</li>
  6682. </ol>
  6683. <ul>
  6684. <li>Pros:
  6685. <ul>
  6686. <li>Simple and flexible; can be used by any clients at any point</li>
  6687. </ul>
  6688. </li>
  6689. <li>Cons:
  6690. <ul>
  6691. <li>If each HS provides one of these independently, all the HSes in a room may needlessly DoS the target URI</li>
  6692. <li>We need somewhere to store the URL metadata rather than just using Matrix itself</li>
  6693. <li>We can't piggyback on matrix to distribute the metadata between HSes.</li>
  6694. </ul>
  6695. </li>
  6696. </ul>
  6697. <ol start="3">
  6698. <li>Make the synapse of the sending user responsible for spidering the URL and inserting an event asynchronously which describes the metadata.</li>
  6699. </ol>
  6700. <ul>
  6701. <li>Pros:
  6702. <ul>
  6703. <li>Works transparently for all clients</li>
  6704. <li>Piggy-backs nicely on using Matrix for distributing the metadata.</li>
  6705. <li>No confusion as to which AS</li>
  6706. </ul>
  6707. </li>
  6708. <li>Cons:
  6709. <ul>
  6710. <li>Doesn't work with E2E</li>
  6711. <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>
  6712. </ul>
  6713. </li>
  6714. </ul>
  6715. <ol start="4">
  6716. <li>Make the sending client use the preview API and insert the event itself when successful.</li>
  6717. </ol>
  6718. <ul>
  6719. <li>Pros:
  6720. <ul>
  6721. <li>Works well with E2E</li>
  6722. <li>No custom server functionality</li>
  6723. <li>Lets the client customise the preview that they send (like on FB)</li>
  6724. </ul>
  6725. </li>
  6726. <li>Cons:
  6727. <ul>
  6728. <li>Entirely specific to the sending client, whereas it'd be nice if /any/ URL was correctly previewed if clients support it.</li>
  6729. </ul>
  6730. </li>
  6731. </ul>
  6732. <ol start="5">
  6733. <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>
  6734. </ol>
  6735. <p>Best solution is probably a combination of both 2 and 4.</p>
  6736. <ul>
  6737. <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>
  6738. <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>
  6739. </ul>
  6740. <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>
  6741. <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>
  6742. <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>
  6743. <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>
  6744. <h2 id="api"><a class="header" href="#api">API</a></h2>
  6745. <pre><code>GET /_matrix/media/r0/preview_url?url=http://wherever.com
  6746. 200 OK
  6747. {
  6748. &quot;og:type&quot; : &quot;article&quot;
  6749. &quot;og:url&quot; : &quot;https://twitter.com/matrixdotorg/status/684074366691356672&quot;
  6750. &quot;og:title&quot; : &quot;Matrix on Twitter&quot;
  6751. &quot;og:image&quot; : &quot;https://pbs.twimg.com/profile_images/500400952029888512/yI0qtFi7_400x400.png&quot;
  6752. &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;
  6753. &quot;og:site_name&quot; : &quot;Twitter&quot;
  6754. }
  6755. </code></pre>
  6756. <ul>
  6757. <li>Downloads the URL
  6758. <ul>
  6759. <li>If HTML, just stores it in RAM and parses it for OG meta tags
  6760. <ul>
  6761. <li>Download any media OG meta tags to the media repo, and refer to them in the OG via mxc:// URIs.</li>
  6762. </ul>
  6763. </li>
  6764. <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>
  6765. <li>Otherwise, don't bother downloading further.</li>
  6766. </ul>
  6767. </li>
  6768. </ul>
  6769. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="user-directory-api-implementation"><a class="header" href="#user-directory-api-implementation">User Directory API Implementation</a></h1>
  6770. <p>The user directory is currently maintained based on the 'visible' users
  6771. on this particular server - i.e. ones which your account shares a room with, or
  6772. who are present in a publicly viewable room present on the server.</p>
  6773. <p>The directory info is stored in various tables, which can (typically after
  6774. DB corruption) get stale or out of sync. If this happens, for now the
  6775. 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>
  6776. and then restart synapse. This should then start a background task to
  6777. flush the current tables and regenerate the directory.</p>
  6778. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="message-retention-policies"><a class="header" href="#message-retention-policies">Message retention policies</a></h1>
  6779. <p>Synapse admins can enable support for message retention policies on
  6780. their homeserver. Message retention policies exist at a room level,
  6781. follow the semantics described in
  6782. <a href="https://github.com/matrix-org/matrix-doc/blob/matthew/msc1763/proposals/1763-configurable-retention-periods.md">MSC1763</a>,
  6783. and allow server and room admins to configure how long messages should
  6784. be kept in a homeserver's database before being purged from it.
  6785. <strong>Please note that, as this feature isn't part of the Matrix
  6786. specification yet, this implementation is to be considered as
  6787. experimental.</strong> </p>
  6788. <p>A message retention policy is mainly defined by its <code>max_lifetime</code>
  6789. parameter, which defines how long a message can be kept around after
  6790. it was sent to the room. If a room doesn't have a message retention
  6791. policy, and there's no default one for a given server, then no message
  6792. sent in that room is ever purged on that server.</p>
  6793. <p>MSC1763 also specifies semantics for a <code>min_lifetime</code> parameter which
  6794. defines the amount of time after which an event <em>can</em> get purged (after
  6795. it was sent to the room), but Synapse doesn't currently support it
  6796. beyond registering it.</p>
  6797. <p>Both <code>max_lifetime</code> and <code>min_lifetime</code> are optional parameters.</p>
  6798. <p>Note that message retention policies don't apply to state events.</p>
  6799. <p>Once an event reaches its expiry date (defined as the time it was sent
  6800. plus the value for <code>max_lifetime</code> in the room), two things happen:</p>
  6801. <ul>
  6802. <li>Synapse stops serving the event to clients via any endpoint.</li>
  6803. <li>The message gets picked up by the next purge job (see the &quot;Purge jobs&quot;
  6804. section) and is removed from Synapse's database.</li>
  6805. </ul>
  6806. <p>Since purge jobs don't run continuously, this means that an event might
  6807. stay in a server's database for longer than the value for <code>max_lifetime</code>
  6808. in the room would allow, though hidden from clients.</p>
  6809. <p>Similarly, if a server (with support for message retention policies
  6810. enabled) receives from another server an event that should have been
  6811. purged according to its room's policy, then the receiving server will
  6812. process and store that event until it's picked up by the next purge job,
  6813. though it will always hide it from clients.</p>
  6814. <p>Synapse requires at least one message in each room, so it will never
  6815. delete the last message in a room. It will, however, hide it from
  6816. clients.</p>
  6817. <h2 id="server-configuration"><a class="header" href="#server-configuration">Server configuration</a></h2>
  6818. <p>Support for this feature can be enabled and configured in the
  6819. <code>retention</code> section of the Synapse configuration file (see the
  6820. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample file</a>).</p>
  6821. <p>To enable support for message retention policies, set the setting
  6822. <code>enabled</code> in this section to <code>true</code>.</p>
  6823. <h3 id="default-policy"><a class="header" href="#default-policy">Default policy</a></h3>
  6824. <p>A default message retention policy is a policy defined in Synapse's
  6825. configuration that is used by Synapse for every room that doesn't have a
  6826. message retention policy configured in its state. This allows server
  6827. admins to ensure that messages are never kept indefinitely in a server's
  6828. database. </p>
  6829. <p>A default policy can be defined as such, in the <code>retention</code> section of
  6830. the configuration file:</p>
  6831. <pre><code class="language-yaml"> default_policy:
  6832. min_lifetime: 1d
  6833. max_lifetime: 1y
  6834. </code></pre>
  6835. <p>Here, <code>min_lifetime</code> and <code>max_lifetime</code> have the same meaning and level
  6836. of support as previously described. They can be expressed either as a
  6837. duration (using the units <code>s</code> (seconds), <code>m</code> (minutes), <code>h</code> (hours),
  6838. <code>d</code> (days), <code>w</code> (weeks) and <code>y</code> (years)) or as a number of milliseconds.</p>
  6839. <h3 id="purge-jobs"><a class="header" href="#purge-jobs">Purge jobs</a></h3>
  6840. <p>Purge jobs are the jobs that Synapse runs in the background to purge
  6841. expired events from the database. They are only run if support for
  6842. message retention policies is enabled in the server's configuration. If
  6843. no configuration for purge jobs is configured by the server admin,
  6844. Synapse will use a default configuration, which is described in the
  6845. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample configuration file</a>.</p>
  6846. <p>Some server admins might want a finer control on when events are removed
  6847. depending on an event's room's policy. This can be done by setting the
  6848. <code>purge_jobs</code> sub-section in the <code>retention</code> section of the configuration
  6849. file. An example of such configuration could be:</p>
  6850. <pre><code class="language-yaml"> purge_jobs:
  6851. - longest_max_lifetime: 3d
  6852. interval: 12h
  6853. - shortest_max_lifetime: 3d
  6854. longest_max_lifetime: 1w
  6855. interval: 1d
  6856. - shortest_max_lifetime: 1w
  6857. interval: 2d
  6858. </code></pre>
  6859. <p>In this example, we define three jobs:</p>
  6860. <ul>
  6861. <li>one that runs twice a day (every 12 hours) and purges events in rooms
  6862. which policy's <code>max_lifetime</code> is lower or equal to 3 days.</li>
  6863. <li>one that runs once a day and purges events in rooms which policy's
  6864. <code>max_lifetime</code> is between 3 days and a week.</li>
  6865. <li>one that runs once every 2 days and purges events in rooms which
  6866. policy's <code>max_lifetime</code> is greater than a week.</li>
  6867. </ul>
  6868. <p>Note that this example is tailored to show different configurations and
  6869. features slightly more jobs than it's probably necessary (in practice, a
  6870. server admin would probably consider it better to replace the two last
  6871. jobs with one that runs once a day and handles rooms which which
  6872. policy's <code>max_lifetime</code> is greater than 3 days).</p>
  6873. <p>Keep in mind, when configuring these jobs, that a purge job can become
  6874. quite heavy on the server if it targets many rooms, therefore prefer
  6875. having jobs with a low interval that target a limited set of rooms. Also
  6876. make sure to include a job with no minimum and one with no maximum to
  6877. make sure your configuration handles every policy.</p>
  6878. <p>As previously mentioned in this documentation, while a purge job that
  6879. runs e.g. every day means that an expired event might stay in the
  6880. database for up to a day after its expiry, Synapse hides expired events
  6881. from clients as soon as they expire, so the event is not visible to
  6882. local users between its expiry date and the moment it gets purged from
  6883. the server's database.</p>
  6884. <h3 id="lifetime-limits"><a class="header" href="#lifetime-limits">Lifetime limits</a></h3>
  6885. <p>Server admins can set limits on the values of <code>max_lifetime</code> to use when
  6886. purging old events in a room. These limits can be defined as such in the
  6887. <code>retention</code> section of the configuration file:</p>
  6888. <pre><code class="language-yaml"> allowed_lifetime_min: 1d
  6889. allowed_lifetime_max: 1y
  6890. </code></pre>
  6891. <p>The limits are considered when running purge jobs. If necessary, the
  6892. effective value of <code>max_lifetime</code> will be brought between
  6893. <code>allowed_lifetime_min</code> and <code>allowed_lifetime_max</code> (inclusive).
  6894. This means that, if the value of <code>max_lifetime</code> defined in the room's state
  6895. is lower than <code>allowed_lifetime_min</code>, the value of <code>allowed_lifetime_min</code>
  6896. will be used instead. Likewise, if the value of <code>max_lifetime</code> is higher
  6897. than <code>allowed_lifetime_max</code>, the value of <code>allowed_lifetime_max</code> will be
  6898. used instead.</p>
  6899. <p>In the example above, we ensure Synapse never deletes events that are less
  6900. than one day old, and that it always deletes events that are over a year
  6901. old.</p>
  6902. <p>If a default policy is set, and its <code>max_lifetime</code> value is lower than
  6903. <code>allowed_lifetime_min</code> or higher than <code>allowed_lifetime_max</code>, the same
  6904. process applies.</p>
  6905. <p>Both parameters are optional; if one is omitted Synapse won't use it to
  6906. adjust the effective value of <code>max_lifetime</code>.</p>
  6907. <p>Like other settings in this section, these parameters can be expressed
  6908. either as a duration or as a number of milliseconds.</p>
  6909. <h2 id="room-configuration"><a class="header" href="#room-configuration">Room configuration</a></h2>
  6910. <p>To configure a room's message retention policy, a room's admin or
  6911. moderator needs to send a state event in that room with the type
  6912. <code>m.room.retention</code> and the following content:</p>
  6913. <pre><code class="language-json">{
  6914. &quot;max_lifetime&quot;: ...
  6915. }
  6916. </code></pre>
  6917. <p>In this event's content, the <code>max_lifetime</code> parameter has the same
  6918. meaning as previously described, and needs to be expressed in
  6919. milliseconds. The event's content can also include a <code>min_lifetime</code>
  6920. parameter, which has the same meaning and limited support as previously
  6921. described.</p>
  6922. <p>Note that over every server in the room, only the ones with support for
  6923. message retention policies will actually remove expired events. This
  6924. support is currently not enabled by default in Synapse.</p>
  6925. <h2 id="note-on-reclaiming-disk-space"><a class="header" href="#note-on-reclaiming-disk-space">Note on reclaiming disk space</a></h2>
  6926. <p>While purge jobs actually delete data from the database, the disk space
  6927. used by the database might not decrease immediately on the database's
  6928. host. However, even though the database engine won't free up the disk
  6929. space, it will start writing new data into where the purged data was.</p>
  6930. <p>If you want to reclaim the freed disk space anyway and return it to the
  6931. operating system, the server admin needs to run <code>VACUUM FULL;</code> (or
  6932. <code>VACUUM;</code> for SQLite databases) on Synapse's database (see the related
  6933. <a href="https://www.postgresql.org/docs/current/sql-vacuum.html">PostgreSQL documentation</a>).</p>
  6934. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="modules"><a class="header" href="#modules">Modules</a></h1>
  6935. <p>Synapse supports extending its functionality by configuring external modules.</p>
  6936. <h2 id="using-modules"><a class="header" href="#using-modules">Using modules</a></h2>
  6937. <p>To use a module on Synapse, add it to the <code>modules</code> section of the configuration file:</p>
  6938. <pre><code class="language-yaml">modules:
  6939. - module: my_super_module.MySuperClass
  6940. config:
  6941. do_thing: true
  6942. - module: my_other_super_module.SomeClass
  6943. config: {}
  6944. </code></pre>
  6945. <p>Each module is defined by a path to a Python class as well as a configuration. This
  6946. information for a given module should be available in the module's own documentation.</p>
  6947. <p><strong>Note</strong>: When using third-party modules, you effectively allow someone else to run
  6948. custom code on your Synapse homeserver. Server admins are encouraged to verify the
  6949. provenance of the modules they use on their homeserver and make sure the modules aren't
  6950. running malicious code on their instance.</p>
  6951. <p>Also note that we are currently in the process of migrating module interfaces to this
  6952. system. While some interfaces might be compatible with it, others still require
  6953. configuring modules in another part of Synapse's configuration file. Currently, only the
  6954. spam checker interface is compatible with this new system.</p>
  6955. <h2 id="writing-a-module"><a class="header" href="#writing-a-module">Writing a module</a></h2>
  6956. <p>A module is a Python class that uses Synapse's module API to interact with the
  6957. homeserver. It can register callbacks that Synapse will call on specific operations, as
  6958. well as web resources to attach to Synapse's web server.</p>
  6959. <p>When instantiated, a module is given its parsed configuration as well as an instance of
  6960. the <code>synapse.module_api.ModuleApi</code> class. The configuration is a dictionary, and is
  6961. either the output of the module's <code>parse_config</code> static method (see below), or the
  6962. configuration associated with the module in Synapse's configuration file.</p>
  6963. <p>See the documentation for the <code>ModuleApi</code> class
  6964. <a href="https://github.com/matrix-org/synapse/blob/master/synapse/module_api/__init__.py">here</a>.</p>
  6965. <h3 id="handling-the-modules-configuration"><a class="header" href="#handling-the-modules-configuration">Handling the module's configuration</a></h3>
  6966. <p>A module can implement the following static method:</p>
  6967. <pre><code class="language-python">@staticmethod
  6968. def parse_config(config: dict) -&gt; dict
  6969. </code></pre>
  6970. <p>This method is given a dictionary resulting from parsing the YAML configuration for the
  6971. module. It may modify it (for example by parsing durations expressed as strings (e.g.
  6972. &quot;5d&quot;) into milliseconds, etc.), and return the modified dictionary. It may also verify
  6973. that the configuration is correct, and raise an instance of
  6974. <code>synapse.module_api.errors.ConfigError</code> if not.</p>
  6975. <h3 id="registering-a-web-resource"><a class="header" href="#registering-a-web-resource">Registering a web resource</a></h3>
  6976. <p>Modules can register web resources onto Synapse's web server using the following module
  6977. API method:</p>
  6978. <pre><code class="language-python">def ModuleApi.register_web_resource(path: str, resource: IResource)
  6979. </code></pre>
  6980. <p>The path is the full absolute path to register the resource at. For example, if you
  6981. register a resource for the path <code>/_synapse/client/my_super_module/say_hello</code>, Synapse
  6982. will serve it at <code>http(s)://[HS_URL]/_synapse/client/my_super_module/say_hello</code>. Note
  6983. that Synapse does not allow registering resources for several sub-paths in the <code>/_matrix</code>
  6984. namespace (such as anything under <code>/_matrix/client</code> for example). It is strongly
  6985. recommended that modules register their web resources under the <code>/_synapse/client</code>
  6986. namespace.</p>
  6987. <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>
  6988. interface (such as <a href="https://twistedmatrix.com/documents/current/api/twisted.web.resource.Resource.html">Resource</a>).</p>
  6989. <p>Only one resource can be registered for a given path. If several modules attempt to
  6990. register a resource for the same path, the module that appears first in Synapse's
  6991. configuration file takes priority.</p>
  6992. <p>Modules <strong>must</strong> register their web resources in their <code>__init__</code> method.</p>
  6993. <h3 id="registering-a-callback"><a class="header" href="#registering-a-callback">Registering a callback</a></h3>
  6994. <p>Modules can use Synapse's module API to register callbacks. Callbacks are functions that
  6995. Synapse will call when performing specific actions. Callbacks must be asynchronous, and
  6996. are split in categories. A single module may implement callbacks from multiple categories,
  6997. and is under no obligation to implement all callbacks from the categories it registers
  6998. callbacks for.</p>
  6999. <h4 id="spam-checker-callbacks"><a class="header" href="#spam-checker-callbacks">Spam checker callbacks</a></h4>
  7000. <p>To register one of the callbacks described in this section, a module needs to use the
  7001. module API's <code>register_spam_checker_callbacks</code> method. The callback functions are passed
  7002. to <code>register_spam_checker_callbacks</code> as keyword arguments, with the callback name as the
  7003. argument name and the function as its value. This is demonstrated in the example below.</p>
  7004. <p>The available spam checker callbacks are:</p>
  7005. <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]
  7006. </code></pre>
  7007. <p>Called when receiving an event from a client or via federation. The module can return
  7008. either a <code>bool</code> to indicate whether the event must be rejected because of spam, or a <code>str</code>
  7009. to indicate the event must be rejected because of spam and to give a rejection reason to
  7010. forward to clients.</p>
  7011. <pre><code class="language-python">async def user_may_invite(inviter: str, invitee: str, room_id: str) -&gt; bool
  7012. </code></pre>
  7013. <p>Called when processing an invitation. The module must return a <code>bool</code> indicating whether
  7014. the inviter can invite the invitee to the given room. Both inviter and invitee are
  7015. represented by their Matrix user ID (i.e. <code>@alice:example.com</code>).</p>
  7016. <pre><code class="language-python">async def user_may_create_room(user: str) -&gt; bool
  7017. </code></pre>
  7018. <p>Called when processing a room creation request. The module must return a <code>bool</code> indicating
  7019. whether the given user (represented by their Matrix user ID) is allowed to create a room.</p>
  7020. <pre><code class="language-python">async def user_may_create_room_alias(user: str, room_alias: &quot;synapse.types.RoomAlias&quot;) -&gt; bool
  7021. </code></pre>
  7022. <p>Called when trying to associate an alias with an existing room. The module must return a
  7023. <code>bool</code> indicating whether the given user (represented by their Matrix user ID) is allowed
  7024. to set the given alias.</p>
  7025. <pre><code class="language-python">async def user_may_publish_room(user: str, room_id: str) -&gt; bool
  7026. </code></pre>
  7027. <p>Called when trying to publish a room to the homeserver's public rooms directory. The
  7028. module must return a <code>bool</code> indicating whether the given user (represented by their
  7029. Matrix user ID) is allowed to publish the given room.</p>
  7030. <pre><code class="language-python">async def check_username_for_spam(user_profile: Dict[str, str]) -&gt; bool
  7031. </code></pre>
  7032. <p>Called when computing search results in the user directory. The module must return a
  7033. <code>bool</code> indicating whether the given user profile can appear in search results. The profile
  7034. is represented as a dictionary with the following keys:</p>
  7035. <ul>
  7036. <li><code>user_id</code>: The Matrix ID for this user.</li>
  7037. <li><code>display_name</code>: The user's display name.</li>
  7038. <li><code>avatar_url</code>: The <code>mxc://</code> URL to the user's avatar.</li>
  7039. </ul>
  7040. <p>The module is given a copy of the original dictionary, so modifying it from within the
  7041. module cannot modify a user's profile when included in user directory search results.</p>
  7042. <pre><code class="language-python">async def check_registration_for_spam(
  7043. email_threepid: Optional[dict],
  7044. username: Optional[str],
  7045. request_info: Collection[Tuple[str, str]],
  7046. auth_provider_id: Optional[str] = None,
  7047. ) -&gt; &quot;synapse.spam_checker_api.RegistrationBehaviour&quot;
  7048. </code></pre>
  7049. <p>Called when registering a new user. The module must return a <code>RegistrationBehaviour</code>
  7050. indicating whether the registration can go through or must be denied, or whether the user
  7051. may be allowed to register but will be shadow banned.</p>
  7052. <p>The arguments passed to this callback are:</p>
  7053. <ul>
  7054. <li><code>email_threepid</code>: The email address used for registering, if any.</li>
  7055. <li><code>username</code>: The username the user would like to register. Can be <code>None</code>, meaning that
  7056. Synapse will generate one later.</li>
  7057. <li><code>request_info</code>: A collection of tuples, which first item is a user agent, and which
  7058. second item is an IP address. These user agents and IP addresses are the ones that were
  7059. used during the registration process.</li>
  7060. <li><code>auth_provider_id</code>: The identifier of the SSO authentication provider, if any.</li>
  7061. </ul>
  7062. <pre><code class="language-python">async def check_media_file_for_spam(
  7063. file_wrapper: &quot;synapse.rest.media.v1.media_storage.ReadableFileWrapper&quot;,
  7064. file_info: &quot;synapse.rest.media.v1._base.FileInfo&quot;
  7065. ) -&gt; bool
  7066. </code></pre>
  7067. <p>Called when storing a local or remote file. The module must return a boolean indicating
  7068. whether the given file can be stored in the homeserver's media store.</p>
  7069. <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>
  7070. <p>In order to port a module that uses Synapse's old module interface, its author needs to:</p>
  7071. <ul>
  7072. <li>ensure the module's callbacks are all asynchronous.</li>
  7073. <li>register their callbacks using one or more of the <code>register_[...]_callbacks</code> methods
  7074. 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>
  7075. for more info).</li>
  7076. </ul>
  7077. <p>Additionally, if the module is packaged with an additional web resource, the module
  7078. should register this resource in its <code>__init__</code> method using the <code>register_web_resource</code>
  7079. method from the <code>ModuleApi</code> class (see <a href="modules.html#registering-a-web-resource">this section</a> for
  7080. more info).</p>
  7081. <p>The module's author should also update any example in the module's configuration to only
  7082. use the new <code>modules</code> section in Synapse's configuration file (see <a href="modules.html#using-modules">this section</a>
  7083. for more info).</p>
  7084. <h3 id="example"><a class="header" href="#example">Example</a></h3>
  7085. <p>The example below is a module that implements the spam checker callback
  7086. <code>user_may_create_room</code> to deny room creation to user <code>@evilguy:example.com</code>, and registers
  7087. a web resource to the path <code>/_synapse/client/demo/hello</code> that returns a JSON object.</p>
  7088. <pre><code class="language-python">import json
  7089. from twisted.web.resource import Resource
  7090. from twisted.web.server import Request
  7091. from synapse.module_api import ModuleApi
  7092. class DemoResource(Resource):
  7093. def __init__(self, config):
  7094. super(DemoResource, self).__init__()
  7095. self.config = config
  7096. def render_GET(self, request: Request):
  7097. name = request.args.get(b&quot;name&quot;)[0]
  7098. request.setHeader(b&quot;Content-Type&quot;, b&quot;application/json&quot;)
  7099. return json.dumps({&quot;hello&quot;: name})
  7100. class DemoModule:
  7101. def __init__(self, config: dict, api: ModuleApi):
  7102. self.config = config
  7103. self.api = api
  7104. self.api.register_web_resource(
  7105. path=&quot;/_synapse/client/demo/hello&quot;,
  7106. resource=DemoResource(self.config),
  7107. )
  7108. self.api.register_spam_checker_callbacks(
  7109. user_may_create_room=self.user_may_create_room,
  7110. )
  7111. @staticmethod
  7112. def parse_config(config):
  7113. return config
  7114. async def user_may_create_room(self, user: str) -&gt; bool:
  7115. if user == &quot;@evilguy:example.com&quot;:
  7116. return False
  7117. return True
  7118. </code></pre>
  7119. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><p><strong>Note: this page of the Synapse documentation is now deprecated. For up to date
  7120. documentation on setting up or writing a spam checker module, please see
  7121. <a href="https://matrix-org.github.io/synapse/develop/modules.html">this page</a>.</strong></p>
  7122. <h1 id="handling-spam-in-synapse"><a class="header" href="#handling-spam-in-synapse">Handling spam in Synapse</a></h1>
  7123. <p>Synapse has support to customize spam checking behavior. It can plug into a
  7124. variety of events and affect how they are presented to users on your homeserver.</p>
  7125. <p>The spam checking behavior is implemented as a Python class, which must be
  7126. able to be imported by the running Synapse.</p>
  7127. <h2 id="python-spam-checker-class"><a class="header" href="#python-spam-checker-class">Python spam checker class</a></h2>
  7128. <p>The Python class is instantiated with two objects:</p>
  7129. <ul>
  7130. <li>Any configuration (see below).</li>
  7131. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7132. </ul>
  7133. <p>It then implements methods which return a boolean to alter behavior in Synapse.
  7134. All the methods must be defined.</p>
  7135. <p>There's a generic method for checking every event (<code>check_event_for_spam</code>), as
  7136. well as some specific methods:</p>
  7137. <ul>
  7138. <li><code>user_may_invite</code></li>
  7139. <li><code>user_may_create_room</code></li>
  7140. <li><code>user_may_create_room_alias</code></li>
  7141. <li><code>user_may_publish_room</code></li>
  7142. <li><code>check_username_for_spam</code></li>
  7143. <li><code>check_registration_for_spam</code></li>
  7144. <li><code>check_media_file_for_spam</code></li>
  7145. </ul>
  7146. <p>The details of each of these methods (as well as their inputs and outputs)
  7147. are documented in the <code>synapse.events.spamcheck.SpamChecker</code> class.</p>
  7148. <p>The <code>ModuleApi</code> class provides a way for the custom spam checker class to
  7149. call back into the homeserver internals.</p>
  7150. <p>Additionally, a <code>parse_config</code> method is mandatory and receives the plugin config
  7151. dictionary. After parsing, It must return an object which will be
  7152. passed to <code>__init__</code> later.</p>
  7153. <h3 id="example-1"><a class="header" href="#example-1">Example</a></h3>
  7154. <pre><code class="language-python">from synapse.spam_checker_api import RegistrationBehaviour
  7155. class ExampleSpamChecker:
  7156. def __init__(self, config, api):
  7157. self.config = config
  7158. self.api = api
  7159. @staticmethod
  7160. def parse_config(config):
  7161. return config
  7162. async def check_event_for_spam(self, foo):
  7163. return False # allow all events
  7164. async def user_may_invite(self, inviter_userid, invitee_userid, room_id):
  7165. return True # allow all invites
  7166. async def user_may_create_room(self, userid):
  7167. return True # allow all room creations
  7168. async def user_may_create_room_alias(self, userid, room_alias):
  7169. return True # allow all room aliases
  7170. async def user_may_publish_room(self, userid, room_id):
  7171. return True # allow publishing of all rooms
  7172. async def check_username_for_spam(self, user_profile):
  7173. return False # allow all usernames
  7174. async def check_registration_for_spam(
  7175. self,
  7176. email_threepid,
  7177. username,
  7178. request_info,
  7179. auth_provider_id,
  7180. ):
  7181. return RegistrationBehaviour.ALLOW # allow all registrations
  7182. async def check_media_file_for_spam(self, file_wrapper, file_info):
  7183. return False # allow all media
  7184. </code></pre>
  7185. <h2 id="configuration-2"><a class="header" href="#configuration-2">Configuration</a></h2>
  7186. <p>Modify the <code>spam_checker</code> section of your <code>homeserver.yaml</code> in the following
  7187. manner:</p>
  7188. <p>Create a list entry with the keys <code>module</code> and <code>config</code>.</p>
  7189. <ul>
  7190. <li>
  7191. <p><code>module</code> should point to the fully qualified Python class that implements your
  7192. custom logic, e.g. <code>my_module.ExampleSpamChecker</code>.</p>
  7193. </li>
  7194. <li>
  7195. <p><code>config</code> is a dictionary that gets passed to the spam checker class.</p>
  7196. </li>
  7197. </ul>
  7198. <h3 id="example-2"><a class="header" href="#example-2">Example</a></h3>
  7199. <p>This section might look like:</p>
  7200. <pre><code class="language-yaml">spam_checker:
  7201. - module: my_module.ExampleSpamChecker
  7202. config:
  7203. # Enable or disable a specific option in ExampleSpamChecker.
  7204. my_custom_option: true
  7205. </code></pre>
  7206. <p>More spam checkers can be added in tandem by appending more items to the list. An
  7207. action is blocked when at least one of the configured spam checkers flags it.</p>
  7208. <h2 id="examples"><a class="header" href="#examples">Examples</a></h2>
  7209. <p>The <a href="https://github.com/matrix-org/mjolnir">Mjolnir</a> project is a full fledged
  7210. example using the Synapse spam checking API, including a bot for dynamic
  7211. configuration.</p>
  7212. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="presence-router-module"><a class="header" href="#presence-router-module">Presence Router Module</a></h1>
  7213. <p>Synapse supports configuring a module that can specify additional users
  7214. (local or remote) to should receive certain presence updates from local
  7215. users.</p>
  7216. <p>Note that routing presence via Application Service transactions is not
  7217. currently supported.</p>
  7218. <p>The presence routing module is implemented as a Python class, which will
  7219. be imported by the running Synapse.</p>
  7220. <h2 id="python-presence-router-class"><a class="header" href="#python-presence-router-class">Python Presence Router Class</a></h2>
  7221. <p>The Python class is instantiated with two objects:</p>
  7222. <ul>
  7223. <li>A configuration object of some type (see below).</li>
  7224. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7225. </ul>
  7226. <p>It then implements methods related to presence routing.</p>
  7227. <p>Note that one method of <code>ModuleApi</code> that may be useful is:</p>
  7228. <pre><code class="language-python">async def ModuleApi.send_local_online_presence_to(users: Iterable[str]) -&gt; None
  7229. </code></pre>
  7230. <p>which can be given a list of local or remote MXIDs to broadcast known, online user
  7231. presence to (for those users that the receiving user is considered interested in).
  7232. It does not include state for users who are currently offline, and it can only be
  7233. called on workers that support sending federation. Additionally, this method must
  7234. only be called from the process that has been configured to write to the
  7235. the <a href="workers.html#stream-writers">presence stream</a>.
  7236. By default, this is the main process, but another worker can be configured to do
  7237. so.</p>
  7238. <h3 id="module-structure"><a class="header" href="#module-structure">Module structure</a></h3>
  7239. <p>Below is a list of possible methods that can be implemented, and whether they are
  7240. required.</p>
  7241. <h4 id="parse_config"><a class="header" href="#parse_config"><code>parse_config</code></a></h4>
  7242. <pre><code class="language-python">def parse_config(config_dict: dict) -&gt; Any
  7243. </code></pre>
  7244. <p><strong>Required.</strong> A static method that is passed a dictionary of config options, and
  7245. should return a validated config object. This method is described further in
  7246. <a href="presence_router_module.html#configuration">Configuration</a>.</p>
  7247. <h4 id="get_users_for_states"><a class="header" href="#get_users_for_states"><code>get_users_for_states</code></a></h4>
  7248. <pre><code class="language-python">async def get_users_for_states(
  7249. self,
  7250. state_updates: Iterable[UserPresenceState],
  7251. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7252. </code></pre>
  7253. <p><strong>Required.</strong> An asynchronous method that is passed an iterable of user presence
  7254. state. This method can determine whether a given presence update should be sent to certain
  7255. users. It does this by returning a dictionary with keys representing local or remote
  7256. Matrix User IDs, and values being a python set
  7257. of <code>synapse.handlers.presence.UserPresenceState</code> instances.</p>
  7258. <p>Synapse will then attempt to send the specified presence updates to each user when
  7259. possible.</p>
  7260. <h4 id="get_interested_users"><a class="header" href="#get_interested_users"><code>get_interested_users</code></a></h4>
  7261. <pre><code class="language-python">async def get_interested_users(self, user_id: str) -&gt; Union[Set[str], str]
  7262. </code></pre>
  7263. <p><strong>Required.</strong> An asynchronous method that is passed a single Matrix User ID. This
  7264. method is expected to return the users that the passed in user may be interested in the
  7265. presence of. Returned users may be local or remote. The presence routed as a result of
  7266. what this method returns is sent in addition to the updates already sent between users
  7267. that share a room together. Presence updates are deduplicated.</p>
  7268. <p>This method should return a python set of Matrix User IDs, or the object
  7269. <code>synapse.events.presence_router.PresenceRouter.ALL_USERS</code> to indicate that the passed
  7270. user should receive presence information for <em>all</em> known users.</p>
  7271. <p>For clarity, if the user <code>@alice:example.org</code> is passed to this method, and the Set
  7272. <code>{&quot;@bob:example.com&quot;, &quot;@charlie:somewhere.org&quot;}</code> is returned, this signifies that Alice
  7273. should receive presence updates sent by Bob and Charlie, regardless of whether these
  7274. users share a room.</p>
  7275. <h3 id="example-3"><a class="header" href="#example-3">Example</a></h3>
  7276. <p>Below is an example implementation of a presence router class.</p>
  7277. <pre><code class="language-python">from typing import Dict, Iterable, Set, Union
  7278. from synapse.events.presence_router import PresenceRouter
  7279. from synapse.handlers.presence import UserPresenceState
  7280. from synapse.module_api import ModuleApi
  7281. class PresenceRouterConfig:
  7282. def __init__(self):
  7283. # Config options with their defaults
  7284. # A list of users to always send all user presence updates to
  7285. self.always_send_to_users = [] # type: List[str]
  7286. # A list of users to ignore presence updates for. Does not affect
  7287. # shared-room presence relationships
  7288. self.blacklisted_users = [] # type: List[str]
  7289. class ExamplePresenceRouter:
  7290. &quot;&quot;&quot;An example implementation of synapse.presence_router.PresenceRouter.
  7291. Supports routing all presence to a configured set of users, or a subset
  7292. of presence from certain users to members of certain rooms.
  7293. Args:
  7294. config: A configuration object.
  7295. module_api: An instance of Synapse's ModuleApi.
  7296. &quot;&quot;&quot;
  7297. def __init__(self, config: PresenceRouterConfig, module_api: ModuleApi):
  7298. self._config = config
  7299. self._module_api = module_api
  7300. @staticmethod
  7301. def parse_config(config_dict: dict) -&gt; PresenceRouterConfig:
  7302. &quot;&quot;&quot;Parse a configuration dictionary from the homeserver config, do
  7303. some validation and return a typed PresenceRouterConfig.
  7304. Args:
  7305. config_dict: The configuration dictionary.
  7306. Returns:
  7307. A validated config object.
  7308. &quot;&quot;&quot;
  7309. # Initialise a typed config object
  7310. config = PresenceRouterConfig()
  7311. always_send_to_users = config_dict.get(&quot;always_send_to_users&quot;)
  7312. blacklisted_users = config_dict.get(&quot;blacklisted_users&quot;)
  7313. # Do some validation of config options... otherwise raise a
  7314. # synapse.config.ConfigError.
  7315. config.always_send_to_users = always_send_to_users
  7316. config.blacklisted_users = blacklisted_users
  7317. return config
  7318. async def get_users_for_states(
  7319. self,
  7320. state_updates: Iterable[UserPresenceState],
  7321. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7322. &quot;&quot;&quot;Given an iterable of user presence updates, determine where each one
  7323. needs to go. Returned results will not affect presence updates that are
  7324. sent between users who share a room.
  7325. Args:
  7326. state_updates: An iterable of user presence state updates.
  7327. Returns:
  7328. A dictionary of user_id -&gt; set of UserPresenceState that the user should
  7329. receive.
  7330. &quot;&quot;&quot;
  7331. destination_users = {} # type: Dict[str, Set[UserPresenceState]
  7332. # Ignore any updates for blacklisted users
  7333. desired_updates = set()
  7334. for update in state_updates:
  7335. if update.state_key not in self._config.blacklisted_users:
  7336. desired_updates.add(update)
  7337. # Send all presence updates to specific users
  7338. for user_id in self._config.always_send_to_users:
  7339. destination_users[user_id] = desired_updates
  7340. return destination_users
  7341. async def get_interested_users(
  7342. self,
  7343. user_id: str,
  7344. ) -&gt; Union[Set[str], PresenceRouter.ALL_USERS]:
  7345. &quot;&quot;&quot;
  7346. Retrieve a list of users that `user_id` is interested in receiving the
  7347. presence of. This will be in addition to those they share a room with.
  7348. Optionally, the object PresenceRouter.ALL_USERS can be returned to indicate
  7349. that this user should receive all incoming local and remote presence updates.
  7350. Note that this method will only be called for local users.
  7351. Args:
  7352. user_id: A user requesting presence updates.
  7353. Returns:
  7354. A set of user IDs to return additional presence updates for, or
  7355. PresenceRouter.ALL_USERS to return presence updates for all other users.
  7356. &quot;&quot;&quot;
  7357. if user_id in self._config.always_send_to_users:
  7358. return PresenceRouter.ALL_USERS
  7359. return set()
  7360. </code></pre>
  7361. <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>
  7362. <p>Both of these methods are effectively two different sides of the same coin. The logic
  7363. regarding which users should receive updates for other users should be the same
  7364. between them.</p>
  7365. <p><code>get_users_for_states</code> is called when presence updates come in from either federation
  7366. or local users, and is used to either direct local presence to remote users, or to
  7367. wake up the sync streams of local users to collect remote presence.</p>
  7368. <p>In contrast, <code>get_interested_users</code> is used to determine the users that presence should
  7369. be fetched for when a local user is syncing. This presence is then retrieved, before
  7370. being fed through <code>get_users_for_states</code> once again, with only the syncing user's
  7371. routing information pulled from the resulting dictionary.</p>
  7372. <p>Their routing logic should thus line up, else you may run into unintended behaviour.</p>
  7373. <h2 id="configuration-3"><a class="header" href="#configuration-3">Configuration</a></h2>
  7374. <p>Once you've crafted your module and installed it into the same Python environment as
  7375. Synapse, amend your homeserver config file with the following.</p>
  7376. <pre><code class="language-yaml">presence:
  7377. enabled: true
  7378. presence_router:
  7379. module: my_module.ExamplePresenceRouter
  7380. config:
  7381. # Any configuration options for your module. The below is an example.
  7382. # of setting options for ExamplePresenceRouter.
  7383. always_send_to_users: [&quot;@presence_gobbler:example.org&quot;]
  7384. blacklisted_users:
  7385. - &quot;@alice:example.com&quot;
  7386. - &quot;@bob:example.com&quot;
  7387. ...
  7388. </code></pre>
  7389. <p>The contents of <code>config</code> will be passed as a Python dictionary to the static
  7390. <code>parse_config</code> method of your class. The object returned by this method will
  7391. then be passed to the <code>__init__</code> method of your module as <code>config</code>.</p>
  7392. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="scaling-synapse-via-workers"><a class="header" href="#scaling-synapse-via-workers">Scaling synapse via workers</a></h1>
  7393. <p>For small instances it recommended to run Synapse in the default monolith mode.
  7394. For larger instances where performance is a concern it can be helpful to split
  7395. out functionality into multiple separate python processes. These processes are
  7396. called 'workers', and are (eventually) intended to scale horizontally
  7397. independently.</p>
  7398. <p>Synapse's worker support is under active development and subject to change as
  7399. we attempt to rapidly scale ever larger Synapse instances. However we are
  7400. documenting it here to help admins needing a highly scalable Synapse instance
  7401. similar to the one running <code>matrix.org</code>.</p>
  7402. <p>All processes continue to share the same database instance, and as such,
  7403. workers only work with PostgreSQL-based Synapse deployments. SQLite should only
  7404. be used for demo purposes and any admin considering workers should already be
  7405. running PostgreSQL.</p>
  7406. <p>See also <a href="https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability">Matrix.org blog post</a>
  7407. for a higher level overview.</p>
  7408. <h2 id="main-processworker-communication"><a class="header" href="#main-processworker-communication">Main process/worker communication</a></h2>
  7409. <p>The processes communicate with each other via a Synapse-specific protocol called
  7410. 'replication' (analogous to MySQL- or Postgres-style database replication) which
  7411. feeds streams of newly written data between processes so they can be kept in
  7412. sync with the database state.</p>
  7413. <p>When configured to do so, Synapse uses a
  7414. <a href="https://redis.io/topics/pubsub">Redis pub/sub channel</a> to send the replication
  7415. stream between all configured Synapse processes. Additionally, processes may
  7416. make HTTP requests to each other, primarily for operations which need to wait
  7417. for a reply ─ such as sending an event.</p>
  7418. <p>Redis support was added in v1.13.0 with it becoming the recommended method in
  7419. v1.18.0. It replaced the old direct TCP connections (which is deprecated as of
  7420. v1.18.0) to the main process. With Redis, rather than all the workers connecting
  7421. to the main process, all the workers and the main process connect to Redis,
  7422. which relays replication commands between processes. This can give a significant
  7423. cpu saving on the main process and will be a prerequisite for upcoming
  7424. performance improvements.</p>
  7425. <p>If Redis support is enabled Synapse will use it as a shared cache, as well as a
  7426. pub/sub mechanism.</p>
  7427. <p>See the <a href="workers.html#architectural-diagram">Architectural diagram</a> section at the end for
  7428. a visualisation of what this looks like.</p>
  7429. <h2 id="setting-up-workers"><a class="header" href="#setting-up-workers">Setting up workers</a></h2>
  7430. <p>A Redis server is required to manage the communication between the processes.
  7431. The Redis server should be installed following the normal procedure for your
  7432. distribution (e.g. <code>apt install redis-server</code> on Debian). It is safe to use an
  7433. existing Redis deployment if you have one.</p>
  7434. <p>Once installed, check that Redis is running and accessible from the host running
  7435. Synapse, for example by executing <code>echo PING | nc -q1 localhost 6379</code> and seeing
  7436. a response of <code>+PONG</code>.</p>
  7437. <p>The appropriate dependencies must also be installed for Synapse. If using a
  7438. virtualenv, these can be installed with:</p>
  7439. <pre><code class="language-sh">pip install &quot;matrix-synapse[redis]&quot;
  7440. </code></pre>
  7441. <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
  7442. <code>matrix.org</code> and in the docker images at
  7443. https://hub.docker.com/r/matrixdotorg/synapse/.</p>
  7444. <p>To make effective use of the workers, you will need to configure an HTTP
  7445. reverse-proxy such as nginx or haproxy, which will direct incoming requests to
  7446. the correct worker, or to the main synapse instance. See
  7447. <a href="reverse_proxy.html">reverse_proxy.md</a> for information on setting up a reverse
  7448. proxy.</p>
  7449. <p>When using workers, each worker process has its own configuration file which
  7450. contains settings specific to that worker, such as the HTTP listener that it
  7451. provides (if any), logging configuration, etc.</p>
  7452. <p>Normally, the worker processes are configured to read from a shared
  7453. configuration file as well as the worker-specific configuration files. This
  7454. makes it easier to keep common configuration settings synchronised across all
  7455. the processes.</p>
  7456. <p>The main process is somewhat special in this respect: it does not normally
  7457. need its own configuration file and can take all of its configuration from the
  7458. shared configuration file.</p>
  7459. <h3 id="shared-configuration"><a class="header" href="#shared-configuration">Shared configuration</a></h3>
  7460. <p>Normally, only a couple of changes are needed to make an existing configuration
  7461. file suitable for use with workers. First, you need to enable an &quot;HTTP replication
  7462. listener&quot; for the main process; and secondly, you need to enable redis-based
  7463. replication. Optionally, a shared secret can be used to authenticate HTTP
  7464. traffic between workers. For example:</p>
  7465. <pre><code class="language-yaml"># extend the existing `listeners` section. This defines the ports that the
  7466. # main process will listen on.
  7467. listeners:
  7468. # The HTTP replication port
  7469. - port: 9093
  7470. bind_address: '127.0.0.1'
  7471. type: http
  7472. resources:
  7473. - names: [replication]
  7474. # Add a random shared secret to authenticate traffic.
  7475. worker_replication_secret: &quot;&quot;
  7476. redis:
  7477. enabled: true
  7478. </code></pre>
  7479. <p>See the sample config for the full documentation of each option.</p>
  7480. <p>Under <strong>no circumstances</strong> should the replication listener be exposed to the
  7481. public internet; it has no authentication and is unencrypted.</p>
  7482. <h3 id="worker-configuration"><a class="header" href="#worker-configuration">Worker configuration</a></h3>
  7483. <p>In the config file for each worker, you must specify the type of worker
  7484. application (<code>worker_app</code>), and you should specify a unique name for the worker
  7485. (<code>worker_name</code>). The currently available worker applications are listed below.
  7486. You must also specify the HTTP replication endpoint that it should talk to on
  7487. the main synapse process. <code>worker_replication_host</code> should specify the host of
  7488. the main synapse and <code>worker_replication_http_port</code> should point to the HTTP
  7489. replication port. If the worker will handle HTTP requests then the
  7490. <code>worker_listeners</code> option should be set with a <code>http</code> listener, in the same way
  7491. as the <code>listeners</code> option in the shared config.</p>
  7492. <p>For example:</p>
  7493. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  7494. worker_name: worker1
  7495. # The replication listener on the main synapse process.
  7496. worker_replication_host: 127.0.0.1
  7497. worker_replication_http_port: 9093
  7498. worker_listeners:
  7499. - type: http
  7500. port: 8083
  7501. resources:
  7502. - names:
  7503. - client
  7504. - federation
  7505. worker_log_config: /home/matrix/synapse/config/worker1_log_config.yaml
  7506. </code></pre>
  7507. <p>...is a full configuration for a generic worker instance, which will expose a
  7508. plain HTTP endpoint on port 8083 separately serving various endpoints, e.g.
  7509. <code>/sync</code>, which are listed below.</p>
  7510. <p>Obviously you should configure your reverse-proxy to route the relevant
  7511. endpoints to the worker (<code>localhost:8083</code> in the above example).</p>
  7512. <h3 id="running-synapse-with-workers"><a class="header" href="#running-synapse-with-workers">Running Synapse with workers</a></h3>
  7513. <p>Finally, you need to start your worker processes. This can be done with either
  7514. <code>synctl</code> or your distribution's preferred service manager such as <code>systemd</code>. We
  7515. recommend the use of <code>systemd</code> where available: for information on setting up
  7516. <code>systemd</code> to start synapse workers, see
  7517. <a href="systemd-with-workers">systemd-with-workers</a>. To use <code>synctl</code>, see
  7518. <a href="synctl_workers.html">synctl_workers.md</a>.</p>
  7519. <h2 id="available-worker-applications"><a class="header" href="#available-worker-applications">Available worker applications</a></h2>
  7520. <h3 id="synapseappgeneric_worker"><a class="header" href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a></h3>
  7521. <p>This worker can handle API requests matching the following regular
  7522. expressions:</p>
  7523. <pre><code># Sync requests
  7524. ^/_matrix/client/(v2_alpha|r0)/sync$
  7525. ^/_matrix/client/(api/v1|v2_alpha|r0)/events$
  7526. ^/_matrix/client/(api/v1|r0)/initialSync$
  7527. ^/_matrix/client/(api/v1|r0)/rooms/[^/]+/initialSync$
  7528. # Federation requests
  7529. ^/_matrix/federation/v1/event/
  7530. ^/_matrix/federation/v1/state/
  7531. ^/_matrix/federation/v1/state_ids/
  7532. ^/_matrix/federation/v1/backfill/
  7533. ^/_matrix/federation/v1/get_missing_events/
  7534. ^/_matrix/federation/v1/publicRooms
  7535. ^/_matrix/federation/v1/query/
  7536. ^/_matrix/federation/v1/make_join/
  7537. ^/_matrix/federation/v1/make_leave/
  7538. ^/_matrix/federation/v1/send_join/
  7539. ^/_matrix/federation/v2/send_join/
  7540. ^/_matrix/federation/v1/send_leave/
  7541. ^/_matrix/federation/v2/send_leave/
  7542. ^/_matrix/federation/v1/invite/
  7543. ^/_matrix/federation/v2/invite/
  7544. ^/_matrix/federation/v1/query_auth/
  7545. ^/_matrix/federation/v1/event_auth/
  7546. ^/_matrix/federation/v1/exchange_third_party_invite/
  7547. ^/_matrix/federation/v1/user/devices/
  7548. ^/_matrix/federation/v1/get_groups_publicised$
  7549. ^/_matrix/key/v2/query
  7550. # Inbound federation transaction request
  7551. ^/_matrix/federation/v1/send/
  7552. # Client API requests
  7553. ^/_matrix/client/(api/v1|r0|unstable)/publicRooms$
  7554. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/joined_members$
  7555. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/context/.*$
  7556. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/members$
  7557. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state$
  7558. ^/_matrix/client/(api/v1|r0|unstable)/account/3pid$
  7559. ^/_matrix/client/(api/v1|r0|unstable)/devices$
  7560. ^/_matrix/client/(api/v1|r0|unstable)/keys/query$
  7561. ^/_matrix/client/(api/v1|r0|unstable)/keys/changes$
  7562. ^/_matrix/client/versions$
  7563. ^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$
  7564. ^/_matrix/client/(api/v1|r0|unstable)/joined_groups$
  7565. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups$
  7566. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups/
  7567. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/event/
  7568. ^/_matrix/client/(api/v1|r0|unstable)/joined_rooms$
  7569. ^/_matrix/client/(api/v1|r0|unstable)/search$
  7570. # Registration/login requests
  7571. ^/_matrix/client/(api/v1|r0|unstable)/login$
  7572. ^/_matrix/client/(r0|unstable)/register$
  7573. # Event sending requests
  7574. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/redact
  7575. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/send
  7576. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state/
  7577. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
  7578. ^/_matrix/client/(api/v1|r0|unstable)/join/
  7579. ^/_matrix/client/(api/v1|r0|unstable)/profile/
  7580. </code></pre>
  7581. <p>Additionally, the following REST endpoints can be handled for GET requests:</p>
  7582. <pre><code>^/_matrix/federation/v1/groups/
  7583. </code></pre>
  7584. <p>Pagination requests can also be handled, but all requests for a given
  7585. room must be routed to the same instance. Additionally, care must be taken to
  7586. ensure that the purge history admin API is not used while pagination requests
  7587. for the room are in flight:</p>
  7588. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/messages$
  7589. </code></pre>
  7590. <p>Additionally, the following endpoints should be included if Synapse is configured
  7591. to use SSO (you only need to include the ones for whichever SSO provider you're
  7592. using):</p>
  7593. <pre><code># for all SSO providers
  7594. ^/_matrix/client/(api/v1|r0|unstable)/login/sso/redirect
  7595. ^/_synapse/client/pick_idp$
  7596. ^/_synapse/client/pick_username
  7597. ^/_synapse/client/new_user_consent$
  7598. ^/_synapse/client/sso_register$
  7599. # OpenID Connect requests.
  7600. ^/_synapse/client/oidc/callback$
  7601. # SAML requests.
  7602. ^/_synapse/client/saml2/authn_response$
  7603. # CAS requests.
  7604. ^/_matrix/client/(api/v1|r0|unstable)/login/cas/ticket$
  7605. </code></pre>
  7606. <p>Ensure that all SSO logins go to a single process.
  7607. For multiple workers not handling the SSO endpoints properly, see
  7608. <a href="https://github.com/matrix-org/synapse/issues/7530">#7530</a> and
  7609. <a href="https://github.com/matrix-org/synapse/issues/9427">#9427</a>.</p>
  7610. <p>Note that a HTTP listener with <code>client</code> and <code>federation</code> resources must be
  7611. configured in the <code>worker_listeners</code> option in the worker config.</p>
  7612. <h4 id="load-balancing"><a class="header" href="#load-balancing">Load balancing</a></h4>
  7613. <p>It is possible to run multiple instances of this worker app, with incoming requests
  7614. being load-balanced between them by the reverse-proxy. However, different endpoints
  7615. have different characteristics and so admins
  7616. may wish to run multiple groups of workers handling different endpoints so that
  7617. load balancing can be done in different ways.</p>
  7618. <p>For <code>/sync</code> and <code>/initialSync</code> requests it will be more efficient if all
  7619. requests from a particular user are routed to a single instance. Extracting a
  7620. user ID from the access token or <code>Authorization</code> header is currently left as an
  7621. exercise for the reader. Admins may additionally wish to separate out <code>/sync</code>
  7622. requests that have a <code>since</code> query parameter from those that don't (and
  7623. <code>/initialSync</code>), as requests that don't are known as &quot;initial sync&quot; that happens
  7624. when a user logs in on a new device and can be <em>very</em> resource intensive, so
  7625. isolating these requests will stop them from interfering with other users ongoing
  7626. syncs.</p>
  7627. <p>Federation and client requests can be balanced via simple round robin.</p>
  7628. <p>The inbound federation transaction request <code>^/_matrix/federation/v1/send/</code>
  7629. should be balanced by source IP so that transactions from the same remote server
  7630. go to the same process.</p>
  7631. <p>Registration/login requests can be handled separately purely to help ensure that
  7632. unexpected load doesn't affect new logins and sign ups.</p>
  7633. <p>Finally, event sending requests can be balanced by the room ID in the URI (or
  7634. the full URI, or even just round robin), the room ID is the path component after
  7635. <code>/rooms/</code>. If there is a large bridge connected that is sending or may send lots
  7636. of events, then a dedicated set of workers can be provisioned to limit the
  7637. effects of bursts of events from that bridge on events sent by normal users.</p>
  7638. <h4 id="stream-writers"><a class="header" href="#stream-writers">Stream writers</a></h4>
  7639. <p>Additionally, there is <em>experimental</em> support for moving writing of specific
  7640. streams (such as events) off of the main process to a particular worker. (This
  7641. is only supported with Redis-based replication.)</p>
  7642. <p>Currently supported streams are <code>events</code> and <code>typing</code>.</p>
  7643. <p>To enable this, the worker must have a HTTP replication listener configured,
  7644. have a <code>worker_name</code> and be listed in the <code>instance_map</code> config. For example to
  7645. move event persistence off to a dedicated worker, the shared configuration would
  7646. include:</p>
  7647. <pre><code class="language-yaml">instance_map:
  7648. event_persister1:
  7649. host: localhost
  7650. port: 8034
  7651. stream_writers:
  7652. events: event_persister1
  7653. </code></pre>
  7654. <p>The <code>events</code> stream also experimentally supports having multiple writers, where
  7655. work is sharded between them by room ID. Note that you <em>must</em> restart all worker
  7656. instances when adding or removing event persisters. An example <code>stream_writers</code>
  7657. configuration with multiple writers:</p>
  7658. <pre><code class="language-yaml">stream_writers:
  7659. events:
  7660. - event_persister1
  7661. - event_persister2
  7662. </code></pre>
  7663. <h4 id="background-tasks"><a class="header" href="#background-tasks">Background tasks</a></h4>
  7664. <p>There is also <em>experimental</em> support for moving background tasks to a separate
  7665. worker. Background tasks are run periodically or started via replication. Exactly
  7666. which tasks are configured to run depends on your Synapse configuration (e.g. if
  7667. stats is enabled).</p>
  7668. <p>To enable this, the worker must have a <code>worker_name</code> and can be configured to run
  7669. background tasks. For example, to move background tasks to a dedicated worker,
  7670. the shared configuration would include:</p>
  7671. <pre><code class="language-yaml">run_background_tasks_on: background_worker
  7672. </code></pre>
  7673. <p>You might also wish to investigate the <code>update_user_directory</code> and
  7674. <code>media_instance_running_background_jobs</code> settings.</p>
  7675. <h3 id="synapseapppusher"><a class="header" href="#synapseapppusher"><code>synapse.app.pusher</code></a></h3>
  7676. <p>Handles sending push notifications to sygnal and email. Doesn't handle any
  7677. REST endpoints itself, but you should set <code>start_pushers: False</code> in the
  7678. shared configuration file to stop the main synapse sending push notifications.</p>
  7679. <p>To run multiple instances at once the <code>pusher_instances</code> option should list all
  7680. pusher instances by their worker name, e.g.:</p>
  7681. <pre><code class="language-yaml">pusher_instances:
  7682. - pusher_worker1
  7683. - pusher_worker2
  7684. </code></pre>
  7685. <h3 id="synapseappappservice"><a class="header" href="#synapseappappservice"><code>synapse.app.appservice</code></a></h3>
  7686. <p>Handles sending output traffic to Application Services. Doesn't handle any
  7687. REST endpoints itself, but you should set <code>notify_appservices: False</code> in the
  7688. shared configuration file to stop the main synapse sending appservice notifications.</p>
  7689. <p>Note this worker cannot be load-balanced: only one instance should be active.</p>
  7690. <h3 id="synapseappfederation_sender"><a class="header" href="#synapseappfederation_sender"><code>synapse.app.federation_sender</code></a></h3>
  7691. <p>Handles sending federation traffic to other servers. Doesn't handle any
  7692. REST endpoints itself, but you should set <code>send_federation: False</code> in the
  7693. shared configuration file to stop the main synapse sending this traffic.</p>
  7694. <p>If running multiple federation senders then you must list each
  7695. instance in the <code>federation_sender_instances</code> option by their <code>worker_name</code>.
  7696. All instances must be stopped and started when adding or removing instances.
  7697. For example:</p>
  7698. <pre><code class="language-yaml">federation_sender_instances:
  7699. - federation_sender1
  7700. - federation_sender2
  7701. </code></pre>
  7702. <h3 id="synapseappmedia_repository"><a class="header" href="#synapseappmedia_repository"><code>synapse.app.media_repository</code></a></h3>
  7703. <p>Handles the media repository. It can handle all endpoints starting with:</p>
  7704. <pre><code>/_matrix/media/
  7705. </code></pre>
  7706. <p>... and the following regular expressions matching media-specific administration APIs:</p>
  7707. <pre><code>^/_synapse/admin/v1/purge_media_cache$
  7708. ^/_synapse/admin/v1/room/.*/media.*$
  7709. ^/_synapse/admin/v1/user/.*/media.*$
  7710. ^/_synapse/admin/v1/media/.*$
  7711. ^/_synapse/admin/v1/quarantine_media/.*$
  7712. </code></pre>
  7713. <p>You should also set <code>enable_media_repo: False</code> in the shared configuration
  7714. file to stop the main synapse running background jobs related to managing the
  7715. media repository.</p>
  7716. <p>In the <code>media_repository</code> worker configuration file, configure the http listener to
  7717. expose the <code>media</code> resource. For example:</p>
  7718. <pre><code class="language-yaml"> worker_listeners:
  7719. - type: http
  7720. port: 8085
  7721. resources:
  7722. - names:
  7723. - media
  7724. </code></pre>
  7725. <p>Note that if running multiple media repositories they must be on the same server
  7726. and you must configure a single instance to run the background tasks, e.g.:</p>
  7727. <pre><code class="language-yaml"> media_instance_running_background_jobs: &quot;media-repository-1&quot;
  7728. </code></pre>
  7729. <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>
  7730. <h3 id="synapseappuser_dir"><a class="header" href="#synapseappuser_dir"><code>synapse.app.user_dir</code></a></h3>
  7731. <p>Handles searches in the user directory. It can handle REST endpoints matching
  7732. the following regular expressions:</p>
  7733. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$
  7734. </code></pre>
  7735. <p>When using this worker you must also set <code>update_user_directory: False</code> in the
  7736. shared configuration file to stop the main synapse running background
  7737. jobs related to updating the user directory.</p>
  7738. <h3 id="synapseappfrontend_proxy"><a class="header" href="#synapseappfrontend_proxy"><code>synapse.app.frontend_proxy</code></a></h3>
  7739. <p>Proxies some frequently-requested client endpoints to add caching and remove
  7740. load from the main synapse. It can handle REST endpoints matching the following
  7741. regular expressions:</p>
  7742. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/keys/upload
  7743. </code></pre>
  7744. <p>If <code>use_presence</code> is False in the homeserver config, it can also handle REST
  7745. endpoints matching the following regular expressions:</p>
  7746. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/presence/[^/]+/status
  7747. </code></pre>
  7748. <p>This &quot;stub&quot; presence handler will pass through <code>GET</code> request but make the
  7749. <code>PUT</code> effectively a no-op.</p>
  7750. <p>It will proxy any requests it cannot handle to the main synapse instance. It
  7751. must therefore be configured with the location of the main instance, via
  7752. the <code>worker_main_http_uri</code> setting in the <code>frontend_proxy</code> worker configuration
  7753. file. For example:</p>
  7754. <pre><code>worker_main_http_uri: http://127.0.0.1:8008
  7755. </code></pre>
  7756. <h3 id="historical-apps"><a class="header" href="#historical-apps">Historical apps</a></h3>
  7757. <p><em>Note:</em> Historically there used to be more apps, however they have been
  7758. amalgamated into a single <code>synapse.app.generic_worker</code> app. The remaining apps
  7759. are ones that do specific processing unrelated to requests, e.g. the <code>pusher</code>
  7760. that handles sending out push notifications for new events. The intention is for
  7761. all these to be folded into the <code>generic_worker</code> app and to use config to define
  7762. which processes handle the various proccessing such as push notifications.</p>
  7763. <h2 id="migration-from-old-config"><a class="header" href="#migration-from-old-config">Migration from old config</a></h2>
  7764. <p>There are two main independent changes that have been made: introducing Redis
  7765. support and merging apps into <code>synapse.app.generic_worker</code>. Both these changes
  7766. are backwards compatible and so no changes to the config are required, however
  7767. server admins are encouraged to plan to migrate to Redis as the old style direct
  7768. TCP replication config is deprecated.</p>
  7769. <p>To migrate to Redis add the <code>redis</code> config as above, and optionally remove the
  7770. TCP <code>replication</code> listener from master and <code>worker_replication_port</code> from worker
  7771. config.</p>
  7772. <p>To migrate apps to use <code>synapse.app.generic_worker</code> simply update the
  7773. <code>worker_app</code> option in the worker configs, and where worker are started (e.g.
  7774. in systemd service files, but not required for synctl).</p>
  7775. <h2 id="architectural-diagram"><a class="header" href="#architectural-diagram">Architectural diagram</a></h2>
  7776. <p>The following shows an example setup using Redis and a reverse proxy:</p>
  7777. <pre><code> Clients &amp; Federation
  7778. |
  7779. v
  7780. +-----------+
  7781. | |
  7782. | Reverse |
  7783. | Proxy |
  7784. | |
  7785. +-----------+
  7786. | | |
  7787. | | | HTTP requests
  7788. +-------------------+ | +-----------+
  7789. | +---+ |
  7790. | | |
  7791. v v v
  7792. +--------------+ +--------------+ +--------------+ +--------------+
  7793. | Main | | Generic | | Generic | | Event |
  7794. | Process | | Worker 1 | | Worker 2 | | Persister |
  7795. +--------------+ +--------------+ +--------------+ +--------------+
  7796. ^ ^ | ^ | | ^ | ^ ^
  7797. | | | | | | | | | |
  7798. | | | | | HTTP | | | | |
  7799. | +----------+&lt;--|---|---------+ | | | |
  7800. | | +-------------|--&gt;+----------+ |
  7801. | | | |
  7802. | | | |
  7803. v v v v
  7804. ====================================================================
  7805. Redis pub/sub channel
  7806. </code></pre>
  7807. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h3 id="using-synctl-with-workers"><a class="header" href="#using-synctl-with-workers">Using synctl with workers</a></h3>
  7808. <p>If you want to use <code>synctl</code> to manage your synapse processes, you will need to
  7809. create an an additional configuration file for the main synapse process. That
  7810. configuration should look like this:</p>
  7811. <pre><code class="language-yaml">worker_app: synapse.app.homeserver
  7812. </code></pre>
  7813. <p>Additionally, each worker app must be configured with the name of a &quot;pid file&quot;,
  7814. to which it will write its process ID when it starts. For example, for a
  7815. synchrotron, you might write:</p>
  7816. <pre><code class="language-yaml">worker_pid_file: /home/matrix/synapse/worker1.pid
  7817. </code></pre>
  7818. <p>Finally, to actually run your worker-based synapse, you must pass synctl the <code>-a</code>
  7819. commandline option to tell it to operate on all the worker configurations found
  7820. in the given directory, e.g.:</p>
  7821. <pre><code>synctl -a $CONFIG/workers start
  7822. </code></pre>
  7823. <p>Currently one should always restart all workers when restarting or upgrading
  7824. synapse, unless you explicitly know it's safe not to. For instance, restarting
  7825. synapse without restarting all the synchrotrons may result in broken typing
  7826. notifications.</p>
  7827. <p>To manipulate a specific worker, you pass the -w option to synctl:</p>
  7828. <pre><code>synctl -w $CONFIG/workers/worker1.yaml restart
  7829. </code></pre>
  7830. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="setting-up-synapse-with-workers-and-systemd"><a class="header" href="#setting-up-synapse-with-workers-and-systemd">Setting up Synapse with Workers and Systemd</a></h1>
  7831. <p>This is a setup for managing synapse with systemd, including support for
  7832. managing workers. It provides a <code>matrix-synapse</code> service for the master, as
  7833. well as a <code>matrix-synapse-worker@</code> service template for any workers you
  7834. require. Additionally, to group the required services, it sets up a
  7835. <code>matrix-synapse.target</code>.</p>
  7836. <p>See the folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/system/">system</a>
  7837. for the systemd unit files.</p>
  7838. <p>The folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/workers/">workers</a>
  7839. contains an example configuration for the <code>federation_reader</code> worker.</p>
  7840. <h2 id="synapse-configuration-files"><a class="header" href="#synapse-configuration-files">Synapse configuration files</a></h2>
  7841. <p>See <a href="systemd-with-workers/../workers.html">workers.md</a> for information on how to set up the
  7842. configuration files and reverse-proxy correctly. You can find an example worker
  7843. config in the <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/workers/">workers</a>
  7844. folder.</p>
  7845. <p>Systemd manages daemonization itself, so ensure that none of the configuration
  7846. files set either <code>daemonize</code> or <code>worker_daemonize</code>.</p>
  7847. <p>The config files of all workers are expected to be located in
  7848. <code>/etc/matrix-synapse/workers</code>. If you want to use a different location, edit
  7849. the provided <code>*.service</code> files accordingly.</p>
  7850. <p>There is no need for a separate configuration file for the master process.</p>
  7851. <h2 id="set-up"><a class="header" href="#set-up">Set up</a></h2>
  7852. <ol>
  7853. <li>Adjust synapse configuration files as above.</li>
  7854. <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>
  7855. to <code>/etc/systemd/system</code>.</li>
  7856. <li>Run <code>systemctl daemon-reload</code> to tell systemd to load the new unit files.</li>
  7857. <li>Run <code>systemctl enable matrix-synapse.service</code>. This will configure the
  7858. synapse master process to be started as part of the <code>matrix-synapse.target</code>
  7859. target.</li>
  7860. <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
  7861. should be a corresponding configuration file.
  7862. <code>/etc/matrix-synapse/workers/&lt;worker_name&gt;.yaml</code>.</li>
  7863. <li>Start all the synapse processes with <code>systemctl start matrix-synapse.target</code>.</li>
  7864. <li>Tell systemd to start synapse on boot with <code>systemctl enable matrix-synapse.target</code>.</li>
  7865. </ol>
  7866. <h2 id="usage"><a class="header" href="#usage">Usage</a></h2>
  7867. <p>Once the services are correctly set up, you can use the following commands
  7868. to manage your synapse installation:</p>
  7869. <pre><code class="language-sh"># Restart Synapse master and all workers
  7870. systemctl restart matrix-synapse.target
  7871. # Stop Synapse and all workers
  7872. systemctl stop matrix-synapse.target
  7873. # Restart the master alone
  7874. systemctl start matrix-synapse.service
  7875. # Restart a specific worker (eg. federation_reader); the master is
  7876. # unaffected by this.
  7877. systemctl restart matrix-synapse-worker@federation_reader.service
  7878. # Add a new worker (assuming all configs are set up already)
  7879. systemctl enable matrix-synapse-worker@federation_writer.service
  7880. systemctl restart matrix-synapse.target
  7881. </code></pre>
  7882. <h2 id="hardening"><a class="header" href="#hardening">Hardening</a></h2>
  7883. <p><strong>Optional:</strong> If further hardening is desired, the file
  7884. <code>override-hardened.conf</code> may be copied from
  7885. <code>contrib/systemd/override-hardened.conf</code> in this repository to the location
  7886. <code>/etc/systemd/system/matrix-synapse.service.d/override-hardened.conf</code> (the
  7887. directory may have to be created). It enables certain sandboxing features in
  7888. systemd to further secure the synapse service. You may read the comments to
  7889. understand what the override file is doing. The same file will need to be copied
  7890. to
  7891. <code>/etc/systemd/system/matrix-synapse-worker@.service.d/override-hardened-worker.conf</code>
  7892. (this directory may also have to be created) in order to apply the same
  7893. hardening options to any worker processes.</p>
  7894. <p>Once these files have been copied to their appropriate locations, simply reload
  7895. systemd's manager config files and restart all Synapse services to apply the hardening options. They will automatically
  7896. be applied at every restart as long as the override files are present at the
  7897. specified locations.</p>
  7898. <pre><code class="language-sh">systemctl daemon-reload
  7899. # Restart services
  7900. systemctl restart matrix-synapse.target
  7901. </code></pre>
  7902. <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
  7903. the changes being applied at a glance.</p>
  7904. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="administration"><a class="header" href="#administration">Administration</a></h1>
  7905. <p>This section contains information on managing your Synapse homeserver. This includes:</p>
  7906. <ul>
  7907. <li>Managing users, rooms and media via the Admin API.</li>
  7908. <li>Setting up metrics and monitoring to give you insight into your homeserver's health.</li>
  7909. <li>Configuring structured logging.</li>
  7910. </ul>
  7911. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="the-admin-api"><a class="header" href="#the-admin-api">The Admin API</a></h1>
  7912. <h2 id="authenticate-as-a-server-admin"><a class="header" href="#authenticate-as-a-server-admin">Authenticate as a server admin</a></h2>
  7913. <p>Many of the API calls in the admin api will require an <code>access_token</code> for a
  7914. server admin. (Note that a server admin is distinct from a room admin.)</p>
  7915. <p>A user can be marked as a server admin by updating the database directly, e.g.:</p>
  7916. <pre><code class="language-sql">UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
  7917. </code></pre>
  7918. <p>A new server admin user can also be created using the <code>register_new_matrix_user</code>
  7919. command. This is a script that is located in the <code>scripts/</code> directory, or possibly
  7920. already on your <code>$PATH</code> depending on how Synapse was installed.</p>
  7921. <p>Finding your user's <code>access_token</code> is client-dependent, but will usually be shown in the client's settings.</p>
  7922. <h2 id="making-an-admin-api-request"><a class="header" href="#making-an-admin-api-request">Making an Admin API request</a></h2>
  7923. <p>Once you have your <code>access_token</code>, you will need to authenticate each request to an Admin API endpoint by
  7924. providing the token as either a query parameter or a request header. To add it as a request header in cURL:</p>
  7925. <pre><code class="language-sh">curl --header &quot;Authorization: Bearer &lt;access_token&gt;&quot; &lt;the_rest_of_your_API_request&gt;
  7926. </code></pre>
  7927. <p>For more details on access tokens in Matrix, please refer to the complete
  7928. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#using-access-tokens">matrix spec documentation</a>.</p>
  7929. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="account-validity-api"><a class="header" href="#account-validity-api">Account validity API</a></h1>
  7930. <p>This API allows a server administrator to manage the validity of an account. To
  7931. use it, you must enable the account validity feature (under
  7932. <code>account_validity</code>) in Synapse's configuration.</p>
  7933. <h2 id="renew-account"><a class="header" href="#renew-account">Renew account</a></h2>
  7934. <p>This API extends the validity of an account by as much time as configured in the
  7935. <code>period</code> parameter from the <code>account_validity</code> configuration.</p>
  7936. <p>The API is:</p>
  7937. <pre><code>POST /_synapse/admin/v1/account_validity/validity
  7938. </code></pre>
  7939. <p>with the following body:</p>
  7940. <pre><code class="language-json">{
  7941. &quot;user_id&quot;: &quot;&lt;user ID for the account to renew&gt;&quot;,
  7942. &quot;expiration_ts&quot;: 0,
  7943. &quot;enable_renewal_emails&quot;: true
  7944. }
  7945. </code></pre>
  7946. <p><code>expiration_ts</code> is an optional parameter and overrides the expiration date,
  7947. which otherwise defaults to now + validity period.</p>
  7948. <p><code>enable_renewal_emails</code> is also an optional parameter and enables/disables
  7949. sending renewal emails to the user. Defaults to true.</p>
  7950. <p>The API returns with the new expiration date for this account, as a timestamp in
  7951. milliseconds since epoch:</p>
  7952. <pre><code class="language-json">{
  7953. &quot;expiration_ts&quot;: 0
  7954. }
  7955. </code></pre>
  7956. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="delete-a-local-group"><a class="header" href="#delete-a-local-group">Delete a local group</a></h1>
  7957. <p>This API lets a server admin delete a local group. Doing so will kick all
  7958. users out of the group so that their clients will correctly handle the group
  7959. being deleted.</p>
  7960. <p>The API is:</p>
  7961. <pre><code>POST /_synapse/admin/v1/delete_group/&lt;group_id&gt;
  7962. </code></pre>
  7963. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  7964. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  7965. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="show-reported-events"><a class="header" href="#show-reported-events">Show reported events</a></h1>
  7966. <p>This API returns information about reported events.</p>
  7967. <p>The api is:</p>
  7968. <pre><code>GET /_synapse/admin/v1/event_reports?from=0&amp;limit=10
  7969. </code></pre>
  7970. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  7971. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  7972. <p>It returns a JSON body like the following:</p>
  7973. <pre><code class="language-json">{
  7974. &quot;event_reports&quot;: [
  7975. {
  7976. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  7977. &quot;id&quot;: 2,
  7978. &quot;reason&quot;: &quot;foo&quot;,
  7979. &quot;score&quot;: -100,
  7980. &quot;received_ts&quot;: 1570897107409,
  7981. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  7982. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  7983. &quot;name&quot;: &quot;Matrix HQ&quot;,
  7984. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  7985. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  7986. },
  7987. {
  7988. &quot;event_id&quot;: &quot;$3IcdZsDaN_En-S1DF4EMCy3v4gNRKeOJs8W5qTOKj4I&quot;,
  7989. &quot;id&quot;: 3,
  7990. &quot;reason&quot;: &quot;bar&quot;,
  7991. &quot;score&quot;: -100,
  7992. &quot;received_ts&quot;: 1598889612059,
  7993. &quot;canonical_alias&quot;: &quot;#alias2:matrix.org&quot;,
  7994. &quot;room_id&quot;: &quot;!eGvUQuTCkHGVwNMOjv:matrix.org&quot;,
  7995. &quot;name&quot;: &quot;Your room name here&quot;,
  7996. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  7997. &quot;user_id&quot;: &quot;@bar:matrix.org&quot;
  7998. }
  7999. ],
  8000. &quot;next_token&quot;: 2,
  8001. &quot;total&quot;: 4
  8002. }
  8003. </code></pre>
  8004. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again with <code>from</code>
  8005. set to the value of <code>next_token</code>. This will return a new page.</p>
  8006. <p>If the endpoint does not return a <code>next_token</code> then there are no more reports to
  8007. paginate through.</p>
  8008. <p><strong>URL parameters:</strong></p>
  8009. <ul>
  8010. <li><code>limit</code>: integer - Is optional but is used for pagination, denoting the maximum number
  8011. of items to return in this call. Defaults to <code>100</code>.</li>
  8012. <li><code>from</code>: integer - Is optional but used for pagination, denoting the offset in the
  8013. returned results. This should be treated as an opaque value and not explicitly set to
  8014. anything other than the return value of <code>next_token</code> from a previous call. Defaults to <code>0</code>.</li>
  8015. <li><code>dir</code>: string - Direction of event report order. Whether to fetch the most recent
  8016. first (<code>b</code>) or the oldest first (<code>f</code>). Defaults to <code>b</code>.</li>
  8017. <li><code>user_id</code>: string - Is optional and filters to only return users with user IDs that
  8018. contain this value. This is the user who reported the event and wrote the reason.</li>
  8019. <li><code>room_id</code>: string - Is optional and filters to only return rooms with room IDs that
  8020. contain this value.</li>
  8021. </ul>
  8022. <p><strong>Response</strong></p>
  8023. <p>The following fields are returned in the JSON response body:</p>
  8024. <ul>
  8025. <li><code>id</code>: integer - ID of event report.</li>
  8026. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8027. report was sent.</li>
  8028. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8029. <li><code>name</code>: string - The name of the room.</li>
  8030. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8031. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8032. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank or <code>null</code>.</li>
  8033. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8034. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;. May be <code>null</code>.</li>
  8035. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8036. was reported.</li>
  8037. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8038. have a canonical alias set.</li>
  8039. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  8040. <li><code>total</code>: integer - Total number of event reports related to the query
  8041. (<code>user_id</code> and <code>room_id</code>).</li>
  8042. </ul>
  8043. <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>
  8044. <p>This API returns information about a specific event report.</p>
  8045. <p>The api is:</p>
  8046. <pre><code>GET /_synapse/admin/v1/event_reports/&lt;report_id&gt;
  8047. </code></pre>
  8048. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8049. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8050. <p>It returns a JSON body like the following:</p>
  8051. <pre><code class="language-jsonc">{
  8052. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8053. &quot;event_json&quot;: {
  8054. &quot;auth_events&quot;: [
  8055. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;,
  8056. &quot;$oggsNXxzPFRE3y53SUNd7nsj69-QzKv03a1RucHu-ws&quot;
  8057. ],
  8058. &quot;content&quot;: {
  8059. &quot;body&quot;: &quot;matrix.org: This Week in Matrix&quot;,
  8060. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  8061. &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;,
  8062. &quot;msgtype&quot;: &quot;m.notice&quot;
  8063. },
  8064. &quot;depth&quot;: 546,
  8065. &quot;hashes&quot;: {
  8066. &quot;sha256&quot;: &quot;xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw&quot;
  8067. },
  8068. &quot;origin&quot;: &quot;matrix.org&quot;,
  8069. &quot;origin_server_ts&quot;: 1592291711430,
  8070. &quot;prev_events&quot;: [
  8071. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;
  8072. ],
  8073. &quot;prev_state&quot;: [],
  8074. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8075. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8076. &quot;signatures&quot;: {
  8077. &quot;matrix.org&quot;: {
  8078. &quot;ed25519:a_JaEG&quot;: &quot;cs+OUKW/iHx5pEidbWxh0UiNNHwe46Ai9LwNz+Ah16aWDNszVIe2gaAcVZfvNsBhakQTew51tlKmL2kspXk/Dg&quot;
  8079. }
  8080. },
  8081. &quot;type&quot;: &quot;m.room.message&quot;,
  8082. &quot;unsigned&quot;: {
  8083. &quot;age_ts&quot;: 1592291711430,
  8084. }
  8085. },
  8086. &quot;id&quot;: &lt;report_id&gt;,
  8087. &quot;reason&quot;: &quot;foo&quot;,
  8088. &quot;score&quot;: -100,
  8089. &quot;received_ts&quot;: 1570897107409,
  8090. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8091. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8092. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8093. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8094. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8095. }
  8096. </code></pre>
  8097. <p><strong>URL parameters:</strong></p>
  8098. <ul>
  8099. <li><code>report_id</code>: string - The ID of the event report.</li>
  8100. </ul>
  8101. <p><strong>Response</strong></p>
  8102. <p>The following fields are returned in the JSON response body:</p>
  8103. <ul>
  8104. <li><code>id</code>: integer - ID of event report.</li>
  8105. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8106. report was sent.</li>
  8107. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8108. <li><code>name</code>: string - The name of the room.</li>
  8109. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8110. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8111. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank.</li>
  8112. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8113. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;.</li>
  8114. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8115. was reported.</li>
  8116. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8117. have a canonical alias set.</li>
  8118. <li><code>event_json</code>: object - Details of the original event that was reported.</li>
  8119. </ul>
  8120. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="contents-1"><a class="header" href="#contents-1">Contents</a></h1>
  8121. <ul>
  8122. <li><a href="admin_api/media_admin_api.html#querying-media">Querying media</a>
  8123. <ul>
  8124. <li><a href="admin_api/media_admin_api.html#list-all-media-in-a-room">List all media in a room</a></li>
  8125. <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>
  8126. </ul>
  8127. </li>
  8128. <li><a href="admin_api/media_admin_api.html#quarantine-media">Quarantine media</a>
  8129. <ul>
  8130. <li><a href="admin_api/media_admin_api.html#quarantining-media-by-id">Quarantining media by ID</a></li>
  8131. <li><a href="admin_api/media_admin_api.html#remove-media-from-quarantine-by-id">Remove media from quarantine by ID</a></li>
  8132. <li><a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">Quarantining media in a room</a></li>
  8133. <li><a href="admin_api/media_admin_api.html#quarantining-all-media-of-a-user">Quarantining all media of a user</a></li>
  8134. <li><a href="admin_api/media_admin_api.html#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></li>
  8135. <li><a href="admin_api/media_admin_api.html#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></li>
  8136. </ul>
  8137. </li>
  8138. <li><a href="admin_api/media_admin_api.html#delete-local-media">Delete local media</a>
  8139. <ul>
  8140. <li><a href="admin_api/media_admin_api.html#delete-a-specific-local-media">Delete a specific local media</a></li>
  8141. <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>
  8142. </ul>
  8143. </li>
  8144. <li><a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a></li>
  8145. </ul>
  8146. <h1 id="querying-media"><a class="header" href="#querying-media">Querying media</a></h1>
  8147. <p>These APIs allow extracting media information from the homeserver.</p>
  8148. <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>
  8149. <p>This API gets a list of known media in a room.
  8150. However, it only shows media from unencrypted events or rooms.</p>
  8151. <p>The API is:</p>
  8152. <pre><code>GET /_synapse/admin/v1/room/&lt;room_id&gt;/media
  8153. </code></pre>
  8154. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8155. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8156. <p>The API returns a JSON body like the following:</p>
  8157. <pre><code class="language-json">{
  8158. &quot;local&quot;: [
  8159. &quot;mxc://localhost/xwvutsrqponmlkjihgfedcba&quot;,
  8160. &quot;mxc://localhost/abcdefghijklmnopqrstuvwx&quot;
  8161. ],
  8162. &quot;remote&quot;: [
  8163. &quot;mxc://matrix.org/xwvutsrqponmlkjihgfedcba&quot;,
  8164. &quot;mxc://matrix.org/abcdefghijklmnopqrstuvwx&quot;
  8165. ]
  8166. }
  8167. </code></pre>
  8168. <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>
  8169. <p>Listing all media that has been uploaded by a local user can be achieved through
  8170. the use of the <a href="admin_api/user_admin_api.rst#list-media-of-a-user">List media of a user</a>
  8171. Admin API.</p>
  8172. <h1 id="quarantine-media"><a class="header" href="#quarantine-media">Quarantine media</a></h1>
  8173. <p>Quarantining media means that it is marked as inaccessible by users. It applies
  8174. to any local media, and any locally-cached copies of remote media.</p>
  8175. <p>The media file itself (and any thumbnails) is not deleted from the server.</p>
  8176. <h2 id="quarantining-media-by-id"><a class="header" href="#quarantining-media-by-id">Quarantining media by ID</a></h2>
  8177. <p>This API quarantines a single piece of local or remote media.</p>
  8178. <p>Request:</p>
  8179. <pre><code>POST /_synapse/admin/v1/media/quarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8180. {}
  8181. </code></pre>
  8182. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8183. form of <code>abcdefg12345...</code>.</p>
  8184. <p>Response:</p>
  8185. <pre><code class="language-json">{}
  8186. </code></pre>
  8187. <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>
  8188. <p>This API removes a single piece of local or remote media from quarantine.</p>
  8189. <p>Request:</p>
  8190. <pre><code>POST /_synapse/admin/v1/media/unquarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8191. {}
  8192. </code></pre>
  8193. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8194. form of <code>abcdefg12345...</code>.</p>
  8195. <p>Response:</p>
  8196. <pre><code class="language-json">{}
  8197. </code></pre>
  8198. <h2 id="quarantining-media-in-a-room"><a class="header" href="#quarantining-media-in-a-room">Quarantining media in a room</a></h2>
  8199. <p>This API quarantines all local and remote media in a room.</p>
  8200. <p>Request:</p>
  8201. <pre><code>POST /_synapse/admin/v1/room/&lt;room_id&gt;/media/quarantine
  8202. {}
  8203. </code></pre>
  8204. <p>Where <code>room_id</code> is in the form of <code>!roomid12345:example.org</code>.</p>
  8205. <p>Response:</p>
  8206. <pre><code class="language-json">{
  8207. &quot;num_quarantined&quot;: 10
  8208. }
  8209. </code></pre>
  8210. <p>The following fields are returned in the JSON response body:</p>
  8211. <ul>
  8212. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8213. </ul>
  8214. <p>Note that there is a legacy endpoint, <code>POST /_synapse/admin/v1/quarantine_media/&lt;room_id&gt;</code>, that operates the same.
  8215. However, it is deprecated and may be removed in a future release.</p>
  8216. <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>
  8217. <p>This API quarantines all <em>local</em> media that a <em>local</em> user has uploaded. That is to say, if
  8218. you would like to quarantine media uploaded by a user on a remote homeserver, you should
  8219. instead use one of the other APIs.</p>
  8220. <p>Request:</p>
  8221. <pre><code>POST /_synapse/admin/v1/user/&lt;user_id&gt;/media/quarantine
  8222. {}
  8223. </code></pre>
  8224. <p>URL Parameters</p>
  8225. <ul>
  8226. <li><code>user_id</code>: string - User ID in the form of <code>@bob:example.org</code></li>
  8227. </ul>
  8228. <p>Response:</p>
  8229. <pre><code class="language-json">{
  8230. &quot;num_quarantined&quot;: 10
  8231. }
  8232. </code></pre>
  8233. <p>The following fields are returned in the JSON response body:</p>
  8234. <ul>
  8235. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8236. </ul>
  8237. <h2 id="protecting-media-from-being-quarantined"><a class="header" href="#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></h2>
  8238. <p>This API protects a single piece of local media from being quarantined using the
  8239. above APIs. This is useful for sticker packs and other shared media which you do
  8240. not want to get quarantined, especially when
  8241. <a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">quarantining media in a room</a>.</p>
  8242. <p>Request:</p>
  8243. <pre><code>POST /_synapse/admin/v1/media/protect/&lt;media_id&gt;
  8244. {}
  8245. </code></pre>
  8246. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8247. <p>Response:</p>
  8248. <pre><code class="language-json">{}
  8249. </code></pre>
  8250. <h2 id="unprotecting-media-from-being-quarantined"><a class="header" href="#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></h2>
  8251. <p>This API reverts the protection of a media.</p>
  8252. <p>Request:</p>
  8253. <pre><code>POST /_synapse/admin/v1/media/unprotect/&lt;media_id&gt;
  8254. {}
  8255. </code></pre>
  8256. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8257. <p>Response:</p>
  8258. <pre><code class="language-json">{}
  8259. </code></pre>
  8260. <h1 id="delete-local-media"><a class="header" href="#delete-local-media">Delete local media</a></h1>
  8261. <p>This API deletes the <em>local</em> media from the disk of your own server.
  8262. This includes any local thumbnails and copies of media downloaded from
  8263. remote homeservers.
  8264. This API will not affect media that has been uploaded to external
  8265. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
  8266. See also <a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a>.</p>
  8267. <h2 id="delete-a-specific-local-media"><a class="header" href="#delete-a-specific-local-media">Delete a specific local media</a></h2>
  8268. <p>Delete a specific <code>media_id</code>.</p>
  8269. <p>Request:</p>
  8270. <pre><code>DELETE /_synapse/admin/v1/media/&lt;server_name&gt;/&lt;media_id&gt;
  8271. {}
  8272. </code></pre>
  8273. <p>URL Parameters</p>
  8274. <ul>
  8275. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>)</li>
  8276. <li><code>media_id</code>: string - The ID of the media (e.g <code>abcdefghijklmnopqrstuvwx</code>)</li>
  8277. </ul>
  8278. <p>Response:</p>
  8279. <pre><code class="language-json">{
  8280. &quot;deleted_media&quot;: [
  8281. &quot;abcdefghijklmnopqrstuvwx&quot;
  8282. ],
  8283. &quot;total&quot;: 1
  8284. }
  8285. </code></pre>
  8286. <p>The following fields are returned in the JSON response body:</p>
  8287. <ul>
  8288. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8289. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8290. </ul>
  8291. <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>
  8292. <p>Request:</p>
  8293. <pre><code>POST /_synapse/admin/v1/media/&lt;server_name&gt;/delete?before_ts=&lt;before_ts&gt;
  8294. {}
  8295. </code></pre>
  8296. <p>URL Parameters</p>
  8297. <ul>
  8298. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>).</li>
  8299. <li><code>before_ts</code>: string representing a positive integer - Unix timestamp in ms.
  8300. Files that were last used before this timestamp will be deleted. It is the timestamp of
  8301. last access and not the timestamp creation. </li>
  8302. <li><code>size_gt</code>: Optional - string representing a positive integer - Size of the media in bytes.
  8303. Files that are larger will be deleted. Defaults to <code>0</code>.</li>
  8304. <li><code>keep_profiles</code>: Optional - string representing a boolean - Switch to also delete files
  8305. that are still used in image data (e.g user profile, room avatar).
  8306. If <code>false</code> these files will be deleted. Defaults to <code>true</code>.</li>
  8307. </ul>
  8308. <p>Response:</p>
  8309. <pre><code class="language-json">{
  8310. &quot;deleted_media&quot;: [
  8311. &quot;abcdefghijklmnopqrstuvwx&quot;,
  8312. &quot;abcdefghijklmnopqrstuvwz&quot;
  8313. ],
  8314. &quot;total&quot;: 2
  8315. }
  8316. </code></pre>
  8317. <p>The following fields are returned in the JSON response body:</p>
  8318. <ul>
  8319. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8320. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8321. </ul>
  8322. <h1 id="purge-remote-media-api"><a class="header" href="#purge-remote-media-api">Purge Remote Media API</a></h1>
  8323. <p>The purge remote media API allows server admins to purge old cached remote media.</p>
  8324. <p>The API is:</p>
  8325. <pre><code>POST /_synapse/admin/v1/purge_media_cache?before_ts=&lt;unix_timestamp_in_ms&gt;
  8326. {}
  8327. </code></pre>
  8328. <p>URL Parameters</p>
  8329. <ul>
  8330. <li><code>unix_timestamp_in_ms</code>: string representing a positive integer - Unix timestamp in ms.
  8331. All cached media that was last accessed before this timestamp will be removed.</li>
  8332. </ul>
  8333. <p>Response:</p>
  8334. <pre><code class="language-json">{
  8335. &quot;deleted&quot;: 10
  8336. }
  8337. </code></pre>
  8338. <p>The following fields are returned in the JSON response body:</p>
  8339. <ul>
  8340. <li><code>deleted</code>: integer - The number of media items successfully deleted</li>
  8341. </ul>
  8342. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8343. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8344. <p>If the user re-requests purged remote media, synapse will re-request the media
  8345. from the originating server.</p>
  8346. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="purge-history-api"><a class="header" href="#purge-history-api">Purge History API</a></h1>
  8347. <p>The purge history API allows server admins to purge historic events from their
  8348. database, reclaiming disk space.</p>
  8349. <p>Depending on the amount of history being purged a call to the API may take
  8350. several minutes or longer. During this period users will not be able to
  8351. paginate further back in the room from the point being purged from.</p>
  8352. <p>Note that Synapse requires at least one message in each room, so it will never
  8353. delete the last message in a room.</p>
  8354. <p>The API is:</p>
  8355. <pre><code>POST /_synapse/admin/v1/purge_history/&lt;room_id&gt;[/&lt;event_id&gt;]
  8356. </code></pre>
  8357. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8358. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  8359. <p>By default, events sent by local users are not deleted, as they may represent
  8360. the only copies of this content in existence. (Events sent by remote users are
  8361. deleted.)</p>
  8362. <p>Room state data (such as joins, leaves, topic) is always preserved.</p>
  8363. <p>To delete local message events as well, set <code>delete_local_events</code> in the body:</p>
  8364. <pre><code>{
  8365. &quot;delete_local_events&quot;: true
  8366. }
  8367. </code></pre>
  8368. <p>The caller must specify the point in the room to purge up to. This can be
  8369. specified by including an event_id in the URI, or by setting a
  8370. <code>purge_up_to_event_id</code> or <code>purge_up_to_ts</code> in the request body. If an event
  8371. id is given, that event (and others at the same graph depth) will be retained.
  8372. If <code>purge_up_to_ts</code> is given, it should be a timestamp since the unix epoch,
  8373. in milliseconds.</p>
  8374. <p>The API starts the purge running, and returns immediately with a JSON body with
  8375. a purge id:</p>
  8376. <pre><code class="language-json">{
  8377. &quot;purge_id&quot;: &quot;&lt;opaque id&gt;&quot;
  8378. }
  8379. </code></pre>
  8380. <h2 id="purge-status-query"><a class="header" href="#purge-status-query">Purge status query</a></h2>
  8381. <p>It is possible to poll for updates on recent purges with a second API;</p>
  8382. <pre><code>GET /_synapse/admin/v1/purge_history_status/&lt;purge_id&gt;
  8383. </code></pre>
  8384. <p>Again, you will need to authenticate by providing an <code>access_token</code> for a
  8385. server admin.</p>
  8386. <p>This API returns a JSON body like the following:</p>
  8387. <pre><code class="language-json">{
  8388. &quot;status&quot;: &quot;active&quot;
  8389. }
  8390. </code></pre>
  8391. <p>The status will be one of <code>active</code>, <code>complete</code>, or <code>failed</code>.</p>
  8392. <h2 id="reclaim-disk-space-postgres"><a class="header" href="#reclaim-disk-space-postgres">Reclaim disk space (Postgres)</a></h2>
  8393. <p>To reclaim the disk space and return it to the operating system, you need to run
  8394. <code>VACUUM FULL;</code> on the database.</p>
  8395. <p><a href="https://www.postgresql.org/docs/current/sql-vacuum.html">https://www.postgresql.org/docs/current/sql-vacuum.html</a></p>
  8396. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="deprecated-purge-room-api"><a class="header" href="#deprecated-purge-room-api">Deprecated: Purge room API</a></h1>
  8397. <p><strong>The old Purge room API is deprecated and will be removed in a future release.
  8398. See the new <a href="admin_api/rooms.html#delete-room-api">Delete Room API</a> for more details.</strong></p>
  8399. <p>This API will remove all trace of a room from your database.</p>
  8400. <p>All local users must have left the room before it can be removed.</p>
  8401. <p>The API is:</p>
  8402. <pre><code>POST /_synapse/admin/v1/purge_room
  8403. {
  8404. &quot;room_id&quot;: &quot;!room:id&quot;
  8405. }
  8406. </code></pre>
  8407. <p>You must authenticate using the access token of an admin user.</p>
  8408. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="shared-secret-registration"><a class="header" href="#shared-secret-registration">Shared-Secret Registration</a></h1>
  8409. <p>This API allows for the creation of users in an administrative and
  8410. non-interactive way. This is generally used for bootstrapping a Synapse
  8411. instance with administrator accounts.</p>
  8412. <p>To authenticate yourself to the server, you will need both the shared secret
  8413. (<code>registration_shared_secret</code> in the homeserver configuration), and a
  8414. one-time nonce. If the registration shared secret is not configured, this API
  8415. is not enabled.</p>
  8416. <p>To fetch the nonce, you need to request one from the API:</p>
  8417. <pre><code>&gt; GET /_synapse/admin/v1/register
  8418. &lt; {&quot;nonce&quot;: &quot;thisisanonce&quot;}
  8419. </code></pre>
  8420. <p>Once you have the nonce, you can make a <code>POST</code> to the same URL with a JSON
  8421. body containing the nonce, username, password, whether they are an admin
  8422. (optional, False by default), and a HMAC digest of the content. Also you can
  8423. set the displayname (optional, <code>username</code> by default).</p>
  8424. <p>As an example:</p>
  8425. <pre><code>&gt; POST /_synapse/admin/v1/register
  8426. &gt; {
  8427. &quot;nonce&quot;: &quot;thisisanonce&quot;,
  8428. &quot;username&quot;: &quot;pepper_roni&quot;,
  8429. &quot;displayname&quot;: &quot;Pepper Roni&quot;,
  8430. &quot;password&quot;: &quot;pizza&quot;,
  8431. &quot;admin&quot;: true,
  8432. &quot;mac&quot;: &quot;mac_digest_here&quot;
  8433. }
  8434. &lt; {
  8435. &quot;access_token&quot;: &quot;token_here&quot;,
  8436. &quot;user_id&quot;: &quot;@pepper_roni:localhost&quot;,
  8437. &quot;home_server&quot;: &quot;test&quot;,
  8438. &quot;device_id&quot;: &quot;device_id_here&quot;
  8439. }
  8440. </code></pre>
  8441. <p>The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
  8442. the shared secret and the content being the nonce, user, password, either the
  8443. string &quot;admin&quot; or &quot;notadmin&quot;, and optionally the user_type
  8444. each separated by NULs. For an example of generation in Python:</p>
  8445. <pre><code class="language-python">import hmac, hashlib
  8446. def generate_mac(nonce, user, password, admin=False, user_type=None):
  8447. mac = hmac.new(
  8448. key=shared_secret,
  8449. digestmod=hashlib.sha1,
  8450. )
  8451. mac.update(nonce.encode('utf8'))
  8452. mac.update(b&quot;\x00&quot;)
  8453. mac.update(user.encode('utf8'))
  8454. mac.update(b&quot;\x00&quot;)
  8455. mac.update(password.encode('utf8'))
  8456. mac.update(b&quot;\x00&quot;)
  8457. mac.update(b&quot;admin&quot; if admin else b&quot;notadmin&quot;)
  8458. if user_type:
  8459. mac.update(b&quot;\x00&quot;)
  8460. mac.update(user_type.encode('utf8'))
  8461. return mac.hexdigest()
  8462. </code></pre>
  8463. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="edit-room-membership-api"><a class="header" href="#edit-room-membership-api">Edit Room Membership API</a></h1>
  8464. <p>This API allows an administrator to join an user account with a given <code>user_id</code>
  8465. to a room with a given <code>room_id_or_alias</code>. You can only modify the membership of
  8466. local users. The server administrator must be in the room and have permission to
  8467. invite users.</p>
  8468. <h2 id="parameters"><a class="header" href="#parameters">Parameters</a></h2>
  8469. <p>The following parameters are available:</p>
  8470. <ul>
  8471. <li><code>user_id</code> - Fully qualified user: for example, <code>@user:server.com</code>.</li>
  8472. <li><code>room_id_or_alias</code> - The room identifier or alias to join: for example,
  8473. <code>!636q39766251:server.com</code>.</li>
  8474. </ul>
  8475. <h2 id="usage-1"><a class="header" href="#usage-1">Usage</a></h2>
  8476. <pre><code>POST /_synapse/admin/v1/join/&lt;room_id_or_alias&gt;
  8477. {
  8478. &quot;user_id&quot;: &quot;@user:server.com&quot;
  8479. }
  8480. </code></pre>
  8481. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8482. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8483. <p>Response:</p>
  8484. <pre><code>{
  8485. &quot;room_id&quot;: &quot;!636q39766251:server.com&quot;
  8486. }
  8487. </code></pre>
  8488. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="contents-2"><a class="header" href="#contents-2">Contents</a></h1>
  8489. <ul>
  8490. <li><a href="admin_api/rooms.html#list-room-api">List Room API</a>
  8491. <ul>
  8492. <li><a href="admin_api/rooms.html#parameters">Parameters</a></li>
  8493. <li><a href="admin_api/rooms.html#usage">Usage</a></li>
  8494. </ul>
  8495. </li>
  8496. <li><a href="admin_api/rooms.html#room-details-api">Room Details API</a></li>
  8497. <li><a href="admin_api/rooms.html#room-members-api">Room Members API</a></li>
  8498. <li><a href="admin_api/rooms.html#room-state-api">Room State API</a></li>
  8499. <li><a href="admin_api/rooms.html#delete-room-api">Delete Room API</a>
  8500. <ul>
  8501. <li><a href="admin_api/rooms.html#parameters-1">Parameters</a></li>
  8502. <li><a href="admin_api/rooms.html#response">Response</a></li>
  8503. <li><a href="admin_api/rooms.html#undoing-room-shutdowns">Undoing room shutdowns</a></li>
  8504. </ul>
  8505. </li>
  8506. <li><a href="admin_api/rooms.html#make-room-admin-api">Make Room Admin API</a></li>
  8507. <li><a href="admin_api/rooms.html#forward-extremities-admin-api">Forward Extremities Admin API</a></li>
  8508. <li><a href="admin_api/rooms.html#event-context-api">Event Context API</a></li>
  8509. </ul>
  8510. <h1 id="list-room-api"><a class="header" href="#list-room-api">List Room API</a></h1>
  8511. <p>The List Room admin API allows server admins to get a list of rooms on their
  8512. server. There are various parameters available that allow for filtering and
  8513. sorting the returned list. This API supports pagination.</p>
  8514. <h2 id="parameters-1"><a class="header" href="#parameters-1">Parameters</a></h2>
  8515. <p>The following query parameters are available:</p>
  8516. <ul>
  8517. <li><code>from</code> - Offset in the returned list. Defaults to <code>0</code>.</li>
  8518. <li><code>limit</code> - Maximum amount of rooms to return. Defaults to <code>100</code>.</li>
  8519. <li><code>order_by</code> - The method in which to sort the returned list of rooms. Valid values are:
  8520. <ul>
  8521. <li><code>alphabetical</code> - Same as <code>name</code>. This is deprecated.</li>
  8522. <li><code>size</code> - Same as <code>joined_members</code>. This is deprecated.</li>
  8523. <li><code>name</code> - Rooms are ordered alphabetically by room name. This is the default.</li>
  8524. <li><code>canonical_alias</code> - Rooms are ordered alphabetically by main alias address of the room.</li>
  8525. <li><code>joined_members</code> - Rooms are ordered by the number of members. Largest to smallest.</li>
  8526. <li><code>joined_local_members</code> - Rooms are ordered by the number of local members. Largest to smallest.</li>
  8527. <li><code>version</code> - Rooms are ordered by room version. Largest to smallest.</li>
  8528. <li><code>creator</code> - Rooms are ordered alphabetically by creator of the room.</li>
  8529. <li><code>encryption</code> - Rooms are ordered alphabetically by the end-to-end encryption algorithm.</li>
  8530. <li><code>federatable</code> - Rooms are ordered by whether the room is federatable.</li>
  8531. <li><code>public</code> - Rooms are ordered by visibility in room list.</li>
  8532. <li><code>join_rules</code> - Rooms are ordered alphabetically by join rules of the room.</li>
  8533. <li><code>guest_access</code> - Rooms are ordered alphabetically by guest access option of the room.</li>
  8534. <li><code>history_visibility</code> - Rooms are ordered alphabetically by visibility of history of the room.</li>
  8535. <li><code>state_events</code> - Rooms are ordered by number of state events. Largest to smallest.</li>
  8536. </ul>
  8537. </li>
  8538. <li><code>dir</code> - Direction of room order. Either <code>f</code> for forwards or <code>b</code> for backwards. Setting
  8539. this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  8540. <li><code>search_term</code> - Filter rooms by their room name. Search term can be contained in any
  8541. part of the room name. Defaults to no filtering.</li>
  8542. </ul>
  8543. <p>The following fields are possible in the JSON response body:</p>
  8544. <ul>
  8545. <li><code>rooms</code> - An array of objects, each containing information about a room.
  8546. <ul>
  8547. <li>Room objects contain the following fields:
  8548. <ul>
  8549. <li><code>room_id</code> - The ID of the room.</li>
  8550. <li><code>name</code> - The name of the room.</li>
  8551. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  8552. <li><code>joined_members</code> - How many users are currently in the room.</li>
  8553. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  8554. <li><code>version</code> - The version of the room as a string.</li>
  8555. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  8556. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  8557. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  8558. <li><code>public</code> - Whether the room is visible in room directory.</li>
  8559. <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>
  8560. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  8561. <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>
  8562. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  8563. </ul>
  8564. </li>
  8565. </ul>
  8566. </li>
  8567. <li><code>offset</code> - The current pagination offset in rooms. This parameter should be
  8568. used instead of <code>next_token</code> for room offset as <code>next_token</code> is
  8569. not intended to be parsed.</li>
  8570. <li><code>total_rooms</code> - The total number of rooms this query can return. Using this
  8571. and <code>offset</code>, you have enough information to know the current
  8572. progression through the list.</li>
  8573. <li><code>next_batch</code> - If this field is present, we know that there are potentially
  8574. more rooms on the server that did not all fit into this response.
  8575. We can use <code>next_batch</code> to get the &quot;next page&quot; of results. To do
  8576. so, simply repeat your request, setting the <code>from</code> parameter to
  8577. the value of <code>next_batch</code>.</li>
  8578. <li><code>prev_batch</code> - If this field is present, it is possible to paginate backwards.
  8579. Use <code>prev_batch</code> for the <code>from</code> value in the next request to
  8580. get the &quot;previous page&quot; of results.</li>
  8581. </ul>
  8582. <h2 id="usage-2"><a class="header" href="#usage-2">Usage</a></h2>
  8583. <p>A standard request with no filtering:</p>
  8584. <pre><code>GET /_synapse/admin/v1/rooms
  8585. {}
  8586. </code></pre>
  8587. <p>Response:</p>
  8588. <pre><code class="language-jsonc">{
  8589. &quot;rooms&quot;: [
  8590. {
  8591. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  8592. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8593. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  8594. &quot;joined_members&quot;: 8326,
  8595. &quot;joined_local_members&quot;: 2,
  8596. &quot;version&quot;: &quot;1&quot;,
  8597. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8598. &quot;encryption&quot;: null,
  8599. &quot;federatable&quot;: true,
  8600. &quot;public&quot;: true,
  8601. &quot;join_rules&quot;: &quot;invite&quot;,
  8602. &quot;guest_access&quot;: null,
  8603. &quot;history_visibility&quot;: &quot;shared&quot;,
  8604. &quot;state_events&quot;: 93534
  8605. },
  8606. ... (8 hidden items) ...
  8607. {
  8608. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8609. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8610. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8611. &quot;joined_members&quot;: 314,
  8612. &quot;joined_local_members&quot;: 20,
  8613. &quot;version&quot;: &quot;4&quot;,
  8614. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8615. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8616. &quot;federatable&quot;: true,
  8617. &quot;public&quot;: false,
  8618. &quot;join_rules&quot;: &quot;invite&quot;,
  8619. &quot;guest_access&quot;: null,
  8620. &quot;history_visibility&quot;: &quot;shared&quot;,
  8621. &quot;state_events&quot;: 8345
  8622. }
  8623. ],
  8624. &quot;offset&quot;: 0,
  8625. &quot;total_rooms&quot;: 10
  8626. }
  8627. </code></pre>
  8628. <p>Filtering by room name:</p>
  8629. <pre><code>GET /_synapse/admin/v1/rooms?search_term=TWIM
  8630. {}
  8631. </code></pre>
  8632. <p>Response:</p>
  8633. <pre><code class="language-json">{
  8634. &quot;rooms&quot;: [
  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;: 8
  8650. }
  8651. ],
  8652. &quot;offset&quot;: 0,
  8653. &quot;total_rooms&quot;: 1
  8654. }
  8655. </code></pre>
  8656. <p>Paginating through a list of rooms:</p>
  8657. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size
  8658. {}
  8659. </code></pre>
  8660. <p>Response:</p>
  8661. <pre><code class="language-jsonc">{
  8662. &quot;rooms&quot;: [
  8663. {
  8664. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  8665. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8666. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  8667. &quot;joined_members&quot;: 8326,
  8668. &quot;joined_local_members&quot;: 2,
  8669. &quot;version&quot;: &quot;1&quot;,
  8670. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8671. &quot;encryption&quot;: null,
  8672. &quot;federatable&quot;: true,
  8673. &quot;public&quot;: true,
  8674. &quot;join_rules&quot;: &quot;invite&quot;,
  8675. &quot;guest_access&quot;: null,
  8676. &quot;history_visibility&quot;: &quot;shared&quot;,
  8677. &quot;state_events&quot;: 93534
  8678. },
  8679. ... (98 hidden items) ...
  8680. {
  8681. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  8682. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  8683. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  8684. &quot;joined_members&quot;: 314,
  8685. &quot;joined_local_members&quot;: 20,
  8686. &quot;version&quot;: &quot;4&quot;,
  8687. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8688. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  8689. &quot;federatable&quot;: true,
  8690. &quot;public&quot;: false,
  8691. &quot;join_rules&quot;: &quot;invite&quot;,
  8692. &quot;guest_access&quot;: null,
  8693. &quot;history_visibility&quot;: &quot;shared&quot;,
  8694. &quot;state_events&quot;: 8345
  8695. }
  8696. ],
  8697. &quot;offset&quot;: 0,
  8698. &quot;total_rooms&quot;: 150
  8699. &quot;next_token&quot;: 100
  8700. }
  8701. </code></pre>
  8702. <p>The presence of the <code>next_token</code> parameter tells us that there are more rooms
  8703. than returned in this request, and we need to make another request to get them.
  8704. To get the next batch of room results, we repeat our request, setting the <code>from</code>
  8705. parameter to the value of <code>next_token</code>.</p>
  8706. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size&amp;from=100
  8707. {}
  8708. </code></pre>
  8709. <p>Response:</p>
  8710. <pre><code class="language-jsonc">{
  8711. &quot;rooms&quot;: [
  8712. {
  8713. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  8714. &quot;name&quot;: &quot;Music Theory&quot;,
  8715. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  8716. &quot;joined_members&quot;: 127,
  8717. &quot;joined_local_members&quot;: 2,
  8718. &quot;version&quot;: &quot;1&quot;,
  8719. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8720. &quot;encryption&quot;: null,
  8721. &quot;federatable&quot;: true,
  8722. &quot;public&quot;: true,
  8723. &quot;join_rules&quot;: &quot;invite&quot;,
  8724. &quot;guest_access&quot;: null,
  8725. &quot;history_visibility&quot;: &quot;shared&quot;,
  8726. &quot;state_events&quot;: 93534
  8727. },
  8728. ... (48 hidden items) ...
  8729. {
  8730. &quot;room_id&quot;: &quot;!twcBhHVdZlQWuuxBhN:termina.org.uk&quot;,
  8731. &quot;name&quot;: &quot;weechat-matrix&quot;,
  8732. &quot;canonical_alias&quot;: &quot;#weechat-matrix:termina.org.uk&quot;,
  8733. &quot;joined_members&quot;: 137,
  8734. &quot;joined_local_members&quot;: 20,
  8735. &quot;version&quot;: &quot;4&quot;,
  8736. &quot;creator&quot;: &quot;@foo:termina.org.uk&quot;,
  8737. &quot;encryption&quot;: null,
  8738. &quot;federatable&quot;: true,
  8739. &quot;public&quot;: true,
  8740. &quot;join_rules&quot;: &quot;invite&quot;,
  8741. &quot;guest_access&quot;: null,
  8742. &quot;history_visibility&quot;: &quot;shared&quot;,
  8743. &quot;state_events&quot;: 8345
  8744. }
  8745. ],
  8746. &quot;offset&quot;: 100,
  8747. &quot;prev_batch&quot;: 0,
  8748. &quot;total_rooms&quot;: 150
  8749. }
  8750. </code></pre>
  8751. <p>Once the <code>next_token</code> parameter is no longer present, we know we've reached the
  8752. end of the list.</p>
  8753. <h1 id="room-details-api"><a class="header" href="#room-details-api">Room Details API</a></h1>
  8754. <p>The Room Details admin API allows server admins to get all details of a room.</p>
  8755. <p>The following fields are possible in the JSON response body:</p>
  8756. <ul>
  8757. <li><code>room_id</code> - The ID of the room.</li>
  8758. <li><code>name</code> - The name of the room.</li>
  8759. <li><code>topic</code> - The topic of the room.</li>
  8760. <li><code>avatar</code> - The <code>mxc</code> URI to the avatar of the room.</li>
  8761. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  8762. <li><code>joined_members</code> - How many users are currently in the room.</li>
  8763. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  8764. <li><code>joined_local_devices</code> - How many local devices are currently in the room.</li>
  8765. <li><code>version</code> - The version of the room as a string.</li>
  8766. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  8767. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  8768. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  8769. <li><code>public</code> - Whether the room is visible in room directory.</li>
  8770. <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>
  8771. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  8772. <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>
  8773. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  8774. </ul>
  8775. <h2 id="usage-3"><a class="header" href="#usage-3">Usage</a></h2>
  8776. <p>A standard request:</p>
  8777. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;
  8778. {}
  8779. </code></pre>
  8780. <p>Response:</p>
  8781. <pre><code class="language-json">{
  8782. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  8783. &quot;name&quot;: &quot;Music Theory&quot;,
  8784. &quot;avatar&quot;: &quot;mxc://matrix.org/AQDaVFlbkQoErdOgqWRgiGSV&quot;,
  8785. &quot;topic&quot;: &quot;Theory, Composition, Notation, Analysis&quot;,
  8786. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  8787. &quot;joined_members&quot;: 127,
  8788. &quot;joined_local_members&quot;: 2,
  8789. &quot;joined_local_devices&quot;: 2,
  8790. &quot;version&quot;: &quot;1&quot;,
  8791. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  8792. &quot;encryption&quot;: null,
  8793. &quot;federatable&quot;: true,
  8794. &quot;public&quot;: true,
  8795. &quot;join_rules&quot;: &quot;invite&quot;,
  8796. &quot;guest_access&quot;: null,
  8797. &quot;history_visibility&quot;: &quot;shared&quot;,
  8798. &quot;state_events&quot;: 93534
  8799. }
  8800. </code></pre>
  8801. <h1 id="room-members-api"><a class="header" href="#room-members-api">Room Members API</a></h1>
  8802. <p>The Room Members admin API allows server admins to get a list of all members of a room.</p>
  8803. <p>The response includes the following fields:</p>
  8804. <ul>
  8805. <li><code>members</code> - A list of all the members that are present in the room, represented by their ids.</li>
  8806. <li><code>total</code> - Total number of members in the room.</li>
  8807. </ul>
  8808. <h2 id="usage-4"><a class="header" href="#usage-4">Usage</a></h2>
  8809. <p>A standard request:</p>
  8810. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/members
  8811. {}
  8812. </code></pre>
  8813. <p>Response:</p>
  8814. <pre><code class="language-json">{
  8815. &quot;members&quot;: [
  8816. &quot;@foo:matrix.org&quot;,
  8817. &quot;@bar:matrix.org&quot;,
  8818. &quot;@foobar:matrix.org&quot;
  8819. ],
  8820. &quot;total&quot;: 3
  8821. }
  8822. </code></pre>
  8823. <h1 id="room-state-api"><a class="header" href="#room-state-api">Room State API</a></h1>
  8824. <p>The Room State admin API allows server admins to get a list of all state events in a room.</p>
  8825. <p>The response includes the following fields:</p>
  8826. <ul>
  8827. <li><code>state</code> - The current state of the room at the time of request.</li>
  8828. </ul>
  8829. <h2 id="usage-5"><a class="header" href="#usage-5">Usage</a></h2>
  8830. <p>A standard request:</p>
  8831. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/state
  8832. {}
  8833. </code></pre>
  8834. <p>Response:</p>
  8835. <pre><code class="language-json">{
  8836. &quot;state&quot;: [
  8837. {&quot;type&quot;: &quot;m.room.create&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  8838. {&quot;type&quot;: &quot;m.room.power_levels&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  8839. {&quot;type&quot;: &quot;m.room.name&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true}
  8840. ]
  8841. }
  8842. </code></pre>
  8843. <h1 id="delete-room-api"><a class="header" href="#delete-room-api">Delete Room API</a></h1>
  8844. <p>The Delete Room admin API allows server admins to remove rooms from server
  8845. and block these rooms.</p>
  8846. <p>Shuts down a room. Moves all local users and room aliases automatically to a
  8847. new room if <code>new_room_user_id</code> is set. Otherwise local users only
  8848. leave the room without any information.</p>
  8849. <p>The new room will be created with the user specified by the <code>new_room_user_id</code> parameter
  8850. as room administrator and will contain a message explaining what happened. Users invited
  8851. to the new room will have power level <code>-10</code> by default, and thus be unable to speak.</p>
  8852. <p>If <code>block</code> is <code>True</code> it prevents new joins to the old room.</p>
  8853. <p>This API will remove all trace of the old room from your database after removing
  8854. all local users. If <code>purge</code> is <code>true</code> (the default), all traces of the old room will
  8855. be removed from your database after removing all local users. If you do not want
  8856. this to happen, set <code>purge</code> to <code>false</code>.
  8857. Depending on the amount of history being purged a call to the API may take
  8858. several minutes or longer.</p>
  8859. <p>The local server will only have the power to move local user and room aliases to
  8860. the new room. Users on other servers will be unaffected.</p>
  8861. <p>The API is:</p>
  8862. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id&gt;
  8863. </code></pre>
  8864. <p>with a body of:</p>
  8865. <pre><code class="language-json">{
  8866. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  8867. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  8868. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;,
  8869. &quot;block&quot;: true,
  8870. &quot;purge&quot;: true
  8871. }
  8872. </code></pre>
  8873. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8874. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8875. <p>A response body like the following is returned:</p>
  8876. <pre><code class="language-json">{
  8877. &quot;kicked_users&quot;: [
  8878. &quot;@foobar:example.com&quot;
  8879. ],
  8880. &quot;failed_to_kick_users&quot;: [],
  8881. &quot;local_aliases&quot;: [
  8882. &quot;#badroom:example.com&quot;,
  8883. &quot;#evilsaloon:example.com&quot;
  8884. ],
  8885. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;
  8886. }
  8887. </code></pre>
  8888. <h2 id="parameters-2"><a class="header" href="#parameters-2">Parameters</a></h2>
  8889. <p>The following parameters should be set in the URL:</p>
  8890. <ul>
  8891. <li><code>room_id</code> - The ID of the room.</li>
  8892. </ul>
  8893. <p>The following JSON body parameters are available:</p>
  8894. <ul>
  8895. <li><code>new_room_user_id</code> - Optional. If set, a new room will be created with this user ID
  8896. as the creator and admin, and all users in the old room will be moved into that
  8897. room. If not set, no new room will be created and the users will just be removed
  8898. from the old room. The user ID must be on the local server, but does not necessarily
  8899. have to belong to a registered user.</li>
  8900. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  8901. invited to. Defaults to <code>Content Violation Notification</code></li>
  8902. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  8903. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  8904. 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>
  8905. <li><code>block</code> - Optional. If set to <code>true</code>, this room will be added to a blocking list, preventing
  8906. future attempts to join the room. Defaults to <code>false</code>.</li>
  8907. <li><code>purge</code> - Optional. If set to <code>true</code>, it will remove all traces of the room from your database.
  8908. Defaults to <code>true</code>.</li>
  8909. <li><code>force_purge</code> - Optional, and ignored unless <code>purge</code> is <code>true</code>. If set to <code>true</code>, it
  8910. will force a purge to go ahead even if there are local users still in the room. Do not
  8911. use this unless a regular <code>purge</code> operation fails, as it could leave those users'
  8912. clients in a confused state.</li>
  8913. </ul>
  8914. <p>The JSON body must not be empty. The body must be at least <code>{}</code>.</p>
  8915. <h2 id="response"><a class="header" href="#response">Response</a></h2>
  8916. <p>The following fields are returned in the JSON response body:</p>
  8917. <ul>
  8918. <li><code>kicked_users</code> - An array of users (<code>user_id</code>) that were kicked.</li>
  8919. <li><code>failed_to_kick_users</code> - An array of users (<code>user_id</code>) that that were not kicked.</li>
  8920. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  8921. the old room to the new.</li>
  8922. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  8923. </ul>
  8924. <h2 id="undoing-room-shutdowns"><a class="header" href="#undoing-room-shutdowns">Undoing room shutdowns</a></h2>
  8925. <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,
  8926. the structure can and does change without notice.</p>
  8927. <p>First, it's important to understand that a room shutdown is very destructive. Undoing a shutdown is not as simple as pretending it
  8928. 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
  8929. to recover at all:</p>
  8930. <ul>
  8931. <li>If the room was invite-only, your users will need to be re-invited.</li>
  8932. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  8933. <li>The first user to rejoin will have to do so via an alias on a different server.</li>
  8934. </ul>
  8935. <p>With all that being said, if you still want to try and recover the room:</p>
  8936. <ol>
  8937. <li>For safety reasons, shut down Synapse.</li>
  8938. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  8939. <ul>
  8940. <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>
  8941. <li>The room ID is the same one supplied to the shutdown room API, not the Content Violation room.</li>
  8942. </ul>
  8943. </li>
  8944. <li>Restart Synapse.</li>
  8945. </ol>
  8946. <p>You will have to manually handle, if you so choose, the following:</p>
  8947. <ul>
  8948. <li>Aliases that would have been redirected to the Content Violation room.</li>
  8949. <li>Users that would have been booted from the room (and will have been force-joined to the Content Violation room).</li>
  8950. <li>Removal of the Content Violation room if desired.</li>
  8951. </ul>
  8952. <h2 id="deprecated-endpoint"><a class="header" href="#deprecated-endpoint">Deprecated endpoint</a></h2>
  8953. <p>The previous deprecated API will be removed in a future release, it was:</p>
  8954. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id&gt;/delete
  8955. </code></pre>
  8956. <p>It behaves the same way than the current endpoint except the path and the method.</p>
  8957. <h1 id="make-room-admin-api"><a class="header" href="#make-room-admin-api">Make Room Admin API</a></h1>
  8958. <p>Grants another user the highest power available to a local user who is in the room.
  8959. If the user is not in the room, and it is not publicly joinable, then invite the user.</p>
  8960. <p>By default the server admin (the caller) is granted power, but another user can
  8961. optionally be specified, e.g.:</p>
  8962. <pre><code> POST /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/make_room_admin
  8963. {
  8964. &quot;user_id&quot;: &quot;@foo:example.com&quot;
  8965. }
  8966. </code></pre>
  8967. <h1 id="forward-extremities-admin-api"><a class="header" href="#forward-extremities-admin-api">Forward Extremities Admin API</a></h1>
  8968. <p>Enables querying and deleting forward extremities from rooms. When a lot of forward
  8969. extremities accumulate in a room, performance can become degraded. For details, see
  8970. <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.</p>
  8971. <h2 id="check-for-forward-extremities"><a class="header" href="#check-for-forward-extremities">Check for forward extremities</a></h2>
  8972. <p>To check the status of forward extremities for a room:</p>
  8973. <pre><code> GET /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  8974. </code></pre>
  8975. <p>A response as follows will be returned:</p>
  8976. <pre><code class="language-json">{
  8977. &quot;count&quot;: 1,
  8978. &quot;results&quot;: [
  8979. {
  8980. &quot;event_id&quot;: &quot;$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdefgh&quot;,
  8981. &quot;state_group&quot;: 439,
  8982. &quot;depth&quot;: 123,
  8983. &quot;received_ts&quot;: 1611263016761
  8984. }
  8985. ]
  8986. }
  8987. </code></pre>
  8988. <h2 id="deleting-forward-extremities"><a class="header" href="#deleting-forward-extremities">Deleting forward extremities</a></h2>
  8989. <p><strong>WARNING</strong>: Please ensure you know what you're doing and have read
  8990. the related issue <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.
  8991. Under no situations should this API be executed as an automated maintenance task!</p>
  8992. <p>If a room has lots of forward extremities, the extra can be
  8993. deleted as follows:</p>
  8994. <pre><code> DELETE /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  8995. </code></pre>
  8996. <p>A response as follows will be returned, indicating the amount of forward extremities
  8997. that were deleted.</p>
  8998. <pre><code class="language-json">{
  8999. &quot;deleted&quot;: 1
  9000. }
  9001. </code></pre>
  9002. <h1 id="event-context-api"><a class="header" href="#event-context-api">Event Context API</a></h1>
  9003. <p>This API lets a client find the context of an event. This is designed primarily to investigate abuse reports.</p>
  9004. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/context/&lt;event_id&gt;
  9005. </code></pre>
  9006. <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>
  9007. <p>Example response:</p>
  9008. <pre><code class="language-json">{
  9009. &quot;end&quot;: &quot;t29-57_2_0_2&quot;,
  9010. &quot;events_after&quot;: [
  9011. {
  9012. &quot;content&quot;: {
  9013. &quot;body&quot;: &quot;This is an example text message&quot;,
  9014. &quot;msgtype&quot;: &quot;m.text&quot;,
  9015. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  9016. &quot;formatted_body&quot;: &quot;&lt;b&gt;This is an example text message&lt;/b&gt;&quot;
  9017. },
  9018. &quot;type&quot;: &quot;m.room.message&quot;,
  9019. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9020. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9021. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9022. &quot;origin_server_ts&quot;: 1432735824653,
  9023. &quot;unsigned&quot;: {
  9024. &quot;age&quot;: 1234
  9025. }
  9026. }
  9027. ],
  9028. &quot;event&quot;: {
  9029. &quot;content&quot;: {
  9030. &quot;body&quot;: &quot;filename.jpg&quot;,
  9031. &quot;info&quot;: {
  9032. &quot;h&quot;: 398,
  9033. &quot;w&quot;: 394,
  9034. &quot;mimetype&quot;: &quot;image/jpeg&quot;,
  9035. &quot;size&quot;: 31037
  9036. },
  9037. &quot;url&quot;: &quot;mxc://example.org/JWEIFJgwEIhweiWJE&quot;,
  9038. &quot;msgtype&quot;: &quot;m.image&quot;
  9039. },
  9040. &quot;type&quot;: &quot;m.room.message&quot;,
  9041. &quot;event_id&quot;: &quot;$f3h4d129462ha:example.com&quot;,
  9042. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9043. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9044. &quot;origin_server_ts&quot;: 1432735824653,
  9045. &quot;unsigned&quot;: {
  9046. &quot;age&quot;: 1234
  9047. }
  9048. },
  9049. &quot;events_before&quot;: [
  9050. {
  9051. &quot;content&quot;: {
  9052. &quot;body&quot;: &quot;something-important.doc&quot;,
  9053. &quot;filename&quot;: &quot;something-important.doc&quot;,
  9054. &quot;info&quot;: {
  9055. &quot;mimetype&quot;: &quot;application/msword&quot;,
  9056. &quot;size&quot;: 46144
  9057. },
  9058. &quot;msgtype&quot;: &quot;m.file&quot;,
  9059. &quot;url&quot;: &quot;mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe&quot;
  9060. },
  9061. &quot;type&quot;: &quot;m.room.message&quot;,
  9062. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9063. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9064. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9065. &quot;origin_server_ts&quot;: 1432735824653,
  9066. &quot;unsigned&quot;: {
  9067. &quot;age&quot;: 1234
  9068. }
  9069. }
  9070. ],
  9071. &quot;start&quot;: &quot;t27-54_2_0_2&quot;,
  9072. &quot;state&quot;: [
  9073. {
  9074. &quot;content&quot;: {
  9075. &quot;creator&quot;: &quot;@example:example.org&quot;,
  9076. &quot;room_version&quot;: &quot;1&quot;,
  9077. &quot;m.federate&quot;: true,
  9078. &quot;predecessor&quot;: {
  9079. &quot;event_id&quot;: &quot;$something:example.org&quot;,
  9080. &quot;room_id&quot;: &quot;!oldroom:example.org&quot;
  9081. }
  9082. },
  9083. &quot;type&quot;: &quot;m.room.create&quot;,
  9084. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9085. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9086. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9087. &quot;origin_server_ts&quot;: 1432735824653,
  9088. &quot;unsigned&quot;: {
  9089. &quot;age&quot;: 1234
  9090. },
  9091. &quot;state_key&quot;: &quot;&quot;
  9092. },
  9093. {
  9094. &quot;content&quot;: {
  9095. &quot;membership&quot;: &quot;join&quot;,
  9096. &quot;avatar_url&quot;: &quot;mxc://example.org/SEsfnsuifSDFSSEF&quot;,
  9097. &quot;displayname&quot;: &quot;Alice Margatroid&quot;
  9098. },
  9099. &quot;type&quot;: &quot;m.room.member&quot;,
  9100. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9101. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9102. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9103. &quot;origin_server_ts&quot;: 1432735824653,
  9104. &quot;unsigned&quot;: {
  9105. &quot;age&quot;: 1234
  9106. },
  9107. &quot;state_key&quot;: &quot;@alice:example.org&quot;
  9108. }
  9109. ]
  9110. }
  9111. </code></pre>
  9112. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="server-notices-1"><a class="header" href="#server-notices-1">Server Notices</a></h1>
  9113. <p>The API to send notices is as follows:</p>
  9114. <pre><code>POST /_synapse/admin/v1/send_server_notice
  9115. </code></pre>
  9116. <p>or:</p>
  9117. <pre><code>PUT /_synapse/admin/v1/send_server_notice/{txnId}
  9118. </code></pre>
  9119. <p>You will need to authenticate with an access token for an admin user.</p>
  9120. <p>When using the <code>PUT</code> form, retransmissions with the same transaction ID will be
  9121. ignored in the same way as with <code>PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}</code>.</p>
  9122. <p>The request body should look something like the following:</p>
  9123. <pre><code class="language-json">{
  9124. &quot;user_id&quot;: &quot;@target_user:server_name&quot;,
  9125. &quot;content&quot;: {
  9126. &quot;msgtype&quot;: &quot;m.text&quot;,
  9127. &quot;body&quot;: &quot;This is my message&quot;
  9128. }
  9129. }
  9130. </code></pre>
  9131. <p>You can optionally include the following additional parameters:</p>
  9132. <ul>
  9133. <li><code>type</code>: the type of event. Defaults to <code>m.room.message</code>.</li>
  9134. <li><code>state_key</code>: Setting this will result in a state event being sent.</li>
  9135. </ul>
  9136. <p>Once the notice has been sent, the API will return the following response:</p>
  9137. <pre><code class="language-json">{
  9138. &quot;event_id&quot;: &quot;&lt;event_id&gt;&quot;
  9139. }
  9140. </code></pre>
  9141. <p>Note that server notices must be enabled in <code>homeserver.yaml</code> before this API
  9142. can be used. See <a href="admin_api/../server_notices.html">server_notices.md</a> for more information.</p>
  9143. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="deprecated-shutdown-room-api"><a class="header" href="#deprecated-shutdown-room-api">Deprecated: Shutdown room API</a></h1>
  9144. <p><strong>The old Shutdown room API is deprecated and will be removed in a future release.
  9145. See the new <a href="admin_api/rooms.html#delete-room-api">Delete Room API</a> for more details.</strong></p>
  9146. <p>Shuts down a room, preventing new joins and moves local users and room aliases automatically
  9147. to a new room. The new room will be created with the user specified by the
  9148. <code>new_room_user_id</code> parameter as room administrator and will contain a message
  9149. explaining what happened. Users invited to the new room will have power level
  9150. -10 by default, and thus be unable to speak. The old room's power levels will be changed to
  9151. disallow any further invites or joins.</p>
  9152. <p>The local server will only have the power to move local user and room aliases to
  9153. the new room. Users on other servers will be unaffected.</p>
  9154. <h2 id="api-1"><a class="header" href="#api-1">API</a></h2>
  9155. <p>You will need to authenticate with an access token for an admin user.</p>
  9156. <h3 id="url"><a class="header" href="#url">URL</a></h3>
  9157. <p><code>POST /_synapse/admin/v1/shutdown_room/{room_id}</code></p>
  9158. <h3 id="url-parameters"><a class="header" href="#url-parameters">URL Parameters</a></h3>
  9159. <ul>
  9160. <li><code>room_id</code> - The ID of the room (e.g <code>!someroom:example.com</code>)</li>
  9161. </ul>
  9162. <h3 id="json-body-parameters"><a class="header" href="#json-body-parameters">JSON Body Parameters</a></h3>
  9163. <ul>
  9164. <li><code>new_room_user_id</code> - Required. A string representing the user ID of the user that will admin
  9165. the new room that all users in the old room will be moved to.</li>
  9166. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  9167. invited to.</li>
  9168. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  9169. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  9170. original room was shut down.</li>
  9171. </ul>
  9172. <p>If not specified, the default value of <code>room_name</code> is &quot;Content Violation
  9173. Notification&quot;. The default value of <code>message</code> is &quot;Sharing illegal content on
  9174. othis server is not permitted and rooms in violation will be blocked.&quot;</p>
  9175. <h3 id="response-parameters"><a class="header" href="#response-parameters">Response Parameters</a></h3>
  9176. <ul>
  9177. <li><code>kicked_users</code> - An integer number representing the number of users that
  9178. were kicked.</li>
  9179. <li><code>failed_to_kick_users</code> - An integer number representing the number of users
  9180. that were not kicked.</li>
  9181. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  9182. the old room to the new.</li>
  9183. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  9184. </ul>
  9185. <h2 id="example-4"><a class="header" href="#example-4">Example</a></h2>
  9186. <p>Request:</p>
  9187. <pre><code>POST /_synapse/admin/v1/shutdown_room/!somebadroom%3Aexample.com
  9188. {
  9189. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  9190. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  9191. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;
  9192. }
  9193. </code></pre>
  9194. <p>Response:</p>
  9195. <pre><code>{
  9196. &quot;kicked_users&quot;: 5,
  9197. &quot;failed_to_kick_users&quot;: 0,
  9198. &quot;local_aliases&quot;: [&quot;#badroom:example.com&quot;, &quot;#evilsaloon:example.com],
  9199. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;,
  9200. },
  9201. </code></pre>
  9202. <h2 id="undoing-room-shutdowns-1"><a class="header" href="#undoing-room-shutdowns-1">Undoing room shutdowns</a></h2>
  9203. <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,
  9204. the structure can and does change without notice.</p>
  9205. <p>First, it's important to understand that a room shutdown is very destructive. Undoing a shutdown is not as simple as pretending it
  9206. 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
  9207. to recover at all:</p>
  9208. <ul>
  9209. <li>If the room was invite-only, your users will need to be re-invited.</li>
  9210. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  9211. <li>The first user to rejoin will have to do so via an alias on a different server.</li>
  9212. </ul>
  9213. <p>With all that being said, if you still want to try and recover the room:</p>
  9214. <ol>
  9215. <li>For safety reasons, shut down Synapse.</li>
  9216. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  9217. <ul>
  9218. <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>
  9219. <li>The room ID is the same one supplied to the shutdown room API, not the Content Violation room.</li>
  9220. </ul>
  9221. </li>
  9222. <li>Restart Synapse.</li>
  9223. </ol>
  9224. <p>You will have to manually handle, if you so choose, the following:</p>
  9225. <ul>
  9226. <li>Aliases that would have been redirected to the Content Violation room.</li>
  9227. <li>Users that would have been booted from the room (and will have been force-joined to the Content Violation room).</li>
  9228. <li>Removal of the Content Violation room if desired.</li>
  9229. </ul>
  9230. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="users-media-usage-statistics"><a class="header" href="#users-media-usage-statistics">Users' media usage statistics</a></h1>
  9231. <p>Returns information about all local media usage of users. Gives the
  9232. possibility to filter them by time and user.</p>
  9233. <p>The API is:</p>
  9234. <pre><code>GET /_synapse/admin/v1/statistics/users/media
  9235. </code></pre>
  9236. <p>To use it, you will need to authenticate by providing an <code>access_token</code>
  9237. for a server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9238. <p>A response body like the following is returned:</p>
  9239. <pre><code class="language-json">{
  9240. &quot;users&quot;: [
  9241. {
  9242. &quot;displayname&quot;: &quot;foo_user_0&quot;,
  9243. &quot;media_count&quot;: 2,
  9244. &quot;media_length&quot;: 134,
  9245. &quot;user_id&quot;: &quot;@foo_user_0:test&quot;
  9246. },
  9247. {
  9248. &quot;displayname&quot;: &quot;foo_user_1&quot;,
  9249. &quot;media_count&quot;: 2,
  9250. &quot;media_length&quot;: 134,
  9251. &quot;user_id&quot;: &quot;@foo_user_1:test&quot;
  9252. }
  9253. ],
  9254. &quot;next_token&quot;: 3,
  9255. &quot;total&quot;: 10
  9256. }
  9257. </code></pre>
  9258. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint
  9259. again with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9260. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9261. reports to paginate through.</p>
  9262. <p><strong>Parameters</strong></p>
  9263. <p>The following parameters should be set in the URL:</p>
  9264. <ul>
  9265. <li><code>limit</code>: string representing a positive integer - Is optional but is
  9266. used for pagination, denoting the maximum number of items to return
  9267. in this call. Defaults to <code>100</code>.</li>
  9268. <li><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9269. denoting the offset in the returned results. This should be treated as an opaque value
  9270. and not explicitly set to anything other than the return value of <code>next_token</code> from a
  9271. previous call. Defaults to <code>0</code>.</li>
  9272. <li><code>order_by</code> - string - The method in which to sort the returned list of users. Valid values are:
  9273. <ul>
  9274. <li><code>user_id</code> - Users are ordered alphabetically by <code>user_id</code>. This is the default.</li>
  9275. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9276. <li><code>media_length</code> - Users are ordered by the total size of uploaded media in bytes.
  9277. Smallest to largest.</li>
  9278. <li><code>media_count</code> - Users are ordered by number of uploaded media. Smallest to largest.</li>
  9279. </ul>
  9280. </li>
  9281. <li><code>from_ts</code> - string representing a positive integer - Considers only
  9282. files created at this timestamp or later. Unix timestamp in ms.</li>
  9283. <li><code>until_ts</code> - string representing a positive integer - Considers only
  9284. files created at this timestamp or earlier. Unix timestamp in ms.</li>
  9285. <li><code>search_term</code> - string - Filter users by their user ID localpart <strong>or</strong> displayname.
  9286. The search term can be found in any part of the string.
  9287. Defaults to no filtering.</li>
  9288. <li><code>dir</code> - string - Direction of order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9289. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  9290. </ul>
  9291. <p><strong>Response</strong></p>
  9292. <p>The following fields are returned in the JSON response body:</p>
  9293. <ul>
  9294. <li><code>users</code> - An array of objects, each containing information
  9295. about the user and their local media. Objects contain the following fields:
  9296. <ul>
  9297. <li><code>displayname</code> - string - Displayname of this user.</li>
  9298. <li><code>media_count</code> - integer - Number of uploaded media by this user.</li>
  9299. <li><code>media_length</code> - integer - Size of uploaded media in bytes by this user.</li>
  9300. <li><code>user_id</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9301. </ul>
  9302. </li>
  9303. <li><code>next_token</code> - integer - Opaque value used for pagination. See above.</li>
  9304. <li><code>total</code> - integer - Total number of users after filtering.</li>
  9305. </ul>
  9306. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="user-admin-api"><a class="header" href="#user-admin-api">User Admin API</a></h1>
  9307. <h2 id="query-user-account"><a class="header" href="#query-user-account">Query User Account</a></h2>
  9308. <p>This API returns information about a specific user account.</p>
  9309. <p>The api is:</p>
  9310. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;
  9311. </code></pre>
  9312. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9313. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9314. <p>It returns a JSON body like the following:</p>
  9315. <pre><code class="language-json">{
  9316. &quot;displayname&quot;: &quot;User&quot;,
  9317. &quot;threepids&quot;: [
  9318. {
  9319. &quot;medium&quot;: &quot;email&quot;,
  9320. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9321. },
  9322. {
  9323. &quot;medium&quot;: &quot;email&quot;,
  9324. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9325. }
  9326. ],
  9327. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9328. &quot;admin&quot;: 0,
  9329. &quot;deactivated&quot;: 0,
  9330. &quot;shadow_banned&quot;: 0,
  9331. &quot;password_hash&quot;: &quot;$2b$12$p9B4GkqYdRTPGD&quot;,
  9332. &quot;creation_ts&quot;: 1560432506,
  9333. &quot;appservice_id&quot;: null,
  9334. &quot;consent_server_notice_sent&quot;: null,
  9335. &quot;consent_version&quot;: null,
  9336. &quot;external_ids&quot;: [
  9337. {
  9338. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9339. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9340. },
  9341. {
  9342. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9343. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9344. }
  9345. ]
  9346. }
  9347. </code></pre>
  9348. <p>URL parameters:</p>
  9349. <ul>
  9350. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9351. </ul>
  9352. <h2 id="create-or-modify-account"><a class="header" href="#create-or-modify-account">Create or modify Account</a></h2>
  9353. <p>This API allows an administrator to create or modify a user account with a
  9354. specific <code>user_id</code>.</p>
  9355. <p>This api is:</p>
  9356. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;
  9357. </code></pre>
  9358. <p>with a body of:</p>
  9359. <pre><code class="language-json">{
  9360. &quot;password&quot;: &quot;user_password&quot;,
  9361. &quot;displayname&quot;: &quot;User&quot;,
  9362. &quot;threepids&quot;: [
  9363. {
  9364. &quot;medium&quot;: &quot;email&quot;,
  9365. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9366. },
  9367. {
  9368. &quot;medium&quot;: &quot;email&quot;,
  9369. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9370. }
  9371. ],
  9372. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9373. &quot;admin&quot;: false,
  9374. &quot;deactivated&quot;: false
  9375. }
  9376. </code></pre>
  9377. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9378. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9379. <p>URL parameters:</p>
  9380. <ul>
  9381. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9382. </ul>
  9383. <p>Body parameters:</p>
  9384. <ul>
  9385. <li>
  9386. <p><code>password</code>, optional. If provided, the user's password is updated and all
  9387. devices are logged out.</p>
  9388. </li>
  9389. <li>
  9390. <p><code>displayname</code>, optional, defaults to the value of <code>user_id</code>.</p>
  9391. </li>
  9392. <li>
  9393. <p><code>threepids</code>, optional, allows setting the third-party IDs (email, msisdn)
  9394. belonging to a user.</p>
  9395. </li>
  9396. <li>
  9397. <p><code>avatar_url</code>, optional, must be a
  9398. <a href="https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris">MXC URI</a>.</p>
  9399. </li>
  9400. <li>
  9401. <p><code>admin</code>, optional, defaults to <code>false</code>.</p>
  9402. </li>
  9403. <li>
  9404. <p><code>deactivated</code>, optional. If unspecified, deactivation state will be left
  9405. unchanged on existing accounts and set to <code>false</code> for new accounts.
  9406. A user cannot be erased by deactivating with this API. For details on
  9407. deactivating users see <a href="admin_api/user_admin_api.html#deactivate-account">Deactivate Account</a>.</p>
  9408. </li>
  9409. </ul>
  9410. <p>If the user already exists then optional parameters default to the current value.</p>
  9411. <p>In order to re-activate an account <code>deactivated</code> must be set to <code>false</code>. If
  9412. users do not login via single-sign-on, a new <code>password</code> must be provided.</p>
  9413. <h2 id="list-accounts"><a class="header" href="#list-accounts">List Accounts</a></h2>
  9414. <p>This API returns all local user accounts.
  9415. By default, the response is ordered by ascending user ID.</p>
  9416. <pre><code>GET /_synapse/admin/v2/users?from=0&amp;limit=10&amp;guests=false
  9417. </code></pre>
  9418. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9419. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9420. <p>A response body like the following is returned:</p>
  9421. <pre><code class="language-json">{
  9422. &quot;users&quot;: [
  9423. {
  9424. &quot;name&quot;: &quot;&lt;user_id1&gt;&quot;,
  9425. &quot;is_guest&quot;: 0,
  9426. &quot;admin&quot;: 0,
  9427. &quot;user_type&quot;: null,
  9428. &quot;deactivated&quot;: 0,
  9429. &quot;shadow_banned&quot;: 0,
  9430. &quot;displayname&quot;: &quot;&lt;User One&gt;&quot;,
  9431. &quot;avatar_url&quot;: null
  9432. }, {
  9433. &quot;name&quot;: &quot;&lt;user_id2&gt;&quot;,
  9434. &quot;is_guest&quot;: 0,
  9435. &quot;admin&quot;: 1,
  9436. &quot;user_type&quot;: null,
  9437. &quot;deactivated&quot;: 0,
  9438. &quot;shadow_banned&quot;: 0,
  9439. &quot;displayname&quot;: &quot;&lt;User Two&gt;&quot;,
  9440. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;
  9441. }
  9442. ],
  9443. &quot;next_token&quot;: &quot;100&quot;,
  9444. &quot;total&quot;: 200
  9445. }
  9446. </code></pre>
  9447. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9448. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9449. <p>If the endpoint does not return a <code>next_token</code> then there are no more users
  9450. to paginate through.</p>
  9451. <p><strong>Parameters</strong></p>
  9452. <p>The following parameters should be set in the URL:</p>
  9453. <ul>
  9454. <li>
  9455. <p><code>user_id</code> - Is optional and filters to only return users with user IDs
  9456. that contain this value. This parameter is ignored when using the <code>name</code> parameter.</p>
  9457. </li>
  9458. <li>
  9459. <p><code>name</code> - Is optional and filters to only return users with user ID localparts
  9460. <strong>or</strong> displaynames that contain this value.</p>
  9461. </li>
  9462. <li>
  9463. <p><code>guests</code> - string representing a bool - Is optional and if <code>false</code> will <strong>exclude</strong> guest users.
  9464. Defaults to <code>true</code> to include guest users.</p>
  9465. </li>
  9466. <li>
  9467. <p><code>deactivated</code> - string representing a bool - Is optional and if <code>true</code> will <strong>include</strong> deactivated users.
  9468. Defaults to <code>false</code> to exclude deactivated users.</p>
  9469. </li>
  9470. <li>
  9471. <p><code>limit</code> - string representing a positive integer - Is optional but is used for pagination,
  9472. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9473. </li>
  9474. <li>
  9475. <p><code>from</code> - string representing a positive integer - Is optional but used for pagination,
  9476. denoting the offset in the returned results. This should be treated as an opaque value and
  9477. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9478. Defaults to <code>0</code>.</p>
  9479. </li>
  9480. <li>
  9481. <p><code>order_by</code> - The method by which to sort the returned list of users.
  9482. If the ordered field has duplicates, the second order is always by ascending <code>name</code>,
  9483. which guarantees a stable ordering. Valid values are:</p>
  9484. <ul>
  9485. <li><code>name</code> - Users are ordered alphabetically by <code>name</code>. This is the default.</li>
  9486. <li><code>is_guest</code> - Users are ordered by <code>is_guest</code> status.</li>
  9487. <li><code>admin</code> - Users are ordered by <code>admin</code> status.</li>
  9488. <li><code>user_type</code> - Users are ordered alphabetically by <code>user_type</code>.</li>
  9489. <li><code>deactivated</code> - Users are ordered by <code>deactivated</code> status.</li>
  9490. <li><code>shadow_banned</code> - Users are ordered by <code>shadow_banned</code> status.</li>
  9491. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9492. <li><code>avatar_url</code> - Users are ordered alphabetically by avatar URL.</li>
  9493. </ul>
  9494. </li>
  9495. <li>
  9496. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9497. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  9498. </li>
  9499. </ul>
  9500. <p>Caution. The database only has indexes on the columns <code>name</code> and <code>created_ts</code>.
  9501. This means that if a different sort order is used (<code>is_guest</code>, <code>admin</code>,
  9502. <code>user_type</code>, <code>deactivated</code>, <code>shadow_banned</code>, <code>avatar_url</code> or <code>displayname</code>),
  9503. this can cause a large load on the database, especially for large environments.</p>
  9504. <p><strong>Response</strong></p>
  9505. <p>The following fields are returned in the JSON response body:</p>
  9506. <ul>
  9507. <li>
  9508. <p><code>users</code> - An array of objects, each containing information about an user.
  9509. User objects contain the following fields:</p>
  9510. <ul>
  9511. <li><code>name</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9512. <li><code>is_guest</code> - bool - Status if that user is a guest account.</li>
  9513. <li><code>admin</code> - bool - Status if that user is a server administrator.</li>
  9514. <li><code>user_type</code> - string - Type of the user. Normal users are type <code>None</code>.
  9515. This allows user type specific behaviour. There are also types <code>support</code> and <code>bot</code>. </li>
  9516. <li><code>deactivated</code> - bool - Status if that user has been marked as deactivated.</li>
  9517. <li><code>shadow_banned</code> - bool - Status if that user has been marked as shadow banned.</li>
  9518. <li><code>displayname</code> - string - The user's display name if they have set one.</li>
  9519. <li><code>avatar_url</code> - string - The user's avatar URL if they have set one.</li>
  9520. </ul>
  9521. </li>
  9522. <li>
  9523. <p><code>next_token</code>: string representing a positive integer - Indication for pagination. See above.</p>
  9524. </li>
  9525. <li>
  9526. <p><code>total</code> - integer - Total number of media.</p>
  9527. </li>
  9528. </ul>
  9529. <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>
  9530. <p>This API returns information about the active sessions for a specific user.</p>
  9531. <p>The endpoints are:</p>
  9532. <pre><code>GET /_synapse/admin/v1/whois/&lt;user_id&gt;
  9533. </code></pre>
  9534. <p>and:</p>
  9535. <pre><code>GET /_matrix/client/r0/admin/whois/&lt;userId&gt;
  9536. </code></pre>
  9537. <p>See also: <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid">Client Server
  9538. API Whois</a>.</p>
  9539. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9540. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9541. <p>It returns a JSON body like the following:</p>
  9542. <pre><code class="language-json">{
  9543. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;,
  9544. &quot;devices&quot;: {
  9545. &quot;&quot;: {
  9546. &quot;sessions&quot;: [
  9547. {
  9548. &quot;connections&quot;: [
  9549. {
  9550. &quot;ip&quot;: &quot;1.2.3.4&quot;,
  9551. &quot;last_seen&quot;: 1417222374433,
  9552. &quot;user_agent&quot;: &quot;Mozilla/5.0 ...&quot;
  9553. },
  9554. {
  9555. &quot;ip&quot;: &quot;1.2.3.10&quot;,
  9556. &quot;last_seen&quot;: 1417222374500,
  9557. &quot;user_agent&quot;: &quot;Dalvik/2.1.0 ...&quot;
  9558. }
  9559. ]
  9560. }
  9561. ]
  9562. }
  9563. }
  9564. }
  9565. </code></pre>
  9566. <p><code>last_seen</code> is measured in milliseconds since the Unix epoch.</p>
  9567. <h2 id="deactivate-account"><a class="header" href="#deactivate-account">Deactivate Account</a></h2>
  9568. <p>This API deactivates an account. It removes active access tokens, resets the
  9569. password, and deletes third-party IDs (to prevent the user requesting a
  9570. password reset).</p>
  9571. <p>It can also mark the user as GDPR-erased. This means messages sent by the
  9572. user will still be visible by anyone that was in the room when these messages
  9573. were sent, but hidden from users joining the room afterwards.</p>
  9574. <p>The api is:</p>
  9575. <pre><code>POST /_synapse/admin/v1/deactivate/&lt;user_id&gt;
  9576. </code></pre>
  9577. <p>with a body of:</p>
  9578. <pre><code class="language-json">{
  9579. &quot;erase&quot;: true
  9580. }
  9581. </code></pre>
  9582. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9583. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9584. <p>The erase parameter is optional and defaults to <code>false</code>.
  9585. An empty body may be passed for backwards compatibility.</p>
  9586. <p>The following actions are performed when deactivating an user:</p>
  9587. <ul>
  9588. <li>Try to unpind 3PIDs from the identity server</li>
  9589. <li>Remove all 3PIDs from the homeserver</li>
  9590. <li>Delete all devices and E2EE keys</li>
  9591. <li>Delete all access tokens</li>
  9592. <li>Delete the password hash</li>
  9593. <li>Removal from all rooms the user is a member of</li>
  9594. <li>Remove the user from the user directory</li>
  9595. <li>Reject all pending invites</li>
  9596. <li>Remove all account validity information related to the user</li>
  9597. </ul>
  9598. <p>The following additional actions are performed during deactivation if <code>erase</code>
  9599. is set to <code>true</code>:</p>
  9600. <ul>
  9601. <li>Remove the user's display name</li>
  9602. <li>Remove the user's avatar URL</li>
  9603. <li>Mark the user as erased</li>
  9604. </ul>
  9605. <h2 id="reset-password"><a class="header" href="#reset-password">Reset password</a></h2>
  9606. <p>Changes the password of another user. This will automatically log the user out of all their devices.</p>
  9607. <p>The api is:</p>
  9608. <pre><code>POST /_synapse/admin/v1/reset_password/&lt;user_id&gt;
  9609. </code></pre>
  9610. <p>with a body of:</p>
  9611. <pre><code class="language-json">{
  9612. &quot;new_password&quot;: &quot;&lt;secret&gt;&quot;,
  9613. &quot;logout_devices&quot;: true
  9614. }
  9615. </code></pre>
  9616. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9617. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9618. <p>The parameter <code>new_password</code> is required.
  9619. The parameter <code>logout_devices</code> is optional and defaults to <code>true</code>.</p>
  9620. <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>
  9621. <p>The api is:</p>
  9622. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  9623. </code></pre>
  9624. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9625. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9626. <p>A response body like the following is returned:</p>
  9627. <pre><code class="language-json">{
  9628. &quot;admin&quot;: true
  9629. }
  9630. </code></pre>
  9631. <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>
  9632. <p>Note that you cannot demote yourself.</p>
  9633. <p>The api is:</p>
  9634. <pre><code>PUT /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  9635. </code></pre>
  9636. <p>with a body of:</p>
  9637. <pre><code class="language-json">{
  9638. &quot;admin&quot;: true
  9639. }
  9640. </code></pre>
  9641. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9642. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9643. <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>
  9644. <p>Gets a list of all <code>room_id</code> that a specific <code>user_id</code> is member.</p>
  9645. <p>The API is:</p>
  9646. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/joined_rooms
  9647. </code></pre>
  9648. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9649. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9650. <p>A response body like the following is returned:</p>
  9651. <pre><code class="language-json"> {
  9652. &quot;joined_rooms&quot;: [
  9653. &quot;!DuGcnbhHGaSZQoNQR:matrix.org&quot;,
  9654. &quot;!ZtSaPCawyWtxfWiIy:matrix.org&quot;
  9655. ],
  9656. &quot;total&quot;: 2
  9657. }
  9658. </code></pre>
  9659. <p>The server returns the list of rooms of which the user and the server
  9660. are member. If the user is local, all the rooms of which the user is
  9661. member are returned.</p>
  9662. <p><strong>Parameters</strong></p>
  9663. <p>The following parameters should be set in the URL:</p>
  9664. <ul>
  9665. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9666. </ul>
  9667. <p><strong>Response</strong></p>
  9668. <p>The following fields are returned in the JSON response body:</p>
  9669. <ul>
  9670. <li><code>joined_rooms</code> - An array of <code>room_id</code>.</li>
  9671. <li><code>total</code> - Number of rooms.</li>
  9672. </ul>
  9673. <h2 id="list-media-of-a-user"><a class="header" href="#list-media-of-a-user">List media of a user</a></h2>
  9674. <p>Gets a list of all local media that a specific <code>user_id</code> has created.
  9675. By default, the response is ordered by descending creation date and ascending media ID.
  9676. The newest media is on top. You can change the order with parameters
  9677. <code>order_by</code> and <code>dir</code>.</p>
  9678. <p>The API is:</p>
  9679. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/media
  9680. </code></pre>
  9681. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9682. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9683. <p>A response body like the following is returned:</p>
  9684. <pre><code class="language-json">{
  9685. &quot;media&quot;: [
  9686. {
  9687. &quot;created_ts&quot;: 100400,
  9688. &quot;last_access_ts&quot;: null,
  9689. &quot;media_id&quot;: &quot;qXhyRzulkwLsNHTbpHreuEgo&quot;,
  9690. &quot;media_length&quot;: 67,
  9691. &quot;media_type&quot;: &quot;image/png&quot;,
  9692. &quot;quarantined_by&quot;: null,
  9693. &quot;safe_from_quarantine&quot;: false,
  9694. &quot;upload_name&quot;: &quot;test1.png&quot;
  9695. },
  9696. {
  9697. &quot;created_ts&quot;: 200400,
  9698. &quot;last_access_ts&quot;: null,
  9699. &quot;media_id&quot;: &quot;FHfiSnzoINDatrXHQIXBtahw&quot;,
  9700. &quot;media_length&quot;: 67,
  9701. &quot;media_type&quot;: &quot;image/png&quot;,
  9702. &quot;quarantined_by&quot;: null,
  9703. &quot;safe_from_quarantine&quot;: false,
  9704. &quot;upload_name&quot;: &quot;test2.png&quot;
  9705. }
  9706. ],
  9707. &quot;next_token&quot;: 3,
  9708. &quot;total&quot;: 2
  9709. }
  9710. </code></pre>
  9711. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9712. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9713. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9714. reports to paginate through.</p>
  9715. <p><strong>Parameters</strong></p>
  9716. <p>The following parameters should be set in the URL:</p>
  9717. <ul>
  9718. <li>
  9719. <p><code>user_id</code> - string - fully qualified: for example, <code>@user:server.com</code>.</p>
  9720. </li>
  9721. <li>
  9722. <p><code>limit</code>: string representing a positive integer - Is optional but is used for pagination,
  9723. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9724. </li>
  9725. <li>
  9726. <p><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9727. denoting the offset in the returned results. This should be treated as an opaque value and
  9728. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9729. Defaults to <code>0</code>.</p>
  9730. </li>
  9731. <li>
  9732. <p><code>order_by</code> - The method by which to sort the returned list of media.
  9733. If the ordered field has duplicates, the second order is always by ascending <code>media_id</code>,
  9734. which guarantees a stable ordering. Valid values are:</p>
  9735. <ul>
  9736. <li><code>media_id</code> - Media are ordered alphabetically by <code>media_id</code>.</li>
  9737. <li><code>upload_name</code> - Media are ordered alphabetically by name the media was uploaded with.</li>
  9738. <li><code>created_ts</code> - Media are ordered by when the content was uploaded in ms.
  9739. Smallest to largest. This is the default.</li>
  9740. <li><code>last_access_ts</code> - Media are ordered by when the content was last accessed in ms.
  9741. Smallest to largest.</li>
  9742. <li><code>media_length</code> - Media are ordered by length of the media in bytes.
  9743. Smallest to largest.</li>
  9744. <li><code>media_type</code> - Media are ordered alphabetically by MIME-type.</li>
  9745. <li><code>quarantined_by</code> - Media are ordered alphabetically by the user ID that
  9746. initiated the quarantine request for this media.</li>
  9747. <li><code>safe_from_quarantine</code> - Media are ordered by the status if this media is safe
  9748. from quarantining.</li>
  9749. </ul>
  9750. </li>
  9751. <li>
  9752. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9753. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  9754. </li>
  9755. </ul>
  9756. <p>If neither <code>order_by</code> nor <code>dir</code> is set, the default order is newest media on top
  9757. (corresponds to <code>order_by</code> = <code>created_ts</code> and <code>dir</code> = <code>b</code>).</p>
  9758. <p>Caution. The database only has indexes on the columns <code>media_id</code>,
  9759. <code>user_id</code> and <code>created_ts</code>. This means that if a different sort order is used
  9760. (<code>upload_name</code>, <code>last_access_ts</code>, <code>media_length</code>, <code>media_type</code>,
  9761. <code>quarantined_by</code> or <code>safe_from_quarantine</code>), this can cause a large load on the
  9762. database, especially for large environments.</p>
  9763. <p><strong>Response</strong></p>
  9764. <p>The following fields are returned in the JSON response body:</p>
  9765. <ul>
  9766. <li>
  9767. <p><code>media</code> - An array of objects, each containing information about a media.
  9768. Media objects contain the following fields:</p>
  9769. <ul>
  9770. <li>
  9771. <p><code>created_ts</code> - integer - Timestamp when the content was uploaded in ms.</p>
  9772. </li>
  9773. <li>
  9774. <p><code>last_access_ts</code> - integer - Timestamp when the content was last accessed in ms.</p>
  9775. </li>
  9776. <li>
  9777. <p><code>media_id</code> - string - The id used to refer to the media.</p>
  9778. </li>
  9779. <li>
  9780. <p><code>media_length</code> - integer - Length of the media in bytes.</p>
  9781. </li>
  9782. <li>
  9783. <p><code>media_type</code> - string - The MIME-type of the media.</p>
  9784. </li>
  9785. <li>
  9786. <p><code>quarantined_by</code> - string - The user ID that initiated the quarantine request
  9787. for this media.</p>
  9788. </li>
  9789. <li>
  9790. <p><code>safe_from_quarantine</code> - bool - Status if this media is safe from quarantining.</p>
  9791. </li>
  9792. <li>
  9793. <p><code>upload_name</code> - string - The name the media was uploaded with.</p>
  9794. </li>
  9795. </ul>
  9796. </li>
  9797. <li>
  9798. <p><code>next_token</code>: integer - Indication for pagination. See above.</p>
  9799. </li>
  9800. <li>
  9801. <p><code>total</code> - integer - Total number of media.</p>
  9802. </li>
  9803. </ul>
  9804. <h2 id="login-as-a-user"><a class="header" href="#login-as-a-user">Login as a user</a></h2>
  9805. <p>Get an access token that can be used to authenticate as that user. Useful for
  9806. when admins wish to do actions on behalf of a user.</p>
  9807. <p>The API is:</p>
  9808. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/login
  9809. {}
  9810. </code></pre>
  9811. <p>An optional <code>valid_until_ms</code> field can be specified in the request body as an
  9812. integer timestamp that specifies when the token should expire. By default tokens
  9813. do not expire.</p>
  9814. <p>A response body like the following is returned:</p>
  9815. <pre><code class="language-json">{
  9816. &quot;access_token&quot;: &quot;&lt;opaque_access_token_string&gt;&quot;
  9817. }
  9818. </code></pre>
  9819. <p>This API does <em>not</em> generate a new device for the user, and so will not appear
  9820. their <code>/devices</code> list, and in general the target user should not be able to
  9821. tell they have been logged in as.</p>
  9822. <p>To expire the token call the standard <code>/logout</code> API with the token.</p>
  9823. <p>Note: The token will expire if the <em>admin</em> user calls <code>/logout/all</code> from any
  9824. of their devices, but the token will <em>not</em> expire if the target user does the
  9825. same.</p>
  9826. <h2 id="user-devices"><a class="header" href="#user-devices">User devices</a></h2>
  9827. <h3 id="list-all-devices"><a class="header" href="#list-all-devices">List all devices</a></h3>
  9828. <p>Gets information about all devices for a specific <code>user_id</code>.</p>
  9829. <p>The API is:</p>
  9830. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices
  9831. </code></pre>
  9832. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9833. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9834. <p>A response body like the following is returned:</p>
  9835. <pre><code class="language-json">{
  9836. &quot;devices&quot;: [
  9837. {
  9838. &quot;device_id&quot;: &quot;QBUAZIFURK&quot;,
  9839. &quot;display_name&quot;: &quot;android&quot;,
  9840. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  9841. &quot;last_seen_ts&quot;: 1474491775024,
  9842. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  9843. },
  9844. {
  9845. &quot;device_id&quot;: &quot;AUIECTSRND&quot;,
  9846. &quot;display_name&quot;: &quot;ios&quot;,
  9847. &quot;last_seen_ip&quot;: &quot;1.2.3.5&quot;,
  9848. &quot;last_seen_ts&quot;: 1474491775025,
  9849. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  9850. }
  9851. ],
  9852. &quot;total&quot;: 2
  9853. }
  9854. </code></pre>
  9855. <p><strong>Parameters</strong></p>
  9856. <p>The following parameters should be set in the URL:</p>
  9857. <ul>
  9858. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9859. </ul>
  9860. <p><strong>Response</strong></p>
  9861. <p>The following fields are returned in the JSON response body:</p>
  9862. <ul>
  9863. <li>
  9864. <p><code>devices</code> - An array of objects, each containing information about a device.
  9865. Device objects contain the following fields:</p>
  9866. <ul>
  9867. <li><code>device_id</code> - Identifier of device.</li>
  9868. <li><code>display_name</code> - Display name set by the user for this device.
  9869. Absent if no name has been set.</li>
  9870. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  9871. (May be a few minutes out of date, for efficiency reasons).</li>
  9872. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  9873. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  9874. <li><code>user_id</code> - Owner of device.</li>
  9875. </ul>
  9876. </li>
  9877. <li>
  9878. <p><code>total</code> - Total number of user's devices.</p>
  9879. </li>
  9880. </ul>
  9881. <h3 id="delete-multiple-devices"><a class="header" href="#delete-multiple-devices">Delete multiple devices</a></h3>
  9882. <p>Deletes the given devices for a specific <code>user_id</code>, and invalidates
  9883. any access token associated with them.</p>
  9884. <p>The API is:</p>
  9885. <pre><code>POST /_synapse/admin/v2/users/&lt;user_id&gt;/delete_devices
  9886. {
  9887. &quot;devices&quot;: [
  9888. &quot;QBUAZIFURK&quot;,
  9889. &quot;AUIECTSRND&quot;
  9890. ],
  9891. }
  9892. </code></pre>
  9893. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9894. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9895. <p>An empty JSON dict is returned.</p>
  9896. <p><strong>Parameters</strong></p>
  9897. <p>The following parameters should be set in the URL:</p>
  9898. <ul>
  9899. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9900. </ul>
  9901. <p>The following fields are required in the JSON request body:</p>
  9902. <ul>
  9903. <li><code>devices</code> - The list of device IDs to delete.</li>
  9904. </ul>
  9905. <h3 id="show-a-device"><a class="header" href="#show-a-device">Show a device</a></h3>
  9906. <p>Gets information on a single device, by <code>device_id</code> for a specific <code>user_id</code>.</p>
  9907. <p>The API is:</p>
  9908. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  9909. </code></pre>
  9910. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9911. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9912. <p>A response body like the following is returned:</p>
  9913. <pre><code class="language-json">{
  9914. &quot;device_id&quot;: &quot;&lt;device_id&gt;&quot;,
  9915. &quot;display_name&quot;: &quot;android&quot;,
  9916. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  9917. &quot;last_seen_ts&quot;: 1474491775024,
  9918. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  9919. }
  9920. </code></pre>
  9921. <p><strong>Parameters</strong></p>
  9922. <p>The following parameters should be set in the URL:</p>
  9923. <ul>
  9924. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9925. <li><code>device_id</code> - The device to retrieve.</li>
  9926. </ul>
  9927. <p><strong>Response</strong></p>
  9928. <p>The following fields are returned in the JSON response body:</p>
  9929. <ul>
  9930. <li><code>device_id</code> - Identifier of device.</li>
  9931. <li><code>display_name</code> - Display name set by the user for this device.
  9932. Absent if no name has been set.</li>
  9933. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  9934. (May be a few minutes out of date, for efficiency reasons).</li>
  9935. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  9936. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  9937. <li><code>user_id</code> - Owner of device.</li>
  9938. </ul>
  9939. <h3 id="update-a-device"><a class="header" href="#update-a-device">Update a device</a></h3>
  9940. <p>Updates the metadata on the given <code>device_id</code> for a specific <code>user_id</code>.</p>
  9941. <p>The API is:</p>
  9942. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  9943. {
  9944. &quot;display_name&quot;: &quot;My other phone&quot;
  9945. }
  9946. </code></pre>
  9947. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9948. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9949. <p>An empty JSON dict is returned.</p>
  9950. <p><strong>Parameters</strong></p>
  9951. <p>The following parameters should be set in the URL:</p>
  9952. <ul>
  9953. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9954. <li><code>device_id</code> - The device to update.</li>
  9955. </ul>
  9956. <p>The following fields are required in the JSON request body:</p>
  9957. <ul>
  9958. <li><code>display_name</code> - The new display name for this device. If not given,
  9959. the display name is unchanged.</li>
  9960. </ul>
  9961. <h3 id="delete-a-device"><a class="header" href="#delete-a-device">Delete a device</a></h3>
  9962. <p>Deletes the given <code>device_id</code> for a specific <code>user_id</code>,
  9963. and invalidates any access token associated with it.</p>
  9964. <p>The API is:</p>
  9965. <pre><code>DELETE /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  9966. {}
  9967. </code></pre>
  9968. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9969. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9970. <p>An empty JSON dict is returned.</p>
  9971. <p><strong>Parameters</strong></p>
  9972. <p>The following parameters should be set in the URL:</p>
  9973. <ul>
  9974. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  9975. <li><code>device_id</code> - The device to delete.</li>
  9976. </ul>
  9977. <h2 id="list-all-pushers"><a class="header" href="#list-all-pushers">List all pushers</a></h2>
  9978. <p>Gets information about all pushers for a specific <code>user_id</code>.</p>
  9979. <p>The API is:</p>
  9980. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/pushers
  9981. </code></pre>
  9982. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9983. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9984. <p>A response body like the following is returned:</p>
  9985. <pre><code class="language-json">{
  9986. &quot;pushers&quot;: [
  9987. {
  9988. &quot;app_display_name&quot;:&quot;HTTP Push Notifications&quot;,
  9989. &quot;app_id&quot;:&quot;m.http&quot;,
  9990. &quot;data&quot;: {
  9991. &quot;url&quot;:&quot;example.com&quot;
  9992. },
  9993. &quot;device_display_name&quot;:&quot;pushy push&quot;,
  9994. &quot;kind&quot;:&quot;http&quot;,
  9995. &quot;lang&quot;:&quot;None&quot;,
  9996. &quot;profile_tag&quot;:&quot;&quot;,
  9997. &quot;pushkey&quot;:&quot;a@example.com&quot;
  9998. }
  9999. ],
  10000. &quot;total&quot;: 1
  10001. }
  10002. </code></pre>
  10003. <p><strong>Parameters</strong></p>
  10004. <p>The following parameters should be set in the URL:</p>
  10005. <ul>
  10006. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10007. </ul>
  10008. <p><strong>Response</strong></p>
  10009. <p>The following fields are returned in the JSON response body:</p>
  10010. <ul>
  10011. <li>
  10012. <p><code>pushers</code> - An array containing the current pushers for the user</p>
  10013. <ul>
  10014. <li>
  10015. <p><code>app_display_name</code> - string - A string that will allow the user to identify
  10016. what application owns this pusher.</p>
  10017. </li>
  10018. <li>
  10019. <p><code>app_id</code> - string - This is a reverse-DNS style identifier for the application.
  10020. Max length, 64 chars.</p>
  10021. </li>
  10022. <li>
  10023. <p><code>data</code> - A dictionary of information for the pusher implementation itself.</p>
  10024. <ul>
  10025. <li>
  10026. <p><code>url</code> - string - Required if <code>kind</code> is <code>http</code>. The URL to use to send
  10027. notifications to.</p>
  10028. </li>
  10029. <li>
  10030. <p><code>format</code> - string - The format to use when sending notifications to the
  10031. Push Gateway.</p>
  10032. </li>
  10033. </ul>
  10034. </li>
  10035. <li>
  10036. <p><code>device_display_name</code> - string - A string that will allow the user to identify
  10037. what device owns this pusher.</p>
  10038. </li>
  10039. <li>
  10040. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10041. this pusher executes.</p>
  10042. </li>
  10043. <li>
  10044. <p><code>kind</code> - string - The kind of pusher. &quot;http&quot; is a pusher that sends HTTP pokes.</p>
  10045. </li>
  10046. <li>
  10047. <p><code>lang</code> - string - The preferred language for receiving notifications
  10048. (e.g. 'en' or 'en-US')</p>
  10049. </li>
  10050. <li>
  10051. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10052. this pusher executes.</p>
  10053. </li>
  10054. <li>
  10055. <p><code>pushkey</code> - string - This is a unique identifier for this pusher.
  10056. Max length, 512 bytes.</p>
  10057. </li>
  10058. </ul>
  10059. </li>
  10060. <li>
  10061. <p><code>total</code> - integer - Number of pushers.</p>
  10062. </li>
  10063. </ul>
  10064. <p>See also the
  10065. <a href="https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers">Client-Server API Spec on pushers</a>.</p>
  10066. <h2 id="shadow-banning-users"><a class="header" href="#shadow-banning-users">Shadow-banning users</a></h2>
  10067. <p>Shadow-banning is a useful tool for moderating malicious or egregiously abusive users.
  10068. A shadow-banned users receives successful responses to their client-server API requests,
  10069. but the events are not propagated into rooms. This can be an effective tool as it
  10070. (hopefully) takes longer for the user to realise they are being moderated before
  10071. pivoting to another account.</p>
  10072. <p>Shadow-banning a user should be used as a tool of last resort and may lead to confusing
  10073. or broken behaviour for the client. A shadow-banned user will not receive any
  10074. notification and it is generally more appropriate to ban or kick abusive users.
  10075. A shadow-banned user will be unable to contact anyone on the server.</p>
  10076. <p>The API is:</p>
  10077. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/shadow_ban
  10078. </code></pre>
  10079. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10080. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10081. <p>An empty JSON dict is returned.</p>
  10082. <p><strong>Parameters</strong></p>
  10083. <p>The following parameters should be set in the URL:</p>
  10084. <ul>
  10085. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10086. be local.</li>
  10087. </ul>
  10088. <h2 id="override-ratelimiting-for-users"><a class="header" href="#override-ratelimiting-for-users">Override ratelimiting for users</a></h2>
  10089. <p>This API allows to override or disable ratelimiting for a specific user.
  10090. There are specific APIs to set, get and delete a ratelimit.</p>
  10091. <h3 id="get-status-of-ratelimit"><a class="header" href="#get-status-of-ratelimit">Get status of ratelimit</a></h3>
  10092. <p>The API is:</p>
  10093. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10094. </code></pre>
  10095. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10096. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10097. <p>A response body like the following is returned:</p>
  10098. <pre><code class="language-json">{
  10099. &quot;messages_per_second&quot;: 0,
  10100. &quot;burst_count&quot;: 0
  10101. }
  10102. </code></pre>
  10103. <p><strong>Parameters</strong></p>
  10104. <p>The following parameters should be set in the URL:</p>
  10105. <ul>
  10106. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10107. be local.</li>
  10108. </ul>
  10109. <p><strong>Response</strong></p>
  10110. <p>The following fields are returned in the JSON response body:</p>
  10111. <ul>
  10112. <li><code>messages_per_second</code> - integer - The number of actions that can
  10113. be performed in a second. <code>0</code> mean that ratelimiting is disabled for this user.</li>
  10114. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10115. being limited.</li>
  10116. </ul>
  10117. <p>If <strong>no</strong> custom ratelimit is set, an empty JSON dict is returned.</p>
  10118. <pre><code class="language-json">{}
  10119. </code></pre>
  10120. <h3 id="set-ratelimit"><a class="header" href="#set-ratelimit">Set ratelimit</a></h3>
  10121. <p>The API is:</p>
  10122. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10123. </code></pre>
  10124. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10125. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10126. <p>A response body like the following is returned:</p>
  10127. <pre><code class="language-json">{
  10128. &quot;messages_per_second&quot;: 0,
  10129. &quot;burst_count&quot;: 0
  10130. }
  10131. </code></pre>
  10132. <p><strong>Parameters</strong></p>
  10133. <p>The following parameters should be set in the URL:</p>
  10134. <ul>
  10135. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10136. be local.</li>
  10137. </ul>
  10138. <p>Body parameters:</p>
  10139. <ul>
  10140. <li><code>messages_per_second</code> - positive integer, optional. The number of actions that can
  10141. be performed in a second. Defaults to <code>0</code>.</li>
  10142. <li><code>burst_count</code> - positive integer, optional. How many actions that can be performed
  10143. before being limited. Defaults to <code>0</code>.</li>
  10144. </ul>
  10145. <p>To disable users' ratelimit set both values to <code>0</code>.</p>
  10146. <p><strong>Response</strong></p>
  10147. <p>The following fields are returned in the JSON response body:</p>
  10148. <ul>
  10149. <li><code>messages_per_second</code> - integer - The number of actions that can
  10150. be performed in a second.</li>
  10151. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10152. being limited.</li>
  10153. </ul>
  10154. <h3 id="delete-ratelimit"><a class="header" href="#delete-ratelimit">Delete ratelimit</a></h3>
  10155. <p>The API is:</p>
  10156. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10157. </code></pre>
  10158. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10159. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10160. <p>An empty JSON dict is returned.</p>
  10161. <pre><code class="language-json">{}
  10162. </code></pre>
  10163. <p><strong>Parameters</strong></p>
  10164. <p>The following parameters should be set in the URL:</p>
  10165. <ul>
  10166. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10167. be local.</li>
  10168. </ul>
  10169. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="version-api"><a class="header" href="#version-api">Version API</a></h1>
  10170. <p>This API returns the running Synapse version and the Python version
  10171. on which Synapse is being run. This is useful when a Synapse instance
  10172. is behind a proxy that does not forward the 'Server' header (which also
  10173. contains Synapse version information).</p>
  10174. <p>The api is:</p>
  10175. <pre><code>GET /_synapse/admin/v1/server_version
  10176. </code></pre>
  10177. <p>It returns a JSON body like the following:</p>
  10178. <pre><code class="language-json">{
  10179. &quot;server_version&quot;: &quot;0.99.2rc1 (b=develop, abcdef123)&quot;,
  10180. &quot;python_version&quot;: &quot;3.6.8&quot;
  10181. }
  10182. </code></pre>
  10183. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="using-the-synapse-manhole"><a class="header" href="#using-the-synapse-manhole">Using the synapse manhole</a></h1>
  10184. <p>The &quot;manhole&quot; allows server administrators to access a Python shell on a running
  10185. Synapse installation. This is a very powerful mechanism for administration and
  10186. debugging.</p>
  10187. <p><strong><em>Security Warning</em></strong></p>
  10188. <p>Note that this will give administrative access to synapse to <strong>all users</strong> with
  10189. shell access to the server. It should therefore <strong>not</strong> be enabled in
  10190. environments where untrusted users have shell access.</p>
  10191. <hr />
  10192. <p>To enable it, first uncomment the <code>manhole</code> listener configuration in
  10193. <code>homeserver.yaml</code>. The configuration is slightly different if you're using docker.</p>
  10194. <h4 id="docker-config"><a class="header" href="#docker-config">Docker config</a></h4>
  10195. <p>If you are using Docker, set <code>bind_addresses</code> to <code>['0.0.0.0']</code> as shown:</p>
  10196. <pre><code class="language-yaml">listeners:
  10197. - port: 9000
  10198. bind_addresses: ['0.0.0.0']
  10199. type: manhole
  10200. </code></pre>
  10201. <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
  10202. <code>manhole</code> port forwarding. The <code>-p 127.0.0.1:9000:9000</code> below is important: it
  10203. ensures that access to the <code>manhole</code> is only possible for local users.</p>
  10204. <pre><code class="language-bash">docker run -d --name synapse \
  10205. --mount type=volume,src=synapse-data,dst=/data \
  10206. -p 8008:8008 \
  10207. -p 127.0.0.1:9000:9000 \
  10208. matrixdotorg/synapse:latest
  10209. </code></pre>
  10210. <h4 id="native-config"><a class="header" href="#native-config">Native config</a></h4>
  10211. <p>If you are not using docker, set <code>bind_addresses</code> to <code>['::1', '127.0.0.1']</code> as shown.
  10212. The <code>bind_addresses</code> in the example below is important: it ensures that access to the
  10213. <code>manhole</code> is only possible for local users).</p>
  10214. <pre><code class="language-yaml">listeners:
  10215. - port: 9000
  10216. bind_addresses: ['::1', '127.0.0.1']
  10217. type: manhole
  10218. </code></pre>
  10219. <h4 id="accessing-synapse-manhole"><a class="header" href="#accessing-synapse-manhole">Accessing synapse manhole</a></h4>
  10220. <p>Then restart synapse, and point an ssh client at port 9000 on localhost, using
  10221. the username <code>matrix</code>:</p>
  10222. <pre><code class="language-bash">ssh -p9000 matrix@localhost
  10223. </code></pre>
  10224. <p>The password is <code>rabbithole</code>.</p>
  10225. <p>This gives a Python REPL in which <code>hs</code> gives access to the
  10226. <code>synapse.server.HomeServer</code> object - which in turn gives access to many other
  10227. parts of the process.</p>
  10228. <p>Note that any call which returns a coroutine will need to be wrapped in <code>ensureDeferred</code>.</p>
  10229. <p>As a simple example, retrieving an event from the database:</p>
  10230. <pre><code class="language-pycon">&gt;&gt;&gt; from twisted.internet import defer
  10231. &gt;&gt;&gt; defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
  10232. &lt;Deferred at 0x7ff253fc6998 current result: &lt;FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''&gt;&gt;
  10233. </code></pre>
  10234. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="how-to-monitor-synapse-metrics-using-prometheus"><a class="header" href="#how-to-monitor-synapse-metrics-using-prometheus">How to monitor Synapse metrics using Prometheus</a></h1>
  10235. <ol>
  10236. <li>
  10237. <p>Install Prometheus:</p>
  10238. <p>Follow instructions at
  10239. <a href="http://prometheus.io/docs/introduction/install/">http://prometheus.io/docs/introduction/install/</a></p>
  10240. </li>
  10241. <li>
  10242. <p>Enable Synapse metrics:</p>
  10243. <p>There are two methods of enabling metrics in Synapse.</p>
  10244. <p>The first serves the metrics as a part of the usual web server and
  10245. can be enabled by adding the &quot;metrics&quot; resource to the existing
  10246. listener as such:</p>
  10247. <pre><code class="language-yaml"> resources:
  10248. - names:
  10249. - client
  10250. - metrics
  10251. </code></pre>
  10252. <p>This provides a simple way of adding metrics to your Synapse
  10253. installation, and serves under <code>/_synapse/metrics</code>. If you do not
  10254. wish your metrics be publicly exposed, you will need to either
  10255. filter it out at your load balancer, or use the second method.</p>
  10256. <p>The second method runs the metrics server on a different port, in a
  10257. different thread to Synapse. This can make it more resilient to
  10258. heavy load meaning metrics cannot be retrieved, and can be exposed
  10259. to just internal networks easier. The served metrics are available
  10260. over HTTP only, and will be available at <code>/_synapse/metrics</code>.</p>
  10261. <p>Add a new listener to homeserver.yaml:</p>
  10262. <pre><code class="language-yaml"> listeners:
  10263. - type: metrics
  10264. port: 9000
  10265. bind_addresses:
  10266. - '0.0.0.0'
  10267. </code></pre>
  10268. <p>For both options, you will need to ensure that <code>enable_metrics</code> is
  10269. set to <code>True</code>.</p>
  10270. </li>
  10271. <li>
  10272. <p>Restart Synapse.</p>
  10273. </li>
  10274. <li>
  10275. <p>Add a Prometheus target for Synapse.</p>
  10276. <p>It needs to set the <code>metrics_path</code> to a non-default value (under
  10277. <code>scrape_configs</code>):</p>
  10278. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10279. scrape_interval: 15s
  10280. metrics_path: &quot;/_synapse/metrics&quot;
  10281. static_configs:
  10282. - targets: [&quot;my.server.here:port&quot;]
  10283. </code></pre>
  10284. <p>where <code>my.server.here</code> is the IP address of Synapse, and <code>port</code> is
  10285. the listener port configured with the <code>metrics</code> resource.</p>
  10286. <p>If your prometheus is older than 1.5.2, you will need to replace
  10287. <code>static_configs</code> in the above with <code>target_groups</code>.</p>
  10288. </li>
  10289. <li>
  10290. <p>Restart Prometheus.</p>
  10291. </li>
  10292. <li>
  10293. <p>Consider using the <a href="https://github.com/matrix-org/synapse/tree/master/contrib/grafana/">grafana dashboard</a>
  10294. and required <a href="https://github.com/matrix-org/synapse/tree/master/contrib/prometheus/">recording rules</a> </p>
  10295. </li>
  10296. </ol>
  10297. <h2 id="monitoring-workers"><a class="header" href="#monitoring-workers">Monitoring workers</a></h2>
  10298. <p>To monitor a Synapse installation using <a href="workers.html">workers</a>,
  10299. every worker needs to be monitored independently, in addition to
  10300. the main homeserver process. This is because workers don't send
  10301. their metrics to the main homeserver process, but expose them
  10302. directly (if they are configured to do so).</p>
  10303. <p>To allow collecting metrics from a worker, you need to add a
  10304. <code>metrics</code> listener to its configuration, by adding the following
  10305. under <code>worker_listeners</code>:</p>
  10306. <pre><code class="language-yaml"> - type: metrics
  10307. bind_address: ''
  10308. port: 9101
  10309. </code></pre>
  10310. <p>The <code>bind_address</code> and <code>port</code> parameters should be set so that
  10311. the resulting listener can be reached by prometheus, and they
  10312. don't clash with an existing worker.
  10313. With this example, the worker's metrics would then be available
  10314. on <code>http://127.0.0.1:9101</code>.</p>
  10315. <p>Example Prometheus target for Synapse with workers:</p>
  10316. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10317. scrape_interval: 15s
  10318. metrics_path: &quot;/_synapse/metrics&quot;
  10319. static_configs:
  10320. - targets: [&quot;my.server.here:port&quot;]
  10321. labels:
  10322. instance: &quot;my.server&quot;
  10323. job: &quot;master&quot;
  10324. index: 1
  10325. - targets: [&quot;my.workerserver.here:port&quot;]
  10326. labels:
  10327. instance: &quot;my.server&quot;
  10328. job: &quot;generic_worker&quot;
  10329. index: 1
  10330. - targets: [&quot;my.workerserver.here:port&quot;]
  10331. labels:
  10332. instance: &quot;my.server&quot;
  10333. job: &quot;generic_worker&quot;
  10334. index: 2
  10335. - targets: [&quot;my.workerserver.here:port&quot;]
  10336. labels:
  10337. instance: &quot;my.server&quot;
  10338. job: &quot;media_repository&quot;
  10339. index: 1
  10340. </code></pre>
  10341. <p>Labels (<code>instance</code>, <code>job</code>, <code>index</code>) can be defined as anything.
  10342. The labels are used to group graphs in grafana.</p>
  10343. <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>
  10344. <p>Synapse 1.2 updates the Prometheus metrics to match the naming
  10345. convention of the upstream <code>prometheus_client</code>. The old names are
  10346. considered deprecated and will be removed in a future version of
  10347. Synapse.</p>
  10348. <table><thead><tr><th>New Name</th><th>Old Name</th></tr></thead><tbody>
  10349. <tr><td>python_gc_objects_collected_total</td><td>python_gc_objects_collected</td></tr>
  10350. <tr><td>python_gc_objects_uncollectable_total</td><td>python_gc_objects_uncollectable</td></tr>
  10351. <tr><td>python_gc_collections_total</td><td>python_gc_collections</td></tr>
  10352. <tr><td>process_cpu_seconds_total</td><td>process_cpu_seconds</td></tr>
  10353. <tr><td>synapse_federation_client_sent_transactions_total</td><td>synapse_federation_client_sent_transactions</td></tr>
  10354. <tr><td>synapse_federation_client_events_processed_total</td><td>synapse_federation_client_events_processed</td></tr>
  10355. <tr><td>synapse_event_processing_loop_count_total</td><td>synapse_event_processing_loop_count</td></tr>
  10356. <tr><td>synapse_event_processing_loop_room_count_total</td><td>synapse_event_processing_loop_room_count</td></tr>
  10357. <tr><td>synapse_util_metrics_block_count_total</td><td>synapse_util_metrics_block_count</td></tr>
  10358. <tr><td>synapse_util_metrics_block_time_seconds_total</td><td>synapse_util_metrics_block_time_seconds</td></tr>
  10359. <tr><td>synapse_util_metrics_block_ru_utime_seconds_total</td><td>synapse_util_metrics_block_ru_utime_seconds</td></tr>
  10360. <tr><td>synapse_util_metrics_block_ru_stime_seconds_total</td><td>synapse_util_metrics_block_ru_stime_seconds</td></tr>
  10361. <tr><td>synapse_util_metrics_block_db_txn_count_total</td><td>synapse_util_metrics_block_db_txn_count</td></tr>
  10362. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds_total</td><td>synapse_util_metrics_block_db_txn_duration_seconds</td></tr>
  10363. <tr><td>synapse_util_metrics_block_db_sched_duration_seconds_total</td><td>synapse_util_metrics_block_db_sched_duration_seconds</td></tr>
  10364. <tr><td>synapse_background_process_start_count_total</td><td>synapse_background_process_start_count</td></tr>
  10365. <tr><td>synapse_background_process_ru_utime_seconds_total</td><td>synapse_background_process_ru_utime_seconds</td></tr>
  10366. <tr><td>synapse_background_process_ru_stime_seconds_total</td><td>synapse_background_process_ru_stime_seconds</td></tr>
  10367. <tr><td>synapse_background_process_db_txn_count_total</td><td>synapse_background_process_db_txn_count</td></tr>
  10368. <tr><td>synapse_background_process_db_txn_duration_seconds_total</td><td>synapse_background_process_db_txn_duration_seconds</td></tr>
  10369. <tr><td>synapse_background_process_db_sched_duration_seconds_total</td><td>synapse_background_process_db_sched_duration_seconds</td></tr>
  10370. <tr><td>synapse_storage_events_persisted_events_total</td><td>synapse_storage_events_persisted_events</td></tr>
  10371. <tr><td>synapse_storage_events_persisted_events_sep_total</td><td>synapse_storage_events_persisted_events_sep</td></tr>
  10372. <tr><td>synapse_storage_events_state_delta_total</td><td>synapse_storage_events_state_delta</td></tr>
  10373. <tr><td>synapse_storage_events_state_delta_single_event_total</td><td>synapse_storage_events_state_delta_single_event</td></tr>
  10374. <tr><td>synapse_storage_events_state_delta_reuse_delta_total</td><td>synapse_storage_events_state_delta_reuse_delta</td></tr>
  10375. <tr><td>synapse_federation_server_received_pdus_total</td><td>synapse_federation_server_received_pdus</td></tr>
  10376. <tr><td>synapse_federation_server_received_edus_total</td><td>synapse_federation_server_received_edus</td></tr>
  10377. <tr><td>synapse_handler_presence_notified_presence_total</td><td>synapse_handler_presence_notified_presence</td></tr>
  10378. <tr><td>synapse_handler_presence_federation_presence_out_total</td><td>synapse_handler_presence_federation_presence_out</td></tr>
  10379. <tr><td>synapse_handler_presence_presence_updates_total</td><td>synapse_handler_presence_presence_updates</td></tr>
  10380. <tr><td>synapse_handler_presence_timers_fired_total</td><td>synapse_handler_presence_timers_fired</td></tr>
  10381. <tr><td>synapse_handler_presence_federation_presence_total</td><td>synapse_handler_presence_federation_presence</td></tr>
  10382. <tr><td>synapse_handler_presence_bump_active_time_total</td><td>synapse_handler_presence_bump_active_time</td></tr>
  10383. <tr><td>synapse_federation_client_sent_edus_total</td><td>synapse_federation_client_sent_edus</td></tr>
  10384. <tr><td>synapse_federation_client_sent_pdu_destinations_count_total</td><td>synapse_federation_client_sent_pdu_destinations:count</td></tr>
  10385. <tr><td>synapse_federation_client_sent_pdu_destinations_total</td><td>synapse_federation_client_sent_pdu_destinations:total</td></tr>
  10386. <tr><td>synapse_handlers_appservice_events_processed_total</td><td>synapse_handlers_appservice_events_processed</td></tr>
  10387. <tr><td>synapse_notifier_notified_events_total</td><td>synapse_notifier_notified_events</td></tr>
  10388. <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>
  10389. <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>
  10390. <tr><td>synapse_http_httppusher_http_pushes_processed_total</td><td>synapse_http_httppusher_http_pushes_processed</td></tr>
  10391. <tr><td>synapse_http_httppusher_http_pushes_failed_total</td><td>synapse_http_httppusher_http_pushes_failed</td></tr>
  10392. <tr><td>synapse_http_httppusher_badge_updates_processed_total</td><td>synapse_http_httppusher_badge_updates_processed</td></tr>
  10393. <tr><td>synapse_http_httppusher_badge_updates_failed_total</td><td>synapse_http_httppusher_badge_updates_failed</td></tr>
  10394. </tbody></table>
  10395. <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>
  10396. <p>The duplicated metrics deprecated in Synapse 0.27.0 have been removed.</p>
  10397. <p>All time duration-based metrics have been changed to be seconds. This
  10398. affects:</p>
  10399. <table><thead><tr><th>msec -&gt; sec metrics</th></tr></thead><tbody>
  10400. <tr><td>python_gc_time</td></tr>
  10401. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10402. <tr><td>synapse_storage_query_time</td></tr>
  10403. <tr><td>synapse_storage_schedule_time</td></tr>
  10404. <tr><td>synapse_storage_transaction_time</td></tr>
  10405. </tbody></table>
  10406. <p>Several metrics have been changed to be histograms, which sort entries
  10407. into buckets and allow better analysis. The following metrics are now
  10408. histograms:</p>
  10409. <table><thead><tr><th>Altered metrics</th></tr></thead><tbody>
  10410. <tr><td>python_gc_time</td></tr>
  10411. <tr><td>python_twisted_reactor_pending_calls</td></tr>
  10412. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10413. <tr><td>synapse_http_server_response_time_seconds</td></tr>
  10414. <tr><td>synapse_storage_query_time</td></tr>
  10415. <tr><td>synapse_storage_schedule_time</td></tr>
  10416. <tr><td>synapse_storage_transaction_time</td></tr>
  10417. </tbody></table>
  10418. <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>
  10419. <p>Synapse 0.27.0 begins the process of rationalising the duplicate
  10420. <code>*:count</code> metrics reported for the resource tracking for code blocks and
  10421. HTTP requests.</p>
  10422. <p>At the same time, the corresponding <code>*:total</code> metrics are being renamed,
  10423. as the <code>:total</code> suffix no longer makes sense in the absence of a
  10424. corresponding <code>:count</code> metric.</p>
  10425. <p>To enable a graceful migration path, this release just adds new names
  10426. for the metrics being renamed. A future release will remove the old
  10427. ones.</p>
  10428. <p>The following table shows the new metrics, and the old metrics which
  10429. they are replacing.</p>
  10430. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10431. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_timer:count</td></tr>
  10432. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_utime:count</td></tr>
  10433. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_stime:count</td></tr>
  10434. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_count:count</td></tr>
  10435. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_duration:count</td></tr>
  10436. <tr><td>synapse_util_metrics_block_time_seconds</td><td>synapse_util_metrics_block_timer:total</td></tr>
  10437. <tr><td>synapse_util_metrics_block_ru_utime_seconds</td><td>synapse_util_metrics_block_ru_utime:total</td></tr>
  10438. <tr><td>synapse_util_metrics_block_ru_stime_seconds</td><td>synapse_util_metrics_block_ru_stime:total</td></tr>
  10439. <tr><td>synapse_util_metrics_block_db_txn_count</td><td>synapse_util_metrics_block_db_txn_count:total</td></tr>
  10440. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds</td><td>synapse_util_metrics_block_db_txn_duration:total</td></tr>
  10441. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_requests</td></tr>
  10442. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_time:count</td></tr>
  10443. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_utime:count</td></tr>
  10444. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_stime:count</td></tr>
  10445. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_count:count</td></tr>
  10446. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_duration:count</td></tr>
  10447. <tr><td>synapse_http_server_response_time_seconds</td><td>synapse_http_server_response_time:total</td></tr>
  10448. <tr><td>synapse_http_server_response_ru_utime_seconds</td><td>synapse_http_server_response_ru_utime:total</td></tr>
  10449. <tr><td>synapse_http_server_response_ru_stime_seconds</td><td>synapse_http_server_response_ru_stime:total</td></tr>
  10450. <tr><td>synapse_http_server_response_db_txn_count</td><td>synapse_http_server_response_db_txn_count:total</td></tr>
  10451. <tr><td>synapse_http_server_response_db_txn_duration_seconds</td><td>synapse_http_server_response_db_txn_duration:total</td></tr>
  10452. </tbody></table>
  10453. <h2 id="standard-metric-names"><a class="header" href="#standard-metric-names">Standard Metric Names</a></h2>
  10454. <p>As of synapse version 0.18.2, the format of the process-wide metrics has
  10455. been changed to fit prometheus standard naming conventions. Additionally
  10456. the units have been changed to seconds, from miliseconds.</p>
  10457. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10458. <tr><td>process_cpu_user_seconds_total</td><td>process_resource_utime / 1000</td></tr>
  10459. <tr><td>process_cpu_system_seconds_total</td><td>process_resource_stime / 1000</td></tr>
  10460. <tr><td>process_open_fds (no 'type' label)</td><td>process_fds</td></tr>
  10461. </tbody></table>
  10462. <p>The python-specific counts of garbage collector performance have been
  10463. renamed.</p>
  10464. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10465. <tr><td>python_gc_time</td><td>reactor_gc_time</td></tr>
  10466. <tr><td>python_gc_unreachable_total</td><td>reactor_gc_unreachable</td></tr>
  10467. <tr><td>python_gc_counts</td><td>reactor_gc_counts</td></tr>
  10468. </tbody></table>
  10469. <p>The twisted-specific reactor metrics have been renamed.</p>
  10470. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10471. <tr><td>python_twisted_reactor_pending_calls</td><td>reactor_pending_calls</td></tr>
  10472. <tr><td>python_twisted_reactor_tick_time</td><td>reactor_tick_time</td></tr>
  10473. </tbody></table>
  10474. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="request-log-format"><a class="header" href="#request-log-format">Request log format</a></h1>
  10475. <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>
  10476. <p>See the following for how to decode the dense data available from the default logging configuration.</p>
  10477. <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]
  10478. -AAAAAAAAAAAAAAAAAAAAA- -BBBBBBBBBBBBBBBBBBBBBB- -C- -DD- -EEEEEE- -FFFFFFFFF- -GG- -HHHHHHHHHHHHHHHHHHHHHHH- -IIIIII- -JJJJJJJ- -KKKKKK-, -LLLLLL- -MMMMMMM- -NNNNNN- O -P- -QQ- -RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR- -SSSSSSSSSSSS- -TTTTTT-
  10479. </code></pre>
  10480. <table><thead><tr><th>Part</th><th>Explanation</th></tr></thead><tbody>
  10481. <tr><td>AAAA</td><td>Timestamp request was logged (not recieved)</td></tr>
  10482. <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>
  10483. <tr><td>CCCC</td><td>Line number in code</td></tr>
  10484. <tr><td>DDDD</td><td>Log Level</td></tr>
  10485. <tr><td>EEEE</td><td>Request Identifier (This identifier is shared by related log lines)</td></tr>
  10486. <tr><td>FFFF</td><td>Source IP (Or X-Forwarded-For if enabled)</td></tr>
  10487. <tr><td>GGGG</td><td>Server Port</td></tr>
  10488. <tr><td>HHHH</td><td>Federated Server or Local User making request (blank if unauthenticated or not supplied)</td></tr>
  10489. <tr><td>IIII</td><td>Total Time to process the request</td></tr>
  10490. <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>
  10491. <tr><td>KKKK</td><td>Userland CPU time</td></tr>
  10492. <tr><td>LLLL</td><td>System CPU time</td></tr>
  10493. <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>
  10494. <tr><td>NNNN</td><td>Total time waiting for response to DB queries across all parallel DB work from this request</td></tr>
  10495. <tr><td>OOOO</td><td>Count of DB transactions performed</td></tr>
  10496. <tr><td>PPPP</td><td>Response body size</td></tr>
  10497. <tr><td>QQQQ</td><td>Response status code (prefixed with ! if the socket was closed before the response was generated)</td></tr>
  10498. <tr><td>RRRR</td><td>Request</td></tr>
  10499. <tr><td>SSSS</td><td>User-agent</td></tr>
  10500. <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>
  10501. </tbody></table>
  10502. <p>MMMM / NNNN can be greater than IIII if there are multiple slow database queries
  10503. running in parallel.</p>
  10504. <p>Some actions can result in multiple identical http requests, which will return
  10505. the same data, but only the first request will report time/transactions in
  10506. <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
  10507. response and will simultaneously return with the first request, but with very
  10508. small processing times.</p>
  10509. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><!--
  10510. Include the contents of CONTRIBUTING.md from the project root (where GitHub likes it
  10511. to be)
  10512. -->
  10513. <h1 id="contributing"><a class="header" href="#contributing">Contributing</a></h1>
  10514. <p>Welcome to Synapse</p>
  10515. <p>This document aims to get you started with contributing to this repo! </p>
  10516. <ul>
  10517. <li><a href="development/contributing_guide.html#1-who-can-contribute-to-synapse">1. Who can contribute to Synapse?</a></li>
  10518. <li><a href="development/contributing_guide.html#2-what-do-i-need">2. What do I need?</a></li>
  10519. <li><a href="development/contributing_guide.html#3-get-the-source">3. Get the source.</a></li>
  10520. <li><a href="development/contributing_guide.html#4-install-the-dependencies">4. Install the dependencies</a>
  10521. <ul>
  10522. <li><a href="development/contributing_guide.html#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></li>
  10523. <li><a href="development/contributing_guide.html#under-windows">Under Windows</a></li>
  10524. </ul>
  10525. </li>
  10526. <li><a href="development/contributing_guide.html#5-get-in-touch">5. Get in touch.</a></li>
  10527. <li><a href="development/contributing_guide.html#6-pick-an-issue">6. Pick an issue.</a></li>
  10528. <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>
  10529. <li><a href="development/contributing_guide.html#8-test-test-test">8. Test, test, test!</a>
  10530. <ul>
  10531. <li><a href="development/contributing_guide.html#run-the-linters">Run the linters.</a></li>
  10532. <li><a href="development/contributing_guide.html#run-the-unit-tests">Run the unit tests.</a></li>
  10533. <li><a href="development/contributing_guide.html#run-the-integration-tests">Run the integration tests.</a></li>
  10534. </ul>
  10535. </li>
  10536. <li><a href="development/contributing_guide.html#9-submit-your-patch">9. Submit your patch.</a>
  10537. <ul>
  10538. <li><a href="development/contributing_guide.html#changelog">Changelog</a>
  10539. <ul>
  10540. <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>
  10541. <li><a href="development/contributing_guide.html#debian-changelog">Debian changelog</a></li>
  10542. </ul>
  10543. </li>
  10544. <li><a href="development/contributing_guide.html#sign-off">Sign off</a></li>
  10545. </ul>
  10546. </li>
  10547. <li><a href="development/contributing_guide.html#10-turn-feedback-into-better-code">10. Turn feedback into better code.</a></li>
  10548. <li><a href="development/contributing_guide.html#11-find-a-new-issue">11. Find a new issue.</a></li>
  10549. <li><a href="development/contributing_guide.html#notes-for-maintainers-on-merging-prs-etc">Notes for maintainers on merging PRs etc</a></li>
  10550. <li><a href="development/contributing_guide.html#conclusion">Conclusion</a></li>
  10551. </ul>
  10552. <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>
  10553. <p>Everyone is welcome to contribute code to <a href="https://github.com/matrix-org">matrix.org
  10554. projects</a>, provided that they are willing to
  10555. license their contributions under the same license as the project itself. We
  10556. follow a simple 'inbound=outbound' model for contributions: the act of
  10557. submitting an 'inbound' contribution means that the contributor agrees to
  10558. license the code under the same terms as the project's overall 'outbound'
  10559. license - in our case, this is almost always Apache Software License v2 (see
  10560. <a href="development/LICENSE">LICENSE</a>).</p>
  10561. <h1 id="2-what-do-i-need"><a class="header" href="#2-what-do-i-need">2. What do I need?</a></h1>
  10562. <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>
  10563. <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>
  10564. <p>For some tests, you will need <a href="https://docs.docker.com/get-docker/">a recent version of Docker</a>.</p>
  10565. <h1 id="3-get-the-source"><a class="header" href="#3-get-the-source">3. Get the source.</a></h1>
  10566. <p>The preferred and easiest way to contribute changes is to fork the relevant
  10567. 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
  10568. changes into our repo.</p>
  10569. <p>Please base your changes on the <code>develop</code> branch.</p>
  10570. <pre><code class="language-sh">git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git
  10571. git checkout develop
  10572. </code></pre>
  10573. <p>If you need help getting started with git, this is beyond the scope of the document, but you
  10574. can find many good git tutorials on the web.</p>
  10575. <h1 id="4-install-the-dependencies"><a class="header" href="#4-install-the-dependencies">4. Install the dependencies</a></h1>
  10576. <h2 id="under-unix-macos-linux-bsd-"><a class="header" href="#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></h2>
  10577. <p>Once you have installed Python 3 and added the source, please open a terminal and
  10578. setup a <em>virtualenv</em>, as follows:</p>
  10579. <pre><code class="language-sh">cd path/where/you/have/cloned/the/repository
  10580. python3 -m venv ./env
  10581. source ./env/bin/activate
  10582. pip install -e &quot;.[all,lint,mypy,test]&quot;
  10583. pip install tox
  10584. </code></pre>
  10585. <p>This will install the developer dependencies for the project.</p>
  10586. <h2 id="under-windows"><a class="header" href="#under-windows">Under Windows</a></h2>
  10587. <p>TBD</p>
  10588. <h1 id="5-get-in-touch"><a class="header" href="#5-get-in-touch">5. Get in touch.</a></h1>
  10589. <p>Join our developer community on Matrix: #synapse-dev:matrix.org !</p>
  10590. <h1 id="6-pick-an-issue"><a class="header" href="#6-pick-an-issue">6. Pick an issue.</a></h1>
  10591. <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>
  10592. to work on.</p>
  10593. <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>
  10594. <p>Synapse's code style is documented <a href="development/docs/code_style.html">here</a>. Please follow
  10595. it, including the conventions for the <a href="development/docs/code_style.html#configuration-file-format">sample configuration
  10596. file</a>.</p>
  10597. <p>There is a growing amount of documentation located in the <a href="development/docs">docs</a>
  10598. directory. This documentation is intended primarily for sysadmins running their
  10599. own Synapse instance, as well as developers interacting externally with
  10600. Synapse. <a href="development/docs/dev">docs/dev</a> exists primarily to house documentation for
  10601. Synapse developers. <a href="development/docs/admin_api">docs/admin_api</a> houses documentation
  10602. regarding Synapse's Admin API, which is used mostly by sysadmins and external
  10603. service developers.</p>
  10604. <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
  10605. Markdown</a>.</p>
  10606. <p>Some documentation also exists in <a href="https://github.com/matrix-org/synapse/wiki">Synapse's GitHub
  10607. Wiki</a>, although this is primarily
  10608. contributed to by community authors.</p>
  10609. <h1 id="8-test-test-test"><a class="header" href="#8-test-test-test">8. Test, test, test!</a></h1>
  10610. <p><a name="test-test-test"></a></p>
  10611. <p>While you're developing and before submitting a patch, you'll
  10612. want to test your code.</p>
  10613. <h2 id="run-the-linters"><a class="header" href="#run-the-linters">Run the linters.</a></h2>
  10614. <p>The linters look at your code and do two things:</p>
  10615. <ul>
  10616. <li>ensure that your code follows the coding style adopted by the project;</li>
  10617. <li>catch a number of errors in your code.</li>
  10618. </ul>
  10619. <p>They're pretty fast, don't hesitate!</p>
  10620. <pre><code class="language-sh">source ./env/bin/activate
  10621. ./scripts-dev/lint.sh
  10622. </code></pre>
  10623. <p>Note that this script <em>will modify your files</em> to fix styling errors.
  10624. Make sure that you have saved all your files.</p>
  10625. <p>If you wish to restrict the linters to only the files changed since the last commit
  10626. (much faster!), you can instead run:</p>
  10627. <pre><code class="language-sh">source ./env/bin/activate
  10628. ./scripts-dev/lint.sh -d
  10629. </code></pre>
  10630. <p>Or if you know exactly which files you wish to lint, you can instead run:</p>
  10631. <pre><code class="language-sh">source ./env/bin/activate
  10632. ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
  10633. </code></pre>
  10634. <h2 id="run-the-unit-tests"><a class="header" href="#run-the-unit-tests">Run the unit tests.</a></h2>
  10635. <p>The unit tests run parts of Synapse, including your changes, to see if anything
  10636. was broken. They are slower than the linters but will typically catch more errors.</p>
  10637. <pre><code class="language-sh">source ./env/bin/activate
  10638. trial tests
  10639. </code></pre>
  10640. <p>If you wish to only run <em>some</em> unit tests, you may specify
  10641. another module instead of <code>tests</code> - or a test class or a method:</p>
  10642. <pre><code class="language-sh">source ./env/bin/activate
  10643. trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
  10644. </code></pre>
  10645. <p>If your tests fail, you may wish to look at the logs (the default log level is <code>ERROR</code>):</p>
  10646. <pre><code class="language-sh">less _trial_temp/test.log
  10647. </code></pre>
  10648. <p>To increase the log level for the tests, set <code>SYNAPSE_TEST_LOG_LEVEL</code>:</p>
  10649. <pre><code class="language-sh">SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
  10650. </code></pre>
  10651. <h2 id="run-the-integration-tests"><a class="header" href="#run-the-integration-tests">Run the integration tests.</a></h2>
  10652. <p>The integration tests are a more comprehensive suite of tests. They
  10653. run a full version of Synapse, including your changes, to check if
  10654. anything was broken. They are slower than the unit tests but will
  10655. typically catch more errors.</p>
  10656. <p>The following command will let you run the integration test with the most common
  10657. configuration:</p>
  10658. <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
  10659. </code></pre>
  10660. <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>
  10661. <h1 id="9-submit-your-patch"><a class="header" href="#9-submit-your-patch">9. Submit your patch.</a></h1>
  10662. <p>Once you're happy with your patch, it's time to prepare a Pull Request.</p>
  10663. <p>To prepare a Pull Request, please:</p>
  10664. <ol>
  10665. <li>verify that <a href="development/contributing_guide.html#test-test-test">all the tests pass</a>, including the coding style;</li>
  10666. <li><a href="development/contributing_guide.html#sign-off">sign off</a> your contribution;</li>
  10667. <li><code>git push</code> your commit to your fork of Synapse;</li>
  10668. <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>
  10669. <li>add a <a href="development/contributing_guide.html#changelog">changelog entry</a> and push it to your Pull Request;</li>
  10670. <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>
  10671. </ol>
  10672. <h2 id="changelog"><a class="header" href="#changelog">Changelog</a></h2>
  10673. <p>All changes, even minor ones, need a corresponding changelog / newsfragment
  10674. entry. These are managed by <a href="https://github.com/hawkowl/towncrier">Towncrier</a>.</p>
  10675. <p>To create a changelog entry, make a new file in the <code>changelog.d</code> directory named
  10676. in the format of <code>PRnumber.type</code>. The type can be one of the following:</p>
  10677. <ul>
  10678. <li><code>feature</code></li>
  10679. <li><code>bugfix</code></li>
  10680. <li><code>docker</code> (for updates to the Docker image)</li>
  10681. <li><code>doc</code> (for updates to the documentation)</li>
  10682. <li><code>removal</code> (also used for deprecations)</li>
  10683. <li><code>misc</code> (for internal-only changes)</li>
  10684. </ul>
  10685. <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
  10686. release, so the content of the file should be a short description of your
  10687. change in the same style as the rest of the changelog. The file can contain Markdown
  10688. formatting, and should end with a full stop (.) or an exclamation mark (!) for
  10689. consistency.</p>
  10690. <p>Adding credits to the changelog is encouraged, we value your
  10691. contributions and would like to have you shouted out in the release notes!</p>
  10692. <p>For example, a fix in PR #1234 would have its changelog entry in
  10693. <code>changelog.d/1234.bugfix</code>, and contain content like:</p>
  10694. <blockquote>
  10695. <p>The security levels of Florbs are now validated when received
  10696. via the <code>/federation/florb</code> endpoint. Contributed by Jane Matrix.</p>
  10697. </blockquote>
  10698. <p>If there are multiple pull requests involved in a single bugfix/feature/etc,
  10699. then the content for each <code>changelog.d</code> file should be the same. Towncrier will
  10700. merge the matching files together into a single changelog entry when we come to
  10701. release.</p>
  10702. <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>
  10703. <p>Obviously, you don't know if you should call your newsfile
  10704. <code>1234.bugfix</code> or <code>5678.bugfix</code> until you create the PR, which leads to a
  10705. chicken-and-egg problem.</p>
  10706. <p>There are two options for solving this:</p>
  10707. <ol>
  10708. <li>
  10709. <p>Open the PR without a changelog file, see what number you got, and <em>then</em>
  10710. add the changelog file to your branch (see <a href="development/contributing_guide.html#updating-your-pull-request">Updating your pull
  10711. request</a>), or:</p>
  10712. </li>
  10713. <li>
  10714. <p>Look at the <a href="https://github.com/matrix-org/synapse/issues?q=">list of all
  10715. issues/PRs</a>, add one to the
  10716. highest number you see, and quickly open the PR before somebody else claims
  10717. your number.</p>
  10718. <p><a href="https://github.com/richvdh/scripts/blob/master/next_github_number.sh">This
  10719. script</a>
  10720. might be helpful if you find yourself doing this a lot.</p>
  10721. </li>
  10722. </ol>
  10723. <p>Sorry, we know it's a bit fiddly, but it's <em>really</em> helpful for us when we come
  10724. to put together a release!</p>
  10725. <h3 id="debian-changelog"><a class="header" href="#debian-changelog">Debian changelog</a></h3>
  10726. <p>Changes which affect the debian packaging files (in <code>debian</code>) are an
  10727. exception to the rule that all changes require a <code>changelog.d</code> file.</p>
  10728. <p>In this case, you will need to add an entry to the debian changelog for the
  10729. next release. For this, run the following command:</p>
  10730. <pre><code>dch
  10731. </code></pre>
  10732. <p>This will make up a new version number (if there isn't already an unreleased
  10733. version in flight), and open an editor where you can add a new changelog entry.
  10734. (Our release process will ensure that the version number and maintainer name is
  10735. corrected for the release.)</p>
  10736. <p>If your change affects both the debian packaging <em>and</em> files outside the debian
  10737. directory, you will need both a regular newsfragment <em>and</em> an entry in the
  10738. debian changelog. (Though typically such changes should be submitted as two
  10739. separate pull requests.)</p>
  10740. <h2 id="sign-off"><a class="header" href="#sign-off">Sign off</a></h2>
  10741. <p>In order to have a concrete record that your contribution is intentional
  10742. and you agree to license it under the same terms as the project's license, we've adopted the
  10743. same lightweight approach that the Linux Kernel
  10744. <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>,
  10745. <a href="https://github.com/docker/docker/blob/master/CONTRIBUTING.md">Docker</a>, and many other
  10746. projects use: the DCO (Developer Certificate of Origin:
  10747. http://developercertificate.org/). This is a simple declaration that you wrote
  10748. the contribution or otherwise have the right to contribute it to Matrix:</p>
  10749. <pre><code>Developer Certificate of Origin
  10750. Version 1.1
  10751. Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
  10752. 660 York Street, Suite 102,
  10753. San Francisco, CA 94110 USA
  10754. Everyone is permitted to copy and distribute verbatim copies of this
  10755. license document, but changing it is not allowed.
  10756. Developer's Certificate of Origin 1.1
  10757. By making a contribution to this project, I certify that:
  10758. (a) The contribution was created in whole or in part by me and I
  10759. have the right to submit it under the open source license
  10760. indicated in the file; or
  10761. (b) The contribution is based upon previous work that, to the best
  10762. of my knowledge, is covered under an appropriate open source
  10763. license and I have the right under that license to submit that
  10764. work with modifications, whether created in whole or in part
  10765. by me, under the same open source license (unless I am
  10766. permitted to submit under a different license), as indicated
  10767. in the file; or
  10768. (c) The contribution was provided directly to me by some other
  10769. person who certified (a), (b) or (c) and I have not modified
  10770. it.
  10771. (d) I understand and agree that this project and the contribution
  10772. are public and that a record of the contribution (including all
  10773. personal information I submit with it, including my sign-off) is
  10774. maintained indefinitely and may be redistributed consistent with
  10775. this project or the open source license(s) involved.
  10776. </code></pre>
  10777. <p>If you agree to this for your contribution, then all that's needed is to
  10778. include the line in your commit or pull request comment:</p>
  10779. <pre><code>Signed-off-by: Your Name &lt;your@email.example.org&gt;
  10780. </code></pre>
  10781. <p>We accept contributions under a legally identifiable name, such as
  10782. your name on government documentation or common-law names (names
  10783. claimed by legitimate usage or repute). Unfortunately, we cannot
  10784. accept anonymous contributions at this time.</p>
  10785. <p>Git allows you to add this signoff automatically when using the <code>-s</code>
  10786. flag to <code>git commit</code>, which uses the name and email set in your
  10787. <code>user.name</code> and <code>user.email</code> git configs.</p>
  10788. <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>
  10789. <p>Once the Pull Request is opened, you will see a few things:</p>
  10790. <ol>
  10791. <li>our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;</li>
  10792. <li>one or more of the developers will take a look at your Pull Request and offer feedback.</li>
  10793. </ol>
  10794. <p>From this point, you should:</p>
  10795. <ol>
  10796. <li>Look at the results of the CI pipeline.
  10797. <ul>
  10798. <li>If there is any error, fix the error.</li>
  10799. </ul>
  10800. </li>
  10801. <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>
  10802. <li>Create a new commit with the changes.
  10803. <ul>
  10804. <li>Please do NOT overwrite the history. New commits make the reviewer's life easier.</li>
  10805. <li>Push this commits to your Pull Request.</li>
  10806. </ul>
  10807. </li>
  10808. <li>Back to 1.</li>
  10809. </ol>
  10810. <p>Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!</p>
  10811. <h1 id="11-find-a-new-issue"><a class="header" href="#11-find-a-new-issue">11. Find a new issue.</a></h1>
  10812. <p>By now, you know the drill!</p>
  10813. <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>
  10814. <p>There are some notes for those with commit access to the project on how we
  10815. manage git <a href="development/docs/dev/git.html">here</a>.</p>
  10816. <h1 id="conclusion"><a class="header" href="#conclusion">Conclusion</a></h1>
  10817. <p>That's it! Matrix is a very open and collaborative project as you might expect
  10818. given our obsession with open communication. If we're going to successfully
  10819. matrix together all the fragmented communication technologies out there we are
  10820. reliant on contributions and collaboration from the community to do so. So
  10821. please get involved - and we hope you have as much fun hacking on Matrix as we
  10822. do!</p>
  10823. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="code-style"><a class="header" href="#code-style">Code Style</a></h1>
  10824. <h2 id="formatting-tools"><a class="header" href="#formatting-tools">Formatting tools</a></h2>
  10825. <p>The Synapse codebase uses a number of code formatting tools in order to
  10826. quickly and automatically check for formatting (and sometimes logical)
  10827. errors in code.</p>
  10828. <p>The necessary tools are detailed below.</p>
  10829. <p>First install them with:</p>
  10830. <pre><code>pip install -e &quot;.[lint,mypy]&quot;
  10831. </code></pre>
  10832. <ul>
  10833. <li>
  10834. <p><strong>black</strong></p>
  10835. <p>The Synapse codebase uses <a href="https://pypi.org/project/black/">black</a>
  10836. as an opinionated code formatter, ensuring all comitted code is
  10837. properly formatted.</p>
  10838. <p>Have <code>black</code> auto-format your code (it shouldn't change any
  10839. functionality) with:</p>
  10840. <pre><code>black . --exclude=&quot;\.tox|build|env&quot;
  10841. </code></pre>
  10842. </li>
  10843. <li>
  10844. <p><strong>flake8</strong></p>
  10845. <p><code>flake8</code> is a code checking tool. We require code to pass <code>flake8</code>
  10846. before being merged into the codebase.</p>
  10847. <p>Check all application and test code with:</p>
  10848. <pre><code>flake8 synapse tests
  10849. </code></pre>
  10850. </li>
  10851. <li>
  10852. <p><strong>isort</strong></p>
  10853. <p><code>isort</code> ensures imports are nicely formatted, and can suggest and
  10854. auto-fix issues such as double-importing.</p>
  10855. <p>Auto-fix imports with:</p>
  10856. <pre><code>isort -rc synapse tests
  10857. </code></pre>
  10858. <p><code>-rc</code> means to recursively search the given directories.</p>
  10859. </li>
  10860. </ul>
  10861. <p>It's worth noting that modern IDEs and text editors can run these tools
  10862. automatically on save. It may be worth looking into whether this
  10863. functionality is supported in your editor for a more convenient
  10864. development workflow. It is not, however, recommended to run <code>flake8</code> on
  10865. save as it takes a while and is very resource intensive.</p>
  10866. <h2 id="general-rules"><a class="header" href="#general-rules">General rules</a></h2>
  10867. <ul>
  10868. <li><strong>Naming</strong>:
  10869. <ul>
  10870. <li>Use camel case for class and type names</li>
  10871. <li>Use underscores for functions and variables.</li>
  10872. </ul>
  10873. </li>
  10874. <li><strong>Docstrings</strong>: should follow the <a href="https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings">google code
  10875. style</a>.
  10876. See the
  10877. <a href="http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html">examples</a>
  10878. in the sphinx documentation.</li>
  10879. <li><strong>Imports</strong>:
  10880. <ul>
  10881. <li>
  10882. <p>Imports should be sorted by <code>isort</code> as described above.</p>
  10883. </li>
  10884. <li>
  10885. <p>Prefer to import classes and functions rather than packages or
  10886. modules.</p>
  10887. <p>Example:</p>
  10888. <pre><code>from synapse.types import UserID
  10889. ...
  10890. user_id = UserID(local, server)
  10891. </code></pre>
  10892. <p>is preferred over:</p>
  10893. <pre><code>from synapse import types
  10894. ...
  10895. user_id = types.UserID(local, server)
  10896. </code></pre>
  10897. <p>(or any other variant).</p>
  10898. <p>This goes against the advice in the Google style guide, but it
  10899. means that errors in the name are caught early (at import time).</p>
  10900. </li>
  10901. <li>
  10902. <p>Avoid wildcard imports (<code>from synapse.types import *</code>) and
  10903. relative imports (<code>from .types import UserID</code>).</p>
  10904. </li>
  10905. </ul>
  10906. </li>
  10907. </ul>
  10908. <h2 id="configuration-file-format"><a class="header" href="#configuration-file-format">Configuration file format</a></h2>
  10909. <p>The <a href="./sample_config.yaml">sample configuration file</a> acts as a
  10910. reference to Synapse's configuration options for server administrators.
  10911. Remember that many readers will be unfamiliar with YAML and server
  10912. administration in general, so that it is important that the file be as
  10913. easy to understand as possible, which includes following a consistent
  10914. format.</p>
  10915. <p>Some guidelines follow:</p>
  10916. <ul>
  10917. <li>
  10918. <p>Sections should be separated with a heading consisting of a single
  10919. line prefixed and suffixed with <code>##</code>. There should be <strong>two</strong> blank
  10920. lines before the section header, and <strong>one</strong> after.</p>
  10921. </li>
  10922. <li>
  10923. <p>Each option should be listed in the file with the following format:</p>
  10924. <ul>
  10925. <li>
  10926. <p>A comment describing the setting. Each line of this comment
  10927. should be prefixed with a hash (<code>#</code>) and a space.</p>
  10928. <p>The comment should describe the default behaviour (ie, what
  10929. happens if the setting is omitted), as well as what the effect
  10930. will be if the setting is changed.</p>
  10931. <p>Often, the comment end with something like &quot;uncomment the
  10932. following to <do action>&quot;.</p>
  10933. </li>
  10934. <li>
  10935. <p>A line consisting of only <code>#</code>.</p>
  10936. </li>
  10937. <li>
  10938. <p>A commented-out example setting, prefixed with only <code>#</code>.</p>
  10939. <p>For boolean (on/off) options, convention is that this example
  10940. should be the <em>opposite</em> to the default (so the comment will end
  10941. with &quot;Uncomment the following to enable [or disable]
  10942. <feature>.&quot; For other options, the example should give some
  10943. non-default value which is likely to be useful to the reader.</p>
  10944. </li>
  10945. </ul>
  10946. </li>
  10947. <li>
  10948. <p>There should be a blank line between each option.</p>
  10949. </li>
  10950. <li>
  10951. <p>Where several settings are grouped into a single dict, <em>avoid</em> the
  10952. convention where the whole block is commented out, resulting in
  10953. comment lines starting <code># #</code>, as this is hard to read and confusing
  10954. to edit. Instead, leave the top-level config option uncommented, and
  10955. follow the conventions above for sub-options. Ensure that your code
  10956. correctly handles the top-level option being set to <code>None</code> (as it
  10957. will be if no sub-options are enabled).</p>
  10958. </li>
  10959. <li>
  10960. <p>Lines should be wrapped at 80 characters.</p>
  10961. </li>
  10962. <li>
  10963. <p>Use two-space indents.</p>
  10964. </li>
  10965. <li>
  10966. <p><code>true</code> and <code>false</code> are spelt thus (as opposed to <code>True</code>, etc.)</p>
  10967. </li>
  10968. <li>
  10969. <p>Use single quotes (<code>'</code>) rather than double-quotes (<code>&quot;</code>) or backticks
  10970. (<code>`</code>) to refer to configuration options.</p>
  10971. </li>
  10972. </ul>
  10973. <p>Example:</p>
  10974. <pre><code>## Frobnication ##
  10975. # The frobnicator will ensure that all requests are fully frobnicated.
  10976. # To enable it, uncomment the following.
  10977. #
  10978. #frobnicator_enabled: true
  10979. # By default, the frobnicator will frobnicate with the default frobber.
  10980. # The following will make it use an alternative frobber.
  10981. #
  10982. #frobincator_frobber: special_frobber
  10983. # Settings for the frobber
  10984. #
  10985. frobber:
  10986. # frobbing speed. Defaults to 1.
  10987. #
  10988. #speed: 10
  10989. # frobbing distance. Defaults to 1000.
  10990. #
  10991. #distance: 100
  10992. </code></pre>
  10993. <p>Note that the sample configuration is generated from the synapse code
  10994. and is maintained by a script, <code>scripts-dev/generate_sample_config</code>.
  10995. Making sure that the output from this script matches the desired format
  10996. is left as an exercise for the reader!</p>
  10997. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="some-notes-on-how-we-use-git"><a class="header" href="#some-notes-on-how-we-use-git">Some notes on how we use git</a></h1>
  10998. <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>
  10999. <p>In an ideal world, our git commit history would be a linear progression of
  11000. commits each of which contains a single change building on what came
  11001. before. Here, by way of an arbitrary example, is the top of <code>git log --graph b2dba0607</code>:</p>
  11002. <img src="dev/git/clean.png" alt="clean git graph" width="500px">
  11003. <p>Note how the commit comment explains clearly what is changing and why. Also
  11004. note the <em>absence</em> of merge commits, as well as the absence of commits called
  11005. things like (to pick a few culprits):
  11006. <a href="https://github.com/matrix-org/synapse/commit/84691da6c">“pep8”</a>, <a href="https://github.com/matrix-org/synapse/commit/474810d9d">“fix broken
  11007. test”</a>,
  11008. <a href="https://github.com/matrix-org/synapse/commit/c9d72e457">“oops”</a>,
  11009. <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
  11010. the president?”</a>.</p>
  11011. <p>There are a number of reasons why keeping a clean commit history is a good
  11012. thing:</p>
  11013. <ul>
  11014. <li>
  11015. <p>From time to time, after a change lands, it turns out to be necessary to
  11016. revert it, or to backport it to a release branch. Those operations are
  11017. <em>much</em> easier when the change is contained in a single commit.</p>
  11018. </li>
  11019. <li>
  11020. <p>Similarly, it's much easier to answer questions like “is the fix for
  11021. <code>/publicRooms</code> on the release branch?” if that change consists of a single
  11022. commit.</p>
  11023. </li>
  11024. <li>
  11025. <p>Likewise: “what has changed on this branch in the last week?” is much
  11026. clearer without merges and “pep8” commits everywhere.</p>
  11027. </li>
  11028. <li>
  11029. <p>Sometimes we need to figure out where a bug got introduced, or some
  11030. behaviour changed. One way of doing that is with <code>git bisect</code>: pick an
  11031. arbitrary commit between the known good point and the known bad point, and
  11032. see how the code behaves. However, that strategy fails if the commit you
  11033. chose is the middle of someone's epic branch in which they broke the world
  11034. before putting it back together again.</p>
  11035. </li>
  11036. </ul>
  11037. <p>One counterargument is that it is sometimes useful to see how a PR evolved as
  11038. it went through review cycles. This is true, but that information is always
  11039. 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
  11040. namespace</a>).</p>
  11041. <p>Of course, in reality, things are more complicated than that. We have release
  11042. branches as well as <code>develop</code> and <code>master</code>, and we deliberately merge changes
  11043. between them. Bugs often slip through and have to be fixed later. That's all
  11044. fine: this not a cast-iron rule which must be obeyed, but an ideal to aim
  11045. towards.</p>
  11046. <h2 id="merges-squashes-rebases-wtf"><a class="header" href="#merges-squashes-rebases-wtf">Merges, squashes, rebases: wtf?</a></h2>
  11047. <p>Ok, so that's what we'd like to achieve. How do we achieve it?</p>
  11048. <p>The TL;DR is: when you come to merge a pull request, you <em>probably</em> want to
  11049. “squash and merge”:</p>
  11050. <p><img src="dev/git/squash.png" alt="squash and merge" />.</p>
  11051. <p>(This applies whether you are merging your own PR, or that of another
  11052. contributor.)</p>
  11053. <p>“Squash and merge”<sup id="a1"><a href="dev/git.html#f1">1</a></sup> takes all of the changes in the
  11054. PR, and bundles them into a single commit. GitHub gives you the opportunity to
  11055. edit the commit message before you confirm, and normally you should do so,
  11056. because the default will be useless (again: <code>* woops typo</code> is not a useful
  11057. thing to keep in the historical record).</p>
  11058. <p>The main problem with this approach comes when you have a series of pull
  11059. requests which build on top of one another: as soon as you squash-merge the
  11060. first PR, you'll end up with a stack of conflicts to resolve in all of the
  11061. others. In general, it's best to avoid this situation in the first place by
  11062. trying not to have multiple related PRs in flight at the same time. Still,
  11063. sometimes that's not possible and doing a regular merge is the lesser evil.</p>
  11064. <p>Another occasion in which a regular merge makes more sense is a PR where you've
  11065. deliberately created a series of commits each of which makes sense in its own
  11066. right. For example: <a href="https://github.com/matrix-org/synapse/pull/6837">a PR which gradually propagates a refactoring operation
  11067. through the codebase</a>, or <a href="https://github.com/matrix-org/synapse/pull/5987">a
  11068. PR which is the culmination of several other
  11069. PRs</a>. In this case the ability
  11070. to figure out when a particular change/bug was introduced could be very useful.</p>
  11071. <p>Ultimately: <strong>this is not a hard-and-fast-rule</strong>. If in doubt, ask yourself “do
  11072. each of the commits I am about to merge make sense in their own right”, but
  11073. remember that we're just doing our best to balance “keeping the commit history
  11074. clean” with other factors.</p>
  11075. <h2 id="git-branching-model"><a class="header" href="#git-branching-model">Git branching model</a></h2>
  11076. <p>A <a href="https://nvie.com/posts/a-successful-git-branching-model/">lot</a>
  11077. <a href="http://scottchacon.com/2011/08/31/github-flow.html">of</a>
  11078. <a href="https://www.endoflineblog.com/gitflow-considered-harmful">words</a> have been
  11079. written in the past about git branching models (no really, <a href="https://martinfowler.com/articles/branching-patterns.html">a
  11080. lot</a>). I tend to
  11081. think the whole thing is overblown. Fundamentally, it's not that
  11082. complicated. Here's how we do it.</p>
  11083. <p>Let's start with a picture:</p>
  11084. <p><img src="dev/git/branches.jpg" alt="branching model" /></p>
  11085. <p>It looks complicated, but it's really not. There's one basic rule: <em>anyone</em> is
  11086. free to merge from <em>any</em> more-stable branch to <em>any</em> less-stable branch at
  11087. <em>any</em> time<sup id="a2"><a href="dev/git.html#f2">2</a></sup>. (The principle behind this is that if a
  11088. change is good enough for the more-stable branch, then it's also good enough go
  11089. put in a less-stable branch.)</p>
  11090. <p>Meanwhile, merging (or squashing, as per the above) from a less-stable to a
  11091. more-stable branch is a deliberate action in which you want to publish a change
  11092. or a set of changes to (some subset of) the world: for example, this happens
  11093. when a PR is landed, or as part of our release process.</p>
  11094. <p>So, what counts as a more- or less-stable branch? A little reflection will show
  11095. that our active branches are ordered thus, from more-stable to less-stable:</p>
  11096. <ul>
  11097. <li><code>master</code> (tracks our last release).</li>
  11098. <li><code>release-vX.Y</code> (the branch where we prepare the next release)<sup
  11099. id="a3"><a href="dev/git.html#f3">3</a></sup>.</li>
  11100. <li>PR branches which are targeting the release.</li>
  11101. <li><code>develop</code> (our &quot;mainline&quot; branch containing our bleeding-edge).</li>
  11102. <li>regular PR branches.</li>
  11103. </ul>
  11104. <p>The corollary is: if you have a bugfix that needs to land in both
  11105. <code>release-vX.Y</code> <em>and</em> <code>develop</code>, then you should base your PR on
  11106. <code>release-vX.Y</code>, get it merged there, and then merge from <code>release-vX.Y</code> to
  11107. <code>develop</code>. (If a fix lands in <code>develop</code> and we later need it in a
  11108. release-branch, we can of course cherry-pick it, but landing it in the release
  11109. branch first helps reduce the chance of annoying conflicts.)</p>
  11110. <hr />
  11111. <p><b id="f1">[1]</b>: “Squash and merge” is GitHub's term for this
  11112. operation. Given that there is no merge involved, I'm not convinced it's the
  11113. most intuitive name. <a href="dev/git.html#a1">^</a></p>
  11114. <p><b id="f2">[2]</b>: Well, anyone with commit access.<a href="dev/git.html#a2">^</a></p>
  11115. <p><b id="f3">[3]</b>: Very, very occasionally (I think this has happened once in
  11116. the history of Synapse), we've had two releases in flight at once. Obviously,
  11117. <code>release-v1.2</code> is more-stable than <code>release-v1.3</code>. <a href="dev/git.html#a3">^</a></p>
  11118. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="opentracing"><a class="header" href="#opentracing">OpenTracing</a></h1>
  11119. <h2 id="background"><a class="header" href="#background">Background</a></h2>
  11120. <p>OpenTracing is a semi-standard being adopted by a number of distributed
  11121. tracing platforms. It is a common api for facilitating vendor-agnostic
  11122. tracing instrumentation. That is, we can use the OpenTracing api and
  11123. select one of a number of tracer implementations to do the heavy lifting
  11124. in the background. Our current selected implementation is Jaeger.</p>
  11125. <p>OpenTracing is a tool which gives an insight into the causal
  11126. relationship of work done in and between servers. The servers each track
  11127. events and report them to a centralised server - in Synapse's case:
  11128. Jaeger. The basic unit used to represent events is the span. The span
  11129. roughly represents a single piece of work that was done and the time at
  11130. which it occurred. A span can have child spans, meaning that the work of
  11131. the child had to be completed for the parent span to complete, or it can
  11132. have follow-on spans which represent work that is undertaken as a result
  11133. of the parent but is not depended on by the parent to in order to
  11134. finish.</p>
  11135. <p>Since this is undertaken in a distributed environment a request to
  11136. another server, such as an RPC or a simple GET, can be considered a span
  11137. (a unit or work) for the local server. This causal link is what
  11138. OpenTracing aims to capture and visualise. In order to do this metadata
  11139. about the local server's span, i.e the 'span context', needs to be
  11140. included with the request to the remote.</p>
  11141. <p>It is up to the remote server to decide what it does with the spans it
  11142. creates. This is called the sampling policy and it can be configured
  11143. through Jaeger's settings.</p>
  11144. <p>For OpenTracing concepts see
  11145. <a href="https://opentracing.io/docs/overview/what-is-tracing/">https://opentracing.io/docs/overview/what-is-tracing/</a>.</p>
  11146. <p>For more information about Jaeger's implementation see
  11147. <a href="https://www.jaegertracing.io/docs/">https://www.jaegertracing.io/docs/</a></p>
  11148. <h2 id="setting-up-opentracing"><a class="header" href="#setting-up-opentracing">Setting up OpenTracing</a></h2>
  11149. <p>To receive OpenTracing spans, start up a Jaeger server. This can be done
  11150. using docker like so:</p>
  11151. <pre><code class="language-sh">docker run -d --name jaeger \
  11152. -p 6831:6831/udp \
  11153. -p 6832:6832/udp \
  11154. -p 5778:5778 \
  11155. -p 16686:16686 \
  11156. -p 14268:14268 \
  11157. jaegertracing/all-in-one:1
  11158. </code></pre>
  11159. <p>Latest documentation is probably at
  11160. https://www.jaegertracing.io/docs/latest/getting-started.</p>
  11161. <h2 id="enable-opentracing-in-synapse"><a class="header" href="#enable-opentracing-in-synapse">Enable OpenTracing in Synapse</a></h2>
  11162. <p>OpenTracing is not enabled by default. It must be enabled in the
  11163. homeserver config by uncommenting the config options under <code>opentracing</code>
  11164. as shown in the <a href="./sample_config.yaml">sample config</a>. For example:</p>
  11165. <pre><code class="language-yaml">opentracing:
  11166. enabled: true
  11167. homeserver_whitelist:
  11168. - &quot;mytrustedhomeserver.org&quot;
  11169. - &quot;*.myotherhomeservers.com&quot;
  11170. </code></pre>
  11171. <h2 id="homeserver-whitelisting"><a class="header" href="#homeserver-whitelisting">Homeserver whitelisting</a></h2>
  11172. <p>The homeserver whitelist is configured using regular expressions. A list
  11173. of regular expressions can be given and their union will be compared
  11174. when propagating any spans contexts to another homeserver.</p>
  11175. <p>Though it's mostly safe to send and receive span contexts to and from
  11176. untrusted users since span contexts are usually opaque ids it can lead
  11177. to two problems, namely:</p>
  11178. <ul>
  11179. <li>If the span context is marked as sampled by the sending homeserver
  11180. the receiver will sample it. Therefore two homeservers with wildly
  11181. different sampling policies could incur higher sampling counts than
  11182. intended.</li>
  11183. <li>Sending servers can attach arbitrary data to spans, known as
  11184. 'baggage'. For safety this has been disabled in Synapse but that
  11185. doesn't prevent another server sending you baggage which will be
  11186. logged to OpenTracing's logs.</li>
  11187. </ul>
  11188. <h2 id="configuring-jaeger"><a class="header" href="#configuring-jaeger">Configuring Jaeger</a></h2>
  11189. <p>Sampling strategies can be set as in this document:
  11190. <a href="https://www.jaegertracing.io/docs/latest/sampling/">https://www.jaegertracing.io/docs/latest/sampling/</a>.</p>
  11191. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="synapse-database-schema-files"><a class="header" href="#synapse-database-schema-files">Synapse database schema files</a></h1>
  11192. <p>Synapse's database schema is stored in the <code>synapse.storage.schema</code> module.</p>
  11193. <h2 id="logical-databases"><a class="header" href="#logical-databases">Logical databases</a></h2>
  11194. <p>Synapse supports splitting its datastore across multiple physical databases (which can
  11195. be useful for large installations), and the schema files are therefore split according
  11196. to the logical database they apply to.</p>
  11197. <p>At the time of writing, the following &quot;logical&quot; databases are supported:</p>
  11198. <ul>
  11199. <li><code>state</code> - used to store Matrix room state (more specifically, <code>state_groups</code>,
  11200. their relationships and contents).</li>
  11201. <li><code>main</code> - stores everything else.</li>
  11202. </ul>
  11203. <p>Additionally, the <code>common</code> directory contains schema files for tables which must be
  11204. present on <em>all</em> physical databases.</p>
  11205. <h2 id="synapse-schema-versions"><a class="header" href="#synapse-schema-versions">Synapse schema versions</a></h2>
  11206. <p>Synapse manages its database schema via &quot;schema versions&quot;. These are mainly used to
  11207. help avoid confusion if the Synapse codebase is rolled back after the database is
  11208. updated. They work as follows:</p>
  11209. <ul>
  11210. <li>
  11211. <p>The Synapse codebase defines a constant <code>synapse.storage.schema.SCHEMA_VERSION</code>
  11212. which represents the expectations made about the database by that version. For
  11213. example, as of Synapse v1.36, this is <code>59</code>.</p>
  11214. </li>
  11215. <li>
  11216. <p>The database stores a &quot;compatibility version&quot; in
  11217. <code>schema_compat_version.compat_version</code> which defines the <code>SCHEMA_VERSION</code> of the
  11218. oldest version of Synapse which will work with the database. On startup, if
  11219. <code>compat_version</code> is found to be newer than <code>SCHEMA_VERSION</code>, Synapse will refuse to
  11220. start.</p>
  11221. <p>Synapse automatically updates this field from
  11222. <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code>.</p>
  11223. </li>
  11224. <li>
  11225. <p>Whenever a backwards-incompatible change is made to the database format (normally
  11226. via a <code>delta</code> file), <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code> is also updated
  11227. so that administrators can not accidentally roll back to a too-old version of Synapse.</p>
  11228. </li>
  11229. </ul>
  11230. <p>Generally, the goal is to maintain compatibility with at least one or two previous
  11231. releases of Synapse, so any substantial change tends to require multiple releases and a
  11232. bit of forward-planning to get right.</p>
  11233. <p>As a worked example: we want to remove the <code>room_stats_historical</code> table. Here is how it
  11234. might pan out.</p>
  11235. <ol>
  11236. <li>
  11237. <p>Replace any code that <em>reads</em> from <code>room_stats_historical</code> with alternative
  11238. implementations, but keep writing to it in case of rollback to an earlier version.
  11239. Also, increase <code>synapse.storage.schema.SCHEMA_VERSION</code>. In this
  11240. instance, there is no existing code which reads from <code>room_stats_historical</code>, so
  11241. our starting point is:</p>
  11242. <p>v1.36.0: <code>SCHEMA_VERSION=59</code>, <code>SCHEMA_COMPAT_VERSION=59</code></p>
  11243. </li>
  11244. <li>
  11245. <p>Next (say in Synapse v1.37.0): remove the code that <em>writes</em> to
  11246. <code>room_stats_historical</code>, but don’t yet remove the table in case of rollback to
  11247. v1.36.0. Again, we increase <code>synapse.storage.schema.SCHEMA_VERSION</code>, but
  11248. because we have not broken compatibility with v1.36, we do not yet update
  11249. <code>SCHEMA_COMPAT_VERSION</code>. We now have:</p>
  11250. <p>v1.37.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=59</code>.</p>
  11251. </li>
  11252. <li>
  11253. <p>Later (say in Synapse v1.38.0): we can remove the table altogether. This will
  11254. break compatibility with v1.36.0, so we must update <code>SCHEMA_COMPAT_VERSION</code> accordingly.
  11255. There is no need to update <code>synapse.storage.schema.SCHEMA_VERSION</code>, since there is no
  11256. change to the Synapse codebase here. So we end up with:</p>
  11257. <p>v1.38.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=60</code>.</p>
  11258. </li>
  11259. </ol>
  11260. <p>If in doubt about whether to update <code>SCHEMA_VERSION</code> or not, it is generally best to
  11261. lean towards doing so.</p>
  11262. <h2 id="full-schema-dumps"><a class="header" href="#full-schema-dumps">Full schema dumps</a></h2>
  11263. <p>In the <code>full_schemas</code> directories, only the most recently-numbered snapshot is used
  11264. (<code>54</code> at the time of writing). Older snapshots (eg, <code>16</code>) are present for historical
  11265. reference only.</p>
  11266. <h3 id="building-full-schema-dumps"><a class="header" href="#building-full-schema-dumps">Building full schema dumps</a></h3>
  11267. <p>If you want to recreate these schemas, they need to be made from a database that
  11268. has had all background updates run.</p>
  11269. <p>To do so, use <code>scripts-dev/make_full_schema.sh</code>. This will produce new
  11270. <code>full.sql.postgres</code> and <code>full.sql.sqlite</code> files.</p>
  11271. <p>Ensure postgres is installed, then run:</p>
  11272. <pre><code>./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
  11273. </code></pre>
  11274. <p>NB at the time of writing, this script predates the split into separate <code>state</code>/<code>main</code>
  11275. databases so will require updates to handle that correctly.</p>
  11276. <h2 id="boolean-columns"><a class="header" href="#boolean-columns">Boolean columns</a></h2>
  11277. <p>Boolean columns require special treatment, since SQLite treats booleans the
  11278. same as integers.</p>
  11279. <p>There are three separate aspects to this:</p>
  11280. <ul>
  11281. <li>
  11282. <p>Any new boolean column must be added to the <code>BOOLEAN_COLUMNS</code> list in
  11283. <code>scripts/synapse_port_db</code>. This tells the port script to cast the integer
  11284. value from SQLite to a boolean before writing the value to the postgres
  11285. database.</p>
  11286. </li>
  11287. <li>
  11288. <p>Before SQLite 3.23, <code>TRUE</code> and <code>FALSE</code> were not recognised as constants by
  11289. SQLite, and the <code>IS [NOT] TRUE</code>/<code>IS [NOT] FALSE</code> operators were not
  11290. supported. This makes it necessary to avoid using <code>TRUE</code> and <code>FALSE</code>
  11291. constants in SQL commands.</p>
  11292. <p>For example, to insert a <code>TRUE</code> value into the database, write:</p>
  11293. <pre><code class="language-python">txn.execute(&quot;INSERT INTO tbl(col) VALUES (?)&quot;, (True, ))
  11294. </code></pre>
  11295. </li>
  11296. <li>
  11297. <p>Default values for new boolean columns present a particular
  11298. difficulty. Generally it is best to create separate schema files for
  11299. Postgres and SQLite. For example:</p>
  11300. <pre><code class="language-sql"># in 00delta.sql.postgres:
  11301. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT FALSE;
  11302. </code></pre>
  11303. <pre><code class="language-sql"># in 00delta.sql.sqlite:
  11304. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT 0;
  11305. </code></pre>
  11306. <p>Note that there is a particularly insidious failure mode here: the Postgres
  11307. flavour will be accepted by SQLite 3.22, but will give a column whose
  11308. default value is the <strong>string</strong> <code>&quot;FALSE&quot;</code> - which, when cast back to a boolean
  11309. in Python, evaluates to <code>True</code>.</p>
  11310. </li>
  11311. </ul>
  11312. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="log-contexts"><a class="header" href="#log-contexts">Log Contexts</a></h1>
  11313. <p>To help track the processing of individual requests, synapse uses a
  11314. '<code>log context</code>' to track which request it is handling at any given
  11315. moment. This is done via a thread-local variable; a <code>logging.Filter</code> is
  11316. then used to fish the information back out of the thread-local variable
  11317. and add it to each log record.</p>
  11318. <p>Logcontexts are also used for CPU and database accounting, so that we
  11319. can track which requests were responsible for high CPU use or database
  11320. activity.</p>
  11321. <p>The <code>synapse.logging.context</code> module provides a facilities for managing
  11322. the current log context (as well as providing the <code>LoggingContextFilter</code>
  11323. class).</p>
  11324. <p>Deferreds make the whole thing complicated, so this document describes
  11325. how it all works, and how to write code which follows the rules.</p>
  11326. <p>##Logcontexts without Deferreds</p>
  11327. <p>In the absence of any Deferred voodoo, things are simple enough. As with
  11328. any code of this nature, the rule is that our function should leave
  11329. things as it found them:</p>
  11330. <pre><code class="language-python">from synapse.logging import context # omitted from future snippets
  11331. def handle_request(request_id):
  11332. request_context = context.LoggingContext()
  11333. calling_context = context.set_current_context(request_context)
  11334. try:
  11335. request_context.request = request_id
  11336. do_request_handling()
  11337. logger.debug(&quot;finished&quot;)
  11338. finally:
  11339. context.set_current_context(calling_context)
  11340. def do_request_handling():
  11341. logger.debug(&quot;phew&quot;) # this will be logged against request_id
  11342. </code></pre>
  11343. <p>LoggingContext implements the context management methods, so the above
  11344. can be written much more succinctly as:</p>
  11345. <pre><code class="language-python">def handle_request(request_id):
  11346. with context.LoggingContext() as request_context:
  11347. request_context.request = request_id
  11348. do_request_handling()
  11349. logger.debug(&quot;finished&quot;)
  11350. def do_request_handling():
  11351. logger.debug(&quot;phew&quot;)
  11352. </code></pre>
  11353. <h2 id="using-logcontexts-with-deferreds"><a class="header" href="#using-logcontexts-with-deferreds">Using logcontexts with Deferreds</a></h2>
  11354. <p>Deferreds --- and in particular, <code>defer.inlineCallbacks</code> --- break the
  11355. linear flow of code so that there is no longer a single entry point
  11356. where we should set the logcontext and a single exit point where we
  11357. should remove it.</p>
  11358. <p>Consider the example above, where <code>do_request_handling</code> needs to do some
  11359. blocking operation, and returns a deferred:</p>
  11360. <pre><code class="language-python">@defer.inlineCallbacks
  11361. def handle_request(request_id):
  11362. with context.LoggingContext() as request_context:
  11363. request_context.request = request_id
  11364. yield do_request_handling()
  11365. logger.debug(&quot;finished&quot;)
  11366. </code></pre>
  11367. <p>In the above flow:</p>
  11368. <ul>
  11369. <li>The logcontext is set</li>
  11370. <li><code>do_request_handling</code> is called, and returns a deferred</li>
  11371. <li><code>handle_request</code> yields the deferred</li>
  11372. <li>The <code>inlineCallbacks</code> wrapper of <code>handle_request</code> returns a deferred</li>
  11373. </ul>
  11374. <p>So we have stopped processing the request (and will probably go on to
  11375. start processing the next), without clearing the logcontext.</p>
  11376. <p>To circumvent this problem, synapse code assumes that, wherever you have
  11377. a deferred, you will want to yield on it. To that end, whereever
  11378. functions return a deferred, we adopt the following conventions:</p>
  11379. <p><strong>Rules for functions returning deferreds:</strong></p>
  11380. <blockquote>
  11381. <ul>
  11382. <li>If the deferred is already complete, the function returns with the
  11383. same logcontext it started with.</li>
  11384. <li>If the deferred is incomplete, the function clears the logcontext
  11385. before returning; when the deferred completes, it restores the
  11386. logcontext before running any callbacks.</li>
  11387. </ul>
  11388. </blockquote>
  11389. <p>That sounds complicated, but actually it means a lot of code (including
  11390. the example above) &quot;just works&quot;. There are two cases:</p>
  11391. <ul>
  11392. <li>
  11393. <p>If <code>do_request_handling</code> returns a completed deferred, then the
  11394. logcontext will still be in place. In this case, execution will
  11395. continue immediately after the <code>yield</code>; the &quot;finished&quot; line will
  11396. be logged against the right context, and the <code>with</code> block restores
  11397. the original context before we return to the caller.</p>
  11398. </li>
  11399. <li>
  11400. <p>If the returned deferred is incomplete, <code>do_request_handling</code> clears
  11401. the logcontext before returning. The logcontext is therefore clear
  11402. when <code>handle_request</code> yields the deferred. At that point, the
  11403. <code>inlineCallbacks</code> wrapper adds a callback to the deferred, and
  11404. returns another (incomplete) deferred to the caller, and it is safe
  11405. to begin processing the next request.</p>
  11406. <p>Once <code>do_request_handling</code>'s deferred completes, it will reinstate
  11407. the logcontext, before running the callback added by the
  11408. <code>inlineCallbacks</code> wrapper. That callback runs the second half of
  11409. <code>handle_request</code>, so again the &quot;finished&quot; line will be logged
  11410. against the right context, and the <code>with</code> block restores the
  11411. original context.</p>
  11412. </li>
  11413. </ul>
  11414. <p>As an aside, it's worth noting that <code>handle_request</code> follows our rules
  11415. -though that only matters if the caller has its own logcontext which it
  11416. cares about.</p>
  11417. <p>The following sections describe pitfalls and helpful patterns when
  11418. implementing these rules.</p>
  11419. <h2 id="always-yield-your-deferreds"><a class="header" href="#always-yield-your-deferreds">Always yield your deferreds</a></h2>
  11420. <p>Whenever you get a deferred back from a function, you should <code>yield</code> on
  11421. it as soon as possible. (Returning it directly to your caller is ok too,
  11422. if you're not doing <code>inlineCallbacks</code>.) Do not pass go; do not do any
  11423. logging; do not call any other functions.</p>
  11424. <pre><code class="language-python">@defer.inlineCallbacks
  11425. def fun():
  11426. logger.debug(&quot;starting&quot;)
  11427. yield do_some_stuff() # just like this
  11428. d = more_stuff()
  11429. result = yield d # also fine, of course
  11430. return result
  11431. def nonInlineCallbacksFun():
  11432. logger.debug(&quot;just a wrapper really&quot;)
  11433. return do_some_stuff() # this is ok too - the caller will yield on
  11434. # it anyway.
  11435. </code></pre>
  11436. <p>Provided this pattern is followed all the way back up to the callchain
  11437. to where the logcontext was set, this will make things work out ok:
  11438. provided <code>do_some_stuff</code> and <code>more_stuff</code> follow the rules above, then
  11439. so will <code>fun</code> (as wrapped by <code>inlineCallbacks</code>) and
  11440. <code>nonInlineCallbacksFun</code>.</p>
  11441. <p>It's all too easy to forget to <code>yield</code>: for instance if we forgot that
  11442. <code>do_some_stuff</code> returned a deferred, we might plough on regardless. This
  11443. leads to a mess; it will probably work itself out eventually, but not
  11444. before a load of stuff has been logged against the wrong context.
  11445. (Normally, other things will break, more obviously, if you forget to
  11446. <code>yield</code>, so this tends not to be a major problem in practice.)</p>
  11447. <p>Of course sometimes you need to do something a bit fancier with your
  11448. Deferreds - not all code follows the linear A-then-B-then-C pattern.
  11449. Notes on implementing more complex patterns are in later sections.</p>
  11450. <h2 id="where-you-create-a-new-deferred-make-it-follow-the-rules"><a class="header" href="#where-you-create-a-new-deferred-make-it-follow-the-rules">Where you create a new Deferred, make it follow the rules</a></h2>
  11451. <p>Most of the time, a Deferred comes from another synapse function.
  11452. Sometimes, though, we need to make up a new Deferred, or we get a
  11453. Deferred back from external code. We need to make it follow our rules.</p>
  11454. <p>The easy way to do it is with a combination of <code>defer.inlineCallbacks</code>,
  11455. and <code>context.PreserveLoggingContext</code>. Suppose we want to implement
  11456. <code>sleep</code>, which returns a deferred which will run its callbacks after a
  11457. given number of seconds. That might look like:</p>
  11458. <pre><code class="language-python"># not a logcontext-rules-compliant function
  11459. def get_sleep_deferred(seconds):
  11460. d = defer.Deferred()
  11461. reactor.callLater(seconds, d.callback, None)
  11462. return d
  11463. </code></pre>
  11464. <p>That doesn't follow the rules, but we can fix it by wrapping it with
  11465. <code>PreserveLoggingContext</code> and <code>yield</code> ing on it:</p>
  11466. <pre><code class="language-python">@defer.inlineCallbacks
  11467. def sleep(seconds):
  11468. with PreserveLoggingContext():
  11469. yield get_sleep_deferred(seconds)
  11470. </code></pre>
  11471. <p>This technique works equally for external functions which return
  11472. deferreds, or deferreds we have made ourselves.</p>
  11473. <p>You can also use <code>context.make_deferred_yieldable</code>, which just does the
  11474. boilerplate for you, so the above could be written:</p>
  11475. <pre><code class="language-python">def sleep(seconds):
  11476. return context.make_deferred_yieldable(get_sleep_deferred(seconds))
  11477. </code></pre>
  11478. <h2 id="fire-and-forget"><a class="header" href="#fire-and-forget">Fire-and-forget</a></h2>
  11479. <p>Sometimes you want to fire off a chain of execution, but not wait for
  11480. its result. That might look a bit like this:</p>
  11481. <pre><code class="language-python">@defer.inlineCallbacks
  11482. def do_request_handling():
  11483. yield foreground_operation()
  11484. # *don't* do this
  11485. background_operation()
  11486. logger.debug(&quot;Request handling complete&quot;)
  11487. @defer.inlineCallbacks
  11488. def background_operation():
  11489. yield first_background_step()
  11490. logger.debug(&quot;Completed first step&quot;)
  11491. yield second_background_step()
  11492. logger.debug(&quot;Completed second step&quot;)
  11493. </code></pre>
  11494. <p>The above code does a couple of steps in the background after
  11495. <code>do_request_handling</code> has finished. The log lines are still logged
  11496. against the <code>request_context</code> logcontext, which may or may not be
  11497. desirable. There are two big problems with the above, however. The first
  11498. problem is that, if <code>background_operation</code> returns an incomplete
  11499. Deferred, it will expect its caller to <code>yield</code> immediately, so will have
  11500. cleared the logcontext. In this example, that means that 'Request
  11501. handling complete' will be logged without any context.</p>
  11502. <p>The second problem, which is potentially even worse, is that when the
  11503. Deferred returned by <code>background_operation</code> completes, it will restore
  11504. the original logcontext. There is nothing waiting on that Deferred, so
  11505. the logcontext will leak into the reactor and possibly get attached to
  11506. some arbitrary future operation.</p>
  11507. <p>There are two potential solutions to this.</p>
  11508. <p>One option is to surround the call to <code>background_operation</code> with a
  11509. <code>PreserveLoggingContext</code> call. That will reset the logcontext before
  11510. starting <code>background_operation</code> (so the context restored when the
  11511. deferred completes will be the empty logcontext), and will restore the
  11512. current logcontext before continuing the foreground process:</p>
  11513. <pre><code class="language-python">@defer.inlineCallbacks
  11514. def do_request_handling():
  11515. yield foreground_operation()
  11516. # start background_operation off in the empty logcontext, to
  11517. # avoid leaking the current context into the reactor.
  11518. with PreserveLoggingContext():
  11519. background_operation()
  11520. # this will now be logged against the request context
  11521. logger.debug(&quot;Request handling complete&quot;)
  11522. </code></pre>
  11523. <p>Obviously that option means that the operations done in
  11524. <code>background_operation</code> would be not be logged against a logcontext
  11525. (though that might be fixed by setting a different logcontext via a
  11526. <code>with LoggingContext(...)</code> in <code>background_operation</code>).</p>
  11527. <p>The second option is to use <code>context.run_in_background</code>, which wraps a
  11528. function so that it doesn't reset the logcontext even when it returns
  11529. an incomplete deferred, and adds a callback to the returned deferred to
  11530. reset the logcontext. In other words, it turns a function that follows
  11531. the Synapse rules about logcontexts and Deferreds into one which behaves
  11532. more like an external function --- the opposite operation to that
  11533. described in the previous section. It can be used like this:</p>
  11534. <pre><code class="language-python">@defer.inlineCallbacks
  11535. def do_request_handling():
  11536. yield foreground_operation()
  11537. context.run_in_background(background_operation)
  11538. # this will now be logged against the request context
  11539. logger.debug(&quot;Request handling complete&quot;)
  11540. </code></pre>
  11541. <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>
  11542. <p>A typical example of this is where we want to collect together two or
  11543. more deferred via <code>defer.gatherResults</code>:</p>
  11544. <pre><code class="language-python">d1 = operation1()
  11545. d2 = operation2()
  11546. d3 = defer.gatherResults([d1, d2])
  11547. </code></pre>
  11548. <p>This is really a variation of the fire-and-forget problem above, in that
  11549. we are firing off <code>d1</code> and <code>d2</code> without yielding on them. The difference
  11550. is that we now have third-party code attached to their callbacks. Anyway
  11551. either technique given in the <a href="log_contexts.html#fire-and-forget">Fire-and-forget</a>
  11552. section will work.</p>
  11553. <p>Of course, the new Deferred returned by <code>gatherResults</code> needs to be
  11554. wrapped in order to make it follow the logcontext rules before we can
  11555. yield it, as described in <a href="log_contexts.html#where-you-create-a-new-deferred-make-it-follow-the-rules">Where you create a new Deferred, make it
  11556. follow the
  11557. rules</a>.</p>
  11558. <p>So, option one: reset the logcontext before starting the operations to
  11559. be gathered:</p>
  11560. <pre><code class="language-python">@defer.inlineCallbacks
  11561. def do_request_handling():
  11562. with PreserveLoggingContext():
  11563. d1 = operation1()
  11564. d2 = operation2()
  11565. result = yield defer.gatherResults([d1, d2])
  11566. </code></pre>
  11567. <p>In this case particularly, though, option two, of using
  11568. <code>context.preserve_fn</code> almost certainly makes more sense, so that
  11569. <code>operation1</code> and <code>operation2</code> are both logged against the original
  11570. logcontext. This looks like:</p>
  11571. <pre><code class="language-python">@defer.inlineCallbacks
  11572. def do_request_handling():
  11573. d1 = context.preserve_fn(operation1)()
  11574. d2 = context.preserve_fn(operation2)()
  11575. with PreserveLoggingContext():
  11576. result = yield defer.gatherResults([d1, d2])
  11577. </code></pre>
  11578. <h2 id="was-all-this-really-necessary"><a class="header" href="#was-all-this-really-necessary">Was all this really necessary?</a></h2>
  11579. <p>The conventions used work fine for a linear flow where everything
  11580. happens in series via <code>defer.inlineCallbacks</code> and <code>yield</code>, but are
  11581. certainly tricky to follow for any more exotic flows. It's hard not to
  11582. wonder if we could have done something else.</p>
  11583. <p>We're not going to rewrite Synapse now, so the following is entirely of
  11584. academic interest, but I'd like to record some thoughts on an
  11585. alternative approach.</p>
  11586. <p>I briefly prototyped some code following an alternative set of rules. I
  11587. think it would work, but I certainly didn't get as far as thinking how
  11588. it would interact with concepts as complicated as the cache descriptors.</p>
  11589. <p>My alternative rules were:</p>
  11590. <ul>
  11591. <li>functions always preserve the logcontext of their caller, whether or
  11592. not they are returning a Deferred.</li>
  11593. <li>Deferreds returned by synapse functions run their callbacks in the
  11594. same context as the function was orignally called in.</li>
  11595. </ul>
  11596. <p>The main point of this scheme is that everywhere that sets the
  11597. logcontext is responsible for clearing it before returning control to
  11598. the reactor.</p>
  11599. <p>So, for example, if you were the function which started a
  11600. <code>with LoggingContext</code> block, you wouldn't <code>yield</code> within it --- instead
  11601. you'd start off the background process, and then leave the <code>with</code> block
  11602. to wait for it:</p>
  11603. <pre><code class="language-python">def handle_request(request_id):
  11604. with context.LoggingContext() as request_context:
  11605. request_context.request = request_id
  11606. d = do_request_handling()
  11607. def cb(r):
  11608. logger.debug(&quot;finished&quot;)
  11609. d.addCallback(cb)
  11610. return d
  11611. </code></pre>
  11612. <p>(in general, mixing <code>with LoggingContext</code> blocks and
  11613. <code>defer.inlineCallbacks</code> in the same function leads to slighly
  11614. counter-intuitive code, under this scheme).</p>
  11615. <p>Because we leave the original <code>with</code> block as soon as the Deferred is
  11616. returned (as opposed to waiting for it to be resolved, as we do today),
  11617. the logcontext is cleared before control passes back to the reactor; so
  11618. if there is some code within <code>do_request_handling</code> which needs to wait
  11619. for a Deferred to complete, there is no need for it to worry about
  11620. clearing the logcontext before doing so:</p>
  11621. <pre><code class="language-python">def handle_request():
  11622. r = do_some_stuff()
  11623. r.addCallback(do_some_more_stuff)
  11624. return r
  11625. </code></pre>
  11626. <p>--- and provided <code>do_some_stuff</code> follows the rules of returning a
  11627. Deferred which runs its callbacks in the original logcontext, all is
  11628. happy.</p>
  11629. <p>The business of a Deferred which runs its callbacks in the original
  11630. logcontext isn't hard to achieve --- we have it today, in the shape of
  11631. <code>context._PreservingContextDeferred</code>:</p>
  11632. <pre><code class="language-python">def do_some_stuff():
  11633. deferred = do_some_io()
  11634. pcd = _PreservingContextDeferred(LoggingContext.current_context())
  11635. deferred.chainDeferred(pcd)
  11636. return pcd
  11637. </code></pre>
  11638. <p>It turns out that, thanks to the way that Deferreds chain together, we
  11639. automatically get the property of a context-preserving deferred with
  11640. <code>defer.inlineCallbacks</code>, provided the final Defered the function
  11641. <code>yields</code> on has that property. So we can just write:</p>
  11642. <pre><code class="language-python">@defer.inlineCallbacks
  11643. def handle_request():
  11644. yield do_some_stuff()
  11645. yield do_some_more_stuff()
  11646. </code></pre>
  11647. <p>To conclude: I think this scheme would have worked equally well, with
  11648. less danger of messing it up, and probably made some more esoteric code
  11649. easier to write. But again --- changing the conventions of the entire
  11650. Synapse codebase is not a sensible option for the marginal improvement
  11651. offered.</p>
  11652. <h2 id="a-note-on-garbage-collection-of-deferred-chains"><a class="header" href="#a-note-on-garbage-collection-of-deferred-chains">A note on garbage-collection of Deferred chains</a></h2>
  11653. <p>It turns out that our logcontext rules do not play nicely with Deferred
  11654. chains which get orphaned and garbage-collected.</p>
  11655. <p>Imagine we have some code that looks like this:</p>
  11656. <pre><code class="language-python">listener_queue = []
  11657. def on_something_interesting():
  11658. for d in listener_queue:
  11659. d.callback(&quot;foo&quot;)
  11660. @defer.inlineCallbacks
  11661. def await_something_interesting():
  11662. new_deferred = defer.Deferred()
  11663. listener_queue.append(new_deferred)
  11664. with PreserveLoggingContext():
  11665. yield new_deferred
  11666. </code></pre>
  11667. <p>Obviously, the idea here is that we have a bunch of things which are
  11668. waiting for an event. (It's just an example of the problem here, but a
  11669. relatively common one.)</p>
  11670. <p>Now let's imagine two further things happen. First of all, whatever was
  11671. waiting for the interesting thing goes away. (Perhaps the request times
  11672. out, or something <em>even more</em> interesting happens.)</p>
  11673. <p>Secondly, let's suppose that we decide that the interesting thing is
  11674. never going to happen, and we reset the listener queue:</p>
  11675. <pre><code class="language-python">def reset_listener_queue():
  11676. listener_queue.clear()
  11677. </code></pre>
  11678. <p>So, both ends of the deferred chain have now dropped their references,
  11679. and the deferred chain is now orphaned, and will be garbage-collected at
  11680. some point. Note that <code>await_something_interesting</code> is a generator
  11681. function, and when Python garbage-collects generator functions, it gives
  11682. them a chance to clean up by making the <code>yield</code> raise a <code>GeneratorExit</code>
  11683. exception. In our case, that means that the <code>__exit__</code> handler of
  11684. <code>PreserveLoggingContext</code> will carefully restore the request context, but
  11685. there is now nothing waiting for its return, so the request context is
  11686. never cleared.</p>
  11687. <p>To reiterate, this problem only arises when <em>both</em> ends of a deferred
  11688. chain are dropped. Dropping the the reference to a deferred you're
  11689. supposed to be calling is probably bad practice, so this doesn't
  11690. actually happen too much. Unfortunately, when it does happen, it will
  11691. lead to leaked logcontexts which are incredibly hard to track down.</p>
  11692. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="replication-architecture"><a class="header" href="#replication-architecture">Replication Architecture</a></h1>
  11693. <h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
  11694. <p>We'd like to be able to split some of the work that synapse does into
  11695. multiple python processes. In theory multiple synapse processes could
  11696. share a single postgresql database and we'd scale up by running more
  11697. synapse processes. However much of synapse assumes that only one process
  11698. is interacting with the database, both for assigning unique identifiers
  11699. when inserting into tables, notifying components about new updates, and
  11700. for invalidating its caches.</p>
  11701. <p>So running multiple copies of the current code isn't an option. One way
  11702. to run multiple processes would be to have a single writer process and
  11703. multiple reader processes connected to the same database. In order to do
  11704. this we'd need a way for the reader process to invalidate its in-memory
  11705. caches when an update happens on the writer. One way to do this is for
  11706. the writer to present an append-only log of updates which the readers
  11707. can consume to invalidate their caches and to push updates to listening
  11708. clients or pushers.</p>
  11709. <p>Synapse already stores much of its data as an append-only log so that it
  11710. can correctly respond to <code>/sync</code> requests so the amount of code changes
  11711. needed to expose the append-only log to the readers should be fairly
  11712. minimal.</p>
  11713. <h2 id="architecture"><a class="header" href="#architecture">Architecture</a></h2>
  11714. <h3 id="the-replication-protocol"><a class="header" href="#the-replication-protocol">The Replication Protocol</a></h3>
  11715. <p>See <a href="tcp_replication.html">tcp_replication.md</a></p>
  11716. <h3 id="the-slaved-datastore"><a class="header" href="#the-slaved-datastore">The Slaved DataStore</a></h3>
  11717. <p>There are read-only version of the synapse storage layer in
  11718. <code>synapse/replication/slave/storage</code> that use the response of the
  11719. replication API to invalidate their caches.</p>
  11720. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="tcp-replication"><a class="header" href="#tcp-replication">TCP Replication</a></h1>
  11721. <h2 id="motivation-1"><a class="header" href="#motivation-1">Motivation</a></h2>
  11722. <p>Previously the workers used an HTTP long poll mechanism to get updates
  11723. from the master, which had the problem of causing a lot of duplicate
  11724. work on the server. This TCP protocol replaces those APIs with the aim
  11725. of increased efficiency.</p>
  11726. <h2 id="overview-3"><a class="header" href="#overview-3">Overview</a></h2>
  11727. <p>The protocol is based on fire and forget, line based commands. An
  11728. example flow would be (where '&gt;' indicates master to worker and
  11729. '&lt;' worker to master flows):</p>
  11730. <pre><code>&gt; SERVER example.com
  11731. &lt; REPLICATE
  11732. &gt; POSITION events master 53 53
  11733. &gt; RDATA events master 54 [&quot;$foo1:bar.com&quot;, ...]
  11734. &gt; RDATA events master 55 [&quot;$foo4:bar.com&quot;, ...]
  11735. </code></pre>
  11736. <p>The example shows the server accepting a new connection and sending its identity
  11737. with the <code>SERVER</code> command, followed by the client server to respond with the
  11738. position of all streams. The server then periodically sends <code>RDATA</code> commands
  11739. which have the format <code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row&gt;</code>, where
  11740. the format of <code>&lt;row&gt;</code> is defined by the individual streams. The
  11741. <code>&lt;instance_name&gt;</code> is the name of the Synapse process that generated the data
  11742. (usually &quot;master&quot;).</p>
  11743. <p>Error reporting happens by either the client or server sending an ERROR
  11744. command, and usually the connection will be closed.</p>
  11745. <p>Since the protocol is a simple line based, its possible to manually
  11746. connect to the server using a tool like netcat. A few things should be
  11747. noted when manually using the protocol:</p>
  11748. <ul>
  11749. <li>The federation stream is only available if federation sending has
  11750. been disabled on the main process.</li>
  11751. <li>The server will only time connections out that have sent a <code>PING</code>
  11752. command. If a ping is sent then the connection will be closed if no
  11753. further commands are receieved within 15s. Both the client and
  11754. server protocol implementations will send an initial PING on
  11755. connection and ensure at least one command every 5s is sent (not
  11756. necessarily <code>PING</code>).</li>
  11757. <li><code>RDATA</code> commands <em>usually</em> include a numeric token, however if the
  11758. stream has multiple rows to replicate per token the server will send
  11759. multiple <code>RDATA</code> commands, with all but the last having a token of
  11760. <code>batch</code>. See the documentation on <code>commands.RdataCommand</code> for
  11761. further details.</li>
  11762. </ul>
  11763. <h2 id="architecture-1"><a class="header" href="#architecture-1">Architecture</a></h2>
  11764. <p>The basic structure of the protocol is line based, where the initial
  11765. word of each line specifies the command. The rest of the line is parsed
  11766. based on the command. For example, the RDATA command is defined as:</p>
  11767. <pre><code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row_json&gt;
  11768. </code></pre>
  11769. <p>(Note that &lt;row_json&gt; may contains spaces, but cannot contain
  11770. newlines.)</p>
  11771. <p>Blank lines are ignored.</p>
  11772. <h3 id="keep-alives"><a class="header" href="#keep-alives">Keep alives</a></h3>
  11773. <p>Both sides are expected to send at least one command every 5s or so, and
  11774. should send a <code>PING</code> command if necessary. If either side do not receive
  11775. a command within e.g. 15s then the connection should be closed.</p>
  11776. <p>Because the server may be connected to manually using e.g. netcat, the
  11777. timeouts aren't enabled until an initial <code>PING</code> command is seen. Both
  11778. the client and server implementations below send a <code>PING</code> command
  11779. immediately on connection to ensure the timeouts are enabled.</p>
  11780. <p>This ensures that both sides can quickly realize if the tcp connection
  11781. has gone and handle the situation appropriately.</p>
  11782. <h3 id="start-up"><a class="header" href="#start-up">Start up</a></h3>
  11783. <p>When a new connection is made, the server:</p>
  11784. <ul>
  11785. <li>Sends a <code>SERVER</code> command, which includes the identity of the server,
  11786. allowing the client to detect if its connected to the expected
  11787. server</li>
  11788. <li>Sends a <code>PING</code> command as above, to enable the client to time out
  11789. connections promptly.</li>
  11790. </ul>
  11791. <p>The client:</p>
  11792. <ul>
  11793. <li>Sends a <code>NAME</code> command, allowing the server to associate a human
  11794. friendly name with the connection. This is optional.</li>
  11795. <li>Sends a <code>PING</code> as above</li>
  11796. <li>Sends a <code>REPLICATE</code> to get the current position of all streams.</li>
  11797. <li>On receipt of a <code>SERVER</code> command, checks that the server name
  11798. matches the expected server name.</li>
  11799. </ul>
  11800. <h3 id="error-handling"><a class="header" href="#error-handling">Error handling</a></h3>
  11801. <p>If either side detects an error it can send an <code>ERROR</code> command and close
  11802. the connection.</p>
  11803. <p>If the client side loses the connection to the server it should
  11804. reconnect, following the steps above.</p>
  11805. <h3 id="congestion"><a class="header" href="#congestion">Congestion</a></h3>
  11806. <p>If the server sends messages faster than the client can consume them the
  11807. server will first buffer a (fairly large) number of commands and then
  11808. disconnect the client. This ensures that we don't queue up an unbounded
  11809. number of commands in memory and gives us a potential oppurtunity to
  11810. squawk loudly. When/if the client recovers it can reconnect to the
  11811. server and ask for missed messages.</p>
  11812. <h3 id="reliability"><a class="header" href="#reliability">Reliability</a></h3>
  11813. <p>In general the replication stream should be considered an unreliable
  11814. transport since e.g. commands are not resent if the connection
  11815. disappears.</p>
  11816. <p>The exception to that are the replication streams, i.e. RDATA commands,
  11817. since these include tokens which can be used to restart the stream on
  11818. connection errors.</p>
  11819. <p>The client should keep track of the token in the last RDATA command
  11820. received for each stream so that on reconneciton it can start streaming
  11821. from the correct place. Note: not all RDATA have valid tokens due to
  11822. batching. See <code>RdataCommand</code> for more details.</p>
  11823. <h3 id="example-5"><a class="header" href="#example-5">Example</a></h3>
  11824. <p>An example iteraction is shown below. Each line is prefixed with '&gt;'
  11825. or '&lt;' to indicate which side is sending, these are <em>not</em> included on
  11826. the wire:</p>
  11827. <pre><code>* connection established *
  11828. &gt; SERVER localhost:8823
  11829. &gt; PING 1490197665618
  11830. &lt; NAME synapse.app.appservice
  11831. &lt; PING 1490197665618
  11832. &lt; REPLICATE
  11833. &gt; POSITION events master 1 1
  11834. &gt; POSITION backfill master 1 1
  11835. &gt; POSITION caches master 1 1
  11836. &gt; RDATA caches master 2 [&quot;get_user_by_id&quot;,[&quot;@01register-user:localhost:8823&quot;],1490197670513]
  11837. &gt; RDATA events master 14 [&quot;$149019767112vOHxz:localhost:8823&quot;,
  11838. &quot;!AFDCvgApUmpdfVjIXm:localhost:8823&quot;,&quot;m.room.guest_access&quot;,&quot;&quot;,null]
  11839. &lt; PING 1490197675618
  11840. &gt; ERROR server stopping
  11841. * connection closed by server *
  11842. </code></pre>
  11843. <p>The <code>POSITION</code> command sent by the server is used to set the clients
  11844. position without needing to send data with the <code>RDATA</code> command.</p>
  11845. <p>An example of a batched set of <code>RDATA</code> is:</p>
  11846. <pre><code>&gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test:localhost:8823&quot;],1490197670513]
  11847. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test2:localhost:8823&quot;],1490197670513]
  11848. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test3:localhost:8823&quot;],1490197670513]
  11849. &gt; RDATA caches master 54 [&quot;get_user_by_id&quot;,[&quot;@test4:localhost:8823&quot;],1490197670513]
  11850. </code></pre>
  11851. <p>In this case the client shouldn't advance their caches token until it
  11852. sees the the last <code>RDATA</code>.</p>
  11853. <h3 id="list-of-commands"><a class="header" href="#list-of-commands">List of commands</a></h3>
  11854. <p>The list of valid commands, with which side can send it: server (S) or
  11855. client (C):</p>
  11856. <h4 id="server-s"><a class="header" href="#server-s">SERVER (S)</a></h4>
  11857. <p>Sent at the start to identify which server the client is talking to</p>
  11858. <h4 id="rdata-s"><a class="header" href="#rdata-s">RDATA (S)</a></h4>
  11859. <p>A single update in a stream</p>
  11860. <h4 id="position-s"><a class="header" href="#position-s">POSITION (S)</a></h4>
  11861. <p>On receipt of a POSITION command clients should check if they have missed any
  11862. updates, and if so then fetch them out of band. Sent in response to a
  11863. REPLICATE command (but can happen at any time).</p>
  11864. <p>The POSITION command includes the source of the stream. Currently all streams
  11865. are written by a single process (usually &quot;master&quot;). If fetching missing
  11866. updates via HTTP API, rather than via the DB, then processes should make the
  11867. request to the appropriate process.</p>
  11868. <p>Two positions are included, the &quot;new&quot; position and the last position sent respectively.
  11869. This allows servers to tell instances that the positions have advanced but no
  11870. data has been written, without clients needlessly checking to see if they
  11871. have missed any updates.</p>
  11872. <h4 id="error-s-c"><a class="header" href="#error-s-c">ERROR (S, C)</a></h4>
  11873. <p>There was an error</p>
  11874. <h4 id="ping-s-c"><a class="header" href="#ping-s-c">PING (S, C)</a></h4>
  11875. <p>Sent periodically to ensure the connection is still alive</p>
  11876. <h4 id="name-c"><a class="header" href="#name-c">NAME (C)</a></h4>
  11877. <p>Sent at the start by client to inform the server who they are</p>
  11878. <h4 id="replicate-c"><a class="header" href="#replicate-c">REPLICATE (C)</a></h4>
  11879. <p>Asks the server for the current position of all streams.</p>
  11880. <h4 id="user_sync-c"><a class="header" href="#user_sync-c">USER_SYNC (C)</a></h4>
  11881. <p>A user has started or stopped syncing on this process.</p>
  11882. <h4 id="clear_user_sync-c"><a class="header" href="#clear_user_sync-c">CLEAR_USER_SYNC (C)</a></h4>
  11883. <p>The server should clear all associated user sync data from the worker.</p>
  11884. <p>This is used when a worker is shutting down.</p>
  11885. <h4 id="federation_ack-c"><a class="header" href="#federation_ack-c">FEDERATION_ACK (C)</a></h4>
  11886. <p>Acknowledge receipt of some federation data</p>
  11887. <h3 id="remote_server_up-s-c"><a class="header" href="#remote_server_up-s-c">REMOTE_SERVER_UP (S, C)</a></h3>
  11888. <p>Inform other processes that a remote server may have come back online.</p>
  11889. <p>See <code>synapse/replication/tcp/commands.py</code> for a detailed description and
  11890. the format of each command.</p>
  11891. <h3 id="cache-invalidation-stream"><a class="header" href="#cache-invalidation-stream">Cache Invalidation Stream</a></h3>
  11892. <p>The cache invalidation stream is used to inform workers when they need
  11893. to invalidate any of their caches in the data store. This is done by
  11894. streaming all cache invalidations done on master down to the workers,
  11895. assuming that any caches on the workers also exist on the master.</p>
  11896. <p>Each individual cache invalidation results in a row being sent down
  11897. replication, which includes the cache name (the name of the function)
  11898. and they key to invalidate. For example:</p>
  11899. <pre><code>&gt; RDATA caches master 550953771 [&quot;get_user_by_id&quot;, [&quot;@bob:example.com&quot;], 1550574873251]
  11900. </code></pre>
  11901. <p>Alternatively, an entire cache can be invalidated by sending down a <code>null</code>
  11902. instead of the key. For example:</p>
  11903. <pre><code>&gt; RDATA caches master 550953772 [&quot;get_user_by_id&quot;, null, 1550574873252]
  11904. </code></pre>
  11905. <p>However, there are times when a number of caches need to be invalidated
  11906. at the same time with the same key. To reduce traffic we batch those
  11907. invalidations into a single poke by defining a special cache name that
  11908. workers understand to mean to expand to invalidate the correct caches.</p>
  11909. <p>Currently the special cache names are declared in
  11910. <code>synapse/storage/_base.py</code> and are:</p>
  11911. <ol>
  11912. <li><code>cs_cache_fake</code> ─ invalidates caches that depend on the current
  11913. state</li>
  11914. </ol>
  11915. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="internal-documentation"><a class="header" href="#internal-documentation">Internal Documentation</a></h1>
  11916. <p>This section covers implementation documentation for various parts of Synapse.</p>
  11917. <p>If a developer is planning to make a change to a feature of Synapse, it can be useful for
  11918. general documentation of how that feature is implemented to be available. This saves the
  11919. developer time in place of needing to understand how the feature works by reading the
  11920. code.</p>
  11921. <p>Documentation that would be more useful for the perspective of a system administrator,
  11922. rather than a developer who's intending to change to code, should instead be placed
  11923. under the Usage section of the documentation.</p>
  11924. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-saml-as-a-developer-without-a-server"><a class="header" href="#how-to-test-saml-as-a-developer-without-a-server">How to test SAML as a developer without a server</a></h1>
  11925. <p>https://capriza.github.io/samling/samling.html (https://github.com/capriza/samling) is a great
  11926. resource for being able to tinker with the SAML options within Synapse without needing to
  11927. deploy and configure a complicated software stack.</p>
  11928. <p>To make Synapse (and therefore Riot) use it:</p>
  11929. <ol>
  11930. <li>Use the samling.html URL above or deploy your own and visit the IdP Metadata tab.</li>
  11931. <li>Copy the XML to your clipboard.</li>
  11932. <li>On your Synapse server, create a new file <code>samling.xml</code> next to your <code>homeserver.yaml</code> with
  11933. the XML from step 2 as the contents.</li>
  11934. <li>Edit your <code>homeserver.yaml</code> to include:
  11935. <pre><code class="language-yaml">saml2_config:
  11936. sp_config:
  11937. allow_unknown_attributes: true # Works around a bug with AVA Hashes: https://github.com/IdentityPython/pysaml2/issues/388
  11938. metadata:
  11939. local: [&quot;samling.xml&quot;]
  11940. </code></pre>
  11941. </li>
  11942. <li>Ensure that your <code>homeserver.yaml</code> has a setting for <code>public_baseurl</code>:
  11943. <pre><code class="language-yaml">public_baseurl: http://localhost:8080/
  11944. </code></pre>
  11945. </li>
  11946. <li>Run <code>apt-get install xmlsec1</code> and <code>pip install --upgrade --force 'pysaml2&gt;=4.5.0'</code> to ensure
  11947. the dependencies are installed and ready to go.</li>
  11948. <li>Restart Synapse.</li>
  11949. </ol>
  11950. <p>Then in Riot:</p>
  11951. <ol>
  11952. <li>Visit the login page with a Riot pointing at your homeserver.</li>
  11953. <li>Click the Single Sign-On button.</li>
  11954. <li>On the samling page, enter a Name Identifier and add a SAML Attribute for <code>uid=your_localpart</code>.
  11955. The response must also be signed.</li>
  11956. <li>Click &quot;Next&quot;.</li>
  11957. <li>Click &quot;Post Response&quot; (change nothing).</li>
  11958. <li>You should be logged in.</li>
  11959. </ol>
  11960. <p>If you try and repeat this process, you may be automatically logged in using the information you
  11961. gave previously. To fix this, open your developer console (<code>F12</code> or <code>Ctrl+Shift+I</code>) while on the
  11962. samling page and clear the site data. In Chrome, this will be a button on the Application tab.</p>
  11963. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-cas-as-a-developer-without-a-server"><a class="header" href="#how-to-test-cas-as-a-developer-without-a-server">How to test CAS as a developer without a server</a></h1>
  11964. <p>The <a href="https://github.com/jbittel/django-mama-cas">django-mama-cas</a> project is an
  11965. easy to run CAS implementation built on top of Django.</p>
  11966. <h2 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h2>
  11967. <ol>
  11968. <li>Create a new virtualenv: <code>python3 -m venv &lt;your virtualenv&gt;</code></li>
  11969. <li>Activate your virtualenv: <code>source /path/to/your/virtualenv/bin/activate</code></li>
  11970. <li>Install Django and django-mama-cas:
  11971. <pre><code>python -m pip install &quot;django&lt;3&quot; &quot;django-mama-cas==2.4.0&quot;
  11972. </code></pre>
  11973. </li>
  11974. <li>Create a Django project in the current directory:
  11975. <pre><code>django-admin startproject cas_test .
  11976. </code></pre>
  11977. </li>
  11978. <li>Follow the <a href="https://django-mama-cas.readthedocs.io/en/latest/installation.html#configuring">install directions</a> for django-mama-cas</li>
  11979. <li>Setup the SQLite database: <code>python manage.py migrate</code></li>
  11980. <li>Create a user:
  11981. <pre><code>python manage.py createsuperuser
  11982. </code></pre>
  11983. <ol>
  11984. <li>Use whatever you want as the username and password.</li>
  11985. <li>Leave the other fields blank.</li>
  11986. </ol>
  11987. </li>
  11988. <li>Use the built-in Django test server to serve the CAS endpoints on port 8000:
  11989. <pre><code>python manage.py runserver
  11990. </code></pre>
  11991. </li>
  11992. </ol>
  11993. <p>You should now have a Django project configured to serve CAS authentication with
  11994. a single user created.</p>
  11995. <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>
  11996. <ol>
  11997. <li>Modify your <code>homeserver.yaml</code> to enable CAS and point it to your locally
  11998. running Django test server:
  11999. <pre><code class="language-yaml">cas_config:
  12000. enabled: true
  12001. server_url: &quot;http://localhost:8000&quot;
  12002. service_url: &quot;http://localhost:8081&quot;
  12003. #displayname_attribute: name
  12004. #required_attributes:
  12005. # name: value
  12006. </code></pre>
  12007. </li>
  12008. <li>Restart Synapse.</li>
  12009. </ol>
  12010. <p>Note that the above configuration assumes the homeserver is running on port 8081
  12011. and that the CAS server is on port 8000, both on localhost.</p>
  12012. <h2 id="testing-the-configuration"><a class="header" href="#testing-the-configuration">Testing the configuration</a></h2>
  12013. <p>Then in Element:</p>
  12014. <ol>
  12015. <li>Visit the login page with a Element pointing at your homeserver.</li>
  12016. <li>Click the Single Sign-On button.</li>
  12017. <li>Login using the credentials created with <code>createsuperuser</code>.</li>
  12018. <li>You should be logged in.</li>
  12019. </ol>
  12020. <p>If you want to repeat this process you'll need to manually logout first:</p>
  12021. <ol>
  12022. <li>http://localhost:8000/admin/</li>
  12023. <li>Click &quot;logout&quot; in the top right.</li>
  12024. </ol>
  12025. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="auth-chain-difference-algorithm"><a class="header" href="#auth-chain-difference-algorithm">Auth Chain Difference Algorithm</a></h1>
  12026. <p>The auth chain difference algorithm is used by V2 state resolution, where a
  12027. naive implementation can be a significant source of CPU and DB usage.</p>
  12028. <h3 id="definitions"><a class="header" href="#definitions">Definitions</a></h3>
  12029. <p>A <em>state set</em> is a set of state events; e.g. the input of a state resolution
  12030. algorithm is a collection of state sets.</p>
  12031. <p>The <em>auth chain</em> of a set of events are all the events' auth events and <em>their</em>
  12032. auth events, recursively (i.e. the events reachable by walking the graph induced
  12033. by an event's auth events links).</p>
  12034. <p>The <em>auth chain difference</em> of a collection of state sets is the union minus the
  12035. intersection of the sets of auth chains corresponding to the state sets, i.e an
  12036. event is in the auth chain difference if it is reachable by walking the auth
  12037. event graph from at least one of the state sets but not from <em>all</em> of the state
  12038. sets.</p>
  12039. <h2 id="breadth-first-walk-algorithm"><a class="header" href="#breadth-first-walk-algorithm">Breadth First Walk Algorithm</a></h2>
  12040. <p>A way of calculating the auth chain difference without calculating the full auth
  12041. chains for each state set is to do a parallel breadth first walk (ordered by
  12042. depth) of each state set's auth chain. By tracking which events are reachable
  12043. from each state set we can finish early if every pending event is reachable from
  12044. every state set.</p>
  12045. <p>This can work well for state sets that have a small auth chain difference, but
  12046. can be very inefficient for larger differences. However, this algorithm is still
  12047. used if we don't have a chain cover index for the room (e.g. because we're in
  12048. the process of indexing it).</p>
  12049. <h2 id="chain-cover-index"><a class="header" href="#chain-cover-index">Chain Cover Index</a></h2>
  12050. <p>Synapse computes auth chain differences by pre-computing a &quot;chain cover&quot; index
  12051. for the auth chain in a room, allowing efficient reachability queries like &quot;is
  12052. event A in the auth chain of event B&quot;. This is done by assigning every event a
  12053. <em>chain ID</em> and <em>sequence number</em> (e.g. <code>(5,3)</code>), and having a map of <em>links</em>
  12054. between chains (e.g. <code>(5,3) -&gt; (2,4)</code>) such that A is reachable by B (i.e. <code>A</code>
  12055. is in the auth chain of <code>B</code>) if and only if either:</p>
  12056. <ol>
  12057. <li>A and B have the same chain ID and <code>A</code>'s sequence number is less than <code>B</code>'s
  12058. sequence number; or</li>
  12059. <li>there is a link <code>L</code> between <code>B</code>'s chain ID and <code>A</code>'s chain ID such that
  12060. <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>
  12061. </ol>
  12062. <p>There are actually two potential implementations, one where we store links from
  12063. each chain to every other reachable chain (the transitive closure of the links
  12064. graph), and one where we remove redundant links (the transitive reduction of the
  12065. links graph) e.g. if we have chains <code>C3 -&gt; C2 -&gt; C1</code> then the link <code>C3 -&gt; C1</code>
  12066. would not be stored. Synapse uses the former implementations so that it doesn't
  12067. need to recurse to test reachability between chains.</p>
  12068. <h3 id="example-6"><a class="header" href="#example-6">Example</a></h3>
  12069. <p>An example auth graph would look like the following, where chains have been
  12070. formed based on type/state_key and are denoted by colour and are labelled with
  12071. <code>(chain ID, sequence number)</code>. Links are denoted by the arrows (links in grey
  12072. are those that would be remove in the second implementation described above).</p>
  12073. <p><img src="auth_chain_diff.dot.png" alt="Example" /></p>
  12074. <p>Note that we don't include all links between events and their auth events, as
  12075. most of those links would be redundant. For example, all events point to the
  12076. create event, but each chain only needs the one link from it's base to the
  12077. create event.</p>
  12078. <h2 id="using-the-index"><a class="header" href="#using-the-index">Using the Index</a></h2>
  12079. <p>This index can be used to calculate the auth chain difference of the state sets
  12080. by looking at the chain ID and sequence numbers reachable from each state set:</p>
  12081. <ol>
  12082. <li>For every state set lookup the chain ID/sequence numbers of each state event</li>
  12083. <li>Use the index to find all chains and the maximum sequence number reachable
  12084. from each state set.</li>
  12085. <li>The auth chain difference is then all events in each chain that have sequence
  12086. numbers between the maximum sequence number reachable from <em>any</em> state set and
  12087. the minimum reachable by <em>all</em> state sets (if any).</li>
  12088. </ol>
  12089. <p>Note that steps 2 is effectively calculating the auth chain for each state set
  12090. (in terms of chain IDs and sequence numbers), and step 3 is calculating the
  12091. difference between the union and intersection of the auth chains.</p>
  12092. <h3 id="worked-example"><a class="header" href="#worked-example">Worked Example</a></h3>
  12093. <p>For example, given the above graph, we can calculate the difference between
  12094. state sets consisting of:</p>
  12095. <ol>
  12096. <li><code>S1</code>: Alice's invite <code>(4,1)</code> and Bob's second join <code>(2,2)</code>; and</li>
  12097. <li><code>S2</code>: Alice's second join <code>(4,3)</code> and Bob's first join <code>(2,1)</code>.</li>
  12098. </ol>
  12099. <p>Using the index we see that the following auth chains are reachable from each
  12100. state set:</p>
  12101. <ol>
  12102. <li><code>S1</code>: <code>(1,1)</code>, <code>(2,2)</code>, <code>(3,1)</code> &amp; <code>(4,1)</code></li>
  12103. <li><code>S2</code>: <code>(1,1)</code>, <code>(2,1)</code>, <code>(3,2)</code> &amp; <code>(4,3)</code></li>
  12104. </ol>
  12105. <p>And so, for each the ranges that are in the auth chain difference:</p>
  12106. <ol>
  12107. <li>Chain 1: None, (since everything can reach the create event).</li>
  12108. <li>Chain 2: The range <code>(1, 2]</code> (i.e. just <code>2</code>), as <code>1</code> is reachable by all state
  12109. sets and the maximum reachable is <code>2</code> (corresponding to Bob's second join).</li>
  12110. <li>Chain 3: Similarly the range <code>(1, 2]</code> (corresponding to the second power
  12111. level).</li>
  12112. <li>Chain 4: The range <code>(1, 3]</code> (corresponding to both of Alice's joins).</li>
  12113. </ol>
  12114. <p>So the final result is: Bob's second join <code>(2,2)</code>, the second power level
  12115. <code>(3,2)</code> and both of Alice's joins <code>(4,2)</code> &amp; <code>(4,3)</code>.</p>
  12116. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="media-repository"><a class="header" href="#media-repository">Media Repository</a></h1>
  12117. <p><em>Synapse implementation-specific details for the media repository</em></p>
  12118. <p>The media repository is where attachments and avatar photos are stored.
  12119. It stores attachment content and thumbnails for media uploaded by local users.
  12120. It caches attachment content and thumbnails for media uploaded by remote users.</p>
  12121. <h2 id="storage"><a class="header" href="#storage">Storage</a></h2>
  12122. <p>Each item of media is assigned a <code>media_id</code> when it is uploaded.
  12123. The <code>media_id</code> is a randomly chosen, URL safe 24 character string.</p>
  12124. <p>Metadata such as the MIME type, upload time and length are stored in the
  12125. sqlite3 database indexed by <code>media_id</code>.</p>
  12126. <p>Content is stored on the filesystem under a <code>&quot;local_content&quot;</code> directory.</p>
  12127. <p>Thumbnails are stored under a <code>&quot;local_thumbnails&quot;</code> directory.</p>
  12128. <p>The item with <code>media_id</code> <code>&quot;aabbccccccccdddddddddddd&quot;</code> is stored under
  12129. <code>&quot;local_content/aa/bb/ccccccccdddddddddddd&quot;</code>. Its thumbnail with width
  12130. <code>128</code> and height <code>96</code> and type <code>&quot;image/jpeg&quot;</code> is stored under
  12131. <code>&quot;local_thumbnails/aa/bb/ccccccccdddddddddddd/128-96-image-jpeg&quot;</code></p>
  12132. <p>Remote content is cached under <code>&quot;remote_content&quot;</code> directory. Each item of
  12133. remote content is assigned a local <code>&quot;filesystem_id&quot;</code> to ensure that the
  12134. directory structure <code>&quot;remote_content/server_name/aa/bb/ccccccccdddddddddddd&quot;</code>
  12135. is appropriate. Thumbnails for remote content are stored under
  12136. <code>&quot;remote_thumbnails/server_name/...&quot;</code></p>
  12137. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="room-and-user-statistics"><a class="header" href="#room-and-user-statistics">Room and User Statistics</a></h1>
  12138. <p>Synapse maintains room and user statistics (as well as a cache of room state),
  12139. in various tables. These can be used for administrative purposes but are also
  12140. used when generating the public room directory.</p>
  12141. <h1 id="synapse-developer-documentation"><a class="header" href="#synapse-developer-documentation">Synapse Developer Documentation</a></h1>
  12142. <h2 id="high-level-concepts"><a class="header" href="#high-level-concepts">High-Level Concepts</a></h2>
  12143. <h3 id="definitions-1"><a class="header" href="#definitions-1">Definitions</a></h3>
  12144. <ul>
  12145. <li><strong>subject</strong>: Something we are tracking stats about – currently a room or user.</li>
  12146. <li><strong>current row</strong>: An entry for a subject in the appropriate current statistics
  12147. table. Each subject can have only one.</li>
  12148. <li><strong>historical row</strong>: An entry for a subject in the appropriate historical
  12149. statistics table. Each subject can have any number of these.</li>
  12150. </ul>
  12151. <h3 id="overview-4"><a class="header" href="#overview-4">Overview</a></h3>
  12152. <p>Stats are maintained as time series. There are two kinds of column:</p>
  12153. <ul>
  12154. <li>absolute columns – where the value is correct for the time given by <code>end_ts</code>
  12155. in the stats row. (Imagine a line graph for these values)
  12156. <ul>
  12157. <li>They can also be thought of as 'gauges' in Prometheus, if you are familiar.</li>
  12158. </ul>
  12159. </li>
  12160. <li>per-slice columns – where the value corresponds to how many of the occurrences
  12161. occurred within the time slice given by <code>(end_ts − bucket_size)…end_ts</code>
  12162. or <code>start_ts…end_ts</code>. (Imagine a histogram for these values)</li>
  12163. </ul>
  12164. <p>Stats are maintained in two tables (for each type): current and historical.</p>
  12165. <p>Current stats correspond to the present values. Each subject can only have one
  12166. entry.</p>
  12167. <p>Historical stats correspond to values in the past. Subjects may have multiple
  12168. entries.</p>
  12169. <h2 id="concepts-around-the-management-of-stats"><a class="header" href="#concepts-around-the-management-of-stats">Concepts around the management of stats</a></h2>
  12170. <h3 id="current-rows"><a class="header" href="#current-rows">Current rows</a></h3>
  12171. <p>Current rows contain the most up-to-date statistics for a room.
  12172. They only contain absolute columns</p>
  12173. <h3 id="historical-rows"><a class="header" href="#historical-rows">Historical rows</a></h3>
  12174. <p>Historical rows can always be considered to be valid for the time slice and
  12175. end time specified.</p>
  12176. <ul>
  12177. <li>historical rows will not exist for every time slice – they will be omitted
  12178. if there were no changes. In this case, the following assumptions can be
  12179. made to interpolate/recreate missing rows:
  12180. <ul>
  12181. <li>absolute fields have the same values as in the preceding row</li>
  12182. <li>per-slice fields are zero (<code>0</code>)</li>
  12183. </ul>
  12184. </li>
  12185. <li>historical rows will not be retained forever – rows older than a configurable
  12186. time will be purged.</li>
  12187. </ul>
  12188. <h4 id="purge"><a class="header" href="#purge">Purge</a></h4>
  12189. <p>The purging of historical rows is not yet implemented.</p>
  12190. <div id="chapter_begin" style="break-before: page; page-break-before: always;"></div><h1 id="deprecation-policy-for-platform-dependencies"><a class="header" href="#deprecation-policy-for-platform-dependencies">Deprecation Policy for Platform Dependencies</a></h1>
  12191. <p>Synapse has a number of platform dependencies, including Python and PostgreSQL.
  12192. This document outlines the policy towards which versions we support, and when we
  12193. drop support for versions in the future.</p>
  12194. <h2 id="policy"><a class="header" href="#policy">Policy</a></h2>
  12195. <p>Synapse follows the upstream support life cycles for Python and PostgreSQL,
  12196. i.e. when a version reaches End of Life Synapse will withdraw support for that
  12197. version in future releases.</p>
  12198. <p>Details on the upstream support life cycles for Python and PostgreSQL are
  12199. documented at https://endoflife.date/python and
  12200. https://endoflife.date/postgresql.</p>
  12201. <h2 id="context"><a class="header" href="#context">Context</a></h2>
  12202. <p>It is important for system admins to have a clear understanding of the platform
  12203. requirements of Synapse and its deprecation policies so that they can
  12204. effectively plan upgrading their infrastructure ahead of time. This is
  12205. especially important in contexts where upgrading the infrastructure requires
  12206. auditing and approval from a security team, or where otherwise upgrading is a
  12207. long process.</p>
  12208. <p>By following the upstream support life cycles Synapse can ensure that its
  12209. dependencies continue to get security patches, while not requiring system admins
  12210. to constantly update their platform dependencies to the latest versions.</p>
  12211. </main>
  12212. <nav class="nav-wrapper" aria-label="Page navigation">
  12213. <!-- Mobile navigation buttons -->
  12214. <div style="clear: both"></div>
  12215. </nav>
  12216. </div>
  12217. </div>
  12218. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  12219. </nav>
  12220. </div>
  12221. <script type="text/javascript">
  12222. window.playground_copyable = true;
  12223. </script>
  12224. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  12225. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  12226. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  12227. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  12228. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  12229. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  12230. <!-- Custom JS scripts -->
  12231. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  12232. <script type="text/javascript">
  12233. window.addEventListener('load', function() {
  12234. window.setTimeout(window.print, 100);
  12235. });
  12236. </script>
  12237. </body>
  12238. </html>