print.html 707 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487
  1. <!DOCTYPE HTML>
  2. <html lang="en" class="sidebar-visible no-js light">
  3. <head>
  4. <!-- Book generated using mdBook -->
  5. <meta charset="UTF-8">
  6. <title>Synapse</title>
  7. <meta name="robots" content="noindex" />
  8. <!-- Custom HTML head -->
  9. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  10. <meta name="description" content="">
  11. <meta name="viewport" content="width=device-width, initial-scale=1">
  12. <meta name="theme-color" content="#ffffff" />
  13. <link rel="icon" href="favicon.svg">
  14. <link rel="shortcut icon" href="favicon.png">
  15. <link rel="stylesheet" href="css/variables.css">
  16. <link rel="stylesheet" href="css/general.css">
  17. <link rel="stylesheet" href="css/chrome.css">
  18. <link rel="stylesheet" href="css/print.css" media="print">
  19. <!-- Fonts -->
  20. <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
  21. <link rel="stylesheet" href="fonts/fonts.css">
  22. <!-- Highlight.js Stylesheets -->
  23. <link rel="stylesheet" href="highlight.css">
  24. <link rel="stylesheet" href="tomorrow-night.css">
  25. <link rel="stylesheet" href="ayu-highlight.css">
  26. <!-- Custom theme stylesheets -->
  27. <link rel="stylesheet" href="docs/website_files/table-of-contents.css">
  28. <link rel="stylesheet" href="docs/website_files/remove-nav-buttons.css">
  29. <link rel="stylesheet" href="docs/website_files/indent-section-headers.css">
  30. <link rel="stylesheet" href="docs/website_files/version-picker.css">
  31. </head>
  32. <body>
  33. <!-- Provide site root to javascript -->
  34. <script type="text/javascript">
  35. var path_to_root = "";
  36. var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
  37. </script>
  38. <!-- Work around some values being stored in localStorage wrapped in quotes -->
  39. <script type="text/javascript">
  40. try {
  41. var theme = localStorage.getItem('mdbook-theme');
  42. var sidebar = localStorage.getItem('mdbook-sidebar');
  43. if (theme.startsWith('"') && theme.endsWith('"')) {
  44. localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
  45. }
  46. if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
  47. localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
  48. }
  49. } catch (e) { }
  50. </script>
  51. <!-- Set the theme before any content is loaded, prevents flash -->
  52. <script type="text/javascript">
  53. var theme;
  54. try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
  55. if (theme === null || theme === undefined) { theme = default_theme; }
  56. var html = document.querySelector('html');
  57. html.classList.remove('no-js')
  58. html.classList.remove('light')
  59. html.classList.add(theme);
  60. html.classList.add('js');
  61. </script>
  62. <!-- Hide / unhide sidebar before it is displayed -->
  63. <script type="text/javascript">
  64. var html = document.querySelector('html');
  65. var sidebar = 'hidden';
  66. if (document.body.clientWidth >= 1080) {
  67. try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
  68. sidebar = sidebar || 'visible';
  69. }
  70. html.classList.remove('sidebar-visible');
  71. html.classList.add("sidebar-" + sidebar);
  72. </script>
  73. <nav id="sidebar" class="sidebar" aria-label="Table of contents">
  74. <div class="sidebar-scrollbox">
  75. <ol class="chapter"><li class="chapter-item expanded affix "><li class="part-title">Introduction</li><li class="chapter-item expanded "><a href="welcome_and_overview.html">Welcome and Overview</a></li><li class="chapter-item expanded affix "><li class="part-title">Setup</li><li class="chapter-item expanded "><a href="setup/installation.html">Installation</a></li><li class="chapter-item expanded "><a href="postgres.html">Using Postgres</a></li><li class="chapter-item expanded "><a href="reverse_proxy.html">Configuring a Reverse Proxy</a></li><li class="chapter-item expanded "><a href="setup/forward_proxy.html">Configuring a Forward/Outbound Proxy</a></li><li class="chapter-item expanded "><a href="turn-howto.html">Configuring a Turn Server</a></li><li class="chapter-item expanded "><a href="delegate.html">Delegation</a></li><li class="chapter-item expanded affix "><li class="part-title">Upgrading</li><li class="chapter-item expanded "><a href="upgrade.html">Upgrading between Synapse Versions</a></li><li class="chapter-item expanded "><a href="MSC1711_certificates_FAQ.html">Upgrading from pre-Synapse 1.0</a></li><li class="chapter-item expanded affix "><li class="part-title">Usage</li><li class="chapter-item expanded "><a href="federate.html">Federation</a></li><li class="chapter-item expanded "><a href="usage/configuration/index.html">Configuration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/configuration/homeserver_sample_config.html">Homeserver Sample Config File</a></li><li class="chapter-item expanded "><a href="usage/configuration/logging_sample_config.html">Logging Sample Config File</a></li><li class="chapter-item expanded "><a href="structured_logging.html">Structured Logging</a></li><li class="chapter-item expanded "><a href="templates.html">Templates</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/index.html">User Authentication</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single-Sign On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="openid.html">OpenID Connect</a></li><li class="chapter-item expanded "><div>SAML</div></li><li class="chapter-item expanded "><div>CAS</div></li><li class="chapter-item expanded "><a href="sso_mapping_providers.html">SSO Mapping Providers</a></li></ol></li><li class="chapter-item expanded "><a href="password_auth_providers.html">Password Auth Providers</a></li><li class="chapter-item expanded "><a href="jwt.html">JSON Web Tokens</a></li></ol></li><li class="chapter-item expanded "><a href="CAPTCHA_SETUP.html">Registration Captcha</a></li><li class="chapter-item expanded "><a href="application_services.html">Application Services</a></li><li class="chapter-item expanded "><a href="server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="consent_tracking.html">Consent Tracking</a></li><li class="chapter-item expanded "><a href="development/url_previews.html">URL Previews</a></li><li class="chapter-item expanded "><a href="user_directory.html">User Directory</a></li><li class="chapter-item expanded "><a href="message_retention_policies.html">Message Retention Policies</a></li><li class="chapter-item expanded "><a href="modules/index.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/writing_a_module.html">Writing a module</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/spam_checker_callbacks.html">Spam checker callbacks</a></li><li class="chapter-item expanded "><a href="modules/third_party_rules_callbacks.html">Third-party rules callbacks</a></li><li class="chapter-item expanded "><a href="modules/presence_router_callbacks.html">Presence router callbacks</a></li><li class="chapter-item expanded "><a href="modules/account_validity_callbacks.html">Account validity callbacks</a></li><li class="chapter-item expanded "><a href="modules/password_auth_provider_callbacks.html">Password auth provider callbacks</a></li><li class="chapter-item expanded "><a href="modules/porting_legacy_module.html">Porting a legacy module to the new interface</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="workers.html">Workers</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="synctl_workers.html">Using synctl with Workers</a></li><li class="chapter-item expanded "><a href="systemd-with-workers/index.html">Systemd</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/index.html">Administration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/admin_api/index.html">Admin API</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="admin_api/account_validity.html">Account Validity</a></li><li class="chapter-item expanded "><a href="admin_api/delete_group.html">Delete Group</a></li><li class="chapter-item expanded "><a href="admin_api/event_reports.html">Event Reports</a></li><li class="chapter-item expanded "><a href="admin_api/media_admin_api.html">Media</a></li><li class="chapter-item expanded "><a href="admin_api/purge_history_api.html">Purge History</a></li><li class="chapter-item expanded "><a href="admin_api/register_api.html">Register Users</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/registration_tokens.html">Registration Tokens</a></li><li class="chapter-item expanded "><a href="admin_api/room_membership.html">Manipulate Room Membership</a></li><li class="chapter-item expanded "><a href="admin_api/rooms.html">Rooms</a></li><li class="chapter-item expanded "><a href="admin_api/server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="admin_api/statistics.html">Statistics</a></li><li class="chapter-item expanded "><a href="admin_api/user_admin_api.html">Users</a></li><li class="chapter-item expanded "><a href="admin_api/version_api.html">Server Version</a></li></ol></li><li class="chapter-item expanded "><a href="manhole.html">Manhole</a></li><li class="chapter-item expanded "><a href="metrics-howto.html">Monitoring</a></li><li class="chapter-item expanded "><a href="usage/administration/request_log.html">Request log format</a></li><li class="chapter-item expanded "><div>Scripts</div></li></ol></li><li class="chapter-item expanded "><li class="part-title">Development</li><li class="chapter-item expanded "><a href="development/contributing_guide.html">Contributing Guide</a></li><li class="chapter-item expanded "><a href="code_style.html">Code Style</a></li><li class="chapter-item expanded "><a href="development/git.html">Git Usage</a></li><li class="chapter-item expanded "><div>Testing</div></li><li class="chapter-item expanded "><a href="opentracing.html">OpenTracing</a></li><li class="chapter-item expanded "><a href="development/database_schema.html">Database Schemas</a></li><li class="chapter-item expanded "><a href="development/experimental_features.html">Experimental features</a></li><li class="chapter-item expanded "><div>Synapse Architecture</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="log_contexts.html">Log Contexts</a></li><li class="chapter-item expanded "><a href="replication.html">Replication</a></li><li class="chapter-item expanded "><a href="tcp_replication.html">TCP Replication</a></li></ol></li><li class="chapter-item expanded "><a href="development/internal_documentation/index.html">Internal Documentation</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single Sign-On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="development/cas.html">CAS</a></li></ol></li><li class="chapter-item expanded "><a href="development/room-dag-concepts.html">Room DAG concepts</a></li><li class="chapter-item expanded "><div>State Resolution</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="auth_chain_difference_algorithm.html">The Auth Chain Difference Algorithm</a></li></ol></li><li class="chapter-item expanded "><a href="media_repository.html">Media Repository</a></li><li class="chapter-item expanded "><a href="room_and_user_statistics.html">Room and User Statistics</a></li></ol></li><li class="chapter-item expanded "><div>Scripts</div></li><li class="chapter-item expanded affix "><li class="part-title">Other</li><li class="chapter-item expanded "><a href="deprecation_policy.html">Dependency Deprecation Policy</a></li></ol>
  76. </div>
  77. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  78. </nav>
  79. <div id="page-wrapper" class="page-wrapper">
  80. <div class="page">
  81. <div id="menu-bar-hover-placeholder"></div>
  82. <div id="menu-bar" class="menu-bar sticky bordered">
  83. <div class="left-buttons">
  84. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  85. <i class="fa fa-bars"></i>
  86. </button>
  87. <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
  88. <i class="fa fa-paint-brush"></i>
  89. </button>
  90. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  91. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  94. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  95. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  96. </ul>
  97. <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
  98. <i class="fa fa-search"></i>
  99. </button>
  100. <div class="version-picker">
  101. <div class="dropdown">
  102. <div class="select">
  103. <span></span>
  104. <i class="fa fa-chevron-down"></i>
  105. </div>
  106. <input type="hidden" name="version">
  107. <ul class="dropdown-menu">
  108. <!-- Versions will be added dynamically in version-picker.js -->
  109. </ul>
  110. </div>
  111. </div>
  112. </div>
  113. <h1 class="menu-title">Synapse</h1>
  114. <div class="right-buttons">
  115. <a href="print.html" title="Print this book" aria-label="Print this book">
  116. <i id="print-button" class="fa fa-print"></i>
  117. </a>
  118. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  119. <i id="git-repository-button" class="fa fa-github"></i>
  120. </a>
  121. </div>
  122. </div>
  123. <div id="search-wrapper" class="hidden">
  124. <form id="searchbar-outer" class="searchbar-outer">
  125. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  126. </form>
  127. <div id="searchresults-outer" class="searchresults-outer hidden">
  128. <div id="searchresults-header" class="searchresults-header"></div>
  129. <ul id="searchresults">
  130. </ul>
  131. </div>
  132. </div>
  133. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  134. <script type="text/javascript">
  135. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  136. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  137. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  138. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  139. });
  140. </script>
  141. <div id="content" class="content">
  142. <main>
  143. <!-- Page table of contents -->
  144. <div class="sidetoc">
  145. <nav class="pagetoc"></nav>
  146. </div>
  147. <div style="break-before: page; page-break-before: always;"></div><h1 id="introduction"><a class="header" href="#introduction">Introduction</a></h1>
  148. <p>Welcome to the documentation repository for Synapse, a
  149. <a href="https://matrix.org">Matrix</a> homeserver implementation developed by the matrix.org core
  150. team.</p>
  151. <h2 id="installing-and-using-synapse"><a class="header" href="#installing-and-using-synapse">Installing and using Synapse</a></h2>
  152. <p>This documentation covers topics for <strong>installation</strong>, <strong>configuration</strong> and
  153. <strong>maintainence</strong> of your Synapse process:</p>
  154. <ul>
  155. <li>
  156. <p>Learn how to <a href="setup/installation.html">install</a> and
  157. <a href="usage/configuration/index.html">configure</a> your own instance, perhaps with <a href="usage/configuration/user_authentication/index.html">Single
  158. Sign-On</a>.</p>
  159. </li>
  160. <li>
  161. <p>See how to <a href="upgrade.html">upgrade</a> between Synapse versions.</p>
  162. </li>
  163. <li>
  164. <p>Administer your instance using the <a href="usage/administration/admin_api/index.html">Admin
  165. API</a>, installing <a href="modules/index.html">pluggable
  166. modules</a>, or by accessing the <a href="manhole.html">manhole</a>.</p>
  167. </li>
  168. <li>
  169. <p>Learn how to <a href="usage/administration/request_log.html">read log lines</a>, configure
  170. <a href="usage/configuration/logging_sample_config.html">logging</a> or set up <a href="structured_logging.html">structured
  171. logging</a>.</p>
  172. </li>
  173. <li>
  174. <p>Scale Synapse through additional <a href="workers.html">worker processes</a>.</p>
  175. </li>
  176. <li>
  177. <p>Set up <a href="metrics-howto.html">monitoring and metrics</a> to keep an eye on your
  178. Synapse instance's performance.</p>
  179. </li>
  180. </ul>
  181. <h2 id="developing-on-synapse"><a class="header" href="#developing-on-synapse">Developing on Synapse</a></h2>
  182. <p>Contributions are welcome! Synapse is primarily written in
  183. <a href="https://python.org">Python</a>. As a developer, you may be interested in the
  184. following documentation:</p>
  185. <ul>
  186. <li>
  187. <p>Read the <a href="development/contributing_guide.html">Contributing Guide</a>. It is meant
  188. to walk new contributors through the process of developing and submitting a
  189. change to the Synapse codebase (which is <a href="https://github.com/matrix-org/synapse">hosted on
  190. GitHub</a>).</p>
  191. </li>
  192. <li>
  193. <p>Set up your <a href="development/contributing_guide.html#2-what-do-i-need">development
  194. environment</a>, then learn
  195. how to <a href="development/contributing_guide.html#run-the-linters">lint</a> and
  196. <a href="development/contributing_guide.html#8-test-test-test">test</a> your code.</p>
  197. </li>
  198. <li>
  199. <p>Look at <a href="https://github.com/matrix-org/synapse/issues">the issue tracker</a> for
  200. bugs to fix or features to add. If you're new, it may be best to start with
  201. those labeled <a href="https://github.com/matrix-org/synapse/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22">good first
  202. issue</a>.</p>
  203. </li>
  204. <li>
  205. <p>Understand <a href="development/internal_documentation/index.html">how Synapse is
  206. built</a>, how to <a href="development/database_schema.html">migrate
  207. database schemas</a>, learn about
  208. <a href="federate.html">federation</a> and how to <a href="federate.html#running-a-demo-federation-of-synapses">set up a local
  209. federation</a> for development.</p>
  210. </li>
  211. <li>
  212. <p>We like to keep our <code>git</code> history clean. <a href="development/git.html">Learn</a> how to
  213. do so!</p>
  214. </li>
  215. <li>
  216. <p>And finally, contribute to this documentation! The source for which is
  217. <a href="https://github.com/matrix-org/synapse/tree/develop/docs">located here</a>.</p>
  218. </li>
  219. </ul>
  220. <h2 id="donating-to-synapse-development"><a class="header" href="#donating-to-synapse-development">Donating to Synapse development</a></h2>
  221. <p>Want to help keep Synapse going but don't know how to code? Synapse is a
  222. <a href="https://matrix.org">Matrix.org Foundation</a> project. Consider becoming a
  223. supportor on <a href="https://liberapay.com/matrixdotorg">Liberapay</a>,
  224. <a href="https://patreon.com/matrixdotorg">Patreon</a> or through
  225. <a href="https://paypal.me/matrixdotorg">PayPal</a> via a one-time donation.</p>
  226. <p>If you are an organisation or enterprise and would like to sponsor development,
  227. reach out to us over email at: support (at) matrix.org</p>
  228. <h2 id="reporting-a-security-vulnerability"><a class="header" href="#reporting-a-security-vulnerability">Reporting a security vulnerability</a></h2>
  229. <p>If you've found a security issue in Synapse or any other Matrix.org Foundation
  230. project, please report it to us in accordance with our <a href="https://www.matrix.org/security-disclosure-policy/">Security Disclosure
  231. Policy</a>. Thank you!</p>
  232. <div style="break-before: page; page-break-before: always;"></div><h1 id="installation-instructions"><a class="header" href="#installation-instructions">Installation Instructions</a></h1>
  233. <h2 id="choosing-your-server-name"><a class="header" href="#choosing-your-server-name">Choosing your server name</a></h2>
  234. <p>It is important to choose the name for your server before you install Synapse,
  235. because it cannot be changed later.</p>
  236. <p>The server name determines the &quot;domain&quot; part of user-ids for users on your
  237. server: these will all be of the format <code>@user:my.domain.name</code>. It also
  238. determines how other matrix servers will reach yours for federation.</p>
  239. <p>For a test configuration, set this to the hostname of your server. For a more
  240. production-ready setup, you will probably want to specify your domain
  241. (<code>example.com</code>) rather than a matrix-specific hostname here (in the same way
  242. that your email address is probably <code>user@example.com</code> rather than
  243. <code>user@email.example.com</code>) - but doing so may require more advanced setup: see
  244. <a href="setup/../federate.html">Setting up Federation</a>.</p>
  245. <h2 id="installing-synapse"><a class="header" href="#installing-synapse">Installing Synapse</a></h2>
  246. <h3 id="prebuilt-packages"><a class="header" href="#prebuilt-packages">Prebuilt packages</a></h3>
  247. <p>Prebuilt packages are available for a number of platforms. These are recommended
  248. for most users.</p>
  249. <h4 id="docker-images-and-ansible-playbooks"><a class="header" href="#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></h4>
  250. <p>There is an official synapse image available at
  251. <a href="https://hub.docker.com/r/matrixdotorg/synapse">https://hub.docker.com/r/matrixdotorg/synapse</a> which can be used with
  252. the docker-compose file available at
  253. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/docker">contrib/docker</a>.
  254. Further information on this including configuration options is available in the README
  255. on hub.docker.com.</p>
  256. <p>Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a
  257. Dockerfile to automate a synapse server in a single Docker image, at
  258. <a href="https://hub.docker.com/r/avhost/docker-matrix/tags/">https://hub.docker.com/r/avhost/docker-matrix/tags/</a></p>
  259. <p>Slavi Pantaleev has created an Ansible playbook,
  260. which installs the offical Docker image of Matrix Synapse
  261. along with many other Matrix-related services (Postgres database, Element, coturn,
  262. ma1sd, SSL support, etc.).
  263. For more details, see
  264. <a href="https://github.com/spantaleev/matrix-docker-ansible-deploy">https://github.com/spantaleev/matrix-docker-ansible-deploy</a></p>
  265. <h4 id="debianubuntu"><a class="header" href="#debianubuntu">Debian/Ubuntu</a></h4>
  266. <h5 id="matrixorg-packages"><a class="header" href="#matrixorg-packages">Matrix.org packages</a></h5>
  267. <p>Matrix.org provides Debian/Ubuntu packages of Synapse, for the amd64
  268. architecture via <a href="https://packages.matrix.org/debian/">https://packages.matrix.org/debian/</a>.</p>
  269. <p>To install the latest release:</p>
  270. <pre><code class="language-sh">sudo apt install -y lsb-release wget apt-transport-https
  271. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  272. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main&quot; |
  273. sudo tee /etc/apt/sources.list.d/matrix-org.list
  274. sudo apt update
  275. sudo apt install matrix-synapse-py3
  276. </code></pre>
  277. <p>Packages are also published for release candidates. To enable the prerelease
  278. channel, add <code>prerelease</code> to the <code>sources.list</code> line. For example:</p>
  279. <pre><code class="language-sh">sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  280. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main prerelease&quot; |
  281. sudo tee /etc/apt/sources.list.d/matrix-org.list
  282. sudo apt update
  283. sudo apt install matrix-synapse-py3
  284. </code></pre>
  285. <p>The fingerprint of the repository signing key (as shown by <code>gpg /usr/share/keyrings/matrix-org-archive-keyring.gpg</code>) is
  286. <code>AAF9AE843A7584B5A3E4CD2BCF45A512DE2DA058</code>.</p>
  287. <h5 id="downstream-debian-packages"><a class="header" href="#downstream-debian-packages">Downstream Debian packages</a></h5>
  288. <p>We do not recommend using the packages from the default Debian <code>buster</code>
  289. repository at this time, as they are old and suffer from known security
  290. vulnerabilities. You can install the latest version of Synapse from
  291. <a href="setup/installation.html#matrixorg-packages">our repository</a> or from <code>buster-backports</code>. Please
  292. see the <a href="https://backports.debian.org/Instructions/">Debian documentation</a>
  293. for information on how to use backports.</p>
  294. <p>If you are using Debian <code>sid</code> or testing, Synapse is available in the default
  295. repositories and it should be possible to install it simply with:</p>
  296. <pre><code class="language-sh">sudo apt install matrix-synapse
  297. </code></pre>
  298. <h5 id="downstream-ubuntu-packages"><a class="header" href="#downstream-ubuntu-packages">Downstream Ubuntu packages</a></h5>
  299. <p>We do not recommend using the packages in the default Ubuntu repository
  300. at this time, as they are old and suffer from known security vulnerabilities.
  301. The latest version of Synapse can be installed from <a href="setup/installation.html#matrixorg-packages">our repository</a>.</p>
  302. <h4 id="fedora"><a class="header" href="#fedora">Fedora</a></h4>
  303. <p>Synapse is in the Fedora repositories as <code>matrix-synapse</code>:</p>
  304. <pre><code class="language-sh">sudo dnf install matrix-synapse
  305. </code></pre>
  306. <p>Oleg Girko provides Fedora RPMs at
  307. <a href="https://obs.infoserver.lv/project/monitor/matrix-synapse">https://obs.infoserver.lv/project/monitor/matrix-synapse</a></p>
  308. <h4 id="opensuse"><a class="header" href="#opensuse">OpenSUSE</a></h4>
  309. <p>Synapse is in the OpenSUSE repositories as <code>matrix-synapse</code>:</p>
  310. <pre><code class="language-sh">sudo zypper install matrix-synapse
  311. </code></pre>
  312. <h4 id="suse-linux-enterprise-server"><a class="header" href="#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></h4>
  313. <p>Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at
  314. <a href="https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/">https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/</a></p>
  315. <h4 id="archlinux"><a class="header" href="#archlinux">ArchLinux</a></h4>
  316. <p>The quickest way to get up and running with ArchLinux is probably with the community package
  317. <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
  318. the necessary dependencies.</p>
  319. <p>pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):</p>
  320. <pre><code class="language-sh">sudo pip install --upgrade pip
  321. </code></pre>
  322. <p>If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  323. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  324. compile it under the right architecture. (This should not be needed if
  325. installing under virtualenv):</p>
  326. <pre><code class="language-sh">sudo pip uninstall py-bcrypt
  327. sudo pip install py-bcrypt
  328. </code></pre>
  329. <h4 id="void-linux"><a class="header" href="#void-linux">Void Linux</a></h4>
  330. <p>Synapse can be found in the void repositories as 'synapse':</p>
  331. <pre><code class="language-sh">xbps-install -Su
  332. xbps-install -S synapse
  333. </code></pre>
  334. <h4 id="freebsd"><a class="header" href="#freebsd">FreeBSD</a></h4>
  335. <p>Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:</p>
  336. <ul>
  337. <li>Ports: <code>cd /usr/ports/net-im/py-matrix-synapse &amp;&amp; make install clean</code></li>
  338. <li>Packages: <code>pkg install py37-matrix-synapse</code></li>
  339. </ul>
  340. <h4 id="openbsd"><a class="header" href="#openbsd">OpenBSD</a></h4>
  341. <p>As of OpenBSD 6.7 Synapse is available as a pre-compiled binary. The filesystem
  342. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  343. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  344. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  345. <p>Installing Synapse:</p>
  346. <pre><code class="language-sh">doas pkg_add synapse
  347. </code></pre>
  348. <h4 id="nixos"><a class="header" href="#nixos">NixOS</a></h4>
  349. <p>Robin Lambertz has packaged Synapse for NixOS at:
  350. <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>
  351. <h3 id="installing-as-a-python-module-from-pypi"><a class="header" href="#installing-as-a-python-module-from-pypi">Installing as a Python module from PyPI</a></h3>
  352. <p>It's also possible to install Synapse as a Python module from PyPI.</p>
  353. <p>When following this route please make sure that the <a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a> are already installed.</p>
  354. <p>System requirements:</p>
  355. <ul>
  356. <li>POSIX-compliant system (tested on Linux &amp; OS X)</li>
  357. <li>Python 3.6 or later, up to Python 3.9.</li>
  358. <li>At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org</li>
  359. </ul>
  360. <p>To install the Synapse homeserver run:</p>
  361. <pre><code class="language-sh">mkdir -p ~/synapse
  362. virtualenv -p python3 ~/synapse/env
  363. source ~/synapse/env/bin/activate
  364. pip install --upgrade pip
  365. pip install --upgrade setuptools
  366. pip install matrix-synapse
  367. </code></pre>
  368. <p>This will download Synapse from <a href="https://pypi.org/project/matrix-synapse">PyPI</a>
  369. and install it, along with the python libraries it uses, into a virtual environment
  370. under <code>~/synapse/env</code>. Feel free to pick a different directory if you
  371. prefer.</p>
  372. <p>This Synapse installation can then be later upgraded by using pip again with the
  373. update flag:</p>
  374. <pre><code class="language-sh">source ~/synapse/env/bin/activate
  375. pip install -U matrix-synapse
  376. </code></pre>
  377. <p>Before you can start Synapse, you will need to generate a configuration
  378. file. To do this, run (in your virtualenv, as before):</p>
  379. <pre><code class="language-sh">cd ~/synapse
  380. python -m synapse.app.homeserver \
  381. --server-name my.domain.name \
  382. --config-path homeserver.yaml \
  383. --generate-config \
  384. --report-stats=[yes|no]
  385. </code></pre>
  386. <p>... substituting an appropriate value for <code>--server-name</code>.</p>
  387. <p>This command will generate you a config file that you can then customise, but it will
  388. also generate a set of keys for you. These keys will allow your homeserver to
  389. identify itself to other homeserver, so don't lose or delete them. It would be
  390. wise to back them up somewhere safe. (If, for whatever reason, you do need to
  391. change your homeserver's keys, you may find that other homeserver have the
  392. old key cached. If you update the signing key, you should change the name of the
  393. key in the <code>&lt;server name&gt;.signing.key</code> file (the second word) to something
  394. 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>
  395. <p>To actually run your new homeserver, pick a working directory for Synapse to
  396. run (e.g. <code>~/synapse</code>), and:</p>
  397. <pre><code class="language-sh">cd ~/synapse
  398. source env/bin/activate
  399. synctl start
  400. </code></pre>
  401. <h4 id="platform-specific-prerequisites"><a class="header" href="#platform-specific-prerequisites">Platform-specific prerequisites</a></h4>
  402. <p>Synapse is written in Python but some of the libraries it uses are written in
  403. C. So before we can install Synapse itself we need a working C compiler and the
  404. header files for Python C extensions.</p>
  405. <h5 id="debianubunturaspbian"><a class="header" href="#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></h5>
  406. <p>Installing prerequisites on Ubuntu or Debian:</p>
  407. <pre><code class="language-sh">sudo apt install build-essential python3-dev libffi-dev \
  408. python3-pip python3-setuptools sqlite3 \
  409. libssl-dev virtualenv libjpeg-dev libxslt1-dev
  410. </code></pre>
  411. <h5 id="archlinux-1"><a class="header" href="#archlinux-1">ArchLinux</a></h5>
  412. <p>Installing prerequisites on ArchLinux:</p>
  413. <pre><code class="language-sh">sudo pacman -S base-devel python python-pip \
  414. python-setuptools python-virtualenv sqlite3
  415. </code></pre>
  416. <h5 id="centosfedora"><a class="header" href="#centosfedora">CentOS/Fedora</a></h5>
  417. <p>Installing prerequisites on CentOS or Fedora Linux:</p>
  418. <pre><code class="language-sh">sudo dnf install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
  419. libwebp-devel libxml2-devel libxslt-devel libpq-devel \
  420. python3-virtualenv libffi-devel openssl-devel python3-devel
  421. sudo dnf groupinstall &quot;Development Tools&quot;
  422. </code></pre>
  423. <h5 id="macos"><a class="header" href="#macos">macOS</a></h5>
  424. <p>Installing prerequisites on macOS:</p>
  425. <p>You may need to install the latest Xcode developer tools:</p>
  426. <pre><code class="language-sh">xcode-select --install
  427. </code></pre>
  428. <p>On ARM-based Macs you may need to explicitly install libjpeg which is a pillow dependency. You can use Homebrew (https://brew.sh):</p>
  429. <pre><code class="language-sh"> brew install jpeg
  430. </code></pre>
  431. <p>On macOS Catalina (10.15) you may need to explicitly install OpenSSL
  432. via brew and inform <code>pip</code> about it so that <code>psycopg2</code> builds:</p>
  433. <pre><code class="language-sh">brew install openssl@1.1
  434. export LDFLAGS=&quot;-L/usr/local/opt/openssl/lib&quot;
  435. export CPPFLAGS=&quot;-I/usr/local/opt/openssl/include&quot;
  436. </code></pre>
  437. <h5 id="opensuse-1"><a class="header" href="#opensuse-1">OpenSUSE</a></h5>
  438. <p>Installing prerequisites on openSUSE:</p>
  439. <pre><code class="language-sh">sudo zypper in -t pattern devel_basis
  440. sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
  441. python-devel libffi-devel libopenssl-devel libjpeg62-devel
  442. </code></pre>
  443. <h5 id="openbsd-1"><a class="header" href="#openbsd-1">OpenBSD</a></h5>
  444. <p>A port of Synapse is available under <code>net/synapse</code>. The filesystem
  445. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  446. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  447. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  448. <p>To be able to build Synapse's dependency on python the <code>WRKOBJDIR</code>
  449. (cf. <code>bsd.port.mk(5)</code>) for building python, too, needs to be on a filesystem
  450. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>).</p>
  451. <p>Creating a <code>WRKOBJDIR</code> for building python under <code>/usr/local</code> (which on a
  452. default OpenBSD installation is mounted with <code>wxallowed</code>):</p>
  453. <pre><code class="language-sh">doas mkdir /usr/local/pobj_wxallowed
  454. </code></pre>
  455. <p>Assuming <code>PORTS_PRIVSEP=Yes</code> (cf. <code>bsd.port.mk(5)</code>) and <code>SUDO=doas</code> are
  456. configured in <code>/etc/mk.conf</code>:</p>
  457. <pre><code class="language-sh">doas chown _pbuild:_pbuild /usr/local/pobj_wxallowed
  458. </code></pre>
  459. <p>Setting the <code>WRKOBJDIR</code> for building python:</p>
  460. <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
  461. </code></pre>
  462. <p>Building Synapse:</p>
  463. <pre><code class="language-sh">cd /usr/ports/net/synapse
  464. make install
  465. </code></pre>
  466. <h5 id="windows"><a class="header" href="#windows">Windows</a></h5>
  467. <p>If you wish to run or develop Synapse on Windows, the Windows Subsystem For
  468. Linux provides a Linux environment on Windows 10 which is capable of using the
  469. Debian, Fedora, or source installation methods. More information about WSL can
  470. 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
  471. 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>
  472. for Windows Server.</p>
  473. <h2 id="setting-up-synapse"><a class="header" href="#setting-up-synapse">Setting up Synapse</a></h2>
  474. <p>Once you have installed synapse as above, you will need to configure it.</p>
  475. <h3 id="using-postgresql"><a class="header" href="#using-postgresql">Using PostgreSQL</a></h3>
  476. <p>By default Synapse uses an <a href="https://sqlite.org/">SQLite</a> database and in doing so trades
  477. performance for convenience. Almost all installations should opt to use <a href="https://www.postgresql.org">PostgreSQL</a>
  478. instead. Advantages include:</p>
  479. <ul>
  480. <li>significant performance improvements due to the superior threading and
  481. caching model, smarter query optimiser</li>
  482. <li>allowing the DB to be run on separate hardware</li>
  483. </ul>
  484. <p>For information on how to install and use PostgreSQL in Synapse, please see
  485. <a href="setup/../postgres.html">Using Postgres</a></p>
  486. <p>SQLite is only acceptable for testing purposes. SQLite should not be used in
  487. a production server. Synapse will perform poorly when using
  488. SQLite, especially when participating in large rooms.</p>
  489. <h3 id="tls-certificates"><a class="header" href="#tls-certificates">TLS certificates</a></h3>
  490. <p>The default configuration exposes a single HTTP port on the local
  491. interface: <code>http://localhost:8008</code>. It is suitable for local testing,
  492. but for any practical use, you will need Synapse's APIs to be served
  493. over HTTPS.</p>
  494. <p>The recommended way to do so is to set up a reverse proxy on port
  495. <code>8448</code>. You can find documentation on doing so in
  496. <a href="setup/../reverse_proxy.html">the reverse proxy documentation</a>.</p>
  497. <p>Alternatively, you can configure Synapse to expose an HTTPS port. To do
  498. so, you will need to edit <code>homeserver.yaml</code>, as follows:</p>
  499. <ul>
  500. <li>First, under the <code>listeners</code> section, uncomment the configuration for the
  501. TLS-enabled listener. (Remove the hash sign (<code>#</code>) at the start of
  502. each line). The relevant lines are like this:</li>
  503. </ul>
  504. <pre><code class="language-yaml"> - port: 8448
  505. type: http
  506. tls: true
  507. resources:
  508. - names: [client, federation]
  509. </code></pre>
  510. <ul>
  511. <li>
  512. <p>You will also need to uncomment the <code>tls_certificate_path</code> and
  513. <code>tls_private_key_path</code> lines under the <code>TLS</code> section. You will need to manage
  514. provisioning of these certificates yourself.</p>
  515. <p>If you are using your own certificate, be sure to use a <code>.pem</code> file that
  516. includes the full certificate chain including any intermediate certificates
  517. (for instance, if using certbot, use <code>fullchain.pem</code> as your certificate, not
  518. <code>cert.pem</code>).</p>
  519. </li>
  520. </ul>
  521. <p>For a more detailed guide to configuring your server for federation, see
  522. <a href="setup/../federate.html">Federation</a>.</p>
  523. <h3 id="client-well-known-uri"><a class="header" href="#client-well-known-uri">Client Well-Known URI</a></h3>
  524. <p>Setting up the client Well-Known URI is optional but if you set it up, it will
  525. allow users to enter their full username (e.g. <code>@user:&lt;server_name&gt;</code>) into clients
  526. which support well-known lookup to automatically configure the homeserver and
  527. identity server URLs. This is useful so that users don't have to memorize or think
  528. about the actual homeserver URL you are using.</p>
  529. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/client</code> should return JSON in
  530. the following format.</p>
  531. <pre><code class="language-json">{
  532. &quot;m.homeserver&quot;: {
  533. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  534. }
  535. }
  536. </code></pre>
  537. <p>It can optionally contain identity server information as well.</p>
  538. <pre><code class="language-json">{
  539. &quot;m.homeserver&quot;: {
  540. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  541. },
  542. &quot;m.identity_server&quot;: {
  543. &quot;base_url&quot;: &quot;https://&lt;identity.example.com&gt;&quot;
  544. }
  545. }
  546. </code></pre>
  547. <p>To work in browser based clients, the file must be served with the appropriate
  548. Cross-Origin Resource Sharing (CORS) headers. A recommended value would be
  549. <code>Access-Control-Allow-Origin: *</code> which would allow all browser based clients to
  550. view it.</p>
  551. <p>In nginx this would be something like:</p>
  552. <pre><code class="language-nginx">location /.well-known/matrix/client {
  553. return 200 '{&quot;m.homeserver&quot;: {&quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;}}';
  554. default_type application/json;
  555. add_header Access-Control-Allow-Origin *;
  556. }
  557. </code></pre>
  558. <p>You should also ensure the <code>public_baseurl</code> option in <code>homeserver.yaml</code> is set
  559. correctly. <code>public_baseurl</code> should be set to the URL that clients will use to
  560. connect to your server. This is the same URL you put for the <code>m.homeserver</code>
  561. <code>base_url</code> above.</p>
  562. <pre><code class="language-yaml">public_baseurl: &quot;https://&lt;matrix.example.com&gt;&quot;
  563. </code></pre>
  564. <h3 id="email"><a class="header" href="#email">Email</a></h3>
  565. <p>It is desirable for Synapse to have the capability to send email. This allows
  566. Synapse to send password reset emails, send verifications when an email address
  567. is added to a user's account, and send email notifications to users when they
  568. receive new messages.</p>
  569. <p>To configure an SMTP server for Synapse, modify the configuration section
  570. headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>, <code>smtp_port</code>
  571. and <code>notif_from</code> fields filled out. You may also need to set <code>smtp_user</code>,
  572. <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  573. <p>If email is not configured, password reset, registration and notifications via
  574. email will be disabled.</p>
  575. <h3 id="registering-a-user"><a class="header" href="#registering-a-user">Registering a user</a></h3>
  576. <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>
  577. <p>Alternatively, you can do so from the command line. This can be done as follows:</p>
  578. <ol>
  579. <li>If synapse was installed via pip, activate the virtualenv as follows (if Synapse was
  580. installed via a prebuilt package, <code>register_new_matrix_user</code> should already be
  581. on the search path):
  582. <pre><code class="language-sh">cd ~/synapse
  583. source env/bin/activate
  584. synctl start # if not already running
  585. </code></pre>
  586. </li>
  587. <li>Run the following command:
  588. <pre><code class="language-sh">register_new_matrix_user -c homeserver.yaml http://localhost:8008
  589. </code></pre>
  590. </li>
  591. </ol>
  592. <p>This will prompt you to add details for the new user, and will then connect to
  593. the running Synapse to create the new user. For example:</p>
  594. <pre><code>New user localpart: erikj
  595. Password:
  596. Confirm password:
  597. Make admin [no]:
  598. Success!
  599. </code></pre>
  600. <p>This process uses a setting <code>registration_shared_secret</code> in
  601. <code>homeserver.yaml</code>, which is shared between Synapse itself and the
  602. <code>register_new_matrix_user</code> script. It doesn't matter what it is (a random
  603. value is generated by <code>--generate-config</code>), but it should be kept secret, as
  604. anyone with knowledge of it can register users, including admin accounts,
  605. on your server even if <code>enable_registration</code> is <code>false</code>.</p>
  606. <h3 id="setting-up-a-turn-server"><a class="header" href="#setting-up-a-turn-server">Setting up a TURN server</a></h3>
  607. <p>For reliable VoIP calls to be routed via this homeserver, you MUST configure
  608. a TURN server. See <a href="setup/../turn-howto.html">TURN setup</a> for details.</p>
  609. <h3 id="url-previews"><a class="header" href="#url-previews">URL previews</a></h3>
  610. <p>Synapse includes support for previewing URLs, which is disabled by default. To
  611. turn it on you must enable the <code>url_preview_enabled: True</code> config parameter
  612. and explicitly specify the IP ranges that Synapse is not allowed to spider for
  613. previewing in the <code>url_preview_ip_range_blacklist</code> configuration parameter.
  614. This is critical from a security perspective to stop arbitrary Matrix users
  615. spidering 'internal' URLs on your network. At the very least we recommend that
  616. your loopback and RFC1918 IP addresses are blacklisted.</p>
  617. <p>This also requires the optional <code>lxml</code> python dependency to be installed. This
  618. in turn requires the <code>libxml2</code> library to be available - on Debian/Ubuntu this
  619. means <code>apt-get install libxml2-dev</code>, or equivalent for your OS.</p>
  620. <h3 id="troubleshooting-installation"><a class="header" href="#troubleshooting-installation">Troubleshooting Installation</a></h3>
  621. <p><code>pip</code> seems to leak <em>lots</em> of memory during installation. For instance, a Linux
  622. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  623. happens, you will have to individually install the dependencies which are
  624. failing, e.g.:</p>
  625. <pre><code class="language-sh">pip install twisted
  626. </code></pre>
  627. <p>If you have any other problems, feel free to ask in
  628. <a href="https://matrix.to/#/#synapse:matrix.org">#synapse:matrix.org</a>.</p>
  629. <div style="break-before: page; page-break-before: always;"></div><h1 id="using-postgres"><a class="header" href="#using-postgres">Using Postgres</a></h1>
  630. <p>Synapse supports PostgreSQL versions 9.6 or later.</p>
  631. <h2 id="install-postgres-client-libraries"><a class="header" href="#install-postgres-client-libraries">Install postgres client libraries</a></h2>
  632. <p>Synapse will require the python postgres client library in order to
  633. connect to a postgres database.</p>
  634. <ul>
  635. <li>
  636. <p>If you are using the <a href="setup/installation.html#matrixorg-packages">matrix.org debian/ubuntu
  637. packages</a>, the necessary python
  638. library will already be installed, but you will need to ensure the
  639. low-level postgres library is installed, which you can do with
  640. <code>apt install libpq5</code>.</p>
  641. </li>
  642. <li>
  643. <p>For other pre-built packages, please consult the documentation from
  644. the relevant package.</p>
  645. </li>
  646. <li>
  647. <p>If you installed synapse <a href="setup/installation.html#installing-from-source">in a
  648. virtualenv</a>, you can install
  649. the library with:</p>
  650. <pre><code>~/synapse/env/bin/pip install &quot;matrix-synapse[postgres]&quot;
  651. </code></pre>
  652. <p>(substituting the path to your virtualenv for <code>~/synapse/env</code>, if
  653. you used a different path). You will require the postgres
  654. development files. These are in the <code>libpq-dev</code> package on
  655. Debian-derived distributions.</p>
  656. </li>
  657. </ul>
  658. <h2 id="set-up-database"><a class="header" href="#set-up-database">Set up database</a></h2>
  659. <p>Assuming your PostgreSQL database user is called <code>postgres</code>, first authenticate as the database user with:</p>
  660. <pre><code>su - postgres
  661. # Or, if your system uses sudo to get administrative rights
  662. sudo -u postgres bash
  663. </code></pre>
  664. <p>Then, create a postgres user and a database with:</p>
  665. <pre><code># this will prompt for a password for the new user
  666. createuser --pwprompt synapse_user
  667. createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse
  668. </code></pre>
  669. <p>The above will create a user called <code>synapse_user</code>, and a database called
  670. <code>synapse</code>.</p>
  671. <p>Note that the PostgreSQL database <em>must</em> have the correct encoding set
  672. (as shown above), otherwise it will not be able to store UTF8 strings.</p>
  673. <p>You may need to enable password authentication so <code>synapse_user</code> can
  674. connect to the database. See
  675. <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>
  676. <h2 id="synapse-config"><a class="header" href="#synapse-config">Synapse config</a></h2>
  677. <p>When you are ready to start using PostgreSQL, edit the <code>database</code>
  678. section in your config file to match the following lines:</p>
  679. <pre><code class="language-yaml">database:
  680. name: psycopg2
  681. args:
  682. user: &lt;user&gt;
  683. password: &lt;pass&gt;
  684. database: &lt;db&gt;
  685. host: &lt;host&gt;
  686. cp_min: 5
  687. cp_max: 10
  688. </code></pre>
  689. <p>All key, values in <code>args</code> are passed to the <code>psycopg2.connect(..)</code>
  690. function, except keys beginning with <code>cp_</code>, which are consumed by the
  691. twisted adbapi connection pool. See the <a href="https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS">libpq
  692. documentation</a>
  693. for a list of options which can be passed.</p>
  694. <p>You should consider tuning the <code>args.keepalives_*</code> options if there is any danger of
  695. the connection between your homeserver and database dropping, otherwise Synapse
  696. may block for an extended period while it waits for a response from the
  697. database server. Example values might be:</p>
  698. <pre><code class="language-yaml">database:
  699. args:
  700. # ... as above
  701. # seconds of inactivity after which TCP should send a keepalive message to the server
  702. keepalives_idle: 10
  703. # the number of seconds after which a TCP keepalive message that is not
  704. # acknowledged by the server should be retransmitted
  705. keepalives_interval: 10
  706. # the number of TCP keepalives that can be lost before the client's connection
  707. # to the server is considered dead
  708. keepalives_count: 3
  709. </code></pre>
  710. <h2 id="tuning-postgres"><a class="header" href="#tuning-postgres">Tuning Postgres</a></h2>
  711. <p>The default settings should be fine for most deployments. For larger
  712. scale deployments tuning some of the settings is recommended, details of
  713. which can be found at
  714. <a href="https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server">https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server</a>.</p>
  715. <p>In particular, we've found tuning the following values helpful for
  716. performance:</p>
  717. <ul>
  718. <li><code>shared_buffers</code></li>
  719. <li><code>effective_cache_size</code></li>
  720. <li><code>work_mem</code></li>
  721. <li><code>maintenance_work_mem</code></li>
  722. <li><code>autovacuum_work_mem</code></li>
  723. </ul>
  724. <p>Note that the appropriate values for those fields depend on the amount
  725. of free memory the database host has available.</p>
  726. <h2 id="porting-from-sqlite"><a class="header" href="#porting-from-sqlite">Porting from SQLite</a></h2>
  727. <h3 id="overview"><a class="header" href="#overview">Overview</a></h3>
  728. <p>The script <code>synapse_port_db</code> allows porting an existing synapse server
  729. backed by SQLite to using PostgreSQL. This is done in as a two phase
  730. process:</p>
  731. <ol>
  732. <li>Copy the existing SQLite database to a separate location and run
  733. the port script against that offline database.</li>
  734. <li>Shut down the server. Rerun the port script to port any data that
  735. has come in since taking the first snapshot. Restart server against
  736. the PostgreSQL database.</li>
  737. </ol>
  738. <p>The port script is designed to be run repeatedly against newer snapshots
  739. of the SQLite database file. This makes it safe to repeat step 1 if
  740. there was a delay between taking the previous snapshot and being ready
  741. to do step 2.</p>
  742. <p>It is safe to at any time kill the port script and restart it.</p>
  743. <p>Note that the database may take up significantly more (25% - 100% more)
  744. space on disk after porting to Postgres.</p>
  745. <h3 id="using-the-port-script"><a class="header" href="#using-the-port-script">Using the port script</a></h3>
  746. <p>Firstly, shut down the currently running synapse server and copy its
  747. database file (typically <code>homeserver.db</code>) to another location. Once the
  748. copy is complete, restart synapse. For instance:</p>
  749. <pre><code>./synctl stop
  750. cp homeserver.db homeserver.db.snapshot
  751. ./synctl start
  752. </code></pre>
  753. <p>Copy the old config file into a new config file:</p>
  754. <pre><code>cp homeserver.yaml homeserver-postgres.yaml
  755. </code></pre>
  756. <p>Edit the database section as described in the section <em>Synapse config</em>
  757. above and with the SQLite snapshot located at <code>homeserver.db.snapshot</code>
  758. simply run:</p>
  759. <pre><code>synapse_port_db --sqlite-database homeserver.db.snapshot \
  760. --postgres-config homeserver-postgres.yaml
  761. </code></pre>
  762. <p>The flag <code>--curses</code> displays a coloured curses progress UI.</p>
  763. <p>If the script took a long time to complete, or time has otherwise passed
  764. since the original snapshot was taken, repeat the previous steps with a
  765. newer snapshot.</p>
  766. <p>To complete the conversion shut down the synapse server and run the port
  767. script one last time, e.g. if the SQLite database is at <code>homeserver.db</code>
  768. run:</p>
  769. <pre><code>synapse_port_db --sqlite-database homeserver.db \
  770. --postgres-config homeserver-postgres.yaml
  771. </code></pre>
  772. <p>Once that has completed, change the synapse config to point at the
  773. PostgreSQL database configuration file <code>homeserver-postgres.yaml</code>:</p>
  774. <pre><code>./synctl stop
  775. mv homeserver.yaml homeserver-old-sqlite.yaml
  776. mv homeserver-postgres.yaml homeserver.yaml
  777. ./synctl start
  778. </code></pre>
  779. <p>Synapse should now be running against PostgreSQL.</p>
  780. <h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
  781. <h3 id="alternative-auth-methods"><a class="header" href="#alternative-auth-methods">Alternative auth methods</a></h3>
  782. <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
  783. <code>ident</code>:</p>
  784. <ul>
  785. <li>
  786. <p>If the <code>synapse_user</code> user has a password, add the password to the <code>database:</code>
  787. section of <code>homeserver.yaml</code>. Then add the following to <code>pg_hba.conf</code>:</p>
  788. <pre><code>host synapse synapse_user ::1/128 md5 # or `scram-sha-256` instead of `md5` if you use that
  789. </code></pre>
  790. </li>
  791. <li>
  792. <p>If the <code>synapse_user</code> user does not have a password, then a password doesn't
  793. have to be added to <code>homeserver.yaml</code>. But the following does need to be added
  794. to <code>pg_hba.conf</code>:</p>
  795. <pre><code>host synapse synapse_user ::1/128 trust
  796. </code></pre>
  797. </li>
  798. </ul>
  799. <p>Note that line order matters in <code>pg_hba.conf</code>, so make sure that if you do add a
  800. new line, it is inserted before:</p>
  801. <pre><code>host all all ::1/128 ident
  802. </code></pre>
  803. <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>
  804. <p>Synapse will refuse to set up a new database if it has the wrong values of
  805. <code>COLLATE</code> and <code>CTYPE</code> set, and will log warnings on existing databases. Using
  806. different locales can cause issues if the locale library is updated from
  807. underneath the database, or if a different version of the locale is used on any
  808. replicas.</p>
  809. <p>The safest way to fix the issue is to dump the database and recreate it with
  810. the correct locale parameter (as shown above). It is also possible to change the
  811. parameters on a live database and run a <code>REINDEX</code> on the entire database,
  812. however extreme care must be taken to avoid database corruption.</p>
  813. <p>Note that the above may fail with an error about duplicate rows if corruption
  814. has already occurred, and such duplicate rows will need to be manually removed.</p>
  815. <h3 id="fixing-inconsistent-sequences-error"><a class="header" href="#fixing-inconsistent-sequences-error">Fixing inconsistent sequences error</a></h3>
  816. <p>Synapse uses Postgres sequences to generate IDs for various tables. A sequence
  817. and associated table can get out of sync if, for example, Synapse has been
  818. downgraded and then upgraded again.</p>
  819. <p>To fix the issue shut down Synapse (including any and all workers) and run the
  820. SQL command included in the error message. Once done Synapse should start
  821. successfully.</p>
  822. <div style="break-before: page; page-break-before: always;"></div><h1 id="using-a-reverse-proxy-with-synapse"><a class="header" href="#using-a-reverse-proxy-with-synapse">Using a reverse proxy with Synapse</a></h1>
  823. <p>It is recommended to put a reverse proxy such as
  824. <a href="https://nginx.org/en/docs/http/ngx_http_proxy_module.html">nginx</a>,
  825. <a href="https://httpd.apache.org/docs/current/mod/mod_proxy_http.html">Apache</a>,
  826. <a href="https://caddyserver.com/docs/quick-starts/reverse-proxy">Caddy</a>,
  827. <a href="https://www.haproxy.org/">HAProxy</a> or
  828. <a href="https://man.openbsd.org/relayd.8">relayd</a> in front of Synapse. One advantage
  829. of doing so is that it means that you can expose the default https port
  830. (443) to Matrix clients without needing to run Synapse with root
  831. privileges.</p>
  832. <p>You should configure your reverse proxy to forward requests to <code>/_matrix</code> or
  833. <code>/_synapse/client</code> to Synapse, and have it set the <code>X-Forwarded-For</code> and
  834. <code>X-Forwarded-Proto</code> request headers.</p>
  835. <p>You should remember that Matrix clients and other Matrix servers do not
  836. necessarily need to connect to your server via the same server name or
  837. port. Indeed, clients will use port 443 by default, whereas servers default to
  838. port 8448. Where these are different, we refer to the 'client port' and the
  839. 'federation port'. See <a href="https://matrix.org/docs/spec/server_server/latest#resolving-server-names">the Matrix
  840. specification</a>
  841. for more details of the algorithm used for federation connections, and
  842. <a href="delegate.html">Delegation</a> for instructions on setting up delegation.</p>
  843. <p><strong>NOTE</strong>: Your reverse proxy must not <code>canonicalise</code> or <code>normalise</code>
  844. the requested URI in any way (for example, by decoding <code>%xx</code> escapes).
  845. Beware that Apache <em>will</em> canonicalise URIs unless you specify
  846. <code>nocanon</code>.</p>
  847. <p>Let's assume that we expect clients to connect to our server at
  848. <code>https://matrix.example.com</code>, and other servers to connect at
  849. <code>https://example.com:8448</code>. The following sections detail the configuration of
  850. the reverse proxy and the homeserver.</p>
  851. <h2 id="homeserver-configuration"><a class="header" href="#homeserver-configuration">Homeserver Configuration</a></h2>
  852. <p>The HTTP configuration will need to be updated for Synapse to correctly record
  853. client IP addresses and generate redirect URLs while behind a reverse proxy. </p>
  854. <p>In <code>homeserver.yaml</code> set <code>x_forwarded: true</code> in the port 8008 section and
  855. consider setting <code>bind_addresses: ['127.0.0.1']</code> so that the server only
  856. listens to traffic on localhost. (Do not change <code>bind_addresses</code> to <code>127.0.0.1</code>
  857. when using a containerized Synapse, as that will prevent it from responding
  858. to proxied traffic.)</p>
  859. <h2 id="reverse-proxy-configuration-examples"><a class="header" href="#reverse-proxy-configuration-examples">Reverse-proxy configuration examples</a></h2>
  860. <p><strong>NOTE</strong>: You only need one of these.</p>
  861. <h3 id="nginx"><a class="header" href="#nginx">nginx</a></h3>
  862. <pre><code>server {
  863. listen 443 ssl http2;
  864. listen [::]:443 ssl http2;
  865. # For the federation port
  866. listen 8448 ssl http2 default_server;
  867. listen [::]:8448 ssl http2 default_server;
  868. server_name matrix.example.com;
  869. location ~* ^(\/_matrix|\/_synapse\/client) {
  870. # note: do not add a path (even a single /) after the port in `proxy_pass`,
  871. # otherwise nginx will canonicalise the URI and cause signature verification
  872. # errors.
  873. proxy_pass http://localhost:8008;
  874. proxy_set_header X-Forwarded-For $remote_addr;
  875. proxy_set_header X-Forwarded-Proto $scheme;
  876. proxy_set_header Host $host;
  877. # Nginx by default only allows file uploads up to 1M in size
  878. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  879. client_max_body_size 50M;
  880. }
  881. }
  882. </code></pre>
  883. <h3 id="caddy-v1"><a class="header" href="#caddy-v1">Caddy v1</a></h3>
  884. <pre><code>matrix.example.com {
  885. proxy /_matrix http://localhost:8008 {
  886. transparent
  887. }
  888. proxy /_synapse/client http://localhost:8008 {
  889. transparent
  890. }
  891. }
  892. example.com:8448 {
  893. proxy / http://localhost:8008 {
  894. transparent
  895. }
  896. }
  897. </code></pre>
  898. <h3 id="caddy-v2"><a class="header" href="#caddy-v2">Caddy v2</a></h3>
  899. <pre><code>matrix.example.com {
  900. reverse_proxy /_matrix/* http://localhost:8008
  901. reverse_proxy /_synapse/client/* http://localhost:8008
  902. }
  903. example.com:8448 {
  904. reverse_proxy http://localhost:8008
  905. }
  906. </code></pre>
  907. <p><a href="delegate.html">Delegation</a> example:</p>
  908. <pre><code>(matrix-well-known-header) {
  909. # Headers
  910. header Access-Control-Allow-Origin &quot;*&quot;
  911. header Access-Control-Allow-Methods &quot;GET, POST, PUT, DELETE, OPTIONS&quot;
  912. header Access-Control-Allow-Headers &quot;Origin, X-Requested-With, Content-Type, Accept, Authorization&quot;
  913. header Content-Type &quot;application/json&quot;
  914. }
  915. example.com {
  916. handle /.well-known/matrix/server {
  917. import matrix-well-known-header
  918. respond `{&quot;m.server&quot;:&quot;matrix.example.com:443&quot;}`
  919. }
  920. handle /.well-known/matrix/client {
  921. import matrix-well-known-header
  922. respond `{&quot;m.homeserver&quot;:{&quot;base_url&quot;:&quot;https://matrix.example.com&quot;},&quot;m.identity_server&quot;:{&quot;base_url&quot;:&quot;https://identity.example.com&quot;}}`
  923. }
  924. }
  925. matrix.example.com {
  926. reverse_proxy /_matrix/* http://localhost:8008
  927. reverse_proxy /_synapse/client/* http://localhost:8008
  928. }
  929. </code></pre>
  930. <h3 id="apache"><a class="header" href="#apache">Apache</a></h3>
  931. <pre><code>&lt;VirtualHost *:443&gt;
  932. SSLEngine on
  933. ServerName matrix.example.com
  934. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  935. AllowEncodedSlashes NoDecode
  936. ProxyPreserveHost on
  937. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  938. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  939. ProxyPass /_synapse/client http://127.0.0.1:8008/_synapse/client nocanon
  940. ProxyPassReverse /_synapse/client http://127.0.0.1:8008/_synapse/client
  941. &lt;/VirtualHost&gt;
  942. &lt;VirtualHost *:8448&gt;
  943. SSLEngine on
  944. ServerName example.com
  945. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  946. AllowEncodedSlashes NoDecode
  947. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  948. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  949. &lt;/VirtualHost&gt;
  950. </code></pre>
  951. <p><strong>NOTE</strong>: ensure the <code>nocanon</code> options are included.</p>
  952. <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>
  953. <pre><code>&lt;IfModule security2_module&gt;
  954. SecRuleEngine off
  955. &lt;/IfModule&gt;
  956. </code></pre>
  957. <p><strong>NOTE 3</strong>: Missing <code>ProxyPreserveHost on</code> can lead to a redirect loop.</p>
  958. <h3 id="haproxy"><a class="header" href="#haproxy">HAProxy</a></h3>
  959. <pre><code>frontend https
  960. bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
  961. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  962. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  963. http-request set-header X-Forwarded-For %[src]
  964. # Matrix client traffic
  965. acl matrix-host hdr(host) -i matrix.example.com
  966. acl matrix-path path_beg /_matrix
  967. acl matrix-path path_beg /_synapse/client
  968. use_backend matrix if matrix-host matrix-path
  969. frontend matrix-federation
  970. bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
  971. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  972. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  973. http-request set-header X-Forwarded-For %[src]
  974. default_backend matrix
  975. backend matrix
  976. server matrix 127.0.0.1:8008
  977. </code></pre>
  978. <h3 id="relayd"><a class="header" href="#relayd">Relayd</a></h3>
  979. <pre><code>table &lt;webserver&gt; { 127.0.0.1 }
  980. table &lt;matrixserver&gt; { 127.0.0.1 }
  981. http protocol &quot;https&quot; {
  982. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  983. tls keypair &quot;example.com&quot;
  984. match header set &quot;X-Forwarded-For&quot; value &quot;$REMOTE_ADDR&quot;
  985. match header set &quot;X-Forwarded-Proto&quot; value &quot;https&quot;
  986. # set CORS header for .well-known/matrix/server, .well-known/matrix/client
  987. # httpd does not support setting headers, so do it here
  988. match request path &quot;/.well-known/matrix/*&quot; tag &quot;matrix-cors&quot;
  989. match response tagged &quot;matrix-cors&quot; header set &quot;Access-Control-Allow-Origin&quot; value &quot;*&quot;
  990. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  991. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  992. # pass on non-matrix traffic to webserver
  993. pass forward to &lt;webserver&gt;
  994. }
  995. relay &quot;https_traffic&quot; {
  996. listen on egress port 443 tls
  997. protocol &quot;https&quot;
  998. forward to &lt;matrixserver&gt; port 8008 check tcp
  999. forward to &lt;webserver&gt; port 8080 check tcp
  1000. }
  1001. http protocol &quot;matrix&quot; {
  1002. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  1003. tls keypair &quot;example.com&quot;
  1004. block
  1005. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  1006. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  1007. }
  1008. relay &quot;matrix_federation&quot; {
  1009. listen on egress port 8448 tls
  1010. protocol &quot;matrix&quot;
  1011. forward to &lt;matrixserver&gt; port 8008 check tcp
  1012. }
  1013. </code></pre>
  1014. <h2 id="health-check-endpoint"><a class="header" href="#health-check-endpoint">Health check endpoint</a></h2>
  1015. <p>Synapse exposes a health check endpoint for use by reverse proxies.
  1016. Each configured HTTP listener has a <code>/health</code> endpoint which always returns
  1017. 200 OK (and doesn't get logged).</p>
  1018. <h2 id="synapse-administration-endpoints"><a class="header" href="#synapse-administration-endpoints">Synapse administration endpoints</a></h2>
  1019. <p>Endpoints for administering your Synapse instance are placed under
  1020. <code>/_synapse/admin</code>. These require authentication through an access token of an
  1021. admin user. However as access to these endpoints grants the caller a lot of power,
  1022. we do not recommend exposing them to the public internet without good reason.</p>
  1023. <div style="break-before: page; page-break-before: always;"></div><h1 id="using-a-forward-proxy-with-synapse"><a class="header" href="#using-a-forward-proxy-with-synapse">Using a forward proxy with Synapse</a></h1>
  1024. <p>You can use Synapse with a forward or outbound proxy. An example of when
  1025. this is necessary is in corporate environments behind a DMZ (demilitarized zone).
  1026. Synapse supports routing outbound HTTP(S) requests via a proxy. Only HTTP(S)
  1027. proxy is supported, not SOCKS proxy or anything else.</p>
  1028. <h2 id="configure"><a class="header" href="#configure">Configure</a></h2>
  1029. <p>The <code>http_proxy</code>, <code>https_proxy</code>, <code>no_proxy</code> environment variables are used to
  1030. specify proxy settings. The environment variable is not case sensitive.</p>
  1031. <ul>
  1032. <li><code>http_proxy</code>: Proxy server to use for HTTP requests.</li>
  1033. <li><code>https_proxy</code>: Proxy server to use for HTTPS requests.</li>
  1034. <li><code>no_proxy</code>: Comma-separated list of hosts, IP addresses, or IP ranges in CIDR
  1035. format which should not use the proxy. Synapse will directly connect to these hosts.</li>
  1036. </ul>
  1037. <p>The <code>http_proxy</code> and <code>https_proxy</code> environment variables have the form: <code>[scheme://][&lt;username&gt;:&lt;password&gt;@]&lt;host&gt;[:&lt;port&gt;]</code></p>
  1038. <ul>
  1039. <li>
  1040. <p>Supported schemes are <code>http://</code> and <code>https://</code>. The default scheme is <code>http://</code>
  1041. for compatibility reasons; it is recommended to set a scheme. If scheme is set
  1042. to <code>https://</code> the connection uses TLS between Synapse and the proxy.</p>
  1043. <p><strong>NOTE</strong>: Synapse validates the certificates. If the certificate is not
  1044. valid, then the connection is dropped.</p>
  1045. </li>
  1046. <li>
  1047. <p>Default port if not given is <code>1080</code>.</p>
  1048. </li>
  1049. <li>
  1050. <p>Username and password are optional and will be used to authenticate against
  1051. the proxy.</p>
  1052. </li>
  1053. </ul>
  1054. <p><strong>Examples</strong></p>
  1055. <ul>
  1056. <li>HTTP_PROXY=http://USERNAME:PASSWORD@10.0.1.1:8080/</li>
  1057. <li>HTTPS_PROXY=http://USERNAME:PASSWORD@proxy.example.com:8080/</li>
  1058. <li>NO_PROXY=master.hostname.example.com,10.1.0.0/16,172.30.0.0/16</li>
  1059. </ul>
  1060. <p><strong>NOTE</strong>:
  1061. Synapse does not apply the IP blacklist to connections through the proxy (since
  1062. the DNS resolution is done by the proxy). It is expected that the proxy or firewall
  1063. will apply blacklisting of IP addresses.</p>
  1064. <h2 id="connection-types"><a class="header" href="#connection-types">Connection types</a></h2>
  1065. <p>The proxy will be <strong>used</strong> for:</p>
  1066. <ul>
  1067. <li>push</li>
  1068. <li>url previews</li>
  1069. <li>phone-home stats</li>
  1070. <li>recaptcha validation</li>
  1071. <li>CAS auth validation</li>
  1072. <li>OpenID Connect</li>
  1073. <li>Outbound federation</li>
  1074. <li>Federation (checking public key revocation)</li>
  1075. <li>Fetching public keys of other servers</li>
  1076. <li>Downloading remote media</li>
  1077. </ul>
  1078. <p>It will <strong>not be used</strong> for:</p>
  1079. <ul>
  1080. <li>Application Services</li>
  1081. <li>Identity servers</li>
  1082. <li>In worker configurations
  1083. <ul>
  1084. <li>connections between workers</li>
  1085. <li>connections from workers to Redis</li>
  1086. </ul>
  1087. </li>
  1088. </ul>
  1089. <h2 id="troubleshooting-1"><a class="header" href="#troubleshooting-1">Troubleshooting</a></h2>
  1090. <p>If a proxy server is used with TLS (HTTPS) and no connections are established,
  1091. it is most likely due to the proxy's certificates. To test this, the validation
  1092. in Synapse can be deactivated.</p>
  1093. <p><strong>NOTE</strong>: This has an impact on security and is for testing purposes only!</p>
  1094. <p>To deactivate the certificate validation, the following setting must be made in
  1095. <a href="setup/../usage/configuration/homeserver_sample_config.html">homserver.yaml</a>.</p>
  1096. <pre><code class="language-yaml">use_insecure_ssl_client_just_for_testing_do_not_use: true
  1097. </code></pre>
  1098. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-1"><a class="header" href="#overview-1">Overview</a></h1>
  1099. <p>This document explains how to enable VoIP relaying on your Home Server with
  1100. TURN.</p>
  1101. <p>The synapse Matrix Home Server supports integration with TURN server via the
  1102. <a href="https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00">TURN server REST API</a>. This
  1103. allows the Home Server to generate credentials that are valid for use on the
  1104. TURN server through the use of a secret shared between the Home Server and the
  1105. TURN server.</p>
  1106. <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>
  1107. <h2 id="requirements"><a class="header" href="#requirements">Requirements</a></h2>
  1108. <p>For TURN relaying with <code>coturn</code> to work, it must be hosted on a server/endpoint with a public IP.</p>
  1109. <p>Hosting TURN behind a NAT (even with appropriate port forwarding) is known to cause issues
  1110. and to often not work.</p>
  1111. <h2 id="coturn-setup"><a class="header" href="#coturn-setup"><code>coturn</code> setup</a></h2>
  1112. <h3 id="initial-installation"><a class="header" href="#initial-installation">Initial installation</a></h3>
  1113. <p>The TURN daemon <code>coturn</code> is available from a variety of sources such as native package managers, or installation from source.</p>
  1114. <h4 id="debian-installation"><a class="header" href="#debian-installation">Debian installation</a></h4>
  1115. <p>Just install the debian package:</p>
  1116. <pre><code class="language-sh">apt install coturn
  1117. </code></pre>
  1118. <p>This will install and start a systemd service called <code>coturn</code>.</p>
  1119. <h4 id="source-installation"><a class="header" href="#source-installation">Source installation</a></h4>
  1120. <ol>
  1121. <li>
  1122. <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>
  1123. </li>
  1124. <li>
  1125. <p>Configure it:</p>
  1126. <pre><code>./configure
  1127. </code></pre>
  1128. <p>You may need to install <code>libevent2</code>: if so, you should do so in
  1129. the way recommended by your operating system. You can ignore
  1130. warnings about lack of database support: a database is unnecessary
  1131. for this purpose.</p>
  1132. </li>
  1133. <li>
  1134. <p>Build and install it:</p>
  1135. <pre><code>make
  1136. make install
  1137. </code></pre>
  1138. </li>
  1139. </ol>
  1140. <h3 id="configuration"><a class="header" href="#configuration">Configuration</a></h3>
  1141. <ol>
  1142. <li>
  1143. <p>Create or edit the config file in <code>/etc/turnserver.conf</code>. The relevant
  1144. lines, with example values, are:</p>
  1145. <pre><code>use-auth-secret
  1146. static-auth-secret=[your secret key here]
  1147. realm=turn.myserver.org
  1148. </code></pre>
  1149. <p>See <code>turnserver.conf</code> for explanations of the options. One way to generate
  1150. the <code>static-auth-secret</code> is with <code>pwgen</code>:</p>
  1151. <pre><code>pwgen -s 64 1
  1152. </code></pre>
  1153. <p>A <code>realm</code> must be specified, but its value is somewhat arbitrary. (It is
  1154. sent to clients as part of the authentication flow.) It is conventional to
  1155. set it to be your server name.</p>
  1156. </li>
  1157. <li>
  1158. <p>You will most likely want to configure coturn to write logs somewhere. The
  1159. easiest way is normally to send them to the syslog:</p>
  1160. <pre><code>syslog
  1161. </code></pre>
  1162. <p>(in which case, the logs will be available via <code>journalctl -u coturn</code> on a
  1163. systemd system). Alternatively, coturn can be configured to write to a
  1164. logfile - check the example config file supplied with coturn.</p>
  1165. </li>
  1166. <li>
  1167. <p>Consider your security settings. TURN lets users request a relay which will
  1168. connect to arbitrary IP addresses and ports. The following configuration is
  1169. suggested as a minimum starting point:</p>
  1170. <pre><code># VoIP traffic is all UDP. There is no reason to let users connect to arbitrary TCP endpoints via the relay.
  1171. no-tcp-relay
  1172. # don't let the relay ever try to connect to private IP address ranges within your network (if any)
  1173. # given the turn server is likely behind your firewall, remember to include any privileged public IPs too.
  1174. denied-peer-ip=10.0.0.0-10.255.255.255
  1175. denied-peer-ip=192.168.0.0-192.168.255.255
  1176. denied-peer-ip=172.16.0.0-172.31.255.255
  1177. # special case the turn server itself so that client-&gt;TURN-&gt;TURN-&gt;client flows work
  1178. allowed-peer-ip=10.0.0.1
  1179. # consider whether you want to limit the quota of relayed streams per user (or total) to avoid risk of DoS.
  1180. user-quota=12 # 4 streams per video call, so 12 streams = 3 simultaneous relayed calls per user.
  1181. total-quota=1200
  1182. </code></pre>
  1183. </li>
  1184. <li>
  1185. <p>Also consider supporting TLS/DTLS. To do this, add the following settings
  1186. to <code>turnserver.conf</code>:</p>
  1187. <pre><code># TLS certificates, including intermediate certs.
  1188. # For Let's Encrypt certificates, use `fullchain.pem` here.
  1189. cert=/path/to/fullchain.pem
  1190. # TLS private key file
  1191. pkey=/path/to/privkey.pem
  1192. </code></pre>
  1193. <p>In this case, replace the <code>turn:</code> schemes in the <code>turn_uri</code> settings below
  1194. with <code>turns:</code>.</p>
  1195. <p>We recommend that you only try to set up TLS/DTLS once you have set up a
  1196. basic installation and got it working.</p>
  1197. </li>
  1198. <li>
  1199. <p>Ensure your firewall allows traffic into the TURN server on the ports
  1200. you've configured it to listen on (By default: 3478 and 5349 for TURN
  1201. traffic (remember to allow both TCP and UDP traffic), and ports 49152-65535
  1202. for the UDP relay.)</p>
  1203. </li>
  1204. <li>
  1205. <p>We do not recommend running a TURN server behind NAT, and are not aware of
  1206. anyone doing so successfully.</p>
  1207. <p>If you want to try it anyway, you will at least need to tell coturn its
  1208. external IP address:</p>
  1209. <pre><code>external-ip=192.88.99.1
  1210. </code></pre>
  1211. <p>... and your NAT gateway must forward all of the relayed ports directly
  1212. (eg, port 56789 on the external IP must be always be forwarded to port
  1213. 56789 on the internal IP).</p>
  1214. <p>If you get this working, let us know!</p>
  1215. </li>
  1216. <li>
  1217. <p>(Re)start the turn server:</p>
  1218. <ul>
  1219. <li>
  1220. <p>If you used the Debian package (or have set up a systemd unit yourself):</p>
  1221. <pre><code class="language-sh">systemctl restart coturn
  1222. </code></pre>
  1223. </li>
  1224. <li>
  1225. <p>If you installed from source:</p>
  1226. <pre><code class="language-sh">bin/turnserver -o
  1227. </code></pre>
  1228. </li>
  1229. </ul>
  1230. </li>
  1231. </ol>
  1232. <h2 id="synapse-setup"><a class="header" href="#synapse-setup">Synapse setup</a></h2>
  1233. <p>Your home server configuration file needs the following extra keys:</p>
  1234. <ol>
  1235. <li>&quot;<code>turn_uris</code>&quot;: This needs to be a yaml list of public-facing URIs
  1236. for your TURN server to be given out to your clients. Add separate
  1237. entries for each transport your TURN server supports.</li>
  1238. <li>&quot;<code>turn_shared_secret</code>&quot;: This is the secret shared between your
  1239. Home server and your TURN server, so you should set it to the same
  1240. string you used in turnserver.conf.</li>
  1241. <li>&quot;<code>turn_user_lifetime</code>&quot;: This is the amount of time credentials
  1242. generated by your Home Server are valid for (in milliseconds).
  1243. Shorter times offer less potential for abuse at the expense of
  1244. increased traffic between web clients and your home server to
  1245. refresh credentials. The TURN REST API specification recommends
  1246. one day (86400000).</li>
  1247. <li>&quot;<code>turn_allow_guests</code>&quot;: Whether to allow guest users to use the
  1248. TURN server. This is enabled by default, as otherwise VoIP will
  1249. not work reliably for guests. However, it does introduce a
  1250. security risk as it lets guests connect to arbitrary endpoints
  1251. without having gone through a CAPTCHA or similar to register a
  1252. real account.</li>
  1253. </ol>
  1254. <p>As an example, here is the relevant section of the config file for <code>matrix.org</code>. The
  1255. <code>turn_uris</code> are appropriate for TURN servers listening on the default ports, with no TLS.</p>
  1256. <pre><code>turn_uris: [ &quot;turn:turn.matrix.org?transport=udp&quot;, &quot;turn:turn.matrix.org?transport=tcp&quot; ]
  1257. turn_shared_secret: &quot;n0t4ctuAllymatr1Xd0TorgSshar3d5ecret4obvIousreAsons&quot;
  1258. turn_user_lifetime: 86400000
  1259. turn_allow_guests: True
  1260. </code></pre>
  1261. <p>After updating the homeserver configuration, you must restart synapse:</p>
  1262. <ul>
  1263. <li>If you use synctl:
  1264. <pre><code class="language-sh">cd /where/you/run/synapse
  1265. ./synctl restart
  1266. </code></pre>
  1267. </li>
  1268. <li>If you use systemd:
  1269. <pre><code>systemctl restart matrix-synapse.service
  1270. </code></pre>
  1271. </li>
  1272. </ul>
  1273. <p>... and then reload any clients (or wait an hour for them to refresh their
  1274. settings).</p>
  1275. <h2 id="troubleshooting-2"><a class="header" href="#troubleshooting-2">Troubleshooting</a></h2>
  1276. <p>The normal symptoms of a misconfigured TURN server are that calls between
  1277. devices on different networks ring, but get stuck at &quot;call
  1278. connecting&quot;. Unfortunately, troubleshooting this can be tricky.</p>
  1279. <p>Here are a few things to try:</p>
  1280. <ul>
  1281. <li>
  1282. <p>Check that your TURN server is not behind NAT. As above, we're not aware of
  1283. anyone who has successfully set this up.</p>
  1284. </li>
  1285. <li>
  1286. <p>Check that you have opened your firewall to allow TCP and UDP traffic to the
  1287. TURN ports (normally 3478 and 5479).</p>
  1288. </li>
  1289. <li>
  1290. <p>Check that you have opened your firewall to allow UDP traffic to the UDP
  1291. relay ports (49152-65535 by default).</p>
  1292. </li>
  1293. <li>
  1294. <p>Some WebRTC implementations (notably, that of Google Chrome) appear to get
  1295. confused by TURN servers which are reachable over IPv6 (this appears to be
  1296. an unexpected side-effect of its handling of multiple IP addresses as
  1297. defined by
  1298. <a href="https://tools.ietf.org/html/draft-ietf-rtcweb-ip-handling-12"><code>draft-ietf-rtcweb-ip-handling</code></a>).</p>
  1299. <p>Try removing any AAAA records for your TURN server, so that it is only
  1300. reachable over IPv4.</p>
  1301. </li>
  1302. <li>
  1303. <p>Enable more verbose logging in coturn via the <code>verbose</code> setting:</p>
  1304. <pre><code>verbose
  1305. </code></pre>
  1306. <p>... and then see if there are any clues in its logs.</p>
  1307. </li>
  1308. <li>
  1309. <p>If you are using a browser-based client under Chrome, check
  1310. <code>chrome://webrtc-internals/</code> for insights into the internals of the
  1311. negotiation. On Firefox, check the &quot;Connection Log&quot; on <code>about:webrtc</code>.</p>
  1312. <p>(Understanding the output is beyond the scope of this document!)</p>
  1313. </li>
  1314. <li>
  1315. <p>You can test your Matrix homeserver TURN setup with https://test.voip.librepush.net/.
  1316. Note that this test is not fully reliable yet, so don't be discouraged if
  1317. the test fails.
  1318. <a href="https://github.com/matrix-org/voip-tester">Here</a> is the github repo of the
  1319. source of the tester, where you can file bug reports.</p>
  1320. </li>
  1321. <li>
  1322. <p>There is a WebRTC test tool at
  1323. https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/. To
  1324. use it, you will need a username/password for your TURN server. You can
  1325. either:</p>
  1326. <ul>
  1327. <li>
  1328. <p>look for the <code>GET /_matrix/client/r0/voip/turnServer</code> request made by a
  1329. matrix client to your homeserver in your browser's network inspector. In
  1330. the response you should see <code>username</code> and <code>password</code>. Or:</p>
  1331. </li>
  1332. <li>
  1333. <p>Use the following shell commands:</p>
  1334. <pre><code class="language-sh">secret=staticAuthSecretHere
  1335. u=$((`date +%s` + 3600)):test
  1336. p=$(echo -n $u | openssl dgst -hmac $secret -sha1 -binary | base64)
  1337. echo -e &quot;username: $u\npassword: $p&quot;
  1338. </code></pre>
  1339. <p>Or:</p>
  1340. </li>
  1341. <li>
  1342. <p>Temporarily configure coturn to accept a static username/password. To do
  1343. this, comment out <code>use-auth-secret</code> and <code>static-auth-secret</code> and add the
  1344. following:</p>
  1345. <pre><code>lt-cred-mech
  1346. user=username:password
  1347. </code></pre>
  1348. <p><strong>Note</strong>: these settings will not take effect unless <code>use-auth-secret</code>
  1349. and <code>static-auth-secret</code> are disabled.</p>
  1350. <p>Restart coturn after changing the configuration file.</p>
  1351. <p>Remember to restore the original settings to go back to testing with
  1352. Matrix clients!</p>
  1353. </li>
  1354. </ul>
  1355. <p>If the TURN server is working correctly, you should see at least one <code>relay</code>
  1356. entry in the results.</p>
  1357. </li>
  1358. </ul>
  1359. <div style="break-before: page; page-break-before: always;"></div><h1 id="delegation"><a class="header" href="#delegation">Delegation</a></h1>
  1360. <p>By default, other homeservers will expect to be able to reach yours via
  1361. your <code>server_name</code>, on port 8448. For example, if you set your <code>server_name</code>
  1362. to <code>example.com</code> (so that your user names look like <code>@user:example.com</code>),
  1363. other servers will try to connect to yours at <code>https://example.com:8448/</code>.</p>
  1364. <p>Delegation is a Matrix feature allowing a homeserver admin to retain a
  1365. <code>server_name</code> of <code>example.com</code> so that user IDs, room aliases, etc continue
  1366. to look like <code>*:example.com</code>, whilst having federation traffic routed
  1367. to a different server and/or port (e.g. <code>synapse.example.com:443</code>).</p>
  1368. <h2 id="well-known-delegation"><a class="header" href="#well-known-delegation">.well-known delegation</a></h2>
  1369. <p>To use this method, you need to be able to alter the
  1370. <code>server_name</code> 's https server to serve the <code>/.well-known/matrix/server</code>
  1371. URL. Having an active server (with a valid TLS certificate) serving your
  1372. <code>server_name</code> domain is out of the scope of this documentation.</p>
  1373. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> should
  1374. return a JSON structure containing the key <code>m.server</code> like so:</p>
  1375. <pre><code class="language-json">{
  1376. &quot;m.server&quot;: &quot;&lt;synapse.server.name&gt;[:&lt;yourport&gt;]&quot;
  1377. }
  1378. </code></pre>
  1379. <p>In our example, this would mean that URL <code>https://example.com/.well-known/matrix/server</code>
  1380. should return:</p>
  1381. <pre><code class="language-json">{
  1382. &quot;m.server&quot;: &quot;synapse.example.com:443&quot;
  1383. }
  1384. </code></pre>
  1385. <p>Note, specifying a port is optional. If no port is specified, then it defaults
  1386. to 8448.</p>
  1387. <p>With .well-known delegation, federating servers will check for a valid TLS
  1388. certificate for the delegated hostname (in our example: <code>synapse.example.com</code>).</p>
  1389. <h2 id="srv-dns-record-delegation"><a class="header" href="#srv-dns-record-delegation">SRV DNS record delegation</a></h2>
  1390. <p>It is also possible to do delegation using a SRV DNS record. However, that is
  1391. considered an advanced topic since it's a bit complex to set up, and <code>.well-known</code>
  1392. delegation is already enough in most cases.</p>
  1393. <p>However, if you really need it, you can find some documentation on how such a
  1394. 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
  1395. specification</a>.</p>
  1396. <h2 id="delegation-faq"><a class="header" href="#delegation-faq">Delegation FAQ</a></h2>
  1397. <h3 id="when-do-i-need-delegation"><a class="header" href="#when-do-i-need-delegation">When do I need delegation?</a></h3>
  1398. <p>If your homeserver's APIs are accessible on the default federation port (8448)
  1399. and the domain your <code>server_name</code> points to, you do not need any delegation.</p>
  1400. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  1401. fresh server, you could install Synapse on that host, giving it a <code>server_name</code>
  1402. of <code>example.com</code>, and once a reverse proxy has been set up to proxy all requests
  1403. sent to the port <code>8448</code> and serve TLS certificates for <code>example.com</code>, you
  1404. wouldn't need any delegation set up.</p>
  1405. <p><strong>However</strong>, if your homeserver's APIs aren't accessible on port 8448 and on the
  1406. domain <code>server_name</code> points to, you will need to let other servers know how to
  1407. find it using delegation.</p>
  1408. <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>
  1409. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  1410. find it easier to direct federation traffic to a reverse proxy and manage their
  1411. own TLS certificates, and this is a supported configuration.</p>
  1412. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  1413. reverse proxy.</p>
  1414. <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>
  1415. <p>This is no longer necessary. If you are using a reverse proxy for all of your
  1416. TLS traffic, then you can set <code>no_tls: True</code> in the Synapse config.</p>
  1417. <p>In that case, the only reason Synapse needs the certificate is to populate a legacy
  1418. <code>tls_fingerprints</code> field in the federation API. This is ignored by Synapse 0.99.0
  1419. and later, and the only time pre-0.99 Synapses will check it is when attempting to
  1420. fetch the server keys - and generally this is delegated via <code>matrix.org</code>, which
  1421. is running a modern version of Synapse.</p>
  1422. <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>
  1423. <p>No. There is nothing stopping you from using different certificates,
  1424. particularly if you are using a reverse proxy.</p>
  1425. <div style="break-before: page; page-break-before: always;"></div><h1 id="upgrading-synapse"><a class="header" href="#upgrading-synapse">Upgrading Synapse</a></h1>
  1426. <p>Before upgrading check if any special steps are required to upgrade from
  1427. the version you currently have installed to the current version of
  1428. Synapse. The extra instructions that may be required are listed later in
  1429. this document.</p>
  1430. <ul>
  1431. <li>
  1432. <p>Check that your versions of Python and PostgreSQL are still
  1433. supported.</p>
  1434. <p>Synapse follows upstream lifecycles for <a href="https://endoflife.date/python">Python</a> and
  1435. <a href="https://endoflife.date/postgresql">PostgreSQL</a>, and removes support for versions
  1436. which are no longer maintained.</p>
  1437. <p>The website <a href="https://endoflife.date">https://endoflife.date</a> also offers convenient
  1438. summaries.</p>
  1439. </li>
  1440. <li>
  1441. <p>If Synapse was installed using <a href="setup/installation.html#prebuilt-packages">prebuilt
  1442. packages</a>, you will need to follow the
  1443. normal process for upgrading those packages.</p>
  1444. </li>
  1445. <li>
  1446. <p>If Synapse was installed from source, then:</p>
  1447. <ol>
  1448. <li>
  1449. <p>Activate the virtualenv before upgrading. For example, if
  1450. Synapse is installed in a virtualenv in <code>~/synapse/env</code> then
  1451. run:</p>
  1452. <pre><code class="language-bash">source ~/synapse/env/bin/activate
  1453. </code></pre>
  1454. </li>
  1455. <li>
  1456. <p>If Synapse was installed using pip then upgrade to the latest
  1457. version by running:</p>
  1458. <pre><code class="language-bash">pip install --upgrade matrix-synapse
  1459. </code></pre>
  1460. <p>If Synapse was installed using git then upgrade to the latest
  1461. version by running:</p>
  1462. <pre><code class="language-bash">git pull
  1463. pip install --upgrade .
  1464. </code></pre>
  1465. </li>
  1466. <li>
  1467. <p>Restart Synapse:</p>
  1468. <pre><code class="language-bash">./synctl restart
  1469. </code></pre>
  1470. </li>
  1471. </ol>
  1472. </li>
  1473. </ul>
  1474. <p>To check whether your update was successful, you can check the running
  1475. server version with:</p>
  1476. <pre><code class="language-bash"># you may need to replace 'localhost:8008' if synapse is not configured
  1477. # to listen on port 8008.
  1478. curl http://localhost:8008/_synapse/admin/v1/server_version
  1479. </code></pre>
  1480. <h2 id="rolling-back-to-older-versions"><a class="header" href="#rolling-back-to-older-versions">Rolling back to older versions</a></h2>
  1481. <p>Rolling back to previous releases can be difficult, due to database
  1482. schema changes between releases. Where we have been able to test the
  1483. rollback process, this will be noted below.</p>
  1484. <p>In general, you will need to undo any changes made during the upgrade
  1485. process, for example:</p>
  1486. <ul>
  1487. <li>
  1488. <p>pip:</p>
  1489. <pre><code class="language-bash">source env/bin/activate
  1490. # replace `1.3.0` accordingly:
  1491. pip install matrix-synapse==1.3.0
  1492. </code></pre>
  1493. </li>
  1494. <li>
  1495. <p>Debian:</p>
  1496. <pre><code class="language-bash"># replace `1.3.0` and `stretch` accordingly:
  1497. wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1498. dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1499. </code></pre>
  1500. </li>
  1501. </ul>
  1502. <h1 id="upgrading-to-v1450"><a class="header" href="#upgrading-to-v1450">Upgrading to v1.45.0</a></h1>
  1503. <h2 id="changes-required-to-media-storage-provider-modules-when-reading-from-the-synapse-configuration-object"><a class="header" href="#changes-required-to-media-storage-provider-modules-when-reading-from-the-synapse-configuration-object">Changes required to media storage provider modules when reading from the Synapse configuration object</a></h2>
  1504. <p>Media storage provider modules that read from the Synapse configuration object (i.e. that
  1505. read the value of <code>hs.config.[...]</code>) now need to specify the configuration section they're
  1506. reading from. This means that if a module reads the value of e.g. <code>hs.config.media_store_path</code>,
  1507. it needs to replace it with <code>hs.config.media.media_store_path</code>.</p>
  1508. <h1 id="upgrading-to-v1440"><a class="header" href="#upgrading-to-v1440">Upgrading to v1.44.0</a></h1>
  1509. <h2 id="the-url-preview-cache-is-no-longer-mirrored-to-storage-providers"><a class="header" href="#the-url-preview-cache-is-no-longer-mirrored-to-storage-providers">The URL preview cache is no longer mirrored to storage providers</a></h2>
  1510. <p>The <code>url_cache/</code> and <code>url_cache_thumbnails/</code> directories in the media store are
  1511. no longer mirrored to storage providers. These two directories can be safely
  1512. deleted from any configured storage providers to reclaim space.</p>
  1513. <h1 id="upgrading-to-v1430"><a class="header" href="#upgrading-to-v1430">Upgrading to v1.43.0</a></h1>
  1514. <h2 id="the-spaces-summary-apis-can-now-be-handled-by-workers"><a class="header" href="#the-spaces-summary-apis-can-now-be-handled-by-workers">The spaces summary APIs can now be handled by workers</a></h2>
  1515. <p>The <a href="https://matrix-org.github.io/synapse/latest/workers.html#available-worker-applications">available worker applications documentation</a>
  1516. has been updated to reflect that calls to the <code>/spaces</code>, <code>/hierarchy</code>, and
  1517. <code>/summary</code> endpoints can now be routed to workers for both client API and
  1518. federation requests.</p>
  1519. <h1 id="upgrading-to-v1420"><a class="header" href="#upgrading-to-v1420">Upgrading to v1.42.0</a></h1>
  1520. <h2 id="removal-of-old-room-admin-api"><a class="header" href="#removal-of-old-room-admin-api">Removal of old Room Admin API</a></h2>
  1521. <p>The following admin APIs were deprecated in <a href="https://github.com/matrix-org/synapse/blob/v1.25.0/CHANGES.md#removal-warning">Synapse 1.25</a>
  1522. (released on 2021-01-13) and have now been removed:</p>
  1523. <ul>
  1524. <li><code>POST /_synapse/admin/v1/purge_room</code></li>
  1525. <li><code>POST /_synapse/admin/v1/shutdown_room/&lt;room_id&gt;</code></li>
  1526. </ul>
  1527. <p>Any scripts still using the above APIs should be converted to use the
  1528. <a href="https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#delete-room-api">Delete Room API</a>.</p>
  1529. <h2 id="user-interactive-authentication-fallback-templates-can-now-display-errors"><a class="header" href="#user-interactive-authentication-fallback-templates-can-now-display-errors">User-interactive authentication fallback templates can now display errors</a></h2>
  1530. <p>This may affect you if you make use of custom HTML templates for the
  1531. <a href="../synapse/res/templates/recaptcha.html">reCAPTCHA</a> or
  1532. <a href="../synapse/res/templates/terms.html">terms</a> fallback pages.</p>
  1533. <p>The template is now provided an <code>error</code> variable if the authentication
  1534. process failed. See the default templates linked above for an example.</p>
  1535. <h2 id="removal-of-out-of-date-email-pushers"><a class="header" href="#removal-of-out-of-date-email-pushers">Removal of out-of-date email pushers</a></h2>
  1536. <p>Users will stop receiving message updates via email for addresses that were
  1537. once, but not still, linked to their account.</p>
  1538. <h1 id="upgrading-to-v1410"><a class="header" href="#upgrading-to-v1410">Upgrading to v1.41.0</a></h1>
  1539. <h2 id="add-support-for-routing-outbound-http-requests-via-a-proxy-for-federation"><a class="header" href="#add-support-for-routing-outbound-http-requests-via-a-proxy-for-federation">Add support for routing outbound HTTP requests via a proxy for federation</a></h2>
  1540. <p>Since Synapse 1.6.0 (2019-11-26) you can set a proxy for outbound HTTP requests via
  1541. http_proxy/https_proxy environment variables. This proxy was set for:</p>
  1542. <ul>
  1543. <li>push</li>
  1544. <li>url previews</li>
  1545. <li>phone-home stats</li>
  1546. <li>recaptcha validation</li>
  1547. <li>CAS auth validation</li>
  1548. <li>OpenID Connect</li>
  1549. <li>Federation (checking public key revocation)</li>
  1550. </ul>
  1551. <p>In this version we have added support for outbound requests for:</p>
  1552. <ul>
  1553. <li>Outbound federation</li>
  1554. <li>Downloading remote media</li>
  1555. <li>Fetching public keys of other servers</li>
  1556. </ul>
  1557. <p>These requests use the same proxy configuration. If you have a proxy configuration we
  1558. recommend to verify the configuration. It may be necessary to adjust the <code>no_proxy</code>
  1559. environment variable.</p>
  1560. <p>See <a href="setup/forward_proxy.html">using a forward proxy with Synapse documentation</a> for
  1561. details.</p>
  1562. <h2 id="deprecation-of-template_dir"><a class="header" href="#deprecation-of-template_dir">Deprecation of <code>template_dir</code></a></h2>
  1563. <p>The <code>template_dir</code> settings in the <code>sso</code>, <code>account_validity</code> and <code>email</code> sections of the
  1564. configuration file are now deprecated. Server admins should use the new
  1565. <code>templates.custom_template_directory</code> setting in the configuration file and use one single
  1566. custom template directory for all aforementioned features. Template file names remain
  1567. unchanged. See <a href="https://matrix-org.github.io/synapse/latest/templates.html">the related documentation</a>
  1568. for more information and examples.</p>
  1569. <p>We plan to remove support for these settings in October 2021.</p>
  1570. <h2 id="_synapseadminv1usersuseridmedia-must-be-handled-by-media-workers"><a class="header" href="#_synapseadminv1usersuseridmedia-must-be-handled-by-media-workers"><code>/_synapse/admin/v1/users/{userId}/media</code> must be handled by media workers</a></h2>
  1571. <p>The <a href="https://matrix-org.github.io/synapse/latest/workers.html#synapseappmedia_repository">media repository worker documentation</a>
  1572. has been updated to reflect that calls to <code>/_synapse/admin/v1/users/{userId}/media</code>
  1573. must now be handled by media repository workers. This is due to the new <code>DELETE</code> method
  1574. of this endpoint modifying the media store.</p>
  1575. <h1 id="upgrading-to-v1390"><a class="header" href="#upgrading-to-v1390">Upgrading to v1.39.0</a></h1>
  1576. <h2 id="deprecation-of-the-current-third-party-rules-module-interface"><a class="header" href="#deprecation-of-the-current-third-party-rules-module-interface">Deprecation of the current third-party rules module interface</a></h2>
  1577. <p>The current third-party rules module interface is deprecated in favour of the new generic
  1578. modules system introduced in Synapse v1.37.0. Authors of third-party rules modules can refer
  1579. to <a href="modules/porting_legacy_module.html">this documentation</a>
  1580. to update their modules. Synapse administrators can refer to <a href="modules/index.html">this documentation</a>
  1581. to update their configuration once the modules they are using have been updated.</p>
  1582. <p>We plan to remove support for the current third-party rules interface in September 2021.</p>
  1583. <h1 id="upgrading-to-v1380"><a class="header" href="#upgrading-to-v1380">Upgrading to v1.38.0</a></h1>
  1584. <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>
  1585. <p>This release includes a database schema update which requires re-indexing one of
  1586. the larger tables in the database, <code>events</code>. This could result in increased
  1587. disk I/O for several hours or days after upgrading while the migration
  1588. completes. Furthermore, because we have to keep the old indexes until the new
  1589. indexes are ready, it could result in a significant, temporary, increase in
  1590. disk space.</p>
  1591. <p>To get a rough idea of the disk space required, check the current size of one
  1592. of the indexes. For example, from a <code>psql</code> shell, run the following sql:</p>
  1593. <pre><code class="language-sql">SELECT pg_size_pretty(pg_relation_size('events_order_room'));
  1594. </code></pre>
  1595. <p>We need to rebuild <strong>four</strong> indexes, so you will need to multiply this result
  1596. by four to give an estimate of the disk space required. For example, on one
  1597. particular server:</p>
  1598. <pre><code>synapse=# select pg_size_pretty(pg_relation_size('events_order_room'));
  1599. pg_size_pretty
  1600. ----------------
  1601. 288 MB
  1602. (1 row)
  1603. </code></pre>
  1604. <p>On this server, it would be wise to ensure that at least 1152MB are free.</p>
  1605. <p>The additional disk space will be freed once the migration completes.</p>
  1606. <p>SQLite databases are unaffected by this change.</p>
  1607. <h1 id="upgrading-to-v1370"><a class="header" href="#upgrading-to-v1370">Upgrading to v1.37.0</a></h1>
  1608. <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>
  1609. <p>The current spam checker interface is deprecated in favour of a new generic modules system.
  1610. Authors of spam checker modules can refer to [this
  1611. documentation](modules/porting_legacy_module.md
  1612. to update their modules. Synapse administrators can refer to <a href="modules/index.html">this
  1613. documentation</a>
  1614. to update their configuration once the modules they are using have been updated.</p>
  1615. <p>We plan to remove support for the current spam checker interface in August 2021.</p>
  1616. <p>More module interfaces will be ported over to this new generic system in future versions
  1617. of Synapse.</p>
  1618. <h1 id="upgrading-to-v1340"><a class="header" href="#upgrading-to-v1340">Upgrading to v1.34.0</a></h1>
  1619. <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>
  1620. <p>The <code>room_invite_state_types</code> configuration setting has been deprecated
  1621. 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
  1622. file</a>.</p>
  1623. <p>If you have set <code>room_invite_state_types</code> to the default value you
  1624. should simply remove it from your configuration file. The default value
  1625. used to be:</p>
  1626. <pre><code class="language-yaml">room_invite_state_types:
  1627. - &quot;m.room.join_rules&quot;
  1628. - &quot;m.room.canonical_alias&quot;
  1629. - &quot;m.room.avatar&quot;
  1630. - &quot;m.room.encryption&quot;
  1631. - &quot;m.room.name&quot;
  1632. </code></pre>
  1633. <p>If you have customised this value, you should remove
  1634. <code>room_invite_state_types</code> and configure <code>room_prejoin_state</code> instead.</p>
  1635. <h1 id="upgrading-to-v1330"><a class="header" href="#upgrading-to-v1330">Upgrading to v1.33.0</a></h1>
  1636. <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>
  1637. <p>This may affect you if you have enabled the account validity feature,
  1638. and have made use of a custom HTML template specified by the
  1639. <code>account_validity.template_dir</code> or
  1640. <code>account_validity.account_renewed_html_path</code> Synapse config options.</p>
  1641. <p>The template can now accept an <code>expiration_ts</code> variable, which
  1642. represents the unix timestamp in milliseconds for the future date of
  1643. 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
  1644. template</a>
  1645. for an example of usage.</p>
  1646. <p>ALso note that a new HTML template, <code>account_previously_renewed.html</code>,
  1647. has been added. This is is shown to users when they attempt to renew
  1648. their account with a valid renewal token that has already been used
  1649. before. The default template contents can been found
  1650. <a href="https://github.com/matrix-org/synapse/blob/release-v1.33.0/synapse/res/templates/account_previously_renewed.html">here</a>,
  1651. and can also accept an <code>expiration_ts</code> variable. This template replaces
  1652. the error message users would previously see upon attempting to use a
  1653. valid renewal token more than once.</p>
  1654. <h1 id="upgrading-to-v1320"><a class="header" href="#upgrading-to-v1320">Upgrading to v1.32.0</a></h1>
  1655. <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>
  1656. <p>This release introduces <a href="https://github.com/matrix-org/synapse/issues/9853">a
  1657. regression</a> that can
  1658. overwhelm connected Prometheus instances. This issue is not present in
  1659. Synapse v1.32.0rc1.</p>
  1660. <p>If you have been affected, please downgrade to 1.31.0. You then may need
  1661. to remove excess writeahead logs in order for Prometheus to recover.
  1662. Instructions for doing so are provided
  1663. <a href="https://github.com/matrix-org/synapse/pull/9854#issuecomment-823472183">here</a>.</p>
  1664. <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>
  1665. <p>In line with our <a href="deprecation_policy.html">deprecation policy</a>,
  1666. we've dropped support for Python 3.5 and PostgreSQL 9.5, as they are no
  1667. longer supported upstream.</p>
  1668. <p>This release of Synapse requires Python 3.6+ and PostgresSQL 9.6+ or
  1669. SQLite 3.22+.</p>
  1670. <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>
  1671. <p>The deprecated v1 &quot;list accounts&quot; admin API
  1672. (<code>GET /_synapse/admin/v1/users/&lt;user_id&gt;</code>) has been removed in this
  1673. version.</p>
  1674. <p>The <a href="admin_api/user_admin_api.html#list-accounts">v2 list accounts API</a>
  1675. has been available since Synapse 1.7.0 (2019-12-13), and is accessible
  1676. under <code>GET /_synapse/admin/v2/users</code>.</p>
  1677. <p>The deprecation of the old endpoint was announced with Synapse 1.28.0
  1678. (released on 2021-02-25).</p>
  1679. <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>
  1680. <p>In compliance with the <a href="https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions">Application Service
  1681. spec</a>,
  1682. Application Services are now required to use the
  1683. <code>m.login.application_service</code> type when registering users via the
  1684. <code>/_matrix/client/r0/register</code> endpoint. This behaviour was deprecated in
  1685. Synapse v1.30.0.</p>
  1686. <p>Please ensure your Application Services are up to date.</p>
  1687. <h1 id="upgrading-to-v1290"><a class="header" href="#upgrading-to-v1290">Upgrading to v1.29.0</a></h1>
  1688. <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>
  1689. <p>When using Synapse with a reverse proxy (in particular, when using the
  1690. <code>x_forwarded</code> option on an HTTP listener), Synapse now
  1691. expects to receive an <code>X-Forwarded-Proto</code> header on incoming
  1692. HTTP requests. If it is not set, Synapse will log a warning on each
  1693. received request.</p>
  1694. <p>To avoid the warning, administrators using a reverse proxy should ensure
  1695. that the reverse proxy sets <code>X-Forwarded-Proto</code> header to
  1696. <code>https</code> or <code>http</code> to indicate the protocol used
  1697. by the client.</p>
  1698. <p>Synapse also requires the <code>Host</code> header to be preserved.</p>
  1699. <p>See the <a href="reverse_proxy.html">reverse proxy documentation</a>, where the
  1700. example configurations have been updated to show how to set these
  1701. headers.</p>
  1702. <p>(Users of <a href="https://caddyserver.com/">Caddy</a> are unaffected, since we
  1703. believe it sets <code>X-Forwarded-Proto</code> by default.)</p>
  1704. <h1 id="upgrading-to-v1270"><a class="header" href="#upgrading-to-v1270">Upgrading to v1.27.0</a></h1>
  1705. <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>
  1706. <p>This version changes the URI used for callbacks from OAuth2 and SAML2
  1707. identity providers:</p>
  1708. <ul>
  1709. <li>
  1710. <p>If your server is configured for single sign-on via an OpenID
  1711. Connect or OAuth2 identity provider, you will need to add
  1712. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> to the list
  1713. of permitted &quot;redirect URIs&quot; at the identity provider.</p>
  1714. <p>See the <a href="openid.html">OpenID docs</a> for more information on setting
  1715. up OpenID Connect.</p>
  1716. </li>
  1717. <li>
  1718. <p>If your server is configured for single sign-on via a SAML2 identity
  1719. provider, you will need to add
  1720. <code>[synapse public baseurl]/_synapse/client/saml2/authn_response</code> as a
  1721. permitted &quot;ACS location&quot; (also known as &quot;allowed callback URLs&quot;)
  1722. at the identity provider.</p>
  1723. <p>The &quot;Issuer&quot; in the &quot;AuthnRequest&quot; to the SAML2 identity
  1724. provider is also updated to
  1725. <code>[synapse public baseurl]/_synapse/client/saml2/metadata.xml</code>. If
  1726. your SAML2 identity provider uses this property to validate or
  1727. otherwise identify Synapse, its configuration will need to be
  1728. updated to use the new URL. Alternatively you could create a new,
  1729. separate &quot;EntityDescriptor&quot; in your SAML2 identity provider with
  1730. the new URLs and leave the URLs in the existing &quot;EntityDescriptor&quot;
  1731. as they were.</p>
  1732. </li>
  1733. </ul>
  1734. <h2 id="changes-to-html-templates"><a class="header" href="#changes-to-html-templates">Changes to HTML templates</a></h2>
  1735. <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
  1736. autoescape</a>
  1737. enabled for files ending in <code>.html</code>, <code>.htm</code>, and <code>.xml</code>. If you have
  1738. customised these templates and see issues when viewing them you might
  1739. need to update them. It is expected that most configurations will need
  1740. no changes.</p>
  1741. <p>If you have customised the templates <em>names</em> for these templates, it is
  1742. recommended to verify they end in <code>.html</code> to ensure autoescape is
  1743. enabled.</p>
  1744. <p>The above applies to the following templates:</p>
  1745. <ul>
  1746. <li><code>add_threepid.html</code></li>
  1747. <li><code>add_threepid_failure.html</code></li>
  1748. <li><code>add_threepid_success.html</code></li>
  1749. <li><code>notice_expiry.html</code></li>
  1750. <li><code>notice_expiry.html</code></li>
  1751. <li><code>notif_mail.html</code> (which, by default, includes <code>room.html</code> and
  1752. <code>notif.html</code>)</li>
  1753. <li><code>password_reset.html</code></li>
  1754. <li><code>password_reset_confirmation.html</code></li>
  1755. <li><code>password_reset_failure.html</code></li>
  1756. <li><code>password_reset_success.html</code></li>
  1757. <li><code>registration.html</code></li>
  1758. <li><code>registration_failure.html</code></li>
  1759. <li><code>registration_success.html</code></li>
  1760. <li><code>sso_account_deactivated.html</code></li>
  1761. <li><code>sso_auth_bad_user.html</code></li>
  1762. <li><code>sso_auth_confirm.html</code></li>
  1763. <li><code>sso_auth_success.html</code></li>
  1764. <li><code>sso_error.html</code></li>
  1765. <li><code>sso_login_idp_picker.html</code></li>
  1766. <li><code>sso_redirect_confirm.html</code></li>
  1767. </ul>
  1768. <h1 id="upgrading-to-v1260"><a class="header" href="#upgrading-to-v1260">Upgrading to v1.26.0</a></h1>
  1769. <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>
  1770. <p>v1.26.0 includes a lot of large changes. If something problematic
  1771. occurs, you may want to roll-back to a previous version of Synapse.
  1772. Because v1.26.0 also includes a new database schema version, reverting
  1773. that version is also required alongside the generic rollback
  1774. instructions mentioned above. In short, to roll back to v1.25.0 you need
  1775. to:</p>
  1776. <ol>
  1777. <li>
  1778. <p>Stop the server</p>
  1779. </li>
  1780. <li>
  1781. <p>Decrease the schema version in the database:</p>
  1782. <pre><code class="language-sql">UPDATE schema_version SET version = 58;
  1783. </code></pre>
  1784. </li>
  1785. <li>
  1786. <p>Delete the ignored users &amp; chain cover data:</p>
  1787. <pre><code class="language-sql">DROP TABLE IF EXISTS ignored_users;
  1788. UPDATE rooms SET has_auth_chain_index = false;
  1789. </code></pre>
  1790. <p>For PostgreSQL run:</p>
  1791. <pre><code class="language-sql">TRUNCATE event_auth_chain_links;
  1792. TRUNCATE event_auth_chains;
  1793. </code></pre>
  1794. <p>For SQLite run:</p>
  1795. <pre><code class="language-sql">DELETE FROM event_auth_chain_links;
  1796. DELETE FROM event_auth_chains;
  1797. </code></pre>
  1798. </li>
  1799. <li>
  1800. <p>Mark the deltas as not run (so they will re-run on upgrade).</p>
  1801. <pre><code class="language-sql">DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/01ignored_user.py&quot;;
  1802. DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/06chain_cover_index.sql&quot;;
  1803. </code></pre>
  1804. </li>
  1805. <li>
  1806. <p>Downgrade Synapse by following the instructions for your
  1807. installation method in the &quot;Rolling back to older versions&quot;
  1808. section above.</p>
  1809. </li>
  1810. </ol>
  1811. <h1 id="upgrading-to-v1250"><a class="header" href="#upgrading-to-v1250">Upgrading to v1.25.0</a></h1>
  1812. <h2 id="last-release-supporting-python-35"><a class="header" href="#last-release-supporting-python-35">Last release supporting Python 3.5</a></h2>
  1813. <p>This is the last release of Synapse which guarantees support with Python
  1814. 3.5, which passed its upstream End of Life date several months ago.</p>
  1815. <p>We will attempt to maintain support through March 2021, but without
  1816. guarantees.</p>
  1817. <p>In the future, Synapse will follow upstream schedules for ending support
  1818. of older versions of Python and PostgreSQL. Please upgrade to at least
  1819. Python 3.6 and PostgreSQL 9.6 as soon as possible.</p>
  1820. <h2 id="blacklisting-ip-ranges"><a class="header" href="#blacklisting-ip-ranges">Blacklisting IP ranges</a></h2>
  1821. <p>Synapse v1.25.0 includes new settings, <code>ip_range_blacklist</code> and
  1822. <code>ip_range_whitelist</code>, for controlling outgoing requests from Synapse for
  1823. federation, identity servers, push, and for checking key validity for
  1824. third-party invite events. The previous setting,
  1825. <code>federation_ip_range_blacklist</code>, is deprecated. The new
  1826. <code>ip_range_blacklist</code> defaults to private IP ranges if it is not defined.</p>
  1827. <p>If you have never customised <code>federation_ip_range_blacklist</code> it is
  1828. recommended that you remove that setting.</p>
  1829. <p>If you have customised <code>federation_ip_range_blacklist</code> you should update
  1830. the setting name to <code>ip_range_blacklist</code>.</p>
  1831. <p>If you have a custom push server that is reached via private IP space
  1832. you may need to customise <code>ip_range_blacklist</code> or <code>ip_range_whitelist</code>.</p>
  1833. <h1 id="upgrading-to-v1240"><a class="header" href="#upgrading-to-v1240">Upgrading to v1.24.0</a></h1>
  1834. <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>
  1835. <p>This release allows the OpenID Connect mapping provider to perform
  1836. normalisation of the localpart of the Matrix ID. This allows for the
  1837. mapping provider to specify different algorithms, instead of the
  1838. <a href="https://matrix.org/docs/spec/appendices#mapping-from-other-character-sets">default
  1839. way</a>.</p>
  1840. <p>If your Synapse configuration uses a custom mapping provider
  1841. (<code>oidc_config.user_mapping_provider.module</code> is specified and
  1842. not equal to
  1843. <code>synapse.handlers.oidc_handler.JinjaOidcMappingProvider</code>)
  1844. then you <em>must</em> ensure that <code>map_user_attributes</code> of the
  1845. mapping provider performs some normalisation of the
  1846. <code>localpart</code> returned. To match previous behaviour you can
  1847. use the <code>map_username_to_mxid_localpart</code> function provided
  1848. by Synapse. An example is shown below:</p>
  1849. <pre><code class="language-python">from synapse.types import map_username_to_mxid_localpart
  1850. class MyMappingProvider:
  1851. def map_user_attributes(self, userinfo, token):
  1852. # ... your custom logic ...
  1853. sso_user_id = ...
  1854. localpart = map_username_to_mxid_localpart(sso_user_id)
  1855. return {&quot;localpart&quot;: localpart}
  1856. </code></pre>
  1857. <h2 id="removal-historical-synapse-admin-api"><a class="header" href="#removal-historical-synapse-admin-api">Removal historical Synapse Admin API</a></h2>
  1858. <p>Historically, the Synapse Admin API has been accessible under:</p>
  1859. <ul>
  1860. <li><code>/_matrix/client/api/v1/admin</code></li>
  1861. <li><code>/_matrix/client/unstable/admin</code></li>
  1862. <li><code>/_matrix/client/r0/admin</code></li>
  1863. <li><code>/_synapse/admin/v1</code></li>
  1864. </ul>
  1865. <p>The endpoints with <code>/_matrix/client/*</code> prefixes have been removed as of
  1866. v1.24.0. The Admin API is now only accessible under:</p>
  1867. <ul>
  1868. <li><code>/_synapse/admin/v1</code></li>
  1869. </ul>
  1870. <p>The only exception is the <code>/admin/whois</code> endpoint, which is
  1871. <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
  1872. API</a>.</p>
  1873. <p>The deprecation of the old endpoints was announced with Synapse 1.20.0
  1874. (released on 2020-09-22) and makes it easier for homeserver admins to
  1875. lock down external access to the Admin API endpoints.</p>
  1876. <h1 id="upgrading-to-v1230"><a class="header" href="#upgrading-to-v1230">Upgrading to v1.23.0</a></h1>
  1877. <h2 id="structured-logging-configuration-breaking-changes"><a class="header" href="#structured-logging-configuration-breaking-changes">Structured logging configuration breaking changes</a></h2>
  1878. <p>This release deprecates use of the <code>structured: true</code> logging
  1879. configuration for structured logging. If your logging configuration
  1880. contains <code>structured: true</code> then it should be modified based on the
  1881. <a href="structured_logging.html">structured logging documentation</a>.</p>
  1882. <p>The <code>structured</code> and <code>drains</code> logging options are now deprecated and
  1883. should be replaced by standard logging configuration of <code>handlers</code> and
  1884. <code>formatters</code>.</p>
  1885. <p>A future will release of Synapse will make using <code>structured: true</code> an
  1886. error.</p>
  1887. <h1 id="upgrading-to-v1220"><a class="header" href="#upgrading-to-v1220">Upgrading to v1.22.0</a></h1>
  1888. <h2 id="thirdpartyeventrules-breaking-changes"><a class="header" href="#thirdpartyeventrules-breaking-changes">ThirdPartyEventRules breaking changes</a></h2>
  1889. <p>This release introduces a backwards-incompatible change to modules
  1890. making use of <code>ThirdPartyEventRules</code> in Synapse. If you make use of a
  1891. module defined under the <code>third_party_event_rules</code> config option, please
  1892. make sure it is updated to handle the below change:</p>
  1893. <p>The <code>http_client</code> argument is no longer passed to modules as they are
  1894. initialised. Instead, modules are expected to make use of the
  1895. <code>http_client</code> property on the <code>ModuleApi</code> class. Modules are now passed
  1896. a <code>module_api</code> argument during initialisation, which is an instance of
  1897. <code>ModuleApi</code>. <code>ModuleApi</code> instances have a <code>http_client</code> property which
  1898. acts the same as the <code>http_client</code> argument previously passed to
  1899. <code>ThirdPartyEventRules</code> modules.</p>
  1900. <h1 id="upgrading-to-v1210"><a class="header" href="#upgrading-to-v1210">Upgrading to v1.21.0</a></h1>
  1901. <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>
  1902. <p>The <a href="reverse_proxy.html">reverse proxy documentation</a>
  1903. has been updated to include reverse proxy directives for
  1904. <code>/_synapse/client/*</code> endpoints. As the user password reset flow now uses
  1905. endpoints under this prefix, <strong>you must update your reverse proxy
  1906. configurations for user password reset to work</strong>.</p>
  1907. <p>Additionally, note that the <a href="workers.html">Synapse worker documentation</a> has been updated to</p>
  1908. <p>: state that the <code>/_synapse/client/password_reset/email/submit_token</code>
  1909. endpoint can be handled</p>
  1910. <p>by all workers. If you make use of Synapse's worker feature, please
  1911. update your reverse proxy configuration to reflect this change.</p>
  1912. <h2 id="new-html-templates"><a class="header" href="#new-html-templates">New HTML templates</a></h2>
  1913. <p>A new HTML template,
  1914. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/res/templates/password_reset_confirmation.html">password_reset_confirmation.html</a>,
  1915. has been added to the <code>synapse/res/templates</code> directory. If you are
  1916. using a custom template directory, you may want to copy the template
  1917. over and modify it.</p>
  1918. <p>Note that as of v1.20.0, templates do not need to be included in custom
  1919. template directories for Synapse to start. The default templates will be
  1920. used if a custom template cannot be found.</p>
  1921. <p>This page will appear to the user after clicking a password reset link
  1922. that has been emailed to them.</p>
  1923. <p>To complete password reset, the page must include a way to make a
  1924. <code>POST</code> request to
  1925. <code>/_synapse/client/password_reset/{medium}/submit_token</code> with the query
  1926. parameters from the original link, presented as a URL-encoded form. See
  1927. the file itself for more details.</p>
  1928. <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>
  1929. <p>The <code>saml_error.html</code> template was removed from Synapse and replaced
  1930. with the <code>sso_error.html</code> template. If your Synapse is configured to use
  1931. SAML and a custom <code>sso_redirect_confirm_template_dir</code> configuration then
  1932. any customisations of the <code>saml_error.html</code> template will need to be
  1933. merged into the <code>sso_error.html</code> template. These templates are similar,
  1934. but the parameters are slightly different:</p>
  1935. <ul>
  1936. <li>The <code>msg</code> parameter should be renamed to <code>error_description</code>.</li>
  1937. <li>There is no longer a <code>code</code> parameter for the response code.</li>
  1938. <li>A string <code>error</code> parameter is available that includes a short hint
  1939. of why a user is seeing the error page.</li>
  1940. </ul>
  1941. <h1 id="upgrading-to-v1180"><a class="header" href="#upgrading-to-v1180">Upgrading to v1.18.0</a></h1>
  1942. <h2 id="docker--py3-suffix-will-be-removed-in-future-versions"><a class="header" href="#docker--py3-suffix-will-be-removed-in-future-versions">Docker <code>-py3</code> suffix will be removed in future versions</a></h2>
  1943. <p>From 10th August 2020, we will no longer publish Docker images with the
  1944. <code>-py3</code> tag suffix. The images tagged with the
  1945. <code>-py3</code> suffix have been identical to the non-suffixed tags
  1946. since release 0.99.0, and the suffix is obsolete.</p>
  1947. <p>On 10th August, we will remove the <code>latest-py3</code> tag.
  1948. Existing per-release tags (such as <code>v1.18.0-py3</code> will not
  1949. be removed, but no new <code>-py3</code> tags will be added.</p>
  1950. <p>Scripts relying on the <code>-py3</code> suffix will need to be
  1951. updated.</p>
  1952. <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>
  1953. <p>When setting up worker processes, we now recommend the use of a Redis
  1954. server for replication. <strong>The old direct TCP connection method is
  1955. deprecated and will be removed in a future release.</strong> See
  1956. <a href="workers.html">workers</a> for more details.</p>
  1957. <h1 id="upgrading-to-v1140"><a class="header" href="#upgrading-to-v1140">Upgrading to v1.14.0</a></h1>
  1958. <p>This version includes a database update which is run as part of the
  1959. upgrade, and which may take a couple of minutes in the case of a large
  1960. server. Synapse will not respond to HTTP requests while this update is
  1961. taking place.</p>
  1962. <h1 id="upgrading-to-v1130"><a class="header" href="#upgrading-to-v1130">Upgrading to v1.13.0</a></h1>
  1963. <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>
  1964. <p>A bug was introduced in Synapse 1.4.0 which could cause the room
  1965. directory to be incomplete or empty if Synapse was upgraded directly
  1966. from v1.2.1 or earlier, to versions between v1.4.0 and v1.12.x.</p>
  1967. <p>This will <em>not</em> be a problem for Synapse installations which were:</p>
  1968. <p>: - created at v1.4.0 or later,
  1969. - upgraded via v1.3.x, or
  1970. - upgraded straight from v1.2.1 or earlier to v1.13.0 or later.</p>
  1971. <p>If completeness of the room directory is a concern, installations which
  1972. are affected can be repaired as follows:</p>
  1973. <ol>
  1974. <li>
  1975. <p>Run the following sql from a <code>psql</code> or
  1976. <code>sqlite3</code> console:</p>
  1977. <pre><code class="language-sql">INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1978. ('populate_stats_process_rooms', '{}', 'current_state_events_membership');
  1979. INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1980. ('populate_stats_process_users', '{}', 'populate_stats_process_rooms');
  1981. </code></pre>
  1982. </li>
  1983. <li>
  1984. <p>Restart synapse.</p>
  1985. </li>
  1986. </ol>
  1987. <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>
  1988. <p>New templates (<code>sso_auth_confirm.html</code>, <code>sso_auth_success.html</code>, and
  1989. <code>sso_account_deactivated.html</code>) were added to Synapse. If your Synapse
  1990. is configured to use SSO and a custom
  1991. <code>sso_redirect_confirm_template_dir</code> configuration then these templates
  1992. will need to be copied from
  1993. <a href="synapse/res/templates">synapse/res/templates</a> into that directory.</p>
  1994. <h2 id="synapse-sso-plugins-method-deprecation"><a class="header" href="#synapse-sso-plugins-method-deprecation">Synapse SSO Plugins Method Deprecation</a></h2>
  1995. <p>Plugins using the <code>complete_sso_login</code> method of
  1996. <code>synapse.module_api.ModuleApi</code> should update to using the async/await
  1997. version <code>complete_sso_login_async</code> which includes additional checks. The
  1998. non-async version is considered deprecated.</p>
  1999. <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>
  2000. <p>v1.13.0 includes a lot of large changes. If something problematic
  2001. occurs, you may want to roll-back to a previous version of Synapse.
  2002. Because v1.13.0 also includes a new database schema version, reverting
  2003. that version is also required alongside the generic rollback
  2004. instructions mentioned above. In short, to roll back to v1.12.4 you need
  2005. to:</p>
  2006. <ol>
  2007. <li>
  2008. <p>Stop the server</p>
  2009. </li>
  2010. <li>
  2011. <p>Decrease the schema version in the database:</p>
  2012. <pre><code class="language-sql">UPDATE schema_version SET version = 57;
  2013. </code></pre>
  2014. </li>
  2015. <li>
  2016. <p>Downgrade Synapse by following the instructions for your
  2017. installation method in the &quot;Rolling back to older versions&quot;
  2018. section above.</p>
  2019. </li>
  2020. </ol>
  2021. <h1 id="upgrading-to-v1120"><a class="header" href="#upgrading-to-v1120">Upgrading to v1.12.0</a></h1>
  2022. <p>This version includes a database update which is run as part of the
  2023. upgrade, and which may take some time (several hours in the case of a
  2024. large server). Synapse will not respond to HTTP requests while this
  2025. update is taking place.</p>
  2026. <p>This is only likely to be a problem in the case of a server which is
  2027. participating in many rooms.</p>
  2028. <ol start="0">
  2029. <li>
  2030. <p>As with all upgrades, it is recommended that you have a recent
  2031. backup of your database which can be used for recovery in the event
  2032. of any problems.</p>
  2033. </li>
  2034. <li>
  2035. <p>As an initial check to see if you will be affected, you can try
  2036. running the following query from the <code>psql</code> or
  2037. <code>sqlite3</code> console. It is safe to run it while Synapse is
  2038. still running.</p>
  2039. <pre><code class="language-sql">SELECT MAX(q.v) FROM (
  2040. SELECT (
  2041. SELECT ej.json AS v
  2042. FROM state_events se INNER JOIN event_json ej USING (event_id)
  2043. WHERE se.room_id=rooms.room_id AND se.type='m.room.create' AND se.state_key=''
  2044. LIMIT 1
  2045. ) FROM rooms WHERE rooms.room_version IS NULL
  2046. ) q;
  2047. </code></pre>
  2048. <p>This query will take about the same amount of time as the upgrade
  2049. process: ie, if it takes 5 minutes, then it is likely that Synapse
  2050. will be unresponsive for 5 minutes during the upgrade.</p>
  2051. <p>If you consider an outage of this duration to be acceptable, no
  2052. further action is necessary and you can simply start Synapse 1.12.0.</p>
  2053. <p>If you would prefer to reduce the downtime, continue with the steps
  2054. below.</p>
  2055. </li>
  2056. <li>
  2057. <p>The easiest workaround for this issue is to manually create a new
  2058. index before upgrading. On PostgreSQL, his can be done as follows:</p>
  2059. <pre><code class="language-sql">CREATE INDEX CONCURRENTLY tmp_upgrade_1_12_0_index
  2060. ON state_events(room_id) WHERE type = 'm.room.create';
  2061. </code></pre>
  2062. <p>The above query may take some time, but is also safe to run while
  2063. Synapse is running.</p>
  2064. <p>We assume that no SQLite users have databases large enough to be
  2065. affected. If you <em>are</em> affected, you can run a similar query,
  2066. omitting the <code>CONCURRENTLY</code> keyword. Note however that this
  2067. operation may in itself cause Synapse to stop running for some time.
  2068. Synapse admins are reminded that <a href="postgres.html">SQLite is not recommended for use
  2069. outside a test environment</a>.</p>
  2070. </li>
  2071. <li>
  2072. <p>Once the index has been created, the <code>SELECT</code> query in step 1 above
  2073. should complete quickly. It is therefore safe to upgrade to Synapse
  2074. 1.12.0.</p>
  2075. </li>
  2076. <li>
  2077. <p>Once Synapse 1.12.0 has successfully started and is responding to
  2078. HTTP requests, the temporary index can be removed:</p>
  2079. <pre><code class="language-sql">DROP INDEX tmp_upgrade_1_12_0_index;
  2080. </code></pre>
  2081. </li>
  2082. </ol>
  2083. <h1 id="upgrading-to-v1100"><a class="header" href="#upgrading-to-v1100">Upgrading to v1.10.0</a></h1>
  2084. <p>Synapse will now log a warning on start up if used with a PostgreSQL
  2085. database that has a non-recommended locale set.</p>
  2086. <p>See <a href="postgres.html">Postgres</a> for details.</p>
  2087. <h1 id="upgrading-to-v180"><a class="header" href="#upgrading-to-v180">Upgrading to v1.8.0</a></h1>
  2088. <p>Specifying a <code>log_file</code> config option will now cause Synapse to refuse
  2089. to start, and should be replaced by with the <code>log_config</code> option.
  2090. Support for the <code>log_file</code> option was removed in v1.3.0 and has since
  2091. had no effect.</p>
  2092. <h1 id="upgrading-to-v170"><a class="header" href="#upgrading-to-v170">Upgrading to v1.7.0</a></h1>
  2093. <p>In an attempt to configure Synapse in a privacy preserving way, the
  2094. default behaviours of <code>allow_public_rooms_without_auth</code> and
  2095. <code>allow_public_rooms_over_federation</code> have been inverted. This means that
  2096. by default, only authenticated users querying the Client/Server API will
  2097. be able to query the room directory, and relatedly that the server will
  2098. not share room directory information with other servers over federation.</p>
  2099. <p>If your installation does not explicitly set these settings one way or
  2100. the other and you want either setting to be <code>true</code> then it will
  2101. necessary to update your homeserver configuration file accordingly.</p>
  2102. <p>For more details on the surrounding context see our
  2103. <a href="https://matrix.org/blog/2019/11/09/avoiding-unwelcome-visitors-on-private-matrix-servers">explainer</a>.</p>
  2104. <h1 id="upgrading-to-v150"><a class="header" href="#upgrading-to-v150">Upgrading to v1.5.0</a></h1>
  2105. <p>This release includes a database migration which may take several
  2106. minutes to complete if there are a large number (more than a million or
  2107. so) of entries in the <code>devices</code> table. This is only likely to a be a
  2108. problem on very large installations.</p>
  2109. <h1 id="upgrading-to-v140"><a class="header" href="#upgrading-to-v140">Upgrading to v1.4.0</a></h1>
  2110. <h2 id="new-custom-templates"><a class="header" href="#new-custom-templates">New custom templates</a></h2>
  2111. <p>If you have configured a custom template directory with the
  2112. <code>email.template_dir</code> option, be aware that there are new templates
  2113. regarding registration and threepid management (see below) that must be
  2114. included.</p>
  2115. <ul>
  2116. <li><code>registration.html</code> and <code>registration.txt</code></li>
  2117. <li><code>registration_success.html</code> and <code>registration_failure.html</code></li>
  2118. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code></li>
  2119. <li><code>add_threepid_failure.html</code> and <code>add_threepid_success.html</code></li>
  2120. </ul>
  2121. <p>Synapse will expect these files to exist inside the configured template
  2122. directory, and <strong>will fail to start</strong> if they are absent. To view the
  2123. default templates, see
  2124. <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">synapse/res/templates</a>.</p>
  2125. <h2 id="3pid-verification-changes"><a class="header" href="#3pid-verification-changes">3pid verification changes</a></h2>
  2126. <p><strong>Note: As of this release, users will be unable to add phone numbers or
  2127. email addresses to their accounts, without changes to the Synapse
  2128. configuration. This includes adding an email address during
  2129. registration.</strong></p>
  2130. <p>It is possible for a user to associate an email address or phone number
  2131. with their account, for a number of reasons:</p>
  2132. <ul>
  2133. <li>for use when logging in, as an alternative to the user id.</li>
  2134. <li>in the case of email, as an alternative contact to help with account
  2135. recovery.</li>
  2136. <li>in the case of email, to receive notifications of missed messages.</li>
  2137. </ul>
  2138. <p>Before an email address or phone number can be added to a user's
  2139. account, or before such an address is used to carry out a
  2140. password-reset, Synapse must confirm the operation with the owner of the
  2141. email address or phone number. It does this by sending an email or text
  2142. giving the user a link or token to confirm receipt. This process is
  2143. known as '3pid verification'. ('3pid', or 'threepid', stands for
  2144. third-party identifier, and we use it to refer to external identifiers
  2145. such as email addresses and phone numbers.)</p>
  2146. <p>Previous versions of Synapse delegated the task of 3pid verification to
  2147. an identity server by default. In most cases this server is <code>vector.im</code>
  2148. or <code>matrix.org</code>.</p>
  2149. <p>In Synapse 1.4.0, for security and privacy reasons, the homeserver will
  2150. no longer delegate this task to an identity server by default. Instead,
  2151. the server administrator will need to explicitly decide how they would
  2152. like the verification messages to be sent.</p>
  2153. <p>In the medium term, the <code>vector.im</code> and <code>matrix.org</code> identity servers
  2154. will disable support for delegated 3pid verification entirely. However,
  2155. in order to ease the transition, they will retain the capability for a
  2156. limited period. Delegated email verification will be disabled on Monday
  2157. 2nd December 2019 (giving roughly 2 months notice). Disabling delegated
  2158. SMS verification will follow some time after that once SMS verification
  2159. support lands in Synapse.</p>
  2160. <p>Once delegated 3pid verification support has been disabled in the
  2161. <code>vector.im</code> and <code>matrix.org</code> identity servers, all Synapse versions that
  2162. depend on those instances will be unable to verify email and phone
  2163. numbers through them. There are no imminent plans to remove delegated
  2164. 3pid verification from Sydent generally. (Sydent is the identity server
  2165. project that backs the <code>vector.im</code> and <code>matrix.org</code> instances).</p>
  2166. <h3 id="email-1"><a class="header" href="#email-1">Email</a></h3>
  2167. <p>Following upgrade, to continue verifying email (e.g. as part of the
  2168. registration process), admins can either:-</p>
  2169. <ul>
  2170. <li>Configure Synapse to use an email server.</li>
  2171. <li>Run or choose an identity server which allows delegated email
  2172. verification and delegate to it.</li>
  2173. </ul>
  2174. <h4 id="configure-smtp-in-synapse"><a class="header" href="#configure-smtp-in-synapse">Configure SMTP in Synapse</a></h4>
  2175. <p>To configure an SMTP server for Synapse, modify the configuration
  2176. section headed <code>email</code>, and be sure to have at least the
  2177. <code>smtp_host, smtp_port</code> and <code>notif_from</code> fields filled out.</p>
  2178. <p>You may also need to set <code>smtp_user</code>, <code>smtp_pass</code>, and
  2179. <code>require_transport_security</code>.</p>
  2180. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2181. for more details on these settings.</p>
  2182. <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>
  2183. <p>Some admins will wish to continue using email verification as part of
  2184. the registration process, but will not immediately have an appropriate
  2185. SMTP server at hand.</p>
  2186. <p>To this end, we will continue to support email verification delegation
  2187. via the <code>vector.im</code> and <code>matrix.org</code> identity servers for two months.
  2188. Support for delegated email verification will be disabled on Monday 2nd
  2189. December.</p>
  2190. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2191. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2192. server</a>) to handle
  2193. sending confirmation messages via email and SMS.</p>
  2194. <p>So to delegate email verification, in <code>homeserver.yaml</code>, set
  2195. <code>account_threepid_delegates.email</code> to the base URL of an identity
  2196. server. For example:</p>
  2197. <pre><code class="language-yaml">account_threepid_delegates:
  2198. email: https://example.com # Delegate email sending to example.com
  2199. </code></pre>
  2200. <p>Note that <code>account_threepid_delegates.email</code> replaces the deprecated
  2201. <code>email.trust_identity_server_for_password_resets</code>: if
  2202. <code>email.trust_identity_server_for_password_resets</code> is set to <code>true</code>, and
  2203. <code>account_threepid_delegates.email</code> is not set, then the first entry in
  2204. <code>trusted_third_party_id_servers</code> will be used as the
  2205. <code>account_threepid_delegate</code> for email. This is to ensure compatibility
  2206. with existing Synapse installs that set up external server handling for
  2207. these tasks before v1.4.0. If
  2208. <code>email.trust_identity_server_for_password_resets</code> is <code>true</code> and no
  2209. trusted identity server domains are configured, Synapse will report an
  2210. error and refuse to start.</p>
  2211. <p>If <code>email.trust_identity_server_for_password_resets</code> is <code>false</code> or
  2212. absent and no <code>email</code> delegate is configured in
  2213. <code>account_threepid_delegates</code>, then Synapse will send email verification
  2214. messages itself, using the configured SMTP server (see above). that
  2215. type.</p>
  2216. <h3 id="phone-numbers"><a class="header" href="#phone-numbers">Phone numbers</a></h3>
  2217. <p>Synapse does not support phone-number verification itself, so the only
  2218. way to maintain the ability for users to add phone numbers to their
  2219. accounts will be by continuing to delegate phone number verification to
  2220. the <code>matrix.org</code> and <code>vector.im</code> identity servers (or another identity
  2221. server that supports SMS sending).</p>
  2222. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2223. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2224. server</a>) to handle
  2225. sending confirmation messages via email and SMS.</p>
  2226. <p>So to delegate phone number verification, in <code>homeserver.yaml</code>, set
  2227. <code>account_threepid_delegates.msisdn</code> to the base URL of an identity
  2228. server. For example:</p>
  2229. <pre><code class="language-yaml">account_threepid_delegates:
  2230. msisdn: https://example.com # Delegate sms sending to example.com
  2231. </code></pre>
  2232. <p>The <code>matrix.org</code> and <code>vector.im</code> identity servers will continue to
  2233. support delegated phone number verification via SMS until such time as
  2234. it is possible for admins to configure their servers to perform phone
  2235. number verification directly. More details will follow in a future
  2236. release.</p>
  2237. <h2 id="rolling-back-to-v131"><a class="header" href="#rolling-back-to-v131">Rolling back to v1.3.1</a></h2>
  2238. <p>If you encounter problems with v1.4.0, it should be possible to roll
  2239. back to v1.3.1, subject to the following:</p>
  2240. <ul>
  2241. <li>
  2242. <p>The 'room statistics' engine was heavily reworked in this release
  2243. (see <a href="https://github.com/matrix-org/synapse/pull/5971">#5971</a>),
  2244. including significant changes to the database schema, which are not
  2245. easily reverted. This will cause the room statistics engine to stop
  2246. updating when you downgrade.</p>
  2247. <p>The room statistics are essentially unused in v1.3.1 (in future
  2248. versions of Synapse, they will be used to populate the room
  2249. directory), so there should be no loss of functionality. However,
  2250. the statistics engine will write errors to the logs, which can be
  2251. avoided by setting the following in <code>homeserver.yaml</code>:</p>
  2252. <pre><code class="language-yaml">stats:
  2253. enabled: false
  2254. </code></pre>
  2255. <p>Don't forget to re-enable it when you upgrade again, in preparation
  2256. for its use in the room directory!</p>
  2257. </li>
  2258. </ul>
  2259. <h1 id="upgrading-to-v120"><a class="header" href="#upgrading-to-v120">Upgrading to v1.2.0</a></h1>
  2260. <p>Some counter metrics have been renamed, with the old names deprecated.
  2261. See <a href="metrics-howto.html#renaming-of-metrics--deprecation-of-old-names-in-12">the metrics
  2262. documentation</a>
  2263. for details.</p>
  2264. <h1 id="upgrading-to-v110"><a class="header" href="#upgrading-to-v110">Upgrading to v1.1.0</a></h1>
  2265. <p>Synapse v1.1.0 removes support for older Python and PostgreSQL versions,
  2266. as outlined in <a href="https://matrix.org/blog/2019/04/08/synapse-deprecating-postgres-9-4-and-python-2-x">our deprecation
  2267. notice</a>.</p>
  2268. <h2 id="minimum-python-version"><a class="header" href="#minimum-python-version">Minimum Python Version</a></h2>
  2269. <p>Synapse v1.1.0 has a minimum Python requirement of Python 3.5. Python
  2270. 3.6 or Python 3.7 are recommended as they have improved internal string
  2271. handling, significantly reducing memory usage.</p>
  2272. <p>If you use current versions of the Matrix.org-distributed Debian
  2273. packages or Docker images, action is not required.</p>
  2274. <p>If you install Synapse in a Python virtual environment, please see
  2275. &quot;Upgrading to v0.34.0&quot; for notes on setting up a new virtualenv under
  2276. Python 3.</p>
  2277. <h2 id="minimum-postgresql-version"><a class="header" href="#minimum-postgresql-version">Minimum PostgreSQL Version</a></h2>
  2278. <p>If using PostgreSQL under Synapse, you will need to use PostgreSQL 9.5
  2279. or above. Please see the <a href="https://www.postgresql.org/docs/11/upgrading.html">PostgreSQL
  2280. documentation</a> for
  2281. more details on upgrading your database.</p>
  2282. <h1 id="upgrading-to-v10"><a class="header" href="#upgrading-to-v10">Upgrading to v1.0</a></h1>
  2283. <h2 id="validation-of-tls-certificates"><a class="header" href="#validation-of-tls-certificates">Validation of TLS certificates</a></h2>
  2284. <p>Synapse v1.0 is the first release to enforce validation of TLS
  2285. certificates for the federation API. It is therefore essential that your
  2286. certificates are correctly configured. See the
  2287. <a href="MSC1711_certificates_FAQ.html">FAQ</a> for more information.</p>
  2288. <p>Note, v1.0 installations will also no longer be able to federate with
  2289. servers that have not correctly configured their certificates.</p>
  2290. <p>In rare cases, it may be desirable to disable certificate checking: for
  2291. example, it might be essential to be able to federate with a given
  2292. legacy server in a closed federation. This can be done in one of two
  2293. ways:-</p>
  2294. <ul>
  2295. <li>Configure the global switch <code>federation_verify_certificates</code> to
  2296. <code>false</code>.</li>
  2297. <li>Configure a whitelist of server domains to trust via
  2298. <code>federation_certificate_verification_whitelist</code>.</li>
  2299. </ul>
  2300. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2301. for more details on these settings.</p>
  2302. <h2 id="email-2"><a class="header" href="#email-2">Email</a></h2>
  2303. <p>When a user requests a password reset, Synapse will send an email to the
  2304. user to confirm the request.</p>
  2305. <p>Previous versions of Synapse delegated the job of sending this email to
  2306. an identity server. If the identity server was somehow malicious or
  2307. became compromised, it would be theoretically possible to hijack an
  2308. account through this means.</p>
  2309. <p>Therefore, by default, Synapse v1.0 will send the confirmation email
  2310. itself. If Synapse is not configured with an SMTP server, password reset
  2311. via email will be disabled.</p>
  2312. <p>To configure an SMTP server for Synapse, modify the configuration
  2313. section headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>,
  2314. <code>smtp_port</code> and <code>notif_from</code> fields filled out. You may also need to set
  2315. <code>smtp_user</code>, <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  2316. <p>If you are absolutely certain that you wish to continue using an
  2317. identity server for password resets, set
  2318. <code>trust_identity_server_for_password_resets</code> to <code>true</code>.</p>
  2319. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2320. for more details on these settings.</p>
  2321. <h2 id="new-email-templates"><a class="header" href="#new-email-templates">New email templates</a></h2>
  2322. <p>Some new templates have been added to the default template directory for the purpose of
  2323. the homeserver sending its own password reset emails. If you have configured a
  2324. custom <code>template_dir</code> in your Synapse config, these files will need to be added.</p>
  2325. <p><code>password_reset.html</code> and <code>password_reset.txt</code> are HTML and plain text
  2326. templates respectively that contain the contents of what will be emailed
  2327. to the user upon attempting to reset their password via email.
  2328. <code>password_reset_success.html</code> and <code>password_reset_failure.html</code> are HTML
  2329. files that the content of which (assuming no redirect URL is set) will
  2330. be shown to the user after they attempt to click the link in the email
  2331. sent to them.</p>
  2332. <h1 id="upgrading-to-v0990"><a class="header" href="#upgrading-to-v0990">Upgrading to v0.99.0</a></h1>
  2333. <p>Please be aware that, before Synapse v1.0 is released around March 2019,
  2334. you will need to replace any self-signed certificates with those
  2335. verified by a root CA. Information on how to do so can be found at the
  2336. ACME docs.</p>
  2337. <p>For more information on configuring TLS certificates see the
  2338. <a href="MSC1711_certificates_FAQ.html">FAQ</a>.</p>
  2339. <h1 id="upgrading-to-v0340"><a class="header" href="#upgrading-to-v0340">Upgrading to v0.34.0</a></h1>
  2340. <ol>
  2341. <li>
  2342. <p>This release is the first to fully support Python 3. Synapse will
  2343. now run on Python versions 3.5, or 3.6 (as well as 2.7). We
  2344. recommend switching to Python 3, as it has been shown to give
  2345. performance improvements.</p>
  2346. <p>For users who have installed Synapse into a virtualenv, we recommend
  2347. doing this by creating a new virtualenv. For example:</p>
  2348. <pre><code>virtualenv -p python3 ~/synapse/env3
  2349. source ~/synapse/env3/bin/activate
  2350. pip install matrix-synapse
  2351. </code></pre>
  2352. <p>You can then start synapse as normal, having activated the new
  2353. virtualenv:</p>
  2354. <pre><code>cd ~/synapse
  2355. source env3/bin/activate
  2356. synctl start
  2357. </code></pre>
  2358. <p>Users who have installed from distribution packages should see the
  2359. relevant package documentation. See below for notes on Debian
  2360. packages.</p>
  2361. <ul>
  2362. <li>
  2363. <p>When upgrading to Python 3, you <strong>must</strong> make sure that your log
  2364. files are configured as UTF-8, by adding <code>encoding: utf8</code> to the
  2365. <code>RotatingFileHandler</code> configuration (if you have one) in your
  2366. <code>&lt;server&gt;.log.config</code> file. For example, if your <code>log.config</code>
  2367. file contains:</p>
  2368. <pre><code>handlers:
  2369. file:
  2370. class: logging.handlers.RotatingFileHandler
  2371. formatter: precise
  2372. filename: homeserver.log
  2373. maxBytes: 104857600
  2374. backupCount: 10
  2375. filters: [context]
  2376. console:
  2377. class: logging.StreamHandler
  2378. formatter: precise
  2379. filters: [context]
  2380. </code></pre>
  2381. <p>Then you should update this to be:</p>
  2382. <pre><code>handlers:
  2383. file:
  2384. class: logging.handlers.RotatingFileHandler
  2385. formatter: precise
  2386. filename: homeserver.log
  2387. maxBytes: 104857600
  2388. backupCount: 10
  2389. filters: [context]
  2390. encoding: utf8
  2391. console:
  2392. class: logging.StreamHandler
  2393. formatter: precise
  2394. filters: [context]
  2395. </code></pre>
  2396. <p>There is no need to revert this change if downgrading to
  2397. Python 2.</p>
  2398. </li>
  2399. </ul>
  2400. <p>We are also making available Debian packages which will run Synapse
  2401. on Python 3. You can switch to these packages with
  2402. <code>apt-get install matrix-synapse-py3</code>, however, please read
  2403. <a href="https://github.com/matrix-org/synapse/blob/release-v0.34.0/debian/NEWS">debian/NEWS</a>
  2404. before doing so. The existing <code>matrix-synapse</code> packages will
  2405. continue to use Python 2 for the time being.</p>
  2406. </li>
  2407. <li>
  2408. <p>This release removes the <code>riot.im</code> from the default list of trusted
  2409. identity servers.</p>
  2410. <p>If <code>riot.im</code> is in your homeserver's list of
  2411. <code>trusted_third_party_id_servers</code>, you should remove it. It was added
  2412. in case a hypothetical future identity server was put there. If you
  2413. don't remove it, users may be unable to deactivate their accounts.</p>
  2414. </li>
  2415. <li>
  2416. <p>This release no longer installs the (unmaintained) Matrix Console
  2417. web client as part of the default installation. It is possible to
  2418. re-enable it by installing it separately and setting the
  2419. <code>web_client_location</code> config option, but please consider switching
  2420. to another client.</p>
  2421. </li>
  2422. </ol>
  2423. <h1 id="upgrading-to-v0337"><a class="header" href="#upgrading-to-v0337">Upgrading to v0.33.7</a></h1>
  2424. <p>This release removes the example email notification templates from
  2425. <code>res/templates</code> (they are now internal to the python package). This
  2426. should only affect you if you (a) deploy your Synapse instance from a
  2427. git checkout or a github snapshot URL, and (b) have email notifications
  2428. enabled.</p>
  2429. <p>If you have email notifications enabled, you should ensure that
  2430. <code>email.template_dir</code> is either configured to point at a directory where
  2431. you have installed customised templates, or leave it unset to use the
  2432. default templates.</p>
  2433. <h1 id="upgrading-to-v0273"><a class="header" href="#upgrading-to-v0273">Upgrading to v0.27.3</a></h1>
  2434. <p>This release expands the anonymous usage stats sent if the opt-in
  2435. <code>report_stats</code> configuration is set to <code>true</code>. We now capture RSS memory
  2436. and cpu use at a very coarse level. This requires administrators to
  2437. install the optional <code>psutil</code> python module.</p>
  2438. <p>We would appreciate it if you could assist by ensuring this module is
  2439. available and <code>report_stats</code> is enabled. This will let us see if
  2440. performance changes to synapse are having an impact to the general
  2441. community.</p>
  2442. <h1 id="upgrading-to-v0150"><a class="header" href="#upgrading-to-v0150">Upgrading to v0.15.0</a></h1>
  2443. <p>If you want to use the new URL previewing API
  2444. (<code>/_matrix/media/r0/preview_url</code>) then you have to explicitly enable it
  2445. in the config and update your dependencies dependencies. See README.rst
  2446. for details.</p>
  2447. <h1 id="upgrading-to-v0110"><a class="header" href="#upgrading-to-v0110">Upgrading to v0.11.0</a></h1>
  2448. <p>This release includes the option to send anonymous usage stats to
  2449. matrix.org, and requires that administrators explictly opt in or out by
  2450. setting the <code>report_stats</code> option to either <code>true</code> or <code>false</code>.</p>
  2451. <p>We would really appreciate it if you could help our project out by
  2452. reporting anonymized usage statistics from your homeserver. Only very
  2453. basic aggregate data (e.g. number of users) will be reported, but it
  2454. helps us to track the growth of the Matrix community, and helps us to
  2455. make Matrix a success, as well as to convince other networks that they
  2456. should peer with us.</p>
  2457. <h1 id="upgrading-to-v090"><a class="header" href="#upgrading-to-v090">Upgrading to v0.9.0</a></h1>
  2458. <p>Application services have had a breaking API change in this version.</p>
  2459. <p>They can no longer register themselves with a home server using the AS
  2460. HTTP API. This decision was made because a compromised application
  2461. service with free reign to register any regex in effect grants full
  2462. read/write access to the home server if a regex of <code>.*</code> is used. An
  2463. attack where a compromised AS re-registers itself with <code>.*</code> was deemed
  2464. too big of a security risk to ignore, and so the ability to register
  2465. with the HS remotely has been removed.</p>
  2466. <p>It has been replaced by specifying a list of application service
  2467. registrations in <code>homeserver.yaml</code>:</p>
  2468. <pre><code>app_service_config_files: [&quot;registration-01.yaml&quot;, &quot;registration-02.yaml&quot;]
  2469. </code></pre>
  2470. <p>Where <code>registration-01.yaml</code> looks like:</p>
  2471. <pre><code>url: &lt;String&gt; # e.g. &quot;https://my.application.service.com&quot;
  2472. as_token: &lt;String&gt;
  2473. hs_token: &lt;String&gt;
  2474. sender_localpart: &lt;String&gt; # This is a new field which denotes the user_id localpart when using the AS token
  2475. namespaces:
  2476. users:
  2477. - exclusive: &lt;Boolean&gt;
  2478. regex: &lt;String&gt; # e.g. &quot;@prefix_.*&quot;
  2479. aliases:
  2480. - exclusive: &lt;Boolean&gt;
  2481. regex: &lt;String&gt;
  2482. rooms:
  2483. - exclusive: &lt;Boolean&gt;
  2484. regex: &lt;String&gt;
  2485. </code></pre>
  2486. <h1 id="upgrading-to-v080"><a class="header" href="#upgrading-to-v080">Upgrading to v0.8.0</a></h1>
  2487. <p>Servers which use captchas will need to add their public key to:</p>
  2488. <pre><code>static/client/register/register_config.js
  2489. window.matrixRegistrationConfig = {
  2490. recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  2491. };
  2492. </code></pre>
  2493. <p>This is required in order to support registration fallback (typically
  2494. used on mobile devices).</p>
  2495. <h1 id="upgrading-to-v070"><a class="header" href="#upgrading-to-v070">Upgrading to v0.7.0</a></h1>
  2496. <p>New dependencies are:</p>
  2497. <ul>
  2498. <li>pydenticon</li>
  2499. <li>simplejson</li>
  2500. <li>syutil</li>
  2501. <li>matrix-angular-sdk</li>
  2502. </ul>
  2503. <p>To pull in these dependencies in a virtual env, run:</p>
  2504. <pre><code>python synapse/python_dependencies.py | xargs -n 1 pip install
  2505. </code></pre>
  2506. <h1 id="upgrading-to-v060"><a class="header" href="#upgrading-to-v060">Upgrading to v0.6.0</a></h1>
  2507. <p>To pull in new dependencies, run:</p>
  2508. <pre><code>python setup.py develop --user
  2509. </code></pre>
  2510. <p>This update includes a change to the database schema. To upgrade you
  2511. first need to upgrade the database by running:</p>
  2512. <pre><code>python scripts/upgrade_db_to_v0.6.0.py &lt;db&gt; &lt;server_name&gt; &lt;signing_key&gt;
  2513. </code></pre>
  2514. <p>Where <code>&lt;db&gt;</code> is the location of the database,
  2515. <code>&lt;server_name&gt;</code> is the server name as specified in the
  2516. synapse configuration, and <code>&lt;signing_key&gt;</code> is the location
  2517. of the signing key as specified in the synapse configuration.</p>
  2518. <p>This may take some time to complete. Failures of signatures and content
  2519. hashes can safely be ignored.</p>
  2520. <h1 id="upgrading-to-v051"><a class="header" href="#upgrading-to-v051">Upgrading to v0.5.1</a></h1>
  2521. <p>Depending on precisely when you installed v0.5.0 you may have ended up
  2522. with a stale release of the reference matrix webclient installed as a
  2523. python module. To uninstall it and ensure you are depending on the
  2524. latest module, please run:</p>
  2525. <pre><code>$ pip uninstall syweb
  2526. </code></pre>
  2527. <h1 id="upgrading-to-v050"><a class="header" href="#upgrading-to-v050">Upgrading to v0.5.0</a></h1>
  2528. <p>The webclient has been split out into a seperate repository/pacakage in
  2529. this release. Before you restart your homeserver you will need to pull
  2530. in the webclient package by running:</p>
  2531. <pre><code>python setup.py develop --user
  2532. </code></pre>
  2533. <p>This release completely changes the database schema and so requires
  2534. upgrading it before starting the new version of the homeserver.</p>
  2535. <p>The script &quot;database-prepare-for-0.5.0.sh&quot; should be used to upgrade
  2536. the database. This will save all user information, such as logins and
  2537. profiles, but will otherwise purge the database. This includes messages,
  2538. which rooms the home server was a member of and room alias mappings.</p>
  2539. <p>If you would like to keep your history, please take a copy of your
  2540. database file and ask for help in #matrix:matrix.org. The upgrade
  2541. process is, unfortunately, non trivial and requires human intervention
  2542. to resolve any resulting conflicts during the upgrade process.</p>
  2543. <p>Before running the command the homeserver should be first completely
  2544. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2545. <blockquote>
  2546. <p>./scripts/database-prepare-for-0.5.0.sh &quot;homeserver.db&quot;</p>
  2547. </blockquote>
  2548. <p>Once this has successfully completed it will be safe to restart the
  2549. homeserver. You may notice that the homeserver takes a few seconds
  2550. longer to restart than usual as it reinitializes the database.</p>
  2551. <p>On startup of the new version, users can either rejoin remote rooms
  2552. using room aliases or by being reinvited. Alternatively, if any other
  2553. homeserver sends a message to a room that the homeserver was previously
  2554. in the local HS will automatically rejoin the room.</p>
  2555. <h1 id="upgrading-to-v040"><a class="header" href="#upgrading-to-v040">Upgrading to v0.4.0</a></h1>
  2556. <p>This release needs an updated syutil version. Run:</p>
  2557. <pre><code>python setup.py develop
  2558. </code></pre>
  2559. <p>You will also need to upgrade your configuration as the signing key
  2560. format has changed. Run:</p>
  2561. <pre><code>python -m synapse.app.homeserver --config-path &lt;CONFIG&gt; --generate-config
  2562. </code></pre>
  2563. <h1 id="upgrading-to-v030"><a class="header" href="#upgrading-to-v030">Upgrading to v0.3.0</a></h1>
  2564. <p>This registration API now closely matches the login API. This introduces
  2565. a bit more backwards and forwards between the HS and the client, but
  2566. this improves the overall flexibility of the API. You can now GET on
  2567. /register to retrieve a list of valid registration flows. Upon choosing
  2568. one, they are submitted in the same way as login, e.g:</p>
  2569. <pre><code>{
  2570. type: m.login.password,
  2571. user: foo,
  2572. password: bar
  2573. }
  2574. </code></pre>
  2575. <p>The default HS supports 2 flows, with and without Identity Server email
  2576. authentication. Enabling captcha on the HS will add in an extra step to
  2577. all flows: <code>m.login.recaptcha</code> which must be completed before you can
  2578. transition to the next stage. There is a new login type:
  2579. <code>m.login.email.identity</code> which contains the <code>threepidCreds</code> key which
  2580. were previously sent in the original register request. For more
  2581. information on this, see the specification.</p>
  2582. <h2 id="web-client"><a class="header" href="#web-client">Web Client</a></h2>
  2583. <p>The VoIP specification has changed between v0.2.0 and v0.3.0. Users
  2584. should refresh any browser tabs to get the latest web client code. Users
  2585. on v0.2.0 of the web client will not be able to call those on v0.3.0 and
  2586. vice versa.</p>
  2587. <h1 id="upgrading-to-v020"><a class="header" href="#upgrading-to-v020">Upgrading to v0.2.0</a></h1>
  2588. <p>The home server now requires setting up of SSL config before it can run.
  2589. To automatically generate default config use:</p>
  2590. <pre><code>$ python synapse/app/homeserver.py \
  2591. --server-name machine.my.domain.name \
  2592. --bind-port 8448 \
  2593. --config-path homeserver.config \
  2594. --generate-config
  2595. </code></pre>
  2596. <p>This config can be edited if desired, for example to specify a different
  2597. SSL certificate to use. Once done you can run the home server using:</p>
  2598. <pre><code>$ python synapse/app/homeserver.py --config-path homeserver.config
  2599. </code></pre>
  2600. <p>See the README.rst for more information.</p>
  2601. <p>Also note that some config options have been renamed, including:</p>
  2602. <ul>
  2603. <li>&quot;host&quot; to &quot;server-name&quot;</li>
  2604. <li>&quot;database&quot; to &quot;database-path&quot;</li>
  2605. <li>&quot;port&quot; to &quot;bind-port&quot; and &quot;unsecure-port&quot;</li>
  2606. </ul>
  2607. <h1 id="upgrading-to-v001"><a class="header" href="#upgrading-to-v001">Upgrading to v0.0.1</a></h1>
  2608. <p>This release completely changes the database schema and so requires
  2609. upgrading it before starting the new version of the homeserver.</p>
  2610. <p>The script &quot;database-prepare-for-0.0.1.sh&quot; should be used to upgrade
  2611. the database. This will save all user information, such as logins and
  2612. profiles, but will otherwise purge the database. This includes messages,
  2613. which rooms the home server was a member of and room alias mappings.</p>
  2614. <p>Before running the command the homeserver should be first completely
  2615. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2616. <blockquote>
  2617. <p>./scripts/database-prepare-for-0.0.1.sh &quot;homeserver.db&quot;</p>
  2618. </blockquote>
  2619. <p>Once this has successfully completed it will be safe to restart the
  2620. homeserver. You may notice that the homeserver takes a few seconds
  2621. longer to restart than usual as it reinitializes the database.</p>
  2622. <p>On startup of the new version, users can either rejoin remote rooms
  2623. using room aliases or by being reinvited. Alternatively, if any other
  2624. homeserver sends a message to a room that the homeserver was previously
  2625. in the local HS will automatically rejoin the room.</p>
  2626. <div style="break-before: page; page-break-before: always;"></div><h1 id="msc1711-certificates-faq"><a class="header" href="#msc1711-certificates-faq">MSC1711 Certificates FAQ</a></h1>
  2627. <h2 id="historical-note"><a class="header" href="#historical-note">Historical Note</a></h2>
  2628. <p>This document was originally written to guide server admins through the upgrade
  2629. path towards Synapse 1.0. Specifically,
  2630. <a href="https://github.com/matrix-org/matrix-doc/blob/main/proposals/1711-x509-for-federation.md">MSC1711</a>
  2631. required that all servers present valid TLS certificates on their federation
  2632. API. Admins were encouraged to achieve compliance from version 0.99.0 (released
  2633. in February 2019) ahead of version 1.0 (released June 2019) enforcing the
  2634. certificate checks.</p>
  2635. <p>Much of what follows is now outdated since most admins will have already
  2636. upgraded, however it may be of use to those with old installs returning to the
  2637. project.</p>
  2638. <p>If you are setting up a server from scratch you almost certainly should look at
  2639. the <a href="setup/installation.html">installation guide</a> instead.</p>
  2640. <h2 id="introduction-1"><a class="header" href="#introduction-1">Introduction</a></h2>
  2641. <p>The goal of Synapse 0.99.0 is to act as a stepping stone to Synapse 1.0.0. It
  2642. supports the r0.1 release of the server to server specification, but is
  2643. compatible with both the legacy Matrix federation behaviour (pre-r0.1) as well
  2644. as post-r0.1 behaviour, in order to allow for a smooth upgrade across the
  2645. federation.</p>
  2646. <p>The most important thing to know is that Synapse 1.0.0 will require a valid TLS
  2647. certificate on federation endpoints. Self signed certificates will not be
  2648. sufficient.</p>
  2649. <p>Synapse 0.99.0 makes it easy to configure TLS certificates and will
  2650. interoperate with both &gt;= 1.0.0 servers as well as existing servers yet to
  2651. upgrade.</p>
  2652. <p><strong>It is critical that all admins upgrade to 0.99.0 and configure a valid TLS
  2653. certificate.</strong> Admins will have 1 month to do so, after which 1.0.0 will be
  2654. released and those servers without a valid certificate will not longer be able
  2655. to federate with &gt;= 1.0.0 servers.</p>
  2656. <p>Full details on how to carry out this configuration change is given
  2657. <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">below</a>. A
  2658. timeline and some frequently asked questions are also given below.</p>
  2659. <p>For more details and context on the release of the r0.1 Server/Server API and
  2660. imminent Matrix 1.0 release, you can also see our
  2661. <a href="https://matrix.org/blog/2019/02/04/matrix-at-fosdem-2019/">main talk from FOSDEM 2019</a>.</p>
  2662. <h2 id="contents"><a class="header" href="#contents">Contents</a></h2>
  2663. <ul>
  2664. <li>Timeline</li>
  2665. <li>Configuring certificates for compatibility with Synapse 1.0</li>
  2666. <li>FAQ
  2667. <ul>
  2668. <li>Synapse 0.99.0 has just been released, what do I need to do right now?</li>
  2669. <li>How do I upgrade?</li>
  2670. <li>What will happen if I do not set up a valid federation certificate
  2671. immediately?</li>
  2672. <li>What will happen if I do nothing at all?</li>
  2673. <li>When do I need a SRV record or .well-known URI?</li>
  2674. <li>Can I still use an SRV record?</li>
  2675. <li>I have created a .well-known URI. Do I still need an SRV record?</li>
  2676. <li>It used to work just fine, why are you breaking everything?</li>
  2677. <li>Can I manage my own certificates rather than having Synapse renew
  2678. certificates itself?</li>
  2679. <li>Do you still recommend against using a reverse proxy on the federation port?</li>
  2680. <li>Do I still need to give my TLS certificates to Synapse if I am using a
  2681. reverse proxy?</li>
  2682. <li>Do I need the same certificate for the client and federation port?</li>
  2683. <li>How do I tell Synapse to reload my keys/certificates after I replace them?</li>
  2684. </ul>
  2685. </li>
  2686. </ul>
  2687. <h2 id="timeline"><a class="header" href="#timeline">Timeline</a></h2>
  2688. <p><strong>5th Feb 2019 - Synapse 0.99.0 is released.</strong></p>
  2689. <p>All server admins are encouraged to upgrade.</p>
  2690. <p>0.99.0:</p>
  2691. <ul>
  2692. <li>
  2693. <p>provides support for ACME to make setting up Let's Encrypt certs easy, as
  2694. well as .well-known support.</p>
  2695. </li>
  2696. <li>
  2697. <p>does not enforce that a valid CA cert is present on the federation API, but
  2698. rather makes it easy to set one up.</p>
  2699. </li>
  2700. <li>
  2701. <p>provides support for .well-known</p>
  2702. </li>
  2703. </ul>
  2704. <p>Admins should upgrade and configure a valid CA cert. Homeservers that require a
  2705. .well-known entry (see below), should retain their SRV record and use it
  2706. alongside their .well-known record.</p>
  2707. <p><strong>10th June 2019 - Synapse 1.0.0 is released</strong></p>
  2708. <p>1.0.0 is scheduled for release on 10th June. In
  2709. accordance with the the <a href="https://matrix.org/docs/spec/server_server/r0.1.0.html">S2S spec</a>
  2710. 1.0.0 will enforce certificate validity. This means that any homeserver without a
  2711. valid certificate after this point will no longer be able to federate with
  2712. 1.0.0 servers.</p>
  2713. <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>
  2714. <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>
  2715. <p>In this case, your <code>server_name</code> points to the host where your Synapse is
  2716. running. There is no need to create a <code>.well-known</code> URI or an SRV record, but
  2717. you will need to give Synapse a valid, signed, certificate.</p>
  2718. <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>
  2719. <p>If you are using an SRV record, your matrix domain (<code>server_name</code>) may not
  2720. point to the same host that your Synapse is running on (the 'target
  2721. domain'). (If it does, you can follow the recommendation above; otherwise, read
  2722. on.)</p>
  2723. <p>Let's assume that your <code>server_name</code> is <code>example.com</code>, and your Synapse is
  2724. hosted at a target domain of <code>customer.example.net</code>. Currently you should have
  2725. an SRV record which looks like:</p>
  2726. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 8000 customer.example.net.
  2727. </code></pre>
  2728. <p>In this situation, you have three choices for how to proceed:</p>
  2729. <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>
  2730. <p>Synapse 1.0 will expect your server to present a TLS certificate for your
  2731. <code>server_name</code> (<code>example.com</code> in the above example). You can achieve this by acquiring a
  2732. certificate for the <code>server_name</code> yourself (for example, using <code>certbot</code>), and giving it
  2733. and the key to Synapse via <code>tls_certificate_path</code> and <code>tls_private_key_path</code>.</p>
  2734. <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>
  2735. <p>If you have an existing reverse proxy set up with correct TLS certificates for
  2736. your domain, you can simply route all traffic through the reverse proxy by
  2737. updating the SRV record appropriately (or removing it, if the proxy listens on
  2738. 8448).</p>
  2739. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2740. reverse proxy.</p>
  2741. <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>
  2742. <p>This will allow you to keep Synapse on a separate domain, without having to
  2743. give it a certificate for the matrix domain.</p>
  2744. <p>You can do this with a <code>.well-known</code> file as follows:</p>
  2745. <ol>
  2746. <li>
  2747. <p>Keep the SRV record in place - it is needed for backwards compatibility
  2748. with Synapse 0.34 and earlier.</p>
  2749. </li>
  2750. <li>
  2751. <p>Give Synapse a certificate corresponding to the target domain
  2752. (<code>customer.example.net</code> in the above example). You can do this by acquire a
  2753. certificate for the target domain and giving it to Synapse via <code>tls_certificate_path</code>
  2754. and <code>tls_private_key_path</code>.</p>
  2755. </li>
  2756. <li>
  2757. <p>Restart Synapse to ensure the new certificate is loaded.</p>
  2758. </li>
  2759. <li>
  2760. <p>Arrange for a <code>.well-known</code> file at
  2761. <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> with contents:</p>
  2762. <pre><code class="language-json">{&quot;m.server&quot;: &quot;&lt;target server name&gt;&quot;}
  2763. </code></pre>
  2764. <p>where the target server name is resolved as usual (i.e. SRV lookup, falling
  2765. back to talking to port 8448).</p>
  2766. <p>In the above example, where synapse is listening on port 8000,
  2767. <code>https://example.com/.well-known/matrix/server</code> should have <code>m.server</code> set to one of:</p>
  2768. <ol>
  2769. <li>
  2770. <p><code>customer.example.net</code> ─ with a SRV record on
  2771. <code>_matrix._tcp.customer.example.com</code> pointing to port 8000, or:</p>
  2772. </li>
  2773. <li>
  2774. <p><code>customer.example.net</code> ─ updating synapse to listen on the default port
  2775. 8448, or:</p>
  2776. </li>
  2777. <li>
  2778. <p><code>customer.example.net:8000</code> ─ ensuring that if there is a reverse proxy
  2779. on <code>customer.example.net:8000</code> it correctly handles HTTP requests with
  2780. Host header set to <code>customer.example.net:8000</code>.</p>
  2781. </li>
  2782. </ol>
  2783. </li>
  2784. </ol>
  2785. <h2 id="faq"><a class="header" href="#faq">FAQ</a></h2>
  2786. <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>
  2787. <p>Upgrade as soon as you can in preparation for Synapse 1.0.0, and update your
  2788. TLS certificates as <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">above</a>.</p>
  2789. <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>
  2790. <p>Nothing initially, but once 1.0.0 is in the wild it will not be possible to
  2791. federate with 1.0.0 servers.</p>
  2792. <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>
  2793. <p>If the admin takes no action at all, and remains on a Synapse &lt; 0.99.0 then the
  2794. homeserver will be unable to federate with those who have implemented
  2795. .well-known. Then, as above, once the month upgrade window has expired the
  2796. homeserver will not be able to federate with any Synapse &gt;= 1.0.0</p>
  2797. <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>
  2798. <p>If your homeserver listens on the default federation port (8448), and your
  2799. <code>server_name</code> points to the host that your homeserver runs on, you do not need an
  2800. SRV record or <code>.well-known/matrix/server</code> URI.</p>
  2801. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  2802. fresh Upcloud VPS or similar, you could install Synapse 0.99 on that host,
  2803. giving it a server_name of <code>example.com</code>, and it would automatically generate a
  2804. valid TLS certificate for you via Let's Encrypt and no SRV record or
  2805. <code>.well-known</code> URI would be needed.</p>
  2806. <p>This is the common case, although you can add an SRV record or
  2807. <code>.well-known/matrix/server</code> URI for completeness if you wish.</p>
  2808. <p><strong>However</strong>, if your server does not listen on port 8448, or if your <code>server_name</code>
  2809. does not point to the host that your homeserver runs on, you will need to let
  2810. other servers know how to find it.</p>
  2811. <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
  2812. currently&quot;</a> above.</p>
  2813. <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>
  2814. <p>Firstly, if you didn't need an SRV record before (because your server is
  2815. listening on port 8448 of your server_name), you certainly don't need one now:
  2816. the defaults are still the same.</p>
  2817. <p>If you previously had an SRV record, you can keep using it provided you are
  2818. able to give Synapse a TLS certificate corresponding to your server name. For
  2819. example, suppose you had the following SRV record, which directs matrix traffic
  2820. for example.com to matrix.example.com:443:</p>
  2821. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 443 matrix.example.com
  2822. </code></pre>
  2823. <p>In this case, Synapse must be given a certificate for example.com - or be
  2824. configured to acquire one from Let's Encrypt.</p>
  2825. <p>If you are unable to give Synapse a certificate for your server_name, you will
  2826. also need to use a .well-known URI instead. However, see also &quot;I have created a
  2827. .well-known URI. Do I still need an SRV record?&quot;.</p>
  2828. <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>
  2829. <p>As of Synapse 0.99, Synapse will first check for the existence of a <code>.well-known</code>
  2830. URI and follow any delegation it suggests. It will only then check for the
  2831. existence of an SRV record.</p>
  2832. <p>That means that the SRV record will often be redundant. However, you should
  2833. remember that there may still be older versions of Synapse in the federation
  2834. which do not understand <code>.well-known</code> URIs, so if you removed your SRV record you
  2835. would no longer be able to federate with them.</p>
  2836. <p>It is therefore best to leave the SRV record in place for now. Synapse 0.34 and
  2837. earlier will follow the SRV record (and not care about the invalid
  2838. certificate). Synapse 0.99 and later will follow the .well-known URI, with the
  2839. correct certificate chain.</p>
  2840. <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>
  2841. <p>We have always wanted Matrix servers to be as easy to set up as possible, and
  2842. so back when we started federation in 2014 we didn't want admins to have to go
  2843. through the cumbersome process of buying a valid TLS certificate to run a
  2844. server. This was before Let's Encrypt came along and made getting a free and
  2845. valid TLS certificate straightforward. So instead, we adopted a system based on
  2846. <a href="https://en.wikipedia.org/wiki/Convergence_(SSL)">Perspectives</a>: an approach
  2847. where you check a set of &quot;notary servers&quot; (in practice, homeservers) to vouch
  2848. for the validity of a certificate rather than having it signed by a CA. As long
  2849. as enough different notaries agree on the certificate's validity, then it is
  2850. trusted.</p>
  2851. <p>However, in practice this has never worked properly. Most people only use the
  2852. default notary server (matrix.org), leading to inadvertent centralisation which
  2853. we want to eliminate. Meanwhile, we never implemented the full consensus
  2854. algorithm to query the servers participating in a room to determine consensus
  2855. on whether a given certificate is valid. This is fiddly to get right
  2856. (especially in face of sybil attacks), and we found ourselves questioning
  2857. whether it was worth the effort to finish the work and commit to maintaining a
  2858. secure certificate validation system as opposed to focusing on core Matrix
  2859. development.</p>
  2860. <p>Meanwhile, Let's Encrypt came along in 2016, and put the final nail in the
  2861. coffin of the Perspectives project (which was already pretty dead). So, the
  2862. Spec Core Team decided that a better approach would be to mandate valid TLS
  2863. certificates for federation alongside the rest of the Web. More details can be
  2864. found in
  2865. <a href="https://github.com/matrix-org/matrix-doc/blob/main/proposals/1711-x509-for-federation.md#background-the-failure-of-the-perspectives-approach">MSC1711</a>.</p>
  2866. <p>This results in a breaking change, which is disruptive, but absolutely critical
  2867. for the security model. However, the existence of Let's Encrypt as a trivial
  2868. way to replace the old self-signed certificates with valid CA-signed ones helps
  2869. smooth things over massively, especially as Synapse can now automate Let's
  2870. Encrypt certificate generation if needed.</p>
  2871. <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>
  2872. <p>Yes, you are welcome to manage your certificates yourself. Synapse will only
  2873. attempt to obtain certificates from Let's Encrypt if you configure it to do
  2874. so.The only requirement is that there is a valid TLS cert present for
  2875. federation end points.</p>
  2876. <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>
  2877. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  2878. find it easier to direct federation traffic to a reverse proxy and manage their
  2879. own TLS certificates, and this is a supported configuration.</p>
  2880. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2881. reverse proxy.</p>
  2882. <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>
  2883. <p>Practically speaking, this is no longer necessary.</p>
  2884. <p>If you are using a reverse proxy for all of your TLS traffic, then you can set
  2885. <code>no_tls: True</code>. In that case, the only reason Synapse needs the certificate is
  2886. to populate a legacy 'tls_fingerprints' field in the federation API. This is
  2887. ignored by Synapse 0.99.0 and later, and the only time pre-0.99 Synapses will
  2888. check it is when attempting to fetch the server keys - and generally this is
  2889. delegated via <code>matrix.org</code>, which is on 0.99.0.</p>
  2890. <p>However, there is a bug in Synapse 0.99.0
  2891. <a href="https://github.com/matrix-org/synapse/issues/4554">4554</a> which prevents
  2892. Synapse from starting if you do not give it a TLS certificate. To work around
  2893. this, you can give it any TLS certificate at all. This will be fixed soon.</p>
  2894. <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>
  2895. <p>No. There is nothing stopping you from using different certificates,
  2896. particularly if you are using a reverse proxy. However, Synapse will use the
  2897. same certificate on any ports where TLS is configured.</p>
  2898. <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>
  2899. <p>Synapse will reload the keys and certificates when it receives a SIGHUP - for
  2900. example <code>kill -HUP $(cat homeserver.pid)</code>. Alternatively, simply restart
  2901. Synapse, though this will result in downtime while it restarts.</p>
  2902. <div style="break-before: page; page-break-before: always;"></div><h1 id="setting-up-federation"><a class="header" href="#setting-up-federation">Setting up federation</a></h1>
  2903. <p>Federation is the process by which users on different servers can participate
  2904. in the same room. For this to work, those other servers must be able to contact
  2905. yours to send messages.</p>
  2906. <p>The <code>server_name</code> configured in the Synapse configuration file (often
  2907. <code>homeserver.yaml</code>) defines how resources (users, rooms, etc.) will be
  2908. identified (eg: <code>@user:example.com</code>, <code>#room:example.com</code>). By default,
  2909. it is also the domain that other servers will use to try to reach your
  2910. server (via port 8448). This is easy to set up and will work provided
  2911. you set the <code>server_name</code> to match your machine's public DNS hostname.</p>
  2912. <p>For this default configuration to work, you will need to listen for TLS
  2913. connections on port 8448. The preferred way to do that is by using a
  2914. reverse proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions
  2915. on how to correctly set one up.</p>
  2916. <p>In some cases you might not want to run Synapse on the machine that has
  2917. the <code>server_name</code> as its public DNS hostname, or you might want federation
  2918. traffic to use a different port than 8448. For example, you might want to
  2919. have your user names look like <code>@user:example.com</code>, but you want to run
  2920. Synapse on <code>synapse.example.com</code> on port 443. This can be done using
  2921. delegation, which allows an admin to control where federation traffic should
  2922. be sent. See <a href="delegate.html">the delegation documentation</a> for instructions on how to set this up.</p>
  2923. <p>Once federation has been configured, you should be able to join a room over
  2924. federation. A good place to start is <code>#synapse:matrix.org</code> - a room for
  2925. Synapse admins.</p>
  2926. <h2 id="troubleshooting-3"><a class="header" href="#troubleshooting-3">Troubleshooting</a></h2>
  2927. <p>You can use the <a href="https://matrix.org/federationtester">federation tester</a>
  2928. to check if your homeserver is configured correctly. Alternatively try the
  2929. <a href="https://matrix.org/federationtester/api/report?server_name=DOMAIN">JSON API used by the federation tester</a>.
  2930. Note that you'll have to modify this URL to replace <code>DOMAIN</code> with your
  2931. <code>server_name</code>. Hitting the API directly provides extra detail.</p>
  2932. <p>The typical failure mode for federation is that when the server tries to join
  2933. a room, it is rejected with &quot;401: Unauthorized&quot;. Generally this means that other
  2934. servers in the room could not access yours. (Joining a room over federation is
  2935. a complicated dance which requires connections in both directions).</p>
  2936. <p>Another common problem is that people on other servers can't join rooms that
  2937. you invite them to. This can be caused by an incorrectly-configured reverse
  2938. proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions on how
  2939. to correctly configure a reverse proxy.</p>
  2940. <h3 id="known-issues"><a class="header" href="#known-issues">Known issues</a></h3>
  2941. <p><strong>HTTP <code>308 Permanent Redirect</code> redirects are not followed</strong>: Due to missing features
  2942. in the HTTP library used by Synapse, 308 redirects are currently not followed by
  2943. federating servers, which can cause <code>M_UNKNOWN</code> or <code>401 Unauthorized</code> errors. This
  2944. may affect users who are redirecting apex-to-www (e.g. <code>example.com</code> -&gt; <code>www.example.com</code>),
  2945. and especially users of the Kubernetes <em>Nginx Ingress</em> module, which uses 308 redirect
  2946. codes by default. For those Kubernetes users, <a href="https://stackoverflow.com/a/52617528/5096871">this Stackoverflow post</a>
  2947. might be helpful. For other users, switching to a <code>301 Moved Permanently</code> code may be
  2948. an option. 308 redirect codes will be supported properly in a future
  2949. release of Synapse.</p>
  2950. <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>
  2951. <p>If you want to get up and running quickly with a trio of homeservers in a
  2952. private federation, there is a script in the <code>demo</code> directory. This is mainly
  2953. useful just for development purposes. See <a href="https://github.com/matrix-org/synapse/tree/develop/demo/">demo/README</a>.</p>
  2954. <div style="break-before: page; page-break-before: always;"></div><h1 id="configuration-1"><a class="header" href="#configuration-1">Configuration</a></h1>
  2955. <p>This section contains information on tweaking Synapse via the various options in the configuration file. A configuration
  2956. file should have been generated when you <a href="usage/configuration/../../setup/installation.html">installed Synapse</a>.</p>
  2957. <div style="break-before: page; page-break-before: always;"></div><h1 id="homeserver-sample-configuration-file"><a class="header" href="#homeserver-sample-configuration-file">Homeserver Sample Configuration File</a></h1>
  2958. <p>Below is a sample homeserver configuration file. The homeserver configuration file
  2959. can be tweaked to change the behaviour of your homeserver. A restart of the server is
  2960. generally required to apply any changes made to this file.</p>
  2961. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  2962. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  2963. a fresh config using Synapse by following the instructions in
  2964. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  2965. <pre><code class="language-yaml"># This file is maintained as an up-to-date snapshot of the default
  2966. # homeserver.yaml configuration generated by Synapse.
  2967. #
  2968. # It is intended to act as a reference for the default configuration,
  2969. # helping admins keep track of new options and other changes, and compare
  2970. # their configs with the current default. As such, many of the actual
  2971. # config values shown are placeholders.
  2972. #
  2973. # It is *not* intended to be copied and used as the basis for a real
  2974. # homeserver.yaml. Instead, if you are starting from scratch, please generate
  2975. # a fresh config using Synapse by following the instructions in
  2976. # https://matrix-org.github.io/synapse/latest/setup/installation.html.
  2977. # Configuration options that take a time period can be set using a number
  2978. # followed by a letter. Letters have the following meanings:
  2979. # s = second
  2980. # m = minute
  2981. # h = hour
  2982. # d = day
  2983. # w = week
  2984. # y = year
  2985. # For example, setting redaction_retention_period: 5m would remove redacted
  2986. # messages from the database after 5 minutes, rather than 5 months.
  2987. ################################################################################
  2988. # Configuration file for Synapse.
  2989. #
  2990. # This is a YAML file: see [1] for a quick introduction. Note in particular
  2991. # that *indentation is important*: all the elements of a list or dictionary
  2992. # should have the same indentation.
  2993. #
  2994. # [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  2995. ## Modules ##
  2996. # Server admins can expand Synapse's functionality with external modules.
  2997. #
  2998. # See https://matrix-org.github.io/synapse/latest/modules.html for more
  2999. # documentation on how to configure or create custom modules for Synapse.
  3000. #
  3001. modules:
  3002. # - module: my_super_module.MySuperClass
  3003. # config:
  3004. # do_thing: true
  3005. # - module: my_other_super_module.SomeClass
  3006. # config: {}
  3007. ## Server ##
  3008. # The public-facing domain of the server
  3009. #
  3010. # The server_name name will appear at the end of usernames and room addresses
  3011. # created on this server. For example if the server_name was example.com,
  3012. # usernames on this server would be in the format @user:example.com
  3013. #
  3014. # In most cases you should avoid using a matrix specific subdomain such as
  3015. # matrix.example.com or synapse.example.com as the server_name for the same
  3016. # reasons you wouldn't use user@email.example.com as your email address.
  3017. # See https://matrix-org.github.io/synapse/latest/delegate.html
  3018. # for information on how to host Synapse on a subdomain while preserving
  3019. # a clean server_name.
  3020. #
  3021. # The server_name cannot be changed later so it is important to
  3022. # configure this correctly before you start Synapse. It should be all
  3023. # lowercase and may contain an explicit port.
  3024. # Examples: matrix.org, localhost:8080
  3025. #
  3026. server_name: &quot;SERVERNAME&quot;
  3027. # When running as a daemon, the file to store the pid in
  3028. #
  3029. pid_file: DATADIR/homeserver.pid
  3030. # The absolute URL to the web client which /_matrix/client will redirect
  3031. # to if 'webclient' is configured under the 'listeners' configuration.
  3032. #
  3033. # This option can be also set to the filesystem path to the web client
  3034. # which will be served at /_matrix/client/ if 'webclient' is configured
  3035. # under the 'listeners' configuration, however this is a security risk:
  3036. # https://github.com/matrix-org/synapse#security-note
  3037. #
  3038. #web_client_location: https://riot.example.com/
  3039. # The public-facing base URL that clients use to access this Homeserver (not
  3040. # including _matrix/...). This is the same URL a user might enter into the
  3041. # 'Custom Homeserver URL' field on their client. If you use Synapse with a
  3042. # reverse proxy, this should be the URL to reach Synapse via the proxy.
  3043. # Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
  3044. # 'listeners' below).
  3045. #
  3046. #public_baseurl: https://example.com/
  3047. # Set the soft limit on the number of file descriptors synapse can use
  3048. # Zero is used to indicate synapse should set the soft limit to the
  3049. # hard limit.
  3050. #
  3051. #soft_file_limit: 0
  3052. # Presence tracking allows users to see the state (e.g online/offline)
  3053. # of other local and remote users.
  3054. #
  3055. presence:
  3056. # Uncomment to disable presence tracking on this homeserver. This option
  3057. # replaces the previous top-level 'use_presence' option.
  3058. #
  3059. #enabled: false
  3060. # Whether to require authentication to retrieve profile data (avatars,
  3061. # display names) of other users through the client API. Defaults to
  3062. # 'false'. Note that profile data is also available via the federation
  3063. # API, unless allow_profile_lookup_over_federation is set to false.
  3064. #
  3065. #require_auth_for_profile_requests: true
  3066. # Uncomment to require a user to share a room with another user in order
  3067. # to retrieve their profile information. Only checked on Client-Server
  3068. # requests. Profile requests from other servers should be checked by the
  3069. # requesting server. Defaults to 'false'.
  3070. #
  3071. #limit_profile_requests_to_users_who_share_rooms: true
  3072. # Uncomment to prevent a user's profile data from being retrieved and
  3073. # displayed in a room until they have joined it. By default, a user's
  3074. # profile data is included in an invite event, regardless of the values
  3075. # of the above two settings, and whether or not the users share a server.
  3076. # Defaults to 'true'.
  3077. #
  3078. #include_profile_data_on_invite: false
  3079. # If set to 'true', removes the need for authentication to access the server's
  3080. # public rooms directory through the client API, meaning that anyone can
  3081. # query the room directory. Defaults to 'false'.
  3082. #
  3083. #allow_public_rooms_without_auth: true
  3084. # If set to 'true', allows any other homeserver to fetch the server's public
  3085. # rooms directory via federation. Defaults to 'false'.
  3086. #
  3087. #allow_public_rooms_over_federation: true
  3088. # The default room version for newly created rooms.
  3089. #
  3090. # Known room versions are listed here:
  3091. # https://matrix.org/docs/spec/#complete-list-of-room-versions
  3092. #
  3093. # For example, for room version 1, default_room_version should be set
  3094. # to &quot;1&quot;.
  3095. #
  3096. #default_room_version: &quot;6&quot;
  3097. # The GC threshold parameters to pass to `gc.set_threshold`, if defined
  3098. #
  3099. #gc_thresholds: [700, 10, 10]
  3100. # The minimum time in seconds between each GC for a generation, regardless of
  3101. # the GC thresholds. This ensures that we don't do GC too frequently.
  3102. #
  3103. # A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
  3104. # generation 0 GCs, etc.
  3105. #
  3106. # Defaults to `[1s, 10s, 30s]`.
  3107. #
  3108. #gc_min_interval: [0.5s, 30s, 1m]
  3109. # Set the limit on the returned events in the timeline in the get
  3110. # and sync operations. The default value is 100. -1 means no upper limit.
  3111. #
  3112. # Uncomment the following to increase the limit to 5000.
  3113. #
  3114. #filter_timeline_limit: 5000
  3115. # Whether room invites to users on this server should be blocked
  3116. # (except those sent by local server admins). The default is False.
  3117. #
  3118. #block_non_admin_invites: true
  3119. # Room searching
  3120. #
  3121. # If disabled, new messages will not be indexed for searching and users
  3122. # will receive errors when searching for messages. Defaults to enabled.
  3123. #
  3124. #enable_search: false
  3125. # Prevent outgoing requests from being sent to the following blacklisted IP address
  3126. # CIDR ranges. If this option is not specified then it defaults to private IP
  3127. # address ranges (see the example below).
  3128. #
  3129. # The blacklist applies to the outbound requests for federation, identity servers,
  3130. # push servers, and for checking key validity for third-party invite events.
  3131. #
  3132. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3133. # listed here, since they correspond to unroutable addresses.)
  3134. #
  3135. # This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
  3136. #
  3137. # Note: The value is ignored when an HTTP proxy is in use
  3138. #
  3139. #ip_range_blacklist:
  3140. # - '127.0.0.0/8'
  3141. # - '10.0.0.0/8'
  3142. # - '172.16.0.0/12'
  3143. # - '192.168.0.0/16'
  3144. # - '100.64.0.0/10'
  3145. # - '192.0.0.0/24'
  3146. # - '169.254.0.0/16'
  3147. # - '192.88.99.0/24'
  3148. # - '198.18.0.0/15'
  3149. # - '192.0.2.0/24'
  3150. # - '198.51.100.0/24'
  3151. # - '203.0.113.0/24'
  3152. # - '224.0.0.0/4'
  3153. # - '::1/128'
  3154. # - 'fe80::/10'
  3155. # - 'fc00::/7'
  3156. # - '2001:db8::/32'
  3157. # - 'ff00::/8'
  3158. # - 'fec0::/10'
  3159. # List of IP address CIDR ranges that should be allowed for federation,
  3160. # identity servers, push servers, and for checking key validity for
  3161. # third-party invite events. This is useful for specifying exceptions to
  3162. # wide-ranging blacklisted target IP ranges - e.g. for communication with
  3163. # a push server only visible in your network.
  3164. #
  3165. # This whitelist overrides ip_range_blacklist and defaults to an empty
  3166. # list.
  3167. #
  3168. #ip_range_whitelist:
  3169. # - '192.168.1.1'
  3170. # List of ports that Synapse should listen on, their purpose and their
  3171. # configuration.
  3172. #
  3173. # Options for each listener include:
  3174. #
  3175. # port: the TCP port to bind to
  3176. #
  3177. # bind_addresses: a list of local addresses to listen on. The default is
  3178. # 'all local interfaces'.
  3179. #
  3180. # type: the type of listener. Normally 'http', but other valid options are:
  3181. # 'manhole' (see https://matrix-org.github.io/synapse/latest/manhole.html),
  3182. # 'metrics' (see https://matrix-org.github.io/synapse/latest/metrics-howto.html),
  3183. # 'replication' (see https://matrix-org.github.io/synapse/latest/workers.html).
  3184. #
  3185. # tls: set to true to enable TLS for this listener. Will use the TLS
  3186. # key/cert specified in tls_private_key_path / tls_certificate_path.
  3187. #
  3188. # x_forwarded: Only valid for an 'http' listener. Set to true to use the
  3189. # X-Forwarded-For header as the client IP. Useful when Synapse is
  3190. # behind a reverse-proxy.
  3191. #
  3192. # resources: Only valid for an 'http' listener. A list of resources to host
  3193. # on this port. Options for each resource are:
  3194. #
  3195. # names: a list of names of HTTP resources. See below for a list of
  3196. # valid resource names.
  3197. #
  3198. # compress: set to true to enable HTTP compression for this resource.
  3199. #
  3200. # additional_resources: Only valid for an 'http' listener. A map of
  3201. # additional endpoints which should be loaded via dynamic modules.
  3202. #
  3203. # Valid resource names are:
  3204. #
  3205. # client: the client-server API (/_matrix/client), and the synapse admin
  3206. # API (/_synapse/admin). Also implies 'media' and 'static'.
  3207. #
  3208. # consent: user consent forms (/_matrix/consent).
  3209. # See https://matrix-org.github.io/synapse/latest/consent_tracking.html.
  3210. #
  3211. # federation: the server-server API (/_matrix/federation). Also implies
  3212. # 'media', 'keys', 'openid'
  3213. #
  3214. # keys: the key discovery API (/_matrix/keys).
  3215. #
  3216. # media: the media API (/_matrix/media).
  3217. #
  3218. # metrics: the metrics interface.
  3219. # See https://matrix-org.github.io/synapse/latest/metrics-howto.html.
  3220. #
  3221. # openid: OpenID authentication.
  3222. #
  3223. # replication: the HTTP replication API (/_synapse/replication).
  3224. # See https://matrix-org.github.io/synapse/latest/workers.html.
  3225. #
  3226. # static: static resources under synapse/static (/_matrix/static). (Mostly
  3227. # useful for 'fallback authentication'.)
  3228. #
  3229. # webclient: A web client. Requires web_client_location to be set.
  3230. #
  3231. listeners:
  3232. # TLS-enabled listener: for when matrix traffic is sent directly to synapse.
  3233. #
  3234. # Disabled by default. To enable it, uncomment the following. (Note that you
  3235. # will also need to give Synapse a TLS key and certificate: see the TLS section
  3236. # below.)
  3237. #
  3238. #- port: 8448
  3239. # type: http
  3240. # tls: true
  3241. # resources:
  3242. # - names: [client, federation]
  3243. # Unsecure HTTP listener: for when matrix traffic passes through a reverse proxy
  3244. # that unwraps TLS.
  3245. #
  3246. # If you plan to use a reverse proxy, please see
  3247. # https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3248. #
  3249. - port: 8008
  3250. tls: false
  3251. type: http
  3252. x_forwarded: true
  3253. bind_addresses: ['::1', '127.0.0.1']
  3254. resources:
  3255. - names: [client, federation]
  3256. compress: false
  3257. # example additional_resources:
  3258. #
  3259. #additional_resources:
  3260. # &quot;/_matrix/my/custom/endpoint&quot;:
  3261. # module: my_module.CustomRequestHandler
  3262. # config: {}
  3263. # Turn on the twisted ssh manhole service on localhost on the given
  3264. # port.
  3265. #
  3266. #- port: 9000
  3267. # bind_addresses: ['::1', '127.0.0.1']
  3268. # type: manhole
  3269. # Connection settings for the manhole
  3270. #
  3271. manhole_settings:
  3272. # The username for the manhole. This defaults to 'matrix'.
  3273. #
  3274. #username: manhole
  3275. # The password for the manhole. This defaults to 'rabbithole'.
  3276. #
  3277. #password: mypassword
  3278. # The private and public SSH key pair used to encrypt the manhole traffic.
  3279. # If these are left unset, then hardcoded and non-secret keys are used,
  3280. # which could allow traffic to be intercepted if sent over a public network.
  3281. #
  3282. #ssh_priv_key_path: CONFDIR/id_rsa
  3283. #ssh_pub_key_path: CONFDIR/id_rsa.pub
  3284. # Forward extremities can build up in a room due to networking delays between
  3285. # homeservers. Once this happens in a large room, calculation of the state of
  3286. # that room can become quite expensive. To mitigate this, once the number of
  3287. # forward extremities reaches a given threshold, Synapse will send an
  3288. # org.matrix.dummy_event event, which will reduce the forward extremities
  3289. # in the room.
  3290. #
  3291. # This setting defines the threshold (i.e. number of forward extremities in the
  3292. # room) at which dummy events are sent. The default value is 10.
  3293. #
  3294. #dummy_events_threshold: 5
  3295. ## Homeserver blocking ##
  3296. # How to reach the server admin, used in ResourceLimitError
  3297. #
  3298. #admin_contact: 'mailto:admin@server.com'
  3299. # Global blocking
  3300. #
  3301. #hs_disabled: false
  3302. #hs_disabled_message: 'Human readable reason for why the HS is blocked'
  3303. # Monthly Active User Blocking
  3304. #
  3305. # Used in cases where the admin or server owner wants to limit to the
  3306. # number of monthly active users.
  3307. #
  3308. # 'limit_usage_by_mau' disables/enables monthly active user blocking. When
  3309. # enabled and a limit is reached the server returns a 'ResourceLimitError'
  3310. # with error type Codes.RESOURCE_LIMIT_EXCEEDED
  3311. #
  3312. # 'max_mau_value' is the hard limit of monthly active users above which
  3313. # the server will start blocking user actions.
  3314. #
  3315. # 'mau_trial_days' is a means to add a grace period for active users. It
  3316. # means that users must be active for this number of days before they
  3317. # can be considered active and guards against the case where lots of users
  3318. # sign up in a short space of time never to return after their initial
  3319. # session.
  3320. #
  3321. # 'mau_limit_alerting' is a means of limiting client side alerting
  3322. # should the mau limit be reached. This is useful for small instances
  3323. # where the admin has 5 mau seats (say) for 5 specific people and no
  3324. # interest increasing the mau limit further. Defaults to True, which
  3325. # means that alerting is enabled
  3326. #
  3327. #limit_usage_by_mau: false
  3328. #max_mau_value: 50
  3329. #mau_trial_days: 2
  3330. #mau_limit_alerting: false
  3331. # If enabled, the metrics for the number of monthly active users will
  3332. # be populated, however no one will be limited. If limit_usage_by_mau
  3333. # is true, this is implied to be true.
  3334. #
  3335. #mau_stats_only: false
  3336. # Sometimes the server admin will want to ensure certain accounts are
  3337. # never blocked by mau checking. These accounts are specified here.
  3338. #
  3339. #mau_limit_reserved_threepids:
  3340. # - medium: 'email'
  3341. # address: 'reserved_user@example.com'
  3342. # Used by phonehome stats to group together related servers.
  3343. #server_context: context
  3344. # Resource-constrained homeserver settings
  3345. #
  3346. # When this is enabled, the room &quot;complexity&quot; will be checked before a user
  3347. # joins a new remote room. If it is above the complexity limit, the server will
  3348. # disallow joining, or will instantly leave.
  3349. #
  3350. # Room complexity is an arbitrary measure based on factors such as the number of
  3351. # users in the room.
  3352. #
  3353. limit_remote_rooms:
  3354. # Uncomment to enable room complexity checking.
  3355. #
  3356. #enabled: true
  3357. # the limit above which rooms cannot be joined. The default is 1.0.
  3358. #
  3359. #complexity: 0.5
  3360. # override the error which is returned when the room is too complex.
  3361. #
  3362. #complexity_error: &quot;This room is too complex.&quot;
  3363. # allow server admins to join complex rooms. Default is false.
  3364. #
  3365. #admins_can_join: true
  3366. # Whether to require a user to be in the room to add an alias to it.
  3367. # Defaults to 'true'.
  3368. #
  3369. #require_membership_for_aliases: false
  3370. # Whether to allow per-room membership profiles through the send of membership
  3371. # events with profile information that differ from the target's global profile.
  3372. # Defaults to 'true'.
  3373. #
  3374. #allow_per_room_profiles: false
  3375. # How long to keep redacted events in unredacted form in the database. After
  3376. # this period redacted events get replaced with their redacted form in the DB.
  3377. #
  3378. # Defaults to `7d`. Set to `null` to disable.
  3379. #
  3380. #redaction_retention_period: 28d
  3381. # How long to track users' last seen time and IPs in the database.
  3382. #
  3383. # Defaults to `28d`. Set to `null` to disable clearing out of old rows.
  3384. #
  3385. #user_ips_max_age: 14d
  3386. # Inhibits the /requestToken endpoints from returning an error that might leak
  3387. # information about whether an e-mail address is in use or not on this
  3388. # homeserver.
  3389. # Note that for some endpoints the error situation is the e-mail already being
  3390. # used, and for others the error is entering the e-mail being unused.
  3391. # If this option is enabled, instead of returning an error, these endpoints will
  3392. # act as if no error happened and return a fake session ID ('sid') to clients.
  3393. #
  3394. #request_token_inhibit_3pid_errors: true
  3395. # A list of domains that the domain portion of 'next_link' parameters
  3396. # must match.
  3397. #
  3398. # This parameter is optionally provided by clients while requesting
  3399. # validation of an email or phone number, and maps to a link that
  3400. # users will be automatically redirected to after validation
  3401. # succeeds. Clients can make use this parameter to aid the validation
  3402. # process.
  3403. #
  3404. # The whitelist is applied whether the homeserver or an
  3405. # identity server is handling validation.
  3406. #
  3407. # The default value is no whitelist functionality; all domains are
  3408. # allowed. Setting this value to an empty list will instead disallow
  3409. # all domains.
  3410. #
  3411. #next_link_domain_whitelist: [&quot;matrix.org&quot;]
  3412. # Templates to use when generating email or HTML page contents.
  3413. #
  3414. templates:
  3415. # Directory in which Synapse will try to find template files to use to generate
  3416. # email or HTML page contents.
  3417. # If not set, or a file is not found within the template directory, a default
  3418. # template from within the Synapse package will be used.
  3419. #
  3420. # See https://matrix-org.github.io/synapse/latest/templates.html for more
  3421. # information about using custom templates.
  3422. #
  3423. #custom_template_directory: /path/to/custom/templates/
  3424. # Message retention policy at the server level.
  3425. #
  3426. # Room admins and mods can define a retention period for their rooms using the
  3427. # 'm.room.retention' state event, and server admins can cap this period by setting
  3428. # the 'allowed_lifetime_min' and 'allowed_lifetime_max' config options.
  3429. #
  3430. # If this feature is enabled, Synapse will regularly look for and purge events
  3431. # which are older than the room's maximum retention period. Synapse will also
  3432. # filter events received over federation so that events that should have been
  3433. # purged are ignored and not stored again.
  3434. #
  3435. retention:
  3436. # The message retention policies feature is disabled by default. Uncomment the
  3437. # following line to enable it.
  3438. #
  3439. #enabled: true
  3440. # Default retention policy. If set, Synapse will apply it to rooms that lack the
  3441. # 'm.room.retention' state event. Currently, the value of 'min_lifetime' doesn't
  3442. # matter much because Synapse doesn't take it into account yet.
  3443. #
  3444. #default_policy:
  3445. # min_lifetime: 1d
  3446. # max_lifetime: 1y
  3447. # Retention policy limits. If set, and the state of a room contains a
  3448. # 'm.room.retention' event in its state which contains a 'min_lifetime' or a
  3449. # 'max_lifetime' that's out of these bounds, Synapse will cap the room's policy
  3450. # to these limits when running purge jobs.
  3451. #
  3452. #allowed_lifetime_min: 1d
  3453. #allowed_lifetime_max: 1y
  3454. # Server admins can define the settings of the background jobs purging the
  3455. # events which lifetime has expired under the 'purge_jobs' section.
  3456. #
  3457. # If no configuration is provided, a single job will be set up to delete expired
  3458. # events in every room daily.
  3459. #
  3460. # Each job's configuration defines which range of message lifetimes the job
  3461. # takes care of. For example, if 'shortest_max_lifetime' is '2d' and
  3462. # 'longest_max_lifetime' is '3d', the job will handle purging expired events in
  3463. # rooms whose state defines a 'max_lifetime' that's both higher than 2 days, and
  3464. # lower than or equal to 3 days. Both the minimum and the maximum value of a
  3465. # range are optional, e.g. a job with no 'shortest_max_lifetime' and a
  3466. # 'longest_max_lifetime' of '3d' will handle every room with a retention policy
  3467. # which 'max_lifetime' is lower than or equal to three days.
  3468. #
  3469. # The rationale for this per-job configuration is that some rooms might have a
  3470. # retention policy with a low 'max_lifetime', where history needs to be purged
  3471. # of outdated messages on a more frequent basis than for the rest of the rooms
  3472. # (e.g. every 12h), but not want that purge to be performed by a job that's
  3473. # iterating over every room it knows, which could be heavy on the server.
  3474. #
  3475. # If any purge job is configured, it is strongly recommended to have at least
  3476. # a single job with neither 'shortest_max_lifetime' nor 'longest_max_lifetime'
  3477. # set, or one job without 'shortest_max_lifetime' and one job without
  3478. # 'longest_max_lifetime' set. Otherwise some rooms might be ignored, even if
  3479. # 'allowed_lifetime_min' and 'allowed_lifetime_max' are set, because capping a
  3480. # room's policy to these values is done after the policies are retrieved from
  3481. # Synapse's database (which is done using the range specified in a purge job's
  3482. # configuration).
  3483. #
  3484. #purge_jobs:
  3485. # - longest_max_lifetime: 3d
  3486. # interval: 12h
  3487. # - shortest_max_lifetime: 3d
  3488. # interval: 1d
  3489. ## TLS ##
  3490. # PEM-encoded X509 certificate for TLS.
  3491. # This certificate, as of Synapse 1.0, will need to be a valid and verifiable
  3492. # certificate, signed by a recognised Certificate Authority.
  3493. #
  3494. # Be sure to use a `.pem` file that includes the full certificate chain including
  3495. # any intermediate certificates (for instance, if using certbot, use
  3496. # `fullchain.pem` as your certificate, not `cert.pem`).
  3497. #
  3498. #tls_certificate_path: &quot;CONFDIR/SERVERNAME.tls.crt&quot;
  3499. # PEM-encoded private key for TLS
  3500. #
  3501. #tls_private_key_path: &quot;CONFDIR/SERVERNAME.tls.key&quot;
  3502. # Whether to verify TLS server certificates for outbound federation requests.
  3503. #
  3504. # Defaults to `true`. To disable certificate verification, uncomment the
  3505. # following line.
  3506. #
  3507. #federation_verify_certificates: false
  3508. # The minimum TLS version that will be used for outbound federation requests.
  3509. #
  3510. # Defaults to `1`. Configurable to `1`, `1.1`, `1.2`, or `1.3`. Note
  3511. # that setting this value higher than `1.2` will prevent federation to most
  3512. # of the public Matrix network: only configure it to `1.3` if you have an
  3513. # entirely private federation setup and you can ensure TLS 1.3 support.
  3514. #
  3515. #federation_client_minimum_tls_version: 1.2
  3516. # Skip federation certificate verification on the following whitelist
  3517. # of domains.
  3518. #
  3519. # This setting should only be used in very specific cases, such as
  3520. # federation over Tor hidden services and similar. For private networks
  3521. # of homeservers, you likely want to use a private CA instead.
  3522. #
  3523. # Only effective if federation_verify_certicates is `true`.
  3524. #
  3525. #federation_certificate_verification_whitelist:
  3526. # - lon.example.com
  3527. # - *.domain.com
  3528. # - *.onion
  3529. # List of custom certificate authorities for federation traffic.
  3530. #
  3531. # This setting should only normally be used within a private network of
  3532. # homeservers.
  3533. #
  3534. # Note that this list will replace those that are provided by your
  3535. # operating environment. Certificates must be in PEM format.
  3536. #
  3537. #federation_custom_ca_list:
  3538. # - myCA1.pem
  3539. # - myCA2.pem
  3540. # - myCA3.pem
  3541. ## Federation ##
  3542. # Restrict federation to the following whitelist of domains.
  3543. # N.B. we recommend also firewalling your federation listener to limit
  3544. # inbound federation traffic as early as possible, rather than relying
  3545. # purely on this application-layer restriction. If not specified, the
  3546. # default is to whitelist everything.
  3547. #
  3548. #federation_domain_whitelist:
  3549. # - lon.example.com
  3550. # - nyc.example.com
  3551. # - syd.example.com
  3552. # Report prometheus metrics on the age of PDUs being sent to and received from
  3553. # the following domains. This can be used to give an idea of &quot;delay&quot; on inbound
  3554. # and outbound federation, though be aware that any delay can be due to problems
  3555. # at either end or with the intermediate network.
  3556. #
  3557. # By default, no domains are monitored in this way.
  3558. #
  3559. #federation_metrics_domains:
  3560. # - matrix.org
  3561. # - example.com
  3562. # Uncomment to disable profile lookup over federation. By default, the
  3563. # Federation API allows other homeservers to obtain profile data of any user
  3564. # on this homeserver. Defaults to 'true'.
  3565. #
  3566. #allow_profile_lookup_over_federation: false
  3567. # Uncomment to disable device display name lookup over federation. By default, the
  3568. # Federation API allows other homeservers to obtain device display names of any user
  3569. # on this homeserver. Defaults to 'true'.
  3570. #
  3571. #allow_device_name_lookup_over_federation: false
  3572. ## Caching ##
  3573. # Caching can be configured through the following options.
  3574. #
  3575. # A cache 'factor' is a multiplier that can be applied to each of
  3576. # Synapse's caches in order to increase or decrease the maximum
  3577. # number of entries that can be stored.
  3578. # The number of events to cache in memory. Not affected by
  3579. # caches.global_factor.
  3580. #
  3581. #event_cache_size: 10K
  3582. caches:
  3583. # Controls the global cache factor, which is the default cache factor
  3584. # for all caches if a specific factor for that cache is not otherwise
  3585. # set.
  3586. #
  3587. # This can also be set by the &quot;SYNAPSE_CACHE_FACTOR&quot; environment
  3588. # variable. Setting by environment variable takes priority over
  3589. # setting through the config file.
  3590. #
  3591. # Defaults to 0.5, which will half the size of all caches.
  3592. #
  3593. #global_factor: 1.0
  3594. # A dictionary of cache name to cache factor for that individual
  3595. # cache. Overrides the global cache factor for a given cache.
  3596. #
  3597. # These can also be set through environment variables comprised
  3598. # of &quot;SYNAPSE_CACHE_FACTOR_&quot; + the name of the cache in capital
  3599. # letters and underscores. Setting by environment variable
  3600. # takes priority over setting through the config file.
  3601. # Ex. SYNAPSE_CACHE_FACTOR_GET_USERS_WHO_SHARE_ROOM_WITH_USER=2.0
  3602. #
  3603. # Some caches have '*' and other characters that are not
  3604. # alphanumeric or underscores. These caches can be named with or
  3605. # without the special characters stripped. For example, to specify
  3606. # the cache factor for `*stateGroupCache*` via an environment
  3607. # variable would be `SYNAPSE_CACHE_FACTOR_STATEGROUPCACHE=2.0`.
  3608. #
  3609. per_cache_factors:
  3610. #get_users_who_share_room_with_user: 2.0
  3611. # Controls how long an entry can be in a cache without having been
  3612. # accessed before being evicted. Defaults to None, which means
  3613. # entries are never evicted based on time.
  3614. #
  3615. #expiry_time: 30m
  3616. # Controls how long the results of a /sync request are cached for after
  3617. # a successful response is returned. A higher duration can help clients with
  3618. # intermittent connections, at the cost of higher memory usage.
  3619. #
  3620. # By default, this is zero, which means that sync responses are not cached
  3621. # at all.
  3622. #
  3623. #sync_response_cache_duration: 2m
  3624. ## Database ##
  3625. # The 'database' setting defines the database that synapse uses to store all of
  3626. # its data.
  3627. #
  3628. # 'name' gives the database engine to use: either 'sqlite3' (for SQLite) or
  3629. # 'psycopg2' (for PostgreSQL).
  3630. #
  3631. # 'txn_limit' gives the maximum number of transactions to run per connection
  3632. # before reconnecting. Defaults to 0, which means no limit.
  3633. #
  3634. # 'args' gives options which are passed through to the database engine,
  3635. # except for options starting 'cp_', which are used to configure the Twisted
  3636. # connection pool. For a reference to valid arguments, see:
  3637. # * for sqlite: https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
  3638. # * for postgres: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
  3639. # * for the connection pool: https://twistedmatrix.com/documents/current/api/twisted.enterprise.adbapi.ConnectionPool.html#__init__
  3640. #
  3641. #
  3642. # Example SQLite configuration:
  3643. #
  3644. #database:
  3645. # name: sqlite3
  3646. # args:
  3647. # database: /path/to/homeserver.db
  3648. #
  3649. #
  3650. # Example Postgres configuration:
  3651. #
  3652. #database:
  3653. # name: psycopg2
  3654. # txn_limit: 10000
  3655. # args:
  3656. # user: synapse_user
  3657. # password: secretpassword
  3658. # database: synapse
  3659. # host: localhost
  3660. # port: 5432
  3661. # cp_min: 5
  3662. # cp_max: 10
  3663. #
  3664. # For more information on using Synapse with Postgres,
  3665. # see https://matrix-org.github.io/synapse/latest/postgres.html.
  3666. #
  3667. database:
  3668. name: sqlite3
  3669. args:
  3670. database: DATADIR/homeserver.db
  3671. ## Logging ##
  3672. # A yaml python logging config file as described by
  3673. # https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  3674. #
  3675. log_config: &quot;CONFDIR/SERVERNAME.log.config&quot;
  3676. ## Ratelimiting ##
  3677. # Ratelimiting settings for client actions (registration, login, messaging).
  3678. #
  3679. # Each ratelimiting configuration is made of two parameters:
  3680. # - per_second: number of requests a client can send per second.
  3681. # - burst_count: number of requests a client can send before being throttled.
  3682. #
  3683. # Synapse currently uses the following configurations:
  3684. # - one for messages that ratelimits sending based on the account the client
  3685. # is using
  3686. # - one for registration that ratelimits registration requests based on the
  3687. # client's IP address.
  3688. # - one for checking the validity of registration tokens that ratelimits
  3689. # requests based on the client's IP address.
  3690. # - one for login that ratelimits login requests based on the client's IP
  3691. # address.
  3692. # - one for login that ratelimits login requests based on the account the
  3693. # client is attempting to log into.
  3694. # - one for login that ratelimits login requests based on the account the
  3695. # client is attempting to log into, based on the amount of failed login
  3696. # attempts for this account.
  3697. # - one for ratelimiting redactions by room admins. If this is not explicitly
  3698. # set then it uses the same ratelimiting as per rc_message. This is useful
  3699. # to allow room admins to deal with abuse quickly.
  3700. # - two for ratelimiting number of rooms a user can join, &quot;local&quot; for when
  3701. # users are joining rooms the server is already in (this is cheap) vs
  3702. # &quot;remote&quot; for when users are trying to join rooms not on the server (which
  3703. # can be more expensive)
  3704. # - one for ratelimiting how often a user or IP can attempt to validate a 3PID.
  3705. # - two for ratelimiting how often invites can be sent in a room or to a
  3706. # specific user.
  3707. #
  3708. # The defaults are as shown below.
  3709. #
  3710. #rc_message:
  3711. # per_second: 0.2
  3712. # burst_count: 10
  3713. #
  3714. #rc_registration:
  3715. # per_second: 0.17
  3716. # burst_count: 3
  3717. #
  3718. #rc_registration_token_validity:
  3719. # per_second: 0.1
  3720. # burst_count: 5
  3721. #
  3722. #rc_login:
  3723. # address:
  3724. # per_second: 0.17
  3725. # burst_count: 3
  3726. # account:
  3727. # per_second: 0.17
  3728. # burst_count: 3
  3729. # failed_attempts:
  3730. # per_second: 0.17
  3731. # burst_count: 3
  3732. #
  3733. #rc_admin_redaction:
  3734. # per_second: 1
  3735. # burst_count: 50
  3736. #
  3737. #rc_joins:
  3738. # local:
  3739. # per_second: 0.1
  3740. # burst_count: 10
  3741. # remote:
  3742. # per_second: 0.01
  3743. # burst_count: 10
  3744. #
  3745. #rc_3pid_validation:
  3746. # per_second: 0.003
  3747. # burst_count: 5
  3748. #
  3749. #rc_invites:
  3750. # per_room:
  3751. # per_second: 0.3
  3752. # burst_count: 10
  3753. # per_user:
  3754. # per_second: 0.003
  3755. # burst_count: 5
  3756. # Ratelimiting settings for incoming federation
  3757. #
  3758. # The rc_federation configuration is made up of the following settings:
  3759. # - window_size: window size in milliseconds
  3760. # - sleep_limit: number of federation requests from a single server in
  3761. # a window before the server will delay processing the request.
  3762. # - sleep_delay: duration in milliseconds to delay processing events
  3763. # from remote servers by if they go over the sleep limit.
  3764. # - reject_limit: maximum number of concurrent federation requests
  3765. # allowed from a single server
  3766. # - concurrent: number of federation requests to concurrently process
  3767. # from a single server
  3768. #
  3769. # The defaults are as shown below.
  3770. #
  3771. #rc_federation:
  3772. # window_size: 1000
  3773. # sleep_limit: 10
  3774. # sleep_delay: 500
  3775. # reject_limit: 50
  3776. # concurrent: 3
  3777. # Target outgoing federation transaction frequency for sending read-receipts,
  3778. # per-room.
  3779. #
  3780. # If we end up trying to send out more read-receipts, they will get buffered up
  3781. # into fewer transactions.
  3782. #
  3783. #federation_rr_transactions_per_room_per_second: 50
  3784. ## Media Store ##
  3785. # Enable the media store service in the Synapse master. Uncomment the
  3786. # following if you are using a separate media store worker.
  3787. #
  3788. #enable_media_repo: false
  3789. # Directory where uploaded images and attachments are stored.
  3790. #
  3791. media_store_path: &quot;DATADIR/media_store&quot;
  3792. # Media storage providers allow media to be stored in different
  3793. # locations.
  3794. #
  3795. #media_storage_providers:
  3796. # - module: file_system
  3797. # # Whether to store newly uploaded local files
  3798. # store_local: false
  3799. # # Whether to store newly downloaded remote files
  3800. # store_remote: false
  3801. # # Whether to wait for successful storage for local uploads
  3802. # store_synchronous: false
  3803. # config:
  3804. # directory: /mnt/some/other/directory
  3805. # The largest allowed upload size in bytes
  3806. #
  3807. # If you are using a reverse proxy you may also need to set this value in
  3808. # your reverse proxy's config. Notably Nginx has a small max body size by default.
  3809. # See https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3810. #
  3811. #max_upload_size: 50M
  3812. # Maximum number of pixels that will be thumbnailed
  3813. #
  3814. #max_image_pixels: 32M
  3815. # Whether to generate new thumbnails on the fly to precisely match
  3816. # the resolution requested by the client. If true then whenever
  3817. # a new resolution is requested by the client the server will
  3818. # generate a new thumbnail. If false the server will pick a thumbnail
  3819. # from a precalculated list.
  3820. #
  3821. #dynamic_thumbnails: false
  3822. # List of thumbnails to precalculate when an image is uploaded.
  3823. #
  3824. #thumbnail_sizes:
  3825. # - width: 32
  3826. # height: 32
  3827. # method: crop
  3828. # - width: 96
  3829. # height: 96
  3830. # method: crop
  3831. # - width: 320
  3832. # height: 240
  3833. # method: scale
  3834. # - width: 640
  3835. # height: 480
  3836. # method: scale
  3837. # - width: 800
  3838. # height: 600
  3839. # method: scale
  3840. # Is the preview URL API enabled?
  3841. #
  3842. # 'false' by default: uncomment the following to enable it (and specify a
  3843. # url_preview_ip_range_blacklist blacklist).
  3844. #
  3845. #url_preview_enabled: true
  3846. # List of IP address CIDR ranges that the URL preview spider is denied
  3847. # from accessing. There are no defaults: you must explicitly
  3848. # specify a list for URL previewing to work. You should specify any
  3849. # internal services in your network that you do not want synapse to try
  3850. # to connect to, otherwise anyone in any Matrix room could cause your
  3851. # synapse to issue arbitrary GET requests to your internal services,
  3852. # causing serious security issues.
  3853. #
  3854. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3855. # listed here, since they correspond to unroutable addresses.)
  3856. #
  3857. # This must be specified if url_preview_enabled is set. It is recommended that
  3858. # you uncomment the following list as a starting point.
  3859. #
  3860. # Note: The value is ignored when an HTTP proxy is in use
  3861. #
  3862. #url_preview_ip_range_blacklist:
  3863. # - '127.0.0.0/8'
  3864. # - '10.0.0.0/8'
  3865. # - '172.16.0.0/12'
  3866. # - '192.168.0.0/16'
  3867. # - '100.64.0.0/10'
  3868. # - '192.0.0.0/24'
  3869. # - '169.254.0.0/16'
  3870. # - '192.88.99.0/24'
  3871. # - '198.18.0.0/15'
  3872. # - '192.0.2.0/24'
  3873. # - '198.51.100.0/24'
  3874. # - '203.0.113.0/24'
  3875. # - '224.0.0.0/4'
  3876. # - '::1/128'
  3877. # - 'fe80::/10'
  3878. # - 'fc00::/7'
  3879. # - '2001:db8::/32'
  3880. # - 'ff00::/8'
  3881. # - 'fec0::/10'
  3882. # List of IP address CIDR ranges that the URL preview spider is allowed
  3883. # to access even if they are specified in url_preview_ip_range_blacklist.
  3884. # This is useful for specifying exceptions to wide-ranging blacklisted
  3885. # target IP ranges - e.g. for enabling URL previews for a specific private
  3886. # website only visible in your network.
  3887. #
  3888. #url_preview_ip_range_whitelist:
  3889. # - '192.168.1.1'
  3890. # Optional list of URL matches that the URL preview spider is
  3891. # denied from accessing. You should use url_preview_ip_range_blacklist
  3892. # in preference to this, otherwise someone could define a public DNS
  3893. # entry that points to a private IP address and circumvent the blacklist.
  3894. # This is more useful if you know there is an entire shape of URL that
  3895. # you know that will never want synapse to try to spider.
  3896. #
  3897. # Each list entry is a dictionary of url component attributes as returned
  3898. # by urlparse.urlsplit as applied to the absolute form of the URL. See
  3899. # https://docs.python.org/2/library/urlparse.html#urlparse.urlsplit
  3900. # The values of the dictionary are treated as an filename match pattern
  3901. # applied to that component of URLs, unless they start with a ^ in which
  3902. # case they are treated as a regular expression match. If all the
  3903. # specified component matches for a given list item succeed, the URL is
  3904. # blacklisted.
  3905. #
  3906. #url_preview_url_blacklist:
  3907. # # blacklist any URL with a username in its URI
  3908. # - username: '*'
  3909. #
  3910. # # blacklist all *.google.com URLs
  3911. # - netloc: 'google.com'
  3912. # - netloc: '*.google.com'
  3913. #
  3914. # # blacklist all plain HTTP URLs
  3915. # - scheme: 'http'
  3916. #
  3917. # # blacklist http(s)://www.acme.com/foo
  3918. # - netloc: 'www.acme.com'
  3919. # path: '/foo'
  3920. #
  3921. # # blacklist any URL with a literal IPv4 address
  3922. # - netloc: '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  3923. # The largest allowed URL preview spidering size in bytes
  3924. #
  3925. #max_spider_size: 10M
  3926. # A list of values for the Accept-Language HTTP header used when
  3927. # downloading webpages during URL preview generation. This allows
  3928. # Synapse to specify the preferred languages that URL previews should
  3929. # be in when communicating with remote servers.
  3930. #
  3931. # Each value is a IETF language tag; a 2-3 letter identifier for a
  3932. # language, optionally followed by subtags separated by '-', specifying
  3933. # a country or region variant.
  3934. #
  3935. # Multiple values can be provided, and a weight can be added to each by
  3936. # using quality value syntax (;q=). '*' translates to any language.
  3937. #
  3938. # Defaults to &quot;en&quot;.
  3939. #
  3940. # Example:
  3941. #
  3942. # url_preview_accept_language:
  3943. # - en-UK
  3944. # - en-US;q=0.9
  3945. # - fr;q=0.8
  3946. # - *;q=0.7
  3947. #
  3948. url_preview_accept_language:
  3949. # - en
  3950. # oEmbed allows for easier embedding content from a website. It can be
  3951. # used for generating URLs previews of services which support it.
  3952. #
  3953. oembed:
  3954. # A default list of oEmbed providers is included with Synapse.
  3955. #
  3956. # Uncomment the following to disable using these default oEmbed URLs.
  3957. # Defaults to 'false'.
  3958. #
  3959. #disable_default_providers: true
  3960. # Additional files with oEmbed configuration (each should be in the
  3961. # form of providers.json).
  3962. #
  3963. # By default, this list is empty (so only the default providers.json
  3964. # is used).
  3965. #
  3966. #additional_providers:
  3967. # - oembed/my_providers.json
  3968. ## Captcha ##
  3969. # See docs/CAPTCHA_SETUP.md for full details of configuring this.
  3970. # This homeserver's ReCAPTCHA public key. Must be specified if
  3971. # enable_registration_captcha is enabled.
  3972. #
  3973. #recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  3974. # This homeserver's ReCAPTCHA private key. Must be specified if
  3975. # enable_registration_captcha is enabled.
  3976. #
  3977. #recaptcha_private_key: &quot;YOUR_PRIVATE_KEY&quot;
  3978. # Uncomment to enable ReCaptcha checks when registering, preventing signup
  3979. # unless a captcha is answered. Requires a valid ReCaptcha
  3980. # public/private key. Defaults to 'false'.
  3981. #
  3982. #enable_registration_captcha: true
  3983. # The API endpoint to use for verifying m.login.recaptcha responses.
  3984. # Defaults to &quot;https://www.recaptcha.net/recaptcha/api/siteverify&quot;.
  3985. #
  3986. #recaptcha_siteverify_api: &quot;https://my.recaptcha.site&quot;
  3987. ## TURN ##
  3988. # The public URIs of the TURN server to give to clients
  3989. #
  3990. #turn_uris: []
  3991. # The shared secret used to compute passwords for the TURN server
  3992. #
  3993. #turn_shared_secret: &quot;YOUR_SHARED_SECRET&quot;
  3994. # The Username and password if the TURN server needs them and
  3995. # does not use a token
  3996. #
  3997. #turn_username: &quot;TURNSERVER_USERNAME&quot;
  3998. #turn_password: &quot;TURNSERVER_PASSWORD&quot;
  3999. # How long generated TURN credentials last
  4000. #
  4001. #turn_user_lifetime: 1h
  4002. # Whether guests should be allowed to use the TURN server.
  4003. # This defaults to True, otherwise VoIP will be unreliable for guests.
  4004. # However, it does introduce a slight security risk as it allows users to
  4005. # connect to arbitrary endpoints without having first signed up for a
  4006. # valid account (e.g. by passing a CAPTCHA).
  4007. #
  4008. #turn_allow_guests: true
  4009. ## Registration ##
  4010. #
  4011. # Registration can be rate-limited using the parameters in the &quot;Ratelimiting&quot;
  4012. # section of this file.
  4013. # Enable registration for new users.
  4014. #
  4015. #enable_registration: false
  4016. # Time that a user's session remains valid for, after they log in.
  4017. #
  4018. # Note that this is not currently compatible with guest logins.
  4019. #
  4020. # Note also that this is calculated at login time: changes are not applied
  4021. # retrospectively to users who have already logged in.
  4022. #
  4023. # By default, this is infinite.
  4024. #
  4025. #session_lifetime: 24h
  4026. # The user must provide all of the below types of 3PID when registering.
  4027. #
  4028. #registrations_require_3pid:
  4029. # - email
  4030. # - msisdn
  4031. # Explicitly disable asking for MSISDNs from the registration
  4032. # flow (overrides registrations_require_3pid if MSISDNs are set as required)
  4033. #
  4034. #disable_msisdn_registration: true
  4035. # Mandate that users are only allowed to associate certain formats of
  4036. # 3PIDs with accounts on this server.
  4037. #
  4038. #allowed_local_3pids:
  4039. # - medium: email
  4040. # pattern: '^[^@]+@matrix\.org$'
  4041. # - medium: email
  4042. # pattern: '^[^@]+@vector\.im$'
  4043. # - medium: msisdn
  4044. # pattern: '\+44'
  4045. # Enable 3PIDs lookup requests to identity servers from this server.
  4046. #
  4047. #enable_3pid_lookup: true
  4048. # Require users to submit a token during registration.
  4049. # Tokens can be managed using the admin API:
  4050. # https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/registration_tokens.html
  4051. # Note that `enable_registration` must be set to `true`.
  4052. # Disabling this option will not delete any tokens previously generated.
  4053. # Defaults to false. Uncomment the following to require tokens:
  4054. #
  4055. #registration_requires_token: true
  4056. # If set, allows registration of standard or admin accounts by anyone who
  4057. # has the shared secret, even if registration is otherwise disabled.
  4058. #
  4059. #registration_shared_secret: &lt;PRIVATE STRING&gt;
  4060. # Set the number of bcrypt rounds used to generate password hash.
  4061. # Larger numbers increase the work factor needed to generate the hash.
  4062. # The default number is 12 (which equates to 2^12 rounds).
  4063. # N.B. that increasing this will exponentially increase the time required
  4064. # to register or login - e.g. 24 =&gt; 2^24 rounds which will take &gt;20 mins.
  4065. #
  4066. #bcrypt_rounds: 12
  4067. # Allows users to register as guests without a password/email/etc, and
  4068. # participate in rooms hosted on this server which have been made
  4069. # accessible to anonymous users.
  4070. #
  4071. #allow_guest_access: false
  4072. # The identity server which we suggest that clients should use when users log
  4073. # in on this server.
  4074. #
  4075. # (By default, no suggestion is made, so it is left up to the client.
  4076. # This setting is ignored unless public_baseurl is also set.)
  4077. #
  4078. #default_identity_server: https://matrix.org
  4079. # Handle threepid (email/phone etc) registration and password resets through a set of
  4080. # *trusted* identity servers. Note that this allows the configured identity server to
  4081. # reset passwords for accounts!
  4082. #
  4083. # Be aware that if `email` is not set, and SMTP options have not been
  4084. # configured in the email config block, registration and user password resets via
  4085. # email will be globally disabled.
  4086. #
  4087. # Additionally, if `msisdn` is not set, registration and password resets via msisdn
  4088. # will be disabled regardless, and users will not be able to associate an msisdn
  4089. # identifier to their account. This is due to Synapse currently not supporting
  4090. # any method of sending SMS messages on its own.
  4091. #
  4092. # To enable using an identity server for operations regarding a particular third-party
  4093. # identifier type, set the value to the URL of that identity server as shown in the
  4094. # examples below.
  4095. #
  4096. # Servers handling the these requests must answer the `/requestToken` endpoints defined
  4097. # by the Matrix Identity Service API specification:
  4098. # https://matrix.org/docs/spec/identity_service/latest
  4099. #
  4100. # If a delegate is specified, the config option public_baseurl must also be filled out.
  4101. #
  4102. account_threepid_delegates:
  4103. #email: https://example.com # Delegate email sending to example.com
  4104. #msisdn: http://localhost:8090 # Delegate SMS sending to this local process
  4105. # Whether users are allowed to change their displayname after it has
  4106. # been initially set. Useful when provisioning users based on the
  4107. # contents of a third-party directory.
  4108. #
  4109. # Does not apply to server administrators. Defaults to 'true'
  4110. #
  4111. #enable_set_displayname: false
  4112. # Whether users are allowed to change their avatar after it has been
  4113. # initially set. Useful when provisioning users based on the contents
  4114. # of a third-party directory.
  4115. #
  4116. # Does not apply to server administrators. Defaults to 'true'
  4117. #
  4118. #enable_set_avatar_url: false
  4119. # Whether users can change the 3PIDs associated with their accounts
  4120. # (email address and msisdn).
  4121. #
  4122. # Defaults to 'true'
  4123. #
  4124. #enable_3pid_changes: false
  4125. # Users who register on this homeserver will automatically be joined
  4126. # to these rooms.
  4127. #
  4128. # By default, any room aliases included in this list will be created
  4129. # as a publicly joinable room when the first user registers for the
  4130. # homeserver. This behaviour can be customised with the settings below.
  4131. # If the room already exists, make certain it is a publicly joinable
  4132. # room. The join rule of the room must be set to 'public'.
  4133. #
  4134. #auto_join_rooms:
  4135. # - &quot;#example:example.com&quot;
  4136. # Where auto_join_rooms are specified, setting this flag ensures that the
  4137. # the rooms exist by creating them when the first user on the
  4138. # homeserver registers.
  4139. #
  4140. # By default the auto-created rooms are publicly joinable from any federated
  4141. # server. Use the autocreate_auto_join_rooms_federated and
  4142. # autocreate_auto_join_room_preset settings below to customise this behaviour.
  4143. #
  4144. # Setting to false means that if the rooms are not manually created,
  4145. # users cannot be auto-joined since they do not exist.
  4146. #
  4147. # Defaults to true. Uncomment the following line to disable automatically
  4148. # creating auto-join rooms.
  4149. #
  4150. #autocreate_auto_join_rooms: false
  4151. # Whether the auto_join_rooms that are auto-created are available via
  4152. # federation. Only has an effect if autocreate_auto_join_rooms is true.
  4153. #
  4154. # Note that whether a room is federated cannot be modified after
  4155. # creation.
  4156. #
  4157. # Defaults to true: the room will be joinable from other servers.
  4158. # Uncomment the following to prevent users from other homeservers from
  4159. # joining these rooms.
  4160. #
  4161. #autocreate_auto_join_rooms_federated: false
  4162. # The room preset to use when auto-creating one of auto_join_rooms. Only has an
  4163. # effect if autocreate_auto_join_rooms is true.
  4164. #
  4165. # This can be one of &quot;public_chat&quot;, &quot;private_chat&quot;, or &quot;trusted_private_chat&quot;.
  4166. # If a value of &quot;private_chat&quot; or &quot;trusted_private_chat&quot; is used then
  4167. # auto_join_mxid_localpart must also be configured.
  4168. #
  4169. # Defaults to &quot;public_chat&quot;, meaning that the room is joinable by anyone, including
  4170. # federated servers if autocreate_auto_join_rooms_federated is true (the default).
  4171. # Uncomment the following to require an invitation to join these rooms.
  4172. #
  4173. #autocreate_auto_join_room_preset: private_chat
  4174. # The local part of the user id which is used to create auto_join_rooms if
  4175. # autocreate_auto_join_rooms is true. If this is not provided then the
  4176. # initial user account that registers will be used to create the rooms.
  4177. #
  4178. # The user id is also used to invite new users to any auto-join rooms which
  4179. # are set to invite-only.
  4180. #
  4181. # It *must* be configured if autocreate_auto_join_room_preset is set to
  4182. # &quot;private_chat&quot; or &quot;trusted_private_chat&quot;.
  4183. #
  4184. # Note that this must be specified in order for new users to be correctly
  4185. # invited to any auto-join rooms which have been set to invite-only (either
  4186. # at the time of creation or subsequently).
  4187. #
  4188. # Note that, if the room already exists, this user must be joined and
  4189. # have the appropriate permissions to invite new members.
  4190. #
  4191. #auto_join_mxid_localpart: system
  4192. # When auto_join_rooms is specified, setting this flag to false prevents
  4193. # guest accounts from being automatically joined to the rooms.
  4194. #
  4195. # Defaults to true.
  4196. #
  4197. #auto_join_rooms_for_guests: false
  4198. ## Metrics ###
  4199. # Enable collection and rendering of performance metrics
  4200. #
  4201. #enable_metrics: false
  4202. # Enable sentry integration
  4203. # NOTE: While attempts are made to ensure that the logs don't contain
  4204. # any sensitive information, this cannot be guaranteed. By enabling
  4205. # this option the sentry server may therefore receive sensitive
  4206. # information, and it in turn may then diseminate sensitive information
  4207. # through insecure notification channels if so configured.
  4208. #
  4209. #sentry:
  4210. # dsn: &quot;...&quot;
  4211. # Flags to enable Prometheus metrics which are not suitable to be
  4212. # enabled by default, either for performance reasons or limited use.
  4213. #
  4214. metrics_flags:
  4215. # Publish synapse_federation_known_servers, a gauge of the number of
  4216. # servers this homeserver knows about, including itself. May cause
  4217. # performance problems on large homeservers.
  4218. #
  4219. #known_servers: true
  4220. # Whether or not to report anonymized homeserver usage statistics.
  4221. #
  4222. #report_stats: true|false
  4223. # The endpoint to report the anonymized homeserver usage statistics to.
  4224. # Defaults to https://matrix.org/report-usage-stats/push
  4225. #
  4226. #report_stats_endpoint: https://example.com/report-usage-stats/push
  4227. ## API Configuration ##
  4228. # Controls for the state that is shared with users who receive an invite
  4229. # to a room
  4230. #
  4231. room_prejoin_state:
  4232. # By default, the following state event types are shared with users who
  4233. # receive invites to the room:
  4234. #
  4235. # - m.room.join_rules
  4236. # - m.room.canonical_alias
  4237. # - m.room.avatar
  4238. # - m.room.encryption
  4239. # - m.room.name
  4240. # - m.room.create
  4241. #
  4242. # Uncomment the following to disable these defaults (so that only the event
  4243. # types listed in 'additional_event_types' are shared). Defaults to 'false'.
  4244. #
  4245. #disable_default_event_types: true
  4246. # Additional state event types to share with users when they are invited
  4247. # to a room.
  4248. #
  4249. # By default, this list is empty (so only the default event types are shared).
  4250. #
  4251. #additional_event_types:
  4252. # - org.example.custom.event.type
  4253. # A list of application service config files to use
  4254. #
  4255. #app_service_config_files:
  4256. # - app_service_1.yaml
  4257. # - app_service_2.yaml
  4258. # Uncomment to enable tracking of application service IP addresses. Implicitly
  4259. # enables MAU tracking for application service users.
  4260. #
  4261. #track_appservice_user_ips: true
  4262. # a secret which is used to sign access tokens. If none is specified,
  4263. # the registration_shared_secret is used, if one is given; otherwise,
  4264. # a secret key is derived from the signing key.
  4265. #
  4266. #macaroon_secret_key: &lt;PRIVATE STRING&gt;
  4267. # a secret which is used to calculate HMACs for form values, to stop
  4268. # falsification of values. Must be specified for the User Consent
  4269. # forms to work.
  4270. #
  4271. #form_secret: &lt;PRIVATE STRING&gt;
  4272. ## Signing Keys ##
  4273. # Path to the signing key to sign messages with
  4274. #
  4275. signing_key_path: &quot;CONFDIR/SERVERNAME.signing.key&quot;
  4276. # The keys that the server used to sign messages with but won't use
  4277. # to sign new messages.
  4278. #
  4279. old_signing_keys:
  4280. # For each key, `key` should be the base64-encoded public key, and
  4281. # `expired_ts`should be the time (in milliseconds since the unix epoch) that
  4282. # it was last used.
  4283. #
  4284. # It is possible to build an entry from an old signing.key file using the
  4285. # `export_signing_key` script which is provided with synapse.
  4286. #
  4287. # For example:
  4288. #
  4289. #&quot;ed25519:id&quot;: { key: &quot;base64string&quot;, expired_ts: 123456789123 }
  4290. # How long key response published by this server is valid for.
  4291. # Used to set the valid_until_ts in /key/v2 APIs.
  4292. # Determines how quickly servers will query to check which keys
  4293. # are still valid.
  4294. #
  4295. #key_refresh_interval: 1d
  4296. # The trusted servers to download signing keys from.
  4297. #
  4298. # When we need to fetch a signing key, each server is tried in parallel.
  4299. #
  4300. # Normally, the connection to the key server is validated via TLS certificates.
  4301. # Additional security can be provided by configuring a `verify key`, which
  4302. # will make synapse check that the response is signed by that key.
  4303. #
  4304. # This setting supercedes an older setting named `perspectives`. The old format
  4305. # is still supported for backwards-compatibility, but it is deprecated.
  4306. #
  4307. # 'trusted_key_servers' defaults to matrix.org, but using it will generate a
  4308. # warning on start-up. To suppress this warning, set
  4309. # 'suppress_key_server_warning' to true.
  4310. #
  4311. # Options for each entry in the list include:
  4312. #
  4313. # server_name: the name of the server. required.
  4314. #
  4315. # verify_keys: an optional map from key id to base64-encoded public key.
  4316. # If specified, we will check that the response is signed by at least
  4317. # one of the given keys.
  4318. #
  4319. # accept_keys_insecurely: a boolean. Normally, if `verify_keys` is unset,
  4320. # and federation_verify_certificates is not `true`, synapse will refuse
  4321. # to start, because this would allow anyone who can spoof DNS responses
  4322. # to masquerade as the trusted key server. If you know what you are doing
  4323. # and are sure that your network environment provides a secure connection
  4324. # to the key server, you can set this to `true` to override this
  4325. # behaviour.
  4326. #
  4327. # An example configuration might look like:
  4328. #
  4329. #trusted_key_servers:
  4330. # - server_name: &quot;my_trusted_server.example.com&quot;
  4331. # verify_keys:
  4332. # &quot;ed25519:auto&quot;: &quot;abcdefghijklmnopqrstuvwxyzabcdefghijklmopqr&quot;
  4333. # - server_name: &quot;my_other_trusted_server.example.com&quot;
  4334. #
  4335. trusted_key_servers:
  4336. - server_name: &quot;matrix.org&quot;
  4337. # Uncomment the following to disable the warning that is emitted when the
  4338. # trusted_key_servers include 'matrix.org'. See above.
  4339. #
  4340. #suppress_key_server_warning: true
  4341. # The signing keys to use when acting as a trusted key server. If not specified
  4342. # defaults to the server signing key.
  4343. #
  4344. # Can contain multiple keys, one per line.
  4345. #
  4346. #key_server_signing_keys_path: &quot;key_server_signing_keys.key&quot;
  4347. ## Single sign-on integration ##
  4348. # The following settings can be used to make Synapse use a single sign-on
  4349. # provider for authentication, instead of its internal password database.
  4350. #
  4351. # You will probably also want to set the following options to `false` to
  4352. # disable the regular login/registration flows:
  4353. # * enable_registration
  4354. # * password_config.enabled
  4355. #
  4356. # You will also want to investigate the settings under the &quot;sso&quot; configuration
  4357. # section below.
  4358. # Enable SAML2 for registration and login. Uses pysaml2.
  4359. #
  4360. # At least one of `sp_config` or `config_path` must be set in this section to
  4361. # enable SAML login.
  4362. #
  4363. # Once SAML support is enabled, a metadata file will be exposed at
  4364. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/metadata.xml, which you may be able to
  4365. # use to configure your SAML IdP with. Alternatively, you can manually configure
  4366. # the IdP to use an ACS location of
  4367. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/authn_response.
  4368. #
  4369. saml2_config:
  4370. # `sp_config` is the configuration for the pysaml2 Service Provider.
  4371. # See pysaml2 docs for format of config.
  4372. #
  4373. # Default values will be used for the 'entityid' and 'service' settings,
  4374. # so it is not normally necessary to specify them unless you need to
  4375. # override them.
  4376. #
  4377. sp_config:
  4378. # Point this to the IdP's metadata. You must provide either a local
  4379. # file via the `local` attribute or (preferably) a URL via the
  4380. # `remote` attribute.
  4381. #
  4382. #metadata:
  4383. # local: [&quot;saml2/idp.xml&quot;]
  4384. # remote:
  4385. # - url: https://our_idp/metadata.xml
  4386. # Allowed clock difference in seconds between the homeserver and IdP.
  4387. #
  4388. # Uncomment the below to increase the accepted time difference from 0 to 3 seconds.
  4389. #
  4390. #accepted_time_diff: 3
  4391. # By default, the user has to go to our login page first. If you'd like
  4392. # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
  4393. # 'service.sp' section:
  4394. #
  4395. #service:
  4396. # sp:
  4397. # allow_unsolicited: true
  4398. # The examples below are just used to generate our metadata xml, and you
  4399. # may well not need them, depending on your setup. Alternatively you
  4400. # may need a whole lot more detail - see the pysaml2 docs!
  4401. #description: [&quot;My awesome SP&quot;, &quot;en&quot;]
  4402. #name: [&quot;Test SP&quot;, &quot;en&quot;]
  4403. #ui_info:
  4404. # display_name:
  4405. # - lang: en
  4406. # text: &quot;Display Name is the descriptive name of your service.&quot;
  4407. # description:
  4408. # - lang: en
  4409. # text: &quot;Description should be a short paragraph explaining the purpose of the service.&quot;
  4410. # information_url:
  4411. # - lang: en
  4412. # text: &quot;https://example.com/terms-of-service&quot;
  4413. # privacy_statement_url:
  4414. # - lang: en
  4415. # text: &quot;https://example.com/privacy-policy&quot;
  4416. # keywords:
  4417. # - lang: en
  4418. # text: [&quot;Matrix&quot;, &quot;Element&quot;]
  4419. # logo:
  4420. # - lang: en
  4421. # text: &quot;https://example.com/logo.svg&quot;
  4422. # width: &quot;200&quot;
  4423. # height: &quot;80&quot;
  4424. #organization:
  4425. # name: Example com
  4426. # display_name:
  4427. # - [&quot;Example co&quot;, &quot;en&quot;]
  4428. # url: &quot;http://example.com&quot;
  4429. #contact_person:
  4430. # - given_name: Bob
  4431. # sur_name: &quot;the Sysadmin&quot;
  4432. # email_address&quot;: [&quot;admin@example.com&quot;]
  4433. # contact_type&quot;: technical
  4434. # Instead of putting the config inline as above, you can specify a
  4435. # separate pysaml2 configuration file:
  4436. #
  4437. #config_path: &quot;CONFDIR/sp_conf.py&quot;
  4438. # The lifetime of a SAML session. This defines how long a user has to
  4439. # complete the authentication process, if allow_unsolicited is unset.
  4440. # The default is 15 minutes.
  4441. #
  4442. #saml_session_lifetime: 5m
  4443. # An external module can be provided here as a custom solution to
  4444. # mapping attributes returned from a saml provider onto a matrix user.
  4445. #
  4446. user_mapping_provider:
  4447. # The custom module's class. Uncomment to use a custom module.
  4448. #
  4449. #module: mapping_provider.SamlMappingProvider
  4450. # Custom configuration values for the module. Below options are
  4451. # intended for the built-in provider, they should be changed if
  4452. # using a custom module. This section will be passed as a Python
  4453. # dictionary to the module's `parse_config` method.
  4454. #
  4455. config:
  4456. # The SAML attribute (after mapping via the attribute maps) to use
  4457. # to derive the Matrix ID from. 'uid' by default.
  4458. #
  4459. # Note: This used to be configured by the
  4460. # saml2_config.mxid_source_attribute option. If that is still
  4461. # defined, its value will be used instead.
  4462. #
  4463. #mxid_source_attribute: displayName
  4464. # The mapping system to use for mapping the saml attribute onto a
  4465. # matrix ID.
  4466. #
  4467. # Options include:
  4468. # * 'hexencode' (which maps unpermitted characters to '=xx')
  4469. # * 'dotreplace' (which replaces unpermitted characters with
  4470. # '.').
  4471. # The default is 'hexencode'.
  4472. #
  4473. # Note: This used to be configured by the
  4474. # saml2_config.mxid_mapping option. If that is still defined, its
  4475. # value will be used instead.
  4476. #
  4477. #mxid_mapping: dotreplace
  4478. # In previous versions of synapse, the mapping from SAML attribute to
  4479. # MXID was always calculated dynamically rather than stored in a
  4480. # table. For backwards- compatibility, we will look for user_ids
  4481. # matching such a pattern before creating a new account.
  4482. #
  4483. # This setting controls the SAML attribute which will be used for this
  4484. # backwards-compatibility lookup. Typically it should be 'uid', but if
  4485. # the attribute maps are changed, it may be necessary to change it.
  4486. #
  4487. # The default is 'uid'.
  4488. #
  4489. #grandfathered_mxid_source_attribute: upn
  4490. # It is possible to configure Synapse to only allow logins if SAML attributes
  4491. # match particular values. The requirements can be listed under
  4492. # `attribute_requirements` as shown below. All of the listed attributes must
  4493. # match for the login to be permitted.
  4494. #
  4495. #attribute_requirements:
  4496. # - attribute: userGroup
  4497. # value: &quot;staff&quot;
  4498. # - attribute: department
  4499. # value: &quot;sales&quot;
  4500. # If the metadata XML contains multiple IdP entities then the `idp_entityid`
  4501. # option must be set to the entity to redirect users to.
  4502. #
  4503. # Most deployments only have a single IdP entity and so should omit this
  4504. # option.
  4505. #
  4506. #idp_entityid: 'https://our_idp/entityid'
  4507. # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration
  4508. # and login.
  4509. #
  4510. # Options for each entry include:
  4511. #
  4512. # idp_id: a unique identifier for this identity provider. Used internally
  4513. # by Synapse; should be a single word such as 'github'.
  4514. #
  4515. # Note that, if this is changed, users authenticating via that provider
  4516. # will no longer be recognised as the same user!
  4517. #
  4518. # (Use &quot;oidc&quot; here if you are migrating from an old &quot;oidc_config&quot;
  4519. # configuration.)
  4520. #
  4521. # idp_name: A user-facing name for this identity provider, which is used to
  4522. # offer the user a choice of login mechanisms.
  4523. #
  4524. # idp_icon: An optional icon for this identity provider, which is presented
  4525. # by clients and Synapse's own IdP picker page. If given, must be an
  4526. # MXC URI of the format mxc://&lt;server-name&gt;/&lt;media-id&gt;. (An easy way to
  4527. # obtain such an MXC URI is to upload an image to an (unencrypted) room
  4528. # and then copy the &quot;url&quot; from the source of the event.)
  4529. #
  4530. # idp_brand: An optional brand for this identity provider, allowing clients
  4531. # to style the login flow according to the identity provider in question.
  4532. # See the spec for possible options here.
  4533. #
  4534. # discover: set to 'false' to disable the use of the OIDC discovery mechanism
  4535. # to discover endpoints. Defaults to true.
  4536. #
  4537. # issuer: Required. The OIDC issuer. Used to validate tokens and (if discovery
  4538. # is enabled) to discover the provider's endpoints.
  4539. #
  4540. # client_id: Required. oauth2 client id to use.
  4541. #
  4542. # client_secret: oauth2 client secret to use. May be omitted if
  4543. # client_secret_jwt_key is given, or if client_auth_method is 'none'.
  4544. #
  4545. # client_secret_jwt_key: Alternative to client_secret: details of a key used
  4546. # to create a JSON Web Token to be used as an OAuth2 client secret. If
  4547. # given, must be a dictionary with the following properties:
  4548. #
  4549. # key: a pem-encoded signing key. Must be a suitable key for the
  4550. # algorithm specified. Required unless 'key_file' is given.
  4551. #
  4552. # key_file: the path to file containing a pem-encoded signing key file.
  4553. # Required unless 'key' is given.
  4554. #
  4555. # jwt_header: a dictionary giving properties to include in the JWT
  4556. # header. Must include the key 'alg', giving the algorithm used to
  4557. # sign the JWT, such as &quot;ES256&quot;, using the JWA identifiers in
  4558. # RFC7518.
  4559. #
  4560. # jwt_payload: an optional dictionary giving properties to include in
  4561. # the JWT payload. Normally this should include an 'iss' key.
  4562. #
  4563. # client_auth_method: auth method to use when exchanging the token. Valid
  4564. # values are 'client_secret_basic' (default), 'client_secret_post' and
  4565. # 'none'.
  4566. #
  4567. # scopes: list of scopes to request. This should normally include the &quot;openid&quot;
  4568. # scope. Defaults to [&quot;openid&quot;].
  4569. #
  4570. # authorization_endpoint: the oauth2 authorization endpoint. Required if
  4571. # provider discovery is disabled.
  4572. #
  4573. # token_endpoint: the oauth2 token endpoint. Required if provider discovery is
  4574. # disabled.
  4575. #
  4576. # userinfo_endpoint: the OIDC userinfo endpoint. Required if discovery is
  4577. # disabled and the 'openid' scope is not requested.
  4578. #
  4579. # jwks_uri: URI where to fetch the JWKS. Required if discovery is disabled and
  4580. # the 'openid' scope is used.
  4581. #
  4582. # skip_verification: set to 'true' to skip metadata verification. Use this if
  4583. # you are connecting to a provider that is not OpenID Connect compliant.
  4584. # Defaults to false. Avoid this in production.
  4585. #
  4586. # user_profile_method: Whether to fetch the user profile from the userinfo
  4587. # endpoint. Valid values are: 'auto' or 'userinfo_endpoint'.
  4588. #
  4589. # Defaults to 'auto', which fetches the userinfo endpoint if 'openid' is
  4590. # included in 'scopes'. Set to 'userinfo_endpoint' to always fetch the
  4591. # userinfo endpoint.
  4592. #
  4593. # allow_existing_users: set to 'true' to allow a user logging in via OIDC to
  4594. # match a pre-existing account instead of failing. This could be used if
  4595. # switching from password logins to OIDC. Defaults to false.
  4596. #
  4597. # user_mapping_provider: Configuration for how attributes returned from a OIDC
  4598. # provider are mapped onto a matrix user. This setting has the following
  4599. # sub-properties:
  4600. #
  4601. # module: The class name of a custom mapping module. Default is
  4602. # 'synapse.handlers.oidc.JinjaOidcMappingProvider'.
  4603. # See https://matrix-org.github.io/synapse/latest/sso_mapping_providers.html#openid-mapping-providers
  4604. # for information on implementing a custom mapping provider.
  4605. #
  4606. # config: Configuration for the mapping provider module. This section will
  4607. # be passed as a Python dictionary to the user mapping provider
  4608. # module's `parse_config` method.
  4609. #
  4610. # For the default provider, the following settings are available:
  4611. #
  4612. # subject_claim: name of the claim containing a unique identifier
  4613. # for the user. Defaults to 'sub', which OpenID Connect
  4614. # compliant providers should provide.
  4615. #
  4616. # localpart_template: Jinja2 template for the localpart of the MXID.
  4617. # If this is not set, the user will be prompted to choose their
  4618. # own username (see 'sso_auth_account_details.html' in the 'sso'
  4619. # section of this file).
  4620. #
  4621. # display_name_template: Jinja2 template for the display name to set
  4622. # on first login. If unset, no displayname will be set.
  4623. #
  4624. # email_template: Jinja2 template for the email address of the user.
  4625. # If unset, no email address will be added to the account.
  4626. #
  4627. # extra_attributes: a map of Jinja2 templates for extra attributes
  4628. # to send back to the client during login.
  4629. # Note that these are non-standard and clients will ignore them
  4630. # without modifications.
  4631. #
  4632. # When rendering, the Jinja2 templates are given a 'user' variable,
  4633. # which is set to the claims returned by the UserInfo Endpoint and/or
  4634. # in the ID Token.
  4635. #
  4636. # It is possible to configure Synapse to only allow logins if certain attributes
  4637. # match particular values in the OIDC userinfo. The requirements can be listed under
  4638. # `attribute_requirements` as shown below. All of the listed attributes must
  4639. # match for the login to be permitted. Additional attributes can be added to
  4640. # userinfo by expanding the `scopes` section of the OIDC config to retrieve
  4641. # additional information from the OIDC provider.
  4642. #
  4643. # If the OIDC claim is a list, then the attribute must match any value in the list.
  4644. # Otherwise, it must exactly match the value of the claim. Using the example
  4645. # below, the `family_name` claim MUST be &quot;Stephensson&quot;, but the `groups`
  4646. # claim MUST contain &quot;admin&quot;.
  4647. #
  4648. # attribute_requirements:
  4649. # - attribute: family_name
  4650. # value: &quot;Stephensson&quot;
  4651. # - attribute: groups
  4652. # value: &quot;admin&quot;
  4653. #
  4654. # See https://matrix-org.github.io/synapse/latest/openid.html
  4655. # for information on how to configure these options.
  4656. #
  4657. # For backwards compatibility, it is also possible to configure a single OIDC
  4658. # provider via an 'oidc_config' setting. This is now deprecated and admins are
  4659. # advised to migrate to the 'oidc_providers' format. (When doing that migration,
  4660. # use 'oidc' for the idp_id to ensure that existing users continue to be
  4661. # recognised.)
  4662. #
  4663. oidc_providers:
  4664. # Generic example
  4665. #
  4666. #- idp_id: my_idp
  4667. # idp_name: &quot;My OpenID provider&quot;
  4668. # idp_icon: &quot;mxc://example.com/mediaid&quot;
  4669. # discover: false
  4670. # issuer: &quot;https://accounts.example.com/&quot;
  4671. # client_id: &quot;provided-by-your-issuer&quot;
  4672. # client_secret: &quot;provided-by-your-issuer&quot;
  4673. # client_auth_method: client_secret_post
  4674. # scopes: [&quot;openid&quot;, &quot;profile&quot;]
  4675. # authorization_endpoint: &quot;https://accounts.example.com/oauth2/auth&quot;
  4676. # token_endpoint: &quot;https://accounts.example.com/oauth2/token&quot;
  4677. # userinfo_endpoint: &quot;https://accounts.example.com/userinfo&quot;
  4678. # jwks_uri: &quot;https://accounts.example.com/.well-known/jwks.json&quot;
  4679. # skip_verification: true
  4680. # user_mapping_provider:
  4681. # config:
  4682. # subject_claim: &quot;id&quot;
  4683. # localpart_template: &quot;{{ user.login }}&quot;
  4684. # display_name_template: &quot;{{ user.name }}&quot;
  4685. # email_template: &quot;{{ user.email }}&quot;
  4686. # attribute_requirements:
  4687. # - attribute: userGroup
  4688. # value: &quot;synapseUsers&quot;
  4689. # Enable Central Authentication Service (CAS) for registration and login.
  4690. #
  4691. cas_config:
  4692. # Uncomment the following to enable authorization against a CAS server.
  4693. # Defaults to false.
  4694. #
  4695. #enabled: true
  4696. # The URL of the CAS authorization endpoint.
  4697. #
  4698. #server_url: &quot;https://cas-server.com&quot;
  4699. # The attribute of the CAS response to use as the display name.
  4700. #
  4701. # If unset, no displayname will be set.
  4702. #
  4703. #displayname_attribute: name
  4704. # It is possible to configure Synapse to only allow logins if CAS attributes
  4705. # match particular values. All of the keys in the mapping below must exist
  4706. # and the values must match the given value. Alternately if the given value
  4707. # is None then any value is allowed (the attribute just must exist).
  4708. # All of the listed attributes must match for the login to be permitted.
  4709. #
  4710. #required_attributes:
  4711. # userGroup: &quot;staff&quot;
  4712. # department: None
  4713. # Additional settings to use with single-sign on systems such as OpenID Connect,
  4714. # SAML2 and CAS.
  4715. #
  4716. # Server admins can configure custom templates for pages related to SSO. See
  4717. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4718. #
  4719. sso:
  4720. # A list of client URLs which are whitelisted so that the user does not
  4721. # have to confirm giving access to their account to the URL. Any client
  4722. # whose URL starts with an entry in the following list will not be subject
  4723. # to an additional confirmation step after the SSO login is completed.
  4724. #
  4725. # WARNING: An entry such as &quot;https://my.client&quot; is insecure, because it
  4726. # will also match &quot;https://my.client.evil.site&quot;, exposing your users to
  4727. # phishing attacks from evil.site. To avoid this, include a slash after the
  4728. # hostname: &quot;https://my.client/&quot;.
  4729. #
  4730. # If public_baseurl is set, then the login fallback page (used by clients
  4731. # that don't natively support the required login flows) is whitelisted in
  4732. # addition to any URLs in this list.
  4733. #
  4734. # By default, this list is empty.
  4735. #
  4736. #client_whitelist:
  4737. # - https://riot.im/develop
  4738. # - https://my.custom.client/
  4739. # Uncomment to keep a user's profile fields in sync with information from
  4740. # the identity provider. Currently only syncing the displayname is
  4741. # supported. Fields are checked on every SSO login, and are updated
  4742. # if necessary.
  4743. #
  4744. # Note that enabling this option will override user profile information,
  4745. # regardless of whether users have opted-out of syncing that
  4746. # information when first signing in. Defaults to false.
  4747. #
  4748. #update_profile_information: true
  4749. # JSON web token integration. The following settings can be used to make
  4750. # Synapse JSON web tokens for authentication, instead of its internal
  4751. # password database.
  4752. #
  4753. # Each JSON Web Token needs to contain a &quot;sub&quot; (subject) claim, which is
  4754. # used as the localpart of the mxid.
  4755. #
  4756. # Additionally, the expiration time (&quot;exp&quot;), not before time (&quot;nbf&quot;),
  4757. # and issued at (&quot;iat&quot;) claims are validated if present.
  4758. #
  4759. # Note that this is a non-standard login type and client support is
  4760. # expected to be non-existent.
  4761. #
  4762. # See https://matrix-org.github.io/synapse/latest/jwt.html.
  4763. #
  4764. #jwt_config:
  4765. # Uncomment the following to enable authorization using JSON web
  4766. # tokens. Defaults to false.
  4767. #
  4768. #enabled: true
  4769. # This is either the private shared secret or the public key used to
  4770. # decode the contents of the JSON web token.
  4771. #
  4772. # Required if 'enabled' is true.
  4773. #
  4774. #secret: &quot;provided-by-your-issuer&quot;
  4775. # The algorithm used to sign the JSON web token.
  4776. #
  4777. # Supported algorithms are listed at
  4778. # https://pyjwt.readthedocs.io/en/latest/algorithms.html
  4779. #
  4780. # Required if 'enabled' is true.
  4781. #
  4782. #algorithm: &quot;provided-by-your-issuer&quot;
  4783. # The issuer to validate the &quot;iss&quot; claim against.
  4784. #
  4785. # Optional, if provided the &quot;iss&quot; claim will be required and
  4786. # validated for all JSON web tokens.
  4787. #
  4788. #issuer: &quot;provided-by-your-issuer&quot;
  4789. # A list of audiences to validate the &quot;aud&quot; claim against.
  4790. #
  4791. # Optional, if provided the &quot;aud&quot; claim will be required and
  4792. # validated for all JSON web tokens.
  4793. #
  4794. # Note that if the &quot;aud&quot; claim is included in a JSON web token then
  4795. # validation will fail without configuring audiences.
  4796. #
  4797. #audiences:
  4798. # - &quot;provided-by-your-issuer&quot;
  4799. password_config:
  4800. # Uncomment to disable password login
  4801. #
  4802. #enabled: false
  4803. # Uncomment to disable authentication against the local password
  4804. # database. This is ignored if `enabled` is false, and is only useful
  4805. # if you have other password_providers.
  4806. #
  4807. #localdb_enabled: false
  4808. # Uncomment and change to a secret random string for extra security.
  4809. # DO NOT CHANGE THIS AFTER INITIAL SETUP!
  4810. #
  4811. #pepper: &quot;EVEN_MORE_SECRET&quot;
  4812. # Define and enforce a password policy. Each parameter is optional.
  4813. # This is an implementation of MSC2000.
  4814. #
  4815. policy:
  4816. # Whether to enforce the password policy.
  4817. # Defaults to 'false'.
  4818. #
  4819. #enabled: true
  4820. # Minimum accepted length for a password.
  4821. # Defaults to 0.
  4822. #
  4823. #minimum_length: 15
  4824. # Whether a password must contain at least one digit.
  4825. # Defaults to 'false'.
  4826. #
  4827. #require_digit: true
  4828. # Whether a password must contain at least one symbol.
  4829. # A symbol is any character that's not a number or a letter.
  4830. # Defaults to 'false'.
  4831. #
  4832. #require_symbol: true
  4833. # Whether a password must contain at least one lowercase letter.
  4834. # Defaults to 'false'.
  4835. #
  4836. #require_lowercase: true
  4837. # Whether a password must contain at least one uppercase letter.
  4838. # Defaults to 'false'.
  4839. #
  4840. #require_uppercase: true
  4841. ui_auth:
  4842. # The amount of time to allow a user-interactive authentication session
  4843. # to be active.
  4844. #
  4845. # This defaults to 0, meaning the user is queried for their credentials
  4846. # before every action, but this can be overridden to allow a single
  4847. # validation to be re-used. This weakens the protections afforded by
  4848. # the user-interactive authentication process, by allowing for multiple
  4849. # (and potentially different) operations to use the same validation session.
  4850. #
  4851. # This is ignored for potentially &quot;dangerous&quot; operations (including
  4852. # deactivating an account, modifying an account password, and
  4853. # adding a 3PID).
  4854. #
  4855. # Uncomment below to allow for credential validation to last for 15
  4856. # seconds.
  4857. #
  4858. #session_timeout: &quot;15s&quot;
  4859. # Configuration for sending emails from Synapse.
  4860. #
  4861. # Server admins can configure custom templates for email content. See
  4862. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4863. #
  4864. email:
  4865. # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'.
  4866. #
  4867. #smtp_host: mail.server
  4868. # The port on the mail server for outgoing SMTP. Defaults to 25.
  4869. #
  4870. #smtp_port: 587
  4871. # Username/password for authentication to the SMTP server. By default, no
  4872. # authentication is attempted.
  4873. #
  4874. #smtp_user: &quot;exampleusername&quot;
  4875. #smtp_pass: &quot;examplepassword&quot;
  4876. # Uncomment the following to require TLS transport security for SMTP.
  4877. # By default, Synapse will connect over plain text, and will then switch to
  4878. # TLS via STARTTLS *if the SMTP server supports it*. If this option is set,
  4879. # Synapse will refuse to connect unless the server supports STARTTLS.
  4880. #
  4881. #require_transport_security: true
  4882. # Uncomment the following to disable TLS for SMTP.
  4883. #
  4884. # By default, if the server supports TLS, it will be used, and the server
  4885. # must present a certificate that is valid for 'smtp_host'. If this option
  4886. # is set to false, TLS will not be used.
  4887. #
  4888. #enable_tls: false
  4889. # notif_from defines the &quot;From&quot; address to use when sending emails.
  4890. # It must be set if email sending is enabled.
  4891. #
  4892. # The placeholder '%(app)s' will be replaced by the application name,
  4893. # which is normally 'app_name' (below), but may be overridden by the
  4894. # Matrix client application.
  4895. #
  4896. # Note that the placeholder must be written '%(app)s', including the
  4897. # trailing 's'.
  4898. #
  4899. #notif_from: &quot;Your Friendly %(app)s homeserver &lt;noreply@example.com&gt;&quot;
  4900. # app_name defines the default value for '%(app)s' in notif_from and email
  4901. # subjects. It defaults to 'Matrix'.
  4902. #
  4903. #app_name: my_branded_matrix_server
  4904. # Uncomment the following to enable sending emails for messages that the user
  4905. # has missed. Disabled by default.
  4906. #
  4907. #enable_notifs: true
  4908. # Uncomment the following to disable automatic subscription to email
  4909. # notifications for new users. Enabled by default.
  4910. #
  4911. #notif_for_new_users: false
  4912. # Custom URL for client links within the email notifications. By default
  4913. # links will be based on &quot;https://matrix.to&quot;.
  4914. #
  4915. # (This setting used to be called riot_base_url; the old name is still
  4916. # supported for backwards-compatibility but is now deprecated.)
  4917. #
  4918. #client_base_url: &quot;http://localhost/riot&quot;
  4919. # Configure the time that a validation email will expire after sending.
  4920. # Defaults to 1h.
  4921. #
  4922. #validation_token_lifetime: 15m
  4923. # The web client location to direct users to during an invite. This is passed
  4924. # to the identity server as the org.matrix.web_client_location key. Defaults
  4925. # to unset, giving no guidance to the identity server.
  4926. #
  4927. #invite_client_location: https://app.element.io
  4928. # Subjects to use when sending emails from Synapse.
  4929. #
  4930. # The placeholder '%(app)s' will be replaced with the value of the 'app_name'
  4931. # setting above, or by a value dictated by the Matrix client application.
  4932. #
  4933. # If a subject isn't overridden in this configuration file, the value used as
  4934. # its example will be used.
  4935. #
  4936. #subjects:
  4937. # Subjects for notification emails.
  4938. #
  4939. # On top of the '%(app)s' placeholder, these can use the following
  4940. # placeholders:
  4941. #
  4942. # * '%(person)s', which will be replaced by the display name of the user(s)
  4943. # that sent the message(s), e.g. &quot;Alice and Bob&quot;.
  4944. # * '%(room)s', which will be replaced by the name of the room the
  4945. # message(s) have been sent to, e.g. &quot;My super room&quot;.
  4946. #
  4947. # See the example provided for each setting to see which placeholder can be
  4948. # used and how to use them.
  4949. #
  4950. # Subject to use to notify about one message from one or more user(s) in a
  4951. # room which has a name.
  4952. #message_from_person_in_room: &quot;[%(app)s] You have a message on %(app)s from %(person)s in the %(room)s room...&quot;
  4953. #
  4954. # Subject to use to notify about one message from one or more user(s) in a
  4955. # room which doesn't have a name.
  4956. #message_from_person: &quot;[%(app)s] You have a message on %(app)s from %(person)s...&quot;
  4957. #
  4958. # Subject to use to notify about multiple messages from one or more users in
  4959. # a room which doesn't have a name.
  4960. #messages_from_person: &quot;[%(app)s] You have messages on %(app)s from %(person)s...&quot;
  4961. #
  4962. # Subject to use to notify about multiple messages in a room which has a
  4963. # name.
  4964. #messages_in_room: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room...&quot;
  4965. #
  4966. # Subject to use to notify about multiple messages in multiple rooms.
  4967. #messages_in_room_and_others: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room and others...&quot;
  4968. #
  4969. # Subject to use to notify about multiple messages from multiple persons in
  4970. # multiple rooms. This is similar to the setting above except it's used when
  4971. # the room in which the notification was triggered has no name.
  4972. #messages_from_person_and_others: &quot;[%(app)s] You have messages on %(app)s from %(person)s and others...&quot;
  4973. #
  4974. # Subject to use to notify about an invite to a room which has a name.
  4975. #invite_from_person_to_room: &quot;[%(app)s] %(person)s has invited you to join the %(room)s room on %(app)s...&quot;
  4976. #
  4977. # Subject to use to notify about an invite to a room which doesn't have a
  4978. # name.
  4979. #invite_from_person: &quot;[%(app)s] %(person)s has invited you to chat on %(app)s...&quot;
  4980. # Subject for emails related to account administration.
  4981. #
  4982. # On top of the '%(app)s' placeholder, these one can use the
  4983. # '%(server_name)s' placeholder, which will be replaced by the value of the
  4984. # 'server_name' setting in your Synapse configuration.
  4985. #
  4986. # Subject to use when sending a password reset email.
  4987. #password_reset: &quot;[%(server_name)s] Password reset&quot;
  4988. #
  4989. # Subject to use when sending a verification email to assert an address's
  4990. # ownership.
  4991. #email_validation: &quot;[%(server_name)s] Validate your email&quot;
  4992. ## Push ##
  4993. push:
  4994. # Clients requesting push notifications can either have the body of
  4995. # the message sent in the notification poke along with other details
  4996. # like the sender, or just the event ID and room ID (`event_id_only`).
  4997. # If clients choose the former, this option controls whether the
  4998. # notification request includes the content of the event (other details
  4999. # like the sender are still included). For `event_id_only` push, it
  5000. # has no effect.
  5001. #
  5002. # For modern android devices the notification content will still appear
  5003. # because it is loaded by the app. iPhone, however will send a
  5004. # notification saying only that a message arrived and who it came from.
  5005. #
  5006. # The default value is &quot;true&quot; to include message details. Uncomment to only
  5007. # include the event ID and room ID in push notification payloads.
  5008. #
  5009. #include_content: false
  5010. # When a push notification is received, an unread count is also sent.
  5011. # This number can either be calculated as the number of unread messages
  5012. # for the user, or the number of *rooms* the user has unread messages in.
  5013. #
  5014. # The default value is &quot;true&quot;, meaning push clients will see the number of
  5015. # rooms with unread messages in them. Uncomment to instead send the number
  5016. # of unread messages.
  5017. #
  5018. #group_unread_count_by_room: false
  5019. ## Rooms ##
  5020. # Controls whether locally-created rooms should be end-to-end encrypted by
  5021. # default.
  5022. #
  5023. # Possible options are &quot;all&quot;, &quot;invite&quot;, and &quot;off&quot;. They are defined as:
  5024. #
  5025. # * &quot;all&quot;: any locally-created room
  5026. # * &quot;invite&quot;: any room created with the &quot;private_chat&quot; or &quot;trusted_private_chat&quot;
  5027. # room creation presets
  5028. # * &quot;off&quot;: this option will take no effect
  5029. #
  5030. # The default value is &quot;off&quot;.
  5031. #
  5032. # Note that this option will only affect rooms created after it is set. It
  5033. # will also not affect rooms created by other servers.
  5034. #
  5035. #encryption_enabled_by_default_for_room_type: invite
  5036. # Uncomment to allow non-server-admin users to create groups on this server
  5037. #
  5038. #enable_group_creation: true
  5039. # If enabled, non server admins can only create groups with local parts
  5040. # starting with this prefix
  5041. #
  5042. #group_creation_prefix: &quot;unofficial_&quot;
  5043. # User Directory configuration
  5044. #
  5045. user_directory:
  5046. # Defines whether users can search the user directory. If false then
  5047. # empty responses are returned to all queries. Defaults to true.
  5048. #
  5049. # Uncomment to disable the user directory.
  5050. #
  5051. #enabled: false
  5052. # Defines whether to search all users visible to your HS when searching
  5053. # the user directory. If false, search results will only contain users
  5054. # visible in public rooms and users sharing a room with the requester.
  5055. # Defaults to false.
  5056. #
  5057. # NB. If you set this to true, and the last time the user_directory search
  5058. # indexes were (re)built was before Synapse 1.44, you'll have to
  5059. # rebuild the indexes in order to search through all known users.
  5060. # These indexes are built the first time Synapse starts; admins can
  5061. # manually trigger a rebuild following the instructions at
  5062. # https://matrix-org.github.io/synapse/latest/user_directory.html
  5063. #
  5064. # Uncomment to return search results containing all known users, even if that
  5065. # user does not share a room with the requester.
  5066. #
  5067. #search_all_users: true
  5068. # Defines whether to prefer local users in search query results.
  5069. # If True, local users are more likely to appear above remote users
  5070. # when searching the user directory. Defaults to false.
  5071. #
  5072. # Uncomment to prefer local over remote users in user directory search
  5073. # results.
  5074. #
  5075. #prefer_local_users: true
  5076. # User Consent configuration
  5077. #
  5078. # for detailed instructions, see
  5079. # https://matrix-org.github.io/synapse/latest/consent_tracking.html
  5080. #
  5081. # Parts of this section are required if enabling the 'consent' resource under
  5082. # 'listeners', in particular 'template_dir' and 'version'.
  5083. #
  5084. # 'template_dir' gives the location of the templates for the HTML forms.
  5085. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  5086. # and each language directory should contain the policy document (named as
  5087. # '&lt;version&gt;.html') and a success page (success.html).
  5088. #
  5089. # 'version' specifies the 'current' version of the policy document. It defines
  5090. # the version to be served by the consent resource if there is no 'v'
  5091. # parameter.
  5092. #
  5093. # 'server_notice_content', if enabled, will send a user a &quot;Server Notice&quot;
  5094. # asking them to consent to the privacy policy. The 'server_notices' section
  5095. # must also be configured for this to work. Notices will *not* be sent to
  5096. # guest users unless 'send_server_notice_to_guests' is set to true.
  5097. #
  5098. # 'block_events_error', if set, will block any attempts to send events
  5099. # until the user consents to the privacy policy. The value of the setting is
  5100. # used as the text of the error.
  5101. #
  5102. # 'require_at_registration', if enabled, will add a step to the registration
  5103. # process, similar to how captcha works. Users will be required to accept the
  5104. # policy before their account is created.
  5105. #
  5106. # 'policy_name' is the display name of the policy users will see when registering
  5107. # for an account. Has no effect unless `require_at_registration` is enabled.
  5108. # Defaults to &quot;Privacy Policy&quot;.
  5109. #
  5110. #user_consent:
  5111. # template_dir: res/templates/privacy
  5112. # version: 1.0
  5113. # server_notice_content:
  5114. # msgtype: m.text
  5115. # body: &gt;-
  5116. # To continue using this homeserver you must review and agree to the
  5117. # terms and conditions at %(consent_uri)s
  5118. # send_server_notice_to_guests: true
  5119. # block_events_error: &gt;-
  5120. # To continue using this homeserver you must review and agree to the
  5121. # terms and conditions at %(consent_uri)s
  5122. # require_at_registration: false
  5123. # policy_name: Privacy Policy
  5124. #
  5125. # Settings for local room and user statistics collection. See
  5126. # https://matrix-org.github.io/synapse/latest/room_and_user_statistics.html.
  5127. #
  5128. stats:
  5129. # Uncomment the following to disable room and user statistics. Note that doing
  5130. # so may cause certain features (such as the room directory) not to work
  5131. # correctly.
  5132. #
  5133. #enabled: false
  5134. # Server Notices room configuration
  5135. #
  5136. # Uncomment this section to enable a room which can be used to send notices
  5137. # from the server to users. It is a special room which cannot be left; notices
  5138. # come from a special &quot;notices&quot; user id.
  5139. #
  5140. # If you uncomment this section, you *must* define the system_mxid_localpart
  5141. # setting, which defines the id of the user which will be used to send the
  5142. # notices.
  5143. #
  5144. # It's also possible to override the room name, the display name of the
  5145. # &quot;notices&quot; user, and the avatar for the user.
  5146. #
  5147. #server_notices:
  5148. # system_mxid_localpart: notices
  5149. # system_mxid_display_name: &quot;Server Notices&quot;
  5150. # system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  5151. # room_name: &quot;Server Notices&quot;
  5152. # Uncomment to disable searching the public room list. When disabled
  5153. # blocks searching local and remote room lists for local and remote
  5154. # users by always returning an empty list for all queries.
  5155. #
  5156. #enable_room_list_search: false
  5157. # The `alias_creation` option controls who's allowed to create aliases
  5158. # on this server.
  5159. #
  5160. # The format of this option is a list of rules that contain globs that
  5161. # match against user_id, room_id and the new alias (fully qualified with
  5162. # server name). The action in the first rule that matches is taken,
  5163. # which can currently either be &quot;allow&quot; or &quot;deny&quot;.
  5164. #
  5165. # Missing user_id/room_id/alias fields default to &quot;*&quot;.
  5166. #
  5167. # If no rules match the request is denied. An empty list means no one
  5168. # can create aliases.
  5169. #
  5170. # Options for the rules include:
  5171. #
  5172. # user_id: Matches against the creator of the alias
  5173. # alias: Matches against the alias being created
  5174. # room_id: Matches against the room ID the alias is being pointed at
  5175. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5176. #
  5177. # The default is:
  5178. #
  5179. #alias_creation_rules:
  5180. # - user_id: &quot;*&quot;
  5181. # alias: &quot;*&quot;
  5182. # room_id: &quot;*&quot;
  5183. # action: allow
  5184. # The `room_list_publication_rules` option controls who can publish and
  5185. # which rooms can be published in the public room list.
  5186. #
  5187. # The format of this option is the same as that for
  5188. # `alias_creation_rules`.
  5189. #
  5190. # If the room has one or more aliases associated with it, only one of
  5191. # the aliases needs to match the alias rule. If there are no aliases
  5192. # then only rules with `alias: *` match.
  5193. #
  5194. # If no rules match the request is denied. An empty list means no one
  5195. # can publish rooms.
  5196. #
  5197. # Options for the rules include:
  5198. #
  5199. # user_id: Matches against the creator of the alias
  5200. # room_id: Matches against the room ID being published
  5201. # alias: Matches against any current local or canonical aliases
  5202. # associated with the room
  5203. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5204. #
  5205. # The default is:
  5206. #
  5207. #room_list_publication_rules:
  5208. # - user_id: &quot;*&quot;
  5209. # alias: &quot;*&quot;
  5210. # room_id: &quot;*&quot;
  5211. # action: allow
  5212. ## Opentracing ##
  5213. # These settings enable opentracing, which implements distributed tracing.
  5214. # This allows you to observe the causal chains of events across servers
  5215. # including requests, key lookups etc., across any server running
  5216. # synapse or any other other services which supports opentracing
  5217. # (specifically those implemented with Jaeger).
  5218. #
  5219. opentracing:
  5220. # tracing is disabled by default. Uncomment the following line to enable it.
  5221. #
  5222. #enabled: true
  5223. # The list of homeservers we wish to send and receive span contexts and span baggage.
  5224. # See https://matrix-org.github.io/synapse/latest/opentracing.html.
  5225. #
  5226. # This is a list of regexes which are matched against the server_name of the
  5227. # homeserver.
  5228. #
  5229. # By default, it is empty, so no servers are matched.
  5230. #
  5231. #homeserver_whitelist:
  5232. # - &quot;.*&quot;
  5233. # A list of the matrix IDs of users whose requests will always be traced,
  5234. # even if the tracing system would otherwise drop the traces due to
  5235. # probabilistic sampling.
  5236. #
  5237. # By default, the list is empty.
  5238. #
  5239. #force_tracing_for_users:
  5240. # - &quot;@user1:server_name&quot;
  5241. # - &quot;@user2:server_name&quot;
  5242. # Jaeger can be configured to sample traces at different rates.
  5243. # All configuration options provided by Jaeger can be set here.
  5244. # Jaeger's configuration is mostly related to trace sampling which
  5245. # is documented here:
  5246. # https://www.jaegertracing.io/docs/latest/sampling/.
  5247. #
  5248. #jaeger_config:
  5249. # sampler:
  5250. # type: const
  5251. # param: 1
  5252. # logging:
  5253. # false
  5254. ## Workers ##
  5255. # Disables sending of outbound federation transactions on the main process.
  5256. # Uncomment if using a federation sender worker.
  5257. #
  5258. #send_federation: false
  5259. # It is possible to run multiple federation sender workers, in which case the
  5260. # work is balanced across them.
  5261. #
  5262. # This configuration must be shared between all federation sender workers, and if
  5263. # changed all federation sender workers must be stopped at the same time and then
  5264. # started, to ensure that all instances are running with the same config (otherwise
  5265. # events may be dropped).
  5266. #
  5267. #federation_sender_instances:
  5268. # - federation_sender1
  5269. # When using workers this should be a map from `worker_name` to the
  5270. # HTTP replication listener of the worker, if configured.
  5271. #
  5272. #instance_map:
  5273. # worker1:
  5274. # host: localhost
  5275. # port: 8034
  5276. # Experimental: When using workers you can define which workers should
  5277. # handle event persistence and typing notifications. Any worker
  5278. # specified here must also be in the `instance_map`.
  5279. #
  5280. #stream_writers:
  5281. # events: worker1
  5282. # typing: worker1
  5283. # The worker that is used to run background tasks (e.g. cleaning up expired
  5284. # data). If not provided this defaults to the main process.
  5285. #
  5286. #run_background_tasks_on: worker1
  5287. # A shared secret used by the replication APIs to authenticate HTTP requests
  5288. # from workers.
  5289. #
  5290. # By default this is unused and traffic is not authenticated.
  5291. #
  5292. #worker_replication_secret: &quot;&quot;
  5293. # Configuration for Redis when using workers. This *must* be enabled when
  5294. # using workers (unless using old style direct TCP configuration).
  5295. #
  5296. redis:
  5297. # Uncomment the below to enable Redis support.
  5298. #
  5299. #enabled: true
  5300. # Optional host and port to use to connect to redis. Defaults to
  5301. # localhost and 6379
  5302. #
  5303. #host: localhost
  5304. #port: 6379
  5305. # Optional password if configured on the Redis instance
  5306. #
  5307. #password: &lt;secret_password&gt;
  5308. </code></pre>
  5309. <div style="break-before: page; page-break-before: always;"></div><h1 id="logging-sample-configuration-file"><a class="header" href="#logging-sample-configuration-file">Logging Sample Configuration File</a></h1>
  5310. <p>Below is a sample logging configuration file. This file can be tweaked to control how your
  5311. homeserver will output logs. A restart of the server is generally required to apply any
  5312. changes made to this file. The value of the <code>log_config</code> option in your homeserver
  5313. config should be the path to this file.</p>
  5314. <p>Note that a default logging configuration (shown below) is created automatically alongside
  5315. the homeserver config when following the <a href="usage/configuration/../../setup/installation.html">installation instructions</a>.
  5316. It should be named <code>&lt;SERVERNAME&gt;.log.config</code> by default.</p>
  5317. <pre><code class="language-yaml"># Log configuration for Synapse.
  5318. #
  5319. # This is a YAML file containing a standard Python logging configuration
  5320. # dictionary. See [1] for details on the valid settings.
  5321. #
  5322. # Synapse also supports structured logging for machine readable logs which can
  5323. # be ingested by ELK stacks. See [2] for details.
  5324. #
  5325. # [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  5326. # [2]: https://matrix-org.github.io/synapse/latest/structured_logging.html
  5327. version: 1
  5328. formatters:
  5329. precise:
  5330. format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
  5331. handlers:
  5332. file:
  5333. class: logging.handlers.TimedRotatingFileHandler
  5334. formatter: precise
  5335. filename: /var/log/matrix-synapse/homeserver.log
  5336. when: midnight
  5337. backupCount: 3 # Does not include the current log file.
  5338. encoding: utf8
  5339. # Default to buffering writes to log file for efficiency.
  5340. # WARNING/ERROR logs will still be flushed immediately, but there will be a
  5341. # delay (of up to `period` seconds, or until the buffer is full with
  5342. # `capacity` messages) before INFO/DEBUG logs get written.
  5343. buffer:
  5344. class: synapse.logging.handlers.PeriodicallyFlushingMemoryHandler
  5345. target: file
  5346. # The capacity is the maximum number of log lines that are buffered
  5347. # before being written to disk. Increasing this will lead to better
  5348. # performance, at the expensive of it taking longer for log lines to
  5349. # be written to disk.
  5350. # This parameter is required.
  5351. capacity: 10
  5352. # Logs with a level at or above the flush level will cause the buffer to
  5353. # be flushed immediately.
  5354. # Default value: 40 (ERROR)
  5355. # Other values: 50 (CRITICAL), 30 (WARNING), 20 (INFO), 10 (DEBUG)
  5356. flushLevel: 30 # Flush immediately for WARNING logs and higher
  5357. # The period of time, in seconds, between forced flushes.
  5358. # Messages will not be delayed for longer than this time.
  5359. # Default value: 5 seconds
  5360. period: 5
  5361. # A handler that writes logs to stderr. Unused by default, but can be used
  5362. # instead of &quot;buffer&quot; and &quot;file&quot; in the logger handlers.
  5363. console:
  5364. class: logging.StreamHandler
  5365. formatter: precise
  5366. loggers:
  5367. synapse.storage.SQL:
  5368. # beware: increasing this to DEBUG will make synapse log sensitive
  5369. # information such as access tokens.
  5370. level: INFO
  5371. twisted:
  5372. # We send the twisted logging directly to the file handler,
  5373. # to work around https://github.com/matrix-org/synapse/issues/3471
  5374. # when using &quot;buffer&quot; logger. Use &quot;console&quot; to log to stderr instead.
  5375. handlers: [file]
  5376. propagate: false
  5377. root:
  5378. level: INFO
  5379. # Write logs to the `buffer` handler, which will buffer them together in memory,
  5380. # then write them to a file.
  5381. #
  5382. # Replace &quot;buffer&quot; with &quot;console&quot; to log to stderr instead. (Note that you'll
  5383. # also need to update the configuration for the `twisted` logger above, in
  5384. # this case.)
  5385. #
  5386. handlers: [buffer]
  5387. disable_existing_loggers: false
  5388. </code></pre>
  5389. <div style="break-before: page; page-break-before: always;"></div><h1 id="structured-logging"><a class="header" href="#structured-logging">Structured Logging</a></h1>
  5390. <p>A structured logging system can be useful when your logs are destined for a
  5391. machine to parse and process. By maintaining its machine-readable characteristics,
  5392. it enables more efficient searching and aggregations when consumed by software
  5393. such as the &quot;ELK stack&quot;.</p>
  5394. <p>Synapse's structured logging system is configured via the file that Synapse's
  5395. <code>log_config</code> config option points to. The file should include a formatter which
  5396. uses the <code>synapse.logging.TerseJsonFormatter</code> class included with Synapse and a
  5397. handler which uses the above formatter.</p>
  5398. <p>There is also a <code>synapse.logging.JsonFormatter</code> option which does not include
  5399. a timestamp in the resulting JSON. This is useful if the log ingester adds its
  5400. own timestamp.</p>
  5401. <p>A structured logging configuration looks similar to the following:</p>
  5402. <pre><code class="language-yaml">version: 1
  5403. formatters:
  5404. structured:
  5405. class: synapse.logging.TerseJsonFormatter
  5406. handlers:
  5407. file:
  5408. class: logging.handlers.TimedRotatingFileHandler
  5409. formatter: structured
  5410. filename: /path/to/my/logs/homeserver.log
  5411. when: midnight
  5412. backupCount: 3 # Does not include the current log file.
  5413. encoding: utf8
  5414. loggers:
  5415. synapse:
  5416. level: INFO
  5417. handlers: [remote]
  5418. synapse.storage.SQL:
  5419. level: WARNING
  5420. </code></pre>
  5421. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5422. with the SQL layer at 'WARNING', and will log to a file, stored as JSON.</p>
  5423. <p>It is also possible to figure Synapse to log to a remote endpoint by using the
  5424. <code>synapse.logging.RemoteHandler</code> class included with Synapse. It takes the
  5425. following arguments:</p>
  5426. <ul>
  5427. <li><code>host</code>: Hostname or IP address of the log aggregator.</li>
  5428. <li><code>port</code>: Numerical port to contact on the host.</li>
  5429. <li><code>maximum_buffer</code>: (Optional, defaults to 1000) The maximum buffer size to allow.</li>
  5430. </ul>
  5431. <p>A remote structured logging configuration looks similar to the following:</p>
  5432. <pre><code class="language-yaml">version: 1
  5433. formatters:
  5434. structured:
  5435. class: synapse.logging.TerseJsonFormatter
  5436. handlers:
  5437. remote:
  5438. class: synapse.logging.RemoteHandler
  5439. formatter: structured
  5440. host: 10.1.2.3
  5441. port: 9999
  5442. loggers:
  5443. synapse:
  5444. level: INFO
  5445. handlers: [remote]
  5446. synapse.storage.SQL:
  5447. level: WARNING
  5448. </code></pre>
  5449. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5450. with the SQL layer at 'WARNING', and will log JSON formatted messages to a
  5451. remote endpoint at 10.1.2.3:9999.</p>
  5452. <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>
  5453. <p>Versions of Synapse prior to v1.23.0 included a custom structured logging
  5454. configuration which is deprecated. It used a <code>structured: true</code> flag and
  5455. configured <code>drains</code> instead of <code>handlers</code> and <code>formatters</code>.</p>
  5456. <p>Synapse currently automatically converts the old configuration to the new
  5457. configuration, but this will be removed in a future version of Synapse. The
  5458. following reference can be used to update your configuration. Based on the drain
  5459. <code>type</code>, we can pick a new handler:</p>
  5460. <ol>
  5461. <li>For a type of <code>console</code>, <code>console_json</code>, or <code>console_json_terse</code>: a handler
  5462. with a class of <code>logging.StreamHandler</code> and a <code>stream</code> of <code>ext://sys.stdout</code>
  5463. or <code>ext://sys.stderr</code> should be used.</li>
  5464. <li>For a type of <code>file</code> or <code>file_json</code>: a handler of <code>logging.FileHandler</code> with
  5465. a location of the file path should be used.</li>
  5466. <li>For a type of <code>network_json_terse</code>: a handler of <code>synapse.logging.RemoteHandler</code>
  5467. with the host and port should be used.</li>
  5468. </ol>
  5469. <p>Then based on the drain <code>type</code> we can pick a new formatter:</p>
  5470. <ol>
  5471. <li>For a type of <code>console</code> or <code>file</code> no formatter is necessary.</li>
  5472. <li>For a type of <code>console_json</code> or <code>file_json</code>: a formatter of
  5473. <code>synapse.logging.JsonFormatter</code> should be used.</li>
  5474. <li>For a type of <code>console_json_terse</code> or <code>network_json_terse</code>: a formatter of
  5475. <code>synapse.logging.TerseJsonFormatter</code> should be used.</li>
  5476. </ol>
  5477. <p>For each new handler and formatter they should be added to the logging configuration
  5478. and then assigned to either a logger or the root logger.</p>
  5479. <p>An example legacy configuration:</p>
  5480. <pre><code class="language-yaml">structured: true
  5481. loggers:
  5482. synapse:
  5483. level: INFO
  5484. synapse.storage.SQL:
  5485. level: WARNING
  5486. drains:
  5487. console:
  5488. type: console
  5489. location: stdout
  5490. file:
  5491. type: file_json
  5492. location: homeserver.log
  5493. </code></pre>
  5494. <p>Would be converted into a new configuration:</p>
  5495. <pre><code class="language-yaml">version: 1
  5496. formatters:
  5497. json:
  5498. class: synapse.logging.JsonFormatter
  5499. handlers:
  5500. console:
  5501. class: logging.StreamHandler
  5502. location: ext://sys.stdout
  5503. file:
  5504. class: logging.FileHandler
  5505. formatter: json
  5506. filename: homeserver.log
  5507. loggers:
  5508. synapse:
  5509. level: INFO
  5510. handlers: [console, file]
  5511. synapse.storage.SQL:
  5512. level: WARNING
  5513. </code></pre>
  5514. <p>The new logging configuration is a bit more verbose, but significantly more
  5515. flexible. It allows for configuration that were not previously possible, such as
  5516. sending plain logs over the network, or using different handlers for different
  5517. modules.</p>
  5518. <div style="break-before: page; page-break-before: always;"></div><h1 id="templates"><a class="header" href="#templates">Templates</a></h1>
  5519. <p>Synapse uses parametrised templates to generate the content of emails it sends and
  5520. webpages it shows to users.</p>
  5521. <p>By default, Synapse will use the templates listed <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">here</a>.
  5522. Server admins can configure an additional directory for Synapse to look for templates
  5523. in, allowing them to specify custom templates:</p>
  5524. <pre><code class="language-yaml">templates:
  5525. custom_templates_directory: /path/to/custom/templates/
  5526. </code></pre>
  5527. <p>If this setting is not set, or the files named below are not found within the directory,
  5528. default templates from within the Synapse package will be used.</p>
  5529. <p>Templates that are given variables when being rendered are rendered using <a href="https://jinja.palletsprojects.com/en/2.11.x/">Jinja 2</a>.
  5530. Templates rendered by Jinja 2 can also access two functions on top of the functions
  5531. already available as part of Jinja 2:</p>
  5532. <pre><code class="language-python">format_ts(value: int, format: str) -&gt; str
  5533. </code></pre>
  5534. <p>Formats a timestamp in milliseconds.</p>
  5535. <p>Example: <code>reason.last_sent_ts|format_ts(&quot;%c&quot;)</code></p>
  5536. <pre><code class="language-python">mxc_to_http(value: str, width: int, height: int, resize_method: str = &quot;crop&quot;) -&gt; str
  5537. </code></pre>
  5538. <p>Turns a <code>mxc://</code> URL for media content into an HTTP(S) one using the homeserver's
  5539. <code>public_baseurl</code> configuration setting as the URL's base.</p>
  5540. <p>Example: <code>message.sender_avatar_url|mxc_to_http(32,32)</code></p>
  5541. <h2 id="email-templates"><a class="header" href="#email-templates">Email templates</a></h2>
  5542. <p>Below are the templates Synapse will look for when generating the content of an email:</p>
  5543. <ul>
  5544. <li><code>notif_mail.html</code> and <code>notif_mail.txt</code>: The contents of email notifications of missed
  5545. events.
  5546. When rendering, this template is given the following variables:
  5547. <ul>
  5548. <li><code>user_display_name</code>: the display name for the user receiving the notification</li>
  5549. <li><code>unsubscribe_link</code>: the link users can click to unsubscribe from email notifications</li>
  5550. <li><code>summary_text</code>: a summary of the notification(s). The text used can be customised
  5551. by configuring the various settings in the <code>email.subjects</code> section of the
  5552. configuration file.</li>
  5553. <li><code>rooms</code>: a list of rooms containing events to include in the email. Each element is
  5554. an object with the following attributes:
  5555. <ul>
  5556. <li><code>title</code>: a human-readable name for the room</li>
  5557. <li><code>hash</code>: a hash of the ID of the room</li>
  5558. <li><code>invite</code>: a boolean, which is <code>True</code> if the room is an invite the user hasn't
  5559. accepted yet, <code>False</code> otherwise</li>
  5560. <li><code>notifs</code>: a list of events, or an empty list if <code>invite</code> is <code>True</code>. Each element
  5561. is an object with the following attributes:
  5562. <ul>
  5563. <li><code>link</code>: a <code>matrix.to</code> link to the event</li>
  5564. <li><code>ts</code>: the time in milliseconds at which the event was received</li>
  5565. <li><code>messages</code>: a list of messages containing one message before the event, the
  5566. message in the event, and one message after the event. Each element is an
  5567. object with the following attributes:
  5568. <ul>
  5569. <li><code>event_type</code>: the type of the event</li>
  5570. <li><code>is_historical</code>: a boolean, which is <code>False</code> if the message is the one
  5571. that triggered the notification, <code>True</code> otherwise</li>
  5572. <li><code>id</code>: the ID of the event</li>
  5573. <li><code>ts</code>: the time in milliseconds at which the event was sent</li>
  5574. <li><code>sender_name</code>: the display name for the event's sender</li>
  5575. <li><code>sender_avatar_url</code>: the avatar URL (as a <code>mxc://</code> URL) for the event's
  5576. sender</li>
  5577. <li><code>sender_hash</code>: a hash of the user ID of the sender</li>
  5578. </ul>
  5579. </li>
  5580. </ul>
  5581. </li>
  5582. <li><code>link</code>: a <code>matrix.to</code> link to the room</li>
  5583. </ul>
  5584. </li>
  5585. <li><code>reason</code>: information on the event that triggered the email to be sent. It's an
  5586. object with the following attributes:
  5587. <ul>
  5588. <li><code>room_id</code>: the ID of the room the event was sent in</li>
  5589. <li><code>room_name</code>: a human-readable name for the room the event was sent in</li>
  5590. <li><code>now</code>: the current time in milliseconds</li>
  5591. <li><code>received_at</code>: the time in milliseconds at which the event was received</li>
  5592. <li><code>delay_before_mail_ms</code>: the amount of time in milliseconds Synapse always waits
  5593. before ever emailing about a notification (to give the user a chance to respond
  5594. to other push or notice the window)</li>
  5595. <li><code>last_sent_ts</code>: the time in milliseconds at which a notification was last sent
  5596. for an event in this room</li>
  5597. <li><code>throttle_ms</code>: the minimum amount of time in milliseconds between two
  5598. notifications can be sent for this room</li>
  5599. </ul>
  5600. </li>
  5601. </ul>
  5602. </li>
  5603. <li><code>password_reset.html</code> and <code>password_reset.txt</code>: The contents of password reset emails
  5604. sent by the homeserver.
  5605. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5606. user must click in order to reset their password.</li>
  5607. <li><code>registration.html</code> and <code>registration.txt</code>: The contents of address verification emails
  5608. sent during registration.
  5609. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5610. user must click in order to validate their email address.</li>
  5611. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code>: The contents of address verification emails
  5612. sent when an address is added to a Matrix account.
  5613. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5614. user must click in order to validate their email address.</li>
  5615. </ul>
  5616. <h2 id="html-page-templates-for-registration-and-password-reset"><a class="header" href="#html-page-templates-for-registration-and-password-reset">HTML page templates for registration and password reset</a></h2>
  5617. <p>Below are the templates Synapse will look for when generating pages related to
  5618. registration and password reset:</p>
  5619. <ul>
  5620. <li><code>password_reset_confirmation.html</code>: An HTML page that a user will see when they follow
  5621. the link in the password reset email. The user will be asked to confirm the action
  5622. before their password is reset.
  5623. When rendering, this template is given the following variables:
  5624. <ul>
  5625. <li><code>sid</code>: the session ID for the password reset</li>
  5626. <li><code>token</code>: the token for the password reset</li>
  5627. <li><code>client_secret</code>: the client secret for the password reset</li>
  5628. </ul>
  5629. </li>
  5630. <li><code>password_reset_success.html</code> and <code>password_reset_failure.html</code>: HTML pages for success
  5631. and failure that a user will see when they confirm the password reset flow using the
  5632. page above.
  5633. When rendering, <code>password_reset_success.html</code> is given no variable, and
  5634. <code>password_reset_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5635. for the password reset failure. </li>
  5636. <li><code>registration_success.html</code> and <code>registration_failure.html</code>: HTML pages for success and
  5637. failure that a user will see when they follow the link in an address verification email
  5638. sent during registration.
  5639. When rendering, <code>registration_success.html</code> is given no variable, and
  5640. <code>registration_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5641. for the registration failure.</li>
  5642. <li><code>add_threepid_success.html</code> and <code>add_threepid_failure.html</code>: HTML pages for success and
  5643. failure that a user will see when they follow the link in an address verification email
  5644. sent when an address is added to a Matrix account.
  5645. When rendering, <code>add_threepid_success.html</code> is given no variable, and
  5646. <code>add_threepid_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5647. for the registration failure.</li>
  5648. </ul>
  5649. <h2 id="html-page-templates-for-single-sign-on-sso"><a class="header" href="#html-page-templates-for-single-sign-on-sso">HTML page templates for Single Sign-On (SSO)</a></h2>
  5650. <p>Below are the templates Synapse will look for when generating pages related to SSO:</p>
  5651. <ul>
  5652. <li><code>sso_login_idp_picker.html</code>: HTML page to prompt the user to choose an
  5653. Identity Provider during login.
  5654. This is only used if multiple SSO Identity Providers are configured.
  5655. When rendering, this template is given the following variables:
  5656. <ul>
  5657. <li><code>redirect_url</code>: the URL that the user will be redirected to after
  5658. login.</li>
  5659. <li><code>server_name</code>: the homeserver's name.</li>
  5660. <li><code>providers</code>: a list of available Identity Providers. Each element is
  5661. an object with the following attributes:
  5662. <ul>
  5663. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5664. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5665. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5666. for the IdP</li>
  5667. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5668. for the brand of the IdP
  5669. The rendered HTML page should contain a form which submits its results
  5670. back as a GET request, with the following query parameters:</li>
  5671. </ul>
  5672. </li>
  5673. <li><code>redirectUrl</code>: the client redirect URI (ie, the <code>redirect_url</code> passed
  5674. to the template)</li>
  5675. <li><code>idp</code>: the 'idp_id' of the chosen IDP.</li>
  5676. </ul>
  5677. </li>
  5678. <li><code>sso_auth_account_details.html</code>: HTML page to prompt new users to enter a
  5679. userid and confirm other details. This is only shown if the
  5680. SSO implementation (with any <code>user_mapping_provider</code>) does not return
  5681. a localpart.
  5682. When rendering, this template is given the following variables:
  5683. <ul>
  5684. <li><code>server_name</code>: the homeserver's name.</li>
  5685. <li><code>idp</code>: details of the SSO Identity Provider that the user logged in
  5686. with: an object with the following attributes:
  5687. <ul>
  5688. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5689. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5690. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5691. for the IdP</li>
  5692. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5693. for the brand of the IdP</li>
  5694. </ul>
  5695. </li>
  5696. <li><code>user_attributes</code>: an object containing details about the user that
  5697. we received from the IdP. May have the following attributes:
  5698. <ul>
  5699. <li>display_name: the user's display_name</li>
  5700. <li>emails: a list of email addresses
  5701. The template should render a form which submits the following fields:</li>
  5702. </ul>
  5703. </li>
  5704. <li><code>username</code>: the localpart of the user's chosen user id</li>
  5705. </ul>
  5706. </li>
  5707. <li><code>sso_new_user_consent.html</code>: HTML page allowing the user to consent to the
  5708. server's terms and conditions. This is only shown for new users, and only if
  5709. <code>user_consent.require_at_registration</code> is set.
  5710. When rendering, this template is given the following variables:
  5711. <ul>
  5712. <li><code>server_name</code>: the homeserver's name.</li>
  5713. <li><code>user_id</code>: the user's matrix proposed ID.</li>
  5714. <li><code>user_profile.display_name</code>: the user's proposed display name, if any.</li>
  5715. <li>consent_version: the version of the terms that the user will be
  5716. shown</li>
  5717. <li><code>terms_url</code>: a link to the page showing the terms.
  5718. The template should render a form which submits the following fields:</li>
  5719. <li><code>accepted_version</code>: the version of the terms accepted by the user
  5720. (ie, 'consent_version' from the input variables).</li>
  5721. </ul>
  5722. </li>
  5723. <li><code>sso_redirect_confirm.html</code>: HTML page for a confirmation step before redirecting back
  5724. to the client with the login token.
  5725. When rendering, this template is given the following variables:
  5726. <ul>
  5727. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5728. <li><code>display_url</code>: the same as <code>redirect_url</code>, but with the query
  5729. parameters stripped. The intention is to have a
  5730. human-readable URL to show to users, not to use it as
  5731. the final address to redirect to.</li>
  5732. <li><code>server_name</code>: the homeserver's name.</li>
  5733. <li><code>new_user</code>: a boolean indicating whether this is the user's first time
  5734. logging in.</li>
  5735. <li><code>user_id</code>: the user's matrix ID.</li>
  5736. <li><code>user_profile.avatar_url</code>: an MXC URI for the user's avatar, if any.
  5737. <code>None</code> if the user has not set an avatar.</li>
  5738. <li><code>user_profile.display_name</code>: the user's display name. <code>None</code> if the user
  5739. has not set a display name.</li>
  5740. </ul>
  5741. </li>
  5742. <li><code>sso_auth_confirm.html</code>: HTML page which notifies the user that they are authenticating
  5743. to confirm an operation on their account during the user interactive authentication
  5744. process.
  5745. When rendering, this template is given the following variables:
  5746. <ul>
  5747. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5748. <li><code>description</code>: the operation which the user is being asked to confirm</li>
  5749. <li><code>idp</code>: details of the Identity Provider that we will use to confirm
  5750. the user's identity: an object with the following attributes:
  5751. <ul>
  5752. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5753. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5754. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5755. for the IdP</li>
  5756. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5757. for the brand of the IdP</li>
  5758. </ul>
  5759. </li>
  5760. </ul>
  5761. </li>
  5762. <li><code>sso_auth_success.html</code>: HTML page shown after a successful user interactive
  5763. authentication session.
  5764. Note that this page must include the JavaScript which notifies of a successful
  5765. authentication (see https://matrix.org/docs/spec/client_server/r0.6.0#fallback).
  5766. This template has no additional variables.</li>
  5767. <li><code>sso_auth_bad_user.html</code>: HTML page shown after a user-interactive authentication
  5768. session which does not map correctly onto the expected user.
  5769. When rendering, this template is given the following variables:
  5770. <ul>
  5771. <li><code>server_name</code>: the homeserver's name.</li>
  5772. <li><code>user_id_to_verify</code>: the MXID of the user that we are trying to
  5773. validate.</li>
  5774. </ul>
  5775. </li>
  5776. <li><code>sso_account_deactivated.html</code>: HTML page shown during single sign-on if a deactivated
  5777. user (according to Synapse's database) attempts to login.
  5778. This template has no additional variables.</li>
  5779. <li><code>sso_error.html</code>: HTML page to display to users if something goes wrong during the
  5780. OpenID Connect authentication process.
  5781. When rendering, this template is given two variables:
  5782. <ul>
  5783. <li><code>error</code>: the technical name of the error</li>
  5784. <li><code>error_description</code>: a human-readable message for the error</li>
  5785. </ul>
  5786. </li>
  5787. </ul>
  5788. <div style="break-before: page; page-break-before: always;"></div><h1 id="user-authentication"><a class="header" href="#user-authentication">User Authentication</a></h1>
  5789. <p>Synapse supports multiple methods of authenticating users, either out-of-the-box or through custom pluggable
  5790. authentication modules.</p>
  5791. <p>Included in Synapse is support for authenticating users via:</p>
  5792. <ul>
  5793. <li>A username and password.</li>
  5794. <li>An email address and password.</li>
  5795. <li>Single Sign-On through the SAML, Open ID Connect or CAS protocols.</li>
  5796. <li>JSON Web Tokens.</li>
  5797. <li>An administrator's shared secret.</li>
  5798. </ul>
  5799. <p>Synapse can additionally be extended to support custom authentication schemes through optional &quot;password auth provider&quot;
  5800. modules.</p>
  5801. <div style="break-before: page; page-break-before: always;"></div><h1 id="configuring-synapse-to-authenticate-against-an-openid-connect-provider"><a class="header" href="#configuring-synapse-to-authenticate-against-an-openid-connect-provider">Configuring Synapse to authenticate against an OpenID Connect provider</a></h1>
  5802. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  5803. authentication, instead of its own local password database.</p>
  5804. <p>Any OP should work with Synapse, as long as it supports the authorization code
  5805. flow. There are a few options for that:</p>
  5806. <ul>
  5807. <li>
  5808. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  5809. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  5810. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  5811. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  5812. environment variable set to the path of the CA.</p>
  5813. </li>
  5814. <li>
  5815. <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
  5816. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  5817. </li>
  5818. </ul>
  5819. <p>It may also be possible to use other OAuth2 providers which provide the
  5820. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  5821. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  5822. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  5823. <p>The OpenID integration in Synapse uses the
  5824. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  5825. as follows:</p>
  5826. <ul>
  5827. <li>
  5828. <p>The relevant libraries are included in the Docker images and Debian packages
  5829. provided by <code>matrix.org</code> so no further action is needed.</p>
  5830. </li>
  5831. <li>
  5832. <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>
  5833. </li>
  5834. <li>
  5835. <p>For other installation mechanisms, see the documentation provided by the
  5836. maintainer.</p>
  5837. </li>
  5838. </ul>
  5839. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  5840. setting in your configuration file (or uncomment one of the existing examples).
  5841. See <a href="./sample_config.yaml">sample_config.yaml</a> for some sample settings, as well as
  5842. the text below for example configurations for specific providers.</p>
  5843. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  5844. <p>Here are a few configs for providers that should work with Synapse.</p>
  5845. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  5846. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  5847. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  5848. application should point to your matrix server:
  5849. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5850. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  5851. Directory (tenant) ID as it will be used in the Azure links.
  5852. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  5853. <pre><code class="language-yaml">oidc_providers:
  5854. - idp_id: microsoft
  5855. idp_name: Microsoft
  5856. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  5857. client_id: &quot;&lt;client id&gt;&quot;
  5858. client_secret: &quot;&lt;client secret&gt;&quot;
  5859. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5860. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  5861. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  5862. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  5863. user_mapping_provider:
  5864. config:
  5865. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  5866. display_name_template: &quot;{{ user.name }}&quot;
  5867. </code></pre>
  5868. <h3 id="dex"><a class="header" href="#dex">Dex</a></h3>
  5869. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source, certified OpenID Connect Provider.
  5870. Although it is designed to help building a full-blown provider with an
  5871. external database, it can be configured with static passwords in a config file.</p>
  5872. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  5873. to install Dex.</p>
  5874. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  5875. <pre><code class="language-yaml">staticClients:
  5876. - id: synapse
  5877. secret: secret
  5878. redirectURIs:
  5879. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  5880. name: 'Synapse'
  5881. </code></pre>
  5882. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  5883. <p>Synapse config:</p>
  5884. <pre><code class="language-yaml">oidc_providers:
  5885. - idp_id: dex
  5886. idp_name: &quot;My Dex server&quot;
  5887. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  5888. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  5889. client_id: &quot;synapse&quot;
  5890. client_secret: &quot;secret&quot;
  5891. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5892. user_mapping_provider:
  5893. config:
  5894. localpart_template: &quot;{{ user.name }}&quot;
  5895. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  5896. </code></pre>
  5897. <h3 id="keycloak"><a class="header" href="#keycloak">Keycloak</a></h3>
  5898. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  5899. <p>Follow the <a href="https://www.keycloak.org/getting-started">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  5900. <ol>
  5901. <li>
  5902. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  5903. </li>
  5904. <li>
  5905. <p>Fill in the fields as below:</p>
  5906. </li>
  5907. </ol>
  5908. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5909. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5910. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5911. </tbody></table>
  5912. <ol start="3">
  5913. <li>Click <code>Save</code></li>
  5914. <li>Fill in the fields as below:</li>
  5915. </ol>
  5916. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5917. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5918. <tr><td>Enabled</td><td><code>On</code></td></tr>
  5919. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5920. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  5921. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  5922. </tbody></table>
  5923. <ol start="5">
  5924. <li>Click <code>Save</code></li>
  5925. <li>On the Credentials tab, update the fields:</li>
  5926. </ol>
  5927. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5928. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  5929. </tbody></table>
  5930. <ol start="7">
  5931. <li>Click <code>Regenerate Secret</code></li>
  5932. <li>Copy Secret</li>
  5933. </ol>
  5934. <pre><code class="language-yaml">oidc_providers:
  5935. - idp_id: keycloak
  5936. idp_name: &quot;My KeyCloak server&quot;
  5937. issuer: &quot;https://127.0.0.1:8443/auth/realms/{realm_name}&quot;
  5938. client_id: &quot;synapse&quot;
  5939. client_secret: &quot;copy secret generated from above&quot;
  5940. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5941. user_mapping_provider:
  5942. config:
  5943. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5944. display_name_template: &quot;{{ user.name }}&quot;
  5945. </code></pre>
  5946. <h3 id="auth0"><a class="header" href="#auth0">Auth0</a></h3>
  5947. <p><a href="https://auth0.com/">Auth0</a> is a hosted SaaS IdP solution.</p>
  5948. <ol>
  5949. <li>
  5950. <p>Create a regular web application for Synapse</p>
  5951. </li>
  5952. <li>
  5953. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5954. </li>
  5955. <li>
  5956. <p>Add a rule to add the <code>preferred_username</code> claim.</p>
  5957. <details>
  5958. <summary>Code sample</summary>
  5959. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  5960. user.user_metadata = user.user_metadata || {};
  5961. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  5962. context.idToken.preferred_username = user.user_metadata.preferred_username;
  5963. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  5964. .then(function(){
  5965. callback(null, user, context);
  5966. })
  5967. .catch(function(err){
  5968. callback(err);
  5969. });
  5970. }
  5971. </code></pre>
  5972. </li>
  5973. </ol>
  5974. </details>
  5975. <p>Synapse config:</p>
  5976. <pre><code class="language-yaml">oidc_providers:
  5977. - idp_id: auth0
  5978. idp_name: Auth0
  5979. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  5980. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5981. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5982. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5983. user_mapping_provider:
  5984. config:
  5985. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5986. display_name_template: &quot;{{ user.name }}&quot;
  5987. </code></pre>
  5988. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  5989. <p><a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">GitHub</a> is a bit special as it is not an OpenID Connect compliant provider, but
  5990. just a regular OAuth2 provider.</p>
  5991. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  5992. can be used to retrieve information on the authenticated user. As the Synapse
  5993. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5994. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5995. <ol>
  5996. <li>Create a new OAuth application: https://github.com/settings/applications/new.</li>
  5997. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5998. </ol>
  5999. <p>Synapse config:</p>
  6000. <pre><code class="language-yaml">oidc_providers:
  6001. - idp_id: github
  6002. idp_name: Github
  6003. idp_brand: &quot;github&quot; # optional: styling hint for clients
  6004. discover: false
  6005. issuer: &quot;https://github.com/&quot;
  6006. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6007. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6008. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  6009. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  6010. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  6011. scopes: [&quot;read:user&quot;]
  6012. user_mapping_provider:
  6013. config:
  6014. subject_claim: &quot;id&quot;
  6015. localpart_template: &quot;{{ user.login }}&quot;
  6016. display_name_template: &quot;{{ user.name }}&quot;
  6017. </code></pre>
  6018. <h3 id="google"><a class="header" href="#google">Google</a></h3>
  6019. <p><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a> is an OpenID certified authentication and authorisation provider.</p>
  6020. <ol>
  6021. <li>Set up a project in the Google API Console (see
  6022. https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup).</li>
  6023. <li>Add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  6024. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  6025. <pre><code class="language-yaml">oidc_providers:
  6026. - idp_id: google
  6027. idp_name: Google
  6028. idp_brand: &quot;google&quot; # optional: styling hint for clients
  6029. issuer: &quot;https://accounts.google.com/&quot;
  6030. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6031. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6032. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  6033. user_mapping_provider:
  6034. config:
  6035. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  6036. display_name_template: &quot;{{ user.name }}&quot;
  6037. </code></pre>
  6038. </li>
  6039. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  6040. </ol>
  6041. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  6042. <ol>
  6043. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  6044. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  6045. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  6046. </ol>
  6047. <p>Synapse config:</p>
  6048. <pre><code class="language-yaml">oidc_providers:
  6049. - idp_id: twitch
  6050. idp_name: Twitch
  6051. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  6052. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6053. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6054. client_auth_method: &quot;client_secret_post&quot;
  6055. user_mapping_provider:
  6056. config:
  6057. localpart_template: &quot;{{ user.preferred_username }}&quot;
  6058. display_name_template: &quot;{{ user.name }}&quot;
  6059. </code></pre>
  6060. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  6061. <ol>
  6062. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  6063. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  6064. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  6065. </ol>
  6066. <p>Synapse config:</p>
  6067. <pre><code class="language-yaml">oidc_providers:
  6068. - idp_id: gitlab
  6069. idp_name: Gitlab
  6070. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  6071. issuer: &quot;https://gitlab.com/&quot;
  6072. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6073. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6074. client_auth_method: &quot;client_secret_post&quot;
  6075. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  6076. user_profile_method: &quot;userinfo_endpoint&quot;
  6077. user_mapping_provider:
  6078. config:
  6079. localpart_template: '{{ user.nickname }}'
  6080. display_name_template: '{{ user.name }}'
  6081. </code></pre>
  6082. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  6083. <p>Like Github, Facebook provide a custom OAuth2 API rather than an OIDC-compliant
  6084. one so requires a little more configuration.</p>
  6085. <ol start="0">
  6086. <li>You will need a Facebook developer account. You can register for one
  6087. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  6088. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  6089. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  6090. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  6091. need to go through the whole form here.</li>
  6092. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  6093. <ul>
  6094. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  6095. URL.</li>
  6096. </ul>
  6097. </li>
  6098. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  6099. and &quot;App Secret&quot; for use below.</li>
  6100. </ol>
  6101. <p>Synapse config:</p>
  6102. <pre><code class="language-yaml"> - idp_id: facebook
  6103. idp_name: Facebook
  6104. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  6105. discover: false
  6106. issuer: &quot;https://facebook.com&quot;
  6107. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6108. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6109. scopes: [&quot;openid&quot;, &quot;email&quot;]
  6110. authorization_endpoint: https://facebook.com/dialog/oauth
  6111. token_endpoint: https://graph.facebook.com/v9.0/oauth/access_token
  6112. user_profile_method: &quot;userinfo_endpoint&quot;
  6113. userinfo_endpoint: &quot;https://graph.facebook.com/v9.0/me?fields=id,name,email,picture&quot;
  6114. user_mapping_provider:
  6115. config:
  6116. subject_claim: &quot;id&quot;
  6117. display_name_template: &quot;{{ user.name }}&quot;
  6118. </code></pre>
  6119. <p>Relevant documents:</p>
  6120. <ul>
  6121. <li>https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow</li>
  6122. <li>Using Facebook's Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/</li>
  6123. <li>Reference to the User endpoint: https://developers.facebook.com/docs/graph-api/reference/user</li>
  6124. </ul>
  6125. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  6126. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  6127. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  6128. can be used to retrieve information on the authenticated user. As the Synapse
  6129. login mechanism needs an attribute to uniquely identify users, and that endpoint
  6130. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  6131. <ol>
  6132. <li>Create a new application.</li>
  6133. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  6134. </ol>
  6135. <p>Synapse config:</p>
  6136. <pre><code class="language-yaml">oidc_providers:
  6137. - idp_id: gitea
  6138. idp_name: Gitea
  6139. discover: false
  6140. issuer: &quot;https://your-gitea.com/&quot;
  6141. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6142. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  6143. client_auth_method: client_secret_post
  6144. scopes: [] # Gitea doesn't support Scopes
  6145. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  6146. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  6147. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  6148. user_mapping_provider:
  6149. config:
  6150. subject_claim: &quot;id&quot;
  6151. localpart_template: &quot;{{ user.login }}&quot;
  6152. display_name_template: &quot;{{ user.full_name }}&quot;
  6153. </code></pre>
  6154. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  6155. <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>
  6156. <p>Synapse config:</p>
  6157. <pre><code class="language-yaml">oidc_providers:
  6158. - idp_id: xwiki
  6159. idp_name: &quot;XWiki&quot;
  6160. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  6161. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6162. client_auth_method: none
  6163. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  6164. user_profile_method: &quot;userinfo_endpoint&quot;
  6165. user_mapping_provider:
  6166. config:
  6167. localpart_template: &quot;{{ user.preferred_username }}&quot;
  6168. display_name_template: &quot;{{ user.name }}&quot;
  6169. </code></pre>
  6170. <h3 id="apple"><a class="header" href="#apple">Apple</a></h3>
  6171. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  6172. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  6173. private key with &quot;SiWA&quot; enabled.</p>
  6174. <p>As well as the private key file, you will need:</p>
  6175. <ul>
  6176. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  6177. <li>Team ID: a 10-character ID associated with your developer account.</li>
  6178. <li>Key ID: the 10-character identifier for the key.</li>
  6179. </ul>
  6180. <p>https://help.apple.com/developer-account/?lang=en#/dev77c875b7e has more
  6181. documentation on setting up SiWA.</p>
  6182. <p>The synapse config will look like this:</p>
  6183. <pre><code class="language-yaml"> - idp_id: apple
  6184. idp_name: Apple
  6185. issuer: &quot;https://appleid.apple.com&quot;
  6186. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  6187. client_auth_method: &quot;client_secret_post&quot;
  6188. client_secret_jwt_key:
  6189. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  6190. jwt_header:
  6191. alg: ES256
  6192. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  6193. jwt_payload:
  6194. iss: TEAMIDCODE # Set to the 10-char Team ID
  6195. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  6196. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  6197. user_mapping_provider:
  6198. config:
  6199. email_template: &quot;{{ user.email }}&quot;
  6200. </code></pre>
  6201. <h2 id="django-oauth-toolkit"><a class="header" href="#django-oauth-toolkit">Django OAuth Toolkit</a></h2>
  6202. <p><a href="https://github.com/jazzband/django-oauth-toolkit">django-oauth-toolkit</a> is a
  6203. Django application providing out of the box all the endpoints, data and logic
  6204. needed to add OAuth2 capabilities to your Django projects. It supports
  6205. <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html">OpenID Connect too</a>.</p>
  6206. <p>Configuration on Django's side:</p>
  6207. <ol>
  6208. <li>Add an application: https://example.com/admin/oauth2_provider/application/add/ and choose parameters like this:</li>
  6209. </ol>
  6210. <ul>
  6211. <li><code>Redirect uris</code>: https://synapse.example.com/_synapse/client/oidc/callback</li>
  6212. <li><code>Client type</code>: <code>Confidential</code></li>
  6213. <li><code>Authorization grant type</code>: <code>Authorization code</code></li>
  6214. <li><code>Algorithm</code>: <code>HMAC with SHA-2 256</code></li>
  6215. </ul>
  6216. <ol start="2">
  6217. <li>
  6218. <p>You can <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html#customizing-the-oidc-responses">customize the claims</a> Django gives to synapse (optional):</p>
  6219. <details>
  6220. <summary>Code sample</summary>
  6221. <pre><code class="language-python">class CustomOAuth2Validator(OAuth2Validator):
  6222. def get_additional_claims(self, request):
  6223. return {
  6224. &quot;sub&quot;: request.user.email,
  6225. &quot;email&quot;: request.user.email,
  6226. &quot;first_name&quot;: request.user.first_name,
  6227. &quot;last_name&quot;: request.user.last_name,
  6228. }
  6229. </code></pre>
  6230. </details>
  6231. </li>
  6232. </ol>
  6233. <p>Your synapse config is then:</p>
  6234. <pre><code class="language-yaml">oidc_providers:
  6235. - idp_id: django_example
  6236. idp_name: &quot;Django Example&quot;
  6237. issuer: &quot;https://example.com/o/&quot;
  6238. client_id: &quot;your-client-id&quot; # CHANGE ME
  6239. client_secret: &quot;your-client-secret&quot; # CHANGE ME
  6240. scopes: [&quot;openid&quot;]
  6241. user_profile_method: &quot;userinfo_endpoint&quot; # needed because oauth-toolkit does not include user information in the authorization response
  6242. user_mapping_provider:
  6243. config:
  6244. localpart_template: &quot;{{ user.email.split('@')[0] }}&quot;
  6245. display_name_template: &quot;{{ user.first_name }} {{ user.last_name }}&quot;
  6246. email_template: &quot;{{ user.email }}&quot;
  6247. </code></pre>
  6248. <div style="break-before: page; page-break-before: always;"></div><h1 id="sso-mapping-providers"><a class="header" href="#sso-mapping-providers">SSO Mapping Providers</a></h1>
  6249. <p>A mapping provider is a Python class (loaded via a Python module) that
  6250. works out how to map attributes of a SSO response to Matrix-specific
  6251. user attributes. Details such as user ID localpart, displayname, and even avatar
  6252. URLs are all things that can be mapped from talking to a SSO service.</p>
  6253. <p>As an example, a SSO service may return the email address
  6254. &quot;john.smith@example.com&quot; for a user, whereas Synapse will need to figure out how
  6255. to turn that into a displayname when creating a Matrix user for this individual.
  6256. It may choose <code>John Smith</code>, or <code>Smith, John [Example.com]</code> or any number of
  6257. variations. As each Synapse configuration may want something different, this is
  6258. where SAML mapping providers come into play.</p>
  6259. <p>SSO mapping providers are currently supported for OpenID and SAML SSO
  6260. configurations. Please see the details below for how to implement your own.</p>
  6261. <p>It is up to the mapping provider whether the user should be assigned a predefined
  6262. Matrix ID based on the SSO attributes, or if the user should be allowed to
  6263. choose their own username.</p>
  6264. <p>In the first case - where users are automatically allocated a Matrix ID - it is
  6265. the responsibility of the mapping provider to normalise the SSO attributes and
  6266. map them to a valid Matrix ID. The <a href="https://matrix.org/docs/spec/appendices#user-identifiers">specification for Matrix
  6267. IDs</a> has some
  6268. information about what is considered valid.</p>
  6269. <p>If the mapping provider does not assign a Matrix ID, then Synapse will
  6270. automatically serve an HTML page allowing the user to pick their own username.</p>
  6271. <p>External mapping providers are provided to Synapse in the form of an external
  6272. Python module. You can retrieve this module from <a href="https://pypi.org">PyPI</a> or elsewhere,
  6273. but it must be importable via Synapse (e.g. it must be in the same virtualenv
  6274. as Synapse). The Synapse config is then modified to point to the mapping provider
  6275. (and optionally provide additional configuration for it).</p>
  6276. <h2 id="openid-mapping-providers"><a class="header" href="#openid-mapping-providers">OpenID Mapping Providers</a></h2>
  6277. <p>The OpenID mapping provider can be customized by editing the
  6278. <code>oidc_config.user_mapping_provider.module</code> config option.</p>
  6279. <p><code>oidc_config.user_mapping_provider.config</code> allows you to provide custom
  6280. configuration options to the module. Check with the module's documentation for
  6281. what options it provides (if any). The options listed by default are for the
  6282. user mapping provider built in to Synapse. If using a custom module, you should
  6283. comment these options out and use those specified by the module instead.</p>
  6284. <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>
  6285. <p>A custom mapping provider must specify the following methods:</p>
  6286. <ul>
  6287. <li><code>__init__(self, parsed_config)</code>
  6288. <ul>
  6289. <li>Arguments:
  6290. <ul>
  6291. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6292. <code>parse_config</code> method. You should set any configuration options needed by
  6293. the module here.</li>
  6294. </ul>
  6295. </li>
  6296. </ul>
  6297. </li>
  6298. <li><code>parse_config(config)</code>
  6299. <ul>
  6300. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6301. <li>Arguments:
  6302. <ul>
  6303. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6304. <code>oidc_config.user_mapping_provider.config</code> homeserver config option.
  6305. Runs on homeserver startup. Providers should extract and validate
  6306. any option values they need here.</li>
  6307. </ul>
  6308. </li>
  6309. <li>Whatever is returned will be passed back to the user mapping provider module's
  6310. <code>__init__</code> method during construction.</li>
  6311. </ul>
  6312. </li>
  6313. <li><code>get_remote_user_id(self, userinfo)</code>
  6314. <ul>
  6315. <li>Arguments:
  6316. <ul>
  6317. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6318. information from.</li>
  6319. </ul>
  6320. </li>
  6321. <li>This method must return a string, which is the unique, immutable identifier
  6322. for the user. Commonly the <code>sub</code> claim of the response.</li>
  6323. </ul>
  6324. </li>
  6325. <li><code>map_user_attributes(self, userinfo, token, failures)</code>
  6326. <ul>
  6327. <li>This method must be async.</li>
  6328. <li>Arguments:
  6329. <ul>
  6330. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6331. information from.</li>
  6332. <li><code>token</code> - A dictionary which includes information necessary to make
  6333. further requests to the OpenID provider.</li>
  6334. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6335. mxid localpart mapping has failed. This should be used
  6336. to create a deduplicated mxid localpart which should be
  6337. returned instead. For example, if this method returns
  6338. <code>john.doe</code> as the value of <code>localpart</code> in the returned
  6339. dict, and that is already taken on the homeserver, this
  6340. method will be called again with the same parameters but
  6341. with failures=1. The method should then return a different
  6342. <code>localpart</code> value, such as <code>john.doe1</code>.</li>
  6343. </ul>
  6344. </li>
  6345. <li>Returns a dictionary with two keys:
  6346. <ul>
  6347. <li><code>localpart</code>: A string, used to generate the Matrix ID. If this is
  6348. <code>None</code>, the user is prompted to pick their own username. This is only used
  6349. during a user's first login. Once a localpart has been associated with a
  6350. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6351. <li><code>displayname</code>: An optional string, the display name for the user.</li>
  6352. </ul>
  6353. </li>
  6354. </ul>
  6355. </li>
  6356. <li><code>get_extra_attributes(self, userinfo, token)</code>
  6357. <ul>
  6358. <li>
  6359. <p>This method must be async.</p>
  6360. </li>
  6361. <li>
  6362. <p>Arguments:</p>
  6363. <ul>
  6364. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6365. information from.</li>
  6366. <li><code>token</code> - A dictionary which includes information necessary to make
  6367. further requests to the OpenID provider.</li>
  6368. </ul>
  6369. </li>
  6370. <li>
  6371. <p>Returns a dictionary that is suitable to be serialized to JSON. This
  6372. will be returned as part of the response during a successful login.</p>
  6373. <p>Note that care should be taken to not overwrite any of the parameters
  6374. 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>
  6375. </li>
  6376. </ul>
  6377. </li>
  6378. </ul>
  6379. <h3 id="default-openid-mapping-provider"><a class="header" href="#default-openid-mapping-provider">Default OpenID Mapping Provider</a></h3>
  6380. <p>Synapse has a built-in OpenID mapping provider if a custom provider isn't
  6381. specified in the config. It is located at
  6382. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/oidc.py"><code>synapse.handlers.oidc.JinjaOidcMappingProvider</code></a>.</p>
  6383. <h2 id="saml-mapping-providers"><a class="header" href="#saml-mapping-providers">SAML Mapping Providers</a></h2>
  6384. <p>The SAML mapping provider can be customized by editing the
  6385. <code>saml2_config.user_mapping_provider.module</code> config option.</p>
  6386. <p><code>saml2_config.user_mapping_provider.config</code> allows you to provide custom
  6387. configuration options to the module. Check with the module's documentation for
  6388. what options it provides (if any). The options listed by default are for the
  6389. user mapping provider built in to Synapse. If using a custom module, you should
  6390. comment these options out and use those specified by the module instead.</p>
  6391. <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>
  6392. <p>A custom mapping provider must specify the following methods:</p>
  6393. <ul>
  6394. <li><code>__init__(self, parsed_config, module_api)</code>
  6395. <ul>
  6396. <li>Arguments:
  6397. <ul>
  6398. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6399. <code>parse_config</code> method. You should set any configuration options needed by
  6400. the module here.</li>
  6401. <li><code>module_api</code> - a <code>synapse.module_api.ModuleApi</code> object which provides the
  6402. stable API available for extension modules.</li>
  6403. </ul>
  6404. </li>
  6405. </ul>
  6406. </li>
  6407. <li><code>parse_config(config)</code>
  6408. <ul>
  6409. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6410. <li>Arguments:
  6411. <ul>
  6412. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6413. <code>saml_config.user_mapping_provider.config</code> homeserver config option.
  6414. Runs on homeserver startup. Providers should extract and validate
  6415. any option values they need here.</li>
  6416. </ul>
  6417. </li>
  6418. <li>Whatever is returned will be passed back to the user mapping provider module's
  6419. <code>__init__</code> method during construction.</li>
  6420. </ul>
  6421. </li>
  6422. <li><code>get_saml_attributes(config)</code>
  6423. <ul>
  6424. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6425. <li>Arguments:
  6426. <ul>
  6427. <li><code>config</code> - A object resulting from a call to <code>parse_config</code>.</li>
  6428. </ul>
  6429. </li>
  6430. <li>Returns a tuple of two sets. The first set equates to the SAML auth
  6431. response attributes that are required for the module to function, whereas
  6432. the second set consists of those attributes which can be used if available,
  6433. but are not necessary.</li>
  6434. </ul>
  6435. </li>
  6436. <li><code>get_remote_user_id(self, saml_response, client_redirect_url)</code>
  6437. <ul>
  6438. <li>Arguments:
  6439. <ul>
  6440. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6441. information from.</li>
  6442. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6443. redirected to.</li>
  6444. </ul>
  6445. </li>
  6446. <li>This method must return a string, which is the unique, immutable identifier
  6447. for the user. Commonly the <code>uid</code> claim of the response.</li>
  6448. </ul>
  6449. </li>
  6450. <li><code>saml_response_to_user_attributes(self, saml_response, failures, client_redirect_url)</code>
  6451. <ul>
  6452. <li>
  6453. <p>Arguments:</p>
  6454. <ul>
  6455. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6456. information from.</li>
  6457. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6458. mxid localpart mapping has failed. This should be used
  6459. to create a deduplicated mxid localpart which should be
  6460. returned instead. For example, if this method returns
  6461. <code>john.doe</code> as the value of <code>mxid_localpart</code> in the returned
  6462. dict, and that is already taken on the homeserver, this
  6463. method will be called again with the same parameters but
  6464. with failures=1. The method should then return a different
  6465. <code>mxid_localpart</code> value, such as <code>john.doe1</code>.</li>
  6466. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6467. redirected to.</li>
  6468. </ul>
  6469. </li>
  6470. <li>
  6471. <p>This method must return a dictionary, which will then be used by Synapse
  6472. to build a new user. The following keys are allowed:</p>
  6473. <ul>
  6474. <li><code>mxid_localpart</code> - A string, the mxid localpart of the new user. If this is
  6475. <code>None</code>, the user is prompted to pick their own username. This is only used
  6476. during a user's first login. Once a localpart has been associated with a
  6477. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6478. <li><code>displayname</code> - The displayname of the new user. If not provided, will default to
  6479. the value of <code>mxid_localpart</code>.</li>
  6480. <li><code>emails</code> - A list of emails for the new user. If not provided, will
  6481. default to an empty list.</li>
  6482. </ul>
  6483. <p>Alternatively it can raise a <code>synapse.api.errors.RedirectException</code> to
  6484. redirect the user to another page. This is useful to prompt the user for
  6485. additional information, e.g. if you want them to provide their own username.
  6486. It is the responsibility of the mapping provider to either redirect back
  6487. to <code>client_redirect_url</code> (including any additional information) or to
  6488. complete registration using methods from the <code>ModuleApi</code>.</p>
  6489. </li>
  6490. </ul>
  6491. </li>
  6492. </ul>
  6493. <h3 id="default-saml-mapping-provider"><a class="header" href="#default-saml-mapping-provider">Default SAML Mapping Provider</a></h3>
  6494. <p>Synapse has a built-in SAML mapping provider if a custom provider isn't
  6495. specified in the config. It is located at
  6496. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/saml.py"><code>synapse.handlers.saml.DefaultSamlMappingProvider</code></a>.</p>
  6497. <div style="break-before: page; page-break-before: always;"></div><h2 style="color:red">
  6498. This page of the Synapse documentation is now deprecated. For up to date
  6499. documentation on setting up or writing a password auth provider module, please see
  6500. <a href="modules.html">this page</a>.
  6501. </h2>
  6502. <h1 id="password-auth-provider-modules"><a class="header" href="#password-auth-provider-modules">Password auth provider modules</a></h1>
  6503. <p>Password auth providers offer a way for server administrators to
  6504. integrate their Synapse installation with an existing authentication
  6505. system.</p>
  6506. <p>A password auth provider is a Python class which is dynamically loaded
  6507. into Synapse, and provides a number of methods by which it can integrate
  6508. with the authentication system.</p>
  6509. <p>This document serves as a reference for those looking to implement their
  6510. own password auth providers. Additionally, here is a list of known
  6511. password auth provider module implementations:</p>
  6512. <ul>
  6513. <li><a href="https://github.com/matrix-org/matrix-synapse-ldap3/">matrix-synapse-ldap3</a></li>
  6514. <li><a href="https://github.com/devture/matrix-synapse-shared-secret-auth">matrix-synapse-shared-secret-auth</a></li>
  6515. <li><a href="https://github.com/ma1uta/matrix-synapse-rest-password-provider">matrix-synapse-rest-password-provider</a></li>
  6516. </ul>
  6517. <h2 id="required-methods"><a class="header" href="#required-methods">Required methods</a></h2>
  6518. <p>Password auth provider classes must provide the following methods:</p>
  6519. <ul>
  6520. <li>
  6521. <p><code>parse_config(config)</code>
  6522. This method is passed the <code>config</code> object for this module from the
  6523. homeserver configuration file.</p>
  6524. <p>It should perform any appropriate sanity checks on the provided
  6525. configuration, and return an object which is then passed into
  6526. <code>__init__</code>.</p>
  6527. <p>This method should have the <code>@staticmethod</code> decoration.</p>
  6528. </li>
  6529. <li>
  6530. <p><code>__init__(self, config, account_handler)</code></p>
  6531. <p>The constructor is passed the config object returned by
  6532. <code>parse_config</code>, and a <code>synapse.module_api.ModuleApi</code> object which
  6533. allows the password provider to check if accounts exist and/or create
  6534. new ones.</p>
  6535. </li>
  6536. </ul>
  6537. <h2 id="optional-methods"><a class="header" href="#optional-methods">Optional methods</a></h2>
  6538. <p>Password auth provider classes may optionally provide the following methods:</p>
  6539. <ul>
  6540. <li>
  6541. <p><code>get_db_schema_files(self)</code></p>
  6542. <p>This method, if implemented, should return an Iterable of
  6543. <code>(name, stream)</code> pairs of database schema files. Each file is applied
  6544. in turn at initialisation, and a record is then made in the database
  6545. so that it is not re-applied on the next start.</p>
  6546. </li>
  6547. <li>
  6548. <p><code>get_supported_login_types(self)</code></p>
  6549. <p>This method, if implemented, should return a <code>dict</code> mapping from a
  6550. login type identifier (such as <code>m.login.password</code>) to an iterable
  6551. giving the fields which must be provided by the user in the submission
  6552. to <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login">the <code>/login</code> API</a>.
  6553. These fields are passed in the <code>login_dict</code> dictionary to <code>check_auth</code>.</p>
  6554. <p>For example, if a password auth provider wants to implement a custom
  6555. login type of <code>com.example.custom_login</code>, where the client is expected
  6556. to pass the fields <code>secret1</code> and <code>secret2</code>, the provider should
  6557. implement this method and return the following dict:</p>
  6558. <pre><code class="language-python">{&quot;com.example.custom_login&quot;: (&quot;secret1&quot;, &quot;secret2&quot;)}
  6559. </code></pre>
  6560. </li>
  6561. <li>
  6562. <p><code>check_auth(self, username, login_type, login_dict)</code></p>
  6563. <p>This method does the real work. If implemented, it
  6564. will be called for each login attempt where the login type matches one
  6565. of the keys returned by <code>get_supported_login_types</code>.</p>
  6566. <p>It is passed the (possibly unqualified) <code>user</code> field provided by the client,
  6567. the login type, and a dictionary of login secrets passed by the
  6568. client.</p>
  6569. <p>The method should return an <code>Awaitable</code> object, which resolves
  6570. to the canonical <code>@localpart:domain</code> user ID if authentication is
  6571. successful, and <code>None</code> if not.</p>
  6572. <p>Alternatively, the <code>Awaitable</code> can resolve to a <code>(str, func)</code> tuple, in
  6573. which case the second field is a callback which will be called with
  6574. the result from the <code>/login</code> call (including <code>access_token</code>,
  6575. <code>device_id</code>, etc.)</p>
  6576. </li>
  6577. <li>
  6578. <p><code>check_3pid_auth(self, medium, address, password)</code></p>
  6579. <p>This method, if implemented, is called when a user attempts to
  6580. register or log in with a third party identifier, such as email. It is
  6581. passed the medium (ex. &quot;email&quot;), an address (ex.
  6582. &quot;<a href="mailto:jdoe@example.com">jdoe@example.com</a>&quot;) and the user's password.</p>
  6583. <p>The method should return an <code>Awaitable</code> object, which resolves
  6584. to a <code>str</code> containing the user's (canonical) User id if
  6585. authentication was successful, and <code>None</code> if not.</p>
  6586. <p>As with <code>check_auth</code>, the <code>Awaitable</code> may alternatively resolve to a
  6587. <code>(user_id, callback)</code> tuple.</p>
  6588. </li>
  6589. <li>
  6590. <p><code>check_password(self, user_id, password)</code></p>
  6591. <p>This method provides a simpler interface than
  6592. <code>get_supported_login_types</code> and <code>check_auth</code> for password auth
  6593. providers that just want to provide a mechanism for validating
  6594. <code>m.login.password</code> logins.</p>
  6595. <p>If implemented, it will be called to check logins with an
  6596. <code>m.login.password</code> login type. It is passed a qualified
  6597. <code>@localpart:domain</code> user id, and the password provided by the user.</p>
  6598. <p>The method should return an <code>Awaitable</code> object, which resolves
  6599. to <code>True</code> if authentication is successful, and <code>False</code> if not.</p>
  6600. </li>
  6601. <li>
  6602. <p><code>on_logged_out(self, user_id, device_id, access_token)</code></p>
  6603. <p>This method, if implemented, is called when a user logs out. It is
  6604. passed the qualified user ID, the ID of the deactivated device (if
  6605. any: access tokens are occasionally created without an associated
  6606. device ID), and the (now deactivated) access token.</p>
  6607. <p>It may return an <code>Awaitable</code> object; the logout request will
  6608. wait for the <code>Awaitable</code> to complete, but the result is ignored.</p>
  6609. </li>
  6610. </ul>
  6611. <div style="break-before: page; page-break-before: always;"></div><h1 id="jwt-login-type"><a class="header" href="#jwt-login-type">JWT Login Type</a></h1>
  6612. <p>Synapse comes with a non-standard login type to support
  6613. <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">JSON Web Tokens</a>. In general the
  6614. documentation for
  6615. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#login">the login endpoint</a>
  6616. is still valid (and the mechanism works similarly to the
  6617. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#token-based">token based login</a>).</p>
  6618. <p>To log in using a JSON Web Token, clients should submit a <code>/login</code> request as
  6619. follows:</p>
  6620. <pre><code class="language-json">{
  6621. &quot;type&quot;: &quot;org.matrix.login.jwt&quot;,
  6622. &quot;token&quot;: &quot;&lt;jwt&gt;&quot;
  6623. }
  6624. </code></pre>
  6625. <p>Note that the login type of <code>m.login.jwt</code> is supported, but is deprecated. This
  6626. will be removed in a future version of Synapse.</p>
  6627. <p>The <code>token</code> field should include the JSON web token with the following claims:</p>
  6628. <ul>
  6629. <li>The <code>sub</code> (subject) claim is required and should encode the local part of the
  6630. user ID.</li>
  6631. <li>The expiration time (<code>exp</code>), not before time (<code>nbf</code>), and issued at (<code>iat</code>)
  6632. claims are optional, but validated if present.</li>
  6633. <li>The issuer (<code>iss</code>) claim is optional, but required and validated if configured.</li>
  6634. <li>The audience (<code>aud</code>) claim is optional, but required and validated if configured.
  6635. Providing the audience claim when not configured will cause validation to fail.</li>
  6636. </ul>
  6637. <p>In the case that the token is not valid, the homeserver must respond with
  6638. <code>403 Forbidden</code> and an error code of <code>M_FORBIDDEN</code>.</p>
  6639. <p>As with other login types, there are additional fields (e.g. <code>device_id</code> and
  6640. <code>initial_device_display_name</code>) which can be included in the above request.</p>
  6641. <h2 id="preparing-synapse-1"><a class="header" href="#preparing-synapse-1">Preparing Synapse</a></h2>
  6642. <p>The JSON Web Token integration in Synapse uses the
  6643. <a href="https://pypi.org/project/pyjwt/"><code>PyJWT</code></a> library, which must be installed
  6644. as follows:</p>
  6645. <ul>
  6646. <li>
  6647. <p>The relevant libraries are included in the Docker images and Debian packages
  6648. provided by <code>matrix.org</code> so no further action is needed.</p>
  6649. </li>
  6650. <li>
  6651. <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>
  6652. </li>
  6653. <li>
  6654. <p>For other installation mechanisms, see the documentation provided by the
  6655. maintainer.</p>
  6656. </li>
  6657. </ul>
  6658. <p>To enable the JSON web token integration, you should then add an <code>jwt_config</code> section
  6659. to your configuration file (or uncomment the <code>enabled: true</code> line in the
  6660. existing section). See <a href="./sample_config.yaml">sample_config.yaml</a> for some
  6661. sample settings.</p>
  6662. <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>
  6663. <p>Although JSON Web Tokens are typically generated from an external server, the
  6664. examples below use <a href="https://pyjwt.readthedocs.io/en/latest/">PyJWT</a> directly.</p>
  6665. <ol>
  6666. <li>
  6667. <p>Configure Synapse with JWT logins, note that this example uses a pre-shared
  6668. secret and an algorithm of HS256:</p>
  6669. <pre><code class="language-yaml">jwt_config:
  6670. enabled: true
  6671. secret: &quot;my-secret-token&quot;
  6672. algorithm: &quot;HS256&quot;
  6673. </code></pre>
  6674. </li>
  6675. <li>
  6676. <p>Generate a JSON web token:</p>
  6677. <pre><code class="language-bash">$ pyjwt --key=my-secret-token --alg=HS256 encode sub=test-user
  6678. eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc
  6679. </code></pre>
  6680. </li>
  6681. <li>
  6682. <p>Query for the login types and ensure <code>org.matrix.login.jwt</code> is there:</p>
  6683. <pre><code class="language-bash">curl http://localhost:8080/_matrix/client/r0/login
  6684. </code></pre>
  6685. </li>
  6686. <li>
  6687. <p>Login used the generated JSON web token from above:</p>
  6688. <pre><code class="language-bash">$ curl http://localhost:8082/_matrix/client/r0/login -X POST \
  6689. --data '{&quot;type&quot;:&quot;org.matrix.login.jwt&quot;,&quot;token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc&quot;}'
  6690. {
  6691. &quot;access_token&quot;: &quot;&lt;access token&gt;&quot;,
  6692. &quot;device_id&quot;: &quot;ACBDEFGHI&quot;,
  6693. &quot;home_server&quot;: &quot;localhost:8080&quot;,
  6694. &quot;user_id&quot;: &quot;@test-user:localhost:8480&quot;
  6695. }
  6696. </code></pre>
  6697. </li>
  6698. </ol>
  6699. <p>You should now be able to use the returned access token to query the client API.</p>
  6700. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-2"><a class="header" href="#overview-2">Overview</a></h1>
  6701. <p>A captcha can be enabled on your homeserver to help prevent bots from registering
  6702. accounts. Synapse currently uses Google's reCAPTCHA service which requires API keys
  6703. from Google.</p>
  6704. <h2 id="getting-api-keys"><a class="header" href="#getting-api-keys">Getting API keys</a></h2>
  6705. <ol>
  6706. <li>Create a new site at <a href="https://www.google.com/recaptcha/admin/create">https://www.google.com/recaptcha/admin/create</a></li>
  6707. <li>Set the label to anything you want</li>
  6708. <li>Set the type to reCAPTCHA v2 using the &quot;I'm not a robot&quot; Checkbox option.
  6709. This is the only type of captcha that works with Synapse.</li>
  6710. <li>Add the public hostname for your server, as set in <code>public_baseurl</code>
  6711. in <code>homeserver.yaml</code>, to the list of authorized domains. If you have not set
  6712. <code>public_baseurl</code>, use <code>server_name</code>.</li>
  6713. <li>Agree to the terms of service and submit.</li>
  6714. <li>Copy your site key and secret key and add them to your <code>homeserver.yaml</code>
  6715. configuration file
  6716. <pre><code>recaptcha_public_key: YOUR_SITE_KEY
  6717. recaptcha_private_key: YOUR_SECRET_KEY
  6718. </code></pre>
  6719. </li>
  6720. <li>Enable the CAPTCHA for new registrations
  6721. <pre><code>enable_registration_captcha: true
  6722. </code></pre>
  6723. </li>
  6724. <li>Go to the settings page for the CAPTCHA you just created</li>
  6725. <li>Uncheck the &quot;Verify the origin of reCAPTCHA solutions&quot; checkbox so that the
  6726. captcha can be displayed in any client. If you do not disable this option then you
  6727. must specify the domains of every client that is allowed to display the CAPTCHA.</li>
  6728. </ol>
  6729. <h2 id="configuring-ip-used-for-auth"><a class="header" href="#configuring-ip-used-for-auth">Configuring IP used for auth</a></h2>
  6730. <p>The reCAPTCHA API requires that the IP address of the user who solved the
  6731. CAPTCHA is sent. If the client is connecting through a proxy or load balancer,
  6732. it may be required to use the <code>X-Forwarded-For</code> (XFF) header instead of the origin
  6733. IP address. This can be configured using the <code>x_forwarded</code> directive in the
  6734. listeners section of the <code>homeserver.yaml</code> configuration file.</p>
  6735. <div style="break-before: page; page-break-before: always;"></div><h1 id="registering-an-application-service"><a class="header" href="#registering-an-application-service">Registering an Application Service</a></h1>
  6736. <p>The registration of new application services depends on the homeserver used.
  6737. In synapse, you need to create a new configuration file for your AS and add it
  6738. to the list specified under the <code>app_service_config_files</code> config
  6739. option in your synapse config.</p>
  6740. <p>For example:</p>
  6741. <pre><code class="language-yaml">app_service_config_files:
  6742. - /home/matrix/.synapse/&lt;your-AS&gt;.yaml
  6743. </code></pre>
  6744. <p>The format of the AS configuration file is as follows:</p>
  6745. <pre><code class="language-yaml">url: &lt;base url of AS&gt;
  6746. as_token: &lt;token AS will add to requests to HS&gt;
  6747. hs_token: &lt;token HS will add to requests to AS&gt;
  6748. sender_localpart: &lt;localpart of AS user&gt;
  6749. namespaces:
  6750. users: # List of users we're interested in
  6751. - exclusive: &lt;bool&gt;
  6752. regex: &lt;regex&gt;
  6753. group_id: &lt;group&gt;
  6754. - ...
  6755. aliases: [] # List of aliases we're interested in
  6756. rooms: [] # List of room ids we're interested in
  6757. </code></pre>
  6758. <p><code>exclusive</code>: If enabled, only this application service is allowed to register users in its namespace(s).
  6759. <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>
  6760. <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>
  6761. <div style="break-before: page; page-break-before: always;"></div><h1 id="server-notices"><a class="header" href="#server-notices">Server Notices</a></h1>
  6762. <p>'Server Notices' are a new feature introduced in Synapse 0.30. They provide a
  6763. channel whereby server administrators can send messages to users on the server.</p>
  6764. <p>They are used as part of communication of the server polices (see
  6765. <a href="consent_tracking.html">Consent Tracking</a>), however the intention is that
  6766. they may also find a use for features such as &quot;Message of the day&quot;.</p>
  6767. <p>This is a feature specific to Synapse, but it uses standard Matrix
  6768. communication mechanisms, so should work with any Matrix client.</p>
  6769. <h2 id="user-experience"><a class="header" href="#user-experience">User experience</a></h2>
  6770. <p>When the user is first sent a server notice, they will get an invitation to a
  6771. room (typically called 'Server Notices', though this is configurable in
  6772. <code>homeserver.yaml</code>). They will be <strong>unable to reject</strong> this invitation -
  6773. attempts to do so will receive an error.</p>
  6774. <p>Once they accept the invitation, they will see the notice message in the room
  6775. history; it will appear to have come from the 'server notices user' (see
  6776. below).</p>
  6777. <p>The user is prevented from sending any messages in this room by the power
  6778. levels.</p>
  6779. <p>Having joined the room, the user can leave the room if they want. Subsequent
  6780. server notices will then cause a new room to be created.</p>
  6781. <h2 id="synapse-configuration"><a class="header" href="#synapse-configuration">Synapse configuration</a></h2>
  6782. <p>Server notices come from a specific user id on the server. Server
  6783. administrators are free to choose the user id - something like <code>server</code> is
  6784. suggested, meaning the notices will come from
  6785. <code>@server:&lt;your_server_name&gt;</code>. Once the Server Notices user is configured, that
  6786. user id becomes a special, privileged user, so administrators should ensure
  6787. that <strong>it is not already allocated</strong>.</p>
  6788. <p>In order to support server notices, it is necessary to add some configuration
  6789. to the <code>homeserver.yaml</code> file. In particular, you should add a <code>server_notices</code>
  6790. section, which should look like this:</p>
  6791. <pre><code class="language-yaml">server_notices:
  6792. system_mxid_localpart: server
  6793. system_mxid_display_name: &quot;Server Notices&quot;
  6794. system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  6795. room_name: &quot;Server Notices&quot;
  6796. </code></pre>
  6797. <p>The only compulsory setting is <code>system_mxid_localpart</code>, which defines the user
  6798. id of the Server Notices user, as above. <code>room_name</code> defines the name of the
  6799. room which will be created.</p>
  6800. <p><code>system_mxid_display_name</code> and <code>system_mxid_avatar_url</code> can be used to set the
  6801. displayname and avatar of the Server Notices user.</p>
  6802. <h2 id="sending-notices"><a class="header" href="#sending-notices">Sending notices</a></h2>
  6803. <p>To send server notices to users you can use the
  6804. <a href="admin_api/server_notices.html">admin_api</a>.</p>
  6805. <div style="break-before: page; page-break-before: always;"></div><h1 id="support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions"><a class="header" href="#support-in-synapse-for-tracking-agreement-to-server-terms-and-conditions">Support in Synapse for tracking agreement to server terms and conditions</a></h1>
  6806. <p>Synapse 0.30 introduces support for tracking whether users have agreed to the
  6807. terms and conditions set by the administrator of a server - and blocking access
  6808. to the server until they have.</p>
  6809. <p>There are several parts to this functionality; each requires some specific
  6810. configuration in <code>homeserver.yaml</code> to be enabled.</p>
  6811. <p>Note that various parts of the configuation and this document refer to the
  6812. &quot;privacy policy&quot;: agreement with a privacy policy is one particular use of this
  6813. feature, but of course adminstrators can specify other terms and conditions
  6814. unrelated to &quot;privacy&quot; per se.</p>
  6815. <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>
  6816. <p>Synapse can be configured to serve the user a simple policy form with an
  6817. &quot;accept&quot; button. Clicking &quot;Accept&quot; records the user's acceptance in the
  6818. database and shows a success page.</p>
  6819. <p>To enable this, first create templates for the policy and success pages.
  6820. These should be stored on the local filesystem.</p>
  6821. <p>These templates use the <a href="http://jinja.pocoo.org">Jinja2</a> templating language,
  6822. and <a href="https://github.com/matrix-org/synapse/tree/develop/docs/privacy_policy_templates/">docs/privacy_policy_templates</a>
  6823. gives examples of the sort of thing that can be done.</p>
  6824. <p>Note that the templates must be stored under a name giving the language of the
  6825. template - currently this must always be <code>en</code> (for &quot;English&quot;);
  6826. internationalisation support is intended for the future.</p>
  6827. <p>The template for the policy itself should be versioned and named according to
  6828. the version: for example <code>1.0.html</code>. The version of the policy which the user
  6829. has agreed to is stored in the database.</p>
  6830. <p>Once the templates are in place, make the following changes to <code>homeserver.yaml</code>:</p>
  6831. <ol>
  6832. <li>
  6833. <p>Add a <code>user_consent</code> section, which should look like:</p>
  6834. <pre><code class="language-yaml">user_consent:
  6835. template_dir: privacy_policy_templates
  6836. version: 1.0
  6837. </code></pre>
  6838. <p><code>template_dir</code> points to the directory containing the policy
  6839. templates. <code>version</code> defines the version of the policy which will be served
  6840. to the user. In the example above, Synapse will serve
  6841. <code>privacy_policy_templates/en/1.0.html</code>.</p>
  6842. </li>
  6843. <li>
  6844. <p>Add a <code>form_secret</code> setting at the top level:</p>
  6845. <pre><code class="language-yaml">form_secret: &quot;&lt;unique secret&gt;&quot;
  6846. </code></pre>
  6847. <p>This should be set to an arbitrary secret string (try <code>pwgen -y 30</code> to
  6848. generate suitable secrets).</p>
  6849. <p>More on what this is used for below.</p>
  6850. </li>
  6851. <li>
  6852. <p>Add <code>consent</code> wherever the <code>client</code> resource is currently enabled in the
  6853. <code>listeners</code> configuration. For example:</p>
  6854. <pre><code class="language-yaml">listeners:
  6855. - port: 8008
  6856. resources:
  6857. - names:
  6858. - client
  6859. - consent
  6860. </code></pre>
  6861. </li>
  6862. </ol>
  6863. <p>Finally, ensure that <code>jinja2</code> is installed. If you are using a virtualenv, this
  6864. should be a matter of <code>pip install Jinja2</code>. On debian, try <code>apt-get install python-jinja2</code>.</p>
  6865. <p>Once this is complete, and the server has been restarted, try visiting
  6866. <code>https://&lt;server&gt;/_matrix/consent</code>. If correctly configured, this should give
  6867. an error &quot;Missing string query parameter 'u'&quot;. It is now possible to manually
  6868. construct URIs where users can give their consent.</p>
  6869. <h3 id="enabling-consent-tracking-at-registration"><a class="header" href="#enabling-consent-tracking-at-registration">Enabling consent tracking at registration</a></h3>
  6870. <ol>
  6871. <li>
  6872. <p>Add the following to your configuration:</p>
  6873. <pre><code class="language-yaml">user_consent:
  6874. require_at_registration: true
  6875. policy_name: &quot;Privacy Policy&quot; # or whatever you'd like to call the policy
  6876. </code></pre>
  6877. </li>
  6878. <li>
  6879. <p>In your consent templates, make use of the <code>public_version</code> variable to
  6880. see if an unauthenticated user is viewing the page. This is typically
  6881. wrapped around the form that would be used to actually agree to the document:</p>
  6882. <pre><code>{% if not public_version %}
  6883. &lt;!-- The variables used here are only provided when the 'u' param is given to the homeserver --&gt;
  6884. &lt;form method=&quot;post&quot; action=&quot;consent&quot;&gt;
  6885. &lt;input type=&quot;hidden&quot; name=&quot;v&quot; value=&quot;{{version}}&quot;/&gt;
  6886. &lt;input type=&quot;hidden&quot; name=&quot;u&quot; value=&quot;{{user}}&quot;/&gt;
  6887. &lt;input type=&quot;hidden&quot; name=&quot;h&quot; value=&quot;{{userhmac}}&quot;/&gt;
  6888. &lt;input type=&quot;submit&quot; value=&quot;Sure thing!&quot;/&gt;
  6889. &lt;/form&gt;
  6890. {% endif %}
  6891. </code></pre>
  6892. </li>
  6893. <li>
  6894. <p>Restart Synapse to apply the changes.</p>
  6895. </li>
  6896. </ol>
  6897. <p>Visiting <code>https://&lt;server&gt;/_matrix/consent</code> should now give you a view of the privacy
  6898. document. This is what users will be able to see when registering for accounts.</p>
  6899. <h3 id="constructing-the-consent-uri"><a class="header" href="#constructing-the-consent-uri">Constructing the consent URI</a></h3>
  6900. <p>It may be useful to manually construct the &quot;consent URI&quot; for a given user - for
  6901. instance, in order to send them an email asking them to consent. To do this,
  6902. take the base <code>https://&lt;server&gt;/_matrix/consent</code> URL and add the following
  6903. query parameters:</p>
  6904. <ul>
  6905. <li>
  6906. <p><code>u</code>: the user id of the user. This can either be a full MXID
  6907. (<code>@user:server.com</code>) or just the localpart (<code>user</code>).</p>
  6908. </li>
  6909. <li>
  6910. <p><code>h</code>: hex-encoded HMAC-SHA256 of <code>u</code> using the <code>form_secret</code> as a key. It is
  6911. possible to calculate this on the commandline with something like:</p>
  6912. <pre><code class="language-bash">echo -n '&lt;user&gt;' | openssl sha256 -hmac '&lt;form_secret&gt;'
  6913. </code></pre>
  6914. <p>This should result in a URI which looks something like:
  6915. <code>https://&lt;server&gt;/_matrix/consent?u=&lt;user&gt;&amp;h=68a152465a4d...</code>.</p>
  6916. </li>
  6917. </ul>
  6918. <p>Note that not providing a <code>u</code> parameter will be interpreted as wanting to view
  6919. the document from an unauthenticated perspective, such as prior to registration.
  6920. Therefore, the <code>h</code> parameter is not required in this scenario. To enable this
  6921. behaviour, set <code>require_at_registration</code> to <code>true</code> in your <code>user_consent</code> config.</p>
  6922. <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>
  6923. <p>It is possible to configure Synapse to send a <a href="server_notices.html">server
  6924. notice</a> to anybody who has not yet agreed to the current
  6925. version of the policy. To do so:</p>
  6926. <ul>
  6927. <li>
  6928. <p>ensure that the consent resource is configured, as in the previous section</p>
  6929. </li>
  6930. <li>
  6931. <p>ensure that server notices are configured, as in <a href="server_notices.html">the server notice documentation</a>.</p>
  6932. </li>
  6933. <li>
  6934. <p>Add <code>server_notice_content</code> under <code>user_consent</code> in <code>homeserver.yaml</code>. For
  6935. example:</p>
  6936. <pre><code class="language-yaml">user_consent:
  6937. server_notice_content:
  6938. msgtype: m.text
  6939. body: &gt;-
  6940. Please give your consent to the privacy policy at %(consent_uri)s.
  6941. </code></pre>
  6942. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6943. consent uri for that user.</p>
  6944. </li>
  6945. <li>
  6946. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6947. URI that clients use to connect to the server. (It is used to construct
  6948. <code>consent_uri</code> in the server notice.)</p>
  6949. </li>
  6950. </ul>
  6951. <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>
  6952. <p>Synapse can be configured to block any attempts to join rooms or send messages
  6953. until the user has given their agreement to the policy. (Joining the server
  6954. notices room is exempted from this).</p>
  6955. <p>To enable this, add <code>block_events_error</code> under <code>user_consent</code>. For example:</p>
  6956. <pre><code class="language-yaml">user_consent:
  6957. block_events_error: &gt;-
  6958. You can't send any messages until you consent to the privacy policy at
  6959. %(consent_uri)s.
  6960. </code></pre>
  6961. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6962. consent uri for that user.</p>
  6963. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6964. URI that clients use to connect to the server. (It is used to construct
  6965. <code>consent_uri</code> in the error.)</p>
  6966. <div style="break-before: page; page-break-before: always;"></div><h1 id="url-previews-1"><a class="header" href="#url-previews-1">URL Previews</a></h1>
  6967. <p>The <code>GET /_matrix/media/r0/preview_url</code> endpoint provides a generic preview API
  6968. for URLs which outputs <a href="https://ogp.me/">Open Graph</a> responses (with some Matrix
  6969. specific additions).</p>
  6970. <p>This does have trade-offs compared to other designs:</p>
  6971. <ul>
  6972. <li>Pros:
  6973. <ul>
  6974. <li>Simple and flexible; can be used by any clients at any point</li>
  6975. </ul>
  6976. </li>
  6977. <li>Cons:
  6978. <ul>
  6979. <li>If each homeserver provides one of these independently, all the HSes in a
  6980. room may needlessly DoS the target URI</li>
  6981. <li>The URL metadata must be stored somewhere, rather than just using Matrix
  6982. itself to store the media.</li>
  6983. <li>Matrix cannot be used to distribute the metadata between homeservers.</li>
  6984. </ul>
  6985. </li>
  6986. </ul>
  6987. <p>When Synapse is asked to preview a URL it does the following:</p>
  6988. <ol>
  6989. <li>Checks against a URL blacklist (defined as <code>url_preview_url_blacklist</code> in the
  6990. config).</li>
  6991. <li>Checks the in-memory cache by URLs and returns the result if it exists. (This
  6992. is also used to de-duplicate processing of multiple in-flight requests at once.)</li>
  6993. <li>Kicks off a background process to generate a preview:
  6994. <ol>
  6995. <li>Checks the database cache by URL and timestamp and returns the result if it
  6996. has not expired and was successful (a 2xx return code).</li>
  6997. <li>Checks if the URL matches an <a href="https://oembed.com/">oEmbed</a> pattern. If it
  6998. does, update the URL to download.</li>
  6999. <li>Downloads the URL and stores it into a file via the media storage provider
  7000. and saves the local media metadata.</li>
  7001. <li>If the media is an image:
  7002. <ol>
  7003. <li>Generates thumbnails.</li>
  7004. <li>Generates an Open Graph response based on image properties.</li>
  7005. </ol>
  7006. </li>
  7007. <li>If the media is HTML:
  7008. <ol>
  7009. <li>Decodes the HTML via the stored file.</li>
  7010. <li>Generates an Open Graph response from the HTML.</li>
  7011. <li>If an image exists in the Open Graph response:
  7012. <ol>
  7013. <li>Downloads the URL and stores it into a file via the media storage
  7014. provider and saves the local media metadata.</li>
  7015. <li>Generates thumbnails.</li>
  7016. <li>Updates the Open Graph response based on image properties.</li>
  7017. </ol>
  7018. </li>
  7019. </ol>
  7020. </li>
  7021. <li>If the media is JSON and an oEmbed URL was found:
  7022. <ol>
  7023. <li>Convert the oEmbed response to an Open Graph response.</li>
  7024. <li>If a thumbnail or image is in the oEmbed response:
  7025. <ol>
  7026. <li>Downloads the URL and stores it into a file via the media storage
  7027. provider and saves the local media metadata.</li>
  7028. <li>Generates thumbnails.</li>
  7029. <li>Updates the Open Graph response based on image properties.</li>
  7030. </ol>
  7031. </li>
  7032. </ol>
  7033. </li>
  7034. <li>Stores the result in the database cache.</li>
  7035. </ol>
  7036. </li>
  7037. <li>Returns the result.</li>
  7038. </ol>
  7039. <p>The in-memory cache expires after 1 hour.</p>
  7040. <p>Expired entries in the database cache (and their associated media files) are
  7041. deleted every 10 seconds. The default expiration time is 1 hour from download.</p>
  7042. <div style="break-before: page; page-break-before: always;"></div><h1 id="user-directory-api-implementation"><a class="header" href="#user-directory-api-implementation">User Directory API Implementation</a></h1>
  7043. <p>The user directory is currently maintained based on the 'visible' users
  7044. on this particular server - i.e. ones which your account shares a room with, or
  7045. who are present in a publicly viewable room present on the server.</p>
  7046. <p>The directory info is stored in various tables, which can (typically after
  7047. DB corruption) get stale or out of sync. If this happens, for now the
  7048. 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>
  7049. and then restart synapse. This should then start a background task to
  7050. flush the current tables and regenerate the directory.</p>
  7051. <h2 id="data-model"><a class="header" href="#data-model">Data model</a></h2>
  7052. <p>There are five relevant tables that collectively form the &quot;user directory&quot;.
  7053. Three of them track a master list of all the users we could search for.
  7054. The last two (collectively called the &quot;search tables&quot;) track who can
  7055. see who.</p>
  7056. <p>From all of these tables we exclude three types of local user:</p>
  7057. <ul>
  7058. <li>support users</li>
  7059. <li>appservice users</li>
  7060. <li>deactivated users</li>
  7061. </ul>
  7062. <ul>
  7063. <li>
  7064. <p><code>user_directory</code>. This contains the user_id, display name and avatar we'll
  7065. return when you search the directory.</p>
  7066. <ul>
  7067. <li>Because there's only one directory entry per user, it's important that we only
  7068. ever put publicly visible names here. Otherwise we might leak a private
  7069. nickname or avatar used in a private room.</li>
  7070. <li>Indexed on rooms. Indexed on users.</li>
  7071. </ul>
  7072. </li>
  7073. <li>
  7074. <p><code>user_directory_search</code>. To be joined to <code>user_directory</code>. It contains an extra
  7075. column that enables full text search based on user ids and display names.
  7076. Different schemas for SQLite and Postgres with different code paths to match.</p>
  7077. <ul>
  7078. <li>Indexed on the full text search data. Indexed on users.</li>
  7079. </ul>
  7080. </li>
  7081. <li>
  7082. <p><code>user_directory_stream_pos</code>. When the initial background update to populate
  7083. the directory is complete, we record a stream position here. This indicates
  7084. that synapse should now listen for room changes and incrementally update
  7085. the directory where necessary.</p>
  7086. </li>
  7087. <li>
  7088. <p><code>users_in_public_rooms</code>. Contains associations between users and the public rooms they're in.
  7089. Used to determine which users are in public rooms and should be publicly visible in the directory.</p>
  7090. </li>
  7091. <li>
  7092. <p><code>users_who_share_private_rooms</code>. Rows are triples <code>(L, M, room id)</code> where <code>L</code>
  7093. is a local user and <code>M</code> is a local or remote user. <code>L</code> and <code>M</code> should be
  7094. different, but this isn't enforced by a constraint.</p>
  7095. </li>
  7096. </ul>
  7097. <div style="break-before: page; page-break-before: always;"></div><h1 id="message-retention-policies"><a class="header" href="#message-retention-policies">Message retention policies</a></h1>
  7098. <p>Synapse admins can enable support for message retention policies on
  7099. their homeserver. Message retention policies exist at a room level,
  7100. follow the semantics described in
  7101. <a href="https://github.com/matrix-org/matrix-doc/blob/matthew/msc1763/proposals/1763-configurable-retention-periods.md">MSC1763</a>,
  7102. and allow server and room admins to configure how long messages should
  7103. be kept in a homeserver's database before being purged from it.
  7104. <strong>Please note that, as this feature isn't part of the Matrix
  7105. specification yet, this implementation is to be considered as
  7106. experimental.</strong> </p>
  7107. <p>A message retention policy is mainly defined by its <code>max_lifetime</code>
  7108. parameter, which defines how long a message can be kept around after
  7109. it was sent to the room. If a room doesn't have a message retention
  7110. policy, and there's no default one for a given server, then no message
  7111. sent in that room is ever purged on that server.</p>
  7112. <p>MSC1763 also specifies semantics for a <code>min_lifetime</code> parameter which
  7113. defines the amount of time after which an event <em>can</em> get purged (after
  7114. it was sent to the room), but Synapse doesn't currently support it
  7115. beyond registering it.</p>
  7116. <p>Both <code>max_lifetime</code> and <code>min_lifetime</code> are optional parameters.</p>
  7117. <p>Note that message retention policies don't apply to state events.</p>
  7118. <p>Once an event reaches its expiry date (defined as the time it was sent
  7119. plus the value for <code>max_lifetime</code> in the room), two things happen:</p>
  7120. <ul>
  7121. <li>Synapse stops serving the event to clients via any endpoint.</li>
  7122. <li>The message gets picked up by the next purge job (see the &quot;Purge jobs&quot;
  7123. section) and is removed from Synapse's database.</li>
  7124. </ul>
  7125. <p>Since purge jobs don't run continuously, this means that an event might
  7126. stay in a server's database for longer than the value for <code>max_lifetime</code>
  7127. in the room would allow, though hidden from clients.</p>
  7128. <p>Similarly, if a server (with support for message retention policies
  7129. enabled) receives from another server an event that should have been
  7130. purged according to its room's policy, then the receiving server will
  7131. process and store that event until it's picked up by the next purge job,
  7132. though it will always hide it from clients.</p>
  7133. <p>Synapse requires at least one message in each room, so it will never
  7134. delete the last message in a room. It will, however, hide it from
  7135. clients.</p>
  7136. <h2 id="server-configuration"><a class="header" href="#server-configuration">Server configuration</a></h2>
  7137. <p>Support for this feature can be enabled and configured in the
  7138. <code>retention</code> section of the Synapse configuration file (see the
  7139. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample file</a>).</p>
  7140. <p>To enable support for message retention policies, set the setting
  7141. <code>enabled</code> in this section to <code>true</code>.</p>
  7142. <h3 id="default-policy"><a class="header" href="#default-policy">Default policy</a></h3>
  7143. <p>A default message retention policy is a policy defined in Synapse's
  7144. configuration that is used by Synapse for every room that doesn't have a
  7145. message retention policy configured in its state. This allows server
  7146. admins to ensure that messages are never kept indefinitely in a server's
  7147. database. </p>
  7148. <p>A default policy can be defined as such, in the <code>retention</code> section of
  7149. the configuration file:</p>
  7150. <pre><code class="language-yaml"> default_policy:
  7151. min_lifetime: 1d
  7152. max_lifetime: 1y
  7153. </code></pre>
  7154. <p>Here, <code>min_lifetime</code> and <code>max_lifetime</code> have the same meaning and level
  7155. of support as previously described. They can be expressed either as a
  7156. duration (using the units <code>s</code> (seconds), <code>m</code> (minutes), <code>h</code> (hours),
  7157. <code>d</code> (days), <code>w</code> (weeks) and <code>y</code> (years)) or as a number of milliseconds.</p>
  7158. <h3 id="purge-jobs"><a class="header" href="#purge-jobs">Purge jobs</a></h3>
  7159. <p>Purge jobs are the jobs that Synapse runs in the background to purge
  7160. expired events from the database. They are only run if support for
  7161. message retention policies is enabled in the server's configuration. If
  7162. no configuration for purge jobs is configured by the server admin,
  7163. Synapse will use a default configuration, which is described in the
  7164. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample configuration file</a>.</p>
  7165. <p>Some server admins might want a finer control on when events are removed
  7166. depending on an event's room's policy. This can be done by setting the
  7167. <code>purge_jobs</code> sub-section in the <code>retention</code> section of the configuration
  7168. file. An example of such configuration could be:</p>
  7169. <pre><code class="language-yaml"> purge_jobs:
  7170. - longest_max_lifetime: 3d
  7171. interval: 12h
  7172. - shortest_max_lifetime: 3d
  7173. longest_max_lifetime: 1w
  7174. interval: 1d
  7175. - shortest_max_lifetime: 1w
  7176. interval: 2d
  7177. </code></pre>
  7178. <p>In this example, we define three jobs:</p>
  7179. <ul>
  7180. <li>one that runs twice a day (every 12 hours) and purges events in rooms
  7181. which policy's <code>max_lifetime</code> is lower or equal to 3 days.</li>
  7182. <li>one that runs once a day and purges events in rooms which policy's
  7183. <code>max_lifetime</code> is between 3 days and a week.</li>
  7184. <li>one that runs once every 2 days and purges events in rooms which
  7185. policy's <code>max_lifetime</code> is greater than a week.</li>
  7186. </ul>
  7187. <p>Note that this example is tailored to show different configurations and
  7188. features slightly more jobs than it's probably necessary (in practice, a
  7189. server admin would probably consider it better to replace the two last
  7190. jobs with one that runs once a day and handles rooms which which
  7191. policy's <code>max_lifetime</code> is greater than 3 days).</p>
  7192. <p>Keep in mind, when configuring these jobs, that a purge job can become
  7193. quite heavy on the server if it targets many rooms, therefore prefer
  7194. having jobs with a low interval that target a limited set of rooms. Also
  7195. make sure to include a job with no minimum and one with no maximum to
  7196. make sure your configuration handles every policy.</p>
  7197. <p>As previously mentioned in this documentation, while a purge job that
  7198. runs e.g. every day means that an expired event might stay in the
  7199. database for up to a day after its expiry, Synapse hides expired events
  7200. from clients as soon as they expire, so the event is not visible to
  7201. local users between its expiry date and the moment it gets purged from
  7202. the server's database.</p>
  7203. <h3 id="lifetime-limits"><a class="header" href="#lifetime-limits">Lifetime limits</a></h3>
  7204. <p>Server admins can set limits on the values of <code>max_lifetime</code> to use when
  7205. purging old events in a room. These limits can be defined as such in the
  7206. <code>retention</code> section of the configuration file:</p>
  7207. <pre><code class="language-yaml"> allowed_lifetime_min: 1d
  7208. allowed_lifetime_max: 1y
  7209. </code></pre>
  7210. <p>The limits are considered when running purge jobs. If necessary, the
  7211. effective value of <code>max_lifetime</code> will be brought between
  7212. <code>allowed_lifetime_min</code> and <code>allowed_lifetime_max</code> (inclusive).
  7213. This means that, if the value of <code>max_lifetime</code> defined in the room's state
  7214. is lower than <code>allowed_lifetime_min</code>, the value of <code>allowed_lifetime_min</code>
  7215. will be used instead. Likewise, if the value of <code>max_lifetime</code> is higher
  7216. than <code>allowed_lifetime_max</code>, the value of <code>allowed_lifetime_max</code> will be
  7217. used instead.</p>
  7218. <p>In the example above, we ensure Synapse never deletes events that are less
  7219. than one day old, and that it always deletes events that are over a year
  7220. old.</p>
  7221. <p>If a default policy is set, and its <code>max_lifetime</code> value is lower than
  7222. <code>allowed_lifetime_min</code> or higher than <code>allowed_lifetime_max</code>, the same
  7223. process applies.</p>
  7224. <p>Both parameters are optional; if one is omitted Synapse won't use it to
  7225. adjust the effective value of <code>max_lifetime</code>.</p>
  7226. <p>Like other settings in this section, these parameters can be expressed
  7227. either as a duration or as a number of milliseconds.</p>
  7228. <h2 id="room-configuration"><a class="header" href="#room-configuration">Room configuration</a></h2>
  7229. <p>To configure a room's message retention policy, a room's admin or
  7230. moderator needs to send a state event in that room with the type
  7231. <code>m.room.retention</code> and the following content:</p>
  7232. <pre><code class="language-json">{
  7233. &quot;max_lifetime&quot;: ...
  7234. }
  7235. </code></pre>
  7236. <p>In this event's content, the <code>max_lifetime</code> parameter has the same
  7237. meaning as previously described, and needs to be expressed in
  7238. milliseconds. The event's content can also include a <code>min_lifetime</code>
  7239. parameter, which has the same meaning and limited support as previously
  7240. described.</p>
  7241. <p>Note that over every server in the room, only the ones with support for
  7242. message retention policies will actually remove expired events. This
  7243. support is currently not enabled by default in Synapse.</p>
  7244. <h2 id="note-on-reclaiming-disk-space"><a class="header" href="#note-on-reclaiming-disk-space">Note on reclaiming disk space</a></h2>
  7245. <p>While purge jobs actually delete data from the database, the disk space
  7246. used by the database might not decrease immediately on the database's
  7247. host. However, even though the database engine won't free up the disk
  7248. space, it will start writing new data into where the purged data was.</p>
  7249. <p>If you want to reclaim the freed disk space anyway and return it to the
  7250. operating system, the server admin needs to run <code>VACUUM FULL;</code> (or
  7251. <code>VACUUM;</code> for SQLite databases) on Synapse's database (see the related
  7252. <a href="https://www.postgresql.org/docs/current/sql-vacuum.html">PostgreSQL documentation</a>).</p>
  7253. <div style="break-before: page; page-break-before: always;"></div><h1 id="modules"><a class="header" href="#modules">Modules</a></h1>
  7254. <p>Synapse supports extending its functionality by configuring external modules.</p>
  7255. <p><strong>Note</strong>: When using third-party modules, you effectively allow someone else to run
  7256. custom code on your Synapse homeserver. Server admins are encouraged to verify the
  7257. provenance of the modules they use on their homeserver and make sure the modules aren't
  7258. running malicious code on their instance.</p>
  7259. <h2 id="using-modules"><a class="header" href="#using-modules">Using modules</a></h2>
  7260. <p>To use a module on Synapse, add it to the <code>modules</code> section of the configuration file:</p>
  7261. <pre><code class="language-yaml">modules:
  7262. - module: my_super_module.MySuperClass
  7263. config:
  7264. do_thing: true
  7265. - module: my_other_super_module.SomeClass
  7266. config: {}
  7267. </code></pre>
  7268. <p>Each module is defined by a path to a Python class as well as a configuration. This
  7269. information for a given module should be available in the module's own documentation.</p>
  7270. <h2 id="using-multiple-modules"><a class="header" href="#using-multiple-modules">Using multiple modules</a></h2>
  7271. <p>The order in which modules are listed in this section is important. When processing an
  7272. action that can be handled by several modules, Synapse will always prioritise the module
  7273. that appears first (i.e. is the highest in the list). This means:</p>
  7274. <ul>
  7275. <li>If several modules register the same callback, the callback registered by the module
  7276. that appears first is used.</li>
  7277. <li>If several modules try to register a handler for the same HTTP path, only the handler
  7278. registered by the module that appears first is used. Handlers registered by the other
  7279. module(s) are ignored and Synapse will log a warning message about them.</li>
  7280. </ul>
  7281. <p>Note that Synapse doesn't allow multiple modules implementing authentication checkers via
  7282. the password auth provider feature for the same login type with different fields. If this
  7283. happens, Synapse will refuse to start.</p>
  7284. <h2 id="current-status"><a class="header" href="#current-status">Current status</a></h2>
  7285. <p>We are currently in the process of migrating module interfaces to this system. While some
  7286. interfaces might be compatible with it, others still require configuring modules in
  7287. another part of Synapse's configuration file.</p>
  7288. <p>Currently, only the following pre-existing interfaces are compatible with this new system:</p>
  7289. <ul>
  7290. <li>spam checker</li>
  7291. <li>third-party rules</li>
  7292. <li>presence router</li>
  7293. <li>password auth providers</li>
  7294. </ul>
  7295. <div style="break-before: page; page-break-before: always;"></div><h1 id="writing-a-module"><a class="header" href="#writing-a-module">Writing a module</a></h1>
  7296. <p>A module is a Python class that uses Synapse's module API to interact with the
  7297. homeserver. It can register callbacks that Synapse will call on specific operations, as
  7298. well as web resources to attach to Synapse's web server.</p>
  7299. <p>When instantiated, a module is given its parsed configuration as well as an instance of
  7300. the <code>synapse.module_api.ModuleApi</code> class. The configuration is a dictionary, and is
  7301. either the output of the module's <code>parse_config</code> static method (see below), or the
  7302. configuration associated with the module in Synapse's configuration file.</p>
  7303. <p>See the documentation for the <code>ModuleApi</code> class
  7304. <a href="https://github.com/matrix-org/synapse/blob/master/synapse/module_api/__init__.py">here</a>.</p>
  7305. <h2 id="when-synapse-runs-with-several-modules-configured"><a class="header" href="#when-synapse-runs-with-several-modules-configured">When Synapse runs with several modules configured</a></h2>
  7306. <p>If Synapse is running with other modules configured, the order each module appears in
  7307. within the <code>modules</code> section of the Synapse configuration file might restrict what it can
  7308. or cannot register. See <a href="modules/index.html#using-multiple-modules">this section</a> for more
  7309. information.</p>
  7310. <p>On top of the rules listed in the link above, if a callback returns a value that should
  7311. cause the current operation to fail (e.g. if a callback checking an event returns with a
  7312. value that should cause the event to be denied), Synapse will fail the operation and
  7313. ignore any subsequent callbacks that should have been run after this one.</p>
  7314. <p>The documentation for each callback mentions how Synapse behaves when
  7315. multiple modules implement it.</p>
  7316. <h2 id="handling-the-modules-configuration"><a class="header" href="#handling-the-modules-configuration">Handling the module's configuration</a></h2>
  7317. <p>A module can implement the following static method:</p>
  7318. <pre><code class="language-python">@staticmethod
  7319. def parse_config(config: dict) -&gt; dict
  7320. </code></pre>
  7321. <p>This method is given a dictionary resulting from parsing the YAML configuration for the
  7322. module. It may modify it (for example by parsing durations expressed as strings (e.g.
  7323. &quot;5d&quot;) into milliseconds, etc.), and return the modified dictionary. It may also verify
  7324. that the configuration is correct, and raise an instance of
  7325. <code>synapse.module_api.errors.ConfigError</code> if not.</p>
  7326. <h2 id="registering-a-web-resource"><a class="header" href="#registering-a-web-resource">Registering a web resource</a></h2>
  7327. <p>Modules can register web resources onto Synapse's web server using the following module
  7328. API method:</p>
  7329. <pre><code class="language-python">def ModuleApi.register_web_resource(path: str, resource: IResource) -&gt; None
  7330. </code></pre>
  7331. <p>The path is the full absolute path to register the resource at. For example, if you
  7332. register a resource for the path <code>/_synapse/client/my_super_module/say_hello</code>, Synapse
  7333. will serve it at <code>http(s)://[HS_URL]/_synapse/client/my_super_module/say_hello</code>. Note
  7334. that Synapse does not allow registering resources for several sub-paths in the <code>/_matrix</code>
  7335. namespace (such as anything under <code>/_matrix/client</code> for example). It is strongly
  7336. recommended that modules register their web resources under the <code>/_synapse/client</code>
  7337. namespace.</p>
  7338. <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>
  7339. interface (such as <a href="https://twistedmatrix.com/documents/current/api/twisted.web.resource.Resource.html">Resource</a>).</p>
  7340. <p>Only one resource can be registered for a given path. If several modules attempt to
  7341. register a resource for the same path, the module that appears first in Synapse's
  7342. configuration file takes priority.</p>
  7343. <p>Modules <strong>must</strong> register their web resources in their <code>__init__</code> method.</p>
  7344. <h2 id="registering-a-callback"><a class="header" href="#registering-a-callback">Registering a callback</a></h2>
  7345. <p>Modules can use Synapse's module API to register callbacks. Callbacks are functions that
  7346. Synapse will call when performing specific actions. Callbacks must be asynchronous, and
  7347. are split in categories. A single module may implement callbacks from multiple categories,
  7348. and is under no obligation to implement all callbacks from the categories it registers
  7349. callbacks for.</p>
  7350. <p>Modules can register callbacks using one of the module API's <code>register_[...]_callbacks</code>
  7351. methods. The callback functions are passed to these methods as keyword arguments, with
  7352. the callback name as the argument name and the function as its value. This is demonstrated
  7353. in the example below. A <code>register_[...]_callbacks</code> method exists for each category.</p>
  7354. <p>Callbacks for each category can be found on their respective page of the
  7355. <a href="https://matrix-org.github.io/synapse">Synapse documentation website</a>.</p>
  7356. <div style="break-before: page; page-break-before: always;"></div><h1 id="spam-checker-callbacks"><a class="header" href="#spam-checker-callbacks">Spam checker callbacks</a></h1>
  7357. <p>Spam checker callbacks allow module developers to implement spam mitigation actions for
  7358. Synapse instances. Spam checker callbacks can be registered using the module API's
  7359. <code>register_spam_checker_callbacks</code> method.</p>
  7360. <h2 id="callbacks"><a class="header" href="#callbacks">Callbacks</a></h2>
  7361. <p>The available spam checker callbacks are:</p>
  7362. <h3 id="check_event_for_spam"><a class="header" href="#check_event_for_spam"><code>check_event_for_spam</code></a></h3>
  7363. <p><em>First introduced in Synapse v1.37.0</em></p>
  7364. <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]
  7365. </code></pre>
  7366. <p>Called when receiving an event from a client or via federation. The module can return
  7367. either a <code>bool</code> to indicate whether the event must be rejected because of spam, or a <code>str</code>
  7368. to indicate the event must be rejected because of spam and to give a rejection reason to
  7369. forward to clients.</p>
  7370. <p>If multiple modules implement this callback, they will be considered in order. If a
  7371. callback returns <code>False</code>, Synapse falls through to the next one. The value of the first
  7372. callback that does not return <code>False</code> will be used. If this happens, Synapse will not call
  7373. any of the subsequent implementations of this callback.</p>
  7374. <h3 id="user_may_join_room"><a class="header" href="#user_may_join_room"><code>user_may_join_room</code></a></h3>
  7375. <p><em>First introduced in Synapse v1.37.0</em></p>
  7376. <pre><code class="language-python">async def user_may_join_room(user: str, room: str, is_invited: bool) -&gt; bool
  7377. </code></pre>
  7378. <p>Called when a user is trying to join a room. The module must return a <code>bool</code> to indicate
  7379. whether the user can join the room. The user is represented by their Matrix user ID (e.g.
  7380. <code>@alice:example.com</code>) and the room is represented by its Matrix ID (e.g.
  7381. <code>!room:example.com</code>). The module is also given a boolean to indicate whether the user
  7382. currently has a pending invite in the room.</p>
  7383. <p>This callback isn't called if the join is performed by a server administrator, or in the
  7384. context of a room creation.</p>
  7385. <p>If multiple modules implement this callback, they will be considered in order. If a
  7386. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7387. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7388. any of the subsequent implementations of this callback.</p>
  7389. <h3 id="user_may_invite"><a class="header" href="#user_may_invite"><code>user_may_invite</code></a></h3>
  7390. <p><em>First introduced in Synapse v1.37.0</em></p>
  7391. <pre><code class="language-python">async def user_may_invite(inviter: str, invitee: str, room_id: str) -&gt; bool
  7392. </code></pre>
  7393. <p>Called when processing an invitation. The module must return a <code>bool</code> indicating whether
  7394. the inviter can invite the invitee to the given room. Both inviter and invitee are
  7395. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7396. <p>If multiple modules implement this callback, they will be considered in order. If a
  7397. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7398. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7399. any of the subsequent implementations of this callback.</p>
  7400. <h3 id="user_may_send_3pid_invite"><a class="header" href="#user_may_send_3pid_invite"><code>user_may_send_3pid_invite</code></a></h3>
  7401. <p><em>First introduced in Synapse v1.45.0</em></p>
  7402. <pre><code class="language-python">async def user_may_send_3pid_invite(
  7403. inviter: str,
  7404. medium: str,
  7405. address: str,
  7406. room_id: str,
  7407. ) -&gt; bool
  7408. </code></pre>
  7409. <p>Called when processing an invitation using a third-party identifier (also called a 3PID,
  7410. e.g. an email address or a phone number). The module must return a <code>bool</code> indicating
  7411. whether the inviter can invite the invitee to the given room.</p>
  7412. <p>The inviter is represented by their Matrix user ID (e.g. <code>@alice:example.com</code>), and the
  7413. invitee is represented by its medium (e.g. &quot;email&quot;) and its address
  7414. (e.g. <code>alice@example.com</code>). See <a href="https://matrix.org/docs/spec/appendices#pid-types">the Matrix specification</a>
  7415. for more information regarding third-party identifiers.</p>
  7416. <p>For example, a call to this callback to send an invitation to the email address
  7417. <code>alice@example.com</code> would look like this:</p>
  7418. <pre><code class="language-python">await user_may_send_3pid_invite(
  7419. &quot;@bob:example.com&quot;, # The inviter's user ID
  7420. &quot;email&quot;, # The medium of the 3PID to invite
  7421. &quot;alice@example.com&quot;, # The address of the 3PID to invite
  7422. &quot;!some_room:example.com&quot;, # The ID of the room to send the invite into
  7423. )
  7424. </code></pre>
  7425. <p><strong>Note</strong>: If the third-party identifier is already associated with a matrix user ID,
  7426. <a href="modules/spam_checker_callbacks.html#user_may_invite"><code>user_may_invite</code></a> will be used instead.</p>
  7427. <p>If multiple modules implement this callback, they will be considered in order. If a
  7428. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7429. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7430. any of the subsequent implementations of this callback.</p>
  7431. <h3 id="user_may_create_room"><a class="header" href="#user_may_create_room"><code>user_may_create_room</code></a></h3>
  7432. <p><em>First introduced in Synapse v1.37.0</em></p>
  7433. <pre><code class="language-python">async def user_may_create_room(user: str) -&gt; bool
  7434. </code></pre>
  7435. <p>Called when processing a room creation request. The module must return a <code>bool</code> indicating
  7436. whether the given user (represented by their Matrix user ID) is allowed to create a room.</p>
  7437. <p>If multiple modules implement this callback, they will be considered in order. If a
  7438. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7439. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7440. any of the subsequent implementations of this callback.</p>
  7441. <h3 id="user_may_create_room_with_invites"><a class="header" href="#user_may_create_room_with_invites"><code>user_may_create_room_with_invites</code></a></h3>
  7442. <p><em>First introduced in Synapse v1.44.0</em></p>
  7443. <pre><code class="language-python">async def user_may_create_room_with_invites(
  7444. user: str,
  7445. invites: List[str],
  7446. threepid_invites: List[Dict[str, str]],
  7447. ) -&gt; bool
  7448. </code></pre>
  7449. <p>Called when processing a room creation request (right after <code>user_may_create_room</code>).
  7450. The module is given the Matrix user ID of the user trying to create a room, as well as a
  7451. list of Matrix users to invite and a list of third-party identifiers (3PID, e.g. email
  7452. addresses) to invite.</p>
  7453. <p>An invited Matrix user to invite is represented by their Matrix user IDs, and an invited
  7454. 3PIDs is represented by a dict that includes the 3PID medium (e.g. &quot;email&quot;) through its
  7455. <code>medium</code> key and its address (e.g. &quot;alice@example.com&quot;) through its <code>address</code> key.</p>
  7456. <p>See <a href="https://matrix.org/docs/spec/appendices#pid-types">the Matrix specification</a> for more
  7457. information regarding third-party identifiers.</p>
  7458. <p>If no invite and/or 3PID invite were specified in the room creation request, the
  7459. corresponding list(s) will be empty.</p>
  7460. <p><strong>Note</strong>: This callback is not called when a room is cloned (e.g. during a room upgrade)
  7461. since no invites are sent when cloning a room. To cover this case, modules also need to
  7462. implement <code>user_may_create_room</code>.</p>
  7463. <p>If multiple modules implement this callback, they will be considered in order. If a
  7464. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7465. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7466. any of the subsequent implementations of this callback.</p>
  7467. <h3 id="user_may_create_room_alias"><a class="header" href="#user_may_create_room_alias"><code>user_may_create_room_alias</code></a></h3>
  7468. <p><em>First introduced in Synapse v1.37.0</em></p>
  7469. <pre><code class="language-python">async def user_may_create_room_alias(user: str, room_alias: &quot;synapse.types.RoomAlias&quot;) -&gt; bool
  7470. </code></pre>
  7471. <p>Called when trying to associate an alias with an existing room. The module must return a
  7472. <code>bool</code> indicating whether the given user (represented by their Matrix user ID) is allowed
  7473. to set the given alias.</p>
  7474. <p>If multiple modules implement this callback, they will be considered in order. If a
  7475. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7476. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7477. any of the subsequent implementations of this callback.</p>
  7478. <h3 id="user_may_publish_room"><a class="header" href="#user_may_publish_room"><code>user_may_publish_room</code></a></h3>
  7479. <p><em>First introduced in Synapse v1.37.0</em></p>
  7480. <pre><code class="language-python">async def user_may_publish_room(user: str, room_id: str) -&gt; bool
  7481. </code></pre>
  7482. <p>Called when trying to publish a room to the homeserver's public rooms directory. The
  7483. module must return a <code>bool</code> indicating whether the given user (represented by their
  7484. Matrix user ID) is allowed to publish the given room.</p>
  7485. <p>If multiple modules implement this callback, they will be considered in order. If a
  7486. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7487. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7488. any of the subsequent implementations of this callback.</p>
  7489. <h3 id="check_username_for_spam"><a class="header" href="#check_username_for_spam"><code>check_username_for_spam</code></a></h3>
  7490. <p><em>First introduced in Synapse v1.37.0</em></p>
  7491. <pre><code class="language-python">async def check_username_for_spam(user_profile: Dict[str, str]) -&gt; bool
  7492. </code></pre>
  7493. <p>Called when computing search results in the user directory. The module must return a
  7494. <code>bool</code> indicating whether the given user profile can appear in search results. The profile
  7495. is represented as a dictionary with the following keys:</p>
  7496. <ul>
  7497. <li><code>user_id</code>: The Matrix ID for this user.</li>
  7498. <li><code>display_name</code>: The user's display name.</li>
  7499. <li><code>avatar_url</code>: The <code>mxc://</code> URL to the user's avatar.</li>
  7500. </ul>
  7501. <p>The module is given a copy of the original dictionary, so modifying it from within the
  7502. module cannot modify a user's profile when included in user directory search results.</p>
  7503. <p>If multiple modules implement this callback, they will be considered in order. If a
  7504. callback returns <code>False</code>, Synapse falls through to the next one. The value of the first
  7505. callback that does not return <code>False</code> will be used. If this happens, Synapse will not call
  7506. any of the subsequent implementations of this callback.</p>
  7507. <h3 id="check_registration_for_spam"><a class="header" href="#check_registration_for_spam"><code>check_registration_for_spam</code></a></h3>
  7508. <p><em>First introduced in Synapse v1.37.0</em></p>
  7509. <pre><code class="language-python">async def check_registration_for_spam(
  7510. email_threepid: Optional[dict],
  7511. username: Optional[str],
  7512. request_info: Collection[Tuple[str, str]],
  7513. auth_provider_id: Optional[str] = None,
  7514. ) -&gt; &quot;synapse.spam_checker_api.RegistrationBehaviour&quot;
  7515. </code></pre>
  7516. <p>Called when registering a new user. The module must return a <code>RegistrationBehaviour</code>
  7517. indicating whether the registration can go through or must be denied, or whether the user
  7518. may be allowed to register but will be shadow banned.</p>
  7519. <p>The arguments passed to this callback are:</p>
  7520. <ul>
  7521. <li><code>email_threepid</code>: The email address used for registering, if any.</li>
  7522. <li><code>username</code>: The username the user would like to register. Can be <code>None</code>, meaning that
  7523. Synapse will generate one later.</li>
  7524. <li><code>request_info</code>: A collection of tuples, which first item is a user agent, and which
  7525. second item is an IP address. These user agents and IP addresses are the ones that were
  7526. used during the registration process.</li>
  7527. <li><code>auth_provider_id</code>: The identifier of the SSO authentication provider, if any.</li>
  7528. </ul>
  7529. <p>If multiple modules implement this callback, they will be considered in order. If a
  7530. callback returns <code>RegistrationBehaviour.ALLOW</code>, Synapse falls through to the next one.
  7531. The value of the first callback that does not return <code>RegistrationBehaviour.ALLOW</code> will
  7532. be used. If this happens, Synapse will not call any of the subsequent implementations of
  7533. this callback.</p>
  7534. <h3 id="check_media_file_for_spam"><a class="header" href="#check_media_file_for_spam"><code>check_media_file_for_spam</code></a></h3>
  7535. <p><em>First introduced in Synapse v1.37.0</em></p>
  7536. <pre><code class="language-python">async def check_media_file_for_spam(
  7537. file_wrapper: &quot;synapse.rest.media.v1.media_storage.ReadableFileWrapper&quot;,
  7538. file_info: &quot;synapse.rest.media.v1._base.FileInfo&quot;,
  7539. ) -&gt; bool
  7540. </code></pre>
  7541. <p>Called when storing a local or remote file. The module must return a boolean indicating
  7542. whether the given file can be stored in the homeserver's media store.</p>
  7543. <p>If multiple modules implement this callback, they will be considered in order. If a
  7544. callback returns <code>False</code>, Synapse falls through to the next one. The value of the first
  7545. callback that does not return <code>False</code> will be used. If this happens, Synapse will not call
  7546. any of the subsequent implementations of this callback.</p>
  7547. <h2 id="example"><a class="header" href="#example">Example</a></h2>
  7548. <p>The example below is a module that implements the spam checker callback
  7549. <code>check_event_for_spam</code> to deny any message sent by users whose Matrix user IDs are
  7550. mentioned in a configured list, and registers a web resource to the path
  7551. <code>/_synapse/client/list_spam_checker/is_evil</code> that returns a JSON object indicating
  7552. whether the provided user appears in that list.</p>
  7553. <pre><code class="language-python">import json
  7554. from typing import Union
  7555. from twisted.web.resource import Resource
  7556. from twisted.web.server import Request
  7557. from synapse.module_api import ModuleApi
  7558. class IsUserEvilResource(Resource):
  7559. def __init__(self, config):
  7560. super(IsUserEvilResource, self).__init__()
  7561. self.evil_users = config.get(&quot;evil_users&quot;) or []
  7562. def render_GET(self, request: Request):
  7563. user = request.args.get(b&quot;user&quot;)[0].decode()
  7564. request.setHeader(b&quot;Content-Type&quot;, b&quot;application/json&quot;)
  7565. return json.dumps({&quot;evil&quot;: user in self.evil_users}).encode()
  7566. class ListSpamChecker:
  7567. def __init__(self, config: dict, api: ModuleApi):
  7568. self.api = api
  7569. self.evil_users = config.get(&quot;evil_users&quot;) or []
  7570. self.api.register_spam_checker_callbacks(
  7571. check_event_for_spam=self.check_event_for_spam,
  7572. )
  7573. self.api.register_web_resource(
  7574. path=&quot;/_synapse/client/list_spam_checker/is_evil&quot;,
  7575. resource=IsUserEvilResource(config),
  7576. )
  7577. async def check_event_for_spam(self, event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]:
  7578. return event.sender not in self.evil_users
  7579. </code></pre>
  7580. <div style="break-before: page; page-break-before: always;"></div><h1 id="third-party-rules-callbacks"><a class="header" href="#third-party-rules-callbacks">Third party rules callbacks</a></h1>
  7581. <p>Third party rules callbacks allow module developers to add extra checks to verify the
  7582. validity of incoming events. Third party event rules callbacks can be registered using
  7583. the module API's <code>register_third_party_rules_callbacks</code> method.</p>
  7584. <h2 id="callbacks-1"><a class="header" href="#callbacks-1">Callbacks</a></h2>
  7585. <p>The available third party rules callbacks are:</p>
  7586. <h3 id="check_event_allowed"><a class="header" href="#check_event_allowed"><code>check_event_allowed</code></a></h3>
  7587. <p><em>First introduced in Synapse v1.39.0</em></p>
  7588. <pre><code class="language-python">async def check_event_allowed(
  7589. event: &quot;synapse.events.EventBase&quot;,
  7590. state_events: &quot;synapse.types.StateMap&quot;,
  7591. ) -&gt; Tuple[bool, Optional[dict]]
  7592. </code></pre>
  7593. <p><strong><span style="color:red">
  7594. This callback is very experimental and can and will break without notice. Module developers
  7595. are encouraged to implement <code>check_event_for_spam</code> from the spam checker category instead.
  7596. </span></strong></p>
  7597. <p>Called when processing any incoming event, with the event and a <code>StateMap</code>
  7598. representing the current state of the room the event is being sent into. A <code>StateMap</code> is
  7599. a dictionary that maps tuples containing an event type and a state key to the
  7600. corresponding state event. For example retrieving the room's <code>m.room.create</code> event from
  7601. the <code>state_events</code> argument would look like this: <code>state_events.get((&quot;m.room.create&quot;, &quot;&quot;))</code>.
  7602. The module must return a boolean indicating whether the event can be allowed.</p>
  7603. <p>Note that this callback function processes incoming events coming via federation
  7604. traffic (on top of client traffic). This means denying an event might cause the local
  7605. copy of the room's history to diverge from that of remote servers. This may cause
  7606. federation issues in the room. It is strongly recommended to only deny events using this
  7607. callback function if the sender is a local user, or in a private federation in which all
  7608. servers are using the same module, with the same configuration.</p>
  7609. <p>If the boolean returned by the module is <code>True</code>, it may also tell Synapse to replace the
  7610. event with new data by returning the new event's data as a dictionary. In order to do
  7611. that, it is recommended the module calls <code>event.get_dict()</code> to get the current event as a
  7612. dictionary, and modify the returned dictionary accordingly.</p>
  7613. <p>Note that replacing the event only works for events sent by local users, not for events
  7614. received over federation.</p>
  7615. <p>If multiple modules implement this callback, they will be considered in order. If a
  7616. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7617. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7618. any of the subsequent implementations of this callback.</p>
  7619. <h3 id="on_create_room"><a class="header" href="#on_create_room"><code>on_create_room</code></a></h3>
  7620. <p><em>First introduced in Synapse v1.39.0</em></p>
  7621. <pre><code class="language-python">async def on_create_room(
  7622. requester: &quot;synapse.types.Requester&quot;,
  7623. request_content: dict,
  7624. is_requester_admin: bool,
  7625. ) -&gt; None
  7626. </code></pre>
  7627. <p>Called when processing a room creation request, with the <code>Requester</code> object for the user
  7628. performing the request, a dictionary representing the room creation request's JSON body
  7629. (see <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom">the spec</a>
  7630. for a list of possible parameters), and a boolean indicating whether the user performing
  7631. the request is a server admin.</p>
  7632. <p>Modules can modify the <code>request_content</code> (by e.g. adding events to its <code>initial_state</code>),
  7633. or deny the room's creation by raising a <code>module_api.errors.SynapseError</code>.</p>
  7634. <p>If multiple modules implement this callback, they will be considered in order. If a
  7635. callback returns without raising an exception, Synapse falls through to the next one. The
  7636. room creation will be forbidden as soon as one of the callbacks raises an exception. If
  7637. this happens, Synapse will not call any of the subsequent implementations of this
  7638. callback.</p>
  7639. <h3 id="check_threepid_can_be_invited"><a class="header" href="#check_threepid_can_be_invited"><code>check_threepid_can_be_invited</code></a></h3>
  7640. <p><em>First introduced in Synapse v1.39.0</em></p>
  7641. <pre><code class="language-python">async def check_threepid_can_be_invited(
  7642. medium: str,
  7643. address: str,
  7644. state_events: &quot;synapse.types.StateMap&quot;,
  7645. ) -&gt; bool:
  7646. </code></pre>
  7647. <p>Called when processing an invite via a third-party identifier (i.e. email or phone number).
  7648. The module must return a boolean indicating whether the invite can go through.</p>
  7649. <p>If multiple modules implement this callback, they will be considered in order. If a
  7650. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7651. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7652. any of the subsequent implementations of this callback.</p>
  7653. <h3 id="check_visibility_can_be_modified"><a class="header" href="#check_visibility_can_be_modified"><code>check_visibility_can_be_modified</code></a></h3>
  7654. <p><em>First introduced in Synapse v1.39.0</em></p>
  7655. <pre><code class="language-python">async def check_visibility_can_be_modified(
  7656. room_id: str,
  7657. state_events: &quot;synapse.types.StateMap&quot;,
  7658. new_visibility: str,
  7659. ) -&gt; bool:
  7660. </code></pre>
  7661. <p>Called when changing the visibility of a room in the local public room directory. The
  7662. visibility is a string that's either &quot;public&quot; or &quot;private&quot;. The module must return a
  7663. boolean indicating whether the change can go through.</p>
  7664. <p>If multiple modules implement this callback, they will be considered in order. If a
  7665. callback returns <code>True</code>, Synapse falls through to the next one. The value of the first
  7666. callback that does not return <code>True</code> will be used. If this happens, Synapse will not call
  7667. any of the subsequent implementations of this callback.</p>
  7668. <h2 id="example-1"><a class="header" href="#example-1">Example</a></h2>
  7669. <p>The example below is a module that implements the third-party rules callback
  7670. <code>check_event_allowed</code> to censor incoming messages as dictated by a third-party service.</p>
  7671. <pre><code class="language-python">from typing import Optional, Tuple
  7672. from synapse.module_api import ModuleApi
  7673. _DEFAULT_CENSOR_ENDPOINT = &quot;https://my-internal-service.local/censor-event&quot;
  7674. class EventCensorer:
  7675. def __init__(self, config: dict, api: ModuleApi):
  7676. self.api = api
  7677. self._endpoint = config.get(&quot;endpoint&quot;, _DEFAULT_CENSOR_ENDPOINT)
  7678. self.api.register_third_party_rules_callbacks(
  7679. check_event_allowed=self.check_event_allowed,
  7680. )
  7681. async def check_event_allowed(
  7682. self,
  7683. event: &quot;synapse.events.EventBase&quot;,
  7684. state_events: &quot;synapse.types.StateMap&quot;,
  7685. ) -&gt; Tuple[bool, Optional[dict]]:
  7686. event_dict = event.get_dict()
  7687. new_event_content = await self.api.http_client.post_json_get_json(
  7688. uri=self._endpoint, post_json=event_dict,
  7689. )
  7690. event_dict[&quot;content&quot;] = new_event_content
  7691. return event_dict
  7692. </code></pre>
  7693. <div style="break-before: page; page-break-before: always;"></div><h1 id="presence-router-callbacks"><a class="header" href="#presence-router-callbacks">Presence router callbacks</a></h1>
  7694. <p>Presence router callbacks allow module developers to specify additional users (local or remote)
  7695. to receive certain presence updates from local users. Presence router callbacks can be
  7696. registered using the module API's <code>register_presence_router_callbacks</code> method.</p>
  7697. <h2 id="callbacks-2"><a class="header" href="#callbacks-2">Callbacks</a></h2>
  7698. <p>The available presence router callbacks are:</p>
  7699. <h3 id="get_users_for_states"><a class="header" href="#get_users_for_states"><code>get_users_for_states</code></a></h3>
  7700. <p><em>First introduced in Synapse v1.42.0</em></p>
  7701. <pre><code class="language-python">async def get_users_for_states(
  7702. state_updates: Iterable[&quot;synapse.api.UserPresenceState&quot;],
  7703. ) -&gt; Dict[str, Set[&quot;synapse.api.UserPresenceState&quot;]]
  7704. </code></pre>
  7705. <p><strong>Requires</strong> <code>get_interested_users</code> to also be registered</p>
  7706. <p>Called when processing updates to the presence state of one or more users. This callback can
  7707. be used to instruct the server to forward that presence state to specific users. The module
  7708. must return a dictionary that maps from Matrix user IDs (which can be local or remote) to the
  7709. <code>UserPresenceState</code> changes that they should be forwarded.</p>
  7710. <p>Synapse will then attempt to send the specified presence updates to each user when possible.</p>
  7711. <p>If multiple modules implement this callback, Synapse merges all the dictionaries returned
  7712. by the callbacks. If multiple callbacks return a dictionary containing the same key,
  7713. Synapse concatenates the sets associated with this key from each dictionary. </p>
  7714. <h3 id="get_interested_users"><a class="header" href="#get_interested_users"><code>get_interested_users</code></a></h3>
  7715. <p><em>First introduced in Synapse v1.42.0</em></p>
  7716. <pre><code class="language-python">async def get_interested_users(
  7717. user_id: str
  7718. ) -&gt; Union[Set[str], &quot;synapse.module_api.PRESENCE_ALL_USERS&quot;]
  7719. </code></pre>
  7720. <p><strong>Requires</strong> <code>get_users_for_states</code> to also be registered</p>
  7721. <p>Called when determining which users someone should be able to see the presence state of. This
  7722. callback should return complementary results to <code>get_users_for_state</code> or the presence information
  7723. may not be properly forwarded.</p>
  7724. <p>The callback is given the Matrix user ID for a local user that is requesting presence data and
  7725. should return the Matrix user IDs of the users whose presence state they are allowed to
  7726. query. The returned users can be local or remote. </p>
  7727. <p>Alternatively the callback can return <code>synapse.module_api.PRESENCE_ALL_USERS</code>
  7728. to indicate that the user should receive updates from all known users.</p>
  7729. <p>If multiple modules implement this callback, they will be considered in order. Synapse
  7730. calls each callback one by one, and use a concatenation of all the <code>set</code>s returned by the
  7731. callbacks. If one callback returns <code>synapse.module_api.PRESENCE_ALL_USERS</code>, Synapse uses
  7732. this value instead. If this happens, Synapse does not call any of the subsequent
  7733. implementations of this callback.</p>
  7734. <h2 id="example-2"><a class="header" href="#example-2">Example</a></h2>
  7735. <p>The example below is a module that implements both presence router callbacks, and ensures
  7736. that <code>@alice:example.org</code> receives all presence updates from <code>@bob:example.com</code> and
  7737. <code>@charlie:somewhere.org</code>, regardless of whether Alice shares a room with any of them.</p>
  7738. <pre><code class="language-python">from typing import Dict, Iterable, Set, Union
  7739. from synapse.module_api import ModuleApi
  7740. class CustomPresenceRouter:
  7741. def __init__(self, config: dict, api: ModuleApi):
  7742. self.api = api
  7743. self.api.register_presence_router_callbacks(
  7744. get_users_for_states=self.get_users_for_states,
  7745. get_interested_users=self.get_interested_users,
  7746. )
  7747. async def get_users_for_states(
  7748. self,
  7749. state_updates: Iterable[&quot;synapse.api.UserPresenceState&quot;],
  7750. ) -&gt; Dict[str, Set[&quot;synapse.api.UserPresenceState&quot;]]:
  7751. res = {}
  7752. for update in state_updates:
  7753. if (
  7754. update.user_id == &quot;@bob:example.com&quot;
  7755. or update.user_id == &quot;@charlie:somewhere.org&quot;
  7756. ):
  7757. res.setdefault(&quot;@alice:example.com&quot;, set()).add(update)
  7758. return res
  7759. async def get_interested_users(
  7760. self,
  7761. user_id: str,
  7762. ) -&gt; Union[Set[str], &quot;synapse.module_api.PRESENCE_ALL_USERS&quot;]:
  7763. if user_id == &quot;@alice:example.com&quot;:
  7764. return {&quot;@bob:example.com&quot;, &quot;@charlie:somewhere.org&quot;}
  7765. return set()
  7766. </code></pre>
  7767. <div style="break-before: page; page-break-before: always;"></div><h1 id="account-validity-callbacks"><a class="header" href="#account-validity-callbacks">Account validity callbacks</a></h1>
  7768. <p>Account validity callbacks allow module developers to add extra steps to verify the
  7769. validity on an account, i.e. see if a user can be granted access to their account on the
  7770. Synapse instance. Account validity callbacks can be registered using the module API's
  7771. <code>register_account_validity_callbacks</code> method.</p>
  7772. <p>The available account validity callbacks are:</p>
  7773. <h3 id="is_user_expired"><a class="header" href="#is_user_expired"><code>is_user_expired</code></a></h3>
  7774. <p><em>First introduced in Synapse v1.39.0</em></p>
  7775. <pre><code class="language-python">async def is_user_expired(user: str) -&gt; Optional[bool]
  7776. </code></pre>
  7777. <p>Called when processing any authenticated request (except for logout requests). The module
  7778. can return a <code>bool</code> to indicate whether the user has expired and should be locked out of
  7779. their account, or <code>None</code> if the module wasn't able to figure it out. The user is
  7780. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7781. <p>If the module returns <code>True</code>, the current request will be denied with the error code
  7782. <code>ORG_MATRIX_EXPIRED_ACCOUNT</code> and the HTTP status code 403. Note that this doesn't
  7783. invalidate the user's access token.</p>
  7784. <p>If multiple modules implement this callback, they will be considered in order. If a
  7785. callback returns <code>None</code>, Synapse falls through to the next one. The value of the first
  7786. callback that does not return <code>None</code> will be used. If this happens, Synapse will not call
  7787. any of the subsequent implementations of this callback.</p>
  7788. <h3 id="on_user_registration"><a class="header" href="#on_user_registration"><code>on_user_registration</code></a></h3>
  7789. <p><em>First introduced in Synapse v1.39.0</em></p>
  7790. <pre><code class="language-python">async def on_user_registration(user: str) -&gt; None
  7791. </code></pre>
  7792. <p>Called after successfully registering a user, in case the module needs to perform extra
  7793. operations to keep track of them. (e.g. add them to a database table). The user is
  7794. represented by their Matrix user ID.</p>
  7795. <p>If multiple modules implement this callback, Synapse runs them all in order.</p>
  7796. <div style="break-before: page; page-break-before: always;"></div><h1 id="password-auth-provider-callbacks"><a class="header" href="#password-auth-provider-callbacks">Password auth provider callbacks</a></h1>
  7797. <p>Password auth providers offer a way for server administrators to integrate
  7798. their Synapse installation with an external authentication system. The callbacks can be
  7799. registered by using the Module API's <code>register_password_auth_provider_callbacks</code> method.</p>
  7800. <h2 id="callbacks-3"><a class="header" href="#callbacks-3">Callbacks</a></h2>
  7801. <h3 id="auth_checkers"><a class="header" href="#auth_checkers"><code>auth_checkers</code></a></h3>
  7802. <p><em>First introduced in Synapse v1.46.0</em></p>
  7803. <pre><code> auth_checkers: Dict[Tuple[str,Tuple], Callable]
  7804. </code></pre>
  7805. <p>A dict mapping from tuples of a login type identifier (such as <code>m.login.password</code>) and a
  7806. tuple of field names (such as <code>(&quot;password&quot;, &quot;secret_thing&quot;)</code>) to authentication checking
  7807. callbacks, which should be of the following form:</p>
  7808. <pre><code class="language-python">async def check_auth(
  7809. user: str,
  7810. login_type: str,
  7811. login_dict: &quot;synapse.module_api.JsonDict&quot;,
  7812. ) -&gt; Optional[
  7813. Tuple[
  7814. str,
  7815. Optional[Callable[[&quot;synapse.module_api.LoginResponse&quot;], Awaitable[None]]]
  7816. ]
  7817. ]
  7818. </code></pre>
  7819. <p>The login type and field names should be provided by the user in the
  7820. request to the <code>/login</code> API. <a href="https://matrix.org/docs/spec/client_server/latest#authentication-types">The Matrix specification</a>
  7821. defines some types, however user defined ones are also allowed.</p>
  7822. <p>The callback is passed the <code>user</code> field provided by the client (which might not be in
  7823. <code>@username:server</code> form), the login type, and a dictionary of login secrets passed by
  7824. the client.</p>
  7825. <p>If the authentication is successful, the module must return the user's Matrix ID (e.g.
  7826. <code>@alice:example.com</code>) and optionally a callback to be called with the response to the
  7827. <code>/login</code> request. If the module doesn't wish to return a callback, it must return <code>None</code>
  7828. instead.</p>
  7829. <p>If the authentication is unsuccessful, the module must return <code>None</code>.</p>
  7830. <p>If multiple modules register an auth checker for the same login type but with different
  7831. fields, Synapse will refuse to start.</p>
  7832. <p>If multiple modules register an auth checker for the same login type with the same fields,
  7833. then the callbacks will be executed in order, until one returns a Matrix User ID (and
  7834. optionally a callback). In that case, the return value of that callback will be accepted
  7835. and subsequent callbacks will not be fired. If every callback returns <code>None</code>, then the
  7836. authentication fails.</p>
  7837. <h3 id="check_3pid_auth"><a class="header" href="#check_3pid_auth"><code>check_3pid_auth</code></a></h3>
  7838. <p><em>First introduced in Synapse v1.46.0</em></p>
  7839. <pre><code class="language-python">async def check_3pid_auth(
  7840. medium: str,
  7841. address: str,
  7842. password: str,
  7843. ) -&gt; Optional[
  7844. Tuple[
  7845. str,
  7846. Optional[Callable[[&quot;synapse.module_api.LoginResponse&quot;], Awaitable[None]]]
  7847. ]
  7848. ]
  7849. </code></pre>
  7850. <p>Called when a user attempts to register or log in with a third party identifier,
  7851. such as email. It is passed the medium (eg. <code>email</code>), an address (eg. <code>jdoe@example.com</code>)
  7852. and the user's password.</p>
  7853. <p>If the authentication is successful, the module must return the user's Matrix ID (e.g.
  7854. <code>@alice:example.com</code>) and optionally a callback to be called with the response to the <code>/login</code> request.
  7855. If the module doesn't wish to return a callback, it must return None instead.</p>
  7856. <p>If the authentication is unsuccessful, the module must return <code>None</code>.</p>
  7857. <p>If multiple modules implement this callback, they will be considered in order. If a
  7858. callback returns <code>None</code>, Synapse falls through to the next one. The value of the first
  7859. callback that does not return <code>None</code> will be used. If this happens, Synapse will not call
  7860. any of the subsequent implementations of this callback. If every callback return <code>None</code>,
  7861. the authentication is denied.</p>
  7862. <h3 id="on_logged_out"><a class="header" href="#on_logged_out"><code>on_logged_out</code></a></h3>
  7863. <p><em>First introduced in Synapse v1.46.0</em></p>
  7864. <pre><code class="language-python">async def on_logged_out(
  7865. user_id: str,
  7866. device_id: Optional[str],
  7867. access_token: str
  7868. ) -&gt; None
  7869. </code></pre>
  7870. <p>Called during a logout request for a user. It is passed the qualified user ID, the ID of the
  7871. deactivated device (if any: access tokens are occasionally created without an associated
  7872. device ID), and the (now deactivated) access token.</p>
  7873. <p>If multiple modules implement this callback, Synapse runs them all in order.</p>
  7874. <h2 id="example-3"><a class="header" href="#example-3">Example</a></h2>
  7875. <p>The example module below implements authentication checkers for two different login types: </p>
  7876. <ul>
  7877. <li><code>my.login.type</code>
  7878. <ul>
  7879. <li>Expects a <code>my_field</code> field to be sent to <code>/login</code></li>
  7880. <li>Is checked by the method: <code>self.check_my_login</code></li>
  7881. </ul>
  7882. </li>
  7883. <li><code>m.login.password</code> (defined in <a href="https://matrix.org/docs/spec/client_server/latest#password-based">the spec</a>)
  7884. <ul>
  7885. <li>Expects a <code>password</code> field to be sent to <code>/login</code></li>
  7886. <li>Is checked by the method: <code>self.check_pass</code> </li>
  7887. </ul>
  7888. </li>
  7889. </ul>
  7890. <pre><code class="language-python">from typing import Awaitable, Callable, Optional, Tuple
  7891. import synapse
  7892. from synapse import module_api
  7893. class MyAuthProvider:
  7894. def __init__(self, config: dict, api: module_api):
  7895. self.api = api
  7896. self.credentials = {
  7897. &quot;bob&quot;: &quot;building&quot;,
  7898. &quot;@scoop:matrix.org&quot;: &quot;digging&quot;,
  7899. }
  7900. api.register_password_auth_provider_callbacks(
  7901. auth_checkers={
  7902. (&quot;my.login_type&quot;, (&quot;my_field&quot;,)): self.check_my_login,
  7903. (&quot;m.login.password&quot;, (&quot;password&quot;,)): self.check_pass,
  7904. },
  7905. )
  7906. async def check_my_login(
  7907. self,
  7908. username: str,
  7909. login_type: str,
  7910. login_dict: &quot;synapse.module_api.JsonDict&quot;,
  7911. ) -&gt; Optional[
  7912. Tuple[
  7913. str,
  7914. Optional[Callable[[&quot;synapse.module_api.LoginResponse&quot;], Awaitable[None]]],
  7915. ]
  7916. ]:
  7917. if login_type != &quot;my.login_type&quot;:
  7918. return None
  7919. if self.credentials.get(username) == login_dict.get(&quot;my_field&quot;):
  7920. return self.api.get_qualified_user_id(username)
  7921. async def check_pass(
  7922. self,
  7923. username: str,
  7924. login_type: str,
  7925. login_dict: &quot;synapse.module_api.JsonDict&quot;,
  7926. ) -&gt; Optional[
  7927. Tuple[
  7928. str,
  7929. Optional[Callable[[&quot;synapse.module_api.LoginResponse&quot;], Awaitable[None]]],
  7930. ]
  7931. ]:
  7932. if login_type != &quot;m.login.password&quot;:
  7933. return None
  7934. if self.credentials.get(username) == login_dict.get(&quot;password&quot;):
  7935. return self.api.get_qualified_user_id(username)
  7936. </code></pre>
  7937. <div style="break-before: page; page-break-before: always;"></div><h1 id="porting-an-existing-module-that-uses-the-old-interface"><a class="header" href="#porting-an-existing-module-that-uses-the-old-interface">Porting an existing module that uses the old interface</a></h1>
  7938. <p>In order to port a module that uses Synapse's old module interface, its author needs to:</p>
  7939. <ul>
  7940. <li>ensure the module's callbacks are all asynchronous.</li>
  7941. <li>register their callbacks using one or more of the <code>register_[...]_callbacks</code> methods
  7942. from the <code>ModuleApi</code> class in the module's <code>__init__</code> method (see <a href="modules/writing_a_module.html#registering-a-callback">this section</a>
  7943. for more info).</li>
  7944. </ul>
  7945. <p>Additionally, if the module is packaged with an additional web resource, the module
  7946. should register this resource in its <code>__init__</code> method using the <code>register_web_resource</code>
  7947. method from the <code>ModuleApi</code> class (see <a href="modules/writing_a_module.html#registering-a-web-resource">this section</a> for
  7948. more info).</p>
  7949. <p>There is no longer a <code>get_db_schema_files</code> callback provided for password auth provider modules. Any
  7950. changes to the database should now be made by the module using the module API class.</p>
  7951. <p>The module's author should also update any example in the module's configuration to only
  7952. use the new <code>modules</code> section in Synapse's configuration file (see <a href="modules/index.html#using-modules">this section</a>
  7953. for more info).</p>
  7954. <div style="break-before: page; page-break-before: always;"></div><h1 id="scaling-synapse-via-workers"><a class="header" href="#scaling-synapse-via-workers">Scaling synapse via workers</a></h1>
  7955. <p>For small instances it recommended to run Synapse in the default monolith mode.
  7956. For larger instances where performance is a concern it can be helpful to split
  7957. out functionality into multiple separate python processes. These processes are
  7958. called 'workers', and are (eventually) intended to scale horizontally
  7959. independently.</p>
  7960. <p>Synapse's worker support is under active development and subject to change as
  7961. we attempt to rapidly scale ever larger Synapse instances. However we are
  7962. documenting it here to help admins needing a highly scalable Synapse instance
  7963. similar to the one running <code>matrix.org</code>.</p>
  7964. <p>All processes continue to share the same database instance, and as such,
  7965. workers only work with PostgreSQL-based Synapse deployments. SQLite should only
  7966. be used for demo purposes and any admin considering workers should already be
  7967. running PostgreSQL.</p>
  7968. <p>See also <a href="https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability">Matrix.org blog post</a>
  7969. for a higher level overview.</p>
  7970. <h2 id="main-processworker-communication"><a class="header" href="#main-processworker-communication">Main process/worker communication</a></h2>
  7971. <p>The processes communicate with each other via a Synapse-specific protocol called
  7972. 'replication' (analogous to MySQL- or Postgres-style database replication) which
  7973. feeds streams of newly written data between processes so they can be kept in
  7974. sync with the database state.</p>
  7975. <p>When configured to do so, Synapse uses a
  7976. <a href="https://redis.io/topics/pubsub">Redis pub/sub channel</a> to send the replication
  7977. stream between all configured Synapse processes. Additionally, processes may
  7978. make HTTP requests to each other, primarily for operations which need to wait
  7979. for a reply ─ such as sending an event.</p>
  7980. <p>Redis support was added in v1.13.0 with it becoming the recommended method in
  7981. v1.18.0. It replaced the old direct TCP connections (which is deprecated as of
  7982. v1.18.0) to the main process. With Redis, rather than all the workers connecting
  7983. to the main process, all the workers and the main process connect to Redis,
  7984. which relays replication commands between processes. This can give a significant
  7985. cpu saving on the main process and will be a prerequisite for upcoming
  7986. performance improvements.</p>
  7987. <p>If Redis support is enabled Synapse will use it as a shared cache, as well as a
  7988. pub/sub mechanism.</p>
  7989. <p>See the <a href="workers.html#architectural-diagram">Architectural diagram</a> section at the end for
  7990. a visualisation of what this looks like.</p>
  7991. <h2 id="setting-up-workers"><a class="header" href="#setting-up-workers">Setting up workers</a></h2>
  7992. <p>A Redis server is required to manage the communication between the processes.
  7993. The Redis server should be installed following the normal procedure for your
  7994. distribution (e.g. <code>apt install redis-server</code> on Debian). It is safe to use an
  7995. existing Redis deployment if you have one.</p>
  7996. <p>Once installed, check that Redis is running and accessible from the host running
  7997. Synapse, for example by executing <code>echo PING | nc -q1 localhost 6379</code> and seeing
  7998. a response of <code>+PONG</code>.</p>
  7999. <p>The appropriate dependencies must also be installed for Synapse. If using a
  8000. virtualenv, these can be installed with:</p>
  8001. <pre><code class="language-sh">pip install &quot;matrix-synapse[redis]&quot;
  8002. </code></pre>
  8003. <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
  8004. <code>matrix.org</code> and in the docker images at
  8005. https://hub.docker.com/r/matrixdotorg/synapse/.</p>
  8006. <p>To make effective use of the workers, you will need to configure an HTTP
  8007. reverse-proxy such as nginx or haproxy, which will direct incoming requests to
  8008. the correct worker, or to the main synapse instance. See
  8009. <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a reverse
  8010. proxy.</p>
  8011. <p>When using workers, each worker process has its own configuration file which
  8012. contains settings specific to that worker, such as the HTTP listener that it
  8013. provides (if any), logging configuration, etc.</p>
  8014. <p>Normally, the worker processes are configured to read from a shared
  8015. configuration file as well as the worker-specific configuration files. This
  8016. makes it easier to keep common configuration settings synchronised across all
  8017. the processes.</p>
  8018. <p>The main process is somewhat special in this respect: it does not normally
  8019. need its own configuration file and can take all of its configuration from the
  8020. shared configuration file.</p>
  8021. <h3 id="shared-configuration"><a class="header" href="#shared-configuration">Shared configuration</a></h3>
  8022. <p>Normally, only a couple of changes are needed to make an existing configuration
  8023. file suitable for use with workers. First, you need to enable an &quot;HTTP replication
  8024. listener&quot; for the main process; and secondly, you need to enable redis-based
  8025. replication. Optionally, a shared secret can be used to authenticate HTTP
  8026. traffic between workers. For example:</p>
  8027. <pre><code class="language-yaml"># extend the existing `listeners` section. This defines the ports that the
  8028. # main process will listen on.
  8029. listeners:
  8030. # The HTTP replication port
  8031. - port: 9093
  8032. bind_address: '127.0.0.1'
  8033. type: http
  8034. resources:
  8035. - names: [replication]
  8036. # Add a random shared secret to authenticate traffic.
  8037. worker_replication_secret: &quot;&quot;
  8038. redis:
  8039. enabled: true
  8040. </code></pre>
  8041. <p>See the sample config for the full documentation of each option.</p>
  8042. <p>Under <strong>no circumstances</strong> should the replication listener be exposed to the
  8043. public internet; it has no authentication and is unencrypted.</p>
  8044. <h3 id="worker-configuration"><a class="header" href="#worker-configuration">Worker configuration</a></h3>
  8045. <p>In the config file for each worker, you must specify the type of worker
  8046. application (<code>worker_app</code>), and you should specify a unique name for the worker
  8047. (<code>worker_name</code>). The currently available worker applications are listed below.
  8048. You must also specify the HTTP replication endpoint that it should talk to on
  8049. the main synapse process. <code>worker_replication_host</code> should specify the host of
  8050. the main synapse and <code>worker_replication_http_port</code> should point to the HTTP
  8051. replication port. If the worker will handle HTTP requests then the
  8052. <code>worker_listeners</code> option should be set with a <code>http</code> listener, in the same way
  8053. as the <code>listeners</code> option in the shared config.</p>
  8054. <p>For example:</p>
  8055. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  8056. worker_name: worker1
  8057. # The replication listener on the main synapse process.
  8058. worker_replication_host: 127.0.0.1
  8059. worker_replication_http_port: 9093
  8060. worker_listeners:
  8061. - type: http
  8062. port: 8083
  8063. resources:
  8064. - names:
  8065. - client
  8066. - federation
  8067. worker_log_config: /home/matrix/synapse/config/worker1_log_config.yaml
  8068. </code></pre>
  8069. <p>...is a full configuration for a generic worker instance, which will expose a
  8070. plain HTTP endpoint on port 8083 separately serving various endpoints, e.g.
  8071. <code>/sync</code>, which are listed below.</p>
  8072. <p>Obviously you should configure your reverse-proxy to route the relevant
  8073. endpoints to the worker (<code>localhost:8083</code> in the above example).</p>
  8074. <h3 id="running-synapse-with-workers"><a class="header" href="#running-synapse-with-workers">Running Synapse with workers</a></h3>
  8075. <p>Finally, you need to start your worker processes. This can be done with either
  8076. <code>synctl</code> or your distribution's preferred service manager such as <code>systemd</code>. We
  8077. recommend the use of <code>systemd</code> where available: for information on setting up
  8078. <code>systemd</code> to start synapse workers, see
  8079. <a href="systemd-with-workers">Systemd with Workers</a>. To use <code>synctl</code>, see
  8080. <a href="synctl_workers.html">Using synctl with Workers</a>.</p>
  8081. <h2 id="available-worker-applications"><a class="header" href="#available-worker-applications">Available worker applications</a></h2>
  8082. <h3 id="synapseappgeneric_worker"><a class="header" href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a></h3>
  8083. <p>This worker can handle API requests matching the following regular
  8084. expressions:</p>
  8085. <pre><code># Sync requests
  8086. ^/_matrix/client/(v2_alpha|r0)/sync$
  8087. ^/_matrix/client/(api/v1|v2_alpha|r0)/events$
  8088. ^/_matrix/client/(api/v1|r0)/initialSync$
  8089. ^/_matrix/client/(api/v1|r0)/rooms/[^/]+/initialSync$
  8090. # Federation requests
  8091. ^/_matrix/federation/v1/event/
  8092. ^/_matrix/federation/v1/state/
  8093. ^/_matrix/federation/v1/state_ids/
  8094. ^/_matrix/federation/v1/backfill/
  8095. ^/_matrix/federation/v1/get_missing_events/
  8096. ^/_matrix/federation/v1/publicRooms
  8097. ^/_matrix/federation/v1/query/
  8098. ^/_matrix/federation/v1/make_join/
  8099. ^/_matrix/federation/v1/make_leave/
  8100. ^/_matrix/federation/v1/send_join/
  8101. ^/_matrix/federation/v2/send_join/
  8102. ^/_matrix/federation/v1/send_leave/
  8103. ^/_matrix/federation/v2/send_leave/
  8104. ^/_matrix/federation/v1/invite/
  8105. ^/_matrix/federation/v2/invite/
  8106. ^/_matrix/federation/v1/query_auth/
  8107. ^/_matrix/federation/v1/event_auth/
  8108. ^/_matrix/federation/v1/exchange_third_party_invite/
  8109. ^/_matrix/federation/v1/user/devices/
  8110. ^/_matrix/federation/v1/get_groups_publicised$
  8111. ^/_matrix/key/v2/query
  8112. ^/_matrix/federation/unstable/org.matrix.msc2946/spaces/
  8113. ^/_matrix/federation/unstable/org.matrix.msc2946/hierarchy/
  8114. # Inbound federation transaction request
  8115. ^/_matrix/federation/v1/send/
  8116. # Client API requests
  8117. ^/_matrix/client/(api/v1|r0|unstable)/createRoom$
  8118. ^/_matrix/client/(api/v1|r0|unstable)/publicRooms$
  8119. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/joined_members$
  8120. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/context/.*$
  8121. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/members$
  8122. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state$
  8123. ^/_matrix/client/unstable/org.matrix.msc2946/rooms/.*/spaces$
  8124. ^/_matrix/client/unstable/org.matrix.msc2946/rooms/.*/hierarchy$
  8125. ^/_matrix/client/unstable/im.nheko.summary/rooms/.*/summary$
  8126. ^/_matrix/client/(api/v1|r0|unstable)/account/3pid$
  8127. ^/_matrix/client/(api/v1|r0|unstable)/devices$
  8128. ^/_matrix/client/(api/v1|r0|unstable)/keys/query$
  8129. ^/_matrix/client/(api/v1|r0|unstable)/keys/changes$
  8130. ^/_matrix/client/versions$
  8131. ^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$
  8132. ^/_matrix/client/(api/v1|r0|unstable)/joined_groups$
  8133. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups$
  8134. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups/
  8135. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/event/
  8136. ^/_matrix/client/(api/v1|r0|unstable)/joined_rooms$
  8137. ^/_matrix/client/(api/v1|r0|unstable)/search$
  8138. # Registration/login requests
  8139. ^/_matrix/client/(api/v1|r0|unstable)/login$
  8140. ^/_matrix/client/(r0|unstable)/register$
  8141. ^/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity$
  8142. # Event sending requests
  8143. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/redact
  8144. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/send
  8145. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state/
  8146. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
  8147. ^/_matrix/client/(api/v1|r0|unstable)/join/
  8148. ^/_matrix/client/(api/v1|r0|unstable)/profile/
  8149. </code></pre>
  8150. <p>Additionally, the following REST endpoints can be handled for GET requests:</p>
  8151. <pre><code>^/_matrix/federation/v1/groups/
  8152. </code></pre>
  8153. <p>Pagination requests can also be handled, but all requests for a given
  8154. room must be routed to the same instance. Additionally, care must be taken to
  8155. ensure that the purge history admin API is not used while pagination requests
  8156. for the room are in flight:</p>
  8157. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/messages$
  8158. </code></pre>
  8159. <p>Additionally, the following endpoints should be included if Synapse is configured
  8160. to use SSO (you only need to include the ones for whichever SSO provider you're
  8161. using):</p>
  8162. <pre><code># for all SSO providers
  8163. ^/_matrix/client/(api/v1|r0|unstable)/login/sso/redirect
  8164. ^/_synapse/client/pick_idp$
  8165. ^/_synapse/client/pick_username
  8166. ^/_synapse/client/new_user_consent$
  8167. ^/_synapse/client/sso_register$
  8168. # OpenID Connect requests.
  8169. ^/_synapse/client/oidc/callback$
  8170. # SAML requests.
  8171. ^/_synapse/client/saml2/authn_response$
  8172. # CAS requests.
  8173. ^/_matrix/client/(api/v1|r0|unstable)/login/cas/ticket$
  8174. </code></pre>
  8175. <p>Ensure that all SSO logins go to a single process.
  8176. For multiple workers not handling the SSO endpoints properly, see
  8177. <a href="https://github.com/matrix-org/synapse/issues/7530">#7530</a> and
  8178. <a href="https://github.com/matrix-org/synapse/issues/9427">#9427</a>.</p>
  8179. <p>Note that a HTTP listener with <code>client</code> and <code>federation</code> resources must be
  8180. configured in the <code>worker_listeners</code> option in the worker config.</p>
  8181. <h4 id="load-balancing"><a class="header" href="#load-balancing">Load balancing</a></h4>
  8182. <p>It is possible to run multiple instances of this worker app, with incoming requests
  8183. being load-balanced between them by the reverse-proxy. However, different endpoints
  8184. have different characteristics and so admins
  8185. may wish to run multiple groups of workers handling different endpoints so that
  8186. load balancing can be done in different ways.</p>
  8187. <p>For <code>/sync</code> and <code>/initialSync</code> requests it will be more efficient if all
  8188. requests from a particular user are routed to a single instance. Extracting a
  8189. user ID from the access token or <code>Authorization</code> header is currently left as an
  8190. exercise for the reader. Admins may additionally wish to separate out <code>/sync</code>
  8191. requests that have a <code>since</code> query parameter from those that don't (and
  8192. <code>/initialSync</code>), as requests that don't are known as &quot;initial sync&quot; that happens
  8193. when a user logs in on a new device and can be <em>very</em> resource intensive, so
  8194. isolating these requests will stop them from interfering with other users ongoing
  8195. syncs.</p>
  8196. <p>Federation and client requests can be balanced via simple round robin.</p>
  8197. <p>The inbound federation transaction request <code>^/_matrix/federation/v1/send/</code>
  8198. should be balanced by source IP so that transactions from the same remote server
  8199. go to the same process.</p>
  8200. <p>Registration/login requests can be handled separately purely to help ensure that
  8201. unexpected load doesn't affect new logins and sign ups.</p>
  8202. <p>Finally, event sending requests can be balanced by the room ID in the URI (or
  8203. the full URI, or even just round robin), the room ID is the path component after
  8204. <code>/rooms/</code>. If there is a large bridge connected that is sending or may send lots
  8205. of events, then a dedicated set of workers can be provisioned to limit the
  8206. effects of bursts of events from that bridge on events sent by normal users.</p>
  8207. <h4 id="stream-writers"><a class="header" href="#stream-writers">Stream writers</a></h4>
  8208. <p>Additionally, there is <em>experimental</em> support for moving writing of specific
  8209. streams (such as events) off of the main process to a particular worker. (This
  8210. is only supported with Redis-based replication.)</p>
  8211. <p>Currently supported streams are <code>events</code> and <code>typing</code>.</p>
  8212. <p>To enable this, the worker must have a HTTP replication listener configured,
  8213. have a <code>worker_name</code> and be listed in the <code>instance_map</code> config. For example to
  8214. move event persistence off to a dedicated worker, the shared configuration would
  8215. include:</p>
  8216. <pre><code class="language-yaml">instance_map:
  8217. event_persister1:
  8218. host: localhost
  8219. port: 8034
  8220. stream_writers:
  8221. events: event_persister1
  8222. </code></pre>
  8223. <p>The <code>events</code> stream also experimentally supports having multiple writers, where
  8224. work is sharded between them by room ID. Note that you <em>must</em> restart all worker
  8225. instances when adding or removing event persisters. An example <code>stream_writers</code>
  8226. configuration with multiple writers:</p>
  8227. <pre><code class="language-yaml">stream_writers:
  8228. events:
  8229. - event_persister1
  8230. - event_persister2
  8231. </code></pre>
  8232. <h4 id="background-tasks"><a class="header" href="#background-tasks">Background tasks</a></h4>
  8233. <p>There is also <em>experimental</em> support for moving background tasks to a separate
  8234. worker. Background tasks are run periodically or started via replication. Exactly
  8235. which tasks are configured to run depends on your Synapse configuration (e.g. if
  8236. stats is enabled).</p>
  8237. <p>To enable this, the worker must have a <code>worker_name</code> and can be configured to run
  8238. background tasks. For example, to move background tasks to a dedicated worker,
  8239. the shared configuration would include:</p>
  8240. <pre><code class="language-yaml">run_background_tasks_on: background_worker
  8241. </code></pre>
  8242. <p>You might also wish to investigate the <code>update_user_directory</code> and
  8243. <code>media_instance_running_background_jobs</code> settings.</p>
  8244. <h3 id="synapseapppusher"><a class="header" href="#synapseapppusher"><code>synapse.app.pusher</code></a></h3>
  8245. <p>Handles sending push notifications to sygnal and email. Doesn't handle any
  8246. REST endpoints itself, but you should set <code>start_pushers: False</code> in the
  8247. shared configuration file to stop the main synapse sending push notifications.</p>
  8248. <p>To run multiple instances at once the <code>pusher_instances</code> option should list all
  8249. pusher instances by their worker name, e.g.:</p>
  8250. <pre><code class="language-yaml">pusher_instances:
  8251. - pusher_worker1
  8252. - pusher_worker2
  8253. </code></pre>
  8254. <h3 id="synapseappappservice"><a class="header" href="#synapseappappservice"><code>synapse.app.appservice</code></a></h3>
  8255. <p>Handles sending output traffic to Application Services. Doesn't handle any
  8256. REST endpoints itself, but you should set <code>notify_appservices: False</code> in the
  8257. shared configuration file to stop the main synapse sending appservice notifications.</p>
  8258. <p>Note this worker cannot be load-balanced: only one instance should be active.</p>
  8259. <h3 id="synapseappfederation_sender"><a class="header" href="#synapseappfederation_sender"><code>synapse.app.federation_sender</code></a></h3>
  8260. <p>Handles sending federation traffic to other servers. Doesn't handle any
  8261. REST endpoints itself, but you should set <code>send_federation: False</code> in the
  8262. shared configuration file to stop the main synapse sending this traffic.</p>
  8263. <p>If running multiple federation senders then you must list each
  8264. instance in the <code>federation_sender_instances</code> option by their <code>worker_name</code>.
  8265. All instances must be stopped and started when adding or removing instances.
  8266. For example:</p>
  8267. <pre><code class="language-yaml">federation_sender_instances:
  8268. - federation_sender1
  8269. - federation_sender2
  8270. </code></pre>
  8271. <h3 id="synapseappmedia_repository"><a class="header" href="#synapseappmedia_repository"><code>synapse.app.media_repository</code></a></h3>
  8272. <p>Handles the media repository. It can handle all endpoints starting with:</p>
  8273. <pre><code>/_matrix/media/
  8274. </code></pre>
  8275. <p>... and the following regular expressions matching media-specific administration APIs:</p>
  8276. <pre><code>^/_synapse/admin/v1/purge_media_cache$
  8277. ^/_synapse/admin/v1/room/.*/media.*$
  8278. ^/_synapse/admin/v1/user/.*/media.*$
  8279. ^/_synapse/admin/v1/media/.*$
  8280. ^/_synapse/admin/v1/quarantine_media/.*$
  8281. ^/_synapse/admin/v1/users/.*/media$
  8282. </code></pre>
  8283. <p>You should also set <code>enable_media_repo: False</code> in the shared configuration
  8284. file to stop the main synapse running background jobs related to managing the
  8285. media repository. Note that doing so will prevent the main process from being
  8286. able to handle the above endpoints.</p>
  8287. <p>In the <code>media_repository</code> worker configuration file, configure the http listener to
  8288. expose the <code>media</code> resource. For example:</p>
  8289. <pre><code class="language-yaml"> worker_listeners:
  8290. - type: http
  8291. port: 8085
  8292. resources:
  8293. - names:
  8294. - media
  8295. </code></pre>
  8296. <p>Note that if running multiple media repositories they must be on the same server
  8297. and you must configure a single instance to run the background tasks, e.g.:</p>
  8298. <pre><code class="language-yaml"> media_instance_running_background_jobs: &quot;media-repository-1&quot;
  8299. </code></pre>
  8300. <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>
  8301. <h3 id="synapseappuser_dir"><a class="header" href="#synapseappuser_dir"><code>synapse.app.user_dir</code></a></h3>
  8302. <p>Handles searches in the user directory. It can handle REST endpoints matching
  8303. the following regular expressions:</p>
  8304. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$
  8305. </code></pre>
  8306. <p>When using this worker you must also set <code>update_user_directory: False</code> in the
  8307. shared configuration file to stop the main synapse running background
  8308. jobs related to updating the user directory.</p>
  8309. <h3 id="synapseappfrontend_proxy"><a class="header" href="#synapseappfrontend_proxy"><code>synapse.app.frontend_proxy</code></a></h3>
  8310. <p>Proxies some frequently-requested client endpoints to add caching and remove
  8311. load from the main synapse. It can handle REST endpoints matching the following
  8312. regular expressions:</p>
  8313. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/keys/upload
  8314. </code></pre>
  8315. <p>If <code>use_presence</code> is False in the homeserver config, it can also handle REST
  8316. endpoints matching the following regular expressions:</p>
  8317. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/presence/[^/]+/status
  8318. </code></pre>
  8319. <p>This &quot;stub&quot; presence handler will pass through <code>GET</code> request but make the
  8320. <code>PUT</code> effectively a no-op.</p>
  8321. <p>It will proxy any requests it cannot handle to the main synapse instance. It
  8322. must therefore be configured with the location of the main instance, via
  8323. the <code>worker_main_http_uri</code> setting in the <code>frontend_proxy</code> worker configuration
  8324. file. For example:</p>
  8325. <pre><code>worker_main_http_uri: http://127.0.0.1:8008
  8326. </code></pre>
  8327. <h3 id="historical-apps"><a class="header" href="#historical-apps">Historical apps</a></h3>
  8328. <p><em>Note:</em> Historically there used to be more apps, however they have been
  8329. amalgamated into a single <code>synapse.app.generic_worker</code> app. The remaining apps
  8330. are ones that do specific processing unrelated to requests, e.g. the <code>pusher</code>
  8331. that handles sending out push notifications for new events. The intention is for
  8332. all these to be folded into the <code>generic_worker</code> app and to use config to define
  8333. which processes handle the various proccessing such as push notifications.</p>
  8334. <h2 id="migration-from-old-config"><a class="header" href="#migration-from-old-config">Migration from old config</a></h2>
  8335. <p>There are two main independent changes that have been made: introducing Redis
  8336. support and merging apps into <code>synapse.app.generic_worker</code>. Both these changes
  8337. are backwards compatible and so no changes to the config are required, however
  8338. server admins are encouraged to plan to migrate to Redis as the old style direct
  8339. TCP replication config is deprecated.</p>
  8340. <p>To migrate to Redis add the <code>redis</code> config as above, and optionally remove the
  8341. TCP <code>replication</code> listener from master and <code>worker_replication_port</code> from worker
  8342. config.</p>
  8343. <p>To migrate apps to use <code>synapse.app.generic_worker</code> simply update the
  8344. <code>worker_app</code> option in the worker configs, and where worker are started (e.g.
  8345. in systemd service files, but not required for synctl).</p>
  8346. <h2 id="architectural-diagram"><a class="header" href="#architectural-diagram">Architectural diagram</a></h2>
  8347. <p>The following shows an example setup using Redis and a reverse proxy:</p>
  8348. <pre><code> Clients &amp; Federation
  8349. |
  8350. v
  8351. +-----------+
  8352. | |
  8353. | Reverse |
  8354. | Proxy |
  8355. | |
  8356. +-----------+
  8357. | | |
  8358. | | | HTTP requests
  8359. +-------------------+ | +-----------+
  8360. | +---+ |
  8361. | | |
  8362. v v v
  8363. +--------------+ +--------------+ +--------------+ +--------------+
  8364. | Main | | Generic | | Generic | | Event |
  8365. | Process | | Worker 1 | | Worker 2 | | Persister |
  8366. +--------------+ +--------------+ +--------------+ +--------------+
  8367. ^ ^ | ^ | | ^ | ^ ^
  8368. | | | | | | | | | |
  8369. | | | | | HTTP | | | | |
  8370. | +----------+&lt;--|---|---------+ | | | |
  8371. | | +-------------|--&gt;+----------+ |
  8372. | | | |
  8373. | | | |
  8374. v v v v
  8375. ====================================================================
  8376. Redis pub/sub channel
  8377. </code></pre>
  8378. <div style="break-before: page; page-break-before: always;"></div><h3 id="using-synctl-with-workers"><a class="header" href="#using-synctl-with-workers">Using synctl with workers</a></h3>
  8379. <p>If you want to use <code>synctl</code> to manage your synapse processes, you will need to
  8380. create an an additional configuration file for the main synapse process. That
  8381. configuration should look like this:</p>
  8382. <pre><code class="language-yaml">worker_app: synapse.app.homeserver
  8383. </code></pre>
  8384. <p>Additionally, each worker app must be configured with the name of a &quot;pid file&quot;,
  8385. to which it will write its process ID when it starts. For example, for a
  8386. synchrotron, you might write:</p>
  8387. <pre><code class="language-yaml">worker_pid_file: /home/matrix/synapse/worker1.pid
  8388. </code></pre>
  8389. <p>Finally, to actually run your worker-based synapse, you must pass synctl the <code>-a</code>
  8390. commandline option to tell it to operate on all the worker configurations found
  8391. in the given directory, e.g.:</p>
  8392. <pre><code>synctl -a $CONFIG/workers start
  8393. </code></pre>
  8394. <p>Currently one should always restart all workers when restarting or upgrading
  8395. synapse, unless you explicitly know it's safe not to. For instance, restarting
  8396. synapse without restarting all the synchrotrons may result in broken typing
  8397. notifications.</p>
  8398. <p>To manipulate a specific worker, you pass the -w option to synctl:</p>
  8399. <pre><code>synctl -w $CONFIG/workers/worker1.yaml restart
  8400. </code></pre>
  8401. <div style="break-before: page; page-break-before: always;"></div><h1 id="setting-up-synapse-with-workers-and-systemd"><a class="header" href="#setting-up-synapse-with-workers-and-systemd">Setting up Synapse with Workers and Systemd</a></h1>
  8402. <p>This is a setup for managing synapse with systemd, including support for
  8403. managing workers. It provides a <code>matrix-synapse</code> service for the master, as
  8404. well as a <code>matrix-synapse-worker@</code> service template for any workers you
  8405. require. Additionally, to group the required services, it sets up a
  8406. <code>matrix-synapse.target</code>.</p>
  8407. <p>See the folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/system/">system</a>
  8408. for the systemd unit files.</p>
  8409. <p>The folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/workers/">workers</a>
  8410. contains an example configuration for the <code>federation_reader</code> worker.</p>
  8411. <h2 id="synapse-configuration-files"><a class="header" href="#synapse-configuration-files">Synapse configuration files</a></h2>
  8412. <p>See <a href="systemd-with-workers/../workers.html">the worker documentation</a> for information on how to set up the
  8413. configuration files and reverse-proxy correctly.
  8414. Below is a sample <code>federation_reader</code> worker configuration file.</p>
  8415. <pre><code class="language-yaml">worker_app: synapse.app.federation_reader
  8416. worker_name: federation_reader1
  8417. worker_replication_host: 127.0.0.1
  8418. worker_replication_http_port: 9093
  8419. worker_listeners:
  8420. - type: http
  8421. port: 8011
  8422. resources:
  8423. - names: [federation]
  8424. worker_log_config: /etc/matrix-synapse/federation-reader-log.yaml
  8425. </code></pre>
  8426. <p>Systemd manages daemonization itself, so ensure that none of the configuration
  8427. files set either <code>daemonize</code> or <code>worker_daemonize</code>.</p>
  8428. <p>The config files of all workers are expected to be located in
  8429. <code>/etc/matrix-synapse/workers</code>. If you want to use a different location, edit
  8430. the provided <code>*.service</code> files accordingly.</p>
  8431. <p>There is no need for a separate configuration file for the master process.</p>
  8432. <h2 id="set-up"><a class="header" href="#set-up">Set up</a></h2>
  8433. <ol>
  8434. <li>Adjust synapse configuration files as above.</li>
  8435. <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>
  8436. to <code>/etc/systemd/system</code>.</li>
  8437. <li>Run <code>systemctl daemon-reload</code> to tell systemd to load the new unit files.</li>
  8438. <li>Run <code>systemctl enable matrix-synapse.service</code>. This will configure the
  8439. synapse master process to be started as part of the <code>matrix-synapse.target</code>
  8440. target.</li>
  8441. <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
  8442. should be a corresponding configuration file.
  8443. <code>/etc/matrix-synapse/workers/&lt;worker_name&gt;.yaml</code>.</li>
  8444. <li>Start all the synapse processes with <code>systemctl start matrix-synapse.target</code>.</li>
  8445. <li>Tell systemd to start synapse on boot with <code>systemctl enable matrix-synapse.target</code>.</li>
  8446. </ol>
  8447. <h2 id="usage"><a class="header" href="#usage">Usage</a></h2>
  8448. <p>Once the services are correctly set up, you can use the following commands
  8449. to manage your synapse installation:</p>
  8450. <pre><code class="language-sh"># Restart Synapse master and all workers
  8451. systemctl restart matrix-synapse.target
  8452. # Stop Synapse and all workers
  8453. systemctl stop matrix-synapse.target
  8454. # Restart the master alone
  8455. systemctl start matrix-synapse.service
  8456. # Restart a specific worker (eg. federation_reader); the master is
  8457. # unaffected by this.
  8458. systemctl restart matrix-synapse-worker@federation_reader.service
  8459. # Add a new worker (assuming all configs are set up already)
  8460. systemctl enable matrix-synapse-worker@federation_writer.service
  8461. systemctl restart matrix-synapse.target
  8462. </code></pre>
  8463. <h2 id="hardening"><a class="header" href="#hardening">Hardening</a></h2>
  8464. <p><strong>Optional:</strong> If further hardening is desired, the file
  8465. <code>override-hardened.conf</code> may be copied from
  8466. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/systemd/">contrib/systemd/override-hardened.conf</a>
  8467. in this repository to the location
  8468. <code>/etc/systemd/system/matrix-synapse.service.d/override-hardened.conf</code> (the
  8469. directory may have to be created). It enables certain sandboxing features in
  8470. systemd to further secure the synapse service. You may read the comments to
  8471. understand what the override file is doing. The same file will need to be copied to
  8472. <code>/etc/systemd/system/matrix-synapse-worker@.service.d/override-hardened-worker.conf</code>
  8473. (this directory may also have to be created) in order to apply the same
  8474. hardening options to any worker processes.</p>
  8475. <p>Once these files have been copied to their appropriate locations, simply reload
  8476. systemd's manager config files and restart all Synapse services to apply the hardening options. They will automatically
  8477. be applied at every restart as long as the override files are present at the
  8478. specified locations.</p>
  8479. <pre><code class="language-sh">systemctl daemon-reload
  8480. # Restart services
  8481. systemctl restart matrix-synapse.target
  8482. </code></pre>
  8483. <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
  8484. the changes being applied at a glance.</p>
  8485. <div style="break-before: page; page-break-before: always;"></div><h1 id="administration"><a class="header" href="#administration">Administration</a></h1>
  8486. <p>This section contains information on managing your Synapse homeserver. This includes:</p>
  8487. <ul>
  8488. <li>Managing users, rooms and media via the Admin API.</li>
  8489. <li>Setting up metrics and monitoring to give you insight into your homeserver's health.</li>
  8490. <li>Configuring structured logging.</li>
  8491. </ul>
  8492. <div style="break-before: page; page-break-before: always;"></div><h1 id="the-admin-api"><a class="header" href="#the-admin-api">The Admin API</a></h1>
  8493. <h2 id="authenticate-as-a-server-admin"><a class="header" href="#authenticate-as-a-server-admin">Authenticate as a server admin</a></h2>
  8494. <p>Many of the API calls in the admin api will require an <code>access_token</code> for a
  8495. server admin. (Note that a server admin is distinct from a room admin.)</p>
  8496. <p>A user can be marked as a server admin by updating the database directly, e.g.:</p>
  8497. <pre><code class="language-sql">UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
  8498. </code></pre>
  8499. <p>A new server admin user can also be created using the <code>register_new_matrix_user</code>
  8500. command. This is a script that is located in the <code>scripts/</code> directory, or possibly
  8501. already on your <code>$PATH</code> depending on how Synapse was installed.</p>
  8502. <p>Finding your user's <code>access_token</code> is client-dependent, but will usually be shown in the client's settings.</p>
  8503. <h2 id="making-an-admin-api-request"><a class="header" href="#making-an-admin-api-request">Making an Admin API request</a></h2>
  8504. <p>Once you have your <code>access_token</code>, you will need to authenticate each request to an Admin API endpoint by
  8505. providing the token as either a query parameter or a request header. To add it as a request header in cURL:</p>
  8506. <pre><code class="language-sh">curl --header &quot;Authorization: Bearer &lt;access_token&gt;&quot; &lt;the_rest_of_your_API_request&gt;
  8507. </code></pre>
  8508. <p>For more details on access tokens in Matrix, please refer to the complete
  8509. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#using-access-tokens">matrix spec documentation</a>.</p>
  8510. <div style="break-before: page; page-break-before: always;"></div><h1 id="account-validity-api"><a class="header" href="#account-validity-api">Account validity API</a></h1>
  8511. <p>This API allows a server administrator to manage the validity of an account. To
  8512. use it, you must enable the account validity feature (under
  8513. <code>account_validity</code>) in Synapse's configuration.</p>
  8514. <h2 id="renew-account"><a class="header" href="#renew-account">Renew account</a></h2>
  8515. <p>This API extends the validity of an account by as much time as configured in the
  8516. <code>period</code> parameter from the <code>account_validity</code> configuration.</p>
  8517. <p>The API is:</p>
  8518. <pre><code>POST /_synapse/admin/v1/account_validity/validity
  8519. </code></pre>
  8520. <p>with the following body:</p>
  8521. <pre><code class="language-json">{
  8522. &quot;user_id&quot;: &quot;&lt;user ID for the account to renew&gt;&quot;,
  8523. &quot;expiration_ts&quot;: 0,
  8524. &quot;enable_renewal_emails&quot;: true
  8525. }
  8526. </code></pre>
  8527. <p><code>expiration_ts</code> is an optional parameter and overrides the expiration date,
  8528. which otherwise defaults to now + validity period.</p>
  8529. <p><code>enable_renewal_emails</code> is also an optional parameter and enables/disables
  8530. sending renewal emails to the user. Defaults to true.</p>
  8531. <p>The API returns with the new expiration date for this account, as a timestamp in
  8532. milliseconds since epoch:</p>
  8533. <pre><code class="language-json">{
  8534. &quot;expiration_ts&quot;: 0
  8535. }
  8536. </code></pre>
  8537. <div style="break-before: page; page-break-before: always;"></div><h1 id="delete-a-local-group"><a class="header" href="#delete-a-local-group">Delete a local group</a></h1>
  8538. <p>This API lets a server admin delete a local group. Doing so will kick all
  8539. users out of the group so that their clients will correctly handle the group
  8540. being deleted.</p>
  8541. <p>The API is:</p>
  8542. <pre><code>POST /_synapse/admin/v1/delete_group/&lt;group_id&gt;
  8543. </code></pre>
  8544. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8545. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8546. <div style="break-before: page; page-break-before: always;"></div><h1 id="show-reported-events"><a class="header" href="#show-reported-events">Show reported events</a></h1>
  8547. <p>This API returns information about reported events.</p>
  8548. <p>The api is:</p>
  8549. <pre><code>GET /_synapse/admin/v1/event_reports?from=0&amp;limit=10
  8550. </code></pre>
  8551. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8552. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8553. <p>It returns a JSON body like the following:</p>
  8554. <pre><code class="language-json">{
  8555. &quot;event_reports&quot;: [
  8556. {
  8557. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8558. &quot;id&quot;: 2,
  8559. &quot;reason&quot;: &quot;foo&quot;,
  8560. &quot;score&quot;: -100,
  8561. &quot;received_ts&quot;: 1570897107409,
  8562. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8563. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8564. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8565. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8566. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8567. },
  8568. {
  8569. &quot;event_id&quot;: &quot;$3IcdZsDaN_En-S1DF4EMCy3v4gNRKeOJs8W5qTOKj4I&quot;,
  8570. &quot;id&quot;: 3,
  8571. &quot;reason&quot;: &quot;bar&quot;,
  8572. &quot;score&quot;: -100,
  8573. &quot;received_ts&quot;: 1598889612059,
  8574. &quot;canonical_alias&quot;: &quot;#alias2:matrix.org&quot;,
  8575. &quot;room_id&quot;: &quot;!eGvUQuTCkHGVwNMOjv:matrix.org&quot;,
  8576. &quot;name&quot;: &quot;Your room name here&quot;,
  8577. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8578. &quot;user_id&quot;: &quot;@bar:matrix.org&quot;
  8579. }
  8580. ],
  8581. &quot;next_token&quot;: 2,
  8582. &quot;total&quot;: 4
  8583. }
  8584. </code></pre>
  8585. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again with <code>from</code>
  8586. set to the value of <code>next_token</code>. This will return a new page.</p>
  8587. <p>If the endpoint does not return a <code>next_token</code> then there are no more reports to
  8588. paginate through.</p>
  8589. <p><strong>URL parameters:</strong></p>
  8590. <ul>
  8591. <li><code>limit</code>: integer - Is optional but is used for pagination, denoting the maximum number
  8592. of items to return in this call. Defaults to <code>100</code>.</li>
  8593. <li><code>from</code>: integer - Is optional but used for pagination, denoting the offset in the
  8594. returned results. This should be treated as an opaque value and not explicitly set to
  8595. anything other than the return value of <code>next_token</code> from a previous call. Defaults to <code>0</code>.</li>
  8596. <li><code>dir</code>: string - Direction of event report order. Whether to fetch the most recent
  8597. first (<code>b</code>) or the oldest first (<code>f</code>). Defaults to <code>b</code>.</li>
  8598. <li><code>user_id</code>: string - Is optional and filters to only return users with user IDs that
  8599. contain this value. This is the user who reported the event and wrote the reason.</li>
  8600. <li><code>room_id</code>: string - Is optional and filters to only return rooms with room IDs that
  8601. contain this value.</li>
  8602. </ul>
  8603. <p><strong>Response</strong></p>
  8604. <p>The following fields are returned in the JSON response body:</p>
  8605. <ul>
  8606. <li><code>id</code>: integer - ID of event report.</li>
  8607. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8608. report was sent.</li>
  8609. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8610. <li><code>name</code>: string - The name of the room.</li>
  8611. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8612. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8613. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank or <code>null</code>.</li>
  8614. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8615. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;. May be <code>null</code>.</li>
  8616. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8617. was reported.</li>
  8618. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8619. have a canonical alias set.</li>
  8620. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  8621. <li><code>total</code>: integer - Total number of event reports related to the query
  8622. (<code>user_id</code> and <code>room_id</code>).</li>
  8623. </ul>
  8624. <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>
  8625. <p>This API returns information about a specific event report.</p>
  8626. <p>The api is:</p>
  8627. <pre><code>GET /_synapse/admin/v1/event_reports/&lt;report_id&gt;
  8628. </code></pre>
  8629. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8630. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8631. <p>It returns a JSON body like the following:</p>
  8632. <pre><code class="language-jsonc">{
  8633. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8634. &quot;event_json&quot;: {
  8635. &quot;auth_events&quot;: [
  8636. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;,
  8637. &quot;$oggsNXxzPFRE3y53SUNd7nsj69-QzKv03a1RucHu-ws&quot;
  8638. ],
  8639. &quot;content&quot;: {
  8640. &quot;body&quot;: &quot;matrix.org: This Week in Matrix&quot;,
  8641. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  8642. &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;,
  8643. &quot;msgtype&quot;: &quot;m.notice&quot;
  8644. },
  8645. &quot;depth&quot;: 546,
  8646. &quot;hashes&quot;: {
  8647. &quot;sha256&quot;: &quot;xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw&quot;
  8648. },
  8649. &quot;origin&quot;: &quot;matrix.org&quot;,
  8650. &quot;origin_server_ts&quot;: 1592291711430,
  8651. &quot;prev_events&quot;: [
  8652. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;
  8653. ],
  8654. &quot;prev_state&quot;: [],
  8655. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8656. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8657. &quot;signatures&quot;: {
  8658. &quot;matrix.org&quot;: {
  8659. &quot;ed25519:a_JaEG&quot;: &quot;cs+OUKW/iHx5pEidbWxh0UiNNHwe46Ai9LwNz+Ah16aWDNszVIe2gaAcVZfvNsBhakQTew51tlKmL2kspXk/Dg&quot;
  8660. }
  8661. },
  8662. &quot;type&quot;: &quot;m.room.message&quot;,
  8663. &quot;unsigned&quot;: {
  8664. &quot;age_ts&quot;: 1592291711430,
  8665. }
  8666. },
  8667. &quot;id&quot;: &lt;report_id&gt;,
  8668. &quot;reason&quot;: &quot;foo&quot;,
  8669. &quot;score&quot;: -100,
  8670. &quot;received_ts&quot;: 1570897107409,
  8671. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8672. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8673. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8674. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8675. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8676. }
  8677. </code></pre>
  8678. <p><strong>URL parameters:</strong></p>
  8679. <ul>
  8680. <li><code>report_id</code>: string - The ID of the event report.</li>
  8681. </ul>
  8682. <p><strong>Response</strong></p>
  8683. <p>The following fields are returned in the JSON response body:</p>
  8684. <ul>
  8685. <li><code>id</code>: integer - ID of event report.</li>
  8686. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8687. report was sent.</li>
  8688. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8689. <li><code>name</code>: string - The name of the room.</li>
  8690. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8691. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8692. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank.</li>
  8693. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8694. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;.</li>
  8695. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8696. was reported.</li>
  8697. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8698. have a canonical alias set.</li>
  8699. <li><code>event_json</code>: object - Details of the original event that was reported.</li>
  8700. </ul>
  8701. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-1"><a class="header" href="#contents-1">Contents</a></h1>
  8702. <ul>
  8703. <li><a href="admin_api/media_admin_api.html#querying-media">Querying media</a>
  8704. <ul>
  8705. <li><a href="admin_api/media_admin_api.html#list-all-media-in-a-room">List all media in a room</a></li>
  8706. <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>
  8707. </ul>
  8708. </li>
  8709. <li><a href="admin_api/media_admin_api.html#quarantine-media">Quarantine media</a>
  8710. <ul>
  8711. <li><a href="admin_api/media_admin_api.html#quarantining-media-by-id">Quarantining media by ID</a></li>
  8712. <li><a href="admin_api/media_admin_api.html#remove-media-from-quarantine-by-id">Remove media from quarantine by ID</a></li>
  8713. <li><a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">Quarantining media in a room</a></li>
  8714. <li><a href="admin_api/media_admin_api.html#quarantining-all-media-of-a-user">Quarantining all media of a user</a></li>
  8715. <li><a href="admin_api/media_admin_api.html#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></li>
  8716. <li><a href="admin_api/media_admin_api.html#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></li>
  8717. </ul>
  8718. </li>
  8719. <li><a href="admin_api/media_admin_api.html#delete-local-media">Delete local media</a>
  8720. <ul>
  8721. <li><a href="admin_api/media_admin_api.html#delete-a-specific-local-media">Delete a specific local media</a></li>
  8722. <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>
  8723. <li><a href="admin_api/media_admin_api.html#delete-media-uploaded-by-a-user">Delete media uploaded by a user</a></li>
  8724. </ul>
  8725. </li>
  8726. <li><a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a></li>
  8727. </ul>
  8728. <h1 id="querying-media"><a class="header" href="#querying-media">Querying media</a></h1>
  8729. <p>These APIs allow extracting media information from the homeserver.</p>
  8730. <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>
  8731. <p>This API gets a list of known media in a room.
  8732. However, it only shows media from unencrypted events or rooms.</p>
  8733. <p>The API is:</p>
  8734. <pre><code>GET /_synapse/admin/v1/room/&lt;room_id&gt;/media
  8735. </code></pre>
  8736. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8737. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8738. <p>The API returns a JSON body like the following:</p>
  8739. <pre><code class="language-json">{
  8740. &quot;local&quot;: [
  8741. &quot;mxc://localhost/xwvutsrqponmlkjihgfedcba&quot;,
  8742. &quot;mxc://localhost/abcdefghijklmnopqrstuvwx&quot;
  8743. ],
  8744. &quot;remote&quot;: [
  8745. &quot;mxc://matrix.org/xwvutsrqponmlkjihgfedcba&quot;,
  8746. &quot;mxc://matrix.org/abcdefghijklmnopqrstuvwx&quot;
  8747. ]
  8748. }
  8749. </code></pre>
  8750. <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>
  8751. <p>Listing all media that has been uploaded by a local user can be achieved through
  8752. the use of the
  8753. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>
  8754. Admin API.</p>
  8755. <h1 id="quarantine-media"><a class="header" href="#quarantine-media">Quarantine media</a></h1>
  8756. <p>Quarantining media means that it is marked as inaccessible by users. It applies
  8757. to any local media, and any locally-cached copies of remote media.</p>
  8758. <p>The media file itself (and any thumbnails) is not deleted from the server.</p>
  8759. <h2 id="quarantining-media-by-id"><a class="header" href="#quarantining-media-by-id">Quarantining media by ID</a></h2>
  8760. <p>This API quarantines a single piece of local or remote media.</p>
  8761. <p>Request:</p>
  8762. <pre><code>POST /_synapse/admin/v1/media/quarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8763. {}
  8764. </code></pre>
  8765. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8766. form of <code>abcdefg12345...</code>.</p>
  8767. <p>Response:</p>
  8768. <pre><code class="language-json">{}
  8769. </code></pre>
  8770. <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>
  8771. <p>This API removes a single piece of local or remote media from quarantine.</p>
  8772. <p>Request:</p>
  8773. <pre><code>POST /_synapse/admin/v1/media/unquarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8774. {}
  8775. </code></pre>
  8776. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8777. form of <code>abcdefg12345...</code>.</p>
  8778. <p>Response:</p>
  8779. <pre><code class="language-json">{}
  8780. </code></pre>
  8781. <h2 id="quarantining-media-in-a-room"><a class="header" href="#quarantining-media-in-a-room">Quarantining media in a room</a></h2>
  8782. <p>This API quarantines all local and remote media in a room.</p>
  8783. <p>Request:</p>
  8784. <pre><code>POST /_synapse/admin/v1/room/&lt;room_id&gt;/media/quarantine
  8785. {}
  8786. </code></pre>
  8787. <p>Where <code>room_id</code> is in the form of <code>!roomid12345:example.org</code>.</p>
  8788. <p>Response:</p>
  8789. <pre><code class="language-json">{
  8790. &quot;num_quarantined&quot;: 10
  8791. }
  8792. </code></pre>
  8793. <p>The following fields are returned in the JSON response body:</p>
  8794. <ul>
  8795. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8796. </ul>
  8797. <p>Note that there is a legacy endpoint, <code>POST /_synapse/admin/v1/quarantine_media/&lt;room_id&gt;</code>, that operates the same.
  8798. However, it is deprecated and may be removed in a future release.</p>
  8799. <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>
  8800. <p>This API quarantines all <em>local</em> media that a <em>local</em> user has uploaded. That is to say, if
  8801. you would like to quarantine media uploaded by a user on a remote homeserver, you should
  8802. instead use one of the other APIs.</p>
  8803. <p>Request:</p>
  8804. <pre><code>POST /_synapse/admin/v1/user/&lt;user_id&gt;/media/quarantine
  8805. {}
  8806. </code></pre>
  8807. <p>URL Parameters</p>
  8808. <ul>
  8809. <li><code>user_id</code>: string - User ID in the form of <code>@bob:example.org</code></li>
  8810. </ul>
  8811. <p>Response:</p>
  8812. <pre><code class="language-json">{
  8813. &quot;num_quarantined&quot;: 10
  8814. }
  8815. </code></pre>
  8816. <p>The following fields are returned in the JSON response body:</p>
  8817. <ul>
  8818. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8819. </ul>
  8820. <h2 id="protecting-media-from-being-quarantined"><a class="header" href="#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></h2>
  8821. <p>This API protects a single piece of local media from being quarantined using the
  8822. above APIs. This is useful for sticker packs and other shared media which you do
  8823. not want to get quarantined, especially when
  8824. <a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">quarantining media in a room</a>.</p>
  8825. <p>Request:</p>
  8826. <pre><code>POST /_synapse/admin/v1/media/protect/&lt;media_id&gt;
  8827. {}
  8828. </code></pre>
  8829. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8830. <p>Response:</p>
  8831. <pre><code class="language-json">{}
  8832. </code></pre>
  8833. <h2 id="unprotecting-media-from-being-quarantined"><a class="header" href="#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></h2>
  8834. <p>This API reverts the protection of a media.</p>
  8835. <p>Request:</p>
  8836. <pre><code>POST /_synapse/admin/v1/media/unprotect/&lt;media_id&gt;
  8837. {}
  8838. </code></pre>
  8839. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8840. <p>Response:</p>
  8841. <pre><code class="language-json">{}
  8842. </code></pre>
  8843. <h1 id="delete-local-media"><a class="header" href="#delete-local-media">Delete local media</a></h1>
  8844. <p>This API deletes the <em>local</em> media from the disk of your own server.
  8845. This includes any local thumbnails and copies of media downloaded from
  8846. remote homeservers.
  8847. This API will not affect media that has been uploaded to external
  8848. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
  8849. See also <a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a>.</p>
  8850. <h2 id="delete-a-specific-local-media"><a class="header" href="#delete-a-specific-local-media">Delete a specific local media</a></h2>
  8851. <p>Delete a specific <code>media_id</code>.</p>
  8852. <p>Request:</p>
  8853. <pre><code>DELETE /_synapse/admin/v1/media/&lt;server_name&gt;/&lt;media_id&gt;
  8854. {}
  8855. </code></pre>
  8856. <p>URL Parameters</p>
  8857. <ul>
  8858. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>)</li>
  8859. <li><code>media_id</code>: string - The ID of the media (e.g <code>abcdefghijklmnopqrstuvwx</code>)</li>
  8860. </ul>
  8861. <p>Response:</p>
  8862. <pre><code class="language-json">{
  8863. &quot;deleted_media&quot;: [
  8864. &quot;abcdefghijklmnopqrstuvwx&quot;
  8865. ],
  8866. &quot;total&quot;: 1
  8867. }
  8868. </code></pre>
  8869. <p>The following fields are returned in the JSON response body:</p>
  8870. <ul>
  8871. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8872. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8873. </ul>
  8874. <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>
  8875. <p>Request:</p>
  8876. <pre><code>POST /_synapse/admin/v1/media/&lt;server_name&gt;/delete?before_ts=&lt;before_ts&gt;
  8877. {}
  8878. </code></pre>
  8879. <p>URL Parameters</p>
  8880. <ul>
  8881. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>).</li>
  8882. <li><code>before_ts</code>: string representing a positive integer - Unix timestamp in milliseconds.
  8883. Files that were last used before this timestamp will be deleted. It is the timestamp of
  8884. last access, not the timestamp when the file was created.</li>
  8885. <li><code>size_gt</code>: Optional - string representing a positive integer - Size of the media in bytes.
  8886. Files that are larger will be deleted. Defaults to <code>0</code>.</li>
  8887. <li><code>keep_profiles</code>: Optional - string representing a boolean - Switch to also delete files
  8888. that are still used in image data (e.g user profile, room avatar).
  8889. If <code>false</code> these files will be deleted. Defaults to <code>true</code>.</li>
  8890. </ul>
  8891. <p>Response:</p>
  8892. <pre><code class="language-json">{
  8893. &quot;deleted_media&quot;: [
  8894. &quot;abcdefghijklmnopqrstuvwx&quot;,
  8895. &quot;abcdefghijklmnopqrstuvwz&quot;
  8896. ],
  8897. &quot;total&quot;: 2
  8898. }
  8899. </code></pre>
  8900. <p>The following fields are returned in the JSON response body:</p>
  8901. <ul>
  8902. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8903. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8904. </ul>
  8905. <h2 id="delete-media-uploaded-by-a-user"><a class="header" href="#delete-media-uploaded-by-a-user">Delete media uploaded by a user</a></h2>
  8906. <p>You can find details of how to delete multiple media uploaded by a user in
  8907. <a href="admin_api/user_admin_api.html#delete-media-uploaded-by-a-user">User Admin API</a>.</p>
  8908. <h1 id="purge-remote-media-api"><a class="header" href="#purge-remote-media-api">Purge Remote Media API</a></h1>
  8909. <p>The purge remote media API allows server admins to purge old cached remote media.</p>
  8910. <p>The API is:</p>
  8911. <pre><code>POST /_synapse/admin/v1/purge_media_cache?before_ts=&lt;unix_timestamp_in_ms&gt;
  8912. {}
  8913. </code></pre>
  8914. <p>URL Parameters</p>
  8915. <ul>
  8916. <li><code>unix_timestamp_in_ms</code>: string representing a positive integer - Unix timestamp in milliseconds.
  8917. All cached media that was last accessed before this timestamp will be removed.</li>
  8918. </ul>
  8919. <p>Response:</p>
  8920. <pre><code class="language-json">{
  8921. &quot;deleted&quot;: 10
  8922. }
  8923. </code></pre>
  8924. <p>The following fields are returned in the JSON response body:</p>
  8925. <ul>
  8926. <li><code>deleted</code>: integer - The number of media items successfully deleted</li>
  8927. </ul>
  8928. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8929. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8930. <p>If the user re-requests purged remote media, synapse will re-request the media
  8931. from the originating server.</p>
  8932. <div style="break-before: page; page-break-before: always;"></div><h1 id="purge-history-api"><a class="header" href="#purge-history-api">Purge History API</a></h1>
  8933. <p>The purge history API allows server admins to purge historic events from their
  8934. database, reclaiming disk space.</p>
  8935. <p>Depending on the amount of history being purged a call to the API may take
  8936. several minutes or longer. During this period users will not be able to
  8937. paginate further back in the room from the point being purged from.</p>
  8938. <p>Note that Synapse requires at least one message in each room, so it will never
  8939. delete the last message in a room.</p>
  8940. <p>The API is:</p>
  8941. <pre><code>POST /_synapse/admin/v1/purge_history/&lt;room_id&gt;[/&lt;event_id&gt;]
  8942. </code></pre>
  8943. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8944. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  8945. <p>By default, events sent by local users are not deleted, as they may represent
  8946. the only copies of this content in existence. (Events sent by remote users are
  8947. deleted.)</p>
  8948. <p>Room state data (such as joins, leaves, topic) is always preserved.</p>
  8949. <p>To delete local message events as well, set <code>delete_local_events</code> in the body:</p>
  8950. <pre><code>{
  8951. &quot;delete_local_events&quot;: true
  8952. }
  8953. </code></pre>
  8954. <p>The caller must specify the point in the room to purge up to. This can be
  8955. specified by including an event_id in the URI, or by setting a
  8956. <code>purge_up_to_event_id</code> or <code>purge_up_to_ts</code> in the request body. If an event
  8957. id is given, that event (and others at the same graph depth) will be retained.
  8958. If <code>purge_up_to_ts</code> is given, it should be a timestamp since the unix epoch,
  8959. in milliseconds.</p>
  8960. <p>The API starts the purge running, and returns immediately with a JSON body with
  8961. a purge id:</p>
  8962. <pre><code class="language-json">{
  8963. &quot;purge_id&quot;: &quot;&lt;opaque id&gt;&quot;
  8964. }
  8965. </code></pre>
  8966. <h2 id="purge-status-query"><a class="header" href="#purge-status-query">Purge status query</a></h2>
  8967. <p>It is possible to poll for updates on recent purges with a second API;</p>
  8968. <pre><code>GET /_synapse/admin/v1/purge_history_status/&lt;purge_id&gt;
  8969. </code></pre>
  8970. <p>Again, you will need to authenticate by providing an <code>access_token</code> for a
  8971. server admin.</p>
  8972. <p>This API returns a JSON body like the following:</p>
  8973. <pre><code class="language-json">{
  8974. &quot;status&quot;: &quot;active&quot;
  8975. }
  8976. </code></pre>
  8977. <p>The status will be one of <code>active</code>, <code>complete</code>, or <code>failed</code>.</p>
  8978. <h2 id="reclaim-disk-space-postgres"><a class="header" href="#reclaim-disk-space-postgres">Reclaim disk space (Postgres)</a></h2>
  8979. <p>To reclaim the disk space and return it to the operating system, you need to run
  8980. <code>VACUUM FULL;</code> on the database.</p>
  8981. <p><a href="https://www.postgresql.org/docs/current/sql-vacuum.html">https://www.postgresql.org/docs/current/sql-vacuum.html</a></p>
  8982. <div style="break-before: page; page-break-before: always;"></div><h1 id="shared-secret-registration"><a class="header" href="#shared-secret-registration">Shared-Secret Registration</a></h1>
  8983. <p>This API allows for the creation of users in an administrative and
  8984. non-interactive way. This is generally used for bootstrapping a Synapse
  8985. instance with administrator accounts.</p>
  8986. <p>To authenticate yourself to the server, you will need both the shared secret
  8987. (<code>registration_shared_secret</code> in the homeserver configuration), and a
  8988. one-time nonce. If the registration shared secret is not configured, this API
  8989. is not enabled.</p>
  8990. <p>To fetch the nonce, you need to request one from the API:</p>
  8991. <pre><code>&gt; GET /_synapse/admin/v1/register
  8992. &lt; {&quot;nonce&quot;: &quot;thisisanonce&quot;}
  8993. </code></pre>
  8994. <p>Once you have the nonce, you can make a <code>POST</code> to the same URL with a JSON
  8995. body containing the nonce, username, password, whether they are an admin
  8996. (optional, False by default), and a HMAC digest of the content. Also you can
  8997. set the displayname (optional, <code>username</code> by default).</p>
  8998. <p>As an example:</p>
  8999. <pre><code>&gt; POST /_synapse/admin/v1/register
  9000. &gt; {
  9001. &quot;nonce&quot;: &quot;thisisanonce&quot;,
  9002. &quot;username&quot;: &quot;pepper_roni&quot;,
  9003. &quot;displayname&quot;: &quot;Pepper Roni&quot;,
  9004. &quot;password&quot;: &quot;pizza&quot;,
  9005. &quot;admin&quot;: true,
  9006. &quot;mac&quot;: &quot;mac_digest_here&quot;
  9007. }
  9008. &lt; {
  9009. &quot;access_token&quot;: &quot;token_here&quot;,
  9010. &quot;user_id&quot;: &quot;@pepper_roni:localhost&quot;,
  9011. &quot;home_server&quot;: &quot;test&quot;,
  9012. &quot;device_id&quot;: &quot;device_id_here&quot;
  9013. }
  9014. </code></pre>
  9015. <p>The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
  9016. the shared secret and the content being the nonce, user, password, either the
  9017. string &quot;admin&quot; or &quot;notadmin&quot;, and optionally the user_type
  9018. each separated by NULs. For an example of generation in Python:</p>
  9019. <pre><code class="language-python">import hmac, hashlib
  9020. def generate_mac(nonce, user, password, admin=False, user_type=None):
  9021. mac = hmac.new(
  9022. key=shared_secret,
  9023. digestmod=hashlib.sha1,
  9024. )
  9025. mac.update(nonce.encode('utf8'))
  9026. mac.update(b&quot;\x00&quot;)
  9027. mac.update(user.encode('utf8'))
  9028. mac.update(b&quot;\x00&quot;)
  9029. mac.update(password.encode('utf8'))
  9030. mac.update(b&quot;\x00&quot;)
  9031. mac.update(b&quot;admin&quot; if admin else b&quot;notadmin&quot;)
  9032. if user_type:
  9033. mac.update(b&quot;\x00&quot;)
  9034. mac.update(user_type.encode('utf8'))
  9035. return mac.hexdigest()
  9036. </code></pre>
  9037. <div style="break-before: page; page-break-before: always;"></div><h1 id="registration-tokens"><a class="header" href="#registration-tokens">Registration Tokens</a></h1>
  9038. <p>This API allows you to manage tokens which can be used to authenticate
  9039. registration requests, as proposed in
  9040. <a href="https://github.com/matrix-org/matrix-doc/blob/main/proposals/3231-token-authenticated-registration.md">MSC3231</a>.
  9041. To use it, you will need to enable the <code>registration_requires_token</code> config
  9042. option, and authenticate by providing an <code>access_token</code> for a server admin:
  9043. see <a href="usage/administration/admin_api/../../usage/administration/admin_api">Admin API</a>.
  9044. Note that this API is still experimental; not all clients may support it yet.</p>
  9045. <h2 id="registration-token-objects"><a class="header" href="#registration-token-objects">Registration token objects</a></h2>
  9046. <p>Most endpoints make use of JSON objects that contain details about tokens.
  9047. These objects have the following fields:</p>
  9048. <ul>
  9049. <li><code>token</code>: The token which can be used to authenticate registration.</li>
  9050. <li><code>uses_allowed</code>: The number of times the token can be used to complete a
  9051. registration before it becomes invalid.</li>
  9052. <li><code>pending</code>: The number of pending uses the token has. When someone uses
  9053. the token to authenticate themselves, the pending counter is incremented
  9054. so that the token is not used more than the permitted number of times.
  9055. When the person completes registration the pending counter is decremented,
  9056. and the completed counter is incremented.</li>
  9057. <li><code>completed</code>: The number of times the token has been used to successfully
  9058. complete a registration.</li>
  9059. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  9060. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  9061. To convert this into a human-readable form you can remove the milliseconds
  9062. and use the <code>date</code> command. For example, <code>date -d '@1625394937'</code>.</li>
  9063. </ul>
  9064. <h2 id="list-all-tokens"><a class="header" href="#list-all-tokens">List all tokens</a></h2>
  9065. <p>Lists all tokens and details about them. If the request is successful, the top
  9066. level JSON object will have a <code>registration_tokens</code> key which is an array of
  9067. registration token objects.</p>
  9068. <pre><code>GET /_synapse/admin/v1/registration_tokens
  9069. </code></pre>
  9070. <p>Optional query parameters:</p>
  9071. <ul>
  9072. <li><code>valid</code>: <code>true</code> or <code>false</code>. If <code>true</code>, only valid tokens are returned.
  9073. If <code>false</code>, only tokens that have expired or have had all uses exhausted are
  9074. returned. If omitted, all tokens are returned regardless of validity.</li>
  9075. </ul>
  9076. <p>Example:</p>
  9077. <pre><code>GET /_synapse/admin/v1/registration_tokens
  9078. </code></pre>
  9079. <pre><code>200 OK
  9080. {
  9081. &quot;registration_tokens&quot;: [
  9082. {
  9083. &quot;token&quot;: &quot;abcd&quot;,
  9084. &quot;uses_allowed&quot;: 3,
  9085. &quot;pending&quot;: 0,
  9086. &quot;completed&quot;: 1,
  9087. &quot;expiry_time&quot;: null
  9088. },
  9089. {
  9090. &quot;token&quot;: &quot;pqrs&quot;,
  9091. &quot;uses_allowed&quot;: 2,
  9092. &quot;pending&quot;: 1,
  9093. &quot;completed&quot;: 1,
  9094. &quot;expiry_time&quot;: null
  9095. },
  9096. {
  9097. &quot;token&quot;: &quot;wxyz&quot;,
  9098. &quot;uses_allowed&quot;: null,
  9099. &quot;pending&quot;: 0,
  9100. &quot;completed&quot;: 9,
  9101. &quot;expiry_time&quot;: 1625394937000 // 2021-07-04 10:35:37 UTC
  9102. }
  9103. ]
  9104. }
  9105. </code></pre>
  9106. <p>Example using the <code>valid</code> query parameter:</p>
  9107. <pre><code>GET /_synapse/admin/v1/registration_tokens?valid=false
  9108. </code></pre>
  9109. <pre><code>200 OK
  9110. {
  9111. &quot;registration_tokens&quot;: [
  9112. {
  9113. &quot;token&quot;: &quot;pqrs&quot;,
  9114. &quot;uses_allowed&quot;: 2,
  9115. &quot;pending&quot;: 1,
  9116. &quot;completed&quot;: 1,
  9117. &quot;expiry_time&quot;: null
  9118. },
  9119. {
  9120. &quot;token&quot;: &quot;wxyz&quot;,
  9121. &quot;uses_allowed&quot;: null,
  9122. &quot;pending&quot;: 0,
  9123. &quot;completed&quot;: 9,
  9124. &quot;expiry_time&quot;: 1625394937000 // 2021-07-04 10:35:37 UTC
  9125. }
  9126. ]
  9127. }
  9128. </code></pre>
  9129. <h2 id="get-one-token"><a class="header" href="#get-one-token">Get one token</a></h2>
  9130. <p>Get details about a single token. If the request is successful, the response
  9131. body will be a registration token object.</p>
  9132. <pre><code>GET /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  9133. </code></pre>
  9134. <p>Path parameters:</p>
  9135. <ul>
  9136. <li><code>token</code>: The registration token to return details of.</li>
  9137. </ul>
  9138. <p>Example:</p>
  9139. <pre><code>GET /_synapse/admin/v1/registration_tokens/abcd
  9140. </code></pre>
  9141. <pre><code>200 OK
  9142. {
  9143. &quot;token&quot;: &quot;abcd&quot;,
  9144. &quot;uses_allowed&quot;: 3,
  9145. &quot;pending&quot;: 0,
  9146. &quot;completed&quot;: 1,
  9147. &quot;expiry_time&quot;: null
  9148. }
  9149. </code></pre>
  9150. <h2 id="create-token"><a class="header" href="#create-token">Create token</a></h2>
  9151. <p>Create a new registration token. If the request is successful, the newly created
  9152. token will be returned as a registration token object in the response body.</p>
  9153. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  9154. </code></pre>
  9155. <p>The request body must be a JSON object and can contain the following fields:</p>
  9156. <ul>
  9157. <li><code>token</code>: The registration token. A string of no more than 64 characters that
  9158. consists only of characters matched by the regex <code>[A-Za-z0-9._~-]</code>.
  9159. Default: randomly generated.</li>
  9160. <li><code>uses_allowed</code>: The integer number of times the token can be used to complete
  9161. a registration before it becomes invalid.
  9162. Default: <code>null</code> (unlimited uses).</li>
  9163. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  9164. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  9165. You could use, for example, <code>date '+%s000' -d 'tomorrow'</code>.
  9166. Default: <code>null</code> (token does not expire).</li>
  9167. <li><code>length</code>: The length of the token randomly generated if <code>token</code> is not
  9168. specified. Must be between 1 and 64 inclusive. Default: <code>16</code>.</li>
  9169. </ul>
  9170. <p>If a field is omitted the default is used.</p>
  9171. <p>Example using defaults:</p>
  9172. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  9173. {}
  9174. </code></pre>
  9175. <pre><code>200 OK
  9176. {
  9177. &quot;token&quot;: &quot;0M-9jbkf2t_Tgiw1&quot;,
  9178. &quot;uses_allowed&quot;: null,
  9179. &quot;pending&quot;: 0,
  9180. &quot;completed&quot;: 0,
  9181. &quot;expiry_time&quot;: null
  9182. }
  9183. </code></pre>
  9184. <p>Example specifying some fields:</p>
  9185. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  9186. {
  9187. &quot;token&quot;: &quot;defg&quot;,
  9188. &quot;uses_allowed&quot;: 1
  9189. }
  9190. </code></pre>
  9191. <pre><code>200 OK
  9192. {
  9193. &quot;token&quot;: &quot;defg&quot;,
  9194. &quot;uses_allowed&quot;: 1,
  9195. &quot;pending&quot;: 0,
  9196. &quot;completed&quot;: 0,
  9197. &quot;expiry_time&quot;: null
  9198. }
  9199. </code></pre>
  9200. <h2 id="update-token"><a class="header" href="#update-token">Update token</a></h2>
  9201. <p>Update the number of allowed uses or expiry time of a token. If the request is
  9202. successful, the updated token will be returned as a registration token object
  9203. in the response body.</p>
  9204. <pre><code>PUT /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  9205. </code></pre>
  9206. <p>Path parameters:</p>
  9207. <ul>
  9208. <li><code>token</code>: The registration token to update.</li>
  9209. </ul>
  9210. <p>The request body must be a JSON object and can contain the following fields:</p>
  9211. <ul>
  9212. <li><code>uses_allowed</code>: The integer number of times the token can be used to complete
  9213. a registration before it becomes invalid. By setting <code>uses_allowed</code> to <code>0</code>
  9214. the token can be easily made invalid without deleting it.
  9215. If <code>null</code> the token will have an unlimited number of uses.</li>
  9216. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  9217. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  9218. If <code>null</code> the token will not expire.</li>
  9219. </ul>
  9220. <p>If a field is omitted its value is not modified.</p>
  9221. <p>Example:</p>
  9222. <pre><code>PUT /_synapse/admin/v1/registration_tokens/defg
  9223. {
  9224. &quot;expiry_time&quot;: 4781243146000 // 2121-07-06 11:05:46 UTC
  9225. }
  9226. </code></pre>
  9227. <pre><code>200 OK
  9228. {
  9229. &quot;token&quot;: &quot;defg&quot;,
  9230. &quot;uses_allowed&quot;: 1,
  9231. &quot;pending&quot;: 0,
  9232. &quot;completed&quot;: 0,
  9233. &quot;expiry_time&quot;: 4781243146000
  9234. }
  9235. </code></pre>
  9236. <h2 id="delete-token"><a class="header" href="#delete-token">Delete token</a></h2>
  9237. <p>Delete a registration token. If the request is successful, the response body
  9238. will be an empty JSON object.</p>
  9239. <pre><code>DELETE /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  9240. </code></pre>
  9241. <p>Path parameters:</p>
  9242. <ul>
  9243. <li><code>token</code>: The registration token to delete.</li>
  9244. </ul>
  9245. <p>Example:</p>
  9246. <pre><code>DELETE /_synapse/admin/v1/registration_tokens/wxyz
  9247. </code></pre>
  9248. <pre><code>200 OK
  9249. {}
  9250. </code></pre>
  9251. <h2 id="errors"><a class="header" href="#errors">Errors</a></h2>
  9252. <p>If a request fails a &quot;standard error response&quot; will be returned as defined in
  9253. the <a href="https://matrix.org/docs/spec/client_server/r0.6.1#api-standards">Matrix Client-Server API specification</a>.</p>
  9254. <p>For example, if the token specified in a path parameter does not exist a
  9255. <code>404 Not Found</code> error will be returned.</p>
  9256. <pre><code>GET /_synapse/admin/v1/registration_tokens/1234
  9257. </code></pre>
  9258. <pre><code>404 Not Found
  9259. {
  9260. &quot;errcode&quot;: &quot;M_NOT_FOUND&quot;,
  9261. &quot;error&quot;: &quot;No such registration token: 1234&quot;
  9262. }
  9263. </code></pre>
  9264. <div style="break-before: page; page-break-before: always;"></div><h1 id="edit-room-membership-api"><a class="header" href="#edit-room-membership-api">Edit Room Membership API</a></h1>
  9265. <p>This API allows an administrator to join an user account with a given <code>user_id</code>
  9266. to a room with a given <code>room_id_or_alias</code>. You can only modify the membership of
  9267. local users. The server administrator must be in the room and have permission to
  9268. invite users.</p>
  9269. <h2 id="parameters"><a class="header" href="#parameters">Parameters</a></h2>
  9270. <p>The following parameters are available:</p>
  9271. <ul>
  9272. <li><code>user_id</code> - Fully qualified user: for example, <code>@user:server.com</code>.</li>
  9273. <li><code>room_id_or_alias</code> - The room identifier or alias to join: for example,
  9274. <code>!636q39766251:server.com</code>.</li>
  9275. </ul>
  9276. <h2 id="usage-1"><a class="header" href="#usage-1">Usage</a></h2>
  9277. <pre><code>POST /_synapse/admin/v1/join/&lt;room_id_or_alias&gt;
  9278. {
  9279. &quot;user_id&quot;: &quot;@user:server.com&quot;
  9280. }
  9281. </code></pre>
  9282. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9283. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9284. <p>Response:</p>
  9285. <pre><code>{
  9286. &quot;room_id&quot;: &quot;!636q39766251:server.com&quot;
  9287. }
  9288. </code></pre>
  9289. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-2"><a class="header" href="#contents-2">Contents</a></h1>
  9290. <ul>
  9291. <li><a href="admin_api/rooms.html#list-room-api">List Room API</a></li>
  9292. <li><a href="admin_api/rooms.html#room-details-api">Room Details API</a></li>
  9293. <li><a href="admin_api/rooms.html#room-members-api">Room Members API</a></li>
  9294. <li><a href="admin_api/rooms.html#room-state-api">Room State API</a></li>
  9295. <li><a href="admin_api/rooms.html#delete-room-api">Delete Room API</a>
  9296. <ul>
  9297. <li><a href="admin_api/rooms.html#undoing-room-shutdowns">Undoing room shutdowns</a></li>
  9298. </ul>
  9299. </li>
  9300. <li><a href="admin_api/rooms.html#make-room-admin-api">Make Room Admin API</a></li>
  9301. <li><a href="admin_api/rooms.html#forward-extremities-admin-api">Forward Extremities Admin API</a></li>
  9302. <li><a href="admin_api/rooms.html#event-context-api">Event Context API</a></li>
  9303. </ul>
  9304. <h1 id="list-room-api"><a class="header" href="#list-room-api">List Room API</a></h1>
  9305. <p>The List Room admin API allows server admins to get a list of rooms on their
  9306. server. There are various parameters available that allow for filtering and
  9307. sorting the returned list. This API supports pagination.</p>
  9308. <p><strong>Parameters</strong></p>
  9309. <p>The following query parameters are available:</p>
  9310. <ul>
  9311. <li><code>from</code> - Offset in the returned list. Defaults to <code>0</code>.</li>
  9312. <li><code>limit</code> - Maximum amount of rooms to return. Defaults to <code>100</code>.</li>
  9313. <li><code>order_by</code> - The method in which to sort the returned list of rooms. Valid values are:
  9314. <ul>
  9315. <li><code>alphabetical</code> - Same as <code>name</code>. This is deprecated.</li>
  9316. <li><code>size</code> - Same as <code>joined_members</code>. This is deprecated.</li>
  9317. <li><code>name</code> - Rooms are ordered alphabetically by room name. This is the default.</li>
  9318. <li><code>canonical_alias</code> - Rooms are ordered alphabetically by main alias address of the room.</li>
  9319. <li><code>joined_members</code> - Rooms are ordered by the number of members. Largest to smallest.</li>
  9320. <li><code>joined_local_members</code> - Rooms are ordered by the number of local members. Largest to smallest.</li>
  9321. <li><code>version</code> - Rooms are ordered by room version. Largest to smallest.</li>
  9322. <li><code>creator</code> - Rooms are ordered alphabetically by creator of the room.</li>
  9323. <li><code>encryption</code> - Rooms are ordered alphabetically by the end-to-end encryption algorithm.</li>
  9324. <li><code>federatable</code> - Rooms are ordered by whether the room is federatable.</li>
  9325. <li><code>public</code> - Rooms are ordered by visibility in room list.</li>
  9326. <li><code>join_rules</code> - Rooms are ordered alphabetically by join rules of the room.</li>
  9327. <li><code>guest_access</code> - Rooms are ordered alphabetically by guest access option of the room.</li>
  9328. <li><code>history_visibility</code> - Rooms are ordered alphabetically by visibility of history of the room.</li>
  9329. <li><code>state_events</code> - Rooms are ordered by number of state events. Largest to smallest.</li>
  9330. </ul>
  9331. </li>
  9332. <li><code>dir</code> - Direction of room order. Either <code>f</code> for forwards or <code>b</code> for backwards. Setting
  9333. this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  9334. <li><code>search_term</code> - Filter rooms by their room name. Search term can be contained in any
  9335. part of the room name. Defaults to no filtering.</li>
  9336. </ul>
  9337. <p><strong>Response</strong></p>
  9338. <p>The following fields are possible in the JSON response body:</p>
  9339. <ul>
  9340. <li><code>rooms</code> - An array of objects, each containing information about a room.
  9341. <ul>
  9342. <li>Room objects contain the following fields:
  9343. <ul>
  9344. <li><code>room_id</code> - The ID of the room.</li>
  9345. <li><code>name</code> - The name of the room.</li>
  9346. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  9347. <li><code>joined_members</code> - How many users are currently in the room.</li>
  9348. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  9349. <li><code>version</code> - The version of the room as a string.</li>
  9350. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  9351. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  9352. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  9353. <li><code>public</code> - Whether the room is visible in room directory.</li>
  9354. <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>
  9355. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  9356. <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>
  9357. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  9358. </ul>
  9359. </li>
  9360. </ul>
  9361. </li>
  9362. <li><code>offset</code> - The current pagination offset in rooms. This parameter should be
  9363. used instead of <code>next_token</code> for room offset as <code>next_token</code> is
  9364. not intended to be parsed.</li>
  9365. <li><code>total_rooms</code> - The total number of rooms this query can return. Using this
  9366. and <code>offset</code>, you have enough information to know the current
  9367. progression through the list.</li>
  9368. <li><code>next_batch</code> - If this field is present, we know that there are potentially
  9369. more rooms on the server that did not all fit into this response.
  9370. We can use <code>next_batch</code> to get the &quot;next page&quot; of results. To do
  9371. so, simply repeat your request, setting the <code>from</code> parameter to
  9372. the value of <code>next_batch</code>.</li>
  9373. <li><code>prev_batch</code> - If this field is present, it is possible to paginate backwards.
  9374. Use <code>prev_batch</code> for the <code>from</code> value in the next request to
  9375. get the &quot;previous page&quot; of results.</li>
  9376. </ul>
  9377. <p>The API is:</p>
  9378. <p>A standard request with no filtering:</p>
  9379. <pre><code>GET /_synapse/admin/v1/rooms
  9380. </code></pre>
  9381. <p>A response body like the following is returned:</p>
  9382. <pre><code class="language-jsonc">{
  9383. &quot;rooms&quot;: [
  9384. {
  9385. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  9386. &quot;name&quot;: &quot;Matrix HQ&quot;,
  9387. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  9388. &quot;joined_members&quot;: 8326,
  9389. &quot;joined_local_members&quot;: 2,
  9390. &quot;version&quot;: &quot;1&quot;,
  9391. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9392. &quot;encryption&quot;: null,
  9393. &quot;federatable&quot;: true,
  9394. &quot;public&quot;: true,
  9395. &quot;join_rules&quot;: &quot;invite&quot;,
  9396. &quot;guest_access&quot;: null,
  9397. &quot;history_visibility&quot;: &quot;shared&quot;,
  9398. &quot;state_events&quot;: 93534
  9399. },
  9400. ... (8 hidden items) ...
  9401. {
  9402. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9403. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9404. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9405. &quot;joined_members&quot;: 314,
  9406. &quot;joined_local_members&quot;: 20,
  9407. &quot;version&quot;: &quot;4&quot;,
  9408. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9409. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9410. &quot;federatable&quot;: true,
  9411. &quot;public&quot;: false,
  9412. &quot;join_rules&quot;: &quot;invite&quot;,
  9413. &quot;guest_access&quot;: null,
  9414. &quot;history_visibility&quot;: &quot;shared&quot;,
  9415. &quot;state_events&quot;: 8345
  9416. }
  9417. ],
  9418. &quot;offset&quot;: 0,
  9419. &quot;total_rooms&quot;: 10
  9420. }
  9421. </code></pre>
  9422. <p>Filtering by room name:</p>
  9423. <pre><code>GET /_synapse/admin/v1/rooms?search_term=TWIM
  9424. </code></pre>
  9425. <p>A response body like the following is returned:</p>
  9426. <pre><code class="language-json">{
  9427. &quot;rooms&quot;: [
  9428. {
  9429. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9430. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9431. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9432. &quot;joined_members&quot;: 314,
  9433. &quot;joined_local_members&quot;: 20,
  9434. &quot;version&quot;: &quot;4&quot;,
  9435. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9436. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9437. &quot;federatable&quot;: true,
  9438. &quot;public&quot;: false,
  9439. &quot;join_rules&quot;: &quot;invite&quot;,
  9440. &quot;guest_access&quot;: null,
  9441. &quot;history_visibility&quot;: &quot;shared&quot;,
  9442. &quot;state_events&quot;: 8
  9443. }
  9444. ],
  9445. &quot;offset&quot;: 0,
  9446. &quot;total_rooms&quot;: 1
  9447. }
  9448. </code></pre>
  9449. <p>Paginating through a list of rooms:</p>
  9450. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size
  9451. </code></pre>
  9452. <p>A response body like the following is returned:</p>
  9453. <pre><code class="language-jsonc">{
  9454. &quot;rooms&quot;: [
  9455. {
  9456. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  9457. &quot;name&quot;: &quot;Matrix HQ&quot;,
  9458. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  9459. &quot;joined_members&quot;: 8326,
  9460. &quot;joined_local_members&quot;: 2,
  9461. &quot;version&quot;: &quot;1&quot;,
  9462. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9463. &quot;encryption&quot;: null,
  9464. &quot;federatable&quot;: true,
  9465. &quot;public&quot;: true,
  9466. &quot;join_rules&quot;: &quot;invite&quot;,
  9467. &quot;guest_access&quot;: null,
  9468. &quot;history_visibility&quot;: &quot;shared&quot;,
  9469. &quot;state_events&quot;: 93534
  9470. },
  9471. ... (98 hidden items) ...
  9472. {
  9473. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9474. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9475. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9476. &quot;joined_members&quot;: 314,
  9477. &quot;joined_local_members&quot;: 20,
  9478. &quot;version&quot;: &quot;4&quot;,
  9479. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9480. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9481. &quot;federatable&quot;: true,
  9482. &quot;public&quot;: false,
  9483. &quot;join_rules&quot;: &quot;invite&quot;,
  9484. &quot;guest_access&quot;: null,
  9485. &quot;history_visibility&quot;: &quot;shared&quot;,
  9486. &quot;state_events&quot;: 8345
  9487. }
  9488. ],
  9489. &quot;offset&quot;: 0,
  9490. &quot;total_rooms&quot;: 150
  9491. &quot;next_token&quot;: 100
  9492. }
  9493. </code></pre>
  9494. <p>The presence of the <code>next_token</code> parameter tells us that there are more rooms
  9495. than returned in this request, and we need to make another request to get them.
  9496. To get the next batch of room results, we repeat our request, setting the <code>from</code>
  9497. parameter to the value of <code>next_token</code>.</p>
  9498. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size&amp;from=100
  9499. </code></pre>
  9500. <p>A response body like the following is returned:</p>
  9501. <pre><code class="language-jsonc">{
  9502. &quot;rooms&quot;: [
  9503. {
  9504. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  9505. &quot;name&quot;: &quot;Music Theory&quot;,
  9506. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  9507. &quot;joined_members&quot;: 127,
  9508. &quot;joined_local_members&quot;: 2,
  9509. &quot;version&quot;: &quot;1&quot;,
  9510. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9511. &quot;encryption&quot;: null,
  9512. &quot;federatable&quot;: true,
  9513. &quot;public&quot;: true,
  9514. &quot;join_rules&quot;: &quot;invite&quot;,
  9515. &quot;guest_access&quot;: null,
  9516. &quot;history_visibility&quot;: &quot;shared&quot;,
  9517. &quot;state_events&quot;: 93534
  9518. },
  9519. ... (48 hidden items) ...
  9520. {
  9521. &quot;room_id&quot;: &quot;!twcBhHVdZlQWuuxBhN:termina.org.uk&quot;,
  9522. &quot;name&quot;: &quot;weechat-matrix&quot;,
  9523. &quot;canonical_alias&quot;: &quot;#weechat-matrix:termina.org.uk&quot;,
  9524. &quot;joined_members&quot;: 137,
  9525. &quot;joined_local_members&quot;: 20,
  9526. &quot;version&quot;: &quot;4&quot;,
  9527. &quot;creator&quot;: &quot;@foo:termina.org.uk&quot;,
  9528. &quot;encryption&quot;: null,
  9529. &quot;federatable&quot;: true,
  9530. &quot;public&quot;: true,
  9531. &quot;join_rules&quot;: &quot;invite&quot;,
  9532. &quot;guest_access&quot;: null,
  9533. &quot;history_visibility&quot;: &quot;shared&quot;,
  9534. &quot;state_events&quot;: 8345
  9535. }
  9536. ],
  9537. &quot;offset&quot;: 100,
  9538. &quot;prev_batch&quot;: 0,
  9539. &quot;total_rooms&quot;: 150
  9540. }
  9541. </code></pre>
  9542. <p>Once the <code>next_token</code> parameter is no longer present, we know we've reached the
  9543. end of the list.</p>
  9544. <h1 id="room-details-api"><a class="header" href="#room-details-api">Room Details API</a></h1>
  9545. <p>The Room Details admin API allows server admins to get all details of a room.</p>
  9546. <p>The following fields are possible in the JSON response body:</p>
  9547. <ul>
  9548. <li><code>room_id</code> - The ID of the room.</li>
  9549. <li><code>name</code> - The name of the room.</li>
  9550. <li><code>topic</code> - The topic of the room.</li>
  9551. <li><code>avatar</code> - The <code>mxc</code> URI to the avatar of the room.</li>
  9552. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  9553. <li><code>joined_members</code> - How many users are currently in the room.</li>
  9554. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  9555. <li><code>joined_local_devices</code> - How many local devices are currently in the room.</li>
  9556. <li><code>version</code> - The version of the room as a string.</li>
  9557. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  9558. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  9559. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  9560. <li><code>public</code> - Whether the room is visible in room directory.</li>
  9561. <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>
  9562. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  9563. <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>
  9564. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  9565. </ul>
  9566. <p>The API is:</p>
  9567. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9568. </code></pre>
  9569. <p>A response body like the following is returned:</p>
  9570. <pre><code class="language-json">{
  9571. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  9572. &quot;name&quot;: &quot;Music Theory&quot;,
  9573. &quot;avatar&quot;: &quot;mxc://matrix.org/AQDaVFlbkQoErdOgqWRgiGSV&quot;,
  9574. &quot;topic&quot;: &quot;Theory, Composition, Notation, Analysis&quot;,
  9575. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  9576. &quot;joined_members&quot;: 127,
  9577. &quot;joined_local_members&quot;: 2,
  9578. &quot;joined_local_devices&quot;: 2,
  9579. &quot;version&quot;: &quot;1&quot;,
  9580. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9581. &quot;encryption&quot;: null,
  9582. &quot;federatable&quot;: true,
  9583. &quot;public&quot;: true,
  9584. &quot;join_rules&quot;: &quot;invite&quot;,
  9585. &quot;guest_access&quot;: null,
  9586. &quot;history_visibility&quot;: &quot;shared&quot;,
  9587. &quot;state_events&quot;: 93534
  9588. }
  9589. </code></pre>
  9590. <h1 id="room-members-api"><a class="header" href="#room-members-api">Room Members API</a></h1>
  9591. <p>The Room Members admin API allows server admins to get a list of all members of a room.</p>
  9592. <p>The response includes the following fields:</p>
  9593. <ul>
  9594. <li><code>members</code> - A list of all the members that are present in the room, represented by their ids.</li>
  9595. <li><code>total</code> - Total number of members in the room.</li>
  9596. </ul>
  9597. <p>The API is:</p>
  9598. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/members
  9599. </code></pre>
  9600. <p>A response body like the following is returned:</p>
  9601. <pre><code class="language-json">{
  9602. &quot;members&quot;: [
  9603. &quot;@foo:matrix.org&quot;,
  9604. &quot;@bar:matrix.org&quot;,
  9605. &quot;@foobar:matrix.org&quot;
  9606. ],
  9607. &quot;total&quot;: 3
  9608. }
  9609. </code></pre>
  9610. <h1 id="room-state-api"><a class="header" href="#room-state-api">Room State API</a></h1>
  9611. <p>The Room State admin API allows server admins to get a list of all state events in a room.</p>
  9612. <p>The response includes the following fields:</p>
  9613. <ul>
  9614. <li><code>state</code> - The current state of the room at the time of request.</li>
  9615. </ul>
  9616. <p>The API is:</p>
  9617. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/state
  9618. </code></pre>
  9619. <p>A response body like the following is returned:</p>
  9620. <pre><code class="language-json">{
  9621. &quot;state&quot;: [
  9622. {&quot;type&quot;: &quot;m.room.create&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9623. {&quot;type&quot;: &quot;m.room.power_levels&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9624. {&quot;type&quot;: &quot;m.room.name&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true}
  9625. ]
  9626. }
  9627. </code></pre>
  9628. <h1 id="delete-room-api"><a class="header" href="#delete-room-api">Delete Room API</a></h1>
  9629. <p>The Delete Room admin API allows server admins to remove rooms from server
  9630. and block these rooms.</p>
  9631. <p>Shuts down a room. Moves all local users and room aliases automatically to a
  9632. new room if <code>new_room_user_id</code> is set. Otherwise local users only
  9633. leave the room without any information.</p>
  9634. <p>The new room will be created with the user specified by the <code>new_room_user_id</code> parameter
  9635. as room administrator and will contain a message explaining what happened. Users invited
  9636. to the new room will have power level <code>-10</code> by default, and thus be unable to speak.</p>
  9637. <p>If <code>block</code> is <code>True</code> it prevents new joins to the old room.</p>
  9638. <p>This API will remove all trace of the old room from your database after removing
  9639. all local users. If <code>purge</code> is <code>true</code> (the default), all traces of the old room will
  9640. be removed from your database after removing all local users. If you do not want
  9641. this to happen, set <code>purge</code> to <code>false</code>.
  9642. Depending on the amount of history being purged a call to the API may take
  9643. several minutes or longer.</p>
  9644. <p>The local server will only have the power to move local user and room aliases to
  9645. the new room. Users on other servers will be unaffected.</p>
  9646. <p>The API is:</p>
  9647. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9648. </code></pre>
  9649. <p>with a body of:</p>
  9650. <pre><code class="language-json">{
  9651. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  9652. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  9653. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;,
  9654. &quot;block&quot;: true,
  9655. &quot;purge&quot;: true
  9656. }
  9657. </code></pre>
  9658. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9659. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9660. <p>A response body like the following is returned:</p>
  9661. <pre><code class="language-json">{
  9662. &quot;kicked_users&quot;: [
  9663. &quot;@foobar:example.com&quot;
  9664. ],
  9665. &quot;failed_to_kick_users&quot;: [],
  9666. &quot;local_aliases&quot;: [
  9667. &quot;#badroom:example.com&quot;,
  9668. &quot;#evilsaloon:example.com&quot;
  9669. ],
  9670. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;
  9671. }
  9672. </code></pre>
  9673. <p><strong>Parameters</strong></p>
  9674. <p>The following parameters should be set in the URL:</p>
  9675. <ul>
  9676. <li><code>room_id</code> - The ID of the room.</li>
  9677. </ul>
  9678. <p>The following JSON body parameters are available:</p>
  9679. <ul>
  9680. <li><code>new_room_user_id</code> - Optional. If set, a new room will be created with this user ID
  9681. as the creator and admin, and all users in the old room will be moved into that
  9682. room. If not set, no new room will be created and the users will just be removed
  9683. from the old room. The user ID must be on the local server, but does not necessarily
  9684. have to belong to a registered user.</li>
  9685. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  9686. invited to. Defaults to <code>Content Violation Notification</code></li>
  9687. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  9688. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  9689. 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>
  9690. <li><code>block</code> - Optional. If set to <code>true</code>, this room will be added to a blocking list, preventing
  9691. future attempts to join the room. Defaults to <code>false</code>.</li>
  9692. <li><code>purge</code> - Optional. If set to <code>true</code>, it will remove all traces of the room from your database.
  9693. Defaults to <code>true</code>.</li>
  9694. <li><code>force_purge</code> - Optional, and ignored unless <code>purge</code> is <code>true</code>. If set to <code>true</code>, it
  9695. will force a purge to go ahead even if there are local users still in the room. Do not
  9696. use this unless a regular <code>purge</code> operation fails, as it could leave those users'
  9697. clients in a confused state.</li>
  9698. </ul>
  9699. <p>The JSON body must not be empty. The body must be at least <code>{}</code>.</p>
  9700. <p><strong>Response</strong></p>
  9701. <p>The following fields are returned in the JSON response body:</p>
  9702. <ul>
  9703. <li><code>kicked_users</code> - An array of users (<code>user_id</code>) that were kicked.</li>
  9704. <li><code>failed_to_kick_users</code> - An array of users (<code>user_id</code>) that that were not kicked.</li>
  9705. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  9706. the old room to the new.</li>
  9707. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  9708. </ul>
  9709. <h2 id="undoing-room-deletions"><a class="header" href="#undoing-room-deletions">Undoing room deletions</a></h2>
  9710. <p><em>Note</em>: This guide may be outdated by the time you read it. By nature of room deletions being performed at the database level,
  9711. the structure can and does change without notice.</p>
  9712. <p>First, it's important to understand that a room deletion is very destructive. Undoing a deletion is not as simple as pretending it
  9713. 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
  9714. to recover at all:</p>
  9715. <ul>
  9716. <li>If the room was invite-only, your users will need to be re-invited.</li>
  9717. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  9718. <li>The first user to rejoin will have to do so via an alias on a different
  9719. server (or receive an invite from a user on a different server).</li>
  9720. </ul>
  9721. <p>With all that being said, if you still want to try and recover the room:</p>
  9722. <ol>
  9723. <li>
  9724. <p>If the room was <code>block</code>ed, you must unblock it on your server. This can be
  9725. accomplished as follows:</p>
  9726. <ol>
  9727. <li>For safety reasons, shut down Synapse.</li>
  9728. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  9729. <ul>
  9730. <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>
  9731. <li>The room ID is the same one supplied to the delete room API, not the Content Violation room.</li>
  9732. </ul>
  9733. </li>
  9734. <li>Restart Synapse.</li>
  9735. </ol>
  9736. <p>This step is unnecessary if <code>block</code> was not set.</p>
  9737. </li>
  9738. <li>
  9739. <p>Any room aliases on your server that pointed to the deleted room may have
  9740. been deleted, or redirected to the Content Violation room. These will need
  9741. to be restored manually.</p>
  9742. </li>
  9743. <li>
  9744. <p>Users on your server that were in the deleted room will have been kicked
  9745. from the room. Consider whether you want to update their membership
  9746. (possibly via the <a href="admin_api/room_membership.html">Edit Room Membership API</a>) or let
  9747. them handle rejoining themselves.</p>
  9748. </li>
  9749. <li>
  9750. <p>If <code>new_room_user_id</code> was given, a 'Content Violation' will have been
  9751. created. Consider whether you want to delete that roomm.</p>
  9752. </li>
  9753. </ol>
  9754. <h2 id="deprecated-endpoint"><a class="header" href="#deprecated-endpoint">Deprecated endpoint</a></h2>
  9755. <p>The previous deprecated API will be removed in a future release, it was:</p>
  9756. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id&gt;/delete
  9757. </code></pre>
  9758. <p>It behaves the same way than the current endpoint except the path and the method.</p>
  9759. <h1 id="make-room-admin-api"><a class="header" href="#make-room-admin-api">Make Room Admin API</a></h1>
  9760. <p>Grants another user the highest power available to a local user who is in the room.
  9761. If the user is not in the room, and it is not publicly joinable, then invite the user.</p>
  9762. <p>By default the server admin (the caller) is granted power, but another user can
  9763. optionally be specified, e.g.:</p>
  9764. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/make_room_admin
  9765. {
  9766. &quot;user_id&quot;: &quot;@foo:example.com&quot;
  9767. }
  9768. </code></pre>
  9769. <h1 id="forward-extremities-admin-api"><a class="header" href="#forward-extremities-admin-api">Forward Extremities Admin API</a></h1>
  9770. <p>Enables querying and deleting forward extremities from rooms. When a lot of forward
  9771. extremities accumulate in a room, performance can become degraded. For details, see
  9772. <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.</p>
  9773. <h2 id="check-for-forward-extremities"><a class="header" href="#check-for-forward-extremities">Check for forward extremities</a></h2>
  9774. <p>To check the status of forward extremities for a room:</p>
  9775. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9776. </code></pre>
  9777. <p>A response as follows will be returned:</p>
  9778. <pre><code class="language-json">{
  9779. &quot;count&quot;: 1,
  9780. &quot;results&quot;: [
  9781. {
  9782. &quot;event_id&quot;: &quot;$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdefgh&quot;,
  9783. &quot;state_group&quot;: 439,
  9784. &quot;depth&quot;: 123,
  9785. &quot;received_ts&quot;: 1611263016761
  9786. }
  9787. ]
  9788. }
  9789. </code></pre>
  9790. <h2 id="deleting-forward-extremities"><a class="header" href="#deleting-forward-extremities">Deleting forward extremities</a></h2>
  9791. <p><strong>WARNING</strong>: Please ensure you know what you're doing and have read
  9792. the related issue <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.
  9793. Under no situations should this API be executed as an automated maintenance task!</p>
  9794. <p>If a room has lots of forward extremities, the extra can be
  9795. deleted as follows:</p>
  9796. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9797. </code></pre>
  9798. <p>A response as follows will be returned, indicating the amount of forward extremities
  9799. that were deleted.</p>
  9800. <pre><code class="language-json">{
  9801. &quot;deleted&quot;: 1
  9802. }
  9803. </code></pre>
  9804. <h1 id="event-context-api"><a class="header" href="#event-context-api">Event Context API</a></h1>
  9805. <p>This API lets a client find the context of an event. This is designed primarily to investigate abuse reports.</p>
  9806. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/context/&lt;event_id&gt;
  9807. </code></pre>
  9808. <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>
  9809. <p>Example response:</p>
  9810. <pre><code class="language-json">{
  9811. &quot;end&quot;: &quot;t29-57_2_0_2&quot;,
  9812. &quot;events_after&quot;: [
  9813. {
  9814. &quot;content&quot;: {
  9815. &quot;body&quot;: &quot;This is an example text message&quot;,
  9816. &quot;msgtype&quot;: &quot;m.text&quot;,
  9817. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  9818. &quot;formatted_body&quot;: &quot;&lt;b&gt;This is an example text message&lt;/b&gt;&quot;
  9819. },
  9820. &quot;type&quot;: &quot;m.room.message&quot;,
  9821. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9822. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9823. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9824. &quot;origin_server_ts&quot;: 1432735824653,
  9825. &quot;unsigned&quot;: {
  9826. &quot;age&quot;: 1234
  9827. }
  9828. }
  9829. ],
  9830. &quot;event&quot;: {
  9831. &quot;content&quot;: {
  9832. &quot;body&quot;: &quot;filename.jpg&quot;,
  9833. &quot;info&quot;: {
  9834. &quot;h&quot;: 398,
  9835. &quot;w&quot;: 394,
  9836. &quot;mimetype&quot;: &quot;image/jpeg&quot;,
  9837. &quot;size&quot;: 31037
  9838. },
  9839. &quot;url&quot;: &quot;mxc://example.org/JWEIFJgwEIhweiWJE&quot;,
  9840. &quot;msgtype&quot;: &quot;m.image&quot;
  9841. },
  9842. &quot;type&quot;: &quot;m.room.message&quot;,
  9843. &quot;event_id&quot;: &quot;$f3h4d129462ha:example.com&quot;,
  9844. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9845. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9846. &quot;origin_server_ts&quot;: 1432735824653,
  9847. &quot;unsigned&quot;: {
  9848. &quot;age&quot;: 1234
  9849. }
  9850. },
  9851. &quot;events_before&quot;: [
  9852. {
  9853. &quot;content&quot;: {
  9854. &quot;body&quot;: &quot;something-important.doc&quot;,
  9855. &quot;filename&quot;: &quot;something-important.doc&quot;,
  9856. &quot;info&quot;: {
  9857. &quot;mimetype&quot;: &quot;application/msword&quot;,
  9858. &quot;size&quot;: 46144
  9859. },
  9860. &quot;msgtype&quot;: &quot;m.file&quot;,
  9861. &quot;url&quot;: &quot;mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe&quot;
  9862. },
  9863. &quot;type&quot;: &quot;m.room.message&quot;,
  9864. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9865. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9866. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9867. &quot;origin_server_ts&quot;: 1432735824653,
  9868. &quot;unsigned&quot;: {
  9869. &quot;age&quot;: 1234
  9870. }
  9871. }
  9872. ],
  9873. &quot;start&quot;: &quot;t27-54_2_0_2&quot;,
  9874. &quot;state&quot;: [
  9875. {
  9876. &quot;content&quot;: {
  9877. &quot;creator&quot;: &quot;@example:example.org&quot;,
  9878. &quot;room_version&quot;: &quot;1&quot;,
  9879. &quot;m.federate&quot;: true,
  9880. &quot;predecessor&quot;: {
  9881. &quot;event_id&quot;: &quot;$something:example.org&quot;,
  9882. &quot;room_id&quot;: &quot;!oldroom:example.org&quot;
  9883. }
  9884. },
  9885. &quot;type&quot;: &quot;m.room.create&quot;,
  9886. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9887. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9888. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9889. &quot;origin_server_ts&quot;: 1432735824653,
  9890. &quot;unsigned&quot;: {
  9891. &quot;age&quot;: 1234
  9892. },
  9893. &quot;state_key&quot;: &quot;&quot;
  9894. },
  9895. {
  9896. &quot;content&quot;: {
  9897. &quot;membership&quot;: &quot;join&quot;,
  9898. &quot;avatar_url&quot;: &quot;mxc://example.org/SEsfnsuifSDFSSEF&quot;,
  9899. &quot;displayname&quot;: &quot;Alice Margatroid&quot;
  9900. },
  9901. &quot;type&quot;: &quot;m.room.member&quot;,
  9902. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9903. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9904. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9905. &quot;origin_server_ts&quot;: 1432735824653,
  9906. &quot;unsigned&quot;: {
  9907. &quot;age&quot;: 1234
  9908. },
  9909. &quot;state_key&quot;: &quot;@alice:example.org&quot;
  9910. }
  9911. ]
  9912. }
  9913. </code></pre>
  9914. <div style="break-before: page; page-break-before: always;"></div><h1 id="server-notices-1"><a class="header" href="#server-notices-1">Server Notices</a></h1>
  9915. <p>The API to send notices is as follows:</p>
  9916. <pre><code>POST /_synapse/admin/v1/send_server_notice
  9917. </code></pre>
  9918. <p>or:</p>
  9919. <pre><code>PUT /_synapse/admin/v1/send_server_notice/{txnId}
  9920. </code></pre>
  9921. <p>You will need to authenticate with an access token for an admin user.</p>
  9922. <p>When using the <code>PUT</code> form, retransmissions with the same transaction ID will be
  9923. ignored in the same way as with <code>PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}</code>.</p>
  9924. <p>The request body should look something like the following:</p>
  9925. <pre><code class="language-json">{
  9926. &quot;user_id&quot;: &quot;@target_user:server_name&quot;,
  9927. &quot;content&quot;: {
  9928. &quot;msgtype&quot;: &quot;m.text&quot;,
  9929. &quot;body&quot;: &quot;This is my message&quot;
  9930. }
  9931. }
  9932. </code></pre>
  9933. <p>You can optionally include the following additional parameters:</p>
  9934. <ul>
  9935. <li><code>type</code>: the type of event. Defaults to <code>m.room.message</code>.</li>
  9936. <li><code>state_key</code>: Setting this will result in a state event being sent.</li>
  9937. </ul>
  9938. <p>Once the notice has been sent, the API will return the following response:</p>
  9939. <pre><code class="language-json">{
  9940. &quot;event_id&quot;: &quot;&lt;event_id&gt;&quot;
  9941. }
  9942. </code></pre>
  9943. <p>Note that server notices must be enabled in <code>homeserver.yaml</code> before this API
  9944. can be used. See <a href="admin_api/../server_notices.html">the server notices documentation</a> for more information.</p>
  9945. <div style="break-before: page; page-break-before: always;"></div><h1 id="users-media-usage-statistics"><a class="header" href="#users-media-usage-statistics">Users' media usage statistics</a></h1>
  9946. <p>Returns information about all local media usage of users. Gives the
  9947. possibility to filter them by time and user.</p>
  9948. <p>The API is:</p>
  9949. <pre><code>GET /_synapse/admin/v1/statistics/users/media
  9950. </code></pre>
  9951. <p>To use it, you will need to authenticate by providing an <code>access_token</code>
  9952. for a server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9953. <p>A response body like the following is returned:</p>
  9954. <pre><code class="language-json">{
  9955. &quot;users&quot;: [
  9956. {
  9957. &quot;displayname&quot;: &quot;foo_user_0&quot;,
  9958. &quot;media_count&quot;: 2,
  9959. &quot;media_length&quot;: 134,
  9960. &quot;user_id&quot;: &quot;@foo_user_0:test&quot;
  9961. },
  9962. {
  9963. &quot;displayname&quot;: &quot;foo_user_1&quot;,
  9964. &quot;media_count&quot;: 2,
  9965. &quot;media_length&quot;: 134,
  9966. &quot;user_id&quot;: &quot;@foo_user_1:test&quot;
  9967. }
  9968. ],
  9969. &quot;next_token&quot;: 3,
  9970. &quot;total&quot;: 10
  9971. }
  9972. </code></pre>
  9973. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint
  9974. again with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9975. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9976. reports to paginate through.</p>
  9977. <p><strong>Parameters</strong></p>
  9978. <p>The following parameters should be set in the URL:</p>
  9979. <ul>
  9980. <li><code>limit</code>: string representing a positive integer - Is optional but is
  9981. used for pagination, denoting the maximum number of items to return
  9982. in this call. Defaults to <code>100</code>.</li>
  9983. <li><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9984. denoting the offset in the returned results. This should be treated as an opaque value
  9985. and not explicitly set to anything other than the return value of <code>next_token</code> from a
  9986. previous call. Defaults to <code>0</code>.</li>
  9987. <li><code>order_by</code> - string - The method in which to sort the returned list of users. Valid values are:
  9988. <ul>
  9989. <li><code>user_id</code> - Users are ordered alphabetically by <code>user_id</code>. This is the default.</li>
  9990. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9991. <li><code>media_length</code> - Users are ordered by the total size of uploaded media in bytes.
  9992. Smallest to largest.</li>
  9993. <li><code>media_count</code> - Users are ordered by number of uploaded media. Smallest to largest.</li>
  9994. </ul>
  9995. </li>
  9996. <li><code>from_ts</code> - string representing a positive integer - Considers only
  9997. files created at this timestamp or later. Unix timestamp in ms.</li>
  9998. <li><code>until_ts</code> - string representing a positive integer - Considers only
  9999. files created at this timestamp or earlier. Unix timestamp in ms.</li>
  10000. <li><code>search_term</code> - string - Filter users by their user ID localpart <strong>or</strong> displayname.
  10001. The search term can be found in any part of the string.
  10002. Defaults to no filtering.</li>
  10003. <li><code>dir</code> - string - Direction of order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  10004. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  10005. </ul>
  10006. <p><strong>Response</strong></p>
  10007. <p>The following fields are returned in the JSON response body:</p>
  10008. <ul>
  10009. <li><code>users</code> - An array of objects, each containing information
  10010. about the user and their local media. Objects contain the following fields:
  10011. <ul>
  10012. <li><code>displayname</code> - string - Displayname of this user.</li>
  10013. <li><code>media_count</code> - integer - Number of uploaded media by this user.</li>
  10014. <li><code>media_length</code> - integer - Size of uploaded media in bytes by this user.</li>
  10015. <li><code>user_id</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  10016. </ul>
  10017. </li>
  10018. <li><code>next_token</code> - integer - Opaque value used for pagination. See above.</li>
  10019. <li><code>total</code> - integer - Total number of users after filtering.</li>
  10020. </ul>
  10021. <div style="break-before: page; page-break-before: always;"></div><h1 id="user-admin-api"><a class="header" href="#user-admin-api">User Admin API</a></h1>
  10022. <h2 id="query-user-account"><a class="header" href="#query-user-account">Query User Account</a></h2>
  10023. <p>This API returns information about a specific user account.</p>
  10024. <p>The api is:</p>
  10025. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;
  10026. </code></pre>
  10027. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10028. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10029. <p>It returns a JSON body like the following:</p>
  10030. <pre><code class="language-json">{
  10031. &quot;displayname&quot;: &quot;User&quot;,
  10032. &quot;threepids&quot;: [
  10033. {
  10034. &quot;medium&quot;: &quot;email&quot;,
  10035. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;,
  10036. &quot;added_at&quot;: 1586458409743,
  10037. &quot;validated_at&quot;: 1586458409743
  10038. },
  10039. {
  10040. &quot;medium&quot;: &quot;email&quot;,
  10041. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;,
  10042. &quot;added_at&quot;: 1586458409743,
  10043. &quot;validated_at&quot;: 1586458409743
  10044. }
  10045. ],
  10046. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  10047. &quot;admin&quot;: 0,
  10048. &quot;deactivated&quot;: 0,
  10049. &quot;shadow_banned&quot;: 0,
  10050. &quot;password_hash&quot;: &quot;$2b$12$p9B4GkqYdRTPGD&quot;,
  10051. &quot;creation_ts&quot;: 1560432506,
  10052. &quot;appservice_id&quot;: null,
  10053. &quot;consent_server_notice_sent&quot;: null,
  10054. &quot;consent_version&quot;: null,
  10055. &quot;external_ids&quot;: [
  10056. {
  10057. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  10058. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  10059. },
  10060. {
  10061. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  10062. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  10063. }
  10064. ],
  10065. &quot;user_type&quot;: null
  10066. }
  10067. </code></pre>
  10068. <p>URL parameters:</p>
  10069. <ul>
  10070. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  10071. </ul>
  10072. <h2 id="create-or-modify-account"><a class="header" href="#create-or-modify-account">Create or modify Account</a></h2>
  10073. <p>This API allows an administrator to create or modify a user account with a
  10074. specific <code>user_id</code>.</p>
  10075. <p>This api is:</p>
  10076. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;
  10077. </code></pre>
  10078. <p>with a body of:</p>
  10079. <pre><code class="language-json">{
  10080. &quot;password&quot;: &quot;user_password&quot;,
  10081. &quot;displayname&quot;: &quot;User&quot;,
  10082. &quot;threepids&quot;: [
  10083. {
  10084. &quot;medium&quot;: &quot;email&quot;,
  10085. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  10086. },
  10087. {
  10088. &quot;medium&quot;: &quot;email&quot;,
  10089. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  10090. }
  10091. ],
  10092. &quot;external_ids&quot;: [
  10093. {
  10094. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  10095. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  10096. },
  10097. {
  10098. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  10099. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  10100. }
  10101. ],
  10102. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  10103. &quot;admin&quot;: false,
  10104. &quot;deactivated&quot;: false,
  10105. &quot;user_type&quot;: null
  10106. }
  10107. </code></pre>
  10108. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10109. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10110. <p>Returns HTTP status code:</p>
  10111. <ul>
  10112. <li><code>201</code> - When a new user object was created.</li>
  10113. <li><code>200</code> - When a user was modified.</li>
  10114. </ul>
  10115. <p>URL parameters:</p>
  10116. <ul>
  10117. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  10118. </ul>
  10119. <p>Body parameters:</p>
  10120. <ul>
  10121. <li><code>password</code> - string, optional. If provided, the user's password is updated and all
  10122. devices are logged out.</li>
  10123. <li><code>displayname</code> - string, optional, defaults to the value of <code>user_id</code>.</li>
  10124. <li><code>threepids</code> - array, optional, allows setting the third-party IDs (email, msisdn)
  10125. <ul>
  10126. <li><code>medium</code> - string. Kind of third-party ID, either <code>email</code> or <code>msisdn</code>.</li>
  10127. <li><code>address</code> - string. Value of third-party ID.
  10128. belonging to a user.</li>
  10129. </ul>
  10130. </li>
  10131. <li><code>external_ids</code> - array, optional. Allow setting the identifier of the external identity
  10132. provider for SSO (Single sign-on). Details in
  10133. <a href="admin_api/../usage/configuration/homeserver_sample_config.html">Sample Configuration File</a>
  10134. section <code>sso</code> and <code>oidc_providers</code>.
  10135. <ul>
  10136. <li><code>auth_provider</code> - string. ID of the external identity provider. Value of <code>idp_id</code>
  10137. in homeserver configuration.</li>
  10138. <li><code>external_id</code> - string, user ID in the external identity provider.</li>
  10139. </ul>
  10140. </li>
  10141. <li><code>avatar_url</code> - string, optional, must be a
  10142. <a href="https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris">MXC URI</a>.</li>
  10143. <li><code>admin</code> - bool, optional, defaults to <code>false</code>.</li>
  10144. <li><code>deactivated</code> - bool, optional. If unspecified, deactivation state will be left
  10145. unchanged on existing accounts and set to <code>false</code> for new accounts.
  10146. A user cannot be erased by deactivating with this API. For details on
  10147. deactivating users see <a href="admin_api/user_admin_api.html#deactivate-account">Deactivate Account</a>.</li>
  10148. <li><code>user_type</code> - string or null, optional. If provided, the user type will be
  10149. adjusted. If <code>null</code> given, the user type will be cleared. Other
  10150. allowed options are: <code>bot</code> and <code>support</code>.</li>
  10151. </ul>
  10152. <p>If the user already exists then optional parameters default to the current value.</p>
  10153. <p>In order to re-activate an account <code>deactivated</code> must be set to <code>false</code>. If
  10154. users do not login via single-sign-on, a new <code>password</code> must be provided.</p>
  10155. <h2 id="list-accounts"><a class="header" href="#list-accounts">List Accounts</a></h2>
  10156. <p>This API returns all local user accounts.
  10157. By default, the response is ordered by ascending user ID.</p>
  10158. <pre><code>GET /_synapse/admin/v2/users?from=0&amp;limit=10&amp;guests=false
  10159. </code></pre>
  10160. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10161. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10162. <p>A response body like the following is returned:</p>
  10163. <pre><code class="language-json">{
  10164. &quot;users&quot;: [
  10165. {
  10166. &quot;name&quot;: &quot;&lt;user_id1&gt;&quot;,
  10167. &quot;is_guest&quot;: 0,
  10168. &quot;admin&quot;: 0,
  10169. &quot;user_type&quot;: null,
  10170. &quot;deactivated&quot;: 0,
  10171. &quot;shadow_banned&quot;: 0,
  10172. &quot;displayname&quot;: &quot;&lt;User One&gt;&quot;,
  10173. &quot;avatar_url&quot;: null,
  10174. &quot;creation_ts&quot;: 1560432668000
  10175. }, {
  10176. &quot;name&quot;: &quot;&lt;user_id2&gt;&quot;,
  10177. &quot;is_guest&quot;: 0,
  10178. &quot;admin&quot;: 1,
  10179. &quot;user_type&quot;: null,
  10180. &quot;deactivated&quot;: 0,
  10181. &quot;shadow_banned&quot;: 0,
  10182. &quot;displayname&quot;: &quot;&lt;User Two&gt;&quot;,
  10183. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  10184. &quot;creation_ts&quot;: 1561550621000
  10185. }
  10186. ],
  10187. &quot;next_token&quot;: &quot;100&quot;,
  10188. &quot;total&quot;: 200
  10189. }
  10190. </code></pre>
  10191. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  10192. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  10193. <p>If the endpoint does not return a <code>next_token</code> then there are no more users
  10194. to paginate through.</p>
  10195. <p><strong>Parameters</strong></p>
  10196. <p>The following parameters should be set in the URL:</p>
  10197. <ul>
  10198. <li>
  10199. <p><code>user_id</code> - Is optional and filters to only return users with user IDs
  10200. that contain this value. This parameter is ignored when using the <code>name</code> parameter.</p>
  10201. </li>
  10202. <li>
  10203. <p><code>name</code> - Is optional and filters to only return users with user ID localparts
  10204. <strong>or</strong> displaynames that contain this value.</p>
  10205. </li>
  10206. <li>
  10207. <p><code>guests</code> - string representing a bool - Is optional and if <code>false</code> will <strong>exclude</strong> guest users.
  10208. Defaults to <code>true</code> to include guest users.</p>
  10209. </li>
  10210. <li>
  10211. <p><code>deactivated</code> - string representing a bool - Is optional and if <code>true</code> will <strong>include</strong> deactivated users.
  10212. Defaults to <code>false</code> to exclude deactivated users.</p>
  10213. </li>
  10214. <li>
  10215. <p><code>limit</code> - string representing a positive integer - Is optional but is used for pagination,
  10216. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  10217. </li>
  10218. <li>
  10219. <p><code>from</code> - string representing a positive integer - Is optional but used for pagination,
  10220. denoting the offset in the returned results. This should be treated as an opaque value and
  10221. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  10222. Defaults to <code>0</code>.</p>
  10223. </li>
  10224. <li>
  10225. <p><code>order_by</code> - The method by which to sort the returned list of users.
  10226. If the ordered field has duplicates, the second order is always by ascending <code>name</code>,
  10227. which guarantees a stable ordering. Valid values are:</p>
  10228. <ul>
  10229. <li><code>name</code> - Users are ordered alphabetically by <code>name</code>. This is the default.</li>
  10230. <li><code>is_guest</code> - Users are ordered by <code>is_guest</code> status.</li>
  10231. <li><code>admin</code> - Users are ordered by <code>admin</code> status.</li>
  10232. <li><code>user_type</code> - Users are ordered alphabetically by <code>user_type</code>.</li>
  10233. <li><code>deactivated</code> - Users are ordered by <code>deactivated</code> status.</li>
  10234. <li><code>shadow_banned</code> - Users are ordered by <code>shadow_banned</code> status.</li>
  10235. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  10236. <li><code>avatar_url</code> - Users are ordered alphabetically by avatar URL.</li>
  10237. <li><code>creation_ts</code> - Users are ordered by when the users was created in ms.</li>
  10238. </ul>
  10239. </li>
  10240. <li>
  10241. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  10242. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  10243. </li>
  10244. </ul>
  10245. <p>Caution. The database only has indexes on the columns <code>name</code> and <code>creation_ts</code>.
  10246. This means that if a different sort order is used (<code>is_guest</code>, <code>admin</code>,
  10247. <code>user_type</code>, <code>deactivated</code>, <code>shadow_banned</code>, <code>avatar_url</code> or <code>displayname</code>),
  10248. this can cause a large load on the database, especially for large environments.</p>
  10249. <p><strong>Response</strong></p>
  10250. <p>The following fields are returned in the JSON response body:</p>
  10251. <ul>
  10252. <li>
  10253. <p><code>users</code> - An array of objects, each containing information about an user.
  10254. User objects contain the following fields:</p>
  10255. <ul>
  10256. <li><code>name</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  10257. <li><code>is_guest</code> - bool - Status if that user is a guest account.</li>
  10258. <li><code>admin</code> - bool - Status if that user is a server administrator.</li>
  10259. <li><code>user_type</code> - string - Type of the user. Normal users are type <code>None</code>.
  10260. This allows user type specific behaviour. There are also types <code>support</code> and <code>bot</code>. </li>
  10261. <li><code>deactivated</code> - bool - Status if that user has been marked as deactivated.</li>
  10262. <li><code>shadow_banned</code> - bool - Status if that user has been marked as shadow banned.</li>
  10263. <li><code>displayname</code> - string - The user's display name if they have set one.</li>
  10264. <li><code>avatar_url</code> - string - The user's avatar URL if they have set one.</li>
  10265. <li><code>creation_ts</code> - integer - The user's creation timestamp in ms.</li>
  10266. </ul>
  10267. </li>
  10268. <li>
  10269. <p><code>next_token</code>: string representing a positive integer - Indication for pagination. See above.</p>
  10270. </li>
  10271. <li>
  10272. <p><code>total</code> - integer - Total number of media.</p>
  10273. </li>
  10274. </ul>
  10275. <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>
  10276. <p>This API returns information about the active sessions for a specific user.</p>
  10277. <p>The endpoints are:</p>
  10278. <pre><code>GET /_synapse/admin/v1/whois/&lt;user_id&gt;
  10279. </code></pre>
  10280. <p>and:</p>
  10281. <pre><code>GET /_matrix/client/r0/admin/whois/&lt;userId&gt;
  10282. </code></pre>
  10283. <p>See also: <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid">Client Server
  10284. API Whois</a>.</p>
  10285. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10286. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10287. <p>It returns a JSON body like the following:</p>
  10288. <pre><code class="language-json">{
  10289. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;,
  10290. &quot;devices&quot;: {
  10291. &quot;&quot;: {
  10292. &quot;sessions&quot;: [
  10293. {
  10294. &quot;connections&quot;: [
  10295. {
  10296. &quot;ip&quot;: &quot;1.2.3.4&quot;,
  10297. &quot;last_seen&quot;: 1417222374433,
  10298. &quot;user_agent&quot;: &quot;Mozilla/5.0 ...&quot;
  10299. },
  10300. {
  10301. &quot;ip&quot;: &quot;1.2.3.10&quot;,
  10302. &quot;last_seen&quot;: 1417222374500,
  10303. &quot;user_agent&quot;: &quot;Dalvik/2.1.0 ...&quot;
  10304. }
  10305. ]
  10306. }
  10307. ]
  10308. }
  10309. }
  10310. }
  10311. </code></pre>
  10312. <p><code>last_seen</code> is measured in milliseconds since the Unix epoch.</p>
  10313. <h2 id="deactivate-account"><a class="header" href="#deactivate-account">Deactivate Account</a></h2>
  10314. <p>This API deactivates an account. It removes active access tokens, resets the
  10315. password, and deletes third-party IDs (to prevent the user requesting a
  10316. password reset).</p>
  10317. <p>It can also mark the user as GDPR-erased. This means messages sent by the
  10318. user will still be visible by anyone that was in the room when these messages
  10319. were sent, but hidden from users joining the room afterwards.</p>
  10320. <p>The api is:</p>
  10321. <pre><code>POST /_synapse/admin/v1/deactivate/&lt;user_id&gt;
  10322. </code></pre>
  10323. <p>with a body of:</p>
  10324. <pre><code class="language-json">{
  10325. &quot;erase&quot;: true
  10326. }
  10327. </code></pre>
  10328. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10329. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10330. <p>The erase parameter is optional and defaults to <code>false</code>.
  10331. An empty body may be passed for backwards compatibility.</p>
  10332. <p>The following actions are performed when deactivating an user:</p>
  10333. <ul>
  10334. <li>Try to unpind 3PIDs from the identity server</li>
  10335. <li>Remove all 3PIDs from the homeserver</li>
  10336. <li>Delete all devices and E2EE keys</li>
  10337. <li>Delete all access tokens</li>
  10338. <li>Delete all pushers</li>
  10339. <li>Delete the password hash</li>
  10340. <li>Removal from all rooms the user is a member of</li>
  10341. <li>Remove the user from the user directory</li>
  10342. <li>Reject all pending invites</li>
  10343. <li>Remove all account validity information related to the user</li>
  10344. </ul>
  10345. <p>The following additional actions are performed during deactivation if <code>erase</code>
  10346. is set to <code>true</code>:</p>
  10347. <ul>
  10348. <li>Remove the user's display name</li>
  10349. <li>Remove the user's avatar URL</li>
  10350. <li>Mark the user as erased</li>
  10351. </ul>
  10352. <p>The following actions are <strong>NOT</strong> performed. The list may be incomplete.</p>
  10353. <ul>
  10354. <li>Remove mappings of SSO IDs</li>
  10355. <li><a href="admin_api/user_admin_api.html#delete-media-uploaded-by-a-user">Delete media uploaded</a> by user (included avatar images)</li>
  10356. <li>Delete sent and received messages</li>
  10357. <li>Delete E2E cross-signing keys</li>
  10358. <li>Remove the user's creation (registration) timestamp</li>
  10359. <li><a href="admin_api/user_admin_api.html#override-ratelimiting-for-users">Remove rate limit overrides</a></li>
  10360. <li>Remove from monthly active users</li>
  10361. </ul>
  10362. <h2 id="reset-password"><a class="header" href="#reset-password">Reset password</a></h2>
  10363. <p>Changes the password of another user. This will automatically log the user out of all their devices.</p>
  10364. <p>The api is:</p>
  10365. <pre><code>POST /_synapse/admin/v1/reset_password/&lt;user_id&gt;
  10366. </code></pre>
  10367. <p>with a body of:</p>
  10368. <pre><code class="language-json">{
  10369. &quot;new_password&quot;: &quot;&lt;secret&gt;&quot;,
  10370. &quot;logout_devices&quot;: true
  10371. }
  10372. </code></pre>
  10373. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10374. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10375. <p>The parameter <code>new_password</code> is required.
  10376. The parameter <code>logout_devices</code> is optional and defaults to <code>true</code>.</p>
  10377. <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>
  10378. <p>The api is:</p>
  10379. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  10380. </code></pre>
  10381. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10382. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10383. <p>A response body like the following is returned:</p>
  10384. <pre><code class="language-json">{
  10385. &quot;admin&quot;: true
  10386. }
  10387. </code></pre>
  10388. <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>
  10389. <p>Note that you cannot demote yourself.</p>
  10390. <p>The api is:</p>
  10391. <pre><code>PUT /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  10392. </code></pre>
  10393. <p>with a body of:</p>
  10394. <pre><code class="language-json">{
  10395. &quot;admin&quot;: true
  10396. }
  10397. </code></pre>
  10398. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10399. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10400. <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>
  10401. <p>Gets a list of all <code>room_id</code> that a specific <code>user_id</code> is member.</p>
  10402. <p>The API is:</p>
  10403. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/joined_rooms
  10404. </code></pre>
  10405. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10406. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10407. <p>A response body like the following is returned:</p>
  10408. <pre><code class="language-json"> {
  10409. &quot;joined_rooms&quot;: [
  10410. &quot;!DuGcnbhHGaSZQoNQR:matrix.org&quot;,
  10411. &quot;!ZtSaPCawyWtxfWiIy:matrix.org&quot;
  10412. ],
  10413. &quot;total&quot;: 2
  10414. }
  10415. </code></pre>
  10416. <p>The server returns the list of rooms of which the user and the server
  10417. are member. If the user is local, all the rooms of which the user is
  10418. member are returned.</p>
  10419. <p><strong>Parameters</strong></p>
  10420. <p>The following parameters should be set in the URL:</p>
  10421. <ul>
  10422. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10423. </ul>
  10424. <p><strong>Response</strong></p>
  10425. <p>The following fields are returned in the JSON response body:</p>
  10426. <ul>
  10427. <li><code>joined_rooms</code> - An array of <code>room_id</code>.</li>
  10428. <li><code>total</code> - Number of rooms.</li>
  10429. </ul>
  10430. <h2 id="user-media"><a class="header" href="#user-media">User media</a></h2>
  10431. <h3 id="list-media-uploaded-by-a-user"><a class="header" href="#list-media-uploaded-by-a-user">List media uploaded by a user</a></h3>
  10432. <p>Gets a list of all local media that a specific <code>user_id</code> has created.
  10433. By default, the response is ordered by descending creation date and ascending media ID.
  10434. The newest media is on top. You can change the order with parameters
  10435. <code>order_by</code> and <code>dir</code>.</p>
  10436. <p>The API is:</p>
  10437. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/media
  10438. </code></pre>
  10439. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10440. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10441. <p>A response body like the following is returned:</p>
  10442. <pre><code class="language-json">{
  10443. &quot;media&quot;: [
  10444. {
  10445. &quot;created_ts&quot;: 100400,
  10446. &quot;last_access_ts&quot;: null,
  10447. &quot;media_id&quot;: &quot;qXhyRzulkwLsNHTbpHreuEgo&quot;,
  10448. &quot;media_length&quot;: 67,
  10449. &quot;media_type&quot;: &quot;image/png&quot;,
  10450. &quot;quarantined_by&quot;: null,
  10451. &quot;safe_from_quarantine&quot;: false,
  10452. &quot;upload_name&quot;: &quot;test1.png&quot;
  10453. },
  10454. {
  10455. &quot;created_ts&quot;: 200400,
  10456. &quot;last_access_ts&quot;: null,
  10457. &quot;media_id&quot;: &quot;FHfiSnzoINDatrXHQIXBtahw&quot;,
  10458. &quot;media_length&quot;: 67,
  10459. &quot;media_type&quot;: &quot;image/png&quot;,
  10460. &quot;quarantined_by&quot;: null,
  10461. &quot;safe_from_quarantine&quot;: false,
  10462. &quot;upload_name&quot;: &quot;test2.png&quot;
  10463. }
  10464. ],
  10465. &quot;next_token&quot;: 3,
  10466. &quot;total&quot;: 2
  10467. }
  10468. </code></pre>
  10469. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  10470. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  10471. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  10472. reports to paginate through.</p>
  10473. <p><strong>Parameters</strong></p>
  10474. <p>The following parameters should be set in the URL:</p>
  10475. <ul>
  10476. <li>
  10477. <p><code>user_id</code> - string - fully qualified: for example, <code>@user:server.com</code>.</p>
  10478. </li>
  10479. <li>
  10480. <p><code>limit</code>: string representing a positive integer - Is optional but is used for pagination,
  10481. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  10482. </li>
  10483. <li>
  10484. <p><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  10485. denoting the offset in the returned results. This should be treated as an opaque value and
  10486. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  10487. Defaults to <code>0</code>.</p>
  10488. </li>
  10489. <li>
  10490. <p><code>order_by</code> - The method by which to sort the returned list of media.
  10491. If the ordered field has duplicates, the second order is always by ascending <code>media_id</code>,
  10492. which guarantees a stable ordering. Valid values are:</p>
  10493. <ul>
  10494. <li><code>media_id</code> - Media are ordered alphabetically by <code>media_id</code>.</li>
  10495. <li><code>upload_name</code> - Media are ordered alphabetically by name the media was uploaded with.</li>
  10496. <li><code>created_ts</code> - Media are ordered by when the content was uploaded in ms.
  10497. Smallest to largest. This is the default.</li>
  10498. <li><code>last_access_ts</code> - Media are ordered by when the content was last accessed in ms.
  10499. Smallest to largest.</li>
  10500. <li><code>media_length</code> - Media are ordered by length of the media in bytes.
  10501. Smallest to largest.</li>
  10502. <li><code>media_type</code> - Media are ordered alphabetically by MIME-type.</li>
  10503. <li><code>quarantined_by</code> - Media are ordered alphabetically by the user ID that
  10504. initiated the quarantine request for this media.</li>
  10505. <li><code>safe_from_quarantine</code> - Media are ordered by the status if this media is safe
  10506. from quarantining.</li>
  10507. </ul>
  10508. </li>
  10509. <li>
  10510. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  10511. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  10512. </li>
  10513. </ul>
  10514. <p>If neither <code>order_by</code> nor <code>dir</code> is set, the default order is newest media on top
  10515. (corresponds to <code>order_by</code> = <code>created_ts</code> and <code>dir</code> = <code>b</code>).</p>
  10516. <p>Caution. The database only has indexes on the columns <code>media_id</code>,
  10517. <code>user_id</code> and <code>created_ts</code>. This means that if a different sort order is used
  10518. (<code>upload_name</code>, <code>last_access_ts</code>, <code>media_length</code>, <code>media_type</code>,
  10519. <code>quarantined_by</code> or <code>safe_from_quarantine</code>), this can cause a large load on the
  10520. database, especially for large environments.</p>
  10521. <p><strong>Response</strong></p>
  10522. <p>The following fields are returned in the JSON response body:</p>
  10523. <ul>
  10524. <li><code>media</code> - An array of objects, each containing information about a media.
  10525. Media objects contain the following fields:
  10526. <ul>
  10527. <li><code>created_ts</code> - integer - Timestamp when the content was uploaded in ms.</li>
  10528. <li><code>last_access_ts</code> - integer - Timestamp when the content was last accessed in ms.</li>
  10529. <li><code>media_id</code> - string - The id used to refer to the media.</li>
  10530. <li><code>media_length</code> - integer - Length of the media in bytes.</li>
  10531. <li><code>media_type</code> - string - The MIME-type of the media.</li>
  10532. <li><code>quarantined_by</code> - string - The user ID that initiated the quarantine request
  10533. for this media.</li>
  10534. <li><code>safe_from_quarantine</code> - bool - Status if this media is safe from quarantining.</li>
  10535. <li><code>upload_name</code> - string - The name the media was uploaded with.</li>
  10536. </ul>
  10537. </li>
  10538. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  10539. <li><code>total</code> - integer - Total number of media.</li>
  10540. </ul>
  10541. <h3 id="delete-media-uploaded-by-a-user-1"><a class="header" href="#delete-media-uploaded-by-a-user-1">Delete media uploaded by a user</a></h3>
  10542. <p>This API deletes the <em>local</em> media from the disk of your own server
  10543. that a specific <code>user_id</code> has created. This includes any local thumbnails.</p>
  10544. <p>This API will not affect media that has been uploaded to external
  10545. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).</p>
  10546. <p>By default, the API deletes media ordered by descending creation date and ascending media ID.
  10547. The newest media is deleted first. You can change the order with parameters
  10548. <code>order_by</code> and <code>dir</code>. If no <code>limit</code> is set the API deletes <code>100</code> files per request.</p>
  10549. <p>The API is:</p>
  10550. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/media
  10551. </code></pre>
  10552. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10553. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10554. <p>A response body like the following is returned:</p>
  10555. <pre><code class="language-json">{
  10556. &quot;deleted_media&quot;: [
  10557. &quot;abcdefghijklmnopqrstuvwx&quot;
  10558. ],
  10559. &quot;total&quot;: 1
  10560. }
  10561. </code></pre>
  10562. <p>The following fields are returned in the JSON response body:</p>
  10563. <ul>
  10564. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  10565. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  10566. </ul>
  10567. <p><strong>Note</strong>: There is no <code>next_token</code>. This is not useful for deleting media, because
  10568. after deleting media the remaining media have a new order.</p>
  10569. <p><strong>Parameters</strong></p>
  10570. <p>This API has the same parameters as
  10571. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>.
  10572. With the parameters you can for example limit the number of files to delete at once or
  10573. delete largest/smallest or newest/oldest files first.</p>
  10574. <h2 id="login-as-a-user"><a class="header" href="#login-as-a-user">Login as a user</a></h2>
  10575. <p>Get an access token that can be used to authenticate as that user. Useful for
  10576. when admins wish to do actions on behalf of a user.</p>
  10577. <p>The API is:</p>
  10578. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/login
  10579. {}
  10580. </code></pre>
  10581. <p>An optional <code>valid_until_ms</code> field can be specified in the request body as an
  10582. integer timestamp that specifies when the token should expire. By default tokens
  10583. do not expire.</p>
  10584. <p>A response body like the following is returned:</p>
  10585. <pre><code class="language-json">{
  10586. &quot;access_token&quot;: &quot;&lt;opaque_access_token_string&gt;&quot;
  10587. }
  10588. </code></pre>
  10589. <p>This API does <em>not</em> generate a new device for the user, and so will not appear
  10590. their <code>/devices</code> list, and in general the target user should not be able to
  10591. tell they have been logged in as.</p>
  10592. <p>To expire the token call the standard <code>/logout</code> API with the token.</p>
  10593. <p>Note: The token will expire if the <em>admin</em> user calls <code>/logout/all</code> from any
  10594. of their devices, but the token will <em>not</em> expire if the target user does the
  10595. same.</p>
  10596. <h2 id="user-devices"><a class="header" href="#user-devices">User devices</a></h2>
  10597. <h3 id="list-all-devices"><a class="header" href="#list-all-devices">List all devices</a></h3>
  10598. <p>Gets information about all devices for a specific <code>user_id</code>.</p>
  10599. <p>The API is:</p>
  10600. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices
  10601. </code></pre>
  10602. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10603. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10604. <p>A response body like the following is returned:</p>
  10605. <pre><code class="language-json">{
  10606. &quot;devices&quot;: [
  10607. {
  10608. &quot;device_id&quot;: &quot;QBUAZIFURK&quot;,
  10609. &quot;display_name&quot;: &quot;android&quot;,
  10610. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10611. &quot;last_seen_ts&quot;: 1474491775024,
  10612. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10613. },
  10614. {
  10615. &quot;device_id&quot;: &quot;AUIECTSRND&quot;,
  10616. &quot;display_name&quot;: &quot;ios&quot;,
  10617. &quot;last_seen_ip&quot;: &quot;1.2.3.5&quot;,
  10618. &quot;last_seen_ts&quot;: 1474491775025,
  10619. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10620. }
  10621. ],
  10622. &quot;total&quot;: 2
  10623. }
  10624. </code></pre>
  10625. <p><strong>Parameters</strong></p>
  10626. <p>The following parameters should be set in the URL:</p>
  10627. <ul>
  10628. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10629. </ul>
  10630. <p><strong>Response</strong></p>
  10631. <p>The following fields are returned in the JSON response body:</p>
  10632. <ul>
  10633. <li>
  10634. <p><code>devices</code> - An array of objects, each containing information about a device.
  10635. Device objects contain the following fields:</p>
  10636. <ul>
  10637. <li><code>device_id</code> - Identifier of device.</li>
  10638. <li><code>display_name</code> - Display name set by the user for this device.
  10639. Absent if no name has been set.</li>
  10640. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10641. (May be a few minutes out of date, for efficiency reasons).</li>
  10642. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10643. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10644. <li><code>user_id</code> - Owner of device.</li>
  10645. </ul>
  10646. </li>
  10647. <li>
  10648. <p><code>total</code> - Total number of user's devices.</p>
  10649. </li>
  10650. </ul>
  10651. <h3 id="delete-multiple-devices"><a class="header" href="#delete-multiple-devices">Delete multiple devices</a></h3>
  10652. <p>Deletes the given devices for a specific <code>user_id</code>, and invalidates
  10653. any access token associated with them.</p>
  10654. <p>The API is:</p>
  10655. <pre><code>POST /_synapse/admin/v2/users/&lt;user_id&gt;/delete_devices
  10656. {
  10657. &quot;devices&quot;: [
  10658. &quot;QBUAZIFURK&quot;,
  10659. &quot;AUIECTSRND&quot;
  10660. ],
  10661. }
  10662. </code></pre>
  10663. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10664. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10665. <p>An empty JSON dict is returned.</p>
  10666. <p><strong>Parameters</strong></p>
  10667. <p>The following parameters should be set in the URL:</p>
  10668. <ul>
  10669. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10670. </ul>
  10671. <p>The following fields are required in the JSON request body:</p>
  10672. <ul>
  10673. <li><code>devices</code> - The list of device IDs to delete.</li>
  10674. </ul>
  10675. <h3 id="show-a-device"><a class="header" href="#show-a-device">Show a device</a></h3>
  10676. <p>Gets information on a single device, by <code>device_id</code> for a specific <code>user_id</code>.</p>
  10677. <p>The API is:</p>
  10678. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10679. </code></pre>
  10680. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10681. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10682. <p>A response body like the following is returned:</p>
  10683. <pre><code class="language-json">{
  10684. &quot;device_id&quot;: &quot;&lt;device_id&gt;&quot;,
  10685. &quot;display_name&quot;: &quot;android&quot;,
  10686. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10687. &quot;last_seen_ts&quot;: 1474491775024,
  10688. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10689. }
  10690. </code></pre>
  10691. <p><strong>Parameters</strong></p>
  10692. <p>The following parameters should be set in the URL:</p>
  10693. <ul>
  10694. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10695. <li><code>device_id</code> - The device to retrieve.</li>
  10696. </ul>
  10697. <p><strong>Response</strong></p>
  10698. <p>The following fields are returned in the JSON response body:</p>
  10699. <ul>
  10700. <li><code>device_id</code> - Identifier of device.</li>
  10701. <li><code>display_name</code> - Display name set by the user for this device.
  10702. Absent if no name has been set.</li>
  10703. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10704. (May be a few minutes out of date, for efficiency reasons).</li>
  10705. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10706. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10707. <li><code>user_id</code> - Owner of device.</li>
  10708. </ul>
  10709. <h3 id="update-a-device"><a class="header" href="#update-a-device">Update a device</a></h3>
  10710. <p>Updates the metadata on the given <code>device_id</code> for a specific <code>user_id</code>.</p>
  10711. <p>The API is:</p>
  10712. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10713. {
  10714. &quot;display_name&quot;: &quot;My other phone&quot;
  10715. }
  10716. </code></pre>
  10717. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10718. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10719. <p>An empty JSON dict is returned.</p>
  10720. <p><strong>Parameters</strong></p>
  10721. <p>The following parameters should be set in the URL:</p>
  10722. <ul>
  10723. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10724. <li><code>device_id</code> - The device to update.</li>
  10725. </ul>
  10726. <p>The following fields are required in the JSON request body:</p>
  10727. <ul>
  10728. <li><code>display_name</code> - The new display name for this device. If not given,
  10729. the display name is unchanged.</li>
  10730. </ul>
  10731. <h3 id="delete-a-device"><a class="header" href="#delete-a-device">Delete a device</a></h3>
  10732. <p>Deletes the given <code>device_id</code> for a specific <code>user_id</code>,
  10733. and invalidates any access token associated with it.</p>
  10734. <p>The API is:</p>
  10735. <pre><code>DELETE /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10736. {}
  10737. </code></pre>
  10738. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10739. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10740. <p>An empty JSON dict is returned.</p>
  10741. <p><strong>Parameters</strong></p>
  10742. <p>The following parameters should be set in the URL:</p>
  10743. <ul>
  10744. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10745. <li><code>device_id</code> - The device to delete.</li>
  10746. </ul>
  10747. <h2 id="list-all-pushers"><a class="header" href="#list-all-pushers">List all pushers</a></h2>
  10748. <p>Gets information about all pushers for a specific <code>user_id</code>.</p>
  10749. <p>The API is:</p>
  10750. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/pushers
  10751. </code></pre>
  10752. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10753. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10754. <p>A response body like the following is returned:</p>
  10755. <pre><code class="language-json">{
  10756. &quot;pushers&quot;: [
  10757. {
  10758. &quot;app_display_name&quot;:&quot;HTTP Push Notifications&quot;,
  10759. &quot;app_id&quot;:&quot;m.http&quot;,
  10760. &quot;data&quot;: {
  10761. &quot;url&quot;:&quot;example.com&quot;
  10762. },
  10763. &quot;device_display_name&quot;:&quot;pushy push&quot;,
  10764. &quot;kind&quot;:&quot;http&quot;,
  10765. &quot;lang&quot;:&quot;None&quot;,
  10766. &quot;profile_tag&quot;:&quot;&quot;,
  10767. &quot;pushkey&quot;:&quot;a@example.com&quot;
  10768. }
  10769. ],
  10770. &quot;total&quot;: 1
  10771. }
  10772. </code></pre>
  10773. <p><strong>Parameters</strong></p>
  10774. <p>The following parameters should be set in the URL:</p>
  10775. <ul>
  10776. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10777. </ul>
  10778. <p><strong>Response</strong></p>
  10779. <p>The following fields are returned in the JSON response body:</p>
  10780. <ul>
  10781. <li>
  10782. <p><code>pushers</code> - An array containing the current pushers for the user</p>
  10783. <ul>
  10784. <li>
  10785. <p><code>app_display_name</code> - string - A string that will allow the user to identify
  10786. what application owns this pusher.</p>
  10787. </li>
  10788. <li>
  10789. <p><code>app_id</code> - string - This is a reverse-DNS style identifier for the application.
  10790. Max length, 64 chars.</p>
  10791. </li>
  10792. <li>
  10793. <p><code>data</code> - A dictionary of information for the pusher implementation itself.</p>
  10794. <ul>
  10795. <li>
  10796. <p><code>url</code> - string - Required if <code>kind</code> is <code>http</code>. The URL to use to send
  10797. notifications to.</p>
  10798. </li>
  10799. <li>
  10800. <p><code>format</code> - string - The format to use when sending notifications to the
  10801. Push Gateway.</p>
  10802. </li>
  10803. </ul>
  10804. </li>
  10805. <li>
  10806. <p><code>device_display_name</code> - string - A string that will allow the user to identify
  10807. what device owns this pusher.</p>
  10808. </li>
  10809. <li>
  10810. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10811. this pusher executes.</p>
  10812. </li>
  10813. <li>
  10814. <p><code>kind</code> - string - The kind of pusher. &quot;http&quot; is a pusher that sends HTTP pokes.</p>
  10815. </li>
  10816. <li>
  10817. <p><code>lang</code> - string - The preferred language for receiving notifications
  10818. (e.g. 'en' or 'en-US')</p>
  10819. </li>
  10820. <li>
  10821. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10822. this pusher executes.</p>
  10823. </li>
  10824. <li>
  10825. <p><code>pushkey</code> - string - This is a unique identifier for this pusher.
  10826. Max length, 512 bytes.</p>
  10827. </li>
  10828. </ul>
  10829. </li>
  10830. <li>
  10831. <p><code>total</code> - integer - Number of pushers.</p>
  10832. </li>
  10833. </ul>
  10834. <p>See also the
  10835. <a href="https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers">Client-Server API Spec on pushers</a>.</p>
  10836. <h2 id="shadow-banning-users"><a class="header" href="#shadow-banning-users">Shadow-banning users</a></h2>
  10837. <p>Shadow-banning is a useful tool for moderating malicious or egregiously abusive users.
  10838. A shadow-banned users receives successful responses to their client-server API requests,
  10839. but the events are not propagated into rooms. This can be an effective tool as it
  10840. (hopefully) takes longer for the user to realise they are being moderated before
  10841. pivoting to another account.</p>
  10842. <p>Shadow-banning a user should be used as a tool of last resort and may lead to confusing
  10843. or broken behaviour for the client. A shadow-banned user will not receive any
  10844. notification and it is generally more appropriate to ban or kick abusive users.
  10845. A shadow-banned user will be unable to contact anyone on the server.</p>
  10846. <p>The API is:</p>
  10847. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/shadow_ban
  10848. </code></pre>
  10849. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10850. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10851. <p>An empty JSON dict is returned.</p>
  10852. <p><strong>Parameters</strong></p>
  10853. <p>The following parameters should be set in the URL:</p>
  10854. <ul>
  10855. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10856. be local.</li>
  10857. </ul>
  10858. <h2 id="override-ratelimiting-for-users"><a class="header" href="#override-ratelimiting-for-users">Override ratelimiting for users</a></h2>
  10859. <p>This API allows to override or disable ratelimiting for a specific user.
  10860. There are specific APIs to set, get and delete a ratelimit.</p>
  10861. <h3 id="get-status-of-ratelimit"><a class="header" href="#get-status-of-ratelimit">Get status of ratelimit</a></h3>
  10862. <p>The API is:</p>
  10863. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10864. </code></pre>
  10865. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10866. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10867. <p>A response body like the following is returned:</p>
  10868. <pre><code class="language-json">{
  10869. &quot;messages_per_second&quot;: 0,
  10870. &quot;burst_count&quot;: 0
  10871. }
  10872. </code></pre>
  10873. <p><strong>Parameters</strong></p>
  10874. <p>The following parameters should be set in the URL:</p>
  10875. <ul>
  10876. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10877. be local.</li>
  10878. </ul>
  10879. <p><strong>Response</strong></p>
  10880. <p>The following fields are returned in the JSON response body:</p>
  10881. <ul>
  10882. <li><code>messages_per_second</code> - integer - The number of actions that can
  10883. be performed in a second. <code>0</code> mean that ratelimiting is disabled for this user.</li>
  10884. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10885. being limited.</li>
  10886. </ul>
  10887. <p>If <strong>no</strong> custom ratelimit is set, an empty JSON dict is returned.</p>
  10888. <pre><code class="language-json">{}
  10889. </code></pre>
  10890. <h3 id="set-ratelimit"><a class="header" href="#set-ratelimit">Set ratelimit</a></h3>
  10891. <p>The API is:</p>
  10892. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10893. </code></pre>
  10894. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10895. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10896. <p>A response body like the following is returned:</p>
  10897. <pre><code class="language-json">{
  10898. &quot;messages_per_second&quot;: 0,
  10899. &quot;burst_count&quot;: 0
  10900. }
  10901. </code></pre>
  10902. <p><strong>Parameters</strong></p>
  10903. <p>The following parameters should be set in the URL:</p>
  10904. <ul>
  10905. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10906. be local.</li>
  10907. </ul>
  10908. <p>Body parameters:</p>
  10909. <ul>
  10910. <li><code>messages_per_second</code> - positive integer, optional. The number of actions that can
  10911. be performed in a second. Defaults to <code>0</code>.</li>
  10912. <li><code>burst_count</code> - positive integer, optional. How many actions that can be performed
  10913. before being limited. Defaults to <code>0</code>.</li>
  10914. </ul>
  10915. <p>To disable users' ratelimit set both values to <code>0</code>.</p>
  10916. <p><strong>Response</strong></p>
  10917. <p>The following fields are returned in the JSON response body:</p>
  10918. <ul>
  10919. <li><code>messages_per_second</code> - integer - The number of actions that can
  10920. be performed in a second.</li>
  10921. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10922. being limited.</li>
  10923. </ul>
  10924. <h3 id="delete-ratelimit"><a class="header" href="#delete-ratelimit">Delete ratelimit</a></h3>
  10925. <p>The API is:</p>
  10926. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10927. </code></pre>
  10928. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10929. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10930. <p>An empty JSON dict is returned.</p>
  10931. <pre><code class="language-json">{}
  10932. </code></pre>
  10933. <p><strong>Parameters</strong></p>
  10934. <p>The following parameters should be set in the URL:</p>
  10935. <ul>
  10936. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10937. be local.</li>
  10938. </ul>
  10939. <h3 id="check-username-availability"><a class="header" href="#check-username-availability">Check username availability</a></h3>
  10940. <p>Checks to see if a username is available, and valid, for the server. See <a href="https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available">the client-server
  10941. API</a>
  10942. for more information.</p>
  10943. <p>This endpoint will work even if registration is disabled on the server, unlike
  10944. <code>/_matrix/client/r0/register/available</code>.</p>
  10945. <p>The API is:</p>
  10946. <pre><code>POST /_synapse/admin/v1/username_availabile?username=$localpart
  10947. </code></pre>
  10948. <p>The request and response format is the same as the <a href="https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-register-available">/_matrix/client/r0/register/available</a> API.</p>
  10949. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10950. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10951. <div style="break-before: page; page-break-before: always;"></div><h1 id="version-api"><a class="header" href="#version-api">Version API</a></h1>
  10952. <p>This API returns the running Synapse version and the Python version
  10953. on which Synapse is being run. This is useful when a Synapse instance
  10954. is behind a proxy that does not forward the 'Server' header (which also
  10955. contains Synapse version information).</p>
  10956. <p>The api is:</p>
  10957. <pre><code>GET /_synapse/admin/v1/server_version
  10958. </code></pre>
  10959. <p>It returns a JSON body like the following:</p>
  10960. <pre><code class="language-json">{
  10961. &quot;server_version&quot;: &quot;0.99.2rc1 (b=develop, abcdef123)&quot;,
  10962. &quot;python_version&quot;: &quot;3.6.8&quot;
  10963. }
  10964. </code></pre>
  10965. <div style="break-before: page; page-break-before: always;"></div><h1 id="using-the-synapse-manhole"><a class="header" href="#using-the-synapse-manhole">Using the synapse manhole</a></h1>
  10966. <p>The &quot;manhole&quot; allows server administrators to access a Python shell on a running
  10967. Synapse installation. This is a very powerful mechanism for administration and
  10968. debugging.</p>
  10969. <p><strong><em>Security Warning</em></strong></p>
  10970. <p>Note that this will give administrative access to synapse to <strong>all users</strong> with
  10971. shell access to the server. It should therefore <strong>not</strong> be enabled in
  10972. environments where untrusted users have shell access.</p>
  10973. <h2 id="configuring-the-manhole"><a class="header" href="#configuring-the-manhole">Configuring the manhole</a></h2>
  10974. <p>To enable it, first uncomment the <code>manhole</code> listener configuration in
  10975. <code>homeserver.yaml</code>. The configuration is slightly different if you're using docker.</p>
  10976. <h4 id="docker-config"><a class="header" href="#docker-config">Docker config</a></h4>
  10977. <p>If you are using Docker, set <code>bind_addresses</code> to <code>['0.0.0.0']</code> as shown:</p>
  10978. <pre><code class="language-yaml">listeners:
  10979. - port: 9000
  10980. bind_addresses: ['0.0.0.0']
  10981. type: manhole
  10982. </code></pre>
  10983. <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
  10984. <code>manhole</code> port forwarding. The <code>-p 127.0.0.1:9000:9000</code> below is important: it
  10985. ensures that access to the <code>manhole</code> is only possible for local users.</p>
  10986. <pre><code class="language-bash">docker run -d --name synapse \
  10987. --mount type=volume,src=synapse-data,dst=/data \
  10988. -p 8008:8008 \
  10989. -p 127.0.0.1:9000:9000 \
  10990. matrixdotorg/synapse:latest
  10991. </code></pre>
  10992. <h4 id="native-config"><a class="header" href="#native-config">Native config</a></h4>
  10993. <p>If you are not using docker, set <code>bind_addresses</code> to <code>['::1', '127.0.0.1']</code> as shown.
  10994. The <code>bind_addresses</code> in the example below is important: it ensures that access to the
  10995. <code>manhole</code> is only possible for local users).</p>
  10996. <pre><code class="language-yaml">listeners:
  10997. - port: 9000
  10998. bind_addresses: ['::1', '127.0.0.1']
  10999. type: manhole
  11000. </code></pre>
  11001. <h3 id="security-settings"><a class="header" href="#security-settings">Security settings</a></h3>
  11002. <p>The following config options are available:</p>
  11003. <ul>
  11004. <li><code>username</code> - The username for the manhole (defaults to <code>matrix</code>)</li>
  11005. <li><code>password</code> - The password for the manhole (defaults to <code>rabbithole</code>)</li>
  11006. <li><code>ssh_priv_key</code> - The path to a private SSH key (defaults to a hardcoded value)</li>
  11007. <li><code>ssh_pub_key</code> - The path to a public SSH key (defaults to a hardcoded value)</li>
  11008. </ul>
  11009. <p>For example:</p>
  11010. <pre><code class="language-yaml">manhole_settings:
  11011. username: manhole
  11012. password: mypassword
  11013. ssh_priv_key: &quot;/home/synapse/manhole_keys/id_rsa&quot;
  11014. ssh_pub_key: &quot;/home/synapse/manhole_keys/id_rsa.pub&quot;
  11015. </code></pre>
  11016. <h2 id="accessing-synapse-manhole"><a class="header" href="#accessing-synapse-manhole">Accessing synapse manhole</a></h2>
  11017. <p>Then restart synapse, and point an ssh client at port 9000 on localhost, using
  11018. the username and password configured in <code>homeserver.yaml</code> - with the default
  11019. configuration, this would be:</p>
  11020. <pre><code class="language-bash">ssh -p9000 matrix@localhost
  11021. </code></pre>
  11022. <p>Then enter the password when prompted (the default is <code>rabbithole</code>).</p>
  11023. <p>This gives a Python REPL in which <code>hs</code> gives access to the
  11024. <code>synapse.server.HomeServer</code> object - which in turn gives access to many other
  11025. parts of the process.</p>
  11026. <p>Note that, prior to Synapse 1.41, any call which returns a coroutine will need to be wrapped in <code>ensureDeferred</code>.</p>
  11027. <p>As a simple example, retrieving an event from the database:</p>
  11028. <pre><code class="language-pycon">&gt;&gt;&gt; from twisted.internet import defer
  11029. &gt;&gt;&gt; defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
  11030. &lt;Deferred at 0x7ff253fc6998 current result: &lt;FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''&gt;&gt;
  11031. </code></pre>
  11032. <div style="break-before: page; page-break-before: always;"></div><h1 id="how-to-monitor-synapse-metrics-using-prometheus"><a class="header" href="#how-to-monitor-synapse-metrics-using-prometheus">How to monitor Synapse metrics using Prometheus</a></h1>
  11033. <ol>
  11034. <li>
  11035. <p>Install Prometheus:</p>
  11036. <p>Follow instructions at
  11037. <a href="http://prometheus.io/docs/introduction/install/">http://prometheus.io/docs/introduction/install/</a></p>
  11038. </li>
  11039. <li>
  11040. <p>Enable Synapse metrics:</p>
  11041. <p>There are two methods of enabling metrics in Synapse.</p>
  11042. <p>The first serves the metrics as a part of the usual web server and
  11043. can be enabled by adding the &quot;metrics&quot; resource to the existing
  11044. listener as such:</p>
  11045. <pre><code class="language-yaml"> resources:
  11046. - names:
  11047. - client
  11048. - metrics
  11049. </code></pre>
  11050. <p>This provides a simple way of adding metrics to your Synapse
  11051. installation, and serves under <code>/_synapse/metrics</code>. If you do not
  11052. wish your metrics be publicly exposed, you will need to either
  11053. filter it out at your load balancer, or use the second method.</p>
  11054. <p>The second method runs the metrics server on a different port, in a
  11055. different thread to Synapse. This can make it more resilient to
  11056. heavy load meaning metrics cannot be retrieved, and can be exposed
  11057. to just internal networks easier. The served metrics are available
  11058. over HTTP only, and will be available at <code>/_synapse/metrics</code>.</p>
  11059. <p>Add a new listener to homeserver.yaml:</p>
  11060. <pre><code class="language-yaml"> listeners:
  11061. - type: metrics
  11062. port: 9000
  11063. bind_addresses:
  11064. - '0.0.0.0'
  11065. </code></pre>
  11066. <p>For both options, you will need to ensure that <code>enable_metrics</code> is
  11067. set to <code>True</code>.</p>
  11068. </li>
  11069. <li>
  11070. <p>Restart Synapse.</p>
  11071. </li>
  11072. <li>
  11073. <p>Add a Prometheus target for Synapse.</p>
  11074. <p>It needs to set the <code>metrics_path</code> to a non-default value (under
  11075. <code>scrape_configs</code>):</p>
  11076. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  11077. scrape_interval: 15s
  11078. metrics_path: &quot;/_synapse/metrics&quot;
  11079. static_configs:
  11080. - targets: [&quot;my.server.here:port&quot;]
  11081. </code></pre>
  11082. <p>where <code>my.server.here</code> is the IP address of Synapse, and <code>port</code> is
  11083. the listener port configured with the <code>metrics</code> resource.</p>
  11084. <p>If your prometheus is older than 1.5.2, you will need to replace
  11085. <code>static_configs</code> in the above with <code>target_groups</code>.</p>
  11086. </li>
  11087. <li>
  11088. <p>Restart Prometheus.</p>
  11089. </li>
  11090. <li>
  11091. <p>Consider using the <a href="https://github.com/matrix-org/synapse/tree/master/contrib/grafana/">grafana dashboard</a>
  11092. and required <a href="https://github.com/matrix-org/synapse/tree/master/contrib/prometheus/">recording rules</a> </p>
  11093. </li>
  11094. </ol>
  11095. <h2 id="monitoring-workers"><a class="header" href="#monitoring-workers">Monitoring workers</a></h2>
  11096. <p>To monitor a Synapse installation using <a href="workers.html">workers</a>,
  11097. every worker needs to be monitored independently, in addition to
  11098. the main homeserver process. This is because workers don't send
  11099. their metrics to the main homeserver process, but expose them
  11100. directly (if they are configured to do so).</p>
  11101. <p>To allow collecting metrics from a worker, you need to add a
  11102. <code>metrics</code> listener to its configuration, by adding the following
  11103. under <code>worker_listeners</code>:</p>
  11104. <pre><code class="language-yaml"> - type: metrics
  11105. bind_address: ''
  11106. port: 9101
  11107. </code></pre>
  11108. <p>The <code>bind_address</code> and <code>port</code> parameters should be set so that
  11109. the resulting listener can be reached by prometheus, and they
  11110. don't clash with an existing worker.
  11111. With this example, the worker's metrics would then be available
  11112. on <code>http://127.0.0.1:9101</code>.</p>
  11113. <p>Example Prometheus target for Synapse with workers:</p>
  11114. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  11115. scrape_interval: 15s
  11116. metrics_path: &quot;/_synapse/metrics&quot;
  11117. static_configs:
  11118. - targets: [&quot;my.server.here:port&quot;]
  11119. labels:
  11120. instance: &quot;my.server&quot;
  11121. job: &quot;master&quot;
  11122. index: 1
  11123. - targets: [&quot;my.workerserver.here:port&quot;]
  11124. labels:
  11125. instance: &quot;my.server&quot;
  11126. job: &quot;generic_worker&quot;
  11127. index: 1
  11128. - targets: [&quot;my.workerserver.here:port&quot;]
  11129. labels:
  11130. instance: &quot;my.server&quot;
  11131. job: &quot;generic_worker&quot;
  11132. index: 2
  11133. - targets: [&quot;my.workerserver.here:port&quot;]
  11134. labels:
  11135. instance: &quot;my.server&quot;
  11136. job: &quot;media_repository&quot;
  11137. index: 1
  11138. </code></pre>
  11139. <p>Labels (<code>instance</code>, <code>job</code>, <code>index</code>) can be defined as anything.
  11140. The labels are used to group graphs in grafana.</p>
  11141. <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>
  11142. <p>Synapse 1.2 updates the Prometheus metrics to match the naming
  11143. convention of the upstream <code>prometheus_client</code>. The old names are
  11144. considered deprecated and will be removed in a future version of
  11145. Synapse.</p>
  11146. <table><thead><tr><th>New Name</th><th>Old Name</th></tr></thead><tbody>
  11147. <tr><td>python_gc_objects_collected_total</td><td>python_gc_objects_collected</td></tr>
  11148. <tr><td>python_gc_objects_uncollectable_total</td><td>python_gc_objects_uncollectable</td></tr>
  11149. <tr><td>python_gc_collections_total</td><td>python_gc_collections</td></tr>
  11150. <tr><td>process_cpu_seconds_total</td><td>process_cpu_seconds</td></tr>
  11151. <tr><td>synapse_federation_client_sent_transactions_total</td><td>synapse_federation_client_sent_transactions</td></tr>
  11152. <tr><td>synapse_federation_client_events_processed_total</td><td>synapse_federation_client_events_processed</td></tr>
  11153. <tr><td>synapse_event_processing_loop_count_total</td><td>synapse_event_processing_loop_count</td></tr>
  11154. <tr><td>synapse_event_processing_loop_room_count_total</td><td>synapse_event_processing_loop_room_count</td></tr>
  11155. <tr><td>synapse_util_metrics_block_count_total</td><td>synapse_util_metrics_block_count</td></tr>
  11156. <tr><td>synapse_util_metrics_block_time_seconds_total</td><td>synapse_util_metrics_block_time_seconds</td></tr>
  11157. <tr><td>synapse_util_metrics_block_ru_utime_seconds_total</td><td>synapse_util_metrics_block_ru_utime_seconds</td></tr>
  11158. <tr><td>synapse_util_metrics_block_ru_stime_seconds_total</td><td>synapse_util_metrics_block_ru_stime_seconds</td></tr>
  11159. <tr><td>synapse_util_metrics_block_db_txn_count_total</td><td>synapse_util_metrics_block_db_txn_count</td></tr>
  11160. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds_total</td><td>synapse_util_metrics_block_db_txn_duration_seconds</td></tr>
  11161. <tr><td>synapse_util_metrics_block_db_sched_duration_seconds_total</td><td>synapse_util_metrics_block_db_sched_duration_seconds</td></tr>
  11162. <tr><td>synapse_background_process_start_count_total</td><td>synapse_background_process_start_count</td></tr>
  11163. <tr><td>synapse_background_process_ru_utime_seconds_total</td><td>synapse_background_process_ru_utime_seconds</td></tr>
  11164. <tr><td>synapse_background_process_ru_stime_seconds_total</td><td>synapse_background_process_ru_stime_seconds</td></tr>
  11165. <tr><td>synapse_background_process_db_txn_count_total</td><td>synapse_background_process_db_txn_count</td></tr>
  11166. <tr><td>synapse_background_process_db_txn_duration_seconds_total</td><td>synapse_background_process_db_txn_duration_seconds</td></tr>
  11167. <tr><td>synapse_background_process_db_sched_duration_seconds_total</td><td>synapse_background_process_db_sched_duration_seconds</td></tr>
  11168. <tr><td>synapse_storage_events_persisted_events_total</td><td>synapse_storage_events_persisted_events</td></tr>
  11169. <tr><td>synapse_storage_events_persisted_events_sep_total</td><td>synapse_storage_events_persisted_events_sep</td></tr>
  11170. <tr><td>synapse_storage_events_state_delta_total</td><td>synapse_storage_events_state_delta</td></tr>
  11171. <tr><td>synapse_storage_events_state_delta_single_event_total</td><td>synapse_storage_events_state_delta_single_event</td></tr>
  11172. <tr><td>synapse_storage_events_state_delta_reuse_delta_total</td><td>synapse_storage_events_state_delta_reuse_delta</td></tr>
  11173. <tr><td>synapse_federation_server_received_pdus_total</td><td>synapse_federation_server_received_pdus</td></tr>
  11174. <tr><td>synapse_federation_server_received_edus_total</td><td>synapse_federation_server_received_edus</td></tr>
  11175. <tr><td>synapse_handler_presence_notified_presence_total</td><td>synapse_handler_presence_notified_presence</td></tr>
  11176. <tr><td>synapse_handler_presence_federation_presence_out_total</td><td>synapse_handler_presence_federation_presence_out</td></tr>
  11177. <tr><td>synapse_handler_presence_presence_updates_total</td><td>synapse_handler_presence_presence_updates</td></tr>
  11178. <tr><td>synapse_handler_presence_timers_fired_total</td><td>synapse_handler_presence_timers_fired</td></tr>
  11179. <tr><td>synapse_handler_presence_federation_presence_total</td><td>synapse_handler_presence_federation_presence</td></tr>
  11180. <tr><td>synapse_handler_presence_bump_active_time_total</td><td>synapse_handler_presence_bump_active_time</td></tr>
  11181. <tr><td>synapse_federation_client_sent_edus_total</td><td>synapse_federation_client_sent_edus</td></tr>
  11182. <tr><td>synapse_federation_client_sent_pdu_destinations_count_total</td><td>synapse_federation_client_sent_pdu_destinations:count</td></tr>
  11183. <tr><td>synapse_federation_client_sent_pdu_destinations_total</td><td>synapse_federation_client_sent_pdu_destinations:total</td></tr>
  11184. <tr><td>synapse_handlers_appservice_events_processed_total</td><td>synapse_handlers_appservice_events_processed</td></tr>
  11185. <tr><td>synapse_notifier_notified_events_total</td><td>synapse_notifier_notified_events</td></tr>
  11186. <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>
  11187. <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>
  11188. <tr><td>synapse_http_httppusher_http_pushes_processed_total</td><td>synapse_http_httppusher_http_pushes_processed</td></tr>
  11189. <tr><td>synapse_http_httppusher_http_pushes_failed_total</td><td>synapse_http_httppusher_http_pushes_failed</td></tr>
  11190. <tr><td>synapse_http_httppusher_badge_updates_processed_total</td><td>synapse_http_httppusher_badge_updates_processed</td></tr>
  11191. <tr><td>synapse_http_httppusher_badge_updates_failed_total</td><td>synapse_http_httppusher_badge_updates_failed</td></tr>
  11192. </tbody></table>
  11193. <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>
  11194. <p>The duplicated metrics deprecated in Synapse 0.27.0 have been removed.</p>
  11195. <p>All time duration-based metrics have been changed to be seconds. This
  11196. affects:</p>
  11197. <table><thead><tr><th>msec -&gt; sec metrics</th></tr></thead><tbody>
  11198. <tr><td>python_gc_time</td></tr>
  11199. <tr><td>python_twisted_reactor_tick_time</td></tr>
  11200. <tr><td>synapse_storage_query_time</td></tr>
  11201. <tr><td>synapse_storage_schedule_time</td></tr>
  11202. <tr><td>synapse_storage_transaction_time</td></tr>
  11203. </tbody></table>
  11204. <p>Several metrics have been changed to be histograms, which sort entries
  11205. into buckets and allow better analysis. The following metrics are now
  11206. histograms:</p>
  11207. <table><thead><tr><th>Altered metrics</th></tr></thead><tbody>
  11208. <tr><td>python_gc_time</td></tr>
  11209. <tr><td>python_twisted_reactor_pending_calls</td></tr>
  11210. <tr><td>python_twisted_reactor_tick_time</td></tr>
  11211. <tr><td>synapse_http_server_response_time_seconds</td></tr>
  11212. <tr><td>synapse_storage_query_time</td></tr>
  11213. <tr><td>synapse_storage_schedule_time</td></tr>
  11214. <tr><td>synapse_storage_transaction_time</td></tr>
  11215. </tbody></table>
  11216. <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>
  11217. <p>Synapse 0.27.0 begins the process of rationalising the duplicate
  11218. <code>*:count</code> metrics reported for the resource tracking for code blocks and
  11219. HTTP requests.</p>
  11220. <p>At the same time, the corresponding <code>*:total</code> metrics are being renamed,
  11221. as the <code>:total</code> suffix no longer makes sense in the absence of a
  11222. corresponding <code>:count</code> metric.</p>
  11223. <p>To enable a graceful migration path, this release just adds new names
  11224. for the metrics being renamed. A future release will remove the old
  11225. ones.</p>
  11226. <p>The following table shows the new metrics, and the old metrics which
  11227. they are replacing.</p>
  11228. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  11229. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_timer:count</td></tr>
  11230. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_utime:count</td></tr>
  11231. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_stime:count</td></tr>
  11232. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_count:count</td></tr>
  11233. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_duration:count</td></tr>
  11234. <tr><td>synapse_util_metrics_block_time_seconds</td><td>synapse_util_metrics_block_timer:total</td></tr>
  11235. <tr><td>synapse_util_metrics_block_ru_utime_seconds</td><td>synapse_util_metrics_block_ru_utime:total</td></tr>
  11236. <tr><td>synapse_util_metrics_block_ru_stime_seconds</td><td>synapse_util_metrics_block_ru_stime:total</td></tr>
  11237. <tr><td>synapse_util_metrics_block_db_txn_count</td><td>synapse_util_metrics_block_db_txn_count:total</td></tr>
  11238. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds</td><td>synapse_util_metrics_block_db_txn_duration:total</td></tr>
  11239. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_requests</td></tr>
  11240. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_time:count</td></tr>
  11241. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_utime:count</td></tr>
  11242. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_stime:count</td></tr>
  11243. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_count:count</td></tr>
  11244. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_duration:count</td></tr>
  11245. <tr><td>synapse_http_server_response_time_seconds</td><td>synapse_http_server_response_time:total</td></tr>
  11246. <tr><td>synapse_http_server_response_ru_utime_seconds</td><td>synapse_http_server_response_ru_utime:total</td></tr>
  11247. <tr><td>synapse_http_server_response_ru_stime_seconds</td><td>synapse_http_server_response_ru_stime:total</td></tr>
  11248. <tr><td>synapse_http_server_response_db_txn_count</td><td>synapse_http_server_response_db_txn_count:total</td></tr>
  11249. <tr><td>synapse_http_server_response_db_txn_duration_seconds</td><td>synapse_http_server_response_db_txn_duration:total</td></tr>
  11250. </tbody></table>
  11251. <h2 id="standard-metric-names"><a class="header" href="#standard-metric-names">Standard Metric Names</a></h2>
  11252. <p>As of synapse version 0.18.2, the format of the process-wide metrics has
  11253. been changed to fit prometheus standard naming conventions. Additionally
  11254. the units have been changed to seconds, from miliseconds.</p>
  11255. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  11256. <tr><td>process_cpu_user_seconds_total</td><td>process_resource_utime / 1000</td></tr>
  11257. <tr><td>process_cpu_system_seconds_total</td><td>process_resource_stime / 1000</td></tr>
  11258. <tr><td>process_open_fds (no 'type' label)</td><td>process_fds</td></tr>
  11259. </tbody></table>
  11260. <p>The python-specific counts of garbage collector performance have been
  11261. renamed.</p>
  11262. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  11263. <tr><td>python_gc_time</td><td>reactor_gc_time</td></tr>
  11264. <tr><td>python_gc_unreachable_total</td><td>reactor_gc_unreachable</td></tr>
  11265. <tr><td>python_gc_counts</td><td>reactor_gc_counts</td></tr>
  11266. </tbody></table>
  11267. <p>The twisted-specific reactor metrics have been renamed.</p>
  11268. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  11269. <tr><td>python_twisted_reactor_pending_calls</td><td>reactor_pending_calls</td></tr>
  11270. <tr><td>python_twisted_reactor_tick_time</td><td>reactor_tick_time</td></tr>
  11271. </tbody></table>
  11272. <div style="break-before: page; page-break-before: always;"></div><h1 id="request-log-format"><a class="header" href="#request-log-format">Request log format</a></h1>
  11273. <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>
  11274. <p>See the following for how to decode the dense data available from the default logging configuration.</p>
  11275. <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]
  11276. -AAAAAAAAAAAAAAAAAAAAA- -BBBBBBBBBBBBBBBBBBBBBB- -C- -DD- -EEEEEE- -FFFFFFFFF- -GG- -HHHHHHHHHHHHHHHHHHHHHHH- -IIIIII- -JJJJJJJ- -KKKKKK-, -LLLLLL- -MMMMMMM- -NNNNNN- O -P- -QQ- -RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR- -SSSSSSSSSSSS- -TTTTTT-
  11277. </code></pre>
  11278. <table><thead><tr><th>Part</th><th>Explanation</th></tr></thead><tbody>
  11279. <tr><td>AAAA</td><td>Timestamp request was logged (not recieved)</td></tr>
  11280. <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>
  11281. <tr><td>CCCC</td><td>Line number in code</td></tr>
  11282. <tr><td>DDDD</td><td>Log Level</td></tr>
  11283. <tr><td>EEEE</td><td>Request Identifier (This identifier is shared by related log lines)</td></tr>
  11284. <tr><td>FFFF</td><td>Source IP (Or X-Forwarded-For if enabled)</td></tr>
  11285. <tr><td>GGGG</td><td>Server Port</td></tr>
  11286. <tr><td>HHHH</td><td>Federated Server or Local User making request (blank if unauthenticated or not supplied)</td></tr>
  11287. <tr><td>IIII</td><td>Total Time to process the request</td></tr>
  11288. <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>
  11289. <tr><td>KKKK</td><td>Userland CPU time</td></tr>
  11290. <tr><td>LLLL</td><td>System CPU time</td></tr>
  11291. <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>
  11292. <tr><td>NNNN</td><td>Total time waiting for response to DB queries across all parallel DB work from this request</td></tr>
  11293. <tr><td>OOOO</td><td>Count of DB transactions performed</td></tr>
  11294. <tr><td>PPPP</td><td>Response body size</td></tr>
  11295. <tr><td>QQQQ</td><td>Response status code (prefixed with ! if the socket was closed before the response was generated)</td></tr>
  11296. <tr><td>RRRR</td><td>Request</td></tr>
  11297. <tr><td>SSSS</td><td>User-agent</td></tr>
  11298. <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>
  11299. </tbody></table>
  11300. <p>MMMM / NNNN can be greater than IIII if there are multiple slow database queries
  11301. running in parallel.</p>
  11302. <p>Some actions can result in multiple identical http requests, which will return
  11303. the same data, but only the first request will report time/transactions in
  11304. <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
  11305. response and will simultaneously return with the first request, but with very
  11306. small processing times.</p>
  11307. <div style="break-before: page; page-break-before: always;"></div><h1 id="contributing"><a class="header" href="#contributing">Contributing</a></h1>
  11308. <p>This document aims to get you started with contributing to Synapse!</p>
  11309. <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>
  11310. <p>Everyone is welcome to contribute code to <a href="https://github.com/matrix-org">matrix.org
  11311. projects</a>, provided that they are willing to
  11312. license their contributions under the same license as the project itself. We
  11313. follow a simple 'inbound=outbound' model for contributions: the act of
  11314. submitting an 'inbound' contribution means that the contributor agrees to
  11315. license the code under the same terms as the project's overall 'outbound'
  11316. license - in our case, this is almost always Apache Software License v2 (see
  11317. <a href="https://github.com/matrix-org/synapse/blob/develop/LICENSE">LICENSE</a>).</p>
  11318. <h1 id="2-what-do-i-need"><a class="header" href="#2-what-do-i-need">2. What do I need?</a></h1>
  11319. <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>
  11320. <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>
  11321. <p>For some tests, you will need <a href="https://docs.docker.com/get-docker/">a recent version of Docker</a>.</p>
  11322. <h1 id="3-get-the-source"><a class="header" href="#3-get-the-source">3. Get the source.</a></h1>
  11323. <p>The preferred and easiest way to contribute changes is to fork the relevant
  11324. 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
  11325. changes into our repo.</p>
  11326. <p>Please base your changes on the <code>develop</code> branch.</p>
  11327. <pre><code class="language-sh">git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git
  11328. git checkout develop
  11329. </code></pre>
  11330. <p>If you need help getting started with git, this is beyond the scope of the document, but you
  11331. can find many good git tutorials on the web.</p>
  11332. <h1 id="4-install-the-dependencies"><a class="header" href="#4-install-the-dependencies">4. Install the dependencies</a></h1>
  11333. <h2 id="under-unix-macos-linux-bsd-"><a class="header" href="#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></h2>
  11334. <p>Once you have installed Python 3 and added the source, please open a terminal and
  11335. setup a <em>virtualenv</em>, as follows:</p>
  11336. <pre><code class="language-sh">cd path/where/you/have/cloned/the/repository
  11337. python3 -m venv ./env
  11338. source ./env/bin/activate
  11339. pip install -e &quot;.[all,dev]&quot;
  11340. pip install tox
  11341. </code></pre>
  11342. <p>This will install the developer dependencies for the project.</p>
  11343. <h2 id="under-windows"><a class="header" href="#under-windows">Under Windows</a></h2>
  11344. <p>TBD</p>
  11345. <h1 id="5-get-in-touch"><a class="header" href="#5-get-in-touch">5. Get in touch.</a></h1>
  11346. <p>Join our developer community on Matrix: <a href="https://matrix.to/#/#synapse-dev:matrix.org">#synapse-dev:matrix.org</a>!</p>
  11347. <h1 id="6-pick-an-issue"><a class="header" href="#6-pick-an-issue">6. Pick an issue.</a></h1>
  11348. <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>
  11349. to work on.</p>
  11350. <h1 id="7-turn-coffee-into-code-and-documentation"><a class="header" href="#7-turn-coffee-into-code-and-documentation">7. Turn coffee into code and documentation!</a></h1>
  11351. <p>There is a growing amount of documentation located in the
  11352. <a href="https://github.com/matrix-org/synapse/tree/develop/docs"><code>docs</code></a>
  11353. directory, with a rendered version <a href="https://matrix-org.github.io/synapse">available online</a>.
  11354. This documentation is intended primarily for sysadmins running their
  11355. own Synapse instance, as well as developers interacting externally with
  11356. Synapse.
  11357. <a href="https://github.com/matrix-org/synapse/tree/develop/docs/development"><code>docs/development</code></a>
  11358. exists primarily to house documentation for
  11359. Synapse developers.
  11360. <a href="https://github.com/matrix-org/synapse/tree/develop/docs/admin_api"><code>docs/admin_api</code></a> houses documentation
  11361. regarding Synapse's Admin API, which is used mostly by sysadmins and external
  11362. service developers.</p>
  11363. <p>Synapse's code style is documented <a href="development/../code_style.html">here</a>. Please follow
  11364. it, including the conventions for the <a href="development/../code_style.html#configuration-file-format">sample configuration
  11365. file</a>.</p>
  11366. <p>We welcome improvements and additions to our documentation itself! When
  11367. writing new pages, please
  11368. <a href="https://github.com/matrix-org/synapse/tree/develop/docs#adding-to-the-documentation">build <code>docs</code> to a book</a>
  11369. to check that your contributions render correctly. The docs are written in
  11370. <a href="https://guides.github.com/features/mastering-markdown/">GitHub-Flavoured Markdown</a>.</p>
  11371. <p>Some documentation also exists in <a href="https://github.com/matrix-org/synapse/wiki">Synapse's GitHub
  11372. Wiki</a>, although this is primarily
  11373. contributed to by community authors.</p>
  11374. <h1 id="8-test-test-test"><a class="header" href="#8-test-test-test">8. Test, test, test!</a></h1>
  11375. <p><a name="test-test-test"></a></p>
  11376. <p>While you're developing and before submitting a patch, you'll
  11377. want to test your code.</p>
  11378. <h2 id="run-the-linters"><a class="header" href="#run-the-linters">Run the linters.</a></h2>
  11379. <p>The linters look at your code and do two things:</p>
  11380. <ul>
  11381. <li>ensure that your code follows the coding style adopted by the project;</li>
  11382. <li>catch a number of errors in your code.</li>
  11383. </ul>
  11384. <p>They're pretty fast, don't hesitate!</p>
  11385. <pre><code class="language-sh">source ./env/bin/activate
  11386. ./scripts-dev/lint.sh
  11387. </code></pre>
  11388. <p>Note that this script <em>will modify your files</em> to fix styling errors.
  11389. Make sure that you have saved all your files.</p>
  11390. <p>If you wish to restrict the linters to only the files changed since the last commit
  11391. (much faster!), you can instead run:</p>
  11392. <pre><code class="language-sh">source ./env/bin/activate
  11393. ./scripts-dev/lint.sh -d
  11394. </code></pre>
  11395. <p>Or if you know exactly which files you wish to lint, you can instead run:</p>
  11396. <pre><code class="language-sh">source ./env/bin/activate
  11397. ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
  11398. </code></pre>
  11399. <h2 id="run-the-unit-tests-twisted-trial"><a class="header" href="#run-the-unit-tests-twisted-trial">Run the unit tests (Twisted trial).</a></h2>
  11400. <p>The unit tests run parts of Synapse, including your changes, to see if anything
  11401. was broken. They are slower than the linters but will typically catch more errors.</p>
  11402. <pre><code class="language-sh">source ./env/bin/activate
  11403. trial tests
  11404. </code></pre>
  11405. <p>If you wish to only run <em>some</em> unit tests, you may specify
  11406. another module instead of <code>tests</code> - or a test class or a method:</p>
  11407. <pre><code class="language-sh">source ./env/bin/activate
  11408. trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
  11409. </code></pre>
  11410. <p>If your tests fail, you may wish to look at the logs (the default log level is <code>ERROR</code>):</p>
  11411. <pre><code class="language-sh">less _trial_temp/test.log
  11412. </code></pre>
  11413. <p>To increase the log level for the tests, set <code>SYNAPSE_TEST_LOG_LEVEL</code>:</p>
  11414. <pre><code class="language-sh">SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
  11415. </code></pre>
  11416. <h3 id="running-tests-under-postgresql"><a class="header" href="#running-tests-under-postgresql">Running tests under PostgreSQL</a></h3>
  11417. <p>Invoking <code>trial</code> as above will use an in-memory SQLite database. This is great for
  11418. quick development and testing. However, we recommend using a PostgreSQL database
  11419. in production (and indeed, we have some code paths specific to each database).
  11420. This means that we need to run our unit tests against PostgreSQL too. Our CI does
  11421. this automatically for pull requests and release candidates, but it's sometimes
  11422. useful to reproduce this locally.</p>
  11423. <p>To do so, <a href="development/../postgres.html">configure Postgres</a> and run <code>trial</code> with the
  11424. following environment variables matching your configuration:</p>
  11425. <ul>
  11426. <li><code>SYNAPSE_POSTGRES</code> to anything nonempty</li>
  11427. <li><code>SYNAPSE_POSTGRES_HOST</code></li>
  11428. <li><code>SYNAPSE_POSTGRES_USER</code></li>
  11429. <li><code>SYNAPSE_POSTGRES_PASSWORD</code></li>
  11430. </ul>
  11431. <p>For example:</p>
  11432. <pre><code class="language-shell">export SYNAPSE_POSTGRES=1
  11433. export SYNAPSE_POSTGRES_HOST=localhost
  11434. export SYNAPSE_POSTGRES_USER=postgres
  11435. export SYNAPSE_POSTGRES_PASSWORD=mydevenvpassword
  11436. trial
  11437. </code></pre>
  11438. <h4 id="prebuilt-container"><a class="header" href="#prebuilt-container">Prebuilt container</a></h4>
  11439. <p>Since configuring PostgreSQL can be fiddly, we can make use of a pre-made
  11440. Docker container to set up PostgreSQL and run our tests for us. To do so, run</p>
  11441. <pre><code class="language-shell">scripts-dev/test_postgresql.sh
  11442. </code></pre>
  11443. <p>Any extra arguments to the script will be passed to <code>tox</code> and then to <code>trial</code>,
  11444. so we can run a specific test in this container with e.g.</p>
  11445. <pre><code class="language-shell">scripts-dev/test_postgresql.sh tests.replication.test_sharded_event_persister.EventPersisterShardTestCase
  11446. </code></pre>
  11447. <p>The container creates a folder in your Synapse checkout called
  11448. <code>.tox-pg-container</code> and uses this as a tox environment. The output of any
  11449. <code>trial</code> runs goes into <code>_trial_temp</code> in your synapse source directory — the same
  11450. as running <code>trial</code> directly on your host machine.</p>
  11451. <h2 id="run-the-integration-tests-sytest"><a class="header" href="#run-the-integration-tests-sytest">Run the integration tests (<a href="https://github.com/matrix-org/sytest">Sytest</a>).</a></h2>
  11452. <p>The integration tests are a more comprehensive suite of tests. They
  11453. run a full version of Synapse, including your changes, to check if
  11454. anything was broken. They are slower than the unit tests but will
  11455. typically catch more errors.</p>
  11456. <p>The following command will let you run the integration test with the most common
  11457. configuration:</p>
  11458. <pre><code class="language-sh">$ docker run --rm -it -v /path/where/you/have/cloned/the/repository\:/src:ro -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapse:buster
  11459. </code></pre>
  11460. <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>
  11461. <h2 id="run-the-integration-tests-complement"><a class="header" href="#run-the-integration-tests-complement">Run the integration tests (<a href="https://github.com/matrix-org/complement">Complement</a>).</a></h2>
  11462. <p><a href="https://github.com/matrix-org/complement">Complement</a> is a suite of black box tests that can be run on any homeserver implementation. It can also be thought of as end-to-end (e2e) tests.</p>
  11463. <p>It's often nice to develop on Synapse and write Complement tests at the same time.
  11464. Here is how to run your local Synapse checkout against your local Complement checkout.</p>
  11465. <p>(checkout <a href="https://github.com/matrix-org/complement"><code>complement</code></a> alongside your <code>synapse</code> checkout)</p>
  11466. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh
  11467. </code></pre>
  11468. <p>To run a specific test file, you can pass the test name at the end of the command. The name passed comes from the naming structure in your Complement tests. If you're unsure of the name, you can do a full run and copy it from the test output:</p>
  11469. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory
  11470. </code></pre>
  11471. <p>To run a specific test, you can specify the whole name structure:</p>
  11472. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory/parallel/Backfilled_historical_events_resolve_with_proper_state_in_correct_order
  11473. </code></pre>
  11474. <h3 id="access-database-for-homeserver-after-complement-test-runs"><a class="header" href="#access-database-for-homeserver-after-complement-test-runs">Access database for homeserver after Complement test runs.</a></h3>
  11475. <p>If you're curious what the database looks like after you run some tests, here are some steps to get you going in Synapse:</p>
  11476. <ol>
  11477. <li>In your Complement test comment out <code>defer deployment.Destroy(t)</code> and replace with <code>defer time.Sleep(2 * time.Hour)</code> to keep the homeserver running after the tests complete</li>
  11478. <li>Start the Complement tests</li>
  11479. <li>Find the name of the container, <code>docker ps -f name=complement_</code> (this will filter for just the Compelement related Docker containers)</li>
  11480. <li>Access the container replacing the name with what you found in the previous step: <code>docker exec -it complement_1_hs_with_application_service.hs1_2 /bin/bash</code></li>
  11481. <li>Install sqlite (database driver), <code>apt-get update &amp;&amp; apt-get install -y sqlite3</code></li>
  11482. <li>Then run <code>sqlite3</code> and open the database <code>.open /conf/homeserver.db</code> (this db path comes from the Synapse homeserver.yaml)</li>
  11483. </ol>
  11484. <h1 id="9-submit-your-patch"><a class="header" href="#9-submit-your-patch">9. Submit your patch.</a></h1>
  11485. <p>Once you're happy with your patch, it's time to prepare a Pull Request.</p>
  11486. <p>To prepare a Pull Request, please:</p>
  11487. <ol>
  11488. <li>verify that <a href="development/contributing_guide.html#test-test-test">all the tests pass</a>, including the coding style;</li>
  11489. <li><a href="development/contributing_guide.html#sign-off">sign off</a> your contribution;</li>
  11490. <li><code>git push</code> your commit to your fork of Synapse;</li>
  11491. <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>
  11492. <li>add a <a href="development/contributing_guide.html#changelog">changelog entry</a> and push it to your Pull Request;</li>
  11493. <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>
  11494. <li>if you need to update your PR, please avoid rebasing and just add new commits to your branch.</li>
  11495. </ol>
  11496. <h2 id="changelog"><a class="header" href="#changelog">Changelog</a></h2>
  11497. <p>All changes, even minor ones, need a corresponding changelog / newsfragment
  11498. entry. These are managed by <a href="https://github.com/hawkowl/towncrier">Towncrier</a>.</p>
  11499. <p>To create a changelog entry, make a new file in the <code>changelog.d</code> directory named
  11500. in the format of <code>PRnumber.type</code>. The type can be one of the following:</p>
  11501. <ul>
  11502. <li><code>feature</code></li>
  11503. <li><code>bugfix</code></li>
  11504. <li><code>docker</code> (for updates to the Docker image)</li>
  11505. <li><code>doc</code> (for updates to the documentation)</li>
  11506. <li><code>removal</code> (also used for deprecations)</li>
  11507. <li><code>misc</code> (for internal-only changes)</li>
  11508. </ul>
  11509. <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
  11510. release, so the content of the file should be a short description of your
  11511. change in the same style as the rest of the changelog. The file can contain Markdown
  11512. formatting, and should end with a full stop (.) or an exclamation mark (!) for
  11513. consistency.</p>
  11514. <p>Adding credits to the changelog is encouraged, we value your
  11515. contributions and would like to have you shouted out in the release notes!</p>
  11516. <p>For example, a fix in PR #1234 would have its changelog entry in
  11517. <code>changelog.d/1234.bugfix</code>, and contain content like:</p>
  11518. <blockquote>
  11519. <p>The security levels of Florbs are now validated when received
  11520. via the <code>/federation/florb</code> endpoint. Contributed by Jane Matrix.</p>
  11521. </blockquote>
  11522. <p>If there are multiple pull requests involved in a single bugfix/feature/etc,
  11523. then the content for each <code>changelog.d</code> file should be the same. Towncrier will
  11524. merge the matching files together into a single changelog entry when we come to
  11525. release.</p>
  11526. <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>
  11527. <p>Obviously, you don't know if you should call your newsfile
  11528. <code>1234.bugfix</code> or <code>5678.bugfix</code> until you create the PR, which leads to a
  11529. chicken-and-egg problem.</p>
  11530. <p>There are two options for solving this:</p>
  11531. <ol>
  11532. <li>
  11533. <p>Open the PR without a changelog file, see what number you got, and <em>then</em>
  11534. add the changelog file to your branch (see <a href="development/contributing_guide.html#updating-your-pull-request">Updating your pull
  11535. request</a>), or:</p>
  11536. </li>
  11537. <li>
  11538. <p>Look at the <a href="https://github.com/matrix-org/synapse/issues?q=">list of all
  11539. issues/PRs</a>, add one to the
  11540. highest number you see, and quickly open the PR before somebody else claims
  11541. your number.</p>
  11542. <p><a href="https://github.com/richvdh/scripts/blob/master/next_github_number.sh">This
  11543. script</a>
  11544. might be helpful if you find yourself doing this a lot.</p>
  11545. </li>
  11546. </ol>
  11547. <p>Sorry, we know it's a bit fiddly, but it's <em>really</em> helpful for us when we come
  11548. to put together a release!</p>
  11549. <h3 id="debian-changelog"><a class="header" href="#debian-changelog">Debian changelog</a></h3>
  11550. <p>Changes which affect the debian packaging files (in <code>debian</code>) are an
  11551. exception to the rule that all changes require a <code>changelog.d</code> file.</p>
  11552. <p>In this case, you will need to add an entry to the debian changelog for the
  11553. next release. For this, run the following command:</p>
  11554. <pre><code>dch
  11555. </code></pre>
  11556. <p>This will make up a new version number (if there isn't already an unreleased
  11557. version in flight), and open an editor where you can add a new changelog entry.
  11558. (Our release process will ensure that the version number and maintainer name is
  11559. corrected for the release.)</p>
  11560. <p>If your change affects both the debian packaging <em>and</em> files outside the debian
  11561. directory, you will need both a regular newsfragment <em>and</em> an entry in the
  11562. debian changelog. (Though typically such changes should be submitted as two
  11563. separate pull requests.)</p>
  11564. <h2 id="sign-off"><a class="header" href="#sign-off">Sign off</a></h2>
  11565. <p>In order to have a concrete record that your contribution is intentional
  11566. and you agree to license it under the same terms as the project's license, we've adopted the
  11567. same lightweight approach that the Linux Kernel
  11568. <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>,
  11569. <a href="https://github.com/docker/docker/blob/master/CONTRIBUTING.md">Docker</a>, and many other
  11570. projects use: the DCO (Developer Certificate of Origin:
  11571. http://developercertificate.org/). This is a simple declaration that you wrote
  11572. the contribution or otherwise have the right to contribute it to Matrix:</p>
  11573. <pre><code>Developer Certificate of Origin
  11574. Version 1.1
  11575. Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
  11576. 660 York Street, Suite 102,
  11577. San Francisco, CA 94110 USA
  11578. Everyone is permitted to copy and distribute verbatim copies of this
  11579. license document, but changing it is not allowed.
  11580. Developer's Certificate of Origin 1.1
  11581. By making a contribution to this project, I certify that:
  11582. (a) The contribution was created in whole or in part by me and I
  11583. have the right to submit it under the open source license
  11584. indicated in the file; or
  11585. (b) The contribution is based upon previous work that, to the best
  11586. of my knowledge, is covered under an appropriate open source
  11587. license and I have the right under that license to submit that
  11588. work with modifications, whether created in whole or in part
  11589. by me, under the same open source license (unless I am
  11590. permitted to submit under a different license), as indicated
  11591. in the file; or
  11592. (c) The contribution was provided directly to me by some other
  11593. person who certified (a), (b) or (c) and I have not modified
  11594. it.
  11595. (d) I understand and agree that this project and the contribution
  11596. are public and that a record of the contribution (including all
  11597. personal information I submit with it, including my sign-off) is
  11598. maintained indefinitely and may be redistributed consistent with
  11599. this project or the open source license(s) involved.
  11600. </code></pre>
  11601. <p>If you agree to this for your contribution, then all that's needed is to
  11602. include the line in your commit or pull request comment:</p>
  11603. <pre><code>Signed-off-by: Your Name &lt;your@email.example.org&gt;
  11604. </code></pre>
  11605. <p>We accept contributions under a legally identifiable name, such as
  11606. your name on government documentation or common-law names (names
  11607. claimed by legitimate usage or repute). Unfortunately, we cannot
  11608. accept anonymous contributions at this time.</p>
  11609. <p>Git allows you to add this signoff automatically when using the <code>-s</code>
  11610. flag to <code>git commit</code>, which uses the name and email set in your
  11611. <code>user.name</code> and <code>user.email</code> git configs.</p>
  11612. <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>
  11613. <p>Once the Pull Request is opened, you will see a few things:</p>
  11614. <ol>
  11615. <li>our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;</li>
  11616. <li>one or more of the developers will take a look at your Pull Request and offer feedback.</li>
  11617. </ol>
  11618. <p>From this point, you should:</p>
  11619. <ol>
  11620. <li>Look at the results of the CI pipeline.
  11621. <ul>
  11622. <li>If there is any error, fix the error.</li>
  11623. </ul>
  11624. </li>
  11625. <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>
  11626. <li>Create a new commit with the changes.
  11627. <ul>
  11628. <li>Please do NOT overwrite the history. New commits make the reviewer's life easier.</li>
  11629. <li>Push this commits to your Pull Request.</li>
  11630. </ul>
  11631. </li>
  11632. <li>Back to 1.</li>
  11633. </ol>
  11634. <p>Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!</p>
  11635. <h1 id="11-find-a-new-issue"><a class="header" href="#11-find-a-new-issue">11. Find a new issue.</a></h1>
  11636. <p>By now, you know the drill!</p>
  11637. <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>
  11638. <p>There are some notes for those with commit access to the project on how we
  11639. manage git <a href="development/git.html">here</a>.</p>
  11640. <h1 id="conclusion"><a class="header" href="#conclusion">Conclusion</a></h1>
  11641. <p>That's it! Matrix is a very open and collaborative project as you might expect
  11642. given our obsession with open communication. If we're going to successfully
  11643. matrix together all the fragmented communication technologies out there we are
  11644. reliant on contributions and collaboration from the community to do so. So
  11645. please get involved - and we hope you have as much fun hacking on Matrix as we
  11646. do!</p>
  11647. <div style="break-before: page; page-break-before: always;"></div><h1 id="code-style"><a class="header" href="#code-style">Code Style</a></h1>
  11648. <h2 id="formatting-tools"><a class="header" href="#formatting-tools">Formatting tools</a></h2>
  11649. <p>The Synapse codebase uses a number of code formatting tools in order to
  11650. quickly and automatically check for formatting (and sometimes logical)
  11651. errors in code.</p>
  11652. <p>The necessary tools are detailed below.</p>
  11653. <p>First install them with:</p>
  11654. <pre><code>pip install -e &quot;.[lint,mypy]&quot;
  11655. </code></pre>
  11656. <ul>
  11657. <li>
  11658. <p><strong>black</strong></p>
  11659. <p>The Synapse codebase uses <a href="https://pypi.org/project/black/">black</a>
  11660. as an opinionated code formatter, ensuring all comitted code is
  11661. properly formatted.</p>
  11662. <p>Have <code>black</code> auto-format your code (it shouldn't change any
  11663. functionality) with:</p>
  11664. <pre><code>black . --exclude=&quot;\.tox|build|env&quot;
  11665. </code></pre>
  11666. </li>
  11667. <li>
  11668. <p><strong>flake8</strong></p>
  11669. <p><code>flake8</code> is a code checking tool. We require code to pass <code>flake8</code>
  11670. before being merged into the codebase.</p>
  11671. <p>Check all application and test code with:</p>
  11672. <pre><code>flake8 synapse tests
  11673. </code></pre>
  11674. </li>
  11675. <li>
  11676. <p><strong>isort</strong></p>
  11677. <p><code>isort</code> ensures imports are nicely formatted, and can suggest and
  11678. auto-fix issues such as double-importing.</p>
  11679. <p>Auto-fix imports with:</p>
  11680. <pre><code>isort -rc synapse tests
  11681. </code></pre>
  11682. <p><code>-rc</code> means to recursively search the given directories.</p>
  11683. </li>
  11684. </ul>
  11685. <p>It's worth noting that modern IDEs and text editors can run these tools
  11686. automatically on save. It may be worth looking into whether this
  11687. functionality is supported in your editor for a more convenient
  11688. development workflow. It is not, however, recommended to run <code>flake8</code> on
  11689. save as it takes a while and is very resource intensive.</p>
  11690. <h2 id="general-rules"><a class="header" href="#general-rules">General rules</a></h2>
  11691. <ul>
  11692. <li><strong>Naming</strong>:
  11693. <ul>
  11694. <li>Use camel case for class and type names</li>
  11695. <li>Use underscores for functions and variables.</li>
  11696. </ul>
  11697. </li>
  11698. <li><strong>Docstrings</strong>: should follow the <a href="https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings">google code
  11699. style</a>.
  11700. See the
  11701. <a href="http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html">examples</a>
  11702. in the sphinx documentation.</li>
  11703. <li><strong>Imports</strong>:
  11704. <ul>
  11705. <li>
  11706. <p>Imports should be sorted by <code>isort</code> as described above.</p>
  11707. </li>
  11708. <li>
  11709. <p>Prefer to import classes and functions rather than packages or
  11710. modules.</p>
  11711. <p>Example:</p>
  11712. <pre><code>from synapse.types import UserID
  11713. ...
  11714. user_id = UserID(local, server)
  11715. </code></pre>
  11716. <p>is preferred over:</p>
  11717. <pre><code>from synapse import types
  11718. ...
  11719. user_id = types.UserID(local, server)
  11720. </code></pre>
  11721. <p>(or any other variant).</p>
  11722. <p>This goes against the advice in the Google style guide, but it
  11723. means that errors in the name are caught early (at import time).</p>
  11724. </li>
  11725. <li>
  11726. <p>Avoid wildcard imports (<code>from synapse.types import *</code>) and
  11727. relative imports (<code>from .types import UserID</code>).</p>
  11728. </li>
  11729. </ul>
  11730. </li>
  11731. </ul>
  11732. <h2 id="configuration-file-format"><a class="header" href="#configuration-file-format">Configuration file format</a></h2>
  11733. <p>The <a href="./sample_config.yaml">sample configuration file</a> acts as a
  11734. reference to Synapse's configuration options for server administrators.
  11735. Remember that many readers will be unfamiliar with YAML and server
  11736. administration in general, so that it is important that the file be as
  11737. easy to understand as possible, which includes following a consistent
  11738. format.</p>
  11739. <p>Some guidelines follow:</p>
  11740. <ul>
  11741. <li>
  11742. <p>Sections should be separated with a heading consisting of a single
  11743. line prefixed and suffixed with <code>##</code>. There should be <strong>two</strong> blank
  11744. lines before the section header, and <strong>one</strong> after.</p>
  11745. </li>
  11746. <li>
  11747. <p>Each option should be listed in the file with the following format:</p>
  11748. <ul>
  11749. <li>
  11750. <p>A comment describing the setting. Each line of this comment
  11751. should be prefixed with a hash (<code>#</code>) and a space.</p>
  11752. <p>The comment should describe the default behaviour (ie, what
  11753. happens if the setting is omitted), as well as what the effect
  11754. will be if the setting is changed.</p>
  11755. <p>Often, the comment end with something like &quot;uncomment the
  11756. following to <do action>&quot;.</p>
  11757. </li>
  11758. <li>
  11759. <p>A line consisting of only <code>#</code>.</p>
  11760. </li>
  11761. <li>
  11762. <p>A commented-out example setting, prefixed with only <code>#</code>.</p>
  11763. <p>For boolean (on/off) options, convention is that this example
  11764. should be the <em>opposite</em> to the default (so the comment will end
  11765. with &quot;Uncomment the following to enable [or disable]
  11766. <feature>.&quot; For other options, the example should give some
  11767. non-default value which is likely to be useful to the reader.</p>
  11768. </li>
  11769. </ul>
  11770. </li>
  11771. <li>
  11772. <p>There should be a blank line between each option.</p>
  11773. </li>
  11774. <li>
  11775. <p>Where several settings are grouped into a single dict, <em>avoid</em> the
  11776. convention where the whole block is commented out, resulting in
  11777. comment lines starting <code># #</code>, as this is hard to read and confusing
  11778. to edit. Instead, leave the top-level config option uncommented, and
  11779. follow the conventions above for sub-options. Ensure that your code
  11780. correctly handles the top-level option being set to <code>None</code> (as it
  11781. will be if no sub-options are enabled).</p>
  11782. </li>
  11783. <li>
  11784. <p>Lines should be wrapped at 80 characters.</p>
  11785. </li>
  11786. <li>
  11787. <p>Use two-space indents.</p>
  11788. </li>
  11789. <li>
  11790. <p><code>true</code> and <code>false</code> are spelt thus (as opposed to <code>True</code>, etc.)</p>
  11791. </li>
  11792. <li>
  11793. <p>Use single quotes (<code>'</code>) rather than double-quotes (<code>&quot;</code>) or backticks
  11794. (<code>`</code>) to refer to configuration options.</p>
  11795. </li>
  11796. </ul>
  11797. <p>Example:</p>
  11798. <pre><code>## Frobnication ##
  11799. # The frobnicator will ensure that all requests are fully frobnicated.
  11800. # To enable it, uncomment the following.
  11801. #
  11802. #frobnicator_enabled: true
  11803. # By default, the frobnicator will frobnicate with the default frobber.
  11804. # The following will make it use an alternative frobber.
  11805. #
  11806. #frobincator_frobber: special_frobber
  11807. # Settings for the frobber
  11808. #
  11809. frobber:
  11810. # frobbing speed. Defaults to 1.
  11811. #
  11812. #speed: 10
  11813. # frobbing distance. Defaults to 1000.
  11814. #
  11815. #distance: 100
  11816. </code></pre>
  11817. <p>Note that the sample configuration is generated from the synapse code
  11818. and is maintained by a script, <code>scripts-dev/generate_sample_config</code>.
  11819. Making sure that the output from this script matches the desired format
  11820. is left as an exercise for the reader!</p>
  11821. <div style="break-before: page; page-break-before: always;"></div><h1 id="some-notes-on-how-we-use-git"><a class="header" href="#some-notes-on-how-we-use-git">Some notes on how we use git</a></h1>
  11822. <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>
  11823. <p>In an ideal world, our git commit history would be a linear progression of
  11824. commits each of which contains a single change building on what came
  11825. before. Here, by way of an arbitrary example, is the top of <code>git log --graph b2dba0607</code>:</p>
  11826. <img src="development/img/git/clean.png" alt="clean git graph" width="500px">
  11827. <p>Note how the commit comment explains clearly what is changing and why. Also
  11828. note the <em>absence</em> of merge commits, as well as the absence of commits called
  11829. things like (to pick a few culprits):
  11830. <a href="https://github.com/matrix-org/synapse/commit/84691da6c">“pep8”</a>, <a href="https://github.com/matrix-org/synapse/commit/474810d9d">“fix broken
  11831. test”</a>,
  11832. <a href="https://github.com/matrix-org/synapse/commit/c9d72e457">“oops”</a>,
  11833. <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
  11834. the president?”</a>.</p>
  11835. <p>There are a number of reasons why keeping a clean commit history is a good
  11836. thing:</p>
  11837. <ul>
  11838. <li>
  11839. <p>From time to time, after a change lands, it turns out to be necessary to
  11840. revert it, or to backport it to a release branch. Those operations are
  11841. <em>much</em> easier when the change is contained in a single commit.</p>
  11842. </li>
  11843. <li>
  11844. <p>Similarly, it's much easier to answer questions like “is the fix for
  11845. <code>/publicRooms</code> on the release branch?” if that change consists of a single
  11846. commit.</p>
  11847. </li>
  11848. <li>
  11849. <p>Likewise: “what has changed on this branch in the last week?” is much
  11850. clearer without merges and “pep8” commits everywhere.</p>
  11851. </li>
  11852. <li>
  11853. <p>Sometimes we need to figure out where a bug got introduced, or some
  11854. behaviour changed. One way of doing that is with <code>git bisect</code>: pick an
  11855. arbitrary commit between the known good point and the known bad point, and
  11856. see how the code behaves. However, that strategy fails if the commit you
  11857. chose is the middle of someone's epic branch in which they broke the world
  11858. before putting it back together again.</p>
  11859. </li>
  11860. </ul>
  11861. <p>One counterargument is that it is sometimes useful to see how a PR evolved as
  11862. it went through review cycles. This is true, but that information is always
  11863. 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
  11864. namespace</a>).</p>
  11865. <p>Of course, in reality, things are more complicated than that. We have release
  11866. branches as well as <code>develop</code> and <code>master</code>, and we deliberately merge changes
  11867. between them. Bugs often slip through and have to be fixed later. That's all
  11868. fine: this not a cast-iron rule which must be obeyed, but an ideal to aim
  11869. towards.</p>
  11870. <h2 id="merges-squashes-rebases-wtf"><a class="header" href="#merges-squashes-rebases-wtf">Merges, squashes, rebases: wtf?</a></h2>
  11871. <p>Ok, so that's what we'd like to achieve. How do we achieve it?</p>
  11872. <p>The TL;DR is: when you come to merge a pull request, you <em>probably</em> want to
  11873. “squash and merge”:</p>
  11874. <p><img src="development/img/git/squash.png" alt="squash and merge" />.</p>
  11875. <p>(This applies whether you are merging your own PR, or that of another
  11876. contributor.)</p>
  11877. <p>“Squash and merge”<sup id="a1"><a href="development/git.html#f1">1</a></sup> takes all of the changes in the
  11878. PR, and bundles them into a single commit. GitHub gives you the opportunity to
  11879. edit the commit message before you confirm, and normally you should do so,
  11880. because the default will be useless (again: <code>* woops typo</code> is not a useful
  11881. thing to keep in the historical record).</p>
  11882. <p>The main problem with this approach comes when you have a series of pull
  11883. requests which build on top of one another: as soon as you squash-merge the
  11884. first PR, you'll end up with a stack of conflicts to resolve in all of the
  11885. others. In general, it's best to avoid this situation in the first place by
  11886. trying not to have multiple related PRs in flight at the same time. Still,
  11887. sometimes that's not possible and doing a regular merge is the lesser evil.</p>
  11888. <p>Another occasion in which a regular merge makes more sense is a PR where you've
  11889. deliberately created a series of commits each of which makes sense in its own
  11890. right. For example: <a href="https://github.com/matrix-org/synapse/pull/6837">a PR which gradually propagates a refactoring operation
  11891. through the codebase</a>, or <a href="https://github.com/matrix-org/synapse/pull/5987">a
  11892. PR which is the culmination of several other
  11893. PRs</a>. In this case the ability
  11894. to figure out when a particular change/bug was introduced could be very useful.</p>
  11895. <p>Ultimately: <strong>this is not a hard-and-fast-rule</strong>. If in doubt, ask yourself “do
  11896. each of the commits I am about to merge make sense in their own right”, but
  11897. remember that we're just doing our best to balance “keeping the commit history
  11898. clean” with other factors.</p>
  11899. <h2 id="git-branching-model"><a class="header" href="#git-branching-model">Git branching model</a></h2>
  11900. <p>A <a href="https://nvie.com/posts/a-successful-git-branching-model/">lot</a>
  11901. <a href="http://scottchacon.com/2011/08/31/github-flow.html">of</a>
  11902. <a href="https://www.endoflineblog.com/gitflow-considered-harmful">words</a> have been
  11903. written in the past about git branching models (no really, <a href="https://martinfowler.com/articles/branching-patterns.html">a
  11904. lot</a>). I tend to
  11905. think the whole thing is overblown. Fundamentally, it's not that
  11906. complicated. Here's how we do it.</p>
  11907. <p>Let's start with a picture:</p>
  11908. <p><img src="development/img/git/branches.jpg" alt="branching model" /></p>
  11909. <p>It looks complicated, but it's really not. There's one basic rule: <em>anyone</em> is
  11910. free to merge from <em>any</em> more-stable branch to <em>any</em> less-stable branch at
  11911. <em>any</em> time<sup id="a2"><a href="development/git.html#f2">2</a></sup>. (The principle behind this is that if a
  11912. change is good enough for the more-stable branch, then it's also good enough go
  11913. put in a less-stable branch.)</p>
  11914. <p>Meanwhile, merging (or squashing, as per the above) from a less-stable to a
  11915. more-stable branch is a deliberate action in which you want to publish a change
  11916. or a set of changes to (some subset of) the world: for example, this happens
  11917. when a PR is landed, or as part of our release process.</p>
  11918. <p>So, what counts as a more- or less-stable branch? A little reflection will show
  11919. that our active branches are ordered thus, from more-stable to less-stable:</p>
  11920. <ul>
  11921. <li><code>master</code> (tracks our last release).</li>
  11922. <li><code>release-vX.Y</code> (the branch where we prepare the next release)<sup
  11923. id="a3"><a href="development/git.html#f3">3</a></sup>.</li>
  11924. <li>PR branches which are targeting the release.</li>
  11925. <li><code>develop</code> (our &quot;mainline&quot; branch containing our bleeding-edge).</li>
  11926. <li>regular PR branches.</li>
  11927. </ul>
  11928. <p>The corollary is: if you have a bugfix that needs to land in both
  11929. <code>release-vX.Y</code> <em>and</em> <code>develop</code>, then you should base your PR on
  11930. <code>release-vX.Y</code>, get it merged there, and then merge from <code>release-vX.Y</code> to
  11931. <code>develop</code>. (If a fix lands in <code>develop</code> and we later need it in a
  11932. release-branch, we can of course cherry-pick it, but landing it in the release
  11933. branch first helps reduce the chance of annoying conflicts.)</p>
  11934. <hr />
  11935. <p><b id="f1">[1]</b>: “Squash and merge” is GitHub's term for this
  11936. operation. Given that there is no merge involved, I'm not convinced it's the
  11937. most intuitive name. <a href="development/git.html#a1">^</a></p>
  11938. <p><b id="f2">[2]</b>: Well, anyone with commit access.<a href="development/git.html#a2">^</a></p>
  11939. <p><b id="f3">[3]</b>: Very, very occasionally (I think this has happened once in
  11940. the history of Synapse), we've had two releases in flight at once. Obviously,
  11941. <code>release-v1.2</code> is more-stable than <code>release-v1.3</code>. <a href="development/git.html#a3">^</a></p>
  11942. <div style="break-before: page; page-break-before: always;"></div><h1 id="opentracing"><a class="header" href="#opentracing">OpenTracing</a></h1>
  11943. <h2 id="background"><a class="header" href="#background">Background</a></h2>
  11944. <p>OpenTracing is a semi-standard being adopted by a number of distributed
  11945. tracing platforms. It is a common api for facilitating vendor-agnostic
  11946. tracing instrumentation. That is, we can use the OpenTracing api and
  11947. select one of a number of tracer implementations to do the heavy lifting
  11948. in the background. Our current selected implementation is Jaeger.</p>
  11949. <p>OpenTracing is a tool which gives an insight into the causal
  11950. relationship of work done in and between servers. The servers each track
  11951. events and report them to a centralised server - in Synapse's case:
  11952. Jaeger. The basic unit used to represent events is the span. The span
  11953. roughly represents a single piece of work that was done and the time at
  11954. which it occurred. A span can have child spans, meaning that the work of
  11955. the child had to be completed for the parent span to complete, or it can
  11956. have follow-on spans which represent work that is undertaken as a result
  11957. of the parent but is not depended on by the parent to in order to
  11958. finish.</p>
  11959. <p>Since this is undertaken in a distributed environment a request to
  11960. another server, such as an RPC or a simple GET, can be considered a span
  11961. (a unit or work) for the local server. This causal link is what
  11962. OpenTracing aims to capture and visualise. In order to do this metadata
  11963. about the local server's span, i.e the 'span context', needs to be
  11964. included with the request to the remote.</p>
  11965. <p>It is up to the remote server to decide what it does with the spans it
  11966. creates. This is called the sampling policy and it can be configured
  11967. through Jaeger's settings.</p>
  11968. <p>For OpenTracing concepts see
  11969. <a href="https://opentracing.io/docs/overview/what-is-tracing/">https://opentracing.io/docs/overview/what-is-tracing/</a>.</p>
  11970. <p>For more information about Jaeger's implementation see
  11971. <a href="https://www.jaegertracing.io/docs/">https://www.jaegertracing.io/docs/</a></p>
  11972. <h2 id="setting-up-opentracing"><a class="header" href="#setting-up-opentracing">Setting up OpenTracing</a></h2>
  11973. <p>To receive OpenTracing spans, start up a Jaeger server. This can be done
  11974. using docker like so:</p>
  11975. <pre><code class="language-sh">docker run -d --name jaeger \
  11976. -p 6831:6831/udp \
  11977. -p 6832:6832/udp \
  11978. -p 5778:5778 \
  11979. -p 16686:16686 \
  11980. -p 14268:14268 \
  11981. jaegertracing/all-in-one:1
  11982. </code></pre>
  11983. <p>Latest documentation is probably at
  11984. https://www.jaegertracing.io/docs/latest/getting-started.</p>
  11985. <h2 id="enable-opentracing-in-synapse"><a class="header" href="#enable-opentracing-in-synapse">Enable OpenTracing in Synapse</a></h2>
  11986. <p>OpenTracing is not enabled by default. It must be enabled in the
  11987. homeserver config by uncommenting the config options under <code>opentracing</code>
  11988. as shown in the <a href="./sample_config.yaml">sample config</a>. For example:</p>
  11989. <pre><code class="language-yaml">opentracing:
  11990. enabled: true
  11991. homeserver_whitelist:
  11992. - &quot;mytrustedhomeserver.org&quot;
  11993. - &quot;*.myotherhomeservers.com&quot;
  11994. </code></pre>
  11995. <h2 id="homeserver-whitelisting"><a class="header" href="#homeserver-whitelisting">Homeserver whitelisting</a></h2>
  11996. <p>The homeserver whitelist is configured using regular expressions. A list
  11997. of regular expressions can be given and their union will be compared
  11998. when propagating any spans contexts to another homeserver.</p>
  11999. <p>Though it's mostly safe to send and receive span contexts to and from
  12000. untrusted users since span contexts are usually opaque ids it can lead
  12001. to two problems, namely:</p>
  12002. <ul>
  12003. <li>If the span context is marked as sampled by the sending homeserver
  12004. the receiver will sample it. Therefore two homeservers with wildly
  12005. different sampling policies could incur higher sampling counts than
  12006. intended.</li>
  12007. <li>Sending servers can attach arbitrary data to spans, known as
  12008. 'baggage'. For safety this has been disabled in Synapse but that
  12009. doesn't prevent another server sending you baggage which will be
  12010. logged to OpenTracing's logs.</li>
  12011. </ul>
  12012. <h2 id="configuring-jaeger"><a class="header" href="#configuring-jaeger">Configuring Jaeger</a></h2>
  12013. <p>Sampling strategies can be set as in this document:
  12014. <a href="https://www.jaegertracing.io/docs/latest/sampling/">https://www.jaegertracing.io/docs/latest/sampling/</a>.</p>
  12015. <div style="break-before: page; page-break-before: always;"></div><h1 id="synapse-database-schema-files"><a class="header" href="#synapse-database-schema-files">Synapse database schema files</a></h1>
  12016. <p>Synapse's database schema is stored in the <code>synapse.storage.schema</code> module.</p>
  12017. <h2 id="logical-databases"><a class="header" href="#logical-databases">Logical databases</a></h2>
  12018. <p>Synapse supports splitting its datastore across multiple physical databases (which can
  12019. be useful for large installations), and the schema files are therefore split according
  12020. to the logical database they apply to.</p>
  12021. <p>At the time of writing, the following &quot;logical&quot; databases are supported:</p>
  12022. <ul>
  12023. <li><code>state</code> - used to store Matrix room state (more specifically, <code>state_groups</code>,
  12024. their relationships and contents).</li>
  12025. <li><code>main</code> - stores everything else.</li>
  12026. </ul>
  12027. <p>Additionally, the <code>common</code> directory contains schema files for tables which must be
  12028. present on <em>all</em> physical databases.</p>
  12029. <h2 id="synapse-schema-versions"><a class="header" href="#synapse-schema-versions">Synapse schema versions</a></h2>
  12030. <p>Synapse manages its database schema via &quot;schema versions&quot;. These are mainly used to
  12031. help avoid confusion if the Synapse codebase is rolled back after the database is
  12032. updated. They work as follows:</p>
  12033. <ul>
  12034. <li>
  12035. <p>The Synapse codebase defines a constant <code>synapse.storage.schema.SCHEMA_VERSION</code>
  12036. which represents the expectations made about the database by that version. For
  12037. example, as of Synapse v1.36, this is <code>59</code>.</p>
  12038. </li>
  12039. <li>
  12040. <p>The database stores a &quot;compatibility version&quot; in
  12041. <code>schema_compat_version.compat_version</code> which defines the <code>SCHEMA_VERSION</code> of the
  12042. oldest version of Synapse which will work with the database. On startup, if
  12043. <code>compat_version</code> is found to be newer than <code>SCHEMA_VERSION</code>, Synapse will refuse to
  12044. start.</p>
  12045. <p>Synapse automatically updates this field from
  12046. <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code>.</p>
  12047. </li>
  12048. <li>
  12049. <p>Whenever a backwards-incompatible change is made to the database format (normally
  12050. via a <code>delta</code> file), <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code> is also updated
  12051. so that administrators can not accidentally roll back to a too-old version of Synapse.</p>
  12052. </li>
  12053. </ul>
  12054. <p>Generally, the goal is to maintain compatibility with at least one or two previous
  12055. releases of Synapse, so any substantial change tends to require multiple releases and a
  12056. bit of forward-planning to get right.</p>
  12057. <p>As a worked example: we want to remove the <code>room_stats_historical</code> table. Here is how it
  12058. might pan out.</p>
  12059. <ol>
  12060. <li>
  12061. <p>Replace any code that <em>reads</em> from <code>room_stats_historical</code> with alternative
  12062. implementations, but keep writing to it in case of rollback to an earlier version.
  12063. Also, increase <code>synapse.storage.schema.SCHEMA_VERSION</code>. In this
  12064. instance, there is no existing code which reads from <code>room_stats_historical</code>, so
  12065. our starting point is:</p>
  12066. <p>v1.36.0: <code>SCHEMA_VERSION=59</code>, <code>SCHEMA_COMPAT_VERSION=59</code></p>
  12067. </li>
  12068. <li>
  12069. <p>Next (say in Synapse v1.37.0): remove the code that <em>writes</em> to
  12070. <code>room_stats_historical</code>, but don’t yet remove the table in case of rollback to
  12071. v1.36.0. Again, we increase <code>synapse.storage.schema.SCHEMA_VERSION</code>, but
  12072. because we have not broken compatibility with v1.36, we do not yet update
  12073. <code>SCHEMA_COMPAT_VERSION</code>. We now have:</p>
  12074. <p>v1.37.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=59</code>.</p>
  12075. </li>
  12076. <li>
  12077. <p>Later (say in Synapse v1.38.0): we can remove the table altogether. This will
  12078. break compatibility with v1.36.0, so we must update <code>SCHEMA_COMPAT_VERSION</code> accordingly.
  12079. There is no need to update <code>synapse.storage.schema.SCHEMA_VERSION</code>, since there is no
  12080. change to the Synapse codebase here. So we end up with:</p>
  12081. <p>v1.38.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=60</code>.</p>
  12082. </li>
  12083. </ol>
  12084. <p>If in doubt about whether to update <code>SCHEMA_VERSION</code> or not, it is generally best to
  12085. lean towards doing so.</p>
  12086. <h2 id="full-schema-dumps"><a class="header" href="#full-schema-dumps">Full schema dumps</a></h2>
  12087. <p>In the <code>full_schemas</code> directories, only the most recently-numbered snapshot is used
  12088. (<code>54</code> at the time of writing). Older snapshots (eg, <code>16</code>) are present for historical
  12089. reference only.</p>
  12090. <h3 id="building-full-schema-dumps"><a class="header" href="#building-full-schema-dumps">Building full schema dumps</a></h3>
  12091. <p>If you want to recreate these schemas, they need to be made from a database that
  12092. has had all background updates run.</p>
  12093. <p>To do so, use <code>scripts-dev/make_full_schema.sh</code>. This will produce new
  12094. <code>full.sql.postgres</code> and <code>full.sql.sqlite</code> files.</p>
  12095. <p>Ensure postgres is installed, then run:</p>
  12096. <pre><code>./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
  12097. </code></pre>
  12098. <p>NB at the time of writing, this script predates the split into separate <code>state</code>/<code>main</code>
  12099. databases so will require updates to handle that correctly.</p>
  12100. <h2 id="boolean-columns"><a class="header" href="#boolean-columns">Boolean columns</a></h2>
  12101. <p>Boolean columns require special treatment, since SQLite treats booleans the
  12102. same as integers.</p>
  12103. <p>There are three separate aspects to this:</p>
  12104. <ul>
  12105. <li>
  12106. <p>Any new boolean column must be added to the <code>BOOLEAN_COLUMNS</code> list in
  12107. <code>scripts/synapse_port_db</code>. This tells the port script to cast the integer
  12108. value from SQLite to a boolean before writing the value to the postgres
  12109. database.</p>
  12110. </li>
  12111. <li>
  12112. <p>Before SQLite 3.23, <code>TRUE</code> and <code>FALSE</code> were not recognised as constants by
  12113. SQLite, and the <code>IS [NOT] TRUE</code>/<code>IS [NOT] FALSE</code> operators were not
  12114. supported. This makes it necessary to avoid using <code>TRUE</code> and <code>FALSE</code>
  12115. constants in SQL commands.</p>
  12116. <p>For example, to insert a <code>TRUE</code> value into the database, write:</p>
  12117. <pre><code class="language-python">txn.execute(&quot;INSERT INTO tbl(col) VALUES (?)&quot;, (True, ))
  12118. </code></pre>
  12119. </li>
  12120. <li>
  12121. <p>Default values for new boolean columns present a particular
  12122. difficulty. Generally it is best to create separate schema files for
  12123. Postgres and SQLite. For example:</p>
  12124. <pre><code class="language-sql"># in 00delta.sql.postgres:
  12125. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT FALSE;
  12126. </code></pre>
  12127. <pre><code class="language-sql"># in 00delta.sql.sqlite:
  12128. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT 0;
  12129. </code></pre>
  12130. <p>Note that there is a particularly insidious failure mode here: the Postgres
  12131. flavour will be accepted by SQLite 3.22, but will give a column whose
  12132. default value is the <strong>string</strong> <code>&quot;FALSE&quot;</code> - which, when cast back to a boolean
  12133. in Python, evaluates to <code>True</code>.</p>
  12134. </li>
  12135. </ul>
  12136. <div style="break-before: page; page-break-before: always;"></div><h1 id="implementing-experimental-features-in-synapse"><a class="header" href="#implementing-experimental-features-in-synapse">Implementing experimental features in Synapse</a></h1>
  12137. <p>It can be desirable to implement &quot;experimental&quot; features which are disabled by
  12138. default and must be explicitly enabled via the Synapse configuration. This is
  12139. applicable for features which:</p>
  12140. <ul>
  12141. <li>Are unstable in the Matrix spec (e.g. those defined by an MSC that has not yet been merged).</li>
  12142. <li>Developers are not confident in their use by general Synapse administrators/users
  12143. (e.g. a feature is incomplete, buggy, performs poorly, or needs further testing).</li>
  12144. </ul>
  12145. <p>Note that this only really applies to features which are expected to be desirable
  12146. to a broad audience. The <a href="development/../modules/index.html">module infrastructure</a> should
  12147. instead be investigated for non-standard features.</p>
  12148. <p>Guarding experimental features behind configuration flags should help with some
  12149. of the following scenarios:</p>
  12150. <ul>
  12151. <li>Ensure that clients do not assume that unstable features exist (failing
  12152. gracefully if they do not).</li>
  12153. <li>Unstable features do not become de-facto standards and can be removed
  12154. aggressively (since only those who have opted-in will be affected).</li>
  12155. <li>Ease finding the implementation of unstable features in Synapse (for future
  12156. removal or stabilization).</li>
  12157. <li>Ease testing a feature (or removal of feature) due to enabling/disabling without
  12158. code changes. It also becomes possible to ask for wider testing, if desired.</li>
  12159. </ul>
  12160. <p>Experimental configuration flags should be disabled by default (requiring Synapse
  12161. administrators to explicitly opt-in), although there are situations where it makes
  12162. sense (from a product point-of-view) to enable features by default. This is
  12163. expected and not an issue.</p>
  12164. <p>It is not a requirement for experimental features to be behind a configuration flag,
  12165. but one should be used if unsure.</p>
  12166. <p>New experimental configuration flags should be added under the <code>experimental</code>
  12167. configuration key (see the <code>synapse.config.experimental</code> file) and either explain
  12168. (briefly) what is being enabled, or include the MSC number.</p>
  12169. <div style="break-before: page; page-break-before: always;"></div><h1 id="log-contexts"><a class="header" href="#log-contexts">Log Contexts</a></h1>
  12170. <p>To help track the processing of individual requests, synapse uses a
  12171. '<code>log context</code>' to track which request it is handling at any given
  12172. moment. This is done via a thread-local variable; a <code>logging.Filter</code> is
  12173. then used to fish the information back out of the thread-local variable
  12174. and add it to each log record.</p>
  12175. <p>Logcontexts are also used for CPU and database accounting, so that we
  12176. can track which requests were responsible for high CPU use or database
  12177. activity.</p>
  12178. <p>The <code>synapse.logging.context</code> module provides facilities for managing
  12179. the current log context (as well as providing the <code>LoggingContextFilter</code>
  12180. class).</p>
  12181. <p>Asynchronous functions make the whole thing complicated, so this document describes
  12182. how it all works, and how to write code which follows the rules.</p>
  12183. <p>In this document, &quot;awaitable&quot; refers to any object which can be <code>await</code>ed. In the context of
  12184. Synapse, that normally means either a coroutine or a Twisted
  12185. <a href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html"><code>Deferred</code></a>.</p>
  12186. <h2 id="logcontexts-without-asynchronous-code"><a class="header" href="#logcontexts-without-asynchronous-code">Logcontexts without asynchronous code</a></h2>
  12187. <p>In the absence of any asynchronous voodoo, things are simple enough. As with
  12188. any code of this nature, the rule is that our function should leave
  12189. things as it found them:</p>
  12190. <pre><code class="language-python">from synapse.logging import context # omitted from future snippets
  12191. def handle_request(request_id):
  12192. request_context = context.LoggingContext()
  12193. calling_context = context.set_current_context(request_context)
  12194. try:
  12195. request_context.request = request_id
  12196. do_request_handling()
  12197. logger.debug(&quot;finished&quot;)
  12198. finally:
  12199. context.set_current_context(calling_context)
  12200. def do_request_handling():
  12201. logger.debug(&quot;phew&quot;) # this will be logged against request_id
  12202. </code></pre>
  12203. <p>LoggingContext implements the context management methods, so the above
  12204. can be written much more succinctly as:</p>
  12205. <pre><code class="language-python">def handle_request(request_id):
  12206. with context.LoggingContext() as request_context:
  12207. request_context.request = request_id
  12208. do_request_handling()
  12209. logger.debug(&quot;finished&quot;)
  12210. def do_request_handling():
  12211. logger.debug(&quot;phew&quot;)
  12212. </code></pre>
  12213. <h2 id="using-logcontexts-with-awaitables"><a class="header" href="#using-logcontexts-with-awaitables">Using logcontexts with awaitables</a></h2>
  12214. <p>Awaitables break the linear flow of code so that there is no longer a single entry point
  12215. where we should set the logcontext and a single exit point where we should remove it.</p>
  12216. <p>Consider the example above, where <code>do_request_handling</code> needs to do some
  12217. blocking operation, and returns an awaitable:</p>
  12218. <pre><code class="language-python">async def handle_request(request_id):
  12219. with context.LoggingContext() as request_context:
  12220. request_context.request = request_id
  12221. await do_request_handling()
  12222. logger.debug(&quot;finished&quot;)
  12223. </code></pre>
  12224. <p>In the above flow:</p>
  12225. <ul>
  12226. <li>The logcontext is set</li>
  12227. <li><code>do_request_handling</code> is called, and returns an awaitable</li>
  12228. <li><code>handle_request</code> awaits the awaitable</li>
  12229. <li>Execution of <code>handle_request</code> is suspended</li>
  12230. </ul>
  12231. <p>So we have stopped processing the request (and will probably go on to
  12232. start processing the next), without clearing the logcontext.</p>
  12233. <p>To circumvent this problem, synapse code assumes that, wherever you have
  12234. an awaitable, you will want to <code>await</code> it. To that end, whereever
  12235. functions return awaitables, we adopt the following conventions:</p>
  12236. <p><strong>Rules for functions returning awaitables:</strong></p>
  12237. <blockquote>
  12238. <ul>
  12239. <li>If the awaitable is already complete, the function returns with the
  12240. same logcontext it started with.</li>
  12241. <li>If the awaitable is incomplete, the function clears the logcontext
  12242. before returning; when the awaitable completes, it restores the
  12243. logcontext before running any callbacks.</li>
  12244. </ul>
  12245. </blockquote>
  12246. <p>That sounds complicated, but actually it means a lot of code (including
  12247. the example above) &quot;just works&quot;. There are two cases:</p>
  12248. <ul>
  12249. <li>
  12250. <p>If <code>do_request_handling</code> returns a completed awaitable, then the
  12251. logcontext will still be in place. In this case, execution will
  12252. continue immediately after the <code>await</code>; the &quot;finished&quot; line will
  12253. be logged against the right context, and the <code>with</code> block restores
  12254. the original context before we return to the caller.</p>
  12255. </li>
  12256. <li>
  12257. <p>If the returned awaitable is incomplete, <code>do_request_handling</code> clears
  12258. the logcontext before returning. The logcontext is therefore clear
  12259. when <code>handle_request</code> <code>await</code>s the awaitable.</p>
  12260. <p>Once <code>do_request_handling</code>'s awaitable completes, it will reinstate
  12261. the logcontext, before running the second half of <code>handle_request</code>,
  12262. so again the &quot;finished&quot; line will be logged against the right context,
  12263. and the <code>with</code> block restores the original context.</p>
  12264. </li>
  12265. </ul>
  12266. <p>As an aside, it's worth noting that <code>handle_request</code> follows our rules</p>
  12267. <ul>
  12268. <li>though that only matters if the caller has its own logcontext which it
  12269. cares about.</li>
  12270. </ul>
  12271. <p>The following sections describe pitfalls and helpful patterns when
  12272. implementing these rules.</p>
  12273. <h2 id="always-await-your-awaitables"><a class="header" href="#always-await-your-awaitables">Always await your awaitables</a></h2>
  12274. <p>Whenever you get an awaitable back from a function, you should <code>await</code> on
  12275. it as soon as possible. Do not pass go; do not do any logging; do not
  12276. call any other functions.</p>
  12277. <pre><code class="language-python">async def fun():
  12278. logger.debug(&quot;starting&quot;)
  12279. await do_some_stuff() # just like this
  12280. coro = more_stuff()
  12281. result = await coro # also fine, of course
  12282. return result
  12283. </code></pre>
  12284. <p>Provided this pattern is followed all the way back up to the callchain
  12285. to where the logcontext was set, this will make things work out ok:
  12286. provided <code>do_some_stuff</code> and <code>more_stuff</code> follow the rules above, then
  12287. so will <code>fun</code>.</p>
  12288. <p>It's all too easy to forget to <code>await</code>: for instance if we forgot that
  12289. <code>do_some_stuff</code> returned an awaitable, we might plough on regardless. This
  12290. leads to a mess; it will probably work itself out eventually, but not
  12291. before a load of stuff has been logged against the wrong context.
  12292. (Normally, other things will break, more obviously, if you forget to
  12293. <code>await</code>, so this tends not to be a major problem in practice.)</p>
  12294. <p>Of course sometimes you need to do something a bit fancier with your
  12295. awaitable - not all code follows the linear A-then-B-then-C pattern.
  12296. Notes on implementing more complex patterns are in later sections.</p>
  12297. <h2 id="where-you-create-a-new-awaitable-make-it-follow-the-rules"><a class="header" href="#where-you-create-a-new-awaitable-make-it-follow-the-rules">Where you create a new awaitable, make it follow the rules</a></h2>
  12298. <p>Most of the time, an awaitable comes from another synapse function.
  12299. Sometimes, though, we need to make up a new awaitable, or we get an awaitable
  12300. back from external code. We need to make it follow our rules.</p>
  12301. <p>The easy way to do it is by using <code>context.make_deferred_yieldable</code>. Suppose we want to implement
  12302. <code>sleep</code>, which returns a deferred which will run its callbacks after a
  12303. given number of seconds. That might look like:</p>
  12304. <pre><code class="language-python"># not a logcontext-rules-compliant function
  12305. def get_sleep_deferred(seconds):
  12306. d = defer.Deferred()
  12307. reactor.callLater(seconds, d.callback, None)
  12308. return d
  12309. </code></pre>
  12310. <p>That doesn't follow the rules, but we can fix it by calling it through
  12311. <code>context.make_deferred_yieldable</code>:</p>
  12312. <pre><code class="language-python">async def sleep(seconds):
  12313. return await context.make_deferred_yieldable(get_sleep_deferred(seconds))
  12314. </code></pre>
  12315. <h2 id="fire-and-forget"><a class="header" href="#fire-and-forget">Fire-and-forget</a></h2>
  12316. <p>Sometimes you want to fire off a chain of execution, but not wait for
  12317. its result. That might look a bit like this:</p>
  12318. <pre><code class="language-python">async def do_request_handling():
  12319. await foreground_operation()
  12320. # *don't* do this
  12321. background_operation()
  12322. logger.debug(&quot;Request handling complete&quot;)
  12323. async def background_operation():
  12324. await first_background_step()
  12325. logger.debug(&quot;Completed first step&quot;)
  12326. await second_background_step()
  12327. logger.debug(&quot;Completed second step&quot;)
  12328. </code></pre>
  12329. <p>The above code does a couple of steps in the background after
  12330. <code>do_request_handling</code> has finished. The log lines are still logged
  12331. against the <code>request_context</code> logcontext, which may or may not be
  12332. desirable. There are two big problems with the above, however. The first
  12333. problem is that, if <code>background_operation</code> returns an incomplete
  12334. awaitable, it will expect its caller to <code>await</code> immediately, so will have
  12335. cleared the logcontext. In this example, that means that 'Request
  12336. handling complete' will be logged without any context.</p>
  12337. <p>The second problem, which is potentially even worse, is that when the
  12338. awaitable returned by <code>background_operation</code> completes, it will restore
  12339. the original logcontext. There is nothing waiting on that awaitable, so
  12340. the logcontext will leak into the reactor and possibly get attached to
  12341. some arbitrary future operation.</p>
  12342. <p>There are two potential solutions to this.</p>
  12343. <p>One option is to surround the call to <code>background_operation</code> with a
  12344. <code>PreserveLoggingContext</code> call. That will reset the logcontext before
  12345. starting <code>background_operation</code> (so the context restored when the
  12346. deferred completes will be the empty logcontext), and will restore the
  12347. current logcontext before continuing the foreground process:</p>
  12348. <pre><code class="language-python">async def do_request_handling():
  12349. await foreground_operation()
  12350. # start background_operation off in the empty logcontext, to
  12351. # avoid leaking the current context into the reactor.
  12352. with PreserveLoggingContext():
  12353. background_operation()
  12354. # this will now be logged against the request context
  12355. logger.debug(&quot;Request handling complete&quot;)
  12356. </code></pre>
  12357. <p>Obviously that option means that the operations done in
  12358. <code>background_operation</code> would be not be logged against a logcontext
  12359. (though that might be fixed by setting a different logcontext via a
  12360. <code>with LoggingContext(...)</code> in <code>background_operation</code>).</p>
  12361. <p>The second option is to use <code>context.run_in_background</code>, which wraps a
  12362. function so that it doesn't reset the logcontext even when it returns
  12363. an incomplete awaitable, and adds a callback to the returned awaitable to
  12364. reset the logcontext. In other words, it turns a function that follows
  12365. the Synapse rules about logcontexts and awaitables into one which behaves
  12366. more like an external function --- the opposite operation to that
  12367. described in the previous section. It can be used like this:</p>
  12368. <pre><code class="language-python">async def do_request_handling():
  12369. await foreground_operation()
  12370. context.run_in_background(background_operation)
  12371. # this will now be logged against the request context
  12372. logger.debug(&quot;Request handling complete&quot;)
  12373. </code></pre>
  12374. <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>
  12375. <p>A typical example of this is where we want to collect together two or
  12376. more awaitables via <code>defer.gatherResults</code>:</p>
  12377. <pre><code class="language-python">a1 = operation1()
  12378. a2 = operation2()
  12379. a3 = defer.gatherResults([a1, a2])
  12380. </code></pre>
  12381. <p>This is really a variation of the fire-and-forget problem above, in that
  12382. we are firing off <code>a1</code> and <code>a2</code> without awaiting on them. The difference
  12383. is that we now have third-party code attached to their callbacks. Anyway
  12384. either technique given in the <a href="log_contexts.html#fire-and-forget">Fire-and-forget</a>
  12385. section will work.</p>
  12386. <p>Of course, the new awaitable returned by <code>gather</code> needs to be
  12387. wrapped in order to make it follow the logcontext rules before we can
  12388. yield it, as described in <a href="log_contexts.html#where-you-create-a-new-awaitable-make-it-follow-the-rules">Where you create a new awaitable, make it
  12389. follow the
  12390. rules</a>.</p>
  12391. <p>So, option one: reset the logcontext before starting the operations to
  12392. be gathered:</p>
  12393. <pre><code class="language-python">async def do_request_handling():
  12394. with PreserveLoggingContext():
  12395. a1 = operation1()
  12396. a2 = operation2()
  12397. result = await defer.gatherResults([a1, a2])
  12398. </code></pre>
  12399. <p>In this case particularly, though, option two, of using
  12400. <code>context.run_in_background</code> almost certainly makes more sense, so that
  12401. <code>operation1</code> and <code>operation2</code> are both logged against the original
  12402. logcontext. This looks like:</p>
  12403. <pre><code class="language-python">async def do_request_handling():
  12404. a1 = context.run_in_background(operation1)
  12405. a2 = context.run_in_background(operation2)
  12406. result = await make_deferred_yieldable(defer.gatherResults([a1, a2]))
  12407. </code></pre>
  12408. <h2 id="a-note-on-garbage-collection-of-awaitable-chains"><a class="header" href="#a-note-on-garbage-collection-of-awaitable-chains">A note on garbage-collection of awaitable chains</a></h2>
  12409. <p>It turns out that our logcontext rules do not play nicely with awaitable
  12410. chains which get orphaned and garbage-collected.</p>
  12411. <p>Imagine we have some code that looks like this:</p>
  12412. <pre><code class="language-python">listener_queue = []
  12413. def on_something_interesting():
  12414. for d in listener_queue:
  12415. d.callback(&quot;foo&quot;)
  12416. async def await_something_interesting():
  12417. new_awaitable = defer.Deferred()
  12418. listener_queue.append(new_awaitable)
  12419. with PreserveLoggingContext():
  12420. await new_awaitable
  12421. </code></pre>
  12422. <p>Obviously, the idea here is that we have a bunch of things which are
  12423. waiting for an event. (It's just an example of the problem here, but a
  12424. relatively common one.)</p>
  12425. <p>Now let's imagine two further things happen. First of all, whatever was
  12426. waiting for the interesting thing goes away. (Perhaps the request times
  12427. out, or something <em>even more</em> interesting happens.)</p>
  12428. <p>Secondly, let's suppose that we decide that the interesting thing is
  12429. never going to happen, and we reset the listener queue:</p>
  12430. <pre><code class="language-python">def reset_listener_queue():
  12431. listener_queue.clear()
  12432. </code></pre>
  12433. <p>So, both ends of the awaitable chain have now dropped their references,
  12434. and the awaitable chain is now orphaned, and will be garbage-collected at
  12435. some point. Note that <code>await_something_interesting</code> is a coroutine,
  12436. which Python implements as a generator function. When Python
  12437. garbage-collects generator functions, it gives them a chance to
  12438. clean up by making the <code>await</code> (or <code>yield</code>) raise a <code>GeneratorExit</code>
  12439. exception. In our case, that means that the <code>__exit__</code> handler of
  12440. <code>PreserveLoggingContext</code> will carefully restore the request context, but
  12441. there is now nothing waiting for its return, so the request context is
  12442. never cleared.</p>
  12443. <p>To reiterate, this problem only arises when <em>both</em> ends of a awaitable
  12444. chain are dropped. Dropping the the reference to an awaitable you're
  12445. supposed to be awaiting is bad practice, so this doesn't
  12446. actually happen too much. Unfortunately, when it does happen, it will
  12447. lead to leaked logcontexts which are incredibly hard to track down.</p>
  12448. <div style="break-before: page; page-break-before: always;"></div><h1 id="replication-architecture"><a class="header" href="#replication-architecture">Replication Architecture</a></h1>
  12449. <h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
  12450. <p>We'd like to be able to split some of the work that synapse does into
  12451. multiple python processes. In theory multiple synapse processes could
  12452. share a single postgresql database and we'd scale up by running more
  12453. synapse processes. However much of synapse assumes that only one process
  12454. is interacting with the database, both for assigning unique identifiers
  12455. when inserting into tables, notifying components about new updates, and
  12456. for invalidating its caches.</p>
  12457. <p>So running multiple copies of the current code isn't an option. One way
  12458. to run multiple processes would be to have a single writer process and
  12459. multiple reader processes connected to the same database. In order to do
  12460. this we'd need a way for the reader process to invalidate its in-memory
  12461. caches when an update happens on the writer. One way to do this is for
  12462. the writer to present an append-only log of updates which the readers
  12463. can consume to invalidate their caches and to push updates to listening
  12464. clients or pushers.</p>
  12465. <p>Synapse already stores much of its data as an append-only log so that it
  12466. can correctly respond to <code>/sync</code> requests so the amount of code changes
  12467. needed to expose the append-only log to the readers should be fairly
  12468. minimal.</p>
  12469. <h2 id="architecture"><a class="header" href="#architecture">Architecture</a></h2>
  12470. <h3 id="the-replication-protocol"><a class="header" href="#the-replication-protocol">The Replication Protocol</a></h3>
  12471. <p>See <a href="tcp_replication.html">the TCP replication documentation</a>.</p>
  12472. <h3 id="the-slaved-datastore"><a class="header" href="#the-slaved-datastore">The Slaved DataStore</a></h3>
  12473. <p>There are read-only version of the synapse storage layer in
  12474. <code>synapse/replication/slave/storage</code> that use the response of the
  12475. replication API to invalidate their caches.</p>
  12476. <div style="break-before: page; page-break-before: always;"></div><h1 id="tcp-replication"><a class="header" href="#tcp-replication">TCP Replication</a></h1>
  12477. <h2 id="motivation-1"><a class="header" href="#motivation-1">Motivation</a></h2>
  12478. <p>Previously the workers used an HTTP long poll mechanism to get updates
  12479. from the master, which had the problem of causing a lot of duplicate
  12480. work on the server. This TCP protocol replaces those APIs with the aim
  12481. of increased efficiency.</p>
  12482. <h2 id="overview-3"><a class="header" href="#overview-3">Overview</a></h2>
  12483. <p>The protocol is based on fire and forget, line based commands. An
  12484. example flow would be (where '&gt;' indicates master to worker and
  12485. '&lt;' worker to master flows):</p>
  12486. <pre><code>&gt; SERVER example.com
  12487. &lt; REPLICATE
  12488. &gt; POSITION events master 53 53
  12489. &gt; RDATA events master 54 [&quot;$foo1:bar.com&quot;, ...]
  12490. &gt; RDATA events master 55 [&quot;$foo4:bar.com&quot;, ...]
  12491. </code></pre>
  12492. <p>The example shows the server accepting a new connection and sending its identity
  12493. with the <code>SERVER</code> command, followed by the client server to respond with the
  12494. position of all streams. The server then periodically sends <code>RDATA</code> commands
  12495. which have the format <code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row&gt;</code>, where
  12496. the format of <code>&lt;row&gt;</code> is defined by the individual streams. The
  12497. <code>&lt;instance_name&gt;</code> is the name of the Synapse process that generated the data
  12498. (usually &quot;master&quot;).</p>
  12499. <p>Error reporting happens by either the client or server sending an ERROR
  12500. command, and usually the connection will be closed.</p>
  12501. <p>Since the protocol is a simple line based, its possible to manually
  12502. connect to the server using a tool like netcat. A few things should be
  12503. noted when manually using the protocol:</p>
  12504. <ul>
  12505. <li>The federation stream is only available if federation sending has
  12506. been disabled on the main process.</li>
  12507. <li>The server will only time connections out that have sent a <code>PING</code>
  12508. command. If a ping is sent then the connection will be closed if no
  12509. further commands are receieved within 15s. Both the client and
  12510. server protocol implementations will send an initial PING on
  12511. connection and ensure at least one command every 5s is sent (not
  12512. necessarily <code>PING</code>).</li>
  12513. <li><code>RDATA</code> commands <em>usually</em> include a numeric token, however if the
  12514. stream has multiple rows to replicate per token the server will send
  12515. multiple <code>RDATA</code> commands, with all but the last having a token of
  12516. <code>batch</code>. See the documentation on <code>commands.RdataCommand</code> for
  12517. further details.</li>
  12518. </ul>
  12519. <h2 id="architecture-1"><a class="header" href="#architecture-1">Architecture</a></h2>
  12520. <p>The basic structure of the protocol is line based, where the initial
  12521. word of each line specifies the command. The rest of the line is parsed
  12522. based on the command. For example, the RDATA command is defined as:</p>
  12523. <pre><code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row_json&gt;
  12524. </code></pre>
  12525. <p>(Note that &lt;row_json&gt; may contains spaces, but cannot contain
  12526. newlines.)</p>
  12527. <p>Blank lines are ignored.</p>
  12528. <h3 id="keep-alives"><a class="header" href="#keep-alives">Keep alives</a></h3>
  12529. <p>Both sides are expected to send at least one command every 5s or so, and
  12530. should send a <code>PING</code> command if necessary. If either side do not receive
  12531. a command within e.g. 15s then the connection should be closed.</p>
  12532. <p>Because the server may be connected to manually using e.g. netcat, the
  12533. timeouts aren't enabled until an initial <code>PING</code> command is seen. Both
  12534. the client and server implementations below send a <code>PING</code> command
  12535. immediately on connection to ensure the timeouts are enabled.</p>
  12536. <p>This ensures that both sides can quickly realize if the tcp connection
  12537. has gone and handle the situation appropriately.</p>
  12538. <h3 id="start-up"><a class="header" href="#start-up">Start up</a></h3>
  12539. <p>When a new connection is made, the server:</p>
  12540. <ul>
  12541. <li>Sends a <code>SERVER</code> command, which includes the identity of the server,
  12542. allowing the client to detect if its connected to the expected
  12543. server</li>
  12544. <li>Sends a <code>PING</code> command as above, to enable the client to time out
  12545. connections promptly.</li>
  12546. </ul>
  12547. <p>The client:</p>
  12548. <ul>
  12549. <li>Sends a <code>NAME</code> command, allowing the server to associate a human
  12550. friendly name with the connection. This is optional.</li>
  12551. <li>Sends a <code>PING</code> as above</li>
  12552. <li>Sends a <code>REPLICATE</code> to get the current position of all streams.</li>
  12553. <li>On receipt of a <code>SERVER</code> command, checks that the server name
  12554. matches the expected server name.</li>
  12555. </ul>
  12556. <h3 id="error-handling"><a class="header" href="#error-handling">Error handling</a></h3>
  12557. <p>If either side detects an error it can send an <code>ERROR</code> command and close
  12558. the connection.</p>
  12559. <p>If the client side loses the connection to the server it should
  12560. reconnect, following the steps above.</p>
  12561. <h3 id="congestion"><a class="header" href="#congestion">Congestion</a></h3>
  12562. <p>If the server sends messages faster than the client can consume them the
  12563. server will first buffer a (fairly large) number of commands and then
  12564. disconnect the client. This ensures that we don't queue up an unbounded
  12565. number of commands in memory and gives us a potential oppurtunity to
  12566. squawk loudly. When/if the client recovers it can reconnect to the
  12567. server and ask for missed messages.</p>
  12568. <h3 id="reliability"><a class="header" href="#reliability">Reliability</a></h3>
  12569. <p>In general the replication stream should be considered an unreliable
  12570. transport since e.g. commands are not resent if the connection
  12571. disappears.</p>
  12572. <p>The exception to that are the replication streams, i.e. RDATA commands,
  12573. since these include tokens which can be used to restart the stream on
  12574. connection errors.</p>
  12575. <p>The client should keep track of the token in the last RDATA command
  12576. received for each stream so that on reconneciton it can start streaming
  12577. from the correct place. Note: not all RDATA have valid tokens due to
  12578. batching. See <code>RdataCommand</code> for more details.</p>
  12579. <h3 id="example-4"><a class="header" href="#example-4">Example</a></h3>
  12580. <p>An example iteraction is shown below. Each line is prefixed with '&gt;'
  12581. or '&lt;' to indicate which side is sending, these are <em>not</em> included on
  12582. the wire:</p>
  12583. <pre><code>* connection established *
  12584. &gt; SERVER localhost:8823
  12585. &gt; PING 1490197665618
  12586. &lt; NAME synapse.app.appservice
  12587. &lt; PING 1490197665618
  12588. &lt; REPLICATE
  12589. &gt; POSITION events master 1 1
  12590. &gt; POSITION backfill master 1 1
  12591. &gt; POSITION caches master 1 1
  12592. &gt; RDATA caches master 2 [&quot;get_user_by_id&quot;,[&quot;@01register-user:localhost:8823&quot;],1490197670513]
  12593. &gt; RDATA events master 14 [&quot;$149019767112vOHxz:localhost:8823&quot;,
  12594. &quot;!AFDCvgApUmpdfVjIXm:localhost:8823&quot;,&quot;m.room.guest_access&quot;,&quot;&quot;,null]
  12595. &lt; PING 1490197675618
  12596. &gt; ERROR server stopping
  12597. * connection closed by server *
  12598. </code></pre>
  12599. <p>The <code>POSITION</code> command sent by the server is used to set the clients
  12600. position without needing to send data with the <code>RDATA</code> command.</p>
  12601. <p>An example of a batched set of <code>RDATA</code> is:</p>
  12602. <pre><code>&gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test:localhost:8823&quot;],1490197670513]
  12603. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test2:localhost:8823&quot;],1490197670513]
  12604. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test3:localhost:8823&quot;],1490197670513]
  12605. &gt; RDATA caches master 54 [&quot;get_user_by_id&quot;,[&quot;@test4:localhost:8823&quot;],1490197670513]
  12606. </code></pre>
  12607. <p>In this case the client shouldn't advance their caches token until it
  12608. sees the the last <code>RDATA</code>.</p>
  12609. <h3 id="list-of-commands"><a class="header" href="#list-of-commands">List of commands</a></h3>
  12610. <p>The list of valid commands, with which side can send it: server (S) or
  12611. client (C):</p>
  12612. <h4 id="server-s"><a class="header" href="#server-s">SERVER (S)</a></h4>
  12613. <p>Sent at the start to identify which server the client is talking to</p>
  12614. <h4 id="rdata-s"><a class="header" href="#rdata-s">RDATA (S)</a></h4>
  12615. <p>A single update in a stream</p>
  12616. <h4 id="position-s"><a class="header" href="#position-s">POSITION (S)</a></h4>
  12617. <p>On receipt of a POSITION command clients should check if they have missed any
  12618. updates, and if so then fetch them out of band. Sent in response to a
  12619. REPLICATE command (but can happen at any time).</p>
  12620. <p>The POSITION command includes the source of the stream. Currently all streams
  12621. are written by a single process (usually &quot;master&quot;). If fetching missing
  12622. updates via HTTP API, rather than via the DB, then processes should make the
  12623. request to the appropriate process.</p>
  12624. <p>Two positions are included, the &quot;new&quot; position and the last position sent respectively.
  12625. This allows servers to tell instances that the positions have advanced but no
  12626. data has been written, without clients needlessly checking to see if they
  12627. have missed any updates.</p>
  12628. <h4 id="error-s-c"><a class="header" href="#error-s-c">ERROR (S, C)</a></h4>
  12629. <p>There was an error</p>
  12630. <h4 id="ping-s-c"><a class="header" href="#ping-s-c">PING (S, C)</a></h4>
  12631. <p>Sent periodically to ensure the connection is still alive</p>
  12632. <h4 id="name-c"><a class="header" href="#name-c">NAME (C)</a></h4>
  12633. <p>Sent at the start by client to inform the server who they are</p>
  12634. <h4 id="replicate-c"><a class="header" href="#replicate-c">REPLICATE (C)</a></h4>
  12635. <p>Asks the server for the current position of all streams.</p>
  12636. <h4 id="user_sync-c"><a class="header" href="#user_sync-c">USER_SYNC (C)</a></h4>
  12637. <p>A user has started or stopped syncing on this process.</p>
  12638. <h4 id="clear_user_sync-c"><a class="header" href="#clear_user_sync-c">CLEAR_USER_SYNC (C)</a></h4>
  12639. <p>The server should clear all associated user sync data from the worker.</p>
  12640. <p>This is used when a worker is shutting down.</p>
  12641. <h4 id="federation_ack-c"><a class="header" href="#federation_ack-c">FEDERATION_ACK (C)</a></h4>
  12642. <p>Acknowledge receipt of some federation data</p>
  12643. <h3 id="remote_server_up-s-c"><a class="header" href="#remote_server_up-s-c">REMOTE_SERVER_UP (S, C)</a></h3>
  12644. <p>Inform other processes that a remote server may have come back online.</p>
  12645. <p>See <code>synapse/replication/tcp/commands.py</code> for a detailed description and
  12646. the format of each command.</p>
  12647. <h3 id="cache-invalidation-stream"><a class="header" href="#cache-invalidation-stream">Cache Invalidation Stream</a></h3>
  12648. <p>The cache invalidation stream is used to inform workers when they need
  12649. to invalidate any of their caches in the data store. This is done by
  12650. streaming all cache invalidations done on master down to the workers,
  12651. assuming that any caches on the workers also exist on the master.</p>
  12652. <p>Each individual cache invalidation results in a row being sent down
  12653. replication, which includes the cache name (the name of the function)
  12654. and they key to invalidate. For example:</p>
  12655. <pre><code>&gt; RDATA caches master 550953771 [&quot;get_user_by_id&quot;, [&quot;@bob:example.com&quot;], 1550574873251]
  12656. </code></pre>
  12657. <p>Alternatively, an entire cache can be invalidated by sending down a <code>null</code>
  12658. instead of the key. For example:</p>
  12659. <pre><code>&gt; RDATA caches master 550953772 [&quot;get_user_by_id&quot;, null, 1550574873252]
  12660. </code></pre>
  12661. <p>However, there are times when a number of caches need to be invalidated
  12662. at the same time with the same key. To reduce traffic we batch those
  12663. invalidations into a single poke by defining a special cache name that
  12664. workers understand to mean to expand to invalidate the correct caches.</p>
  12665. <p>Currently the special cache names are declared in
  12666. <code>synapse/storage/_base.py</code> and are:</p>
  12667. <ol>
  12668. <li><code>cs_cache_fake</code> ─ invalidates caches that depend on the current
  12669. state</li>
  12670. </ol>
  12671. <div style="break-before: page; page-break-before: always;"></div><h1 id="internal-documentation"><a class="header" href="#internal-documentation">Internal Documentation</a></h1>
  12672. <p>This section covers implementation documentation for various parts of Synapse.</p>
  12673. <p>If a developer is planning to make a change to a feature of Synapse, it can be useful for
  12674. general documentation of how that feature is implemented to be available. This saves the
  12675. developer time in place of needing to understand how the feature works by reading the
  12676. code.</p>
  12677. <p>Documentation that would be more useful for the perspective of a system administrator,
  12678. rather than a developer who's intending to change to code, should instead be placed
  12679. under the Usage section of the documentation.</p>
  12680. <div style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-saml-as-a-developer-without-a-server"><a class="header" href="#how-to-test-saml-as-a-developer-without-a-server">How to test SAML as a developer without a server</a></h1>
  12681. <p>https://fujifish.github.io/samling/samling.html (https://github.com/fujifish/samling) is a great resource for being able to tinker with the
  12682. SAML options within Synapse without needing to deploy and configure a complicated software stack.</p>
  12683. <p>To make Synapse (and therefore Element) use it:</p>
  12684. <ol>
  12685. <li>Use the samling.html URL above or deploy your own and visit the IdP Metadata tab.</li>
  12686. <li>Copy the XML to your clipboard.</li>
  12687. <li>On your Synapse server, create a new file <code>samling.xml</code> next to your <code>homeserver.yaml</code> with
  12688. the XML from step 2 as the contents.</li>
  12689. <li>Edit your <code>homeserver.yaml</code> to include:
  12690. <pre><code class="language-yaml">saml2_config:
  12691. sp_config:
  12692. allow_unknown_attributes: true # Works around a bug with AVA Hashes: https://github.com/IdentityPython/pysaml2/issues/388
  12693. metadata:
  12694. local: [&quot;samling.xml&quot;]
  12695. </code></pre>
  12696. </li>
  12697. <li>Ensure that your <code>homeserver.yaml</code> has a setting for <code>public_baseurl</code>:
  12698. <pre><code class="language-yaml">public_baseurl: http://localhost:8080/
  12699. </code></pre>
  12700. </li>
  12701. <li>Run <code>apt-get install xmlsec1</code> and <code>pip install --upgrade --force 'pysaml2&gt;=4.5.0'</code> to ensure
  12702. the dependencies are installed and ready to go.</li>
  12703. <li>Restart Synapse.</li>
  12704. </ol>
  12705. <p>Then in Element:</p>
  12706. <ol>
  12707. <li>Visit the login page and point Element towards your homeserver using the <code>public_baseurl</code> above.</li>
  12708. <li>Click the Single Sign-On button.</li>
  12709. <li>On the samling page, enter a Name Identifier and add a SAML Attribute for <code>uid=your_localpart</code>.
  12710. The response must also be signed.</li>
  12711. <li>Click &quot;Next&quot;.</li>
  12712. <li>Click &quot;Post Response&quot; (change nothing).</li>
  12713. <li>You should be logged in.</li>
  12714. </ol>
  12715. <p>If you try and repeat this process, you may be automatically logged in using the information you
  12716. gave previously. To fix this, open your developer console (<code>F12</code> or <code>Ctrl+Shift+I</code>) while on the
  12717. samling page and clear the site data. In Chrome, this will be a button on the Application tab.</p>
  12718. <div style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-cas-as-a-developer-without-a-server"><a class="header" href="#how-to-test-cas-as-a-developer-without-a-server">How to test CAS as a developer without a server</a></h1>
  12719. <p>The <a href="https://github.com/jbittel/django-mama-cas">django-mama-cas</a> project is an
  12720. easy to run CAS implementation built on top of Django.</p>
  12721. <h2 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h2>
  12722. <ol>
  12723. <li>Create a new virtualenv: <code>python3 -m venv &lt;your virtualenv&gt;</code></li>
  12724. <li>Activate your virtualenv: <code>source /path/to/your/virtualenv/bin/activate</code></li>
  12725. <li>Install Django and django-mama-cas:
  12726. <pre><code>python -m pip install &quot;django&lt;3&quot; &quot;django-mama-cas==2.4.0&quot;
  12727. </code></pre>
  12728. </li>
  12729. <li>Create a Django project in the current directory:
  12730. <pre><code>django-admin startproject cas_test .
  12731. </code></pre>
  12732. </li>
  12733. <li>Follow the <a href="https://django-mama-cas.readthedocs.io/en/latest/installation.html#configuring">install directions</a> for django-mama-cas</li>
  12734. <li>Setup the SQLite database: <code>python manage.py migrate</code></li>
  12735. <li>Create a user:
  12736. <pre><code>python manage.py createsuperuser
  12737. </code></pre>
  12738. <ol>
  12739. <li>Use whatever you want as the username and password.</li>
  12740. <li>Leave the other fields blank.</li>
  12741. </ol>
  12742. </li>
  12743. <li>Use the built-in Django test server to serve the CAS endpoints on port 8000:
  12744. <pre><code>python manage.py runserver
  12745. </code></pre>
  12746. </li>
  12747. </ol>
  12748. <p>You should now have a Django project configured to serve CAS authentication with
  12749. a single user created.</p>
  12750. <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>
  12751. <ol>
  12752. <li>Modify your <code>homeserver.yaml</code> to enable CAS and point it to your locally
  12753. running Django test server:
  12754. <pre><code class="language-yaml">cas_config:
  12755. enabled: true
  12756. server_url: &quot;http://localhost:8000&quot;
  12757. service_url: &quot;http://localhost:8081&quot;
  12758. #displayname_attribute: name
  12759. #required_attributes:
  12760. # name: value
  12761. </code></pre>
  12762. </li>
  12763. <li>Restart Synapse.</li>
  12764. </ol>
  12765. <p>Note that the above configuration assumes the homeserver is running on port 8081
  12766. and that the CAS server is on port 8000, both on localhost.</p>
  12767. <h2 id="testing-the-configuration"><a class="header" href="#testing-the-configuration">Testing the configuration</a></h2>
  12768. <p>Then in Element:</p>
  12769. <ol>
  12770. <li>Visit the login page with a Element pointing at your homeserver.</li>
  12771. <li>Click the Single Sign-On button.</li>
  12772. <li>Login using the credentials created with <code>createsuperuser</code>.</li>
  12773. <li>You should be logged in.</li>
  12774. </ol>
  12775. <p>If you want to repeat this process you'll need to manually logout first:</p>
  12776. <ol>
  12777. <li>http://localhost:8000/admin/</li>
  12778. <li>Click &quot;logout&quot; in the top right.</li>
  12779. </ol>
  12780. <div style="break-before: page; page-break-before: always;"></div><h1 id="room-dag-concepts"><a class="header" href="#room-dag-concepts">Room DAG concepts</a></h1>
  12781. <h2 id="edges"><a class="header" href="#edges">Edges</a></h2>
  12782. <p>The word &quot;edge&quot; comes from graph theory lingo. An edge is just a connection
  12783. between two events. In Synapse, we connect events by specifying their
  12784. <code>prev_events</code>. A subsequent event points back at a previous event.</p>
  12785. <pre><code>A (oldest) &lt;---- B &lt;---- C (most recent)
  12786. </code></pre>
  12787. <h2 id="depth-and-stream-ordering"><a class="header" href="#depth-and-stream-ordering">Depth and stream ordering</a></h2>
  12788. <p>Events are normally sorted by <code>(topological_ordering, stream_ordering)</code> where
  12789. <code>topological_ordering</code> is just <code>depth</code>. In other words, we first sort by <code>depth</code>
  12790. and then tie-break based on <code>stream_ordering</code>. <code>depth</code> is incremented as new
  12791. messages are added to the DAG. Normally, <code>stream_ordering</code> is an auto
  12792. incrementing integer, but backfilled events start with <code>stream_ordering=-1</code> and decrement.</p>
  12793. <hr />
  12794. <ul>
  12795. <li><code>/sync</code> returns things in the order they arrive at the server (<code>stream_ordering</code>).</li>
  12796. <li><code>/messages</code> (and <code>/backfill</code> in the federation API) return them in the order determined by the event graph <code>(topological_ordering, stream_ordering)</code>.</li>
  12797. </ul>
  12798. <p>The general idea is that, if you're following a room in real-time (i.e.
  12799. <code>/sync</code>), you probably want to see the messages as they arrive at your server,
  12800. rather than skipping any that arrived late; whereas if you're looking at a
  12801. historical section of timeline (i.e. <code>/messages</code>), you want to see the best
  12802. representation of the state of the room as others were seeing it at the time.</p>
  12803. <h2 id="forward-extremity"><a class="header" href="#forward-extremity">Forward extremity</a></h2>
  12804. <p>Most-recent-in-time events in the DAG which are not referenced by any other events' <code>prev_events</code> yet.</p>
  12805. <p>The forward extremities of a room are used as the <code>prev_events</code> when the next event is sent.</p>
  12806. <h2 id="backwards-extremity"><a class="header" href="#backwards-extremity">Backwards extremity</a></h2>
  12807. <p>The current marker of where we have backfilled up to and will generally be the
  12808. oldest-in-time events we know of in the DAG.</p>
  12809. <p>This is an event where we haven't fetched all of the <code>prev_events</code> for.</p>
  12810. <p>Once we have fetched all of its <code>prev_events</code>, it's unmarked as a backwards
  12811. extremity (although we may have formed new backwards extremities from the prev
  12812. events during the backfilling process).</p>
  12813. <h2 id="outliers"><a class="header" href="#outliers">Outliers</a></h2>
  12814. <p>We mark an event as an <code>outlier</code> when we haven't figured out the state for the
  12815. room at that point in the DAG yet.</p>
  12816. <p>We won't <em>necessarily</em> have the <code>prev_events</code> of an <code>outlier</code> in the database,
  12817. but it's entirely possible that we <em>might</em>. The status of whether we have all of
  12818. the <code>prev_events</code> is marked as a <a href="development/room-dag-concepts.html#backwards-extremity">backwards extremity</a>.</p>
  12819. <p>For example, when we fetch the event auth chain or state for a given event, we
  12820. mark all of those claimed auth events as outliers because we haven't done the
  12821. state calculation ourself.</p>
  12822. <h2 id="state-groups"><a class="header" href="#state-groups">State groups</a></h2>
  12823. <p>For every non-outlier event we need to know the state at that event. Instead of
  12824. storing the full state for each event in the DB (i.e. a <code>event_id -&gt; state</code>
  12825. mapping), which is <em>very</em> space inefficient when state doesn't change, we
  12826. instead assign each different set of state a &quot;state group&quot; and then have
  12827. mappings of <code>event_id -&gt; state_group</code> and <code>state_group -&gt; state</code>.</p>
  12828. <h3 id="stage-group-edges"><a class="header" href="#stage-group-edges">Stage group edges</a></h3>
  12829. <p>TODO: <code>state_group_edges</code> is a further optimization...
  12830. notes from @Azrenbeth, https://pastebin.com/seUGVGeT</p>
  12831. <div style="break-before: page; page-break-before: always;"></div><h1 id="auth-chain-difference-algorithm"><a class="header" href="#auth-chain-difference-algorithm">Auth Chain Difference Algorithm</a></h1>
  12832. <p>The auth chain difference algorithm is used by V2 state resolution, where a
  12833. naive implementation can be a significant source of CPU and DB usage.</p>
  12834. <h3 id="definitions"><a class="header" href="#definitions">Definitions</a></h3>
  12835. <p>A <em>state set</em> is a set of state events; e.g. the input of a state resolution
  12836. algorithm is a collection of state sets.</p>
  12837. <p>The <em>auth chain</em> of a set of events are all the events' auth events and <em>their</em>
  12838. auth events, recursively (i.e. the events reachable by walking the graph induced
  12839. by an event's auth events links).</p>
  12840. <p>The <em>auth chain difference</em> of a collection of state sets is the union minus the
  12841. intersection of the sets of auth chains corresponding to the state sets, i.e an
  12842. event is in the auth chain difference if it is reachable by walking the auth
  12843. event graph from at least one of the state sets but not from <em>all</em> of the state
  12844. sets.</p>
  12845. <h2 id="breadth-first-walk-algorithm"><a class="header" href="#breadth-first-walk-algorithm">Breadth First Walk Algorithm</a></h2>
  12846. <p>A way of calculating the auth chain difference without calculating the full auth
  12847. chains for each state set is to do a parallel breadth first walk (ordered by
  12848. depth) of each state set's auth chain. By tracking which events are reachable
  12849. from each state set we can finish early if every pending event is reachable from
  12850. every state set.</p>
  12851. <p>This can work well for state sets that have a small auth chain difference, but
  12852. can be very inefficient for larger differences. However, this algorithm is still
  12853. used if we don't have a chain cover index for the room (e.g. because we're in
  12854. the process of indexing it).</p>
  12855. <h2 id="chain-cover-index"><a class="header" href="#chain-cover-index">Chain Cover Index</a></h2>
  12856. <p>Synapse computes auth chain differences by pre-computing a &quot;chain cover&quot; index
  12857. for the auth chain in a room, allowing efficient reachability queries like &quot;is
  12858. event A in the auth chain of event B&quot;. This is done by assigning every event a
  12859. <em>chain ID</em> and <em>sequence number</em> (e.g. <code>(5,3)</code>), and having a map of <em>links</em>
  12860. between chains (e.g. <code>(5,3) -&gt; (2,4)</code>) such that A is reachable by B (i.e. <code>A</code>
  12861. is in the auth chain of <code>B</code>) if and only if either:</p>
  12862. <ol>
  12863. <li>A and B have the same chain ID and <code>A</code>'s sequence number is less than <code>B</code>'s
  12864. sequence number; or</li>
  12865. <li>there is a link <code>L</code> between <code>B</code>'s chain ID and <code>A</code>'s chain ID such that
  12866. <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>
  12867. </ol>
  12868. <p>There are actually two potential implementations, one where we store links from
  12869. each chain to every other reachable chain (the transitive closure of the links
  12870. graph), and one where we remove redundant links (the transitive reduction of the
  12871. links graph) e.g. if we have chains <code>C3 -&gt; C2 -&gt; C1</code> then the link <code>C3 -&gt; C1</code>
  12872. would not be stored. Synapse uses the former implementations so that it doesn't
  12873. need to recurse to test reachability between chains.</p>
  12874. <h3 id="example-5"><a class="header" href="#example-5">Example</a></h3>
  12875. <p>An example auth graph would look like the following, where chains have been
  12876. formed based on type/state_key and are denoted by colour and are labelled with
  12877. <code>(chain ID, sequence number)</code>. Links are denoted by the arrows (links in grey
  12878. are those that would be remove in the second implementation described above).</p>
  12879. <p><img src="auth_chain_diff.dot.png" alt="Example" /></p>
  12880. <p>Note that we don't include all links between events and their auth events, as
  12881. most of those links would be redundant. For example, all events point to the
  12882. create event, but each chain only needs the one link from it's base to the
  12883. create event.</p>
  12884. <h2 id="using-the-index"><a class="header" href="#using-the-index">Using the Index</a></h2>
  12885. <p>This index can be used to calculate the auth chain difference of the state sets
  12886. by looking at the chain ID and sequence numbers reachable from each state set:</p>
  12887. <ol>
  12888. <li>For every state set lookup the chain ID/sequence numbers of each state event</li>
  12889. <li>Use the index to find all chains and the maximum sequence number reachable
  12890. from each state set.</li>
  12891. <li>The auth chain difference is then all events in each chain that have sequence
  12892. numbers between the maximum sequence number reachable from <em>any</em> state set and
  12893. the minimum reachable by <em>all</em> state sets (if any).</li>
  12894. </ol>
  12895. <p>Note that steps 2 is effectively calculating the auth chain for each state set
  12896. (in terms of chain IDs and sequence numbers), and step 3 is calculating the
  12897. difference between the union and intersection of the auth chains.</p>
  12898. <h3 id="worked-example"><a class="header" href="#worked-example">Worked Example</a></h3>
  12899. <p>For example, given the above graph, we can calculate the difference between
  12900. state sets consisting of:</p>
  12901. <ol>
  12902. <li><code>S1</code>: Alice's invite <code>(4,1)</code> and Bob's second join <code>(2,2)</code>; and</li>
  12903. <li><code>S2</code>: Alice's second join <code>(4,3)</code> and Bob's first join <code>(2,1)</code>.</li>
  12904. </ol>
  12905. <p>Using the index we see that the following auth chains are reachable from each
  12906. state set:</p>
  12907. <ol>
  12908. <li><code>S1</code>: <code>(1,1)</code>, <code>(2,2)</code>, <code>(3,1)</code> &amp; <code>(4,1)</code></li>
  12909. <li><code>S2</code>: <code>(1,1)</code>, <code>(2,1)</code>, <code>(3,2)</code> &amp; <code>(4,3)</code></li>
  12910. </ol>
  12911. <p>And so, for each the ranges that are in the auth chain difference:</p>
  12912. <ol>
  12913. <li>Chain 1: None, (since everything can reach the create event).</li>
  12914. <li>Chain 2: The range <code>(1, 2]</code> (i.e. just <code>2</code>), as <code>1</code> is reachable by all state
  12915. sets and the maximum reachable is <code>2</code> (corresponding to Bob's second join).</li>
  12916. <li>Chain 3: Similarly the range <code>(1, 2]</code> (corresponding to the second power
  12917. level).</li>
  12918. <li>Chain 4: The range <code>(1, 3]</code> (corresponding to both of Alice's joins).</li>
  12919. </ol>
  12920. <p>So the final result is: Bob's second join <code>(2,2)</code>, the second power level
  12921. <code>(3,2)</code> and both of Alice's joins <code>(4,2)</code> &amp; <code>(4,3)</code>.</p>
  12922. <div style="break-before: page; page-break-before: always;"></div><h1 id="media-repository"><a class="header" href="#media-repository">Media Repository</a></h1>
  12923. <p><em>Synapse implementation-specific details for the media repository</em></p>
  12924. <p>The media repository is where attachments and avatar photos are stored.
  12925. It stores attachment content and thumbnails for media uploaded by local users.
  12926. It caches attachment content and thumbnails for media uploaded by remote users.</p>
  12927. <h2 id="storage"><a class="header" href="#storage">Storage</a></h2>
  12928. <p>Each item of media is assigned a <code>media_id</code> when it is uploaded.
  12929. The <code>media_id</code> is a randomly chosen, URL safe 24 character string.</p>
  12930. <p>Metadata such as the MIME type, upload time and length are stored in the
  12931. sqlite3 database indexed by <code>media_id</code>.</p>
  12932. <p>Content is stored on the filesystem under a <code>&quot;local_content&quot;</code> directory.</p>
  12933. <p>Thumbnails are stored under a <code>&quot;local_thumbnails&quot;</code> directory.</p>
  12934. <p>The item with <code>media_id</code> <code>&quot;aabbccccccccdddddddddddd&quot;</code> is stored under
  12935. <code>&quot;local_content/aa/bb/ccccccccdddddddddddd&quot;</code>. Its thumbnail with width
  12936. <code>128</code> and height <code>96</code> and type <code>&quot;image/jpeg&quot;</code> is stored under
  12937. <code>&quot;local_thumbnails/aa/bb/ccccccccdddddddddddd/128-96-image-jpeg&quot;</code></p>
  12938. <p>Remote content is cached under <code>&quot;remote_content&quot;</code> directory. Each item of
  12939. remote content is assigned a local <code>&quot;filesystem_id&quot;</code> to ensure that the
  12940. directory structure <code>&quot;remote_content/server_name/aa/bb/ccccccccdddddddddddd&quot;</code>
  12941. is appropriate. Thumbnails for remote content are stored under
  12942. <code>&quot;remote_thumbnail/server_name/...&quot;</code></p>
  12943. <div style="break-before: page; page-break-before: always;"></div><h1 id="room-and-user-statistics"><a class="header" href="#room-and-user-statistics">Room and User Statistics</a></h1>
  12944. <p>Synapse maintains room and user statistics in various tables. These can be used
  12945. for administrative purposes but are also used when generating the public room
  12946. directory.</p>
  12947. <h1 id="synapse-developer-documentation"><a class="header" href="#synapse-developer-documentation">Synapse Developer Documentation</a></h1>
  12948. <h2 id="high-level-concepts"><a class="header" href="#high-level-concepts">High-Level Concepts</a></h2>
  12949. <h3 id="definitions-1"><a class="header" href="#definitions-1">Definitions</a></h3>
  12950. <ul>
  12951. <li><strong>subject</strong>: Something we are tracking stats about – currently a room or user.</li>
  12952. <li><strong>current row</strong>: An entry for a subject in the appropriate current statistics
  12953. table. Each subject can have only one.</li>
  12954. </ul>
  12955. <h3 id="overview-4"><a class="header" href="#overview-4">Overview</a></h3>
  12956. <p>Stats correspond to the present values. Current rows contain the most up-to-date
  12957. statistics for a room. Each subject can only have one entry.</p>
  12958. <div style="break-before: page; page-break-before: always;"></div><h1 id="deprecation-policy-for-platform-dependencies"><a class="header" href="#deprecation-policy-for-platform-dependencies">Deprecation Policy for Platform Dependencies</a></h1>
  12959. <p>Synapse has a number of platform dependencies, including Python and PostgreSQL.
  12960. This document outlines the policy towards which versions we support, and when we
  12961. drop support for versions in the future.</p>
  12962. <h2 id="policy"><a class="header" href="#policy">Policy</a></h2>
  12963. <p>Synapse follows the upstream support life cycles for Python and PostgreSQL,
  12964. i.e. when a version reaches End of Life Synapse will withdraw support for that
  12965. version in future releases.</p>
  12966. <p>Details on the upstream support life cycles for Python and PostgreSQL are
  12967. documented at https://endoflife.date/python and
  12968. https://endoflife.date/postgresql.</p>
  12969. <h2 id="context"><a class="header" href="#context">Context</a></h2>
  12970. <p>It is important for system admins to have a clear understanding of the platform
  12971. requirements of Synapse and its deprecation policies so that they can
  12972. effectively plan upgrading their infrastructure ahead of time. This is
  12973. especially important in contexts where upgrading the infrastructure requires
  12974. auditing and approval from a security team, or where otherwise upgrading is a
  12975. long process.</p>
  12976. <p>By following the upstream support life cycles Synapse can ensure that its
  12977. dependencies continue to get security patches, while not requiring system admins
  12978. to constantly update their platform dependencies to the latest versions.</p>
  12979. </main>
  12980. <nav class="nav-wrapper" aria-label="Page navigation">
  12981. <!-- Mobile navigation buttons -->
  12982. <div style="clear: both"></div>
  12983. </nav>
  12984. </div>
  12985. </div>
  12986. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  12987. </nav>
  12988. </div>
  12989. <script type="text/javascript">
  12990. window.playground_copyable = true;
  12991. </script>
  12992. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  12993. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  12994. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  12995. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  12996. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  12997. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  12998. <!-- Custom JS scripts -->
  12999. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  13000. <script type="text/javascript" src="docs/website_files/version-picker.js"></script>
  13001. <script type="text/javascript" src="docs/website_files/version.js"></script>
  13002. <script type="text/javascript">
  13003. window.addEventListener('load', function() {
  13004. window.setTimeout(window.print, 100);
  13005. });
  13006. </script>
  13007. </body>
  13008. </html>