print.html 681 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109
  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="url_previews.html">URL Previews</a></li><li class="chapter-item expanded "><a href="user_directory.html">User Directory</a></li><li class="chapter-item expanded "><a href="message_retention_policies.html">Message Retention Policies</a></li><li class="chapter-item expanded "><a href="modules.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Third Party Rules</div></li><li class="chapter-item expanded "><a href="spam_checker.html">Spam Checker</a></li><li class="chapter-item expanded "><a href="presence_router_module.html">Presence Router</a></li><li class="chapter-item expanded "><div>Media Storage Providers</div></li></ol></li><li class="chapter-item expanded "><a href="workers.html">Workers</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="synctl_workers.html">Using synctl with Workers</a></li><li class="chapter-item expanded "><a href="systemd-with-workers/index.html">Systemd</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/index.html">Administration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/admin_api/index.html">Admin API</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="admin_api/account_validity.html">Account Validity</a></li><li class="chapter-item expanded "><a href="admin_api/delete_group.html">Delete Group</a></li><li class="chapter-item expanded "><a href="admin_api/event_reports.html">Event Reports</a></li><li class="chapter-item expanded "><a href="admin_api/media_admin_api.html">Media</a></li><li class="chapter-item expanded "><a href="admin_api/purge_history_api.html">Purge History</a></li><li class="chapter-item expanded "><a href="admin_api/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 "><div>Synapse Architecture</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="log_contexts.html">Log Contexts</a></li><li class="chapter-item expanded "><a href="replication.html">Replication</a></li><li class="chapter-item expanded "><a href="tcp_replication.html">TCP Replication</a></li></ol></li><li class="chapter-item expanded "><a href="development/internal_documentation/index.html">Internal Documentation</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single Sign-On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="development/cas.html">CAS</a></li></ol></li><li class="chapter-item expanded "><a href="development/room-dag-concepts.html">Room DAG concepts</a></li><li class="chapter-item expanded "><div>State Resolution</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="auth_chain_difference_algorithm.html">The Auth Chain Difference Algorithm</a></li></ol></li><li class="chapter-item expanded "><a href="media_repository.html">Media Repository</a></li><li class="chapter-item expanded "><a href="room_and_user_statistics.html">Room and User Statistics</a></li></ol></li><li class="chapter-item expanded "><div>Scripts</div></li><li class="chapter-item expanded affix "><li class="part-title">Other</li><li class="chapter-item expanded "><a href="deprecation_policy.html">Dependency Deprecation Policy</a></li></ol>
  76. </div>
  77. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  78. </nav>
  79. <div id="page-wrapper" class="page-wrapper">
  80. <div class="page">
  81. <div id="menu-bar-hover-placeholder"></div>
  82. <div id="menu-bar" class="menu-bar sticky bordered">
  83. <div class="left-buttons">
  84. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  85. <i class="fa fa-bars"></i>
  86. </button>
  87. <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
  88. <i class="fa fa-paint-brush"></i>
  89. </button>
  90. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  91. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  94. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  95. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  96. </ul>
  97. <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
  98. <i class="fa fa-search"></i>
  99. </button>
  100. <div class="version-picker">
  101. <div class="dropdown">
  102. <div class="select">
  103. <span></span>
  104. <i class="fa fa-chevron-down"></i>
  105. </div>
  106. <input type="hidden" name="version">
  107. <ul class="dropdown-menu">
  108. <!-- Versions will be added dynamically in version-picker.js -->
  109. </ul>
  110. </div>
  111. </div>
  112. </div>
  113. <h1 class="menu-title">Synapse</h1>
  114. <div class="right-buttons">
  115. <a href="print.html" title="Print this book" aria-label="Print this book">
  116. <i id="print-button" class="fa fa-print"></i>
  117. </a>
  118. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  119. <i id="git-repository-button" class="fa fa-github"></i>
  120. </a>
  121. </div>
  122. </div>
  123. <div id="search-wrapper" class="hidden">
  124. <form id="searchbar-outer" class="searchbar-outer">
  125. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  126. </form>
  127. <div id="searchresults-outer" class="searchresults-outer hidden">
  128. <div id="searchresults-header" class="searchresults-header"></div>
  129. <ul id="searchresults">
  130. </ul>
  131. </div>
  132. </div>
  133. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  134. <script type="text/javascript">
  135. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  136. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  137. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  138. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  139. });
  140. </script>
  141. <div id="content" class="content">
  142. <main>
  143. <!-- Page table of contents -->
  144. <div class="sidetoc">
  145. <nav class="pagetoc"></nav>
  146. </div>
  147. <div style="break-before: page; page-break-before: always;"></div><h1 id="introduction"><a class="header" href="#introduction">Introduction</a></h1>
  148. <p>Welcome to the documentation repository for Synapse, the reference
  149. <a href="https://matrix.org">Matrix</a> homeserver implementation.</p>
  150. <div style="break-before: page; page-break-before: always;"></div><h1 id="installation-instructions"><a class="header" href="#installation-instructions">Installation Instructions</a></h1>
  151. <h2 id="choosing-your-server-name"><a class="header" href="#choosing-your-server-name">Choosing your server name</a></h2>
  152. <p>It is important to choose the name for your server before you install Synapse,
  153. because it cannot be changed later.</p>
  154. <p>The server name determines the &quot;domain&quot; part of user-ids for users on your
  155. server: these will all be of the format <code>@user:my.domain.name</code>. It also
  156. determines how other matrix servers will reach yours for federation.</p>
  157. <p>For a test configuration, set this to the hostname of your server. For a more
  158. production-ready setup, you will probably want to specify your domain
  159. (<code>example.com</code>) rather than a matrix-specific hostname here (in the same way
  160. that your email address is probably <code>user@example.com</code> rather than
  161. <code>user@email.example.com</code>) - but doing so may require more advanced setup: see
  162. <a href="setup/../federate.html">Setting up Federation</a>.</p>
  163. <h2 id="installing-synapse"><a class="header" href="#installing-synapse">Installing Synapse</a></h2>
  164. <h3 id="installing-from-source"><a class="header" href="#installing-from-source">Installing from source</a></h3>
  165. <p>(Prebuilt packages are available for some platforms - see <a href="setup/installation.html#prebuilt-packages">Prebuilt packages</a>.)</p>
  166. <p>When installing from source please make sure that the <a href="setup/installation.html#platform-specific-prerequisites">Platform-specific prerequisites</a> are already installed.</p>
  167. <p>System requirements:</p>
  168. <ul>
  169. <li>POSIX-compliant system (tested on Linux &amp; OS X)</li>
  170. <li>Python 3.5.2 or later, up to Python 3.9.</li>
  171. <li>At least 1GB of free RAM if you want to join large public rooms like #matrix:matrix.org</li>
  172. </ul>
  173. <p>To install the Synapse homeserver run:</p>
  174. <pre><code class="language-sh">mkdir -p ~/synapse
  175. virtualenv -p python3 ~/synapse/env
  176. source ~/synapse/env/bin/activate
  177. pip install --upgrade pip
  178. pip install --upgrade setuptools
  179. pip install matrix-synapse
  180. </code></pre>
  181. <p>This will download Synapse from <a href="https://pypi.org/project/matrix-synapse">PyPI</a>
  182. and install it, along with the python libraries it uses, into a virtual environment
  183. under <code>~/synapse/env</code>. Feel free to pick a different directory if you
  184. prefer.</p>
  185. <p>This Synapse installation can then be later upgraded by using pip again with the
  186. update flag:</p>
  187. <pre><code class="language-sh">source ~/synapse/env/bin/activate
  188. pip install -U matrix-synapse
  189. </code></pre>
  190. <p>Before you can start Synapse, you will need to generate a configuration
  191. file. To do this, run (in your virtualenv, as before):</p>
  192. <pre><code class="language-sh">cd ~/synapse
  193. python -m synapse.app.homeserver \
  194. --server-name my.domain.name \
  195. --config-path homeserver.yaml \
  196. --generate-config \
  197. --report-stats=[yes|no]
  198. </code></pre>
  199. <p>... substituting an appropriate value for <code>--server-name</code>.</p>
  200. <p>This command will generate you a config file that you can then customise, but it will
  201. also generate a set of keys for you. These keys will allow your homeserver to
  202. identify itself to other homeserver, so don't lose or delete them. It would be
  203. wise to back them up somewhere safe. (If, for whatever reason, you do need to
  204. change your homeserver's keys, you may find that other homeserver have the
  205. old key cached. If you update the signing key, you should change the name of the
  206. key in the <code>&lt;server name&gt;.signing.key</code> file (the second word) to something
  207. 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>
  208. <p>To actually run your new homeserver, pick a working directory for Synapse to
  209. run (e.g. <code>~/synapse</code>), and:</p>
  210. <pre><code class="language-sh">cd ~/synapse
  211. source env/bin/activate
  212. synctl start
  213. </code></pre>
  214. <h4 id="platform-specific-prerequisites"><a class="header" href="#platform-specific-prerequisites">Platform-specific prerequisites</a></h4>
  215. <p>Synapse is written in Python but some of the libraries it uses are written in
  216. C. So before we can install Synapse itself we need a working C compiler and the
  217. header files for Python C extensions.</p>
  218. <h5 id="debianubunturaspbian"><a class="header" href="#debianubunturaspbian">Debian/Ubuntu/Raspbian</a></h5>
  219. <p>Installing prerequisites on Ubuntu or Debian:</p>
  220. <pre><code class="language-sh">sudo apt install build-essential python3-dev libffi-dev \
  221. python3-pip python3-setuptools sqlite3 \
  222. libssl-dev virtualenv libjpeg-dev libxslt1-dev
  223. </code></pre>
  224. <h5 id="archlinux"><a class="header" href="#archlinux">ArchLinux</a></h5>
  225. <p>Installing prerequisites on ArchLinux:</p>
  226. <pre><code class="language-sh">sudo pacman -S base-devel python python-pip \
  227. python-setuptools python-virtualenv sqlite3
  228. </code></pre>
  229. <h5 id="centosfedora"><a class="header" href="#centosfedora">CentOS/Fedora</a></h5>
  230. <p>Installing prerequisites on CentOS or Fedora Linux:</p>
  231. <pre><code class="language-sh">sudo dnf install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
  232. libwebp-devel libxml2-devel libxslt-devel libpq-devel \
  233. python3-virtualenv libffi-devel openssl-devel python3-devel
  234. sudo dnf groupinstall &quot;Development Tools&quot;
  235. </code></pre>
  236. <h5 id="macos"><a class="header" href="#macos">macOS</a></h5>
  237. <p>Installing prerequisites on macOS:</p>
  238. <p>You may need to install the latest Xcode developer tools:</p>
  239. <pre><code class="language-sh">xcode-select --install
  240. </code></pre>
  241. <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>
  242. <pre><code class="language-sh"> brew install jpeg
  243. </code></pre>
  244. <p>On macOS Catalina (10.15) you may need to explicitly install OpenSSL
  245. via brew and inform <code>pip</code> about it so that <code>psycopg2</code> builds:</p>
  246. <pre><code class="language-sh">brew install openssl@1.1
  247. export LDFLAGS=&quot;-L/usr/local/opt/openssl/lib&quot;
  248. export CPPFLAGS=&quot;-I/usr/local/opt/openssl/include&quot;
  249. </code></pre>
  250. <h5 id="opensuse"><a class="header" href="#opensuse">OpenSUSE</a></h5>
  251. <p>Installing prerequisites on openSUSE:</p>
  252. <pre><code class="language-sh">sudo zypper in -t pattern devel_basis
  253. sudo zypper in python-pip python-setuptools sqlite3 python-virtualenv \
  254. python-devel libffi-devel libopenssl-devel libjpeg62-devel
  255. </code></pre>
  256. <h5 id="openbsd"><a class="header" href="#openbsd">OpenBSD</a></h5>
  257. <p>A port of Synapse is available under <code>net/synapse</code>. The filesystem
  258. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  259. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  260. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  261. <p>To be able to build Synapse's dependency on python the <code>WRKOBJDIR</code>
  262. (cf. <code>bsd.port.mk(5)</code>) for building python, too, needs to be on a filesystem
  263. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>).</p>
  264. <p>Creating a <code>WRKOBJDIR</code> for building python under <code>/usr/local</code> (which on a
  265. default OpenBSD installation is mounted with <code>wxallowed</code>):</p>
  266. <pre><code class="language-sh">doas mkdir /usr/local/pobj_wxallowed
  267. </code></pre>
  268. <p>Assuming <code>PORTS_PRIVSEP=Yes</code> (cf. <code>bsd.port.mk(5)</code>) and <code>SUDO=doas</code> are
  269. configured in <code>/etc/mk.conf</code>:</p>
  270. <pre><code class="language-sh">doas chown _pbuild:_pbuild /usr/local/pobj_wxallowed
  271. </code></pre>
  272. <p>Setting the <code>WRKOBJDIR</code> for building python:</p>
  273. <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
  274. </code></pre>
  275. <p>Building Synapse:</p>
  276. <pre><code class="language-sh">cd /usr/ports/net/synapse
  277. make install
  278. </code></pre>
  279. <h5 id="windows"><a class="header" href="#windows">Windows</a></h5>
  280. <p>If you wish to run or develop Synapse on Windows, the Windows Subsystem For
  281. Linux provides a Linux environment on Windows 10 which is capable of using the
  282. Debian, Fedora, or source installation methods. More information about WSL can
  283. 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
  284. 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>
  285. for Windows Server.</p>
  286. <h3 id="prebuilt-packages"><a class="header" href="#prebuilt-packages">Prebuilt packages</a></h3>
  287. <p>As an alternative to installing from source, prebuilt packages are available
  288. for a number of platforms.</p>
  289. <h4 id="docker-images-and-ansible-playbooks"><a class="header" href="#docker-images-and-ansible-playbooks">Docker images and Ansible playbooks</a></h4>
  290. <p>There is an official synapse image available at
  291. <a href="https://hub.docker.com/r/matrixdotorg/synapse">https://hub.docker.com/r/matrixdotorg/synapse</a> which can be used with
  292. the docker-compose file available at
  293. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/docker">contrib/docker</a>.
  294. Further information on this including configuration options is available in the README
  295. on hub.docker.com.</p>
  296. <p>Alternatively, Andreas Peters (previously Silvio Fricke) has contributed a
  297. Dockerfile to automate a synapse server in a single Docker image, at
  298. <a href="https://hub.docker.com/r/avhost/docker-matrix/tags/">https://hub.docker.com/r/avhost/docker-matrix/tags/</a></p>
  299. <p>Slavi Pantaleev has created an Ansible playbook,
  300. which installs the offical Docker image of Matrix Synapse
  301. along with many other Matrix-related services (Postgres database, Element, coturn,
  302. ma1sd, SSL support, etc.).
  303. For more details, see
  304. <a href="https://github.com/spantaleev/matrix-docker-ansible-deploy">https://github.com/spantaleev/matrix-docker-ansible-deploy</a></p>
  305. <h4 id="debianubuntu"><a class="header" href="#debianubuntu">Debian/Ubuntu</a></h4>
  306. <h5 id="matrixorg-packages"><a class="header" href="#matrixorg-packages">Matrix.org packages</a></h5>
  307. <p>Matrix.org provides Debian/Ubuntu packages of Synapse via
  308. <a href="https://packages.matrix.org/debian/">https://packages.matrix.org/debian/</a>. To install the latest release:</p>
  309. <pre><code class="language-sh">sudo apt install -y lsb-release wget apt-transport-https
  310. sudo wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
  311. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main&quot; |
  312. sudo tee /etc/apt/sources.list.d/matrix-org.list
  313. sudo apt update
  314. sudo apt install matrix-synapse-py3
  315. </code></pre>
  316. <p>Packages are also published for release candidates. To enable the prerelease
  317. channel, add <code>prerelease</code> to the <code>sources.list</code> line. For example:</p>
  318. <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
  319. echo &quot;deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main prerelease&quot; |
  320. sudo tee /etc/apt/sources.list.d/matrix-org.list
  321. sudo apt update
  322. sudo apt install matrix-synapse-py3
  323. </code></pre>
  324. <p>The fingerprint of the repository signing key (as shown by <code>gpg /usr/share/keyrings/matrix-org-archive-keyring.gpg</code>) is
  325. <code>AAF9AE843A7584B5A3E4CD2BCF45A512DE2DA058</code>.</p>
  326. <h5 id="downstream-debian-packages"><a class="header" href="#downstream-debian-packages">Downstream Debian packages</a></h5>
  327. <p>We do not recommend using the packages from the default Debian <code>buster</code>
  328. repository at this time, as they are old and suffer from known security
  329. vulnerabilities. You can install the latest version of Synapse from
  330. <a href="setup/installation.html#matrixorg-packages">our repository</a> or from <code>buster-backports</code>. Please
  331. see the <a href="https://backports.debian.org/Instructions/">Debian documentation</a>
  332. for information on how to use backports.</p>
  333. <p>If you are using Debian <code>sid</code> or testing, Synapse is available in the default
  334. repositories and it should be possible to install it simply with:</p>
  335. <pre><code class="language-sh">sudo apt install matrix-synapse
  336. </code></pre>
  337. <h5 id="downstream-ubuntu-packages"><a class="header" href="#downstream-ubuntu-packages">Downstream Ubuntu packages</a></h5>
  338. <p>We do not recommend using the packages in the default Ubuntu repository
  339. at this time, as they are old and suffer from known security vulnerabilities.
  340. The latest version of Synapse can be installed from <a href="setup/installation.html#matrixorg-packages">our repository</a>.</p>
  341. <h4 id="fedora"><a class="header" href="#fedora">Fedora</a></h4>
  342. <p>Synapse is in the Fedora repositories as <code>matrix-synapse</code>:</p>
  343. <pre><code class="language-sh">sudo dnf install matrix-synapse
  344. </code></pre>
  345. <p>Oleg Girko provides Fedora RPMs at
  346. <a href="https://obs.infoserver.lv/project/monitor/matrix-synapse">https://obs.infoserver.lv/project/monitor/matrix-synapse</a></p>
  347. <h4 id="opensuse-1"><a class="header" href="#opensuse-1">OpenSUSE</a></h4>
  348. <p>Synapse is in the OpenSUSE repositories as <code>matrix-synapse</code>:</p>
  349. <pre><code class="language-sh">sudo zypper install matrix-synapse
  350. </code></pre>
  351. <h4 id="suse-linux-enterprise-server"><a class="header" href="#suse-linux-enterprise-server">SUSE Linux Enterprise Server</a></h4>
  352. <p>Unofficial package are built for SLES 15 in the openSUSE:Backports:SLE-15 repository at
  353. <a href="https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/">https://download.opensuse.org/repositories/openSUSE:/Backports:/SLE-15/standard/</a></p>
  354. <h4 id="archlinux-1"><a class="header" href="#archlinux-1">ArchLinux</a></h4>
  355. <p>The quickest way to get up and running with ArchLinux is probably with the community package
  356. <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
  357. the necessary dependencies.</p>
  358. <p>pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 ):</p>
  359. <pre><code class="language-sh">sudo pip install --upgrade pip
  360. </code></pre>
  361. <p>If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  362. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  363. compile it under the right architecture. (This should not be needed if
  364. installing under virtualenv):</p>
  365. <pre><code class="language-sh">sudo pip uninstall py-bcrypt
  366. sudo pip install py-bcrypt
  367. </code></pre>
  368. <h4 id="void-linux"><a class="header" href="#void-linux">Void Linux</a></h4>
  369. <p>Synapse can be found in the void repositories as 'synapse':</p>
  370. <pre><code class="language-sh">xbps-install -Su
  371. xbps-install -S synapse
  372. </code></pre>
  373. <h4 id="freebsd"><a class="header" href="#freebsd">FreeBSD</a></h4>
  374. <p>Synapse can be installed via FreeBSD Ports or Packages contributed by Brendan Molloy from:</p>
  375. <ul>
  376. <li>Ports: <code>cd /usr/ports/net-im/py-matrix-synapse &amp;&amp; make install clean</code></li>
  377. <li>Packages: <code>pkg install py37-matrix-synapse</code></li>
  378. </ul>
  379. <h4 id="openbsd-1"><a class="header" href="#openbsd-1">OpenBSD</a></h4>
  380. <p>As of OpenBSD 6.7 Synapse is available as a pre-compiled binary. The filesystem
  381. underlying the homeserver directory (defaults to <code>/var/synapse</code>) has to be
  382. mounted with <code>wxallowed</code> (cf. <code>mount(8)</code>), so creating a separate filesystem
  383. and mounting it to <code>/var/synapse</code> should be taken into consideration.</p>
  384. <p>Installing Synapse:</p>
  385. <pre><code class="language-sh">doas pkg_add synapse
  386. </code></pre>
  387. <h4 id="nixos"><a class="header" href="#nixos">NixOS</a></h4>
  388. <p>Robin Lambertz has packaged Synapse for NixOS at:
  389. <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>
  390. <h2 id="setting-up-synapse"><a class="header" href="#setting-up-synapse">Setting up Synapse</a></h2>
  391. <p>Once you have installed synapse as above, you will need to configure it.</p>
  392. <h3 id="using-postgresql"><a class="header" href="#using-postgresql">Using PostgreSQL</a></h3>
  393. <p>By default Synapse uses an <a href="https://sqlite.org/">SQLite</a> database and in doing so trades
  394. performance for convenience. Almost all installations should opt to use <a href="https://www.postgresql.org">PostgreSQL</a>
  395. instead. Advantages include:</p>
  396. <ul>
  397. <li>significant performance improvements due to the superior threading and
  398. caching model, smarter query optimiser</li>
  399. <li>allowing the DB to be run on separate hardware</li>
  400. </ul>
  401. <p>For information on how to install and use PostgreSQL in Synapse, please see
  402. <a href="setup/../postgres.html">Using Postgres</a></p>
  403. <p>SQLite is only acceptable for testing purposes. SQLite should not be used in
  404. a production server. Synapse will perform poorly when using
  405. SQLite, especially when participating in large rooms.</p>
  406. <h3 id="tls-certificates"><a class="header" href="#tls-certificates">TLS certificates</a></h3>
  407. <p>The default configuration exposes a single HTTP port on the local
  408. interface: <code>http://localhost:8008</code>. It is suitable for local testing,
  409. but for any practical use, you will need Synapse's APIs to be served
  410. over HTTPS.</p>
  411. <p>The recommended way to do so is to set up a reverse proxy on port
  412. <code>8448</code>. You can find documentation on doing so in
  413. <a href="setup/../reverse_proxy.html">the reverse proxy documentation</a>.</p>
  414. <p>Alternatively, you can configure Synapse to expose an HTTPS port. To do
  415. so, you will need to edit <code>homeserver.yaml</code>, as follows:</p>
  416. <ul>
  417. <li>First, under the <code>listeners</code> section, uncomment the configuration for the
  418. TLS-enabled listener. (Remove the hash sign (<code>#</code>) at the start of
  419. each line). The relevant lines are like this:</li>
  420. </ul>
  421. <pre><code class="language-yaml"> - port: 8448
  422. type: http
  423. tls: true
  424. resources:
  425. - names: [client, federation]
  426. </code></pre>
  427. <ul>
  428. <li>
  429. <p>You will also need to uncomment the <code>tls_certificate_path</code> and
  430. <code>tls_private_key_path</code> lines under the <code>TLS</code> section. You will need to manage
  431. provisioning of these certificates yourself.</p>
  432. <p>If you are using your own certificate, be sure to use a <code>.pem</code> file that
  433. includes the full certificate chain including any intermediate certificates
  434. (for instance, if using certbot, use <code>fullchain.pem</code> as your certificate, not
  435. <code>cert.pem</code>).</p>
  436. </li>
  437. </ul>
  438. <p>For a more detailed guide to configuring your server for federation, see
  439. <a href="setup/../federate.html">Federation</a>.</p>
  440. <h3 id="client-well-known-uri"><a class="header" href="#client-well-known-uri">Client Well-Known URI</a></h3>
  441. <p>Setting up the client Well-Known URI is optional but if you set it up, it will
  442. allow users to enter their full username (e.g. <code>@user:&lt;server_name&gt;</code>) into clients
  443. which support well-known lookup to automatically configure the homeserver and
  444. identity server URLs. This is useful so that users don't have to memorize or think
  445. about the actual homeserver URL you are using.</p>
  446. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/client</code> should return JSON in
  447. the following format.</p>
  448. <pre><code class="language-json">{
  449. &quot;m.homeserver&quot;: {
  450. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  451. }
  452. }
  453. </code></pre>
  454. <p>It can optionally contain identity server information as well.</p>
  455. <pre><code class="language-json">{
  456. &quot;m.homeserver&quot;: {
  457. &quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;
  458. },
  459. &quot;m.identity_server&quot;: {
  460. &quot;base_url&quot;: &quot;https://&lt;identity.example.com&gt;&quot;
  461. }
  462. }
  463. </code></pre>
  464. <p>To work in browser based clients, the file must be served with the appropriate
  465. Cross-Origin Resource Sharing (CORS) headers. A recommended value would be
  466. <code>Access-Control-Allow-Origin: *</code> which would allow all browser based clients to
  467. view it.</p>
  468. <p>In nginx this would be something like:</p>
  469. <pre><code class="language-nginx">location /.well-known/matrix/client {
  470. return 200 '{&quot;m.homeserver&quot;: {&quot;base_url&quot;: &quot;https://&lt;matrix.example.com&gt;&quot;}}';
  471. default_type application/json;
  472. add_header Access-Control-Allow-Origin *;
  473. }
  474. </code></pre>
  475. <p>You should also ensure the <code>public_baseurl</code> option in <code>homeserver.yaml</code> is set
  476. correctly. <code>public_baseurl</code> should be set to the URL that clients will use to
  477. connect to your server. This is the same URL you put for the <code>m.homeserver</code>
  478. <code>base_url</code> above.</p>
  479. <pre><code class="language-yaml">public_baseurl: &quot;https://&lt;matrix.example.com&gt;&quot;
  480. </code></pre>
  481. <h3 id="email"><a class="header" href="#email">Email</a></h3>
  482. <p>It is desirable for Synapse to have the capability to send email. This allows
  483. Synapse to send password reset emails, send verifications when an email address
  484. is added to a user's account, and send email notifications to users when they
  485. receive new messages.</p>
  486. <p>To configure an SMTP server for Synapse, modify the configuration section
  487. headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>, <code>smtp_port</code>
  488. and <code>notif_from</code> fields filled out. You may also need to set <code>smtp_user</code>,
  489. <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  490. <p>If email is not configured, password reset, registration and notifications via
  491. email will be disabled.</p>
  492. <h3 id="registering-a-user"><a class="header" href="#registering-a-user">Registering a user</a></h3>
  493. <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>
  494. <p>Alternatively, you can do so from the command line. This can be done as follows:</p>
  495. <ol>
  496. <li>If synapse was installed via pip, activate the virtualenv as follows (if Synapse was
  497. installed via a prebuilt package, <code>register_new_matrix_user</code> should already be
  498. on the search path):
  499. <pre><code class="language-sh">cd ~/synapse
  500. source env/bin/activate
  501. synctl start # if not already running
  502. </code></pre>
  503. </li>
  504. <li>Run the following command:
  505. <pre><code class="language-sh">register_new_matrix_user -c homeserver.yaml http://localhost:8008
  506. </code></pre>
  507. </li>
  508. </ol>
  509. <p>This will prompt you to add details for the new user, and will then connect to
  510. the running Synapse to create the new user. For example:</p>
  511. <pre><code>New user localpart: erikj
  512. Password:
  513. Confirm password:
  514. Make admin [no]:
  515. Success!
  516. </code></pre>
  517. <p>This process uses a setting <code>registration_shared_secret</code> in
  518. <code>homeserver.yaml</code>, which is shared between Synapse itself and the
  519. <code>register_new_matrix_user</code> script. It doesn't matter what it is (a random
  520. value is generated by <code>--generate-config</code>), but it should be kept secret, as
  521. anyone with knowledge of it can register users, including admin accounts,
  522. on your server even if <code>enable_registration</code> is <code>false</code>.</p>
  523. <h3 id="setting-up-a-turn-server"><a class="header" href="#setting-up-a-turn-server">Setting up a TURN server</a></h3>
  524. <p>For reliable VoIP calls to be routed via this homeserver, you MUST configure
  525. a TURN server. See <a href="setup/../turn-howto.html">TURN setup</a> for details.</p>
  526. <h3 id="url-previews"><a class="header" href="#url-previews">URL previews</a></h3>
  527. <p>Synapse includes support for previewing URLs, which is disabled by default. To
  528. turn it on you must enable the <code>url_preview_enabled: True</code> config parameter
  529. and explicitly specify the IP ranges that Synapse is not allowed to spider for
  530. previewing in the <code>url_preview_ip_range_blacklist</code> configuration parameter.
  531. This is critical from a security perspective to stop arbitrary Matrix users
  532. spidering 'internal' URLs on your network. At the very least we recommend that
  533. your loopback and RFC1918 IP addresses are blacklisted.</p>
  534. <p>This also requires the optional <code>lxml</code> python dependency to be installed. This
  535. in turn requires the <code>libxml2</code> library to be available - on Debian/Ubuntu this
  536. means <code>apt-get install libxml2-dev</code>, or equivalent for your OS.</p>
  537. <h3 id="troubleshooting-installation"><a class="header" href="#troubleshooting-installation">Troubleshooting Installation</a></h3>
  538. <p><code>pip</code> seems to leak <em>lots</em> of memory during installation. For instance, a Linux
  539. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  540. happens, you will have to individually install the dependencies which are
  541. failing, e.g.:</p>
  542. <pre><code class="language-sh">pip install twisted
  543. </code></pre>
  544. <p>If you have any other problems, feel free to ask in
  545. <a href="https://matrix.to/#/#synapse:matrix.org">#synapse:matrix.org</a>.</p>
  546. <div style="break-before: page; page-break-before: always;"></div><h1 id="using-postgres"><a class="header" href="#using-postgres">Using Postgres</a></h1>
  547. <p>Synapse supports PostgreSQL versions 9.6 or later.</p>
  548. <h2 id="install-postgres-client-libraries"><a class="header" href="#install-postgres-client-libraries">Install postgres client libraries</a></h2>
  549. <p>Synapse will require the python postgres client library in order to
  550. connect to a postgres database.</p>
  551. <ul>
  552. <li>
  553. <p>If you are using the <a href="setup/installation.html#matrixorg-packages">matrix.org debian/ubuntu
  554. packages</a>, the necessary python
  555. library will already be installed, but you will need to ensure the
  556. low-level postgres library is installed, which you can do with
  557. <code>apt install libpq5</code>.</p>
  558. </li>
  559. <li>
  560. <p>For other pre-built packages, please consult the documentation from
  561. the relevant package.</p>
  562. </li>
  563. <li>
  564. <p>If you installed synapse <a href="setup/installation.html#installing-from-source">in a
  565. virtualenv</a>, you can install
  566. the library with:</p>
  567. <pre><code>~/synapse/env/bin/pip install &quot;matrix-synapse[postgres]&quot;
  568. </code></pre>
  569. <p>(substituting the path to your virtualenv for <code>~/synapse/env</code>, if
  570. you used a different path). You will require the postgres
  571. development files. These are in the <code>libpq-dev</code> package on
  572. Debian-derived distributions.</p>
  573. </li>
  574. </ul>
  575. <h2 id="set-up-database"><a class="header" href="#set-up-database">Set up database</a></h2>
  576. <p>Assuming your PostgreSQL database user is called <code>postgres</code>, first authenticate as the database user with:</p>
  577. <pre><code>su - postgres
  578. # Or, if your system uses sudo to get administrative rights
  579. sudo -u postgres bash
  580. </code></pre>
  581. <p>Then, create a postgres user and a database with:</p>
  582. <pre><code># this will prompt for a password for the new user
  583. createuser --pwprompt synapse_user
  584. createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse
  585. </code></pre>
  586. <p>The above will create a user called <code>synapse_user</code>, and a database called
  587. <code>synapse</code>.</p>
  588. <p>Note that the PostgreSQL database <em>must</em> have the correct encoding set
  589. (as shown above), otherwise it will not be able to store UTF8 strings.</p>
  590. <p>You may need to enable password authentication so <code>synapse_user</code> can
  591. connect to the database. See
  592. <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>
  593. <h2 id="synapse-config"><a class="header" href="#synapse-config">Synapse config</a></h2>
  594. <p>When you are ready to start using PostgreSQL, edit the <code>database</code>
  595. section in your config file to match the following lines:</p>
  596. <pre><code class="language-yaml">database:
  597. name: psycopg2
  598. args:
  599. user: &lt;user&gt;
  600. password: &lt;pass&gt;
  601. database: &lt;db&gt;
  602. host: &lt;host&gt;
  603. cp_min: 5
  604. cp_max: 10
  605. </code></pre>
  606. <p>All key, values in <code>args</code> are passed to the <code>psycopg2.connect(..)</code>
  607. function, except keys beginning with <code>cp_</code>, which are consumed by the
  608. twisted adbapi connection pool. See the <a href="https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS">libpq
  609. documentation</a>
  610. for a list of options which can be passed.</p>
  611. <p>You should consider tuning the <code>args.keepalives_*</code> options if there is any danger of
  612. the connection between your homeserver and database dropping, otherwise Synapse
  613. may block for an extended period while it waits for a response from the
  614. database server. Example values might be:</p>
  615. <pre><code class="language-yaml">database:
  616. args:
  617. # ... as above
  618. # seconds of inactivity after which TCP should send a keepalive message to the server
  619. keepalives_idle: 10
  620. # the number of seconds after which a TCP keepalive message that is not
  621. # acknowledged by the server should be retransmitted
  622. keepalives_interval: 10
  623. # the number of TCP keepalives that can be lost before the client's connection
  624. # to the server is considered dead
  625. keepalives_count: 3
  626. </code></pre>
  627. <h2 id="tuning-postgres"><a class="header" href="#tuning-postgres">Tuning Postgres</a></h2>
  628. <p>The default settings should be fine for most deployments. For larger
  629. scale deployments tuning some of the settings is recommended, details of
  630. which can be found at
  631. <a href="https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server">https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server</a>.</p>
  632. <p>In particular, we've found tuning the following values helpful for
  633. performance:</p>
  634. <ul>
  635. <li><code>shared_buffers</code></li>
  636. <li><code>effective_cache_size</code></li>
  637. <li><code>work_mem</code></li>
  638. <li><code>maintenance_work_mem</code></li>
  639. <li><code>autovacuum_work_mem</code></li>
  640. </ul>
  641. <p>Note that the appropriate values for those fields depend on the amount
  642. of free memory the database host has available.</p>
  643. <h2 id="porting-from-sqlite"><a class="header" href="#porting-from-sqlite">Porting from SQLite</a></h2>
  644. <h3 id="overview"><a class="header" href="#overview">Overview</a></h3>
  645. <p>The script <code>synapse_port_db</code> allows porting an existing synapse server
  646. backed by SQLite to using PostgreSQL. This is done in as a two phase
  647. process:</p>
  648. <ol>
  649. <li>Copy the existing SQLite database to a separate location and run
  650. the port script against that offline database.</li>
  651. <li>Shut down the server. Rerun the port script to port any data that
  652. has come in since taking the first snapshot. Restart server against
  653. the PostgreSQL database.</li>
  654. </ol>
  655. <p>The port script is designed to be run repeatedly against newer snapshots
  656. of the SQLite database file. This makes it safe to repeat step 1 if
  657. there was a delay between taking the previous snapshot and being ready
  658. to do step 2.</p>
  659. <p>It is safe to at any time kill the port script and restart it.</p>
  660. <p>Note that the database may take up significantly more (25% - 100% more)
  661. space on disk after porting to Postgres.</p>
  662. <h3 id="using-the-port-script"><a class="header" href="#using-the-port-script">Using the port script</a></h3>
  663. <p>Firstly, shut down the currently running synapse server and copy its
  664. database file (typically <code>homeserver.db</code>) to another location. Once the
  665. copy is complete, restart synapse. For instance:</p>
  666. <pre><code>./synctl stop
  667. cp homeserver.db homeserver.db.snapshot
  668. ./synctl start
  669. </code></pre>
  670. <p>Copy the old config file into a new config file:</p>
  671. <pre><code>cp homeserver.yaml homeserver-postgres.yaml
  672. </code></pre>
  673. <p>Edit the database section as described in the section <em>Synapse config</em>
  674. above and with the SQLite snapshot located at <code>homeserver.db.snapshot</code>
  675. simply run:</p>
  676. <pre><code>synapse_port_db --sqlite-database homeserver.db.snapshot \
  677. --postgres-config homeserver-postgres.yaml
  678. </code></pre>
  679. <p>The flag <code>--curses</code> displays a coloured curses progress UI.</p>
  680. <p>If the script took a long time to complete, or time has otherwise passed
  681. since the original snapshot was taken, repeat the previous steps with a
  682. newer snapshot.</p>
  683. <p>To complete the conversion shut down the synapse server and run the port
  684. script one last time, e.g. if the SQLite database is at <code>homeserver.db</code>
  685. run:</p>
  686. <pre><code>synapse_port_db --sqlite-database homeserver.db \
  687. --postgres-config homeserver-postgres.yaml
  688. </code></pre>
  689. <p>Once that has completed, change the synapse config to point at the
  690. PostgreSQL database configuration file <code>homeserver-postgres.yaml</code>:</p>
  691. <pre><code>./synctl stop
  692. mv homeserver.yaml homeserver-old-sqlite.yaml
  693. mv homeserver-postgres.yaml homeserver.yaml
  694. ./synctl start
  695. </code></pre>
  696. <p>Synapse should now be running against PostgreSQL.</p>
  697. <h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
  698. <h3 id="alternative-auth-methods"><a class="header" href="#alternative-auth-methods">Alternative auth methods</a></h3>
  699. <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
  700. <code>ident</code>:</p>
  701. <ul>
  702. <li>
  703. <p>If the <code>synapse_user</code> user has a password, add the password to the <code>database:</code>
  704. section of <code>homeserver.yaml</code>. Then add the following to <code>pg_hba.conf</code>:</p>
  705. <pre><code>host synapse synapse_user ::1/128 md5 # or `scram-sha-256` instead of `md5` if you use that
  706. </code></pre>
  707. </li>
  708. <li>
  709. <p>If the <code>synapse_user</code> user does not have a password, then a password doesn't
  710. have to be added to <code>homeserver.yaml</code>. But the following does need to be added
  711. to <code>pg_hba.conf</code>:</p>
  712. <pre><code>host synapse synapse_user ::1/128 trust
  713. </code></pre>
  714. </li>
  715. </ul>
  716. <p>Note that line order matters in <code>pg_hba.conf</code>, so make sure that if you do add a
  717. new line, it is inserted before:</p>
  718. <pre><code>host all all ::1/128 ident
  719. </code></pre>
  720. <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>
  721. <p>Synapse will refuse to set up a new database if it has the wrong values of
  722. <code>COLLATE</code> and <code>CTYPE</code> set, and will log warnings on existing databases. Using
  723. different locales can cause issues if the locale library is updated from
  724. underneath the database, or if a different version of the locale is used on any
  725. replicas.</p>
  726. <p>The safest way to fix the issue is to dump the database and recreate it with
  727. the correct locale parameter (as shown above). It is also possible to change the
  728. parameters on a live database and run a <code>REINDEX</code> on the entire database,
  729. however extreme care must be taken to avoid database corruption.</p>
  730. <p>Note that the above may fail with an error about duplicate rows if corruption
  731. has already occurred, and such duplicate rows will need to be manually removed.</p>
  732. <h3 id="fixing-inconsistent-sequences-error"><a class="header" href="#fixing-inconsistent-sequences-error">Fixing inconsistent sequences error</a></h3>
  733. <p>Synapse uses Postgres sequences to generate IDs for various tables. A sequence
  734. and associated table can get out of sync if, for example, Synapse has been
  735. downgraded and then upgraded again.</p>
  736. <p>To fix the issue shut down Synapse (including any and all workers) and run the
  737. SQL command included in the error message. Once done Synapse should start
  738. successfully.</p>
  739. <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>
  740. <p>It is recommended to put a reverse proxy such as
  741. <a href="https://nginx.org/en/docs/http/ngx_http_proxy_module.html">nginx</a>,
  742. <a href="https://httpd.apache.org/docs/current/mod/mod_proxy_http.html">Apache</a>,
  743. <a href="https://caddyserver.com/docs/quick-starts/reverse-proxy">Caddy</a>,
  744. <a href="https://www.haproxy.org/">HAProxy</a> or
  745. <a href="https://man.openbsd.org/relayd.8">relayd</a> in front of Synapse. One advantage
  746. of doing so is that it means that you can expose the default https port
  747. (443) to Matrix clients without needing to run Synapse with root
  748. privileges.</p>
  749. <p>You should configure your reverse proxy to forward requests to <code>/_matrix</code> or
  750. <code>/_synapse/client</code> to Synapse, and have it set the <code>X-Forwarded-For</code> and
  751. <code>X-Forwarded-Proto</code> request headers.</p>
  752. <p>You should remember that Matrix clients and other Matrix servers do not
  753. necessarily need to connect to your server via the same server name or
  754. port. Indeed, clients will use port 443 by default, whereas servers default to
  755. port 8448. Where these are different, we refer to the 'client port' and the
  756. 'federation port'. See <a href="https://matrix.org/docs/spec/server_server/latest#resolving-server-names">the Matrix
  757. specification</a>
  758. for more details of the algorithm used for federation connections, and
  759. <a href="delegate.html">Delegation</a> for instructions on setting up delegation.</p>
  760. <p><strong>NOTE</strong>: Your reverse proxy must not <code>canonicalise</code> or <code>normalise</code>
  761. the requested URI in any way (for example, by decoding <code>%xx</code> escapes).
  762. Beware that Apache <em>will</em> canonicalise URIs unless you specify
  763. <code>nocanon</code>.</p>
  764. <p>Let's assume that we expect clients to connect to our server at
  765. <code>https://matrix.example.com</code>, and other servers to connect at
  766. <code>https://example.com:8448</code>. The following sections detail the configuration of
  767. the reverse proxy and the homeserver.</p>
  768. <h2 id="homeserver-configuration"><a class="header" href="#homeserver-configuration">Homeserver Configuration</a></h2>
  769. <p>The HTTP configuration will need to be updated for Synapse to correctly record
  770. client IP addresses and generate redirect URLs while behind a reverse proxy. </p>
  771. <p>In <code>homeserver.yaml</code> set <code>x_forwarded: true</code> in the port 8008 section and
  772. consider setting <code>bind_addresses: ['127.0.0.1']</code> so that the server only
  773. listens to traffic on localhost. (Do not change <code>bind_addresses</code> to <code>127.0.0.1</code>
  774. when using a containerized Synapse, as that will prevent it from responding
  775. to proxied traffic.)</p>
  776. <h2 id="reverse-proxy-configuration-examples"><a class="header" href="#reverse-proxy-configuration-examples">Reverse-proxy configuration examples</a></h2>
  777. <p><strong>NOTE</strong>: You only need one of these.</p>
  778. <h3 id="nginx"><a class="header" href="#nginx">nginx</a></h3>
  779. <pre><code>server {
  780. listen 443 ssl http2;
  781. listen [::]:443 ssl http2;
  782. # For the federation port
  783. listen 8448 ssl http2 default_server;
  784. listen [::]:8448 ssl http2 default_server;
  785. server_name matrix.example.com;
  786. location ~* ^(\/_matrix|\/_synapse\/client) {
  787. # note: do not add a path (even a single /) after the port in `proxy_pass`,
  788. # otherwise nginx will canonicalise the URI and cause signature verification
  789. # errors.
  790. proxy_pass http://localhost:8008;
  791. proxy_set_header X-Forwarded-For $remote_addr;
  792. proxy_set_header X-Forwarded-Proto $scheme;
  793. proxy_set_header Host $host;
  794. # Nginx by default only allows file uploads up to 1M in size
  795. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  796. client_max_body_size 50M;
  797. }
  798. }
  799. </code></pre>
  800. <h3 id="caddy-v1"><a class="header" href="#caddy-v1">Caddy v1</a></h3>
  801. <pre><code>matrix.example.com {
  802. proxy /_matrix http://localhost:8008 {
  803. transparent
  804. }
  805. proxy /_synapse/client http://localhost:8008 {
  806. transparent
  807. }
  808. }
  809. example.com:8448 {
  810. proxy / http://localhost:8008 {
  811. transparent
  812. }
  813. }
  814. </code></pre>
  815. <h3 id="caddy-v2"><a class="header" href="#caddy-v2">Caddy v2</a></h3>
  816. <pre><code>matrix.example.com {
  817. reverse_proxy /_matrix/* http://localhost:8008
  818. reverse_proxy /_synapse/client/* http://localhost:8008
  819. }
  820. example.com:8448 {
  821. reverse_proxy http://localhost:8008
  822. }
  823. </code></pre>
  824. <p><a href="delegate.html">Delegation</a> example:</p>
  825. <pre><code>(matrix-well-known-header) {
  826. # Headers
  827. header Access-Control-Allow-Origin &quot;*&quot;
  828. header Access-Control-Allow-Methods &quot;GET, POST, PUT, DELETE, OPTIONS&quot;
  829. header Access-Control-Allow-Headers &quot;Origin, X-Requested-With, Content-Type, Accept, Authorization&quot;
  830. header Content-Type &quot;application/json&quot;
  831. }
  832. example.com {
  833. handle /.well-known/matrix/server {
  834. import matrix-well-known-header
  835. respond `{&quot;m.server&quot;:&quot;matrix.example.com:443&quot;}`
  836. }
  837. handle /.well-known/matrix/client {
  838. import matrix-well-known-header
  839. 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;}}`
  840. }
  841. }
  842. matrix.example.com {
  843. reverse_proxy /_matrix/* http://localhost:8008
  844. reverse_proxy /_synapse/client/* http://localhost:8008
  845. }
  846. </code></pre>
  847. <h3 id="apache"><a class="header" href="#apache">Apache</a></h3>
  848. <pre><code>&lt;VirtualHost *:443&gt;
  849. SSLEngine on
  850. ServerName matrix.example.com
  851. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  852. AllowEncodedSlashes NoDecode
  853. ProxyPreserveHost on
  854. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  855. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  856. ProxyPass /_synapse/client http://127.0.0.1:8008/_synapse/client nocanon
  857. ProxyPassReverse /_synapse/client http://127.0.0.1:8008/_synapse/client
  858. &lt;/VirtualHost&gt;
  859. &lt;VirtualHost *:8448&gt;
  860. SSLEngine on
  861. ServerName example.com
  862. RequestHeader set &quot;X-Forwarded-Proto&quot; expr=%{REQUEST_SCHEME}
  863. AllowEncodedSlashes NoDecode
  864. ProxyPass /_matrix http://127.0.0.1:8008/_matrix nocanon
  865. ProxyPassReverse /_matrix http://127.0.0.1:8008/_matrix
  866. &lt;/VirtualHost&gt;
  867. </code></pre>
  868. <p><strong>NOTE</strong>: ensure the <code>nocanon</code> options are included.</p>
  869. <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>
  870. <pre><code>&lt;IfModule security2_module&gt;
  871. SecRuleEngine off
  872. &lt;/IfModule&gt;
  873. </code></pre>
  874. <p><strong>NOTE 3</strong>: Missing <code>ProxyPreserveHost on</code> can lead to a redirect loop.</p>
  875. <h3 id="haproxy"><a class="header" href="#haproxy">HAProxy</a></h3>
  876. <pre><code>frontend https
  877. bind :::443 v4v6 ssl crt /etc/ssl/haproxy/ strict-sni alpn h2,http/1.1
  878. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  879. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  880. http-request set-header X-Forwarded-For %[src]
  881. # Matrix client traffic
  882. acl matrix-host hdr(host) -i matrix.example.com
  883. acl matrix-path path_beg /_matrix
  884. acl matrix-path path_beg /_synapse/client
  885. use_backend matrix if matrix-host matrix-path
  886. frontend matrix-federation
  887. bind :::8448 v4v6 ssl crt /etc/ssl/haproxy/synapse.pem alpn h2,http/1.1
  888. http-request set-header X-Forwarded-Proto https if { ssl_fc }
  889. http-request set-header X-Forwarded-Proto http if !{ ssl_fc }
  890. http-request set-header X-Forwarded-For %[src]
  891. default_backend matrix
  892. backend matrix
  893. server matrix 127.0.0.1:8008
  894. </code></pre>
  895. <h3 id="relayd"><a class="header" href="#relayd">Relayd</a></h3>
  896. <pre><code>table &lt;webserver&gt; { 127.0.0.1 }
  897. table &lt;matrixserver&gt; { 127.0.0.1 }
  898. http protocol &quot;https&quot; {
  899. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  900. tls keypair &quot;example.com&quot;
  901. match header set &quot;X-Forwarded-For&quot; value &quot;$REMOTE_ADDR&quot;
  902. match header set &quot;X-Forwarded-Proto&quot; value &quot;https&quot;
  903. # set CORS header for .well-known/matrix/server, .well-known/matrix/client
  904. # httpd does not support setting headers, so do it here
  905. match request path &quot;/.well-known/matrix/*&quot; tag &quot;matrix-cors&quot;
  906. match response tagged &quot;matrix-cors&quot; header set &quot;Access-Control-Allow-Origin&quot; value &quot;*&quot;
  907. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  908. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  909. # pass on non-matrix traffic to webserver
  910. pass forward to &lt;webserver&gt;
  911. }
  912. relay &quot;https_traffic&quot; {
  913. listen on egress port 443 tls
  914. protocol &quot;https&quot;
  915. forward to &lt;matrixserver&gt; port 8008 check tcp
  916. forward to &lt;webserver&gt; port 8080 check tcp
  917. }
  918. http protocol &quot;matrix&quot; {
  919. tls { no tlsv1.0, ciphers &quot;HIGH&quot; }
  920. tls keypair &quot;example.com&quot;
  921. block
  922. pass quick path &quot;/_matrix/*&quot; forward to &lt;matrixserver&gt;
  923. pass quick path &quot;/_synapse/client/*&quot; forward to &lt;matrixserver&gt;
  924. }
  925. relay &quot;matrix_federation&quot; {
  926. listen on egress port 8448 tls
  927. protocol &quot;matrix&quot;
  928. forward to &lt;matrixserver&gt; port 8008 check tcp
  929. }
  930. </code></pre>
  931. <h2 id="health-check-endpoint"><a class="header" href="#health-check-endpoint">Health check endpoint</a></h2>
  932. <p>Synapse exposes a health check endpoint for use by reverse proxies.
  933. Each configured HTTP listener has a <code>/health</code> endpoint which always returns
  934. 200 OK (and doesn't get logged).</p>
  935. <h2 id="synapse-administration-endpoints"><a class="header" href="#synapse-administration-endpoints">Synapse administration endpoints</a></h2>
  936. <p>Endpoints for administering your Synapse instance are placed under
  937. <code>/_synapse/admin</code>. These require authentication through an access token of an
  938. admin user. However as access to these endpoints grants the caller a lot of power,
  939. we do not recommend exposing them to the public internet without good reason.</p>
  940. <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>
  941. <p>You can use Synapse with a forward or outbound proxy. An example of when
  942. this is necessary is in corporate environments behind a DMZ (demilitarized zone).
  943. Synapse supports routing outbound HTTP(S) requests via a proxy. Only HTTP(S)
  944. proxy is supported, not SOCKS proxy or anything else.</p>
  945. <h2 id="configure"><a class="header" href="#configure">Configure</a></h2>
  946. <p>The <code>http_proxy</code>, <code>https_proxy</code>, <code>no_proxy</code> environment variables are used to
  947. specify proxy settings. The environment variable is not case sensitive.</p>
  948. <ul>
  949. <li><code>http_proxy</code>: Proxy server to use for HTTP requests.</li>
  950. <li><code>https_proxy</code>: Proxy server to use for HTTPS requests.</li>
  951. <li><code>no_proxy</code>: Comma-separated list of hosts, IP addresses, or IP ranges in CIDR
  952. format which should not use the proxy. Synapse will directly connect to these hosts.</li>
  953. </ul>
  954. <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>
  955. <ul>
  956. <li>
  957. <p>Supported schemes are <code>http://</code> and <code>https://</code>. The default scheme is <code>http://</code>
  958. for compatibility reasons; it is recommended to set a scheme. If scheme is set
  959. to <code>https://</code> the connection uses TLS between Synapse and the proxy.</p>
  960. <p><strong>NOTE</strong>: Synapse validates the certificates. If the certificate is not
  961. valid, then the connection is dropped.</p>
  962. </li>
  963. <li>
  964. <p>Default port if not given is <code>1080</code>.</p>
  965. </li>
  966. <li>
  967. <p>Username and password are optional and will be used to authenticate against
  968. the proxy.</p>
  969. </li>
  970. </ul>
  971. <p><strong>Examples</strong></p>
  972. <ul>
  973. <li>HTTP_PROXY=http://USERNAME:PASSWORD@10.0.1.1:8080/</li>
  974. <li>HTTPS_PROXY=http://USERNAME:PASSWORD@proxy.example.com:8080/</li>
  975. <li>NO_PROXY=master.hostname.example.com,10.1.0.0/16,172.30.0.0/16</li>
  976. </ul>
  977. <p><strong>NOTE</strong>:
  978. Synapse does not apply the IP blacklist to connections through the proxy (since
  979. the DNS resolution is done by the proxy). It is expected that the proxy or firewall
  980. will apply blacklisting of IP addresses.</p>
  981. <h2 id="connection-types"><a class="header" href="#connection-types">Connection types</a></h2>
  982. <p>The proxy will be <strong>used</strong> for:</p>
  983. <ul>
  984. <li>push</li>
  985. <li>url previews</li>
  986. <li>phone-home stats</li>
  987. <li>recaptcha validation</li>
  988. <li>CAS auth validation</li>
  989. <li>OpenID Connect</li>
  990. <li>Outbound federation</li>
  991. <li>Federation (checking public key revocation)</li>
  992. <li>Fetching public keys of other servers</li>
  993. <li>Downloading remote media</li>
  994. </ul>
  995. <p>It will <strong>not be used</strong> for:</p>
  996. <ul>
  997. <li>Application Services</li>
  998. <li>Identity servers</li>
  999. <li>In worker configurations
  1000. <ul>
  1001. <li>connections between workers</li>
  1002. <li>connections from workers to Redis</li>
  1003. </ul>
  1004. </li>
  1005. </ul>
  1006. <h2 id="troubleshooting-1"><a class="header" href="#troubleshooting-1">Troubleshooting</a></h2>
  1007. <p>If a proxy server is used with TLS (HTTPS) and no connections are established,
  1008. it is most likely due to the proxy's certificates. To test this, the validation
  1009. in Synapse can be deactivated.</p>
  1010. <p><strong>NOTE</strong>: This has an impact on security and is for testing purposes only!</p>
  1011. <p>To deactivate the certificate validation, the following setting must be made in
  1012. <a href="setup/../usage/configuration/homeserver_sample_config.html">homserver.yaml</a>.</p>
  1013. <pre><code class="language-yaml">use_insecure_ssl_client_just_for_testing_do_not_use: true
  1014. </code></pre>
  1015. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-1"><a class="header" href="#overview-1">Overview</a></h1>
  1016. <p>This document explains how to enable VoIP relaying on your Home Server with
  1017. TURN.</p>
  1018. <p>The synapse Matrix Home Server supports integration with TURN server via the
  1019. <a href="https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00">TURN server REST API</a>. This
  1020. allows the Home Server to generate credentials that are valid for use on the
  1021. TURN server through the use of a secret shared between the Home Server and the
  1022. TURN server.</p>
  1023. <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>
  1024. <h2 id="requirements"><a class="header" href="#requirements">Requirements</a></h2>
  1025. <p>For TURN relaying with <code>coturn</code> to work, it must be hosted on a server/endpoint with a public IP.</p>
  1026. <p>Hosting TURN behind a NAT (even with appropriate port forwarding) is known to cause issues
  1027. and to often not work.</p>
  1028. <h2 id="coturn-setup"><a class="header" href="#coturn-setup"><code>coturn</code> setup</a></h2>
  1029. <h3 id="initial-installation"><a class="header" href="#initial-installation">Initial installation</a></h3>
  1030. <p>The TURN daemon <code>coturn</code> is available from a variety of sources such as native package managers, or installation from source.</p>
  1031. <h4 id="debian-installation"><a class="header" href="#debian-installation">Debian installation</a></h4>
  1032. <p>Just install the debian package:</p>
  1033. <pre><code class="language-sh">apt install coturn
  1034. </code></pre>
  1035. <p>This will install and start a systemd service called <code>coturn</code>.</p>
  1036. <h4 id="source-installation"><a class="header" href="#source-installation">Source installation</a></h4>
  1037. <ol>
  1038. <li>
  1039. <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>
  1040. </li>
  1041. <li>
  1042. <p>Configure it:</p>
  1043. <pre><code>./configure
  1044. </code></pre>
  1045. <p>You may need to install <code>libevent2</code>: if so, you should do so in
  1046. the way recommended by your operating system. You can ignore
  1047. warnings about lack of database support: a database is unnecessary
  1048. for this purpose.</p>
  1049. </li>
  1050. <li>
  1051. <p>Build and install it:</p>
  1052. <pre><code>make
  1053. make install
  1054. </code></pre>
  1055. </li>
  1056. </ol>
  1057. <h3 id="configuration"><a class="header" href="#configuration">Configuration</a></h3>
  1058. <ol>
  1059. <li>
  1060. <p>Create or edit the config file in <code>/etc/turnserver.conf</code>. The relevant
  1061. lines, with example values, are:</p>
  1062. <pre><code>use-auth-secret
  1063. static-auth-secret=[your secret key here]
  1064. realm=turn.myserver.org
  1065. </code></pre>
  1066. <p>See <code>turnserver.conf</code> for explanations of the options. One way to generate
  1067. the <code>static-auth-secret</code> is with <code>pwgen</code>:</p>
  1068. <pre><code>pwgen -s 64 1
  1069. </code></pre>
  1070. <p>A <code>realm</code> must be specified, but its value is somewhat arbitrary. (It is
  1071. sent to clients as part of the authentication flow.) It is conventional to
  1072. set it to be your server name.</p>
  1073. </li>
  1074. <li>
  1075. <p>You will most likely want to configure coturn to write logs somewhere. The
  1076. easiest way is normally to send them to the syslog:</p>
  1077. <pre><code>syslog
  1078. </code></pre>
  1079. <p>(in which case, the logs will be available via <code>journalctl -u coturn</code> on a
  1080. systemd system). Alternatively, coturn can be configured to write to a
  1081. logfile - check the example config file supplied with coturn.</p>
  1082. </li>
  1083. <li>
  1084. <p>Consider your security settings. TURN lets users request a relay which will
  1085. connect to arbitrary IP addresses and ports. The following configuration is
  1086. suggested as a minimum starting point:</p>
  1087. <pre><code># VoIP traffic is all UDP. There is no reason to let users connect to arbitrary TCP endpoints via the relay.
  1088. no-tcp-relay
  1089. # don't let the relay ever try to connect to private IP address ranges within your network (if any)
  1090. # given the turn server is likely behind your firewall, remember to include any privileged public IPs too.
  1091. denied-peer-ip=10.0.0.0-10.255.255.255
  1092. denied-peer-ip=192.168.0.0-192.168.255.255
  1093. denied-peer-ip=172.16.0.0-172.31.255.255
  1094. # special case the turn server itself so that client-&gt;TURN-&gt;TURN-&gt;client flows work
  1095. allowed-peer-ip=10.0.0.1
  1096. # consider whether you want to limit the quota of relayed streams per user (or total) to avoid risk of DoS.
  1097. user-quota=12 # 4 streams per video call, so 12 streams = 3 simultaneous relayed calls per user.
  1098. total-quota=1200
  1099. </code></pre>
  1100. </li>
  1101. <li>
  1102. <p>Also consider supporting TLS/DTLS. To do this, add the following settings
  1103. to <code>turnserver.conf</code>:</p>
  1104. <pre><code># TLS certificates, including intermediate certs.
  1105. # For Let's Encrypt certificates, use `fullchain.pem` here.
  1106. cert=/path/to/fullchain.pem
  1107. # TLS private key file
  1108. pkey=/path/to/privkey.pem
  1109. </code></pre>
  1110. <p>In this case, replace the <code>turn:</code> schemes in the <code>turn_uri</code> settings below
  1111. with <code>turns:</code>.</p>
  1112. <p>We recommend that you only try to set up TLS/DTLS once you have set up a
  1113. basic installation and got it working.</p>
  1114. </li>
  1115. <li>
  1116. <p>Ensure your firewall allows traffic into the TURN server on the ports
  1117. you've configured it to listen on (By default: 3478 and 5349 for TURN
  1118. traffic (remember to allow both TCP and UDP traffic), and ports 49152-65535
  1119. for the UDP relay.)</p>
  1120. </li>
  1121. <li>
  1122. <p>We do not recommend running a TURN server behind NAT, and are not aware of
  1123. anyone doing so successfully.</p>
  1124. <p>If you want to try it anyway, you will at least need to tell coturn its
  1125. external IP address:</p>
  1126. <pre><code>external-ip=192.88.99.1
  1127. </code></pre>
  1128. <p>... and your NAT gateway must forward all of the relayed ports directly
  1129. (eg, port 56789 on the external IP must be always be forwarded to port
  1130. 56789 on the internal IP).</p>
  1131. <p>If you get this working, let us know!</p>
  1132. </li>
  1133. <li>
  1134. <p>(Re)start the turn server:</p>
  1135. <ul>
  1136. <li>
  1137. <p>If you used the Debian package (or have set up a systemd unit yourself):</p>
  1138. <pre><code class="language-sh">systemctl restart coturn
  1139. </code></pre>
  1140. </li>
  1141. <li>
  1142. <p>If you installed from source:</p>
  1143. <pre><code class="language-sh">bin/turnserver -o
  1144. </code></pre>
  1145. </li>
  1146. </ul>
  1147. </li>
  1148. </ol>
  1149. <h2 id="synapse-setup"><a class="header" href="#synapse-setup">Synapse setup</a></h2>
  1150. <p>Your home server configuration file needs the following extra keys:</p>
  1151. <ol>
  1152. <li>&quot;<code>turn_uris</code>&quot;: This needs to be a yaml list of public-facing URIs
  1153. for your TURN server to be given out to your clients. Add separate
  1154. entries for each transport your TURN server supports.</li>
  1155. <li>&quot;<code>turn_shared_secret</code>&quot;: This is the secret shared between your
  1156. Home server and your TURN server, so you should set it to the same
  1157. string you used in turnserver.conf.</li>
  1158. <li>&quot;<code>turn_user_lifetime</code>&quot;: This is the amount of time credentials
  1159. generated by your Home Server are valid for (in milliseconds).
  1160. Shorter times offer less potential for abuse at the expense of
  1161. increased traffic between web clients and your home server to
  1162. refresh credentials. The TURN REST API specification recommends
  1163. one day (86400000).</li>
  1164. <li>&quot;<code>turn_allow_guests</code>&quot;: Whether to allow guest users to use the
  1165. TURN server. This is enabled by default, as otherwise VoIP will
  1166. not work reliably for guests. However, it does introduce a
  1167. security risk as it lets guests connect to arbitrary endpoints
  1168. without having gone through a CAPTCHA or similar to register a
  1169. real account.</li>
  1170. </ol>
  1171. <p>As an example, here is the relevant section of the config file for <code>matrix.org</code>. The
  1172. <code>turn_uris</code> are appropriate for TURN servers listening on the default ports, with no TLS.</p>
  1173. <pre><code>turn_uris: [ &quot;turn:turn.matrix.org?transport=udp&quot;, &quot;turn:turn.matrix.org?transport=tcp&quot; ]
  1174. turn_shared_secret: &quot;n0t4ctuAllymatr1Xd0TorgSshar3d5ecret4obvIousreAsons&quot;
  1175. turn_user_lifetime: 86400000
  1176. turn_allow_guests: True
  1177. </code></pre>
  1178. <p>After updating the homeserver configuration, you must restart synapse:</p>
  1179. <ul>
  1180. <li>If you use synctl:
  1181. <pre><code class="language-sh">cd /where/you/run/synapse
  1182. ./synctl restart
  1183. </code></pre>
  1184. </li>
  1185. <li>If you use systemd:
  1186. <pre><code>systemctl restart matrix-synapse.service
  1187. </code></pre>
  1188. </li>
  1189. </ul>
  1190. <p>... and then reload any clients (or wait an hour for them to refresh their
  1191. settings).</p>
  1192. <h2 id="troubleshooting-2"><a class="header" href="#troubleshooting-2">Troubleshooting</a></h2>
  1193. <p>The normal symptoms of a misconfigured TURN server are that calls between
  1194. devices on different networks ring, but get stuck at &quot;call
  1195. connecting&quot;. Unfortunately, troubleshooting this can be tricky.</p>
  1196. <p>Here are a few things to try:</p>
  1197. <ul>
  1198. <li>
  1199. <p>Check that your TURN server is not behind NAT. As above, we're not aware of
  1200. anyone who has successfully set this up.</p>
  1201. </li>
  1202. <li>
  1203. <p>Check that you have opened your firewall to allow TCP and UDP traffic to the
  1204. TURN ports (normally 3478 and 5479).</p>
  1205. </li>
  1206. <li>
  1207. <p>Check that you have opened your firewall to allow UDP traffic to the UDP
  1208. relay ports (49152-65535 by default).</p>
  1209. </li>
  1210. <li>
  1211. <p>Some WebRTC implementations (notably, that of Google Chrome) appear to get
  1212. confused by TURN servers which are reachable over IPv6 (this appears to be
  1213. an unexpected side-effect of its handling of multiple IP addresses as
  1214. defined by
  1215. <a href="https://tools.ietf.org/html/draft-ietf-rtcweb-ip-handling-12"><code>draft-ietf-rtcweb-ip-handling</code></a>).</p>
  1216. <p>Try removing any AAAA records for your TURN server, so that it is only
  1217. reachable over IPv4.</p>
  1218. </li>
  1219. <li>
  1220. <p>Enable more verbose logging in coturn via the <code>verbose</code> setting:</p>
  1221. <pre><code>verbose
  1222. </code></pre>
  1223. <p>... and then see if there are any clues in its logs.</p>
  1224. </li>
  1225. <li>
  1226. <p>If you are using a browser-based client under Chrome, check
  1227. <code>chrome://webrtc-internals/</code> for insights into the internals of the
  1228. negotiation. On Firefox, check the &quot;Connection Log&quot; on <code>about:webrtc</code>.</p>
  1229. <p>(Understanding the output is beyond the scope of this document!)</p>
  1230. </li>
  1231. <li>
  1232. <p>You can test your Matrix homeserver TURN setup with https://test.voip.librepush.net/.
  1233. Note that this test is not fully reliable yet, so don't be discouraged if
  1234. the test fails.
  1235. <a href="https://github.com/matrix-org/voip-tester">Here</a> is the github repo of the
  1236. source of the tester, where you can file bug reports.</p>
  1237. </li>
  1238. <li>
  1239. <p>There is a WebRTC test tool at
  1240. https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/. To
  1241. use it, you will need a username/password for your TURN server. You can
  1242. either:</p>
  1243. <ul>
  1244. <li>
  1245. <p>look for the <code>GET /_matrix/client/r0/voip/turnServer</code> request made by a
  1246. matrix client to your homeserver in your browser's network inspector. In
  1247. the response you should see <code>username</code> and <code>password</code>. Or:</p>
  1248. </li>
  1249. <li>
  1250. <p>Use the following shell commands:</p>
  1251. <pre><code class="language-sh">secret=staticAuthSecretHere
  1252. u=$((`date +%s` + 3600)):test
  1253. p=$(echo -n $u | openssl dgst -hmac $secret -sha1 -binary | base64)
  1254. echo -e &quot;username: $u\npassword: $p&quot;
  1255. </code></pre>
  1256. <p>Or:</p>
  1257. </li>
  1258. <li>
  1259. <p>Temporarily configure coturn to accept a static username/password. To do
  1260. this, comment out <code>use-auth-secret</code> and <code>static-auth-secret</code> and add the
  1261. following:</p>
  1262. <pre><code>lt-cred-mech
  1263. user=username:password
  1264. </code></pre>
  1265. <p><strong>Note</strong>: these settings will not take effect unless <code>use-auth-secret</code>
  1266. and <code>static-auth-secret</code> are disabled.</p>
  1267. <p>Restart coturn after changing the configuration file.</p>
  1268. <p>Remember to restore the original settings to go back to testing with
  1269. Matrix clients!</p>
  1270. </li>
  1271. </ul>
  1272. <p>If the TURN server is working correctly, you should see at least one <code>relay</code>
  1273. entry in the results.</p>
  1274. </li>
  1275. </ul>
  1276. <div style="break-before: page; page-break-before: always;"></div><h1 id="delegation"><a class="header" href="#delegation">Delegation</a></h1>
  1277. <p>By default, other homeservers will expect to be able to reach yours via
  1278. your <code>server_name</code>, on port 8448. For example, if you set your <code>server_name</code>
  1279. to <code>example.com</code> (so that your user names look like <code>@user:example.com</code>),
  1280. other servers will try to connect to yours at <code>https://example.com:8448/</code>.</p>
  1281. <p>Delegation is a Matrix feature allowing a homeserver admin to retain a
  1282. <code>server_name</code> of <code>example.com</code> so that user IDs, room aliases, etc continue
  1283. to look like <code>*:example.com</code>, whilst having federation traffic routed
  1284. to a different server and/or port (e.g. <code>synapse.example.com:443</code>).</p>
  1285. <h2 id="well-known-delegation"><a class="header" href="#well-known-delegation">.well-known delegation</a></h2>
  1286. <p>To use this method, you need to be able to alter the
  1287. <code>server_name</code> 's https server to serve the <code>/.well-known/matrix/server</code>
  1288. URL. Having an active server (with a valid TLS certificate) serving your
  1289. <code>server_name</code> domain is out of the scope of this documentation.</p>
  1290. <p>The URL <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> should
  1291. return a JSON structure containing the key <code>m.server</code> like so:</p>
  1292. <pre><code class="language-json">{
  1293. &quot;m.server&quot;: &quot;&lt;synapse.server.name&gt;[:&lt;yourport&gt;]&quot;
  1294. }
  1295. </code></pre>
  1296. <p>In our example, this would mean that URL <code>https://example.com/.well-known/matrix/server</code>
  1297. should return:</p>
  1298. <pre><code class="language-json">{
  1299. &quot;m.server&quot;: &quot;synapse.example.com:443&quot;
  1300. }
  1301. </code></pre>
  1302. <p>Note, specifying a port is optional. If no port is specified, then it defaults
  1303. to 8448.</p>
  1304. <p>With .well-known delegation, federating servers will check for a valid TLS
  1305. certificate for the delegated hostname (in our example: <code>synapse.example.com</code>).</p>
  1306. <h2 id="srv-dns-record-delegation"><a class="header" href="#srv-dns-record-delegation">SRV DNS record delegation</a></h2>
  1307. <p>It is also possible to do delegation using a SRV DNS record. However, that is
  1308. considered an advanced topic since it's a bit complex to set up, and <code>.well-known</code>
  1309. delegation is already enough in most cases.</p>
  1310. <p>However, if you really need it, you can find some documentation on how such a
  1311. 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
  1312. specification</a>.</p>
  1313. <h2 id="delegation-faq"><a class="header" href="#delegation-faq">Delegation FAQ</a></h2>
  1314. <h3 id="when-do-i-need-delegation"><a class="header" href="#when-do-i-need-delegation">When do I need delegation?</a></h3>
  1315. <p>If your homeserver's APIs are accessible on the default federation port (8448)
  1316. and the domain your <code>server_name</code> points to, you do not need any delegation.</p>
  1317. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  1318. fresh server, you could install Synapse on that host, giving it a <code>server_name</code>
  1319. of <code>example.com</code>, and once a reverse proxy has been set up to proxy all requests
  1320. sent to the port <code>8448</code> and serve TLS certificates for <code>example.com</code>, you
  1321. wouldn't need any delegation set up.</p>
  1322. <p><strong>However</strong>, if your homeserver's APIs aren't accessible on port 8448 and on the
  1323. domain <code>server_name</code> points to, you will need to let other servers know how to
  1324. find it using delegation.</p>
  1325. <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>
  1326. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  1327. find it easier to direct federation traffic to a reverse proxy and manage their
  1328. own TLS certificates, and this is a supported configuration.</p>
  1329. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  1330. reverse proxy.</p>
  1331. <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>
  1332. <p>This is no longer necessary. If you are using a reverse proxy for all of your
  1333. TLS traffic, then you can set <code>no_tls: True</code> in the Synapse config.</p>
  1334. <p>In that case, the only reason Synapse needs the certificate is to populate a legacy
  1335. <code>tls_fingerprints</code> field in the federation API. This is ignored by Synapse 0.99.0
  1336. and later, and the only time pre-0.99 Synapses will check it is when attempting to
  1337. fetch the server keys - and generally this is delegated via <code>matrix.org</code>, which
  1338. is running a modern version of Synapse.</p>
  1339. <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>
  1340. <p>No. There is nothing stopping you from using different certificates,
  1341. particularly if you are using a reverse proxy.</p>
  1342. <div style="break-before: page; page-break-before: always;"></div><h1 id="upgrading-synapse"><a class="header" href="#upgrading-synapse">Upgrading Synapse</a></h1>
  1343. <p>Before upgrading check if any special steps are required to upgrade from
  1344. the version you currently have installed to the current version of
  1345. Synapse. The extra instructions that may be required are listed later in
  1346. this document.</p>
  1347. <ul>
  1348. <li>
  1349. <p>Check that your versions of Python and PostgreSQL are still
  1350. supported.</p>
  1351. <p>Synapse follows upstream lifecycles for <a href="https://endoflife.date/python">Python</a> and
  1352. <a href="https://endoflife.date/postgresql">PostgreSQL</a>, and removes support for versions
  1353. which are no longer maintained.</p>
  1354. <p>The website <a href="https://endoflife.date">https://endoflife.date</a> also offers convenient
  1355. summaries.</p>
  1356. </li>
  1357. <li>
  1358. <p>If Synapse was installed using <a href="setup/installation.html#prebuilt-packages">prebuilt
  1359. packages</a>, you will need to follow the
  1360. normal process for upgrading those packages.</p>
  1361. </li>
  1362. <li>
  1363. <p>If Synapse was installed from source, then:</p>
  1364. <ol>
  1365. <li>
  1366. <p>Activate the virtualenv before upgrading. For example, if
  1367. Synapse is installed in a virtualenv in <code>~/synapse/env</code> then
  1368. run:</p>
  1369. <pre><code class="language-bash">source ~/synapse/env/bin/activate
  1370. </code></pre>
  1371. </li>
  1372. <li>
  1373. <p>If Synapse was installed using pip then upgrade to the latest
  1374. version by running:</p>
  1375. <pre><code class="language-bash">pip install --upgrade matrix-synapse
  1376. </code></pre>
  1377. <p>If Synapse was installed using git then upgrade to the latest
  1378. version by running:</p>
  1379. <pre><code class="language-bash">git pull
  1380. pip install --upgrade .
  1381. </code></pre>
  1382. </li>
  1383. <li>
  1384. <p>Restart Synapse:</p>
  1385. <pre><code class="language-bash">./synctl restart
  1386. </code></pre>
  1387. </li>
  1388. </ol>
  1389. </li>
  1390. </ul>
  1391. <p>To check whether your update was successful, you can check the running
  1392. server version with:</p>
  1393. <pre><code class="language-bash"># you may need to replace 'localhost:8008' if synapse is not configured
  1394. # to listen on port 8008.
  1395. curl http://localhost:8008/_synapse/admin/v1/server_version
  1396. </code></pre>
  1397. <h2 id="rolling-back-to-older-versions"><a class="header" href="#rolling-back-to-older-versions">Rolling back to older versions</a></h2>
  1398. <p>Rolling back to previous releases can be difficult, due to database
  1399. schema changes between releases. Where we have been able to test the
  1400. rollback process, this will be noted below.</p>
  1401. <p>In general, you will need to undo any changes made during the upgrade
  1402. process, for example:</p>
  1403. <ul>
  1404. <li>
  1405. <p>pip:</p>
  1406. <pre><code class="language-bash">source env/bin/activate
  1407. # replace `1.3.0` accordingly:
  1408. pip install matrix-synapse==1.3.0
  1409. </code></pre>
  1410. </li>
  1411. <li>
  1412. <p>Debian:</p>
  1413. <pre><code class="language-bash"># replace `1.3.0` and `stretch` accordingly:
  1414. wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1415. dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
  1416. </code></pre>
  1417. </li>
  1418. </ul>
  1419. <h1 id="upgrading-to-v1420"><a class="header" href="#upgrading-to-v1420">Upgrading to v1.42.0</a></h1>
  1420. <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>
  1421. <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>
  1422. (released on 2021-01-13) and have now been removed:</p>
  1423. <ul>
  1424. <li><code>POST /_synapse/admin/v1/purge_room</code></li>
  1425. <li><code>POST /_synapse/admin/v1/shutdown_room/&lt;room_id&gt;</code></li>
  1426. </ul>
  1427. <p>Any scripts still using the above APIs should be converted to use the
  1428. <a href="https://matrix-org.github.io/synapse/latest/admin_api/rooms.html#delete-room-api">Delete Room API</a>.</p>
  1429. <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>
  1430. <p>This may affect you if you make use of custom HTML templates for the
  1431. <a href="../synapse/res/templates/recaptcha.html">reCAPTCHA</a> or
  1432. <a href="../synapse/res/templates/terms.html">terms</a> fallback pages.</p>
  1433. <p>The template is now provided an <code>error</code> variable if the authentication
  1434. process failed. See the default templates linked above for an example.</p>
  1435. <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>
  1436. <p>Users will stop receiving message updates via email for addresses that were
  1437. once, but not still, linked to their account.</p>
  1438. <h1 id="upgrading-to-v1410"><a class="header" href="#upgrading-to-v1410">Upgrading to v1.41.0</a></h1>
  1439. <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>
  1440. <p>Since Synapse 1.6.0 (2019-11-26) you can set a proxy for outbound HTTP requests via
  1441. http_proxy/https_proxy environment variables. This proxy was set for:</p>
  1442. <ul>
  1443. <li>push</li>
  1444. <li>url previews</li>
  1445. <li>phone-home stats</li>
  1446. <li>recaptcha validation</li>
  1447. <li>CAS auth validation</li>
  1448. <li>OpenID Connect</li>
  1449. <li>Federation (checking public key revocation)</li>
  1450. </ul>
  1451. <p>In this version we have added support for outbound requests for:</p>
  1452. <ul>
  1453. <li>Outbound federation</li>
  1454. <li>Downloading remote media</li>
  1455. <li>Fetching public keys of other servers</li>
  1456. </ul>
  1457. <p>These requests use the same proxy configuration. If you have a proxy configuration we
  1458. recommend to verify the configuration. It may be necessary to adjust the <code>no_proxy</code>
  1459. environment variable.</p>
  1460. <p>See <a href="setup/forward_proxy.html">using a forward proxy with Synapse documentation</a> for
  1461. details.</p>
  1462. <h2 id="deprecation-of-template_dir"><a class="header" href="#deprecation-of-template_dir">Deprecation of <code>template_dir</code></a></h2>
  1463. <p>The <code>template_dir</code> settings in the <code>sso</code>, <code>account_validity</code> and <code>email</code> sections of the
  1464. configuration file are now deprecated. Server admins should use the new
  1465. <code>templates.custom_template_directory</code> setting in the configuration file and use one single
  1466. custom template directory for all aforementioned features. Template file names remain
  1467. unchanged. See <a href="https://matrix-org.github.io/synapse/latest/templates.html">the related documentation</a>
  1468. for more information and examples.</p>
  1469. <p>We plan to remove support for these settings in October 2021.</p>
  1470. <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>
  1471. <p>The <a href="https://matrix-org.github.io/synapse/latest/workers.html#synapseappmedia_repository">media repository worker documentation</a>
  1472. has been updated to reflect that calls to <code>/_synapse/admin/v1/users/{userId}/media</code>
  1473. must now be handled by media repository workers. This is due to the new <code>DELETE</code> method
  1474. of this endpoint modifying the media store.</p>
  1475. <h1 id="upgrading-to-v1390"><a class="header" href="#upgrading-to-v1390">Upgrading to v1.39.0</a></h1>
  1476. <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>
  1477. <p>The current third-party rules module interface is deprecated in favour of the new generic
  1478. modules system introduced in Synapse v1.37.0. Authors of third-party rules modules can refer
  1479. to <a href="modules.html#porting-an-existing-module-that-uses-the-old-interface">this documentation</a>
  1480. to update their modules. Synapse administrators can refer to <a href="modules.html#using-modules">this documentation</a>
  1481. to update their configuration once the modules they are using have been updated.</p>
  1482. <p>We plan to remove support for the current third-party rules interface in September 2021.</p>
  1483. <h1 id="upgrading-to-v1380"><a class="header" href="#upgrading-to-v1380">Upgrading to v1.38.0</a></h1>
  1484. <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>
  1485. <p>This release includes a database schema update which requires re-indexing one of
  1486. the larger tables in the database, <code>events</code>. This could result in increased
  1487. disk I/O for several hours or days after upgrading while the migration
  1488. completes. Furthermore, because we have to keep the old indexes until the new
  1489. indexes are ready, it could result in a significant, temporary, increase in
  1490. disk space.</p>
  1491. <p>To get a rough idea of the disk space required, check the current size of one
  1492. of the indexes. For example, from a <code>psql</code> shell, run the following sql:</p>
  1493. <pre><code class="language-sql">SELECT pg_size_pretty(pg_relation_size('events_order_room'));
  1494. </code></pre>
  1495. <p>We need to rebuild <strong>four</strong> indexes, so you will need to multiply this result
  1496. by four to give an estimate of the disk space required. For example, on one
  1497. particular server:</p>
  1498. <pre><code>synapse=# select pg_size_pretty(pg_relation_size('events_order_room'));
  1499. pg_size_pretty
  1500. ----------------
  1501. 288 MB
  1502. (1 row)
  1503. </code></pre>
  1504. <p>On this server, it would be wise to ensure that at least 1152MB are free.</p>
  1505. <p>The additional disk space will be freed once the migration completes.</p>
  1506. <p>SQLite databases are unaffected by this change.</p>
  1507. <h1 id="upgrading-to-v1370"><a class="header" href="#upgrading-to-v1370">Upgrading to v1.37.0</a></h1>
  1508. <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>
  1509. <p>The current spam checker interface is deprecated in favour of a new generic modules system.
  1510. Authors of spam checker modules can refer to <a href="modules.html#porting-an-existing-module-that-uses-the-old-interface">this
  1511. documentation</a>
  1512. to update their modules. Synapse administrators can refer to <a href="modules.html#using-modules">this
  1513. documentation</a>
  1514. to update their configuration once the modules they are using have been updated.</p>
  1515. <p>We plan to remove support for the current spam checker interface in August 2021.</p>
  1516. <p>More module interfaces will be ported over to this new generic system in future versions
  1517. of Synapse.</p>
  1518. <h1 id="upgrading-to-v1340"><a class="header" href="#upgrading-to-v1340">Upgrading to v1.34.0</a></h1>
  1519. <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>
  1520. <p>The <code>room_invite_state_types</code> configuration setting has been deprecated
  1521. 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
  1522. file</a>.</p>
  1523. <p>If you have set <code>room_invite_state_types</code> to the default value you
  1524. should simply remove it from your configuration file. The default value
  1525. used to be:</p>
  1526. <pre><code class="language-yaml">room_invite_state_types:
  1527. - &quot;m.room.join_rules&quot;
  1528. - &quot;m.room.canonical_alias&quot;
  1529. - &quot;m.room.avatar&quot;
  1530. - &quot;m.room.encryption&quot;
  1531. - &quot;m.room.name&quot;
  1532. </code></pre>
  1533. <p>If you have customised this value, you should remove
  1534. <code>room_invite_state_types</code> and configure <code>room_prejoin_state</code> instead.</p>
  1535. <h1 id="upgrading-to-v1330"><a class="header" href="#upgrading-to-v1330">Upgrading to v1.33.0</a></h1>
  1536. <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>
  1537. <p>This may affect you if you have enabled the account validity feature,
  1538. and have made use of a custom HTML template specified by the
  1539. <code>account_validity.template_dir</code> or
  1540. <code>account_validity.account_renewed_html_path</code> Synapse config options.</p>
  1541. <p>The template can now accept an <code>expiration_ts</code> variable, which
  1542. represents the unix timestamp in milliseconds for the future date of
  1543. 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
  1544. template</a>
  1545. for an example of usage.</p>
  1546. <p>ALso note that a new HTML template, <code>account_previously_renewed.html</code>,
  1547. has been added. This is is shown to users when they attempt to renew
  1548. their account with a valid renewal token that has already been used
  1549. before. The default template contents can been found
  1550. <a href="https://github.com/matrix-org/synapse/blob/release-v1.33.0/synapse/res/templates/account_previously_renewed.html">here</a>,
  1551. and can also accept an <code>expiration_ts</code> variable. This template replaces
  1552. the error message users would previously see upon attempting to use a
  1553. valid renewal token more than once.</p>
  1554. <h1 id="upgrading-to-v1320"><a class="header" href="#upgrading-to-v1320">Upgrading to v1.32.0</a></h1>
  1555. <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>
  1556. <p>This release introduces <a href="https://github.com/matrix-org/synapse/issues/9853">a
  1557. regression</a> that can
  1558. overwhelm connected Prometheus instances. This issue is not present in
  1559. Synapse v1.32.0rc1.</p>
  1560. <p>If you have been affected, please downgrade to 1.31.0. You then may need
  1561. to remove excess writeahead logs in order for Prometheus to recover.
  1562. Instructions for doing so are provided
  1563. <a href="https://github.com/matrix-org/synapse/pull/9854#issuecomment-823472183">here</a>.</p>
  1564. <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>
  1565. <p>In line with our <a href="deprecation_policy.html">deprecation policy</a>,
  1566. we've dropped support for Python 3.5 and PostgreSQL 9.5, as they are no
  1567. longer supported upstream.</p>
  1568. <p>This release of Synapse requires Python 3.6+ and PostgresSQL 9.6+ or
  1569. SQLite 3.22+.</p>
  1570. <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>
  1571. <p>The deprecated v1 &quot;list accounts&quot; admin API
  1572. (<code>GET /_synapse/admin/v1/users/&lt;user_id&gt;</code>) has been removed in this
  1573. version.</p>
  1574. <p>The <a href="admin_api/user_admin_api.html#list-accounts">v2 list accounts API</a>
  1575. has been available since Synapse 1.7.0 (2019-12-13), and is accessible
  1576. under <code>GET /_synapse/admin/v2/users</code>.</p>
  1577. <p>The deprecation of the old endpoint was announced with Synapse 1.28.0
  1578. (released on 2021-02-25).</p>
  1579. <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>
  1580. <p>In compliance with the <a href="https://matrix.org/docs/spec/application_service/r0.1.2#server-admin-style-permissions">Application Service
  1581. spec</a>,
  1582. Application Services are now required to use the
  1583. <code>m.login.application_service</code> type when registering users via the
  1584. <code>/_matrix/client/r0/register</code> endpoint. This behaviour was deprecated in
  1585. Synapse v1.30.0.</p>
  1586. <p>Please ensure your Application Services are up to date.</p>
  1587. <h1 id="upgrading-to-v1290"><a class="header" href="#upgrading-to-v1290">Upgrading to v1.29.0</a></h1>
  1588. <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>
  1589. <p>When using Synapse with a reverse proxy (in particular, when using the
  1590. [x_forwarded]{.title-ref} option on an HTTP listener), Synapse now
  1591. expects to receive an [X-Forwarded-Proto]{.title-ref} header on incoming
  1592. HTTP requests. If it is not set, Synapse will log a warning on each
  1593. received request.</p>
  1594. <p>To avoid the warning, administrators using a reverse proxy should ensure
  1595. that the reverse proxy sets [X-Forwarded-Proto]{.title-ref} header to
  1596. [https]{.title-ref} or [http]{.title-ref} to indicate the protocol used
  1597. by the client.</p>
  1598. <p>Synapse also requires the [Host]{.title-ref} header to be preserved.</p>
  1599. <p>See the <a href="reverse_proxy.html">reverse proxy documentation</a>, where the
  1600. example configurations have been updated to show how to set these
  1601. headers.</p>
  1602. <p>(Users of <a href="https://caddyserver.com/">Caddy</a> are unaffected, since we
  1603. believe it sets [X-Forwarded-Proto]{.title-ref} by default.)</p>
  1604. <h1 id="upgrading-to-v1270"><a class="header" href="#upgrading-to-v1270">Upgrading to v1.27.0</a></h1>
  1605. <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>
  1606. <p>This version changes the URI used for callbacks from OAuth2 and SAML2
  1607. identity providers:</p>
  1608. <ul>
  1609. <li>
  1610. <p>If your server is configured for single sign-on via an OpenID
  1611. Connect or OAuth2 identity provider, you will need to add
  1612. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> to the list
  1613. of permitted &quot;redirect URIs&quot; at the identity provider.</p>
  1614. <p>See the <a href="openid.html">OpenID docs</a> for more information on setting
  1615. up OpenID Connect.</p>
  1616. </li>
  1617. <li>
  1618. <p>If your server is configured for single sign-on via a SAML2 identity
  1619. provider, you will need to add
  1620. <code>[synapse public baseurl]/_synapse/client/saml2/authn_response</code> as a
  1621. permitted &quot;ACS location&quot; (also known as &quot;allowed callback URLs&quot;)
  1622. at the identity provider.</p>
  1623. <p>The &quot;Issuer&quot; in the &quot;AuthnRequest&quot; to the SAML2 identity
  1624. provider is also updated to
  1625. <code>[synapse public baseurl]/_synapse/client/saml2/metadata.xml</code>. If
  1626. your SAML2 identity provider uses this property to validate or
  1627. otherwise identify Synapse, its configuration will need to be
  1628. updated to use the new URL. Alternatively you could create a new,
  1629. separate &quot;EntityDescriptor&quot; in your SAML2 identity provider with
  1630. the new URLs and leave the URLs in the existing &quot;EntityDescriptor&quot;
  1631. as they were.</p>
  1632. </li>
  1633. </ul>
  1634. <h2 id="changes-to-html-templates"><a class="header" href="#changes-to-html-templates">Changes to HTML templates</a></h2>
  1635. <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
  1636. autoescape</a>
  1637. enabled for files ending in <code>.html</code>, <code>.htm</code>, and <code>.xml</code>. If you have
  1638. customised these templates and see issues when viewing them you might
  1639. need to update them. It is expected that most configurations will need
  1640. no changes.</p>
  1641. <p>If you have customised the templates <em>names</em> for these templates, it is
  1642. recommended to verify they end in <code>.html</code> to ensure autoescape is
  1643. enabled.</p>
  1644. <p>The above applies to the following templates:</p>
  1645. <ul>
  1646. <li><code>add_threepid.html</code></li>
  1647. <li><code>add_threepid_failure.html</code></li>
  1648. <li><code>add_threepid_success.html</code></li>
  1649. <li><code>notice_expiry.html</code></li>
  1650. <li><code>notice_expiry.html</code></li>
  1651. <li><code>notif_mail.html</code> (which, by default, includes <code>room.html</code> and
  1652. <code>notif.html</code>)</li>
  1653. <li><code>password_reset.html</code></li>
  1654. <li><code>password_reset_confirmation.html</code></li>
  1655. <li><code>password_reset_failure.html</code></li>
  1656. <li><code>password_reset_success.html</code></li>
  1657. <li><code>registration.html</code></li>
  1658. <li><code>registration_failure.html</code></li>
  1659. <li><code>registration_success.html</code></li>
  1660. <li><code>sso_account_deactivated.html</code></li>
  1661. <li><code>sso_auth_bad_user.html</code></li>
  1662. <li><code>sso_auth_confirm.html</code></li>
  1663. <li><code>sso_auth_success.html</code></li>
  1664. <li><code>sso_error.html</code></li>
  1665. <li><code>sso_login_idp_picker.html</code></li>
  1666. <li><code>sso_redirect_confirm.html</code></li>
  1667. </ul>
  1668. <h1 id="upgrading-to-v1260"><a class="header" href="#upgrading-to-v1260">Upgrading to v1.26.0</a></h1>
  1669. <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>
  1670. <p>v1.26.0 includes a lot of large changes. If something problematic
  1671. occurs, you may want to roll-back to a previous version of Synapse.
  1672. Because v1.26.0 also includes a new database schema version, reverting
  1673. that version is also required alongside the generic rollback
  1674. instructions mentioned above. In short, to roll back to v1.25.0 you need
  1675. to:</p>
  1676. <ol>
  1677. <li>
  1678. <p>Stop the server</p>
  1679. </li>
  1680. <li>
  1681. <p>Decrease the schema version in the database:</p>
  1682. <pre><code class="language-sql">UPDATE schema_version SET version = 58;
  1683. </code></pre>
  1684. </li>
  1685. <li>
  1686. <p>Delete the ignored users &amp; chain cover data:</p>
  1687. <pre><code class="language-sql">DROP TABLE IF EXISTS ignored_users;
  1688. UPDATE rooms SET has_auth_chain_index = false;
  1689. </code></pre>
  1690. <p>For PostgreSQL run:</p>
  1691. <pre><code class="language-sql">TRUNCATE event_auth_chain_links;
  1692. TRUNCATE event_auth_chains;
  1693. </code></pre>
  1694. <p>For SQLite run:</p>
  1695. <pre><code class="language-sql">DELETE FROM event_auth_chain_links;
  1696. DELETE FROM event_auth_chains;
  1697. </code></pre>
  1698. </li>
  1699. <li>
  1700. <p>Mark the deltas as not run (so they will re-run on upgrade).</p>
  1701. <pre><code class="language-sql">DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/01ignored_user.py&quot;;
  1702. DELETE FROM applied_schema_deltas WHERE version = 59 AND file = &quot;59/06chain_cover_index.sql&quot;;
  1703. </code></pre>
  1704. </li>
  1705. <li>
  1706. <p>Downgrade Synapse by following the instructions for your
  1707. installation method in the &quot;Rolling back to older versions&quot;
  1708. section above.</p>
  1709. </li>
  1710. </ol>
  1711. <h1 id="upgrading-to-v1250"><a class="header" href="#upgrading-to-v1250">Upgrading to v1.25.0</a></h1>
  1712. <h2 id="last-release-supporting-python-35"><a class="header" href="#last-release-supporting-python-35">Last release supporting Python 3.5</a></h2>
  1713. <p>This is the last release of Synapse which guarantees support with Python
  1714. 3.5, which passed its upstream End of Life date several months ago.</p>
  1715. <p>We will attempt to maintain support through March 2021, but without
  1716. guarantees.</p>
  1717. <p>In the future, Synapse will follow upstream schedules for ending support
  1718. of older versions of Python and PostgreSQL. Please upgrade to at least
  1719. Python 3.6 and PostgreSQL 9.6 as soon as possible.</p>
  1720. <h2 id="blacklisting-ip-ranges"><a class="header" href="#blacklisting-ip-ranges">Blacklisting IP ranges</a></h2>
  1721. <p>Synapse v1.25.0 includes new settings, <code>ip_range_blacklist</code> and
  1722. <code>ip_range_whitelist</code>, for controlling outgoing requests from Synapse for
  1723. federation, identity servers, push, and for checking key validity for
  1724. third-party invite events. The previous setting,
  1725. <code>federation_ip_range_blacklist</code>, is deprecated. The new
  1726. <code>ip_range_blacklist</code> defaults to private IP ranges if it is not defined.</p>
  1727. <p>If you have never customised <code>federation_ip_range_blacklist</code> it is
  1728. recommended that you remove that setting.</p>
  1729. <p>If you have customised <code>federation_ip_range_blacklist</code> you should update
  1730. the setting name to <code>ip_range_blacklist</code>.</p>
  1731. <p>If you have a custom push server that is reached via private IP space
  1732. you may need to customise <code>ip_range_blacklist</code> or <code>ip_range_whitelist</code>.</p>
  1733. <h1 id="upgrading-to-v1240"><a class="header" href="#upgrading-to-v1240">Upgrading to v1.24.0</a></h1>
  1734. <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>
  1735. <p>This release allows the OpenID Connect mapping provider to perform
  1736. normalisation of the localpart of the Matrix ID. This allows for the
  1737. mapping provider to specify different algorithms, instead of the
  1738. <a href="https://matrix.org/docs/spec/appendices#mapping-from-other-character-sets">default
  1739. way</a>.</p>
  1740. <p>If your Synapse configuration uses a custom mapping provider
  1741. ([oidc_config.user_mapping_provider.module]{.title-ref} is specified and
  1742. not equal to
  1743. [synapse.handlers.oidc_handler.JinjaOidcMappingProvider]{.title-ref})
  1744. then you <em>must</em> ensure that [map_user_attributes]{.title-ref} of the
  1745. mapping provider performs some normalisation of the
  1746. [localpart]{.title-ref} returned. To match previous behaviour you can
  1747. use the [map_username_to_mxid_localpart]{.title-ref} function provided
  1748. by Synapse. An example is shown below:</p>
  1749. <pre><code class="language-python">from synapse.types import map_username_to_mxid_localpart
  1750. class MyMappingProvider:
  1751. def map_user_attributes(self, userinfo, token):
  1752. # ... your custom logic ...
  1753. sso_user_id = ...
  1754. localpart = map_username_to_mxid_localpart(sso_user_id)
  1755. return {&quot;localpart&quot;: localpart}
  1756. </code></pre>
  1757. <h2 id="removal-historical-synapse-admin-api"><a class="header" href="#removal-historical-synapse-admin-api">Removal historical Synapse Admin API</a></h2>
  1758. <p>Historically, the Synapse Admin API has been accessible under:</p>
  1759. <ul>
  1760. <li><code>/_matrix/client/api/v1/admin</code></li>
  1761. <li><code>/_matrix/client/unstable/admin</code></li>
  1762. <li><code>/_matrix/client/r0/admin</code></li>
  1763. <li><code>/_synapse/admin/v1</code></li>
  1764. </ul>
  1765. <p>The endpoints with <code>/_matrix/client/*</code> prefixes have been removed as of
  1766. v1.24.0. The Admin API is now only accessible under:</p>
  1767. <ul>
  1768. <li><code>/_synapse/admin/v1</code></li>
  1769. </ul>
  1770. <p>The only exception is the [/admin/whois]{.title-ref} endpoint, which is
  1771. <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
  1772. API</a>.</p>
  1773. <p>The deprecation of the old endpoints was announced with Synapse 1.20.0
  1774. (released on 2020-09-22) and makes it easier for homeserver admins to
  1775. lock down external access to the Admin API endpoints.</p>
  1776. <h1 id="upgrading-to-v1230"><a class="header" href="#upgrading-to-v1230">Upgrading to v1.23.0</a></h1>
  1777. <h2 id="structured-logging-configuration-breaking-changes"><a class="header" href="#structured-logging-configuration-breaking-changes">Structured logging configuration breaking changes</a></h2>
  1778. <p>This release deprecates use of the <code>structured: true</code> logging
  1779. configuration for structured logging. If your logging configuration
  1780. contains <code>structured: true</code> then it should be modified based on the
  1781. <a href="structured_logging.html">structured logging documentation</a>.</p>
  1782. <p>The <code>structured</code> and <code>drains</code> logging options are now deprecated and
  1783. should be replaced by standard logging configuration of <code>handlers</code> and
  1784. <code>formatters</code>.</p>
  1785. <p>A future will release of Synapse will make using <code>structured: true</code> an
  1786. error.</p>
  1787. <h1 id="upgrading-to-v1220"><a class="header" href="#upgrading-to-v1220">Upgrading to v1.22.0</a></h1>
  1788. <h2 id="thirdpartyeventrules-breaking-changes"><a class="header" href="#thirdpartyeventrules-breaking-changes">ThirdPartyEventRules breaking changes</a></h2>
  1789. <p>This release introduces a backwards-incompatible change to modules
  1790. making use of <code>ThirdPartyEventRules</code> in Synapse. If you make use of a
  1791. module defined under the <code>third_party_event_rules</code> config option, please
  1792. make sure it is updated to handle the below change:</p>
  1793. <p>The <code>http_client</code> argument is no longer passed to modules as they are
  1794. initialised. Instead, modules are expected to make use of the
  1795. <code>http_client</code> property on the <code>ModuleApi</code> class. Modules are now passed
  1796. a <code>module_api</code> argument during initialisation, which is an instance of
  1797. <code>ModuleApi</code>. <code>ModuleApi</code> instances have a <code>http_client</code> property which
  1798. acts the same as the <code>http_client</code> argument previously passed to
  1799. <code>ThirdPartyEventRules</code> modules.</p>
  1800. <h1 id="upgrading-to-v1210"><a class="header" href="#upgrading-to-v1210">Upgrading to v1.21.0</a></h1>
  1801. <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>
  1802. <p>The <a href="reverse_proxy.html">reverse proxy documentation</a>
  1803. has been updated to include reverse proxy directives for
  1804. <code>/_synapse/client/*</code> endpoints. As the user password reset flow now uses
  1805. endpoints under this prefix, <strong>you must update your reverse proxy
  1806. configurations for user password reset to work</strong>.</p>
  1807. <p>Additionally, note that the <a href="workers.html">Synapse worker documentation</a> has been updated to</p>
  1808. <p>: state that the <code>/_synapse/client/password_reset/email/submit_token</code>
  1809. endpoint can be handled</p>
  1810. <p>by all workers. If you make use of Synapse's worker feature, please
  1811. update your reverse proxy configuration to reflect this change.</p>
  1812. <h2 id="new-html-templates"><a class="header" href="#new-html-templates">New HTML templates</a></h2>
  1813. <p>A new HTML template,
  1814. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/res/templates/password_reset_confirmation.html">password_reset_confirmation.html</a>,
  1815. has been added to the <code>synapse/res/templates</code> directory. If you are
  1816. using a custom template directory, you may want to copy the template
  1817. over and modify it.</p>
  1818. <p>Note that as of v1.20.0, templates do not need to be included in custom
  1819. template directories for Synapse to start. The default templates will be
  1820. used if a custom template cannot be found.</p>
  1821. <p>This page will appear to the user after clicking a password reset link
  1822. that has been emailed to them.</p>
  1823. <p>To complete password reset, the page must include a way to make a
  1824. [POST]{.title-ref} request to
  1825. <code>/_synapse/client/password_reset/{medium}/submit_token</code> with the query
  1826. parameters from the original link, presented as a URL-encoded form. See
  1827. the file itself for more details.</p>
  1828. <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>
  1829. <p>The <code>saml_error.html</code> template was removed from Synapse and replaced
  1830. with the <code>sso_error.html</code> template. If your Synapse is configured to use
  1831. SAML and a custom <code>sso_redirect_confirm_template_dir</code> configuration then
  1832. any customisations of the <code>saml_error.html</code> template will need to be
  1833. merged into the <code>sso_error.html</code> template. These templates are similar,
  1834. but the parameters are slightly different:</p>
  1835. <ul>
  1836. <li>The <code>msg</code> parameter should be renamed to <code>error_description</code>.</li>
  1837. <li>There is no longer a <code>code</code> parameter for the response code.</li>
  1838. <li>A string <code>error</code> parameter is available that includes a short hint
  1839. of why a user is seeing the error page.</li>
  1840. </ul>
  1841. <h1 id="upgrading-to-v1180"><a class="header" href="#upgrading-to-v1180">Upgrading to v1.18.0</a></h1>
  1842. <h2 id="docker--py3title-ref-suffix-will-be-removed-in-future-versions"><a class="header" href="#docker--py3title-ref-suffix-will-be-removed-in-future-versions">Docker [-py3]{.title-ref} suffix will be removed in future versions</a></h2>
  1843. <p>From 10th August 2020, we will no longer publish Docker images with the
  1844. [-py3]{.title-ref} tag suffix. The images tagged with the
  1845. [-py3]{.title-ref} suffix have been identical to the non-suffixed tags
  1846. since release 0.99.0, and the suffix is obsolete.</p>
  1847. <p>On 10th August, we will remove the [latest-py3]{.title-ref} tag.
  1848. Existing per-release tags (such as [v1.18.0-py3]{.title-ref}) will not
  1849. be removed, but no new [-py3]{.title-ref} tags will be added.</p>
  1850. <p>Scripts relying on the [-py3]{.title-ref} suffix will need to be
  1851. updated.</p>
  1852. <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>
  1853. <p>When setting up worker processes, we now recommend the use of a Redis
  1854. server for replication. <strong>The old direct TCP connection method is
  1855. deprecated and will be removed in a future release.</strong> See
  1856. <a href="workers.html">workers</a> for more details.</p>
  1857. <h1 id="upgrading-to-v1140"><a class="header" href="#upgrading-to-v1140">Upgrading to v1.14.0</a></h1>
  1858. <p>This version includes a database update which is run as part of the
  1859. upgrade, and which may take a couple of minutes in the case of a large
  1860. server. Synapse will not respond to HTTP requests while this update is
  1861. taking place.</p>
  1862. <h1 id="upgrading-to-v1130"><a class="header" href="#upgrading-to-v1130">Upgrading to v1.13.0</a></h1>
  1863. <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>
  1864. <p>A bug was introduced in Synapse 1.4.0 which could cause the room
  1865. directory to be incomplete or empty if Synapse was upgraded directly
  1866. from v1.2.1 or earlier, to versions between v1.4.0 and v1.12.x.</p>
  1867. <p>This will <em>not</em> be a problem for Synapse installations which were:</p>
  1868. <p>: - created at v1.4.0 or later,
  1869. - upgraded via v1.3.x, or
  1870. - upgraded straight from v1.2.1 or earlier to v1.13.0 or later.</p>
  1871. <p>If completeness of the room directory is a concern, installations which
  1872. are affected can be repaired as follows:</p>
  1873. <ol>
  1874. <li>
  1875. <p>Run the following sql from a [psql]{.title-ref} or
  1876. [sqlite3]{.title-ref} console:</p>
  1877. <pre><code class="language-sql">INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1878. ('populate_stats_process_rooms', '{}', 'current_state_events_membership');
  1879. INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
  1880. ('populate_stats_process_users', '{}', 'populate_stats_process_rooms');
  1881. </code></pre>
  1882. </li>
  1883. <li>
  1884. <p>Restart synapse.</p>
  1885. </li>
  1886. </ol>
  1887. <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>
  1888. <p>New templates (<code>sso_auth_confirm.html</code>, <code>sso_auth_success.html</code>, and
  1889. <code>sso_account_deactivated.html</code>) were added to Synapse. If your Synapse
  1890. is configured to use SSO and a custom
  1891. <code>sso_redirect_confirm_template_dir</code> configuration then these templates
  1892. will need to be copied from
  1893. <a href="synapse/res/templates">synapse/res/templates</a> into that directory.</p>
  1894. <h2 id="synapse-sso-plugins-method-deprecation"><a class="header" href="#synapse-sso-plugins-method-deprecation">Synapse SSO Plugins Method Deprecation</a></h2>
  1895. <p>Plugins using the <code>complete_sso_login</code> method of
  1896. <code>synapse.module_api.ModuleApi</code> should update to using the async/await
  1897. version <code>complete_sso_login_async</code> which includes additional checks. The
  1898. non-async version is considered deprecated.</p>
  1899. <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>
  1900. <p>v1.13.0 includes a lot of large changes. If something problematic
  1901. occurs, you may want to roll-back to a previous version of Synapse.
  1902. Because v1.13.0 also includes a new database schema version, reverting
  1903. that version is also required alongside the generic rollback
  1904. instructions mentioned above. In short, to roll back to v1.12.4 you need
  1905. to:</p>
  1906. <ol>
  1907. <li>
  1908. <p>Stop the server</p>
  1909. </li>
  1910. <li>
  1911. <p>Decrease the schema version in the database:</p>
  1912. <pre><code class="language-sql">UPDATE schema_version SET version = 57;
  1913. </code></pre>
  1914. </li>
  1915. <li>
  1916. <p>Downgrade Synapse by following the instructions for your
  1917. installation method in the &quot;Rolling back to older versions&quot;
  1918. section above.</p>
  1919. </li>
  1920. </ol>
  1921. <h1 id="upgrading-to-v1120"><a class="header" href="#upgrading-to-v1120">Upgrading to v1.12.0</a></h1>
  1922. <p>This version includes a database update which is run as part of the
  1923. upgrade, and which may take some time (several hours in the case of a
  1924. large server). Synapse will not respond to HTTP requests while this
  1925. update is taking place.</p>
  1926. <p>This is only likely to be a problem in the case of a server which is
  1927. participating in many rooms.</p>
  1928. <ol start="0">
  1929. <li>
  1930. <p>As with all upgrades, it is recommended that you have a recent
  1931. backup of your database which can be used for recovery in the event
  1932. of any problems.</p>
  1933. </li>
  1934. <li>
  1935. <p>As an initial check to see if you will be affected, you can try
  1936. running the following query from the [psql]{.title-ref} or
  1937. [sqlite3]{.title-ref} console. It is safe to run it while Synapse is
  1938. still running.</p>
  1939. <pre><code class="language-sql">SELECT MAX(q.v) FROM (
  1940. SELECT (
  1941. SELECT ej.json AS v
  1942. FROM state_events se INNER JOIN event_json ej USING (event_id)
  1943. WHERE se.room_id=rooms.room_id AND se.type='m.room.create' AND se.state_key=''
  1944. LIMIT 1
  1945. ) FROM rooms WHERE rooms.room_version IS NULL
  1946. ) q;
  1947. </code></pre>
  1948. <p>This query will take about the same amount of time as the upgrade
  1949. process: ie, if it takes 5 minutes, then it is likely that Synapse
  1950. will be unresponsive for 5 minutes during the upgrade.</p>
  1951. <p>If you consider an outage of this duration to be acceptable, no
  1952. further action is necessary and you can simply start Synapse 1.12.0.</p>
  1953. <p>If you would prefer to reduce the downtime, continue with the steps
  1954. below.</p>
  1955. </li>
  1956. <li>
  1957. <p>The easiest workaround for this issue is to manually create a new
  1958. index before upgrading. On PostgreSQL, his can be done as follows:</p>
  1959. <pre><code class="language-sql">CREATE INDEX CONCURRENTLY tmp_upgrade_1_12_0_index
  1960. ON state_events(room_id) WHERE type = 'm.room.create';
  1961. </code></pre>
  1962. <p>The above query may take some time, but is also safe to run while
  1963. Synapse is running.</p>
  1964. <p>We assume that no SQLite users have databases large enough to be
  1965. affected. If you <em>are</em> affected, you can run a similar query,
  1966. omitting the <code>CONCURRENTLY</code> keyword. Note however that this
  1967. operation may in itself cause Synapse to stop running for some time.
  1968. Synapse admins are reminded that <a href="postgres.html">SQLite is not recommended for use
  1969. outside a test environment</a>.</p>
  1970. </li>
  1971. <li>
  1972. <p>Once the index has been created, the <code>SELECT</code> query in step 1 above
  1973. should complete quickly. It is therefore safe to upgrade to Synapse
  1974. 1.12.0.</p>
  1975. </li>
  1976. <li>
  1977. <p>Once Synapse 1.12.0 has successfully started and is responding to
  1978. HTTP requests, the temporary index can be removed:</p>
  1979. <pre><code class="language-sql">DROP INDEX tmp_upgrade_1_12_0_index;
  1980. </code></pre>
  1981. </li>
  1982. </ol>
  1983. <h1 id="upgrading-to-v1100"><a class="header" href="#upgrading-to-v1100">Upgrading to v1.10.0</a></h1>
  1984. <p>Synapse will now log a warning on start up if used with a PostgreSQL
  1985. database that has a non-recommended locale set.</p>
  1986. <p>See <a href="postgres.html">Postgres</a> for details.</p>
  1987. <h1 id="upgrading-to-v180"><a class="header" href="#upgrading-to-v180">Upgrading to v1.8.0</a></h1>
  1988. <p>Specifying a <code>log_file</code> config option will now cause Synapse to refuse
  1989. to start, and should be replaced by with the <code>log_config</code> option.
  1990. Support for the <code>log_file</code> option was removed in v1.3.0 and has since
  1991. had no effect.</p>
  1992. <h1 id="upgrading-to-v170"><a class="header" href="#upgrading-to-v170">Upgrading to v1.7.0</a></h1>
  1993. <p>In an attempt to configure Synapse in a privacy preserving way, the
  1994. default behaviours of <code>allow_public_rooms_without_auth</code> and
  1995. <code>allow_public_rooms_over_federation</code> have been inverted. This means that
  1996. by default, only authenticated users querying the Client/Server API will
  1997. be able to query the room directory, and relatedly that the server will
  1998. not share room directory information with other servers over federation.</p>
  1999. <p>If your installation does not explicitly set these settings one way or
  2000. the other and you want either setting to be <code>true</code> then it will
  2001. necessary to update your homeserver configuration file accordingly.</p>
  2002. <p>For more details on the surrounding context see our
  2003. <a href="https://matrix.org/blog/2019/11/09/avoiding-unwelcome-visitors-on-private-matrix-servers">explainer</a>.</p>
  2004. <h1 id="upgrading-to-v150"><a class="header" href="#upgrading-to-v150">Upgrading to v1.5.0</a></h1>
  2005. <p>This release includes a database migration which may take several
  2006. minutes to complete if there are a large number (more than a million or
  2007. so) of entries in the <code>devices</code> table. This is only likely to a be a
  2008. problem on very large installations.</p>
  2009. <h1 id="upgrading-to-v140"><a class="header" href="#upgrading-to-v140">Upgrading to v1.4.0</a></h1>
  2010. <h2 id="new-custom-templates"><a class="header" href="#new-custom-templates">New custom templates</a></h2>
  2011. <p>If you have configured a custom template directory with the
  2012. <code>email.template_dir</code> option, be aware that there are new templates
  2013. regarding registration and threepid management (see below) that must be
  2014. included.</p>
  2015. <ul>
  2016. <li><code>registration.html</code> and <code>registration.txt</code></li>
  2017. <li><code>registration_success.html</code> and <code>registration_failure.html</code></li>
  2018. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code></li>
  2019. <li><code>add_threepid_failure.html</code> and <code>add_threepid_success.html</code></li>
  2020. </ul>
  2021. <p>Synapse will expect these files to exist inside the configured template
  2022. directory, and <strong>will fail to start</strong> if they are absent. To view the
  2023. default templates, see
  2024. <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">synapse/res/templates</a>.</p>
  2025. <h2 id="3pid-verification-changes"><a class="header" href="#3pid-verification-changes">3pid verification changes</a></h2>
  2026. <p><strong>Note: As of this release, users will be unable to add phone numbers or
  2027. email addresses to their accounts, without changes to the Synapse
  2028. configuration. This includes adding an email address during
  2029. registration.</strong></p>
  2030. <p>It is possible for a user to associate an email address or phone number
  2031. with their account, for a number of reasons:</p>
  2032. <ul>
  2033. <li>for use when logging in, as an alternative to the user id.</li>
  2034. <li>in the case of email, as an alternative contact to help with account
  2035. recovery.</li>
  2036. <li>in the case of email, to receive notifications of missed messages.</li>
  2037. </ul>
  2038. <p>Before an email address or phone number can be added to a user's
  2039. account, or before such an address is used to carry out a
  2040. password-reset, Synapse must confirm the operation with the owner of the
  2041. email address or phone number. It does this by sending an email or text
  2042. giving the user a link or token to confirm receipt. This process is
  2043. known as '3pid verification'. ('3pid', or 'threepid', stands for
  2044. third-party identifier, and we use it to refer to external identifiers
  2045. such as email addresses and phone numbers.)</p>
  2046. <p>Previous versions of Synapse delegated the task of 3pid verification to
  2047. an identity server by default. In most cases this server is <code>vector.im</code>
  2048. or <code>matrix.org</code>.</p>
  2049. <p>In Synapse 1.4.0, for security and privacy reasons, the homeserver will
  2050. no longer delegate this task to an identity server by default. Instead,
  2051. the server administrator will need to explicitly decide how they would
  2052. like the verification messages to be sent.</p>
  2053. <p>In the medium term, the <code>vector.im</code> and <code>matrix.org</code> identity servers
  2054. will disable support for delegated 3pid verification entirely. However,
  2055. in order to ease the transition, they will retain the capability for a
  2056. limited period. Delegated email verification will be disabled on Monday
  2057. 2nd December 2019 (giving roughly 2 months notice). Disabling delegated
  2058. SMS verification will follow some time after that once SMS verification
  2059. support lands in Synapse.</p>
  2060. <p>Once delegated 3pid verification support has been disabled in the
  2061. <code>vector.im</code> and <code>matrix.org</code> identity servers, all Synapse versions that
  2062. depend on those instances will be unable to verify email and phone
  2063. numbers through them. There are no imminent plans to remove delegated
  2064. 3pid verification from Sydent generally. (Sydent is the identity server
  2065. project that backs the <code>vector.im</code> and <code>matrix.org</code> instances).</p>
  2066. <h3 id="email-1"><a class="header" href="#email-1">Email</a></h3>
  2067. <p>Following upgrade, to continue verifying email (e.g. as part of the
  2068. registration process), admins can either:-</p>
  2069. <ul>
  2070. <li>Configure Synapse to use an email server.</li>
  2071. <li>Run or choose an identity server which allows delegated email
  2072. verification and delegate to it.</li>
  2073. </ul>
  2074. <h4 id="configure-smtp-in-synapse"><a class="header" href="#configure-smtp-in-synapse">Configure SMTP in Synapse</a></h4>
  2075. <p>To configure an SMTP server for Synapse, modify the configuration
  2076. section headed <code>email</code>, and be sure to have at least the
  2077. <code>smtp_host, smtp_port</code> and <code>notif_from</code> fields filled out.</p>
  2078. <p>You may also need to set <code>smtp_user</code>, <code>smtp_pass</code>, and
  2079. <code>require_transport_security</code>.</p>
  2080. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2081. for more details on these settings.</p>
  2082. <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>
  2083. <p>Some admins will wish to continue using email verification as part of
  2084. the registration process, but will not immediately have an appropriate
  2085. SMTP server at hand.</p>
  2086. <p>To this end, we will continue to support email verification delegation
  2087. via the <code>vector.im</code> and <code>matrix.org</code> identity servers for two months.
  2088. Support for delegated email verification will be disabled on Monday 2nd
  2089. December.</p>
  2090. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2091. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2092. server</a>) to handle
  2093. sending confirmation messages via email and SMS.</p>
  2094. <p>So to delegate email verification, in <code>homeserver.yaml</code>, set
  2095. <code>account_threepid_delegates.email</code> to the base URL of an identity
  2096. server. For example:</p>
  2097. <pre><code class="language-yaml">account_threepid_delegates:
  2098. email: https://example.com # Delegate email sending to example.com
  2099. </code></pre>
  2100. <p>Note that <code>account_threepid_delegates.email</code> replaces the deprecated
  2101. <code>email.trust_identity_server_for_password_resets</code>: if
  2102. <code>email.trust_identity_server_for_password_resets</code> is set to <code>true</code>, and
  2103. <code>account_threepid_delegates.email</code> is not set, then the first entry in
  2104. <code>trusted_third_party_id_servers</code> will be used as the
  2105. <code>account_threepid_delegate</code> for email. This is to ensure compatibility
  2106. with existing Synapse installs that set up external server handling for
  2107. these tasks before v1.4.0. If
  2108. <code>email.trust_identity_server_for_password_resets</code> is <code>true</code> and no
  2109. trusted identity server domains are configured, Synapse will report an
  2110. error and refuse to start.</p>
  2111. <p>If <code>email.trust_identity_server_for_password_resets</code> is <code>false</code> or
  2112. absent and no <code>email</code> delegate is configured in
  2113. <code>account_threepid_delegates</code>, then Synapse will send email verification
  2114. messages itself, using the configured SMTP server (see above). that
  2115. type.</p>
  2116. <h3 id="phone-numbers"><a class="header" href="#phone-numbers">Phone numbers</a></h3>
  2117. <p>Synapse does not support phone-number verification itself, so the only
  2118. way to maintain the ability for users to add phone numbers to their
  2119. accounts will be by continuing to delegate phone number verification to
  2120. the <code>matrix.org</code> and <code>vector.im</code> identity servers (or another identity
  2121. server that supports SMS sending).</p>
  2122. <p>The <code>account_threepid_delegates</code> dictionary defines whether the
  2123. homeserver should delegate an external server (typically an <a href="https://matrix.org/docs/spec/identity_service/r0.2.1">identity
  2124. server</a>) to handle
  2125. sending confirmation messages via email and SMS.</p>
  2126. <p>So to delegate phone number verification, in <code>homeserver.yaml</code>, set
  2127. <code>account_threepid_delegates.msisdn</code> to the base URL of an identity
  2128. server. For example:</p>
  2129. <pre><code class="language-yaml">account_threepid_delegates:
  2130. msisdn: https://example.com # Delegate sms sending to example.com
  2131. </code></pre>
  2132. <p>The <code>matrix.org</code> and <code>vector.im</code> identity servers will continue to
  2133. support delegated phone number verification via SMS until such time as
  2134. it is possible for admins to configure their servers to perform phone
  2135. number verification directly. More details will follow in a future
  2136. release.</p>
  2137. <h2 id="rolling-back-to-v131"><a class="header" href="#rolling-back-to-v131">Rolling back to v1.3.1</a></h2>
  2138. <p>If you encounter problems with v1.4.0, it should be possible to roll
  2139. back to v1.3.1, subject to the following:</p>
  2140. <ul>
  2141. <li>
  2142. <p>The 'room statistics' engine was heavily reworked in this release
  2143. (see <a href="https://github.com/matrix-org/synapse/pull/5971">#5971</a>),
  2144. including significant changes to the database schema, which are not
  2145. easily reverted. This will cause the room statistics engine to stop
  2146. updating when you downgrade.</p>
  2147. <p>The room statistics are essentially unused in v1.3.1 (in future
  2148. versions of Synapse, they will be used to populate the room
  2149. directory), so there should be no loss of functionality. However,
  2150. the statistics engine will write errors to the logs, which can be
  2151. avoided by setting the following in <code>homeserver.yaml</code>:</p>
  2152. <pre><code class="language-yaml">stats:
  2153. enabled: false
  2154. </code></pre>
  2155. <p>Don't forget to re-enable it when you upgrade again, in preparation
  2156. for its use in the room directory!</p>
  2157. </li>
  2158. </ul>
  2159. <h1 id="upgrading-to-v120"><a class="header" href="#upgrading-to-v120">Upgrading to v1.2.0</a></h1>
  2160. <p>Some counter metrics have been renamed, with the old names deprecated.
  2161. See <a href="metrics-howto.html#renaming-of-metrics--deprecation-of-old-names-in-12">the metrics
  2162. documentation</a>
  2163. for details.</p>
  2164. <h1 id="upgrading-to-v110"><a class="header" href="#upgrading-to-v110">Upgrading to v1.1.0</a></h1>
  2165. <p>Synapse v1.1.0 removes support for older Python and PostgreSQL versions,
  2166. as outlined in <a href="https://matrix.org/blog/2019/04/08/synapse-deprecating-postgres-9-4-and-python-2-x">our deprecation
  2167. notice</a>.</p>
  2168. <h2 id="minimum-python-version"><a class="header" href="#minimum-python-version">Minimum Python Version</a></h2>
  2169. <p>Synapse v1.1.0 has a minimum Python requirement of Python 3.5. Python
  2170. 3.6 or Python 3.7 are recommended as they have improved internal string
  2171. handling, significantly reducing memory usage.</p>
  2172. <p>If you use current versions of the Matrix.org-distributed Debian
  2173. packages or Docker images, action is not required.</p>
  2174. <p>If you install Synapse in a Python virtual environment, please see
  2175. &quot;Upgrading to v0.34.0&quot; for notes on setting up a new virtualenv under
  2176. Python 3.</p>
  2177. <h2 id="minimum-postgresql-version"><a class="header" href="#minimum-postgresql-version">Minimum PostgreSQL Version</a></h2>
  2178. <p>If using PostgreSQL under Synapse, you will need to use PostgreSQL 9.5
  2179. or above. Please see the <a href="https://www.postgresql.org/docs/11/upgrading.html">PostgreSQL
  2180. documentation</a> for
  2181. more details on upgrading your database.</p>
  2182. <h1 id="upgrading-to-v10"><a class="header" href="#upgrading-to-v10">Upgrading to v1.0</a></h1>
  2183. <h2 id="validation-of-tls-certificates"><a class="header" href="#validation-of-tls-certificates">Validation of TLS certificates</a></h2>
  2184. <p>Synapse v1.0 is the first release to enforce validation of TLS
  2185. certificates for the federation API. It is therefore essential that your
  2186. certificates are correctly configured. See the
  2187. <a href="MSC1711_certificates_FAQ.html">FAQ</a> for more information.</p>
  2188. <p>Note, v1.0 installations will also no longer be able to federate with
  2189. servers that have not correctly configured their certificates.</p>
  2190. <p>In rare cases, it may be desirable to disable certificate checking: for
  2191. example, it might be essential to be able to federate with a given
  2192. legacy server in a closed federation. This can be done in one of two
  2193. ways:-</p>
  2194. <ul>
  2195. <li>Configure the global switch <code>federation_verify_certificates</code> to
  2196. <code>false</code>.</li>
  2197. <li>Configure a whitelist of server domains to trust via
  2198. <code>federation_certificate_verification_whitelist</code>.</li>
  2199. </ul>
  2200. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2201. for more details on these settings.</p>
  2202. <h2 id="email-2"><a class="header" href="#email-2">Email</a></h2>
  2203. <p>When a user requests a password reset, Synapse will send an email to the
  2204. user to confirm the request.</p>
  2205. <p>Previous versions of Synapse delegated the job of sending this email to
  2206. an identity server. If the identity server was somehow malicious or
  2207. became compromised, it would be theoretically possible to hijack an
  2208. account through this means.</p>
  2209. <p>Therefore, by default, Synapse v1.0 will send the confirmation email
  2210. itself. If Synapse is not configured with an SMTP server, password reset
  2211. via email will be disabled.</p>
  2212. <p>To configure an SMTP server for Synapse, modify the configuration
  2213. section headed <code>email</code>, and be sure to have at least the <code>smtp_host</code>,
  2214. <code>smtp_port</code> and <code>notif_from</code> fields filled out. You may also need to set
  2215. <code>smtp_user</code>, <code>smtp_pass</code>, and <code>require_transport_security</code>.</p>
  2216. <p>If you are absolutely certain that you wish to continue using an
  2217. identity server for password resets, set
  2218. <code>trust_identity_server_for_password_resets</code> to <code>true</code>.</p>
  2219. <p>See the <a href="usage/configuration/homeserver_sample_config.html">sample configuration file</a>
  2220. for more details on these settings.</p>
  2221. <h2 id="new-email-templates"><a class="header" href="#new-email-templates">New email templates</a></h2>
  2222. <p>Some new templates have been added to the default template directory for the purpose of
  2223. the homeserver sending its own password reset emails. If you have configured a
  2224. custom <code>template_dir</code> in your Synapse config, these files will need to be added.</p>
  2225. <p><code>password_reset.html</code> and <code>password_reset.txt</code> are HTML and plain text
  2226. templates respectively that contain the contents of what will be emailed
  2227. to the user upon attempting to reset their password via email.
  2228. <code>password_reset_success.html</code> and <code>password_reset_failure.html</code> are HTML
  2229. files that the content of which (assuming no redirect URL is set) will
  2230. be shown to the user after they attempt to click the link in the email
  2231. sent to them.</p>
  2232. <h1 id="upgrading-to-v0990"><a class="header" href="#upgrading-to-v0990">Upgrading to v0.99.0</a></h1>
  2233. <p>Please be aware that, before Synapse v1.0 is released around March 2019,
  2234. you will need to replace any self-signed certificates with those
  2235. verified by a root CA. Information on how to do so can be found at the
  2236. ACME docs.</p>
  2237. <p>For more information on configuring TLS certificates see the
  2238. <a href="MSC1711_certificates_FAQ.html">FAQ</a>.</p>
  2239. <h1 id="upgrading-to-v0340"><a class="header" href="#upgrading-to-v0340">Upgrading to v0.34.0</a></h1>
  2240. <ol>
  2241. <li>
  2242. <p>This release is the first to fully support Python 3. Synapse will
  2243. now run on Python versions 3.5, or 3.6 (as well as 2.7). We
  2244. recommend switching to Python 3, as it has been shown to give
  2245. performance improvements.</p>
  2246. <p>For users who have installed Synapse into a virtualenv, we recommend
  2247. doing this by creating a new virtualenv. For example:</p>
  2248. <pre><code>virtualenv -p python3 ~/synapse/env3
  2249. source ~/synapse/env3/bin/activate
  2250. pip install matrix-synapse
  2251. </code></pre>
  2252. <p>You can then start synapse as normal, having activated the new
  2253. virtualenv:</p>
  2254. <pre><code>cd ~/synapse
  2255. source env3/bin/activate
  2256. synctl start
  2257. </code></pre>
  2258. <p>Users who have installed from distribution packages should see the
  2259. relevant package documentation. See below for notes on Debian
  2260. packages.</p>
  2261. <ul>
  2262. <li>
  2263. <p>When upgrading to Python 3, you <strong>must</strong> make sure that your log
  2264. files are configured as UTF-8, by adding <code>encoding: utf8</code> to the
  2265. <code>RotatingFileHandler</code> configuration (if you have one) in your
  2266. <code>&lt;server&gt;.log.config</code> file. For example, if your <code>log.config</code>
  2267. file contains:</p>
  2268. <pre><code>handlers:
  2269. file:
  2270. class: logging.handlers.RotatingFileHandler
  2271. formatter: precise
  2272. filename: homeserver.log
  2273. maxBytes: 104857600
  2274. backupCount: 10
  2275. filters: [context]
  2276. console:
  2277. class: logging.StreamHandler
  2278. formatter: precise
  2279. filters: [context]
  2280. </code></pre>
  2281. <p>Then you should update this to be:</p>
  2282. <pre><code>handlers:
  2283. file:
  2284. class: logging.handlers.RotatingFileHandler
  2285. formatter: precise
  2286. filename: homeserver.log
  2287. maxBytes: 104857600
  2288. backupCount: 10
  2289. filters: [context]
  2290. encoding: utf8
  2291. console:
  2292. class: logging.StreamHandler
  2293. formatter: precise
  2294. filters: [context]
  2295. </code></pre>
  2296. <p>There is no need to revert this change if downgrading to
  2297. Python 2.</p>
  2298. </li>
  2299. </ul>
  2300. <p>We are also making available Debian packages which will run Synapse
  2301. on Python 3. You can switch to these packages with
  2302. <code>apt-get install matrix-synapse-py3</code>, however, please read
  2303. <a href="https://github.com/matrix-org/synapse/blob/release-v0.34.0/debian/NEWS">debian/NEWS</a>
  2304. before doing so. The existing <code>matrix-synapse</code> packages will
  2305. continue to use Python 2 for the time being.</p>
  2306. </li>
  2307. <li>
  2308. <p>This release removes the <code>riot.im</code> from the default list of trusted
  2309. identity servers.</p>
  2310. <p>If <code>riot.im</code> is in your homeserver's list of
  2311. <code>trusted_third_party_id_servers</code>, you should remove it. It was added
  2312. in case a hypothetical future identity server was put there. If you
  2313. don't remove it, users may be unable to deactivate their accounts.</p>
  2314. </li>
  2315. <li>
  2316. <p>This release no longer installs the (unmaintained) Matrix Console
  2317. web client as part of the default installation. It is possible to
  2318. re-enable it by installing it separately and setting the
  2319. <code>web_client_location</code> config option, but please consider switching
  2320. to another client.</p>
  2321. </li>
  2322. </ol>
  2323. <h1 id="upgrading-to-v0337"><a class="header" href="#upgrading-to-v0337">Upgrading to v0.33.7</a></h1>
  2324. <p>This release removes the example email notification templates from
  2325. <code>res/templates</code> (they are now internal to the python package). This
  2326. should only affect you if you (a) deploy your Synapse instance from a
  2327. git checkout or a github snapshot URL, and (b) have email notifications
  2328. enabled.</p>
  2329. <p>If you have email notifications enabled, you should ensure that
  2330. <code>email.template_dir</code> is either configured to point at a directory where
  2331. you have installed customised templates, or leave it unset to use the
  2332. default templates.</p>
  2333. <h1 id="upgrading-to-v0273"><a class="header" href="#upgrading-to-v0273">Upgrading to v0.27.3</a></h1>
  2334. <p>This release expands the anonymous usage stats sent if the opt-in
  2335. <code>report_stats</code> configuration is set to <code>true</code>. We now capture RSS memory
  2336. and cpu use at a very coarse level. This requires administrators to
  2337. install the optional <code>psutil</code> python module.</p>
  2338. <p>We would appreciate it if you could assist by ensuring this module is
  2339. available and <code>report_stats</code> is enabled. This will let us see if
  2340. performance changes to synapse are having an impact to the general
  2341. community.</p>
  2342. <h1 id="upgrading-to-v0150"><a class="header" href="#upgrading-to-v0150">Upgrading to v0.15.0</a></h1>
  2343. <p>If you want to use the new URL previewing API
  2344. (<code>/_matrix/media/r0/preview_url</code>) then you have to explicitly enable it
  2345. in the config and update your dependencies dependencies. See README.rst
  2346. for details.</p>
  2347. <h1 id="upgrading-to-v0110"><a class="header" href="#upgrading-to-v0110">Upgrading to v0.11.0</a></h1>
  2348. <p>This release includes the option to send anonymous usage stats to
  2349. matrix.org, and requires that administrators explictly opt in or out by
  2350. setting the <code>report_stats</code> option to either <code>true</code> or <code>false</code>.</p>
  2351. <p>We would really appreciate it if you could help our project out by
  2352. reporting anonymized usage statistics from your homeserver. Only very
  2353. basic aggregate data (e.g. number of users) will be reported, but it
  2354. helps us to track the growth of the Matrix community, and helps us to
  2355. make Matrix a success, as well as to convince other networks that they
  2356. should peer with us.</p>
  2357. <h1 id="upgrading-to-v090"><a class="header" href="#upgrading-to-v090">Upgrading to v0.9.0</a></h1>
  2358. <p>Application services have had a breaking API change in this version.</p>
  2359. <p>They can no longer register themselves with a home server using the AS
  2360. HTTP API. This decision was made because a compromised application
  2361. service with free reign to register any regex in effect grants full
  2362. read/write access to the home server if a regex of <code>.*</code> is used. An
  2363. attack where a compromised AS re-registers itself with <code>.*</code> was deemed
  2364. too big of a security risk to ignore, and so the ability to register
  2365. with the HS remotely has been removed.</p>
  2366. <p>It has been replaced by specifying a list of application service
  2367. registrations in <code>homeserver.yaml</code>:</p>
  2368. <pre><code>app_service_config_files: [&quot;registration-01.yaml&quot;, &quot;registration-02.yaml&quot;]
  2369. </code></pre>
  2370. <p>Where <code>registration-01.yaml</code> looks like:</p>
  2371. <pre><code>url: &lt;String&gt; # e.g. &quot;https://my.application.service.com&quot;
  2372. as_token: &lt;String&gt;
  2373. hs_token: &lt;String&gt;
  2374. sender_localpart: &lt;String&gt; # This is a new field which denotes the user_id localpart when using the AS token
  2375. namespaces:
  2376. users:
  2377. - exclusive: &lt;Boolean&gt;
  2378. regex: &lt;String&gt; # e.g. &quot;@prefix_.*&quot;
  2379. aliases:
  2380. - exclusive: &lt;Boolean&gt;
  2381. regex: &lt;String&gt;
  2382. rooms:
  2383. - exclusive: &lt;Boolean&gt;
  2384. regex: &lt;String&gt;
  2385. </code></pre>
  2386. <h1 id="upgrading-to-v080"><a class="header" href="#upgrading-to-v080">Upgrading to v0.8.0</a></h1>
  2387. <p>Servers which use captchas will need to add their public key to:</p>
  2388. <pre><code>static/client/register/register_config.js
  2389. window.matrixRegistrationConfig = {
  2390. recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  2391. };
  2392. </code></pre>
  2393. <p>This is required in order to support registration fallback (typically
  2394. used on mobile devices).</p>
  2395. <h1 id="upgrading-to-v070"><a class="header" href="#upgrading-to-v070">Upgrading to v0.7.0</a></h1>
  2396. <p>New dependencies are:</p>
  2397. <ul>
  2398. <li>pydenticon</li>
  2399. <li>simplejson</li>
  2400. <li>syutil</li>
  2401. <li>matrix-angular-sdk</li>
  2402. </ul>
  2403. <p>To pull in these dependencies in a virtual env, run:</p>
  2404. <pre><code>python synapse/python_dependencies.py | xargs -n 1 pip install
  2405. </code></pre>
  2406. <h1 id="upgrading-to-v060"><a class="header" href="#upgrading-to-v060">Upgrading to v0.6.0</a></h1>
  2407. <p>To pull in new dependencies, run:</p>
  2408. <pre><code>python setup.py develop --user
  2409. </code></pre>
  2410. <p>This update includes a change to the database schema. To upgrade you
  2411. first need to upgrade the database by running:</p>
  2412. <pre><code>python scripts/upgrade_db_to_v0.6.0.py &lt;db&gt; &lt;server_name&gt; &lt;signing_key&gt;
  2413. </code></pre>
  2414. <p>Where [<db>]{.title-ref} is the location of the database,
  2415. [&lt;server_name&gt;]{.title-ref} is the server name as specified in the
  2416. synapse configuration, and [&lt;signing_key&gt;]{.title-ref} is the location
  2417. of the signing key as specified in the synapse configuration.</p>
  2418. <p>This may take some time to complete. Failures of signatures and content
  2419. hashes can safely be ignored.</p>
  2420. <h1 id="upgrading-to-v051"><a class="header" href="#upgrading-to-v051">Upgrading to v0.5.1</a></h1>
  2421. <p>Depending on precisely when you installed v0.5.0 you may have ended up
  2422. with a stale release of the reference matrix webclient installed as a
  2423. python module. To uninstall it and ensure you are depending on the
  2424. latest module, please run:</p>
  2425. <pre><code>$ pip uninstall syweb
  2426. </code></pre>
  2427. <h1 id="upgrading-to-v050"><a class="header" href="#upgrading-to-v050">Upgrading to v0.5.0</a></h1>
  2428. <p>The webclient has been split out into a seperate repository/pacakage in
  2429. this release. Before you restart your homeserver you will need to pull
  2430. in the webclient package by running:</p>
  2431. <pre><code>python setup.py develop --user
  2432. </code></pre>
  2433. <p>This release completely changes the database schema and so requires
  2434. upgrading it before starting the new version of the homeserver.</p>
  2435. <p>The script &quot;database-prepare-for-0.5.0.sh&quot; should be used to upgrade
  2436. the database. This will save all user information, such as logins and
  2437. profiles, but will otherwise purge the database. This includes messages,
  2438. which rooms the home server was a member of and room alias mappings.</p>
  2439. <p>If you would like to keep your history, please take a copy of your
  2440. database file and ask for help in #matrix:matrix.org. The upgrade
  2441. process is, unfortunately, non trivial and requires human intervention
  2442. to resolve any resulting conflicts during the upgrade process.</p>
  2443. <p>Before running the command the homeserver should be first completely
  2444. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2445. <blockquote>
  2446. <p>./scripts/database-prepare-for-0.5.0.sh &quot;homeserver.db&quot;</p>
  2447. </blockquote>
  2448. <p>Once this has successfully completed it will be safe to restart the
  2449. homeserver. You may notice that the homeserver takes a few seconds
  2450. longer to restart than usual as it reinitializes the database.</p>
  2451. <p>On startup of the new version, users can either rejoin remote rooms
  2452. using room aliases or by being reinvited. Alternatively, if any other
  2453. homeserver sends a message to a room that the homeserver was previously
  2454. in the local HS will automatically rejoin the room.</p>
  2455. <h1 id="upgrading-to-v040"><a class="header" href="#upgrading-to-v040">Upgrading to v0.4.0</a></h1>
  2456. <p>This release needs an updated syutil version. Run:</p>
  2457. <pre><code>python setup.py develop
  2458. </code></pre>
  2459. <p>You will also need to upgrade your configuration as the signing key
  2460. format has changed. Run:</p>
  2461. <pre><code>python -m synapse.app.homeserver --config-path &lt;CONFIG&gt; --generate-config
  2462. </code></pre>
  2463. <h1 id="upgrading-to-v030"><a class="header" href="#upgrading-to-v030">Upgrading to v0.3.0</a></h1>
  2464. <p>This registration API now closely matches the login API. This introduces
  2465. a bit more backwards and forwards between the HS and the client, but
  2466. this improves the overall flexibility of the API. You can now GET on
  2467. /register to retrieve a list of valid registration flows. Upon choosing
  2468. one, they are submitted in the same way as login, e.g:</p>
  2469. <pre><code>{
  2470. type: m.login.password,
  2471. user: foo,
  2472. password: bar
  2473. }
  2474. </code></pre>
  2475. <p>The default HS supports 2 flows, with and without Identity Server email
  2476. authentication. Enabling captcha on the HS will add in an extra step to
  2477. all flows: <code>m.login.recaptcha</code> which must be completed before you can
  2478. transition to the next stage. There is a new login type:
  2479. <code>m.login.email.identity</code> which contains the <code>threepidCreds</code> key which
  2480. were previously sent in the original register request. For more
  2481. information on this, see the specification.</p>
  2482. <h2 id="web-client"><a class="header" href="#web-client">Web Client</a></h2>
  2483. <p>The VoIP specification has changed between v0.2.0 and v0.3.0. Users
  2484. should refresh any browser tabs to get the latest web client code. Users
  2485. on v0.2.0 of the web client will not be able to call those on v0.3.0 and
  2486. vice versa.</p>
  2487. <h1 id="upgrading-to-v020"><a class="header" href="#upgrading-to-v020">Upgrading to v0.2.0</a></h1>
  2488. <p>The home server now requires setting up of SSL config before it can run.
  2489. To automatically generate default config use:</p>
  2490. <pre><code>$ python synapse/app/homeserver.py \
  2491. --server-name machine.my.domain.name \
  2492. --bind-port 8448 \
  2493. --config-path homeserver.config \
  2494. --generate-config
  2495. </code></pre>
  2496. <p>This config can be edited if desired, for example to specify a different
  2497. SSL certificate to use. Once done you can run the home server using:</p>
  2498. <pre><code>$ python synapse/app/homeserver.py --config-path homeserver.config
  2499. </code></pre>
  2500. <p>See the README.rst for more information.</p>
  2501. <p>Also note that some config options have been renamed, including:</p>
  2502. <ul>
  2503. <li>&quot;host&quot; to &quot;server-name&quot;</li>
  2504. <li>&quot;database&quot; to &quot;database-path&quot;</li>
  2505. <li>&quot;port&quot; to &quot;bind-port&quot; and &quot;unsecure-port&quot;</li>
  2506. </ul>
  2507. <h1 id="upgrading-to-v001"><a class="header" href="#upgrading-to-v001">Upgrading to v0.0.1</a></h1>
  2508. <p>This release completely changes the database schema and so requires
  2509. upgrading it before starting the new version of the homeserver.</p>
  2510. <p>The script &quot;database-prepare-for-0.0.1.sh&quot; should be used to upgrade
  2511. the database. This will save all user information, such as logins and
  2512. profiles, but will otherwise purge the database. This includes messages,
  2513. which rooms the home server was a member of and room alias mappings.</p>
  2514. <p>Before running the command the homeserver should be first completely
  2515. shutdown. To run it, simply specify the location of the database, e.g.:</p>
  2516. <blockquote>
  2517. <p>./scripts/database-prepare-for-0.0.1.sh &quot;homeserver.db&quot;</p>
  2518. </blockquote>
  2519. <p>Once this has successfully completed it will be safe to restart the
  2520. homeserver. You may notice that the homeserver takes a few seconds
  2521. longer to restart than usual as it reinitializes the database.</p>
  2522. <p>On startup of the new version, users can either rejoin remote rooms
  2523. using room aliases or by being reinvited. Alternatively, if any other
  2524. homeserver sends a message to a room that the homeserver was previously
  2525. in the local HS will automatically rejoin the room.</p>
  2526. <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>
  2527. <h2 id="historical-note"><a class="header" href="#historical-note">Historical Note</a></h2>
  2528. <p>This document was originally written to guide server admins through the upgrade
  2529. path towards Synapse 1.0. Specifically,
  2530. <a href="https://github.com/matrix-org/matrix-doc/blob/master/proposals/1711-x509-for-federation.md">MSC1711</a>
  2531. required that all servers present valid TLS certificates on their federation
  2532. API. Admins were encouraged to achieve compliance from version 0.99.0 (released
  2533. in February 2019) ahead of version 1.0 (released June 2019) enforcing the
  2534. certificate checks.</p>
  2535. <p>Much of what follows is now outdated since most admins will have already
  2536. upgraded, however it may be of use to those with old installs returning to the
  2537. project.</p>
  2538. <p>If you are setting up a server from scratch you almost certainly should look at
  2539. the <a href="setup/installation.html">installation guide</a> instead.</p>
  2540. <h2 id="introduction-1"><a class="header" href="#introduction-1">Introduction</a></h2>
  2541. <p>The goal of Synapse 0.99.0 is to act as a stepping stone to Synapse 1.0.0. It
  2542. supports the r0.1 release of the server to server specification, but is
  2543. compatible with both the legacy Matrix federation behaviour (pre-r0.1) as well
  2544. as post-r0.1 behaviour, in order to allow for a smooth upgrade across the
  2545. federation.</p>
  2546. <p>The most important thing to know is that Synapse 1.0.0 will require a valid TLS
  2547. certificate on federation endpoints. Self signed certificates will not be
  2548. sufficient.</p>
  2549. <p>Synapse 0.99.0 makes it easy to configure TLS certificates and will
  2550. interoperate with both &gt;= 1.0.0 servers as well as existing servers yet to
  2551. upgrade.</p>
  2552. <p><strong>It is critical that all admins upgrade to 0.99.0 and configure a valid TLS
  2553. certificate.</strong> Admins will have 1 month to do so, after which 1.0.0 will be
  2554. released and those servers without a valid certificate will not longer be able
  2555. to federate with &gt;= 1.0.0 servers.</p>
  2556. <p>Full details on how to carry out this configuration change is given
  2557. <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">below</a>. A
  2558. timeline and some frequently asked questions are also given below.</p>
  2559. <p>For more details and context on the release of the r0.1 Server/Server API and
  2560. imminent Matrix 1.0 release, you can also see our
  2561. <a href="https://matrix.org/blog/2019/02/04/matrix-at-fosdem-2019/">main talk from FOSDEM 2019</a>.</p>
  2562. <h2 id="contents"><a class="header" href="#contents">Contents</a></h2>
  2563. <ul>
  2564. <li>Timeline</li>
  2565. <li>Configuring certificates for compatibility with Synapse 1.0</li>
  2566. <li>FAQ
  2567. <ul>
  2568. <li>Synapse 0.99.0 has just been released, what do I need to do right now?</li>
  2569. <li>How do I upgrade?</li>
  2570. <li>What will happen if I do not set up a valid federation certificate
  2571. immediately?</li>
  2572. <li>What will happen if I do nothing at all?</li>
  2573. <li>When do I need a SRV record or .well-known URI?</li>
  2574. <li>Can I still use an SRV record?</li>
  2575. <li>I have created a .well-known URI. Do I still need an SRV record?</li>
  2576. <li>It used to work just fine, why are you breaking everything?</li>
  2577. <li>Can I manage my own certificates rather than having Synapse renew
  2578. certificates itself?</li>
  2579. <li>Do you still recommend against using a reverse proxy on the federation port?</li>
  2580. <li>Do I still need to give my TLS certificates to Synapse if I am using a
  2581. reverse proxy?</li>
  2582. <li>Do I need the same certificate for the client and federation port?</li>
  2583. <li>How do I tell Synapse to reload my keys/certificates after I replace them?</li>
  2584. </ul>
  2585. </li>
  2586. </ul>
  2587. <h2 id="timeline"><a class="header" href="#timeline">Timeline</a></h2>
  2588. <p><strong>5th Feb 2019 - Synapse 0.99.0 is released.</strong></p>
  2589. <p>All server admins are encouraged to upgrade.</p>
  2590. <p>0.99.0:</p>
  2591. <ul>
  2592. <li>
  2593. <p>provides support for ACME to make setting up Let's Encrypt certs easy, as
  2594. well as .well-known support.</p>
  2595. </li>
  2596. <li>
  2597. <p>does not enforce that a valid CA cert is present on the federation API, but
  2598. rather makes it easy to set one up.</p>
  2599. </li>
  2600. <li>
  2601. <p>provides support for .well-known</p>
  2602. </li>
  2603. </ul>
  2604. <p>Admins should upgrade and configure a valid CA cert. Homeservers that require a
  2605. .well-known entry (see below), should retain their SRV record and use it
  2606. alongside their .well-known record.</p>
  2607. <p><strong>10th June 2019 - Synapse 1.0.0 is released</strong></p>
  2608. <p>1.0.0 is scheduled for release on 10th June. In
  2609. accordance with the the <a href="https://matrix.org/docs/spec/server_server/r0.1.0.html">S2S spec</a>
  2610. 1.0.0 will enforce certificate validity. This means that any homeserver without a
  2611. valid certificate after this point will no longer be able to federate with
  2612. 1.0.0 servers.</p>
  2613. <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>
  2614. <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>
  2615. <p>In this case, your <code>server_name</code> points to the host where your Synapse is
  2616. running. There is no need to create a <code>.well-known</code> URI or an SRV record, but
  2617. you will need to give Synapse a valid, signed, certificate.</p>
  2618. <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>
  2619. <p>If you are using an SRV record, your matrix domain (<code>server_name</code>) may not
  2620. point to the same host that your Synapse is running on (the 'target
  2621. domain'). (If it does, you can follow the recommendation above; otherwise, read
  2622. on.)</p>
  2623. <p>Let's assume that your <code>server_name</code> is <code>example.com</code>, and your Synapse is
  2624. hosted at a target domain of <code>customer.example.net</code>. Currently you should have
  2625. an SRV record which looks like:</p>
  2626. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 8000 customer.example.net.
  2627. </code></pre>
  2628. <p>In this situation, you have three choices for how to proceed:</p>
  2629. <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>
  2630. <p>Synapse 1.0 will expect your server to present a TLS certificate for your
  2631. <code>server_name</code> (<code>example.com</code> in the above example). You can achieve this by acquiring a
  2632. certificate for the <code>server_name</code> yourself (for example, using <code>certbot</code>), and giving it
  2633. and the key to Synapse via <code>tls_certificate_path</code> and <code>tls_private_key_path</code>.</p>
  2634. <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>
  2635. <p>If you have an existing reverse proxy set up with correct TLS certificates for
  2636. your domain, you can simply route all traffic through the reverse proxy by
  2637. updating the SRV record appropriately (or removing it, if the proxy listens on
  2638. 8448).</p>
  2639. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2640. reverse proxy.</p>
  2641. <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>
  2642. <p>This will allow you to keep Synapse on a separate domain, without having to
  2643. give it a certificate for the matrix domain.</p>
  2644. <p>You can do this with a <code>.well-known</code> file as follows:</p>
  2645. <ol>
  2646. <li>
  2647. <p>Keep the SRV record in place - it is needed for backwards compatibility
  2648. with Synapse 0.34 and earlier.</p>
  2649. </li>
  2650. <li>
  2651. <p>Give Synapse a certificate corresponding to the target domain
  2652. (<code>customer.example.net</code> in the above example). You can do this by acquire a
  2653. certificate for the target domain and giving it to Synapse via <code>tls_certificate_path</code>
  2654. and <code>tls_private_key_path</code>.</p>
  2655. </li>
  2656. <li>
  2657. <p>Restart Synapse to ensure the new certificate is loaded.</p>
  2658. </li>
  2659. <li>
  2660. <p>Arrange for a <code>.well-known</code> file at
  2661. <code>https://&lt;server_name&gt;/.well-known/matrix/server</code> with contents:</p>
  2662. <pre><code class="language-json">{&quot;m.server&quot;: &quot;&lt;target server name&gt;&quot;}
  2663. </code></pre>
  2664. <p>where the target server name is resolved as usual (i.e. SRV lookup, falling
  2665. back to talking to port 8448).</p>
  2666. <p>In the above example, where synapse is listening on port 8000,
  2667. <code>https://example.com/.well-known/matrix/server</code> should have <code>m.server</code> set to one of:</p>
  2668. <ol>
  2669. <li>
  2670. <p><code>customer.example.net</code> ─ with a SRV record on
  2671. <code>_matrix._tcp.customer.example.com</code> pointing to port 8000, or:</p>
  2672. </li>
  2673. <li>
  2674. <p><code>customer.example.net</code> ─ updating synapse to listen on the default port
  2675. 8448, or:</p>
  2676. </li>
  2677. <li>
  2678. <p><code>customer.example.net:8000</code> ─ ensuring that if there is a reverse proxy
  2679. on <code>customer.example.net:8000</code> it correctly handles HTTP requests with
  2680. Host header set to <code>customer.example.net:8000</code>.</p>
  2681. </li>
  2682. </ol>
  2683. </li>
  2684. </ol>
  2685. <h2 id="faq"><a class="header" href="#faq">FAQ</a></h2>
  2686. <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>
  2687. <p>Upgrade as soon as you can in preparation for Synapse 1.0.0, and update your
  2688. TLS certificates as <a href="MSC1711_certificates_FAQ.html#configuring-certificates-for-compatibility-with-synapse-100">above</a>.</p>
  2689. <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>
  2690. <p>Nothing initially, but once 1.0.0 is in the wild it will not be possible to
  2691. federate with 1.0.0 servers.</p>
  2692. <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>
  2693. <p>If the admin takes no action at all, and remains on a Synapse &lt; 0.99.0 then the
  2694. homeserver will be unable to federate with those who have implemented
  2695. .well-known. Then, as above, once the month upgrade window has expired the
  2696. homeserver will not be able to federate with any Synapse &gt;= 1.0.0</p>
  2697. <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>
  2698. <p>If your homeserver listens on the default federation port (8448), and your
  2699. <code>server_name</code> points to the host that your homeserver runs on, you do not need an
  2700. SRV record or <code>.well-known/matrix/server</code> URI.</p>
  2701. <p>For instance, if you registered <code>example.com</code> and pointed its DNS A record at a
  2702. fresh Upcloud VPS or similar, you could install Synapse 0.99 on that host,
  2703. giving it a server_name of <code>example.com</code>, and it would automatically generate a
  2704. valid TLS certificate for you via Let's Encrypt and no SRV record or
  2705. <code>.well-known</code> URI would be needed.</p>
  2706. <p>This is the common case, although you can add an SRV record or
  2707. <code>.well-known/matrix/server</code> URI for completeness if you wish.</p>
  2708. <p><strong>However</strong>, if your server does not listen on port 8448, or if your <code>server_name</code>
  2709. does not point to the host that your homeserver runs on, you will need to let
  2710. other servers know how to find it.</p>
  2711. <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
  2712. currently&quot;</a> above.</p>
  2713. <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>
  2714. <p>Firstly, if you didn't need an SRV record before (because your server is
  2715. listening on port 8448 of your server_name), you certainly don't need one now:
  2716. the defaults are still the same.</p>
  2717. <p>If you previously had an SRV record, you can keep using it provided you are
  2718. able to give Synapse a TLS certificate corresponding to your server name. For
  2719. example, suppose you had the following SRV record, which directs matrix traffic
  2720. for example.com to matrix.example.com:443:</p>
  2721. <pre><code>_matrix._tcp.example.com. IN SRV 10 5 443 matrix.example.com
  2722. </code></pre>
  2723. <p>In this case, Synapse must be given a certificate for example.com - or be
  2724. configured to acquire one from Let's Encrypt.</p>
  2725. <p>If you are unable to give Synapse a certificate for your server_name, you will
  2726. also need to use a .well-known URI instead. However, see also &quot;I have created a
  2727. .well-known URI. Do I still need an SRV record?&quot;.</p>
  2728. <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>
  2729. <p>As of Synapse 0.99, Synapse will first check for the existence of a <code>.well-known</code>
  2730. URI and follow any delegation it suggests. It will only then check for the
  2731. existence of an SRV record.</p>
  2732. <p>That means that the SRV record will often be redundant. However, you should
  2733. remember that there may still be older versions of Synapse in the federation
  2734. which do not understand <code>.well-known</code> URIs, so if you removed your SRV record you
  2735. would no longer be able to federate with them.</p>
  2736. <p>It is therefore best to leave the SRV record in place for now. Synapse 0.34 and
  2737. earlier will follow the SRV record (and not care about the invalid
  2738. certificate). Synapse 0.99 and later will follow the .well-known URI, with the
  2739. correct certificate chain.</p>
  2740. <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>
  2741. <p>We have always wanted Matrix servers to be as easy to set up as possible, and
  2742. so back when we started federation in 2014 we didn't want admins to have to go
  2743. through the cumbersome process of buying a valid TLS certificate to run a
  2744. server. This was before Let's Encrypt came along and made getting a free and
  2745. valid TLS certificate straightforward. So instead, we adopted a system based on
  2746. <a href="https://en.wikipedia.org/wiki/Convergence_(SSL)">Perspectives</a>: an approach
  2747. where you check a set of &quot;notary servers&quot; (in practice, homeservers) to vouch
  2748. for the validity of a certificate rather than having it signed by a CA. As long
  2749. as enough different notaries agree on the certificate's validity, then it is
  2750. trusted.</p>
  2751. <p>However, in practice this has never worked properly. Most people only use the
  2752. default notary server (matrix.org), leading to inadvertent centralisation which
  2753. we want to eliminate. Meanwhile, we never implemented the full consensus
  2754. algorithm to query the servers participating in a room to determine consensus
  2755. on whether a given certificate is valid. This is fiddly to get right
  2756. (especially in face of sybil attacks), and we found ourselves questioning
  2757. whether it was worth the effort to finish the work and commit to maintaining a
  2758. secure certificate validation system as opposed to focusing on core Matrix
  2759. development.</p>
  2760. <p>Meanwhile, Let's Encrypt came along in 2016, and put the final nail in the
  2761. coffin of the Perspectives project (which was already pretty dead). So, the
  2762. Spec Core Team decided that a better approach would be to mandate valid TLS
  2763. certificates for federation alongside the rest of the Web. More details can be
  2764. found in
  2765. <a href="https://github.com/matrix-org/matrix-doc/blob/master/proposals/1711-x509-for-federation.md#background-the-failure-of-the-perspectives-approach">MSC1711</a>.</p>
  2766. <p>This results in a breaking change, which is disruptive, but absolutely critical
  2767. for the security model. However, the existence of Let's Encrypt as a trivial
  2768. way to replace the old self-signed certificates with valid CA-signed ones helps
  2769. smooth things over massively, especially as Synapse can now automate Let's
  2770. Encrypt certificate generation if needed.</p>
  2771. <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>
  2772. <p>Yes, you are welcome to manage your certificates yourself. Synapse will only
  2773. attempt to obtain certificates from Let's Encrypt if you configure it to do
  2774. so.The only requirement is that there is a valid TLS cert present for
  2775. federation end points.</p>
  2776. <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>
  2777. <p>We no longer actively recommend against using a reverse proxy. Many admins will
  2778. find it easier to direct federation traffic to a reverse proxy and manage their
  2779. own TLS certificates, and this is a supported configuration.</p>
  2780. <p>See <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a
  2781. reverse proxy.</p>
  2782. <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>
  2783. <p>Practically speaking, this is no longer necessary.</p>
  2784. <p>If you are using a reverse proxy for all of your TLS traffic, then you can set
  2785. <code>no_tls: True</code>. In that case, the only reason Synapse needs the certificate is
  2786. to populate a legacy 'tls_fingerprints' field in the federation API. This is
  2787. ignored by Synapse 0.99.0 and later, and the only time pre-0.99 Synapses will
  2788. check it is when attempting to fetch the server keys - and generally this is
  2789. delegated via <code>matrix.org</code>, which is on 0.99.0.</p>
  2790. <p>However, there is a bug in Synapse 0.99.0
  2791. <a href="https://github.com/matrix-org/synapse/issues/4554">4554</a> which prevents
  2792. Synapse from starting if you do not give it a TLS certificate. To work around
  2793. this, you can give it any TLS certificate at all. This will be fixed soon.</p>
  2794. <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>
  2795. <p>No. There is nothing stopping you from using different certificates,
  2796. particularly if you are using a reverse proxy. However, Synapse will use the
  2797. same certificate on any ports where TLS is configured.</p>
  2798. <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>
  2799. <p>Synapse will reload the keys and certificates when it receives a SIGHUP - for
  2800. example <code>kill -HUP $(cat homeserver.pid)</code>. Alternatively, simply restart
  2801. Synapse, though this will result in downtime while it restarts.</p>
  2802. <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>
  2803. <p>Federation is the process by which users on different servers can participate
  2804. in the same room. For this to work, those other servers must be able to contact
  2805. yours to send messages.</p>
  2806. <p>The <code>server_name</code> configured in the Synapse configuration file (often
  2807. <code>homeserver.yaml</code>) defines how resources (users, rooms, etc.) will be
  2808. identified (eg: <code>@user:example.com</code>, <code>#room:example.com</code>). By default,
  2809. it is also the domain that other servers will use to try to reach your
  2810. server (via port 8448). This is easy to set up and will work provided
  2811. you set the <code>server_name</code> to match your machine's public DNS hostname.</p>
  2812. <p>For this default configuration to work, you will need to listen for TLS
  2813. connections on port 8448. The preferred way to do that is by using a
  2814. reverse proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions
  2815. on how to correctly set one up.</p>
  2816. <p>In some cases you might not want to run Synapse on the machine that has
  2817. the <code>server_name</code> as its public DNS hostname, or you might want federation
  2818. traffic to use a different port than 8448. For example, you might want to
  2819. have your user names look like <code>@user:example.com</code>, but you want to run
  2820. Synapse on <code>synapse.example.com</code> on port 443. This can be done using
  2821. delegation, which allows an admin to control where federation traffic should
  2822. be sent. See <a href="delegate.html">the delegation documentation</a> for instructions on how to set this up.</p>
  2823. <p>Once federation has been configured, you should be able to join a room over
  2824. federation. A good place to start is <code>#synapse:matrix.org</code> - a room for
  2825. Synapse admins.</p>
  2826. <h2 id="troubleshooting-3"><a class="header" href="#troubleshooting-3">Troubleshooting</a></h2>
  2827. <p>You can use the <a href="https://matrix.org/federationtester">federation tester</a>
  2828. to check if your homeserver is configured correctly. Alternatively try the
  2829. <a href="https://matrix.org/federationtester/api/report?server_name=DOMAIN">JSON API used by the federation tester</a>.
  2830. Note that you'll have to modify this URL to replace <code>DOMAIN</code> with your
  2831. <code>server_name</code>. Hitting the API directly provides extra detail.</p>
  2832. <p>The typical failure mode for federation is that when the server tries to join
  2833. a room, it is rejected with &quot;401: Unauthorized&quot;. Generally this means that other
  2834. servers in the room could not access yours. (Joining a room over federation is
  2835. a complicated dance which requires connections in both directions).</p>
  2836. <p>Another common problem is that people on other servers can't join rooms that
  2837. you invite them to. This can be caused by an incorrectly-configured reverse
  2838. proxy: see <a href="reverse_proxy.html">the reverse proxy documentation</a> for instructions on how
  2839. to correctly configure a reverse proxy.</p>
  2840. <h3 id="known-issues"><a class="header" href="#known-issues">Known issues</a></h3>
  2841. <p><strong>HTTP <code>308 Permanent Redirect</code> redirects are not followed</strong>: Due to missing features
  2842. in the HTTP library used by Synapse, 308 redirects are currently not followed by
  2843. federating servers, which can cause <code>M_UNKNOWN</code> or <code>401 Unauthorized</code> errors. This
  2844. may affect users who are redirecting apex-to-www (e.g. <code>example.com</code> -&gt; <code>www.example.com</code>),
  2845. and especially users of the Kubernetes <em>Nginx Ingress</em> module, which uses 308 redirect
  2846. codes by default. For those Kubernetes users, <a href="https://stackoverflow.com/a/52617528/5096871">this Stackoverflow post</a>
  2847. might be helpful. For other users, switching to a <code>301 Moved Permanently</code> code may be
  2848. an option. 308 redirect codes will be supported properly in a future
  2849. release of Synapse.</p>
  2850. <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>
  2851. <p>If you want to get up and running quickly with a trio of homeservers in a
  2852. private federation, there is a script in the <code>demo</code> directory. This is mainly
  2853. useful just for development purposes. See <a href="https://github.com/matrix-org/synapse/tree/develop/demo/">demo/README</a>.</p>
  2854. <div style="break-before: page; page-break-before: always;"></div><h1 id="configuration-1"><a class="header" href="#configuration-1">Configuration</a></h1>
  2855. <p>This section contains information on tweaking Synapse via the various options in the configuration file. A configuration
  2856. file should have been generated when you <a href="usage/configuration/../../setup/installation.html">installed Synapse</a>.</p>
  2857. <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>
  2858. <p>Below is a sample homeserver configuration file. The homeserver configuration file
  2859. can be tweaked to change the behaviour of your homeserver. A restart of the server is
  2860. generally required to apply any changes made to this file.</p>
  2861. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  2862. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  2863. a fresh config using Synapse by following the instructions in
  2864. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  2865. <pre><code class="language-yaml"># This file is maintained as an up-to-date snapshot of the default
  2866. # homeserver.yaml configuration generated by Synapse.
  2867. #
  2868. # It is intended to act as a reference for the default configuration,
  2869. # helping admins keep track of new options and other changes, and compare
  2870. # their configs with the current default. As such, many of the actual
  2871. # config values shown are placeholders.
  2872. #
  2873. # It is *not* intended to be copied and used as the basis for a real
  2874. # homeserver.yaml. Instead, if you are starting from scratch, please generate
  2875. # a fresh config using Synapse by following the instructions in
  2876. # https://matrix-org.github.io/synapse/latest/setup/installation.html.
  2877. # Configuration options that take a time period can be set using a number
  2878. # followed by a letter. Letters have the following meanings:
  2879. # s = second
  2880. # m = minute
  2881. # h = hour
  2882. # d = day
  2883. # w = week
  2884. # y = year
  2885. # For example, setting redaction_retention_period: 5m would remove redacted
  2886. # messages from the database after 5 minutes, rather than 5 months.
  2887. ################################################################################
  2888. # Configuration file for Synapse.
  2889. #
  2890. # This is a YAML file: see [1] for a quick introduction. Note in particular
  2891. # that *indentation is important*: all the elements of a list or dictionary
  2892. # should have the same indentation.
  2893. #
  2894. # [1] https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html
  2895. ## Modules ##
  2896. # Server admins can expand Synapse's functionality with external modules.
  2897. #
  2898. # See https://matrix-org.github.io/synapse/latest/modules.html for more
  2899. # documentation on how to configure or create custom modules for Synapse.
  2900. #
  2901. modules:
  2902. # - module: my_super_module.MySuperClass
  2903. # config:
  2904. # do_thing: true
  2905. # - module: my_other_super_module.SomeClass
  2906. # config: {}
  2907. ## Server ##
  2908. # The public-facing domain of the server
  2909. #
  2910. # The server_name name will appear at the end of usernames and room addresses
  2911. # created on this server. For example if the server_name was example.com,
  2912. # usernames on this server would be in the format @user:example.com
  2913. #
  2914. # In most cases you should avoid using a matrix specific subdomain such as
  2915. # matrix.example.com or synapse.example.com as the server_name for the same
  2916. # reasons you wouldn't use user@email.example.com as your email address.
  2917. # See https://matrix-org.github.io/synapse/latest/delegate.html
  2918. # for information on how to host Synapse on a subdomain while preserving
  2919. # a clean server_name.
  2920. #
  2921. # The server_name cannot be changed later so it is important to
  2922. # configure this correctly before you start Synapse. It should be all
  2923. # lowercase and may contain an explicit port.
  2924. # Examples: matrix.org, localhost:8080
  2925. #
  2926. server_name: &quot;SERVERNAME&quot;
  2927. # When running as a daemon, the file to store the pid in
  2928. #
  2929. pid_file: DATADIR/homeserver.pid
  2930. # The absolute URL to the web client which /_matrix/client will redirect
  2931. # to if 'webclient' is configured under the 'listeners' configuration.
  2932. #
  2933. # This option can be also set to the filesystem path to the web client
  2934. # which will be served at /_matrix/client/ if 'webclient' is configured
  2935. # under the 'listeners' configuration, however this is a security risk:
  2936. # https://github.com/matrix-org/synapse#security-note
  2937. #
  2938. #web_client_location: https://riot.example.com/
  2939. # The public-facing base URL that clients use to access this Homeserver (not
  2940. # including _matrix/...). This is the same URL a user might enter into the
  2941. # 'Custom Homeserver URL' field on their client. If you use Synapse with a
  2942. # reverse proxy, this should be the URL to reach Synapse via the proxy.
  2943. # Otherwise, it should be the URL to reach Synapse's client HTTP listener (see
  2944. # 'listeners' below).
  2945. #
  2946. #public_baseurl: https://example.com/
  2947. # Set the soft limit on the number of file descriptors synapse can use
  2948. # Zero is used to indicate synapse should set the soft limit to the
  2949. # hard limit.
  2950. #
  2951. #soft_file_limit: 0
  2952. # Presence tracking allows users to see the state (e.g online/offline)
  2953. # of other local and remote users.
  2954. #
  2955. presence:
  2956. # Uncomment to disable presence tracking on this homeserver. This option
  2957. # replaces the previous top-level 'use_presence' option.
  2958. #
  2959. #enabled: false
  2960. # Whether to require authentication to retrieve profile data (avatars,
  2961. # display names) of other users through the client API. Defaults to
  2962. # 'false'. Note that profile data is also available via the federation
  2963. # API, unless allow_profile_lookup_over_federation is set to false.
  2964. #
  2965. #require_auth_for_profile_requests: true
  2966. # Uncomment to require a user to share a room with another user in order
  2967. # to retrieve their profile information. Only checked on Client-Server
  2968. # requests. Profile requests from other servers should be checked by the
  2969. # requesting server. Defaults to 'false'.
  2970. #
  2971. #limit_profile_requests_to_users_who_share_rooms: true
  2972. # Uncomment to prevent a user's profile data from being retrieved and
  2973. # displayed in a room until they have joined it. By default, a user's
  2974. # profile data is included in an invite event, regardless of the values
  2975. # of the above two settings, and whether or not the users share a server.
  2976. # Defaults to 'true'.
  2977. #
  2978. #include_profile_data_on_invite: false
  2979. # If set to 'true', removes the need for authentication to access the server's
  2980. # public rooms directory through the client API, meaning that anyone can
  2981. # query the room directory. Defaults to 'false'.
  2982. #
  2983. #allow_public_rooms_without_auth: true
  2984. # If set to 'true', allows any other homeserver to fetch the server's public
  2985. # rooms directory via federation. Defaults to 'false'.
  2986. #
  2987. #allow_public_rooms_over_federation: true
  2988. # The default room version for newly created rooms.
  2989. #
  2990. # Known room versions are listed here:
  2991. # https://matrix.org/docs/spec/#complete-list-of-room-versions
  2992. #
  2993. # For example, for room version 1, default_room_version should be set
  2994. # to &quot;1&quot;.
  2995. #
  2996. #default_room_version: &quot;6&quot;
  2997. # The GC threshold parameters to pass to `gc.set_threshold`, if defined
  2998. #
  2999. #gc_thresholds: [700, 10, 10]
  3000. # The minimum time in seconds between each GC for a generation, regardless of
  3001. # the GC thresholds. This ensures that we don't do GC too frequently.
  3002. #
  3003. # A value of `[1s, 10s, 30s]` indicates that a second must pass between consecutive
  3004. # generation 0 GCs, etc.
  3005. #
  3006. # Defaults to `[1s, 10s, 30s]`.
  3007. #
  3008. #gc_min_interval: [0.5s, 30s, 1m]
  3009. # Set the limit on the returned events in the timeline in the get
  3010. # and sync operations. The default value is 100. -1 means no upper limit.
  3011. #
  3012. # Uncomment the following to increase the limit to 5000.
  3013. #
  3014. #filter_timeline_limit: 5000
  3015. # Whether room invites to users on this server should be blocked
  3016. # (except those sent by local server admins). The default is False.
  3017. #
  3018. #block_non_admin_invites: true
  3019. # Room searching
  3020. #
  3021. # If disabled, new messages will not be indexed for searching and users
  3022. # will receive errors when searching for messages. Defaults to enabled.
  3023. #
  3024. #enable_search: false
  3025. # Prevent outgoing requests from being sent to the following blacklisted IP address
  3026. # CIDR ranges. If this option is not specified then it defaults to private IP
  3027. # address ranges (see the example below).
  3028. #
  3029. # The blacklist applies to the outbound requests for federation, identity servers,
  3030. # push servers, and for checking key validity for third-party invite events.
  3031. #
  3032. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3033. # listed here, since they correspond to unroutable addresses.)
  3034. #
  3035. # This option replaces federation_ip_range_blacklist in Synapse v1.25.0.
  3036. #
  3037. # Note: The value is ignored when an HTTP proxy is in use
  3038. #
  3039. #ip_range_blacklist:
  3040. # - '127.0.0.0/8'
  3041. # - '10.0.0.0/8'
  3042. # - '172.16.0.0/12'
  3043. # - '192.168.0.0/16'
  3044. # - '100.64.0.0/10'
  3045. # - '192.0.0.0/24'
  3046. # - '169.254.0.0/16'
  3047. # - '192.88.99.0/24'
  3048. # - '198.18.0.0/15'
  3049. # - '192.0.2.0/24'
  3050. # - '198.51.100.0/24'
  3051. # - '203.0.113.0/24'
  3052. # - '224.0.0.0/4'
  3053. # - '::1/128'
  3054. # - 'fe80::/10'
  3055. # - 'fc00::/7'
  3056. # - '2001:db8::/32'
  3057. # - 'ff00::/8'
  3058. # - 'fec0::/10'
  3059. # List of IP address CIDR ranges that should be allowed for federation,
  3060. # identity servers, push servers, and for checking key validity for
  3061. # third-party invite events. This is useful for specifying exceptions to
  3062. # wide-ranging blacklisted target IP ranges - e.g. for communication with
  3063. # a push server only visible in your network.
  3064. #
  3065. # This whitelist overrides ip_range_blacklist and defaults to an empty
  3066. # list.
  3067. #
  3068. #ip_range_whitelist:
  3069. # - '192.168.1.1'
  3070. # List of ports that Synapse should listen on, their purpose and their
  3071. # configuration.
  3072. #
  3073. # Options for each listener include:
  3074. #
  3075. # port: the TCP port to bind to
  3076. #
  3077. # bind_addresses: a list of local addresses to listen on. The default is
  3078. # 'all local interfaces'.
  3079. #
  3080. # type: the type of listener. Normally 'http', but other valid options are:
  3081. # 'manhole' (see https://matrix-org.github.io/synapse/latest/manhole.html),
  3082. # 'metrics' (see https://matrix-org.github.io/synapse/latest/metrics-howto.html),
  3083. # 'replication' (see https://matrix-org.github.io/synapse/latest/workers.html).
  3084. #
  3085. # tls: set to true to enable TLS for this listener. Will use the TLS
  3086. # key/cert specified in tls_private_key_path / tls_certificate_path.
  3087. #
  3088. # x_forwarded: Only valid for an 'http' listener. Set to true to use the
  3089. # X-Forwarded-For header as the client IP. Useful when Synapse is
  3090. # behind a reverse-proxy.
  3091. #
  3092. # resources: Only valid for an 'http' listener. A list of resources to host
  3093. # on this port. Options for each resource are:
  3094. #
  3095. # names: a list of names of HTTP resources. See below for a list of
  3096. # valid resource names.
  3097. #
  3098. # compress: set to true to enable HTTP compression for this resource.
  3099. #
  3100. # additional_resources: Only valid for an 'http' listener. A map of
  3101. # additional endpoints which should be loaded via dynamic modules.
  3102. #
  3103. # Valid resource names are:
  3104. #
  3105. # client: the client-server API (/_matrix/client), and the synapse admin
  3106. # API (/_synapse/admin). Also implies 'media' and 'static'.
  3107. #
  3108. # consent: user consent forms (/_matrix/consent).
  3109. # See https://matrix-org.github.io/synapse/latest/consent_tracking.html.
  3110. #
  3111. # federation: the server-server API (/_matrix/federation). Also implies
  3112. # 'media', 'keys', 'openid'
  3113. #
  3114. # keys: the key discovery API (/_matrix/keys).
  3115. #
  3116. # media: the media API (/_matrix/media).
  3117. #
  3118. # metrics: the metrics interface.
  3119. # See https://matrix-org.github.io/synapse/latest/metrics-howto.html.
  3120. #
  3121. # openid: OpenID authentication.
  3122. #
  3123. # replication: the HTTP replication API (/_synapse/replication).
  3124. # See https://matrix-org.github.io/synapse/latest/workers.html.
  3125. #
  3126. # static: static resources under synapse/static (/_matrix/static). (Mostly
  3127. # useful for 'fallback authentication'.)
  3128. #
  3129. # webclient: A web client. Requires web_client_location to be set.
  3130. #
  3131. listeners:
  3132. # TLS-enabled listener: for when matrix traffic is sent directly to synapse.
  3133. #
  3134. # Disabled by default. To enable it, uncomment the following. (Note that you
  3135. # will also need to give Synapse a TLS key and certificate: see the TLS section
  3136. # below.)
  3137. #
  3138. #- port: 8448
  3139. # type: http
  3140. # tls: true
  3141. # resources:
  3142. # - names: [client, federation]
  3143. # Unsecure HTTP listener: for when matrix traffic passes through a reverse proxy
  3144. # that unwraps TLS.
  3145. #
  3146. # If you plan to use a reverse proxy, please see
  3147. # https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3148. #
  3149. - port: 8008
  3150. tls: false
  3151. type: http
  3152. x_forwarded: true
  3153. bind_addresses: ['::1', '127.0.0.1']
  3154. resources:
  3155. - names: [client, federation]
  3156. compress: false
  3157. # example additional_resources:
  3158. #
  3159. #additional_resources:
  3160. # &quot;/_matrix/my/custom/endpoint&quot;:
  3161. # module: my_module.CustomRequestHandler
  3162. # config: {}
  3163. # Turn on the twisted ssh manhole service on localhost on the given
  3164. # port.
  3165. #
  3166. #- port: 9000
  3167. # bind_addresses: ['::1', '127.0.0.1']
  3168. # type: manhole
  3169. # Forward extremities can build up in a room due to networking delays between
  3170. # homeservers. Once this happens in a large room, calculation of the state of
  3171. # that room can become quite expensive. To mitigate this, once the number of
  3172. # forward extremities reaches a given threshold, Synapse will send an
  3173. # org.matrix.dummy_event event, which will reduce the forward extremities
  3174. # in the room.
  3175. #
  3176. # This setting defines the threshold (i.e. number of forward extremities in the
  3177. # room) at which dummy events are sent. The default value is 10.
  3178. #
  3179. #dummy_events_threshold: 5
  3180. ## Homeserver blocking ##
  3181. # How to reach the server admin, used in ResourceLimitError
  3182. #
  3183. #admin_contact: 'mailto:admin@server.com'
  3184. # Global blocking
  3185. #
  3186. #hs_disabled: false
  3187. #hs_disabled_message: 'Human readable reason for why the HS is blocked'
  3188. # Monthly Active User Blocking
  3189. #
  3190. # Used in cases where the admin or server owner wants to limit to the
  3191. # number of monthly active users.
  3192. #
  3193. # 'limit_usage_by_mau' disables/enables monthly active user blocking. When
  3194. # enabled and a limit is reached the server returns a 'ResourceLimitError'
  3195. # with error type Codes.RESOURCE_LIMIT_EXCEEDED
  3196. #
  3197. # 'max_mau_value' is the hard limit of monthly active users above which
  3198. # the server will start blocking user actions.
  3199. #
  3200. # 'mau_trial_days' is a means to add a grace period for active users. It
  3201. # means that users must be active for this number of days before they
  3202. # can be considered active and guards against the case where lots of users
  3203. # sign up in a short space of time never to return after their initial
  3204. # session.
  3205. #
  3206. # 'mau_limit_alerting' is a means of limiting client side alerting
  3207. # should the mau limit be reached. This is useful for small instances
  3208. # where the admin has 5 mau seats (say) for 5 specific people and no
  3209. # interest increasing the mau limit further. Defaults to True, which
  3210. # means that alerting is enabled
  3211. #
  3212. #limit_usage_by_mau: false
  3213. #max_mau_value: 50
  3214. #mau_trial_days: 2
  3215. #mau_limit_alerting: false
  3216. # If enabled, the metrics for the number of monthly active users will
  3217. # be populated, however no one will be limited. If limit_usage_by_mau
  3218. # is true, this is implied to be true.
  3219. #
  3220. #mau_stats_only: false
  3221. # Sometimes the server admin will want to ensure certain accounts are
  3222. # never blocked by mau checking. These accounts are specified here.
  3223. #
  3224. #mau_limit_reserved_threepids:
  3225. # - medium: 'email'
  3226. # address: 'reserved_user@example.com'
  3227. # Used by phonehome stats to group together related servers.
  3228. #server_context: context
  3229. # Resource-constrained homeserver settings
  3230. #
  3231. # When this is enabled, the room &quot;complexity&quot; will be checked before a user
  3232. # joins a new remote room. If it is above the complexity limit, the server will
  3233. # disallow joining, or will instantly leave.
  3234. #
  3235. # Room complexity is an arbitrary measure based on factors such as the number of
  3236. # users in the room.
  3237. #
  3238. limit_remote_rooms:
  3239. # Uncomment to enable room complexity checking.
  3240. #
  3241. #enabled: true
  3242. # the limit above which rooms cannot be joined. The default is 1.0.
  3243. #
  3244. #complexity: 0.5
  3245. # override the error which is returned when the room is too complex.
  3246. #
  3247. #complexity_error: &quot;This room is too complex.&quot;
  3248. # allow server admins to join complex rooms. Default is false.
  3249. #
  3250. #admins_can_join: true
  3251. # Whether to require a user to be in the room to add an alias to it.
  3252. # Defaults to 'true'.
  3253. #
  3254. #require_membership_for_aliases: false
  3255. # Whether to allow per-room membership profiles through the send of membership
  3256. # events with profile information that differ from the target's global profile.
  3257. # Defaults to 'true'.
  3258. #
  3259. #allow_per_room_profiles: false
  3260. # How long to keep redacted events in unredacted form in the database. After
  3261. # this period redacted events get replaced with their redacted form in the DB.
  3262. #
  3263. # Defaults to `7d`. Set to `null` to disable.
  3264. #
  3265. #redaction_retention_period: 28d
  3266. # How long to track users' last seen time and IPs in the database.
  3267. #
  3268. # Defaults to `28d`. Set to `null` to disable clearing out of old rows.
  3269. #
  3270. #user_ips_max_age: 14d
  3271. # Message retention policy at the server level.
  3272. #
  3273. # Room admins and mods can define a retention period for their rooms using the
  3274. # 'm.room.retention' state event, and server admins can cap this period by setting
  3275. # the 'allowed_lifetime_min' and 'allowed_lifetime_max' config options.
  3276. #
  3277. # If this feature is enabled, Synapse will regularly look for and purge events
  3278. # which are older than the room's maximum retention period. Synapse will also
  3279. # filter events received over federation so that events that should have been
  3280. # purged are ignored and not stored again.
  3281. #
  3282. retention:
  3283. # The message retention policies feature is disabled by default. Uncomment the
  3284. # following line to enable it.
  3285. #
  3286. #enabled: true
  3287. # Default retention policy. If set, Synapse will apply it to rooms that lack the
  3288. # 'm.room.retention' state event. Currently, the value of 'min_lifetime' doesn't
  3289. # matter much because Synapse doesn't take it into account yet.
  3290. #
  3291. #default_policy:
  3292. # min_lifetime: 1d
  3293. # max_lifetime: 1y
  3294. # Retention policy limits. If set, and the state of a room contains a
  3295. # 'm.room.retention' event in its state which contains a 'min_lifetime' or a
  3296. # 'max_lifetime' that's out of these bounds, Synapse will cap the room's policy
  3297. # to these limits when running purge jobs.
  3298. #
  3299. #allowed_lifetime_min: 1d
  3300. #allowed_lifetime_max: 1y
  3301. # Server admins can define the settings of the background jobs purging the
  3302. # events which lifetime has expired under the 'purge_jobs' section.
  3303. #
  3304. # If no configuration is provided, a single job will be set up to delete expired
  3305. # events in every room daily.
  3306. #
  3307. # Each job's configuration defines which range of message lifetimes the job
  3308. # takes care of. For example, if 'shortest_max_lifetime' is '2d' and
  3309. # 'longest_max_lifetime' is '3d', the job will handle purging expired events in
  3310. # rooms whose state defines a 'max_lifetime' that's both higher than 2 days, and
  3311. # lower than or equal to 3 days. Both the minimum and the maximum value of a
  3312. # range are optional, e.g. a job with no 'shortest_max_lifetime' and a
  3313. # 'longest_max_lifetime' of '3d' will handle every room with a retention policy
  3314. # which 'max_lifetime' is lower than or equal to three days.
  3315. #
  3316. # The rationale for this per-job configuration is that some rooms might have a
  3317. # retention policy with a low 'max_lifetime', where history needs to be purged
  3318. # of outdated messages on a more frequent basis than for the rest of the rooms
  3319. # (e.g. every 12h), but not want that purge to be performed by a job that's
  3320. # iterating over every room it knows, which could be heavy on the server.
  3321. #
  3322. # If any purge job is configured, it is strongly recommended to have at least
  3323. # a single job with neither 'shortest_max_lifetime' nor 'longest_max_lifetime'
  3324. # set, or one job without 'shortest_max_lifetime' and one job without
  3325. # 'longest_max_lifetime' set. Otherwise some rooms might be ignored, even if
  3326. # 'allowed_lifetime_min' and 'allowed_lifetime_max' are set, because capping a
  3327. # room's policy to these values is done after the policies are retrieved from
  3328. # Synapse's database (which is done using the range specified in a purge job's
  3329. # configuration).
  3330. #
  3331. #purge_jobs:
  3332. # - longest_max_lifetime: 3d
  3333. # interval: 12h
  3334. # - shortest_max_lifetime: 3d
  3335. # interval: 1d
  3336. # Inhibits the /requestToken endpoints from returning an error that might leak
  3337. # information about whether an e-mail address is in use or not on this
  3338. # homeserver.
  3339. # Note that for some endpoints the error situation is the e-mail already being
  3340. # used, and for others the error is entering the e-mail being unused.
  3341. # If this option is enabled, instead of returning an error, these endpoints will
  3342. # act as if no error happened and return a fake session ID ('sid') to clients.
  3343. #
  3344. #request_token_inhibit_3pid_errors: true
  3345. # A list of domains that the domain portion of 'next_link' parameters
  3346. # must match.
  3347. #
  3348. # This parameter is optionally provided by clients while requesting
  3349. # validation of an email or phone number, and maps to a link that
  3350. # users will be automatically redirected to after validation
  3351. # succeeds. Clients can make use this parameter to aid the validation
  3352. # process.
  3353. #
  3354. # The whitelist is applied whether the homeserver or an
  3355. # identity server is handling validation.
  3356. #
  3357. # The default value is no whitelist functionality; all domains are
  3358. # allowed. Setting this value to an empty list will instead disallow
  3359. # all domains.
  3360. #
  3361. #next_link_domain_whitelist: [&quot;matrix.org&quot;]
  3362. # Templates to use when generating email or HTML page contents.
  3363. #
  3364. templates:
  3365. # Directory in which Synapse will try to find template files to use to generate
  3366. # email or HTML page contents.
  3367. # If not set, or a file is not found within the template directory, a default
  3368. # template from within the Synapse package will be used.
  3369. #
  3370. # See https://matrix-org.github.io/synapse/latest/templates.html for more
  3371. # information about using custom templates.
  3372. #
  3373. #custom_template_directory: /path/to/custom/templates/
  3374. ## TLS ##
  3375. # PEM-encoded X509 certificate for TLS.
  3376. # This certificate, as of Synapse 1.0, will need to be a valid and verifiable
  3377. # certificate, signed by a recognised Certificate Authority.
  3378. #
  3379. # Be sure to use a `.pem` file that includes the full certificate chain including
  3380. # any intermediate certificates (for instance, if using certbot, use
  3381. # `fullchain.pem` as your certificate, not `cert.pem`).
  3382. #
  3383. #tls_certificate_path: &quot;CONFDIR/SERVERNAME.tls.crt&quot;
  3384. # PEM-encoded private key for TLS
  3385. #
  3386. #tls_private_key_path: &quot;CONFDIR/SERVERNAME.tls.key&quot;
  3387. # Whether to verify TLS server certificates for outbound federation requests.
  3388. #
  3389. # Defaults to `true`. To disable certificate verification, uncomment the
  3390. # following line.
  3391. #
  3392. #federation_verify_certificates: false
  3393. # The minimum TLS version that will be used for outbound federation requests.
  3394. #
  3395. # Defaults to `1`. Configurable to `1`, `1.1`, `1.2`, or `1.3`. Note
  3396. # that setting this value higher than `1.2` will prevent federation to most
  3397. # of the public Matrix network: only configure it to `1.3` if you have an
  3398. # entirely private federation setup and you can ensure TLS 1.3 support.
  3399. #
  3400. #federation_client_minimum_tls_version: 1.2
  3401. # Skip federation certificate verification on the following whitelist
  3402. # of domains.
  3403. #
  3404. # This setting should only be used in very specific cases, such as
  3405. # federation over Tor hidden services and similar. For private networks
  3406. # of homeservers, you likely want to use a private CA instead.
  3407. #
  3408. # Only effective if federation_verify_certicates is `true`.
  3409. #
  3410. #federation_certificate_verification_whitelist:
  3411. # - lon.example.com
  3412. # - *.domain.com
  3413. # - *.onion
  3414. # List of custom certificate authorities for federation traffic.
  3415. #
  3416. # This setting should only normally be used within a private network of
  3417. # homeservers.
  3418. #
  3419. # Note that this list will replace those that are provided by your
  3420. # operating environment. Certificates must be in PEM format.
  3421. #
  3422. #federation_custom_ca_list:
  3423. # - myCA1.pem
  3424. # - myCA2.pem
  3425. # - myCA3.pem
  3426. ## Federation ##
  3427. # Restrict federation to the following whitelist of domains.
  3428. # N.B. we recommend also firewalling your federation listener to limit
  3429. # inbound federation traffic as early as possible, rather than relying
  3430. # purely on this application-layer restriction. If not specified, the
  3431. # default is to whitelist everything.
  3432. #
  3433. #federation_domain_whitelist:
  3434. # - lon.example.com
  3435. # - nyc.example.com
  3436. # - syd.example.com
  3437. # Report prometheus metrics on the age of PDUs being sent to and received from
  3438. # the following domains. This can be used to give an idea of &quot;delay&quot; on inbound
  3439. # and outbound federation, though be aware that any delay can be due to problems
  3440. # at either end or with the intermediate network.
  3441. #
  3442. # By default, no domains are monitored in this way.
  3443. #
  3444. #federation_metrics_domains:
  3445. # - matrix.org
  3446. # - example.com
  3447. # Uncomment to disable profile lookup over federation. By default, the
  3448. # Federation API allows other homeservers to obtain profile data of any user
  3449. # on this homeserver. Defaults to 'true'.
  3450. #
  3451. #allow_profile_lookup_over_federation: false
  3452. # Uncomment to disable device display name lookup over federation. By default, the
  3453. # Federation API allows other homeservers to obtain device display names of any user
  3454. # on this homeserver. Defaults to 'true'.
  3455. #
  3456. #allow_device_name_lookup_over_federation: false
  3457. ## Caching ##
  3458. # Caching can be configured through the following options.
  3459. #
  3460. # A cache 'factor' is a multiplier that can be applied to each of
  3461. # Synapse's caches in order to increase or decrease the maximum
  3462. # number of entries that can be stored.
  3463. # The number of events to cache in memory. Not affected by
  3464. # caches.global_factor.
  3465. #
  3466. #event_cache_size: 10K
  3467. caches:
  3468. # Controls the global cache factor, which is the default cache factor
  3469. # for all caches if a specific factor for that cache is not otherwise
  3470. # set.
  3471. #
  3472. # This can also be set by the &quot;SYNAPSE_CACHE_FACTOR&quot; environment
  3473. # variable. Setting by environment variable takes priority over
  3474. # setting through the config file.
  3475. #
  3476. # Defaults to 0.5, which will half the size of all caches.
  3477. #
  3478. #global_factor: 1.0
  3479. # A dictionary of cache name to cache factor for that individual
  3480. # cache. Overrides the global cache factor for a given cache.
  3481. #
  3482. # These can also be set through environment variables comprised
  3483. # of &quot;SYNAPSE_CACHE_FACTOR_&quot; + the name of the cache in capital
  3484. # letters and underscores. Setting by environment variable
  3485. # takes priority over setting through the config file.
  3486. # Ex. SYNAPSE_CACHE_FACTOR_GET_USERS_WHO_SHARE_ROOM_WITH_USER=2.0
  3487. #
  3488. # Some caches have '*' and other characters that are not
  3489. # alphanumeric or underscores. These caches can be named with or
  3490. # without the special characters stripped. For example, to specify
  3491. # the cache factor for `*stateGroupCache*` via an environment
  3492. # variable would be `SYNAPSE_CACHE_FACTOR_STATEGROUPCACHE=2.0`.
  3493. #
  3494. per_cache_factors:
  3495. #get_users_who_share_room_with_user: 2.0
  3496. # Controls how long an entry can be in a cache without having been
  3497. # accessed before being evicted. Defaults to None, which means
  3498. # entries are never evicted based on time.
  3499. #
  3500. #expiry_time: 30m
  3501. # Controls how long the results of a /sync request are cached for after
  3502. # a successful response is returned. A higher duration can help clients with
  3503. # intermittent connections, at the cost of higher memory usage.
  3504. #
  3505. # By default, this is zero, which means that sync responses are not cached
  3506. # at all.
  3507. #
  3508. #sync_response_cache_duration: 2m
  3509. ## Database ##
  3510. # The 'database' setting defines the database that synapse uses to store all of
  3511. # its data.
  3512. #
  3513. # 'name' gives the database engine to use: either 'sqlite3' (for SQLite) or
  3514. # 'psycopg2' (for PostgreSQL).
  3515. #
  3516. # 'txn_limit' gives the maximum number of transactions to run per connection
  3517. # before reconnecting. Defaults to 0, which means no limit.
  3518. #
  3519. # 'args' gives options which are passed through to the database engine,
  3520. # except for options starting 'cp_', which are used to configure the Twisted
  3521. # connection pool. For a reference to valid arguments, see:
  3522. # * for sqlite: https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
  3523. # * for postgres: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
  3524. # * for the connection pool: https://twistedmatrix.com/documents/current/api/twisted.enterprise.adbapi.ConnectionPool.html#__init__
  3525. #
  3526. #
  3527. # Example SQLite configuration:
  3528. #
  3529. #database:
  3530. # name: sqlite3
  3531. # args:
  3532. # database: /path/to/homeserver.db
  3533. #
  3534. #
  3535. # Example Postgres configuration:
  3536. #
  3537. #database:
  3538. # name: psycopg2
  3539. # txn_limit: 10000
  3540. # args:
  3541. # user: synapse_user
  3542. # password: secretpassword
  3543. # database: synapse
  3544. # host: localhost
  3545. # port: 5432
  3546. # cp_min: 5
  3547. # cp_max: 10
  3548. #
  3549. # For more information on using Synapse with Postgres,
  3550. # see https://matrix-org.github.io/synapse/latest/postgres.html.
  3551. #
  3552. database:
  3553. name: sqlite3
  3554. args:
  3555. database: DATADIR/homeserver.db
  3556. ## Logging ##
  3557. # A yaml python logging config file as described by
  3558. # https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  3559. #
  3560. log_config: &quot;CONFDIR/SERVERNAME.log.config&quot;
  3561. ## Ratelimiting ##
  3562. # Ratelimiting settings for client actions (registration, login, messaging).
  3563. #
  3564. # Each ratelimiting configuration is made of two parameters:
  3565. # - per_second: number of requests a client can send per second.
  3566. # - burst_count: number of requests a client can send before being throttled.
  3567. #
  3568. # Synapse currently uses the following configurations:
  3569. # - one for messages that ratelimits sending based on the account the client
  3570. # is using
  3571. # - one for registration that ratelimits registration requests based on the
  3572. # client's IP address.
  3573. # - one for checking the validity of registration tokens that ratelimits
  3574. # requests based on the client's IP address.
  3575. # - one for login that ratelimits login requests based on the client's IP
  3576. # address.
  3577. # - one for login that ratelimits login requests based on the account the
  3578. # client is attempting to log into.
  3579. # - one for login that ratelimits login requests based on the account the
  3580. # client is attempting to log into, based on the amount of failed login
  3581. # attempts for this account.
  3582. # - one for ratelimiting redactions by room admins. If this is not explicitly
  3583. # set then it uses the same ratelimiting as per rc_message. This is useful
  3584. # to allow room admins to deal with abuse quickly.
  3585. # - two for ratelimiting number of rooms a user can join, &quot;local&quot; for when
  3586. # users are joining rooms the server is already in (this is cheap) vs
  3587. # &quot;remote&quot; for when users are trying to join rooms not on the server (which
  3588. # can be more expensive)
  3589. # - one for ratelimiting how often a user or IP can attempt to validate a 3PID.
  3590. # - two for ratelimiting how often invites can be sent in a room or to a
  3591. # specific user.
  3592. #
  3593. # The defaults are as shown below.
  3594. #
  3595. #rc_message:
  3596. # per_second: 0.2
  3597. # burst_count: 10
  3598. #
  3599. #rc_registration:
  3600. # per_second: 0.17
  3601. # burst_count: 3
  3602. #
  3603. #rc_registration_token_validity:
  3604. # per_second: 0.1
  3605. # burst_count: 5
  3606. #
  3607. #rc_login:
  3608. # address:
  3609. # per_second: 0.17
  3610. # burst_count: 3
  3611. # account:
  3612. # per_second: 0.17
  3613. # burst_count: 3
  3614. # failed_attempts:
  3615. # per_second: 0.17
  3616. # burst_count: 3
  3617. #
  3618. #rc_admin_redaction:
  3619. # per_second: 1
  3620. # burst_count: 50
  3621. #
  3622. #rc_joins:
  3623. # local:
  3624. # per_second: 0.1
  3625. # burst_count: 10
  3626. # remote:
  3627. # per_second: 0.01
  3628. # burst_count: 10
  3629. #
  3630. #rc_3pid_validation:
  3631. # per_second: 0.003
  3632. # burst_count: 5
  3633. #
  3634. #rc_invites:
  3635. # per_room:
  3636. # per_second: 0.3
  3637. # burst_count: 10
  3638. # per_user:
  3639. # per_second: 0.003
  3640. # burst_count: 5
  3641. # Ratelimiting settings for incoming federation
  3642. #
  3643. # The rc_federation configuration is made up of the following settings:
  3644. # - window_size: window size in milliseconds
  3645. # - sleep_limit: number of federation requests from a single server in
  3646. # a window before the server will delay processing the request.
  3647. # - sleep_delay: duration in milliseconds to delay processing events
  3648. # from remote servers by if they go over the sleep limit.
  3649. # - reject_limit: maximum number of concurrent federation requests
  3650. # allowed from a single server
  3651. # - concurrent: number of federation requests to concurrently process
  3652. # from a single server
  3653. #
  3654. # The defaults are as shown below.
  3655. #
  3656. #rc_federation:
  3657. # window_size: 1000
  3658. # sleep_limit: 10
  3659. # sleep_delay: 500
  3660. # reject_limit: 50
  3661. # concurrent: 3
  3662. # Target outgoing federation transaction frequency for sending read-receipts,
  3663. # per-room.
  3664. #
  3665. # If we end up trying to send out more read-receipts, they will get buffered up
  3666. # into fewer transactions.
  3667. #
  3668. #federation_rr_transactions_per_room_per_second: 50
  3669. ## Media Store ##
  3670. # Enable the media store service in the Synapse master. Uncomment the
  3671. # following if you are using a separate media store worker.
  3672. #
  3673. #enable_media_repo: false
  3674. # Directory where uploaded images and attachments are stored.
  3675. #
  3676. media_store_path: &quot;DATADIR/media_store&quot;
  3677. # Media storage providers allow media to be stored in different
  3678. # locations.
  3679. #
  3680. #media_storage_providers:
  3681. # - module: file_system
  3682. # # Whether to store newly uploaded local files
  3683. # store_local: false
  3684. # # Whether to store newly downloaded remote files
  3685. # store_remote: false
  3686. # # Whether to wait for successful storage for local uploads
  3687. # store_synchronous: false
  3688. # config:
  3689. # directory: /mnt/some/other/directory
  3690. # The largest allowed upload size in bytes
  3691. #
  3692. # If you are using a reverse proxy you may also need to set this value in
  3693. # your reverse proxy's config. Notably Nginx has a small max body size by default.
  3694. # See https://matrix-org.github.io/synapse/latest/reverse_proxy.html.
  3695. #
  3696. #max_upload_size: 50M
  3697. # Maximum number of pixels that will be thumbnailed
  3698. #
  3699. #max_image_pixels: 32M
  3700. # Whether to generate new thumbnails on the fly to precisely match
  3701. # the resolution requested by the client. If true then whenever
  3702. # a new resolution is requested by the client the server will
  3703. # generate a new thumbnail. If false the server will pick a thumbnail
  3704. # from a precalculated list.
  3705. #
  3706. #dynamic_thumbnails: false
  3707. # List of thumbnails to precalculate when an image is uploaded.
  3708. #
  3709. #thumbnail_sizes:
  3710. # - width: 32
  3711. # height: 32
  3712. # method: crop
  3713. # - width: 96
  3714. # height: 96
  3715. # method: crop
  3716. # - width: 320
  3717. # height: 240
  3718. # method: scale
  3719. # - width: 640
  3720. # height: 480
  3721. # method: scale
  3722. # - width: 800
  3723. # height: 600
  3724. # method: scale
  3725. # Is the preview URL API enabled?
  3726. #
  3727. # 'false' by default: uncomment the following to enable it (and specify a
  3728. # url_preview_ip_range_blacklist blacklist).
  3729. #
  3730. #url_preview_enabled: true
  3731. # List of IP address CIDR ranges that the URL preview spider is denied
  3732. # from accessing. There are no defaults: you must explicitly
  3733. # specify a list for URL previewing to work. You should specify any
  3734. # internal services in your network that you do not want synapse to try
  3735. # to connect to, otherwise anyone in any Matrix room could cause your
  3736. # synapse to issue arbitrary GET requests to your internal services,
  3737. # causing serious security issues.
  3738. #
  3739. # (0.0.0.0 and :: are always blacklisted, whether or not they are explicitly
  3740. # listed here, since they correspond to unroutable addresses.)
  3741. #
  3742. # This must be specified if url_preview_enabled is set. It is recommended that
  3743. # you uncomment the following list as a starting point.
  3744. #
  3745. # Note: The value is ignored when an HTTP proxy is in use
  3746. #
  3747. #url_preview_ip_range_blacklist:
  3748. # - '127.0.0.0/8'
  3749. # - '10.0.0.0/8'
  3750. # - '172.16.0.0/12'
  3751. # - '192.168.0.0/16'
  3752. # - '100.64.0.0/10'
  3753. # - '192.0.0.0/24'
  3754. # - '169.254.0.0/16'
  3755. # - '192.88.99.0/24'
  3756. # - '198.18.0.0/15'
  3757. # - '192.0.2.0/24'
  3758. # - '198.51.100.0/24'
  3759. # - '203.0.113.0/24'
  3760. # - '224.0.0.0/4'
  3761. # - '::1/128'
  3762. # - 'fe80::/10'
  3763. # - 'fc00::/7'
  3764. # - '2001:db8::/32'
  3765. # - 'ff00::/8'
  3766. # - 'fec0::/10'
  3767. # List of IP address CIDR ranges that the URL preview spider is allowed
  3768. # to access even if they are specified in url_preview_ip_range_blacklist.
  3769. # This is useful for specifying exceptions to wide-ranging blacklisted
  3770. # target IP ranges - e.g. for enabling URL previews for a specific private
  3771. # website only visible in your network.
  3772. #
  3773. #url_preview_ip_range_whitelist:
  3774. # - '192.168.1.1'
  3775. # Optional list of URL matches that the URL preview spider is
  3776. # denied from accessing. You should use url_preview_ip_range_blacklist
  3777. # in preference to this, otherwise someone could define a public DNS
  3778. # entry that points to a private IP address and circumvent the blacklist.
  3779. # This is more useful if you know there is an entire shape of URL that
  3780. # you know that will never want synapse to try to spider.
  3781. #
  3782. # Each list entry is a dictionary of url component attributes as returned
  3783. # by urlparse.urlsplit as applied to the absolute form of the URL. See
  3784. # https://docs.python.org/2/library/urlparse.html#urlparse.urlsplit
  3785. # The values of the dictionary are treated as an filename match pattern
  3786. # applied to that component of URLs, unless they start with a ^ in which
  3787. # case they are treated as a regular expression match. If all the
  3788. # specified component matches for a given list item succeed, the URL is
  3789. # blacklisted.
  3790. #
  3791. #url_preview_url_blacklist:
  3792. # # blacklist any URL with a username in its URI
  3793. # - username: '*'
  3794. #
  3795. # # blacklist all *.google.com URLs
  3796. # - netloc: 'google.com'
  3797. # - netloc: '*.google.com'
  3798. #
  3799. # # blacklist all plain HTTP URLs
  3800. # - scheme: 'http'
  3801. #
  3802. # # blacklist http(s)://www.acme.com/foo
  3803. # - netloc: 'www.acme.com'
  3804. # path: '/foo'
  3805. #
  3806. # # blacklist any URL with a literal IPv4 address
  3807. # - netloc: '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  3808. # The largest allowed URL preview spidering size in bytes
  3809. #
  3810. #max_spider_size: 10M
  3811. # A list of values for the Accept-Language HTTP header used when
  3812. # downloading webpages during URL preview generation. This allows
  3813. # Synapse to specify the preferred languages that URL previews should
  3814. # be in when communicating with remote servers.
  3815. #
  3816. # Each value is a IETF language tag; a 2-3 letter identifier for a
  3817. # language, optionally followed by subtags separated by '-', specifying
  3818. # a country or region variant.
  3819. #
  3820. # Multiple values can be provided, and a weight can be added to each by
  3821. # using quality value syntax (;q=). '*' translates to any language.
  3822. #
  3823. # Defaults to &quot;en&quot;.
  3824. #
  3825. # Example:
  3826. #
  3827. # url_preview_accept_language:
  3828. # - en-UK
  3829. # - en-US;q=0.9
  3830. # - fr;q=0.8
  3831. # - *;q=0.7
  3832. #
  3833. url_preview_accept_language:
  3834. # - en
  3835. ## Captcha ##
  3836. # See docs/CAPTCHA_SETUP.md for full details of configuring this.
  3837. # This homeserver's ReCAPTCHA public key. Must be specified if
  3838. # enable_registration_captcha is enabled.
  3839. #
  3840. #recaptcha_public_key: &quot;YOUR_PUBLIC_KEY&quot;
  3841. # This homeserver's ReCAPTCHA private key. Must be specified if
  3842. # enable_registration_captcha is enabled.
  3843. #
  3844. #recaptcha_private_key: &quot;YOUR_PRIVATE_KEY&quot;
  3845. # Uncomment to enable ReCaptcha checks when registering, preventing signup
  3846. # unless a captcha is answered. Requires a valid ReCaptcha
  3847. # public/private key. Defaults to 'false'.
  3848. #
  3849. #enable_registration_captcha: true
  3850. # The API endpoint to use for verifying m.login.recaptcha responses.
  3851. # Defaults to &quot;https://www.recaptcha.net/recaptcha/api/siteverify&quot;.
  3852. #
  3853. #recaptcha_siteverify_api: &quot;https://my.recaptcha.site&quot;
  3854. ## TURN ##
  3855. # The public URIs of the TURN server to give to clients
  3856. #
  3857. #turn_uris: []
  3858. # The shared secret used to compute passwords for the TURN server
  3859. #
  3860. #turn_shared_secret: &quot;YOUR_SHARED_SECRET&quot;
  3861. # The Username and password if the TURN server needs them and
  3862. # does not use a token
  3863. #
  3864. #turn_username: &quot;TURNSERVER_USERNAME&quot;
  3865. #turn_password: &quot;TURNSERVER_PASSWORD&quot;
  3866. # How long generated TURN credentials last
  3867. #
  3868. #turn_user_lifetime: 1h
  3869. # Whether guests should be allowed to use the TURN server.
  3870. # This defaults to True, otherwise VoIP will be unreliable for guests.
  3871. # However, it does introduce a slight security risk as it allows users to
  3872. # connect to arbitrary endpoints without having first signed up for a
  3873. # valid account (e.g. by passing a CAPTCHA).
  3874. #
  3875. #turn_allow_guests: true
  3876. ## Registration ##
  3877. #
  3878. # Registration can be rate-limited using the parameters in the &quot;Ratelimiting&quot;
  3879. # section of this file.
  3880. # Enable registration for new users.
  3881. #
  3882. #enable_registration: false
  3883. # Time that a user's session remains valid for, after they log in.
  3884. #
  3885. # Note that this is not currently compatible with guest logins.
  3886. #
  3887. # Note also that this is calculated at login time: changes are not applied
  3888. # retrospectively to users who have already logged in.
  3889. #
  3890. # By default, this is infinite.
  3891. #
  3892. #session_lifetime: 24h
  3893. # The user must provide all of the below types of 3PID when registering.
  3894. #
  3895. #registrations_require_3pid:
  3896. # - email
  3897. # - msisdn
  3898. # Explicitly disable asking for MSISDNs from the registration
  3899. # flow (overrides registrations_require_3pid if MSISDNs are set as required)
  3900. #
  3901. #disable_msisdn_registration: true
  3902. # Mandate that users are only allowed to associate certain formats of
  3903. # 3PIDs with accounts on this server.
  3904. #
  3905. #allowed_local_3pids:
  3906. # - medium: email
  3907. # pattern: '^[^@]+@matrix\.org$'
  3908. # - medium: email
  3909. # pattern: '^[^@]+@vector\.im$'
  3910. # - medium: msisdn
  3911. # pattern: '\+44'
  3912. # Enable 3PIDs lookup requests to identity servers from this server.
  3913. #
  3914. #enable_3pid_lookup: true
  3915. # Require users to submit a token during registration.
  3916. # Tokens can be managed using the admin API:
  3917. # https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/registration_tokens.html
  3918. # Note that `enable_registration` must be set to `true`.
  3919. # Disabling this option will not delete any tokens previously generated.
  3920. # Defaults to false. Uncomment the following to require tokens:
  3921. #
  3922. #registration_requires_token: true
  3923. # If set, allows registration of standard or admin accounts by anyone who
  3924. # has the shared secret, even if registration is otherwise disabled.
  3925. #
  3926. #registration_shared_secret: &lt;PRIVATE STRING&gt;
  3927. # Set the number of bcrypt rounds used to generate password hash.
  3928. # Larger numbers increase the work factor needed to generate the hash.
  3929. # The default number is 12 (which equates to 2^12 rounds).
  3930. # N.B. that increasing this will exponentially increase the time required
  3931. # to register or login - e.g. 24 =&gt; 2^24 rounds which will take &gt;20 mins.
  3932. #
  3933. #bcrypt_rounds: 12
  3934. # Allows users to register as guests without a password/email/etc, and
  3935. # participate in rooms hosted on this server which have been made
  3936. # accessible to anonymous users.
  3937. #
  3938. #allow_guest_access: false
  3939. # The identity server which we suggest that clients should use when users log
  3940. # in on this server.
  3941. #
  3942. # (By default, no suggestion is made, so it is left up to the client.
  3943. # This setting is ignored unless public_baseurl is also set.)
  3944. #
  3945. #default_identity_server: https://matrix.org
  3946. # Handle threepid (email/phone etc) registration and password resets through a set of
  3947. # *trusted* identity servers. Note that this allows the configured identity server to
  3948. # reset passwords for accounts!
  3949. #
  3950. # Be aware that if `email` is not set, and SMTP options have not been
  3951. # configured in the email config block, registration and user password resets via
  3952. # email will be globally disabled.
  3953. #
  3954. # Additionally, if `msisdn` is not set, registration and password resets via msisdn
  3955. # will be disabled regardless, and users will not be able to associate an msisdn
  3956. # identifier to their account. This is due to Synapse currently not supporting
  3957. # any method of sending SMS messages on its own.
  3958. #
  3959. # To enable using an identity server for operations regarding a particular third-party
  3960. # identifier type, set the value to the URL of that identity server as shown in the
  3961. # examples below.
  3962. #
  3963. # Servers handling the these requests must answer the `/requestToken` endpoints defined
  3964. # by the Matrix Identity Service API specification:
  3965. # https://matrix.org/docs/spec/identity_service/latest
  3966. #
  3967. # If a delegate is specified, the config option public_baseurl must also be filled out.
  3968. #
  3969. account_threepid_delegates:
  3970. #email: https://example.com # Delegate email sending to example.com
  3971. #msisdn: http://localhost:8090 # Delegate SMS sending to this local process
  3972. # Whether users are allowed to change their displayname after it has
  3973. # been initially set. Useful when provisioning users based on the
  3974. # contents of a third-party directory.
  3975. #
  3976. # Does not apply to server administrators. Defaults to 'true'
  3977. #
  3978. #enable_set_displayname: false
  3979. # Whether users are allowed to change their avatar after it has been
  3980. # initially set. Useful when provisioning users based on the contents
  3981. # of a third-party directory.
  3982. #
  3983. # Does not apply to server administrators. Defaults to 'true'
  3984. #
  3985. #enable_set_avatar_url: false
  3986. # Whether users can change the 3PIDs associated with their accounts
  3987. # (email address and msisdn).
  3988. #
  3989. # Defaults to 'true'
  3990. #
  3991. #enable_3pid_changes: false
  3992. # Users who register on this homeserver will automatically be joined
  3993. # to these rooms.
  3994. #
  3995. # By default, any room aliases included in this list will be created
  3996. # as a publicly joinable room when the first user registers for the
  3997. # homeserver. This behaviour can be customised with the settings below.
  3998. # If the room already exists, make certain it is a publicly joinable
  3999. # room. The join rule of the room must be set to 'public'.
  4000. #
  4001. #auto_join_rooms:
  4002. # - &quot;#example:example.com&quot;
  4003. # Where auto_join_rooms are specified, setting this flag ensures that the
  4004. # the rooms exist by creating them when the first user on the
  4005. # homeserver registers.
  4006. #
  4007. # By default the auto-created rooms are publicly joinable from any federated
  4008. # server. Use the autocreate_auto_join_rooms_federated and
  4009. # autocreate_auto_join_room_preset settings below to customise this behaviour.
  4010. #
  4011. # Setting to false means that if the rooms are not manually created,
  4012. # users cannot be auto-joined since they do not exist.
  4013. #
  4014. # Defaults to true. Uncomment the following line to disable automatically
  4015. # creating auto-join rooms.
  4016. #
  4017. #autocreate_auto_join_rooms: false
  4018. # Whether the auto_join_rooms that are auto-created are available via
  4019. # federation. Only has an effect if autocreate_auto_join_rooms is true.
  4020. #
  4021. # Note that whether a room is federated cannot be modified after
  4022. # creation.
  4023. #
  4024. # Defaults to true: the room will be joinable from other servers.
  4025. # Uncomment the following to prevent users from other homeservers from
  4026. # joining these rooms.
  4027. #
  4028. #autocreate_auto_join_rooms_federated: false
  4029. # The room preset to use when auto-creating one of auto_join_rooms. Only has an
  4030. # effect if autocreate_auto_join_rooms is true.
  4031. #
  4032. # This can be one of &quot;public_chat&quot;, &quot;private_chat&quot;, or &quot;trusted_private_chat&quot;.
  4033. # If a value of &quot;private_chat&quot; or &quot;trusted_private_chat&quot; is used then
  4034. # auto_join_mxid_localpart must also be configured.
  4035. #
  4036. # Defaults to &quot;public_chat&quot;, meaning that the room is joinable by anyone, including
  4037. # federated servers if autocreate_auto_join_rooms_federated is true (the default).
  4038. # Uncomment the following to require an invitation to join these rooms.
  4039. #
  4040. #autocreate_auto_join_room_preset: private_chat
  4041. # The local part of the user id which is used to create auto_join_rooms if
  4042. # autocreate_auto_join_rooms is true. If this is not provided then the
  4043. # initial user account that registers will be used to create the rooms.
  4044. #
  4045. # The user id is also used to invite new users to any auto-join rooms which
  4046. # are set to invite-only.
  4047. #
  4048. # It *must* be configured if autocreate_auto_join_room_preset is set to
  4049. # &quot;private_chat&quot; or &quot;trusted_private_chat&quot;.
  4050. #
  4051. # Note that this must be specified in order for new users to be correctly
  4052. # invited to any auto-join rooms which have been set to invite-only (either
  4053. # at the time of creation or subsequently).
  4054. #
  4055. # Note that, if the room already exists, this user must be joined and
  4056. # have the appropriate permissions to invite new members.
  4057. #
  4058. #auto_join_mxid_localpart: system
  4059. # When auto_join_rooms is specified, setting this flag to false prevents
  4060. # guest accounts from being automatically joined to the rooms.
  4061. #
  4062. # Defaults to true.
  4063. #
  4064. #auto_join_rooms_for_guests: false
  4065. ## Metrics ###
  4066. # Enable collection and rendering of performance metrics
  4067. #
  4068. #enable_metrics: false
  4069. # Enable sentry integration
  4070. # NOTE: While attempts are made to ensure that the logs don't contain
  4071. # any sensitive information, this cannot be guaranteed. By enabling
  4072. # this option the sentry server may therefore receive sensitive
  4073. # information, and it in turn may then diseminate sensitive information
  4074. # through insecure notification channels if so configured.
  4075. #
  4076. #sentry:
  4077. # dsn: &quot;...&quot;
  4078. # Flags to enable Prometheus metrics which are not suitable to be
  4079. # enabled by default, either for performance reasons or limited use.
  4080. #
  4081. metrics_flags:
  4082. # Publish synapse_federation_known_servers, a gauge of the number of
  4083. # servers this homeserver knows about, including itself. May cause
  4084. # performance problems on large homeservers.
  4085. #
  4086. #known_servers: true
  4087. # Whether or not to report anonymized homeserver usage statistics.
  4088. #
  4089. #report_stats: true|false
  4090. # The endpoint to report the anonymized homeserver usage statistics to.
  4091. # Defaults to https://matrix.org/report-usage-stats/push
  4092. #
  4093. #report_stats_endpoint: https://example.com/report-usage-stats/push
  4094. ## API Configuration ##
  4095. # Controls for the state that is shared with users who receive an invite
  4096. # to a room
  4097. #
  4098. room_prejoin_state:
  4099. # By default, the following state event types are shared with users who
  4100. # receive invites to the room:
  4101. #
  4102. # - m.room.join_rules
  4103. # - m.room.canonical_alias
  4104. # - m.room.avatar
  4105. # - m.room.encryption
  4106. # - m.room.name
  4107. # - m.room.create
  4108. #
  4109. # Uncomment the following to disable these defaults (so that only the event
  4110. # types listed in 'additional_event_types' are shared). Defaults to 'false'.
  4111. #
  4112. #disable_default_event_types: true
  4113. # Additional state event types to share with users when they are invited
  4114. # to a room.
  4115. #
  4116. # By default, this list is empty (so only the default event types are shared).
  4117. #
  4118. #additional_event_types:
  4119. # - org.example.custom.event.type
  4120. # A list of application service config files to use
  4121. #
  4122. #app_service_config_files:
  4123. # - app_service_1.yaml
  4124. # - app_service_2.yaml
  4125. # Uncomment to enable tracking of application service IP addresses. Implicitly
  4126. # enables MAU tracking for application service users.
  4127. #
  4128. #track_appservice_user_ips: true
  4129. # a secret which is used to sign access tokens. If none is specified,
  4130. # the registration_shared_secret is used, if one is given; otherwise,
  4131. # a secret key is derived from the signing key.
  4132. #
  4133. #macaroon_secret_key: &lt;PRIVATE STRING&gt;
  4134. # a secret which is used to calculate HMACs for form values, to stop
  4135. # falsification of values. Must be specified for the User Consent
  4136. # forms to work.
  4137. #
  4138. #form_secret: &lt;PRIVATE STRING&gt;
  4139. ## Signing Keys ##
  4140. # Path to the signing key to sign messages with
  4141. #
  4142. signing_key_path: &quot;CONFDIR/SERVERNAME.signing.key&quot;
  4143. # The keys that the server used to sign messages with but won't use
  4144. # to sign new messages.
  4145. #
  4146. old_signing_keys:
  4147. # For each key, `key` should be the base64-encoded public key, and
  4148. # `expired_ts`should be the time (in milliseconds since the unix epoch) that
  4149. # it was last used.
  4150. #
  4151. # It is possible to build an entry from an old signing.key file using the
  4152. # `export_signing_key` script which is provided with synapse.
  4153. #
  4154. # For example:
  4155. #
  4156. #&quot;ed25519:id&quot;: { key: &quot;base64string&quot;, expired_ts: 123456789123 }
  4157. # How long key response published by this server is valid for.
  4158. # Used to set the valid_until_ts in /key/v2 APIs.
  4159. # Determines how quickly servers will query to check which keys
  4160. # are still valid.
  4161. #
  4162. #key_refresh_interval: 1d
  4163. # The trusted servers to download signing keys from.
  4164. #
  4165. # When we need to fetch a signing key, each server is tried in parallel.
  4166. #
  4167. # Normally, the connection to the key server is validated via TLS certificates.
  4168. # Additional security can be provided by configuring a `verify key`, which
  4169. # will make synapse check that the response is signed by that key.
  4170. #
  4171. # This setting supercedes an older setting named `perspectives`. The old format
  4172. # is still supported for backwards-compatibility, but it is deprecated.
  4173. #
  4174. # 'trusted_key_servers' defaults to matrix.org, but using it will generate a
  4175. # warning on start-up. To suppress this warning, set
  4176. # 'suppress_key_server_warning' to true.
  4177. #
  4178. # Options for each entry in the list include:
  4179. #
  4180. # server_name: the name of the server. required.
  4181. #
  4182. # verify_keys: an optional map from key id to base64-encoded public key.
  4183. # If specified, we will check that the response is signed by at least
  4184. # one of the given keys.
  4185. #
  4186. # accept_keys_insecurely: a boolean. Normally, if `verify_keys` is unset,
  4187. # and federation_verify_certificates is not `true`, synapse will refuse
  4188. # to start, because this would allow anyone who can spoof DNS responses
  4189. # to masquerade as the trusted key server. If you know what you are doing
  4190. # and are sure that your network environment provides a secure connection
  4191. # to the key server, you can set this to `true` to override this
  4192. # behaviour.
  4193. #
  4194. # An example configuration might look like:
  4195. #
  4196. #trusted_key_servers:
  4197. # - server_name: &quot;my_trusted_server.example.com&quot;
  4198. # verify_keys:
  4199. # &quot;ed25519:auto&quot;: &quot;abcdefghijklmnopqrstuvwxyzabcdefghijklmopqr&quot;
  4200. # - server_name: &quot;my_other_trusted_server.example.com&quot;
  4201. #
  4202. trusted_key_servers:
  4203. - server_name: &quot;matrix.org&quot;
  4204. # Uncomment the following to disable the warning that is emitted when the
  4205. # trusted_key_servers include 'matrix.org'. See above.
  4206. #
  4207. #suppress_key_server_warning: true
  4208. # The signing keys to use when acting as a trusted key server. If not specified
  4209. # defaults to the server signing key.
  4210. #
  4211. # Can contain multiple keys, one per line.
  4212. #
  4213. #key_server_signing_keys_path: &quot;key_server_signing_keys.key&quot;
  4214. ## Single sign-on integration ##
  4215. # The following settings can be used to make Synapse use a single sign-on
  4216. # provider for authentication, instead of its internal password database.
  4217. #
  4218. # You will probably also want to set the following options to `false` to
  4219. # disable the regular login/registration flows:
  4220. # * enable_registration
  4221. # * password_config.enabled
  4222. #
  4223. # You will also want to investigate the settings under the &quot;sso&quot; configuration
  4224. # section below.
  4225. # Enable SAML2 for registration and login. Uses pysaml2.
  4226. #
  4227. # At least one of `sp_config` or `config_path` must be set in this section to
  4228. # enable SAML login.
  4229. #
  4230. # Once SAML support is enabled, a metadata file will be exposed at
  4231. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/metadata.xml, which you may be able to
  4232. # use to configure your SAML IdP with. Alternatively, you can manually configure
  4233. # the IdP to use an ACS location of
  4234. # https://&lt;server&gt;:&lt;port&gt;/_synapse/client/saml2/authn_response.
  4235. #
  4236. saml2_config:
  4237. # `sp_config` is the configuration for the pysaml2 Service Provider.
  4238. # See pysaml2 docs for format of config.
  4239. #
  4240. # Default values will be used for the 'entityid' and 'service' settings,
  4241. # so it is not normally necessary to specify them unless you need to
  4242. # override them.
  4243. #
  4244. sp_config:
  4245. # Point this to the IdP's metadata. You must provide either a local
  4246. # file via the `local` attribute or (preferably) a URL via the
  4247. # `remote` attribute.
  4248. #
  4249. #metadata:
  4250. # local: [&quot;saml2/idp.xml&quot;]
  4251. # remote:
  4252. # - url: https://our_idp/metadata.xml
  4253. # Allowed clock difference in seconds between the homeserver and IdP.
  4254. #
  4255. # Uncomment the below to increase the accepted time difference from 0 to 3 seconds.
  4256. #
  4257. #accepted_time_diff: 3
  4258. # By default, the user has to go to our login page first. If you'd like
  4259. # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
  4260. # 'service.sp' section:
  4261. #
  4262. #service:
  4263. # sp:
  4264. # allow_unsolicited: true
  4265. # The examples below are just used to generate our metadata xml, and you
  4266. # may well not need them, depending on your setup. Alternatively you
  4267. # may need a whole lot more detail - see the pysaml2 docs!
  4268. #description: [&quot;My awesome SP&quot;, &quot;en&quot;]
  4269. #name: [&quot;Test SP&quot;, &quot;en&quot;]
  4270. #ui_info:
  4271. # display_name:
  4272. # - lang: en
  4273. # text: &quot;Display Name is the descriptive name of your service.&quot;
  4274. # description:
  4275. # - lang: en
  4276. # text: &quot;Description should be a short paragraph explaining the purpose of the service.&quot;
  4277. # information_url:
  4278. # - lang: en
  4279. # text: &quot;https://example.com/terms-of-service&quot;
  4280. # privacy_statement_url:
  4281. # - lang: en
  4282. # text: &quot;https://example.com/privacy-policy&quot;
  4283. # keywords:
  4284. # - lang: en
  4285. # text: [&quot;Matrix&quot;, &quot;Element&quot;]
  4286. # logo:
  4287. # - lang: en
  4288. # text: &quot;https://example.com/logo.svg&quot;
  4289. # width: &quot;200&quot;
  4290. # height: &quot;80&quot;
  4291. #organization:
  4292. # name: Example com
  4293. # display_name:
  4294. # - [&quot;Example co&quot;, &quot;en&quot;]
  4295. # url: &quot;http://example.com&quot;
  4296. #contact_person:
  4297. # - given_name: Bob
  4298. # sur_name: &quot;the Sysadmin&quot;
  4299. # email_address&quot;: [&quot;admin@example.com&quot;]
  4300. # contact_type&quot;: technical
  4301. # Instead of putting the config inline as above, you can specify a
  4302. # separate pysaml2 configuration file:
  4303. #
  4304. #config_path: &quot;CONFDIR/sp_conf.py&quot;
  4305. # The lifetime of a SAML session. This defines how long a user has to
  4306. # complete the authentication process, if allow_unsolicited is unset.
  4307. # The default is 15 minutes.
  4308. #
  4309. #saml_session_lifetime: 5m
  4310. # An external module can be provided here as a custom solution to
  4311. # mapping attributes returned from a saml provider onto a matrix user.
  4312. #
  4313. user_mapping_provider:
  4314. # The custom module's class. Uncomment to use a custom module.
  4315. #
  4316. #module: mapping_provider.SamlMappingProvider
  4317. # Custom configuration values for the module. Below options are
  4318. # intended for the built-in provider, they should be changed if
  4319. # using a custom module. This section will be passed as a Python
  4320. # dictionary to the module's `parse_config` method.
  4321. #
  4322. config:
  4323. # The SAML attribute (after mapping via the attribute maps) to use
  4324. # to derive the Matrix ID from. 'uid' by default.
  4325. #
  4326. # Note: This used to be configured by the
  4327. # saml2_config.mxid_source_attribute option. If that is still
  4328. # defined, its value will be used instead.
  4329. #
  4330. #mxid_source_attribute: displayName
  4331. # The mapping system to use for mapping the saml attribute onto a
  4332. # matrix ID.
  4333. #
  4334. # Options include:
  4335. # * 'hexencode' (which maps unpermitted characters to '=xx')
  4336. # * 'dotreplace' (which replaces unpermitted characters with
  4337. # '.').
  4338. # The default is 'hexencode'.
  4339. #
  4340. # Note: This used to be configured by the
  4341. # saml2_config.mxid_mapping option. If that is still defined, its
  4342. # value will be used instead.
  4343. #
  4344. #mxid_mapping: dotreplace
  4345. # In previous versions of synapse, the mapping from SAML attribute to
  4346. # MXID was always calculated dynamically rather than stored in a
  4347. # table. For backwards- compatibility, we will look for user_ids
  4348. # matching such a pattern before creating a new account.
  4349. #
  4350. # This setting controls the SAML attribute which will be used for this
  4351. # backwards-compatibility lookup. Typically it should be 'uid', but if
  4352. # the attribute maps are changed, it may be necessary to change it.
  4353. #
  4354. # The default is 'uid'.
  4355. #
  4356. #grandfathered_mxid_source_attribute: upn
  4357. # It is possible to configure Synapse to only allow logins if SAML attributes
  4358. # match particular values. The requirements can be listed under
  4359. # `attribute_requirements` as shown below. All of the listed attributes must
  4360. # match for the login to be permitted.
  4361. #
  4362. #attribute_requirements:
  4363. # - attribute: userGroup
  4364. # value: &quot;staff&quot;
  4365. # - attribute: department
  4366. # value: &quot;sales&quot;
  4367. # If the metadata XML contains multiple IdP entities then the `idp_entityid`
  4368. # option must be set to the entity to redirect users to.
  4369. #
  4370. # Most deployments only have a single IdP entity and so should omit this
  4371. # option.
  4372. #
  4373. #idp_entityid: 'https://our_idp/entityid'
  4374. # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration
  4375. # and login.
  4376. #
  4377. # Options for each entry include:
  4378. #
  4379. # idp_id: a unique identifier for this identity provider. Used internally
  4380. # by Synapse; should be a single word such as 'github'.
  4381. #
  4382. # Note that, if this is changed, users authenticating via that provider
  4383. # will no longer be recognised as the same user!
  4384. #
  4385. # (Use &quot;oidc&quot; here if you are migrating from an old &quot;oidc_config&quot;
  4386. # configuration.)
  4387. #
  4388. # idp_name: A user-facing name for this identity provider, which is used to
  4389. # offer the user a choice of login mechanisms.
  4390. #
  4391. # idp_icon: An optional icon for this identity provider, which is presented
  4392. # by clients and Synapse's own IdP picker page. If given, must be an
  4393. # MXC URI of the format mxc://&lt;server-name&gt;/&lt;media-id&gt;. (An easy way to
  4394. # obtain such an MXC URI is to upload an image to an (unencrypted) room
  4395. # and then copy the &quot;url&quot; from the source of the event.)
  4396. #
  4397. # idp_brand: An optional brand for this identity provider, allowing clients
  4398. # to style the login flow according to the identity provider in question.
  4399. # See the spec for possible options here.
  4400. #
  4401. # discover: set to 'false' to disable the use of the OIDC discovery mechanism
  4402. # to discover endpoints. Defaults to true.
  4403. #
  4404. # issuer: Required. The OIDC issuer. Used to validate tokens and (if discovery
  4405. # is enabled) to discover the provider's endpoints.
  4406. #
  4407. # client_id: Required. oauth2 client id to use.
  4408. #
  4409. # client_secret: oauth2 client secret to use. May be omitted if
  4410. # client_secret_jwt_key is given, or if client_auth_method is 'none'.
  4411. #
  4412. # client_secret_jwt_key: Alternative to client_secret: details of a key used
  4413. # to create a JSON Web Token to be used as an OAuth2 client secret. If
  4414. # given, must be a dictionary with the following properties:
  4415. #
  4416. # key: a pem-encoded signing key. Must be a suitable key for the
  4417. # algorithm specified. Required unless 'key_file' is given.
  4418. #
  4419. # key_file: the path to file containing a pem-encoded signing key file.
  4420. # Required unless 'key' is given.
  4421. #
  4422. # jwt_header: a dictionary giving properties to include in the JWT
  4423. # header. Must include the key 'alg', giving the algorithm used to
  4424. # sign the JWT, such as &quot;ES256&quot;, using the JWA identifiers in
  4425. # RFC7518.
  4426. #
  4427. # jwt_payload: an optional dictionary giving properties to include in
  4428. # the JWT payload. Normally this should include an 'iss' key.
  4429. #
  4430. # client_auth_method: auth method to use when exchanging the token. Valid
  4431. # values are 'client_secret_basic' (default), 'client_secret_post' and
  4432. # 'none'.
  4433. #
  4434. # scopes: list of scopes to request. This should normally include the &quot;openid&quot;
  4435. # scope. Defaults to [&quot;openid&quot;].
  4436. #
  4437. # authorization_endpoint: the oauth2 authorization endpoint. Required if
  4438. # provider discovery is disabled.
  4439. #
  4440. # token_endpoint: the oauth2 token endpoint. Required if provider discovery is
  4441. # disabled.
  4442. #
  4443. # userinfo_endpoint: the OIDC userinfo endpoint. Required if discovery is
  4444. # disabled and the 'openid' scope is not requested.
  4445. #
  4446. # jwks_uri: URI where to fetch the JWKS. Required if discovery is disabled and
  4447. # the 'openid' scope is used.
  4448. #
  4449. # skip_verification: set to 'true' to skip metadata verification. Use this if
  4450. # you are connecting to a provider that is not OpenID Connect compliant.
  4451. # Defaults to false. Avoid this in production.
  4452. #
  4453. # user_profile_method: Whether to fetch the user profile from the userinfo
  4454. # endpoint. Valid values are: 'auto' or 'userinfo_endpoint'.
  4455. #
  4456. # Defaults to 'auto', which fetches the userinfo endpoint if 'openid' is
  4457. # included in 'scopes'. Set to 'userinfo_endpoint' to always fetch the
  4458. # userinfo endpoint.
  4459. #
  4460. # allow_existing_users: set to 'true' to allow a user logging in via OIDC to
  4461. # match a pre-existing account instead of failing. This could be used if
  4462. # switching from password logins to OIDC. Defaults to false.
  4463. #
  4464. # user_mapping_provider: Configuration for how attributes returned from a OIDC
  4465. # provider are mapped onto a matrix user. This setting has the following
  4466. # sub-properties:
  4467. #
  4468. # module: The class name of a custom mapping module. Default is
  4469. # 'synapse.handlers.oidc.JinjaOidcMappingProvider'.
  4470. # See https://matrix-org.github.io/synapse/latest/sso_mapping_providers.html#openid-mapping-providers
  4471. # for information on implementing a custom mapping provider.
  4472. #
  4473. # config: Configuration for the mapping provider module. This section will
  4474. # be passed as a Python dictionary to the user mapping provider
  4475. # module's `parse_config` method.
  4476. #
  4477. # For the default provider, the following settings are available:
  4478. #
  4479. # subject_claim: name of the claim containing a unique identifier
  4480. # for the user. Defaults to 'sub', which OpenID Connect
  4481. # compliant providers should provide.
  4482. #
  4483. # localpart_template: Jinja2 template for the localpart of the MXID.
  4484. # If this is not set, the user will be prompted to choose their
  4485. # own username (see 'sso_auth_account_details.html' in the 'sso'
  4486. # section of this file).
  4487. #
  4488. # display_name_template: Jinja2 template for the display name to set
  4489. # on first login. If unset, no displayname will be set.
  4490. #
  4491. # email_template: Jinja2 template for the email address of the user.
  4492. # If unset, no email address will be added to the account.
  4493. #
  4494. # extra_attributes: a map of Jinja2 templates for extra attributes
  4495. # to send back to the client during login.
  4496. # Note that these are non-standard and clients will ignore them
  4497. # without modifications.
  4498. #
  4499. # When rendering, the Jinja2 templates are given a 'user' variable,
  4500. # which is set to the claims returned by the UserInfo Endpoint and/or
  4501. # in the ID Token.
  4502. #
  4503. # It is possible to configure Synapse to only allow logins if certain attributes
  4504. # match particular values in the OIDC userinfo. The requirements can be listed under
  4505. # `attribute_requirements` as shown below. All of the listed attributes must
  4506. # match for the login to be permitted. Additional attributes can be added to
  4507. # userinfo by expanding the `scopes` section of the OIDC config to retrieve
  4508. # additional information from the OIDC provider.
  4509. #
  4510. # If the OIDC claim is a list, then the attribute must match any value in the list.
  4511. # Otherwise, it must exactly match the value of the claim. Using the example
  4512. # below, the `family_name` claim MUST be &quot;Stephensson&quot;, but the `groups`
  4513. # claim MUST contain &quot;admin&quot;.
  4514. #
  4515. # attribute_requirements:
  4516. # - attribute: family_name
  4517. # value: &quot;Stephensson&quot;
  4518. # - attribute: groups
  4519. # value: &quot;admin&quot;
  4520. #
  4521. # See https://matrix-org.github.io/synapse/latest/openid.html
  4522. # for information on how to configure these options.
  4523. #
  4524. # For backwards compatibility, it is also possible to configure a single OIDC
  4525. # provider via an 'oidc_config' setting. This is now deprecated and admins are
  4526. # advised to migrate to the 'oidc_providers' format. (When doing that migration,
  4527. # use 'oidc' for the idp_id to ensure that existing users continue to be
  4528. # recognised.)
  4529. #
  4530. oidc_providers:
  4531. # Generic example
  4532. #
  4533. #- idp_id: my_idp
  4534. # idp_name: &quot;My OpenID provider&quot;
  4535. # idp_icon: &quot;mxc://example.com/mediaid&quot;
  4536. # discover: false
  4537. # issuer: &quot;https://accounts.example.com/&quot;
  4538. # client_id: &quot;provided-by-your-issuer&quot;
  4539. # client_secret: &quot;provided-by-your-issuer&quot;
  4540. # client_auth_method: client_secret_post
  4541. # scopes: [&quot;openid&quot;, &quot;profile&quot;]
  4542. # authorization_endpoint: &quot;https://accounts.example.com/oauth2/auth&quot;
  4543. # token_endpoint: &quot;https://accounts.example.com/oauth2/token&quot;
  4544. # userinfo_endpoint: &quot;https://accounts.example.com/userinfo&quot;
  4545. # jwks_uri: &quot;https://accounts.example.com/.well-known/jwks.json&quot;
  4546. # skip_verification: true
  4547. # user_mapping_provider:
  4548. # config:
  4549. # subject_claim: &quot;id&quot;
  4550. # localpart_template: &quot;{{ user.login }}&quot;
  4551. # display_name_template: &quot;{{ user.name }}&quot;
  4552. # email_template: &quot;{{ user.email }}&quot;
  4553. # attribute_requirements:
  4554. # - attribute: userGroup
  4555. # value: &quot;synapseUsers&quot;
  4556. # Enable Central Authentication Service (CAS) for registration and login.
  4557. #
  4558. cas_config:
  4559. # Uncomment the following to enable authorization against a CAS server.
  4560. # Defaults to false.
  4561. #
  4562. #enabled: true
  4563. # The URL of the CAS authorization endpoint.
  4564. #
  4565. #server_url: &quot;https://cas-server.com&quot;
  4566. # The attribute of the CAS response to use as the display name.
  4567. #
  4568. # If unset, no displayname will be set.
  4569. #
  4570. #displayname_attribute: name
  4571. # It is possible to configure Synapse to only allow logins if CAS attributes
  4572. # match particular values. All of the keys in the mapping below must exist
  4573. # and the values must match the given value. Alternately if the given value
  4574. # is None then any value is allowed (the attribute just must exist).
  4575. # All of the listed attributes must match for the login to be permitted.
  4576. #
  4577. #required_attributes:
  4578. # userGroup: &quot;staff&quot;
  4579. # department: None
  4580. # Additional settings to use with single-sign on systems such as OpenID Connect,
  4581. # SAML2 and CAS.
  4582. #
  4583. # Server admins can configure custom templates for pages related to SSO. See
  4584. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4585. #
  4586. sso:
  4587. # A list of client URLs which are whitelisted so that the user does not
  4588. # have to confirm giving access to their account to the URL. Any client
  4589. # whose URL starts with an entry in the following list will not be subject
  4590. # to an additional confirmation step after the SSO login is completed.
  4591. #
  4592. # WARNING: An entry such as &quot;https://my.client&quot; is insecure, because it
  4593. # will also match &quot;https://my.client.evil.site&quot;, exposing your users to
  4594. # phishing attacks from evil.site. To avoid this, include a slash after the
  4595. # hostname: &quot;https://my.client/&quot;.
  4596. #
  4597. # If public_baseurl is set, then the login fallback page (used by clients
  4598. # that don't natively support the required login flows) is whitelisted in
  4599. # addition to any URLs in this list.
  4600. #
  4601. # By default, this list is empty.
  4602. #
  4603. #client_whitelist:
  4604. # - https://riot.im/develop
  4605. # - https://my.custom.client/
  4606. # Uncomment to keep a user's profile fields in sync with information from
  4607. # the identity provider. Currently only syncing the displayname is
  4608. # supported. Fields are checked on every SSO login, and are updated
  4609. # if necessary.
  4610. #
  4611. # Note that enabling this option will override user profile information,
  4612. # regardless of whether users have opted-out of syncing that
  4613. # information when first signing in. Defaults to false.
  4614. #
  4615. #update_profile_information: true
  4616. # JSON web token integration. The following settings can be used to make
  4617. # Synapse JSON web tokens for authentication, instead of its internal
  4618. # password database.
  4619. #
  4620. # Each JSON Web Token needs to contain a &quot;sub&quot; (subject) claim, which is
  4621. # used as the localpart of the mxid.
  4622. #
  4623. # Additionally, the expiration time (&quot;exp&quot;), not before time (&quot;nbf&quot;),
  4624. # and issued at (&quot;iat&quot;) claims are validated if present.
  4625. #
  4626. # Note that this is a non-standard login type and client support is
  4627. # expected to be non-existent.
  4628. #
  4629. # See https://matrix-org.github.io/synapse/latest/jwt.html.
  4630. #
  4631. #jwt_config:
  4632. # Uncomment the following to enable authorization using JSON web
  4633. # tokens. Defaults to false.
  4634. #
  4635. #enabled: true
  4636. # This is either the private shared secret or the public key used to
  4637. # decode the contents of the JSON web token.
  4638. #
  4639. # Required if 'enabled' is true.
  4640. #
  4641. #secret: &quot;provided-by-your-issuer&quot;
  4642. # The algorithm used to sign the JSON web token.
  4643. #
  4644. # Supported algorithms are listed at
  4645. # https://pyjwt.readthedocs.io/en/latest/algorithms.html
  4646. #
  4647. # Required if 'enabled' is true.
  4648. #
  4649. #algorithm: &quot;provided-by-your-issuer&quot;
  4650. # The issuer to validate the &quot;iss&quot; claim against.
  4651. #
  4652. # Optional, if provided the &quot;iss&quot; claim will be required and
  4653. # validated for all JSON web tokens.
  4654. #
  4655. #issuer: &quot;provided-by-your-issuer&quot;
  4656. # A list of audiences to validate the &quot;aud&quot; claim against.
  4657. #
  4658. # Optional, if provided the &quot;aud&quot; claim will be required and
  4659. # validated for all JSON web tokens.
  4660. #
  4661. # Note that if the &quot;aud&quot; claim is included in a JSON web token then
  4662. # validation will fail without configuring audiences.
  4663. #
  4664. #audiences:
  4665. # - &quot;provided-by-your-issuer&quot;
  4666. password_config:
  4667. # Uncomment to disable password login
  4668. #
  4669. #enabled: false
  4670. # Uncomment to disable authentication against the local password
  4671. # database. This is ignored if `enabled` is false, and is only useful
  4672. # if you have other password_providers.
  4673. #
  4674. #localdb_enabled: false
  4675. # Uncomment and change to a secret random string for extra security.
  4676. # DO NOT CHANGE THIS AFTER INITIAL SETUP!
  4677. #
  4678. #pepper: &quot;EVEN_MORE_SECRET&quot;
  4679. # Define and enforce a password policy. Each parameter is optional.
  4680. # This is an implementation of MSC2000.
  4681. #
  4682. policy:
  4683. # Whether to enforce the password policy.
  4684. # Defaults to 'false'.
  4685. #
  4686. #enabled: true
  4687. # Minimum accepted length for a password.
  4688. # Defaults to 0.
  4689. #
  4690. #minimum_length: 15
  4691. # Whether a password must contain at least one digit.
  4692. # Defaults to 'false'.
  4693. #
  4694. #require_digit: true
  4695. # Whether a password must contain at least one symbol.
  4696. # A symbol is any character that's not a number or a letter.
  4697. # Defaults to 'false'.
  4698. #
  4699. #require_symbol: true
  4700. # Whether a password must contain at least one lowercase letter.
  4701. # Defaults to 'false'.
  4702. #
  4703. #require_lowercase: true
  4704. # Whether a password must contain at least one lowercase letter.
  4705. # Defaults to 'false'.
  4706. #
  4707. #require_uppercase: true
  4708. ui_auth:
  4709. # The amount of time to allow a user-interactive authentication session
  4710. # to be active.
  4711. #
  4712. # This defaults to 0, meaning the user is queried for their credentials
  4713. # before every action, but this can be overridden to allow a single
  4714. # validation to be re-used. This weakens the protections afforded by
  4715. # the user-interactive authentication process, by allowing for multiple
  4716. # (and potentially different) operations to use the same validation session.
  4717. #
  4718. # This is ignored for potentially &quot;dangerous&quot; operations (including
  4719. # deactivating an account, modifying an account password, and
  4720. # adding a 3PID).
  4721. #
  4722. # Uncomment below to allow for credential validation to last for 15
  4723. # seconds.
  4724. #
  4725. #session_timeout: &quot;15s&quot;
  4726. # Configuration for sending emails from Synapse.
  4727. #
  4728. # Server admins can configure custom templates for email content. See
  4729. # https://matrix-org.github.io/synapse/latest/templates.html for more information.
  4730. #
  4731. email:
  4732. # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'.
  4733. #
  4734. #smtp_host: mail.server
  4735. # The port on the mail server for outgoing SMTP. Defaults to 25.
  4736. #
  4737. #smtp_port: 587
  4738. # Username/password for authentication to the SMTP server. By default, no
  4739. # authentication is attempted.
  4740. #
  4741. #smtp_user: &quot;exampleusername&quot;
  4742. #smtp_pass: &quot;examplepassword&quot;
  4743. # Uncomment the following to require TLS transport security for SMTP.
  4744. # By default, Synapse will connect over plain text, and will then switch to
  4745. # TLS via STARTTLS *if the SMTP server supports it*. If this option is set,
  4746. # Synapse will refuse to connect unless the server supports STARTTLS.
  4747. #
  4748. #require_transport_security: true
  4749. # Uncomment the following to disable TLS for SMTP.
  4750. #
  4751. # By default, if the server supports TLS, it will be used, and the server
  4752. # must present a certificate that is valid for 'smtp_host'. If this option
  4753. # is set to false, TLS will not be used.
  4754. #
  4755. #enable_tls: false
  4756. # notif_from defines the &quot;From&quot; address to use when sending emails.
  4757. # It must be set if email sending is enabled.
  4758. #
  4759. # The placeholder '%(app)s' will be replaced by the application name,
  4760. # which is normally 'app_name' (below), but may be overridden by the
  4761. # Matrix client application.
  4762. #
  4763. # Note that the placeholder must be written '%(app)s', including the
  4764. # trailing 's'.
  4765. #
  4766. #notif_from: &quot;Your Friendly %(app)s homeserver &lt;noreply@example.com&gt;&quot;
  4767. # app_name defines the default value for '%(app)s' in notif_from and email
  4768. # subjects. It defaults to 'Matrix'.
  4769. #
  4770. #app_name: my_branded_matrix_server
  4771. # Uncomment the following to enable sending emails for messages that the user
  4772. # has missed. Disabled by default.
  4773. #
  4774. #enable_notifs: true
  4775. # Uncomment the following to disable automatic subscription to email
  4776. # notifications for new users. Enabled by default.
  4777. #
  4778. #notif_for_new_users: false
  4779. # Custom URL for client links within the email notifications. By default
  4780. # links will be based on &quot;https://matrix.to&quot;.
  4781. #
  4782. # (This setting used to be called riot_base_url; the old name is still
  4783. # supported for backwards-compatibility but is now deprecated.)
  4784. #
  4785. #client_base_url: &quot;http://localhost/riot&quot;
  4786. # Configure the time that a validation email will expire after sending.
  4787. # Defaults to 1h.
  4788. #
  4789. #validation_token_lifetime: 15m
  4790. # The web client location to direct users to during an invite. This is passed
  4791. # to the identity server as the org.matrix.web_client_location key. Defaults
  4792. # to unset, giving no guidance to the identity server.
  4793. #
  4794. #invite_client_location: https://app.element.io
  4795. # Subjects to use when sending emails from Synapse.
  4796. #
  4797. # The placeholder '%(app)s' will be replaced with the value of the 'app_name'
  4798. # setting above, or by a value dictated by the Matrix client application.
  4799. #
  4800. # If a subject isn't overridden in this configuration file, the value used as
  4801. # its example will be used.
  4802. #
  4803. #subjects:
  4804. # Subjects for notification emails.
  4805. #
  4806. # On top of the '%(app)s' placeholder, these can use the following
  4807. # placeholders:
  4808. #
  4809. # * '%(person)s', which will be replaced by the display name of the user(s)
  4810. # that sent the message(s), e.g. &quot;Alice and Bob&quot;.
  4811. # * '%(room)s', which will be replaced by the name of the room the
  4812. # message(s) have been sent to, e.g. &quot;My super room&quot;.
  4813. #
  4814. # See the example provided for each setting to see which placeholder can be
  4815. # used and how to use them.
  4816. #
  4817. # Subject to use to notify about one message from one or more user(s) in a
  4818. # room which has a name.
  4819. #message_from_person_in_room: &quot;[%(app)s] You have a message on %(app)s from %(person)s in the %(room)s room...&quot;
  4820. #
  4821. # Subject to use to notify about one message from one or more user(s) in a
  4822. # room which doesn't have a name.
  4823. #message_from_person: &quot;[%(app)s] You have a message on %(app)s from %(person)s...&quot;
  4824. #
  4825. # Subject to use to notify about multiple messages from one or more users in
  4826. # a room which doesn't have a name.
  4827. #messages_from_person: &quot;[%(app)s] You have messages on %(app)s from %(person)s...&quot;
  4828. #
  4829. # Subject to use to notify about multiple messages in a room which has a
  4830. # name.
  4831. #messages_in_room: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room...&quot;
  4832. #
  4833. # Subject to use to notify about multiple messages in multiple rooms.
  4834. #messages_in_room_and_others: &quot;[%(app)s] You have messages on %(app)s in the %(room)s room and others...&quot;
  4835. #
  4836. # Subject to use to notify about multiple messages from multiple persons in
  4837. # multiple rooms. This is similar to the setting above except it's used when
  4838. # the room in which the notification was triggered has no name.
  4839. #messages_from_person_and_others: &quot;[%(app)s] You have messages on %(app)s from %(person)s and others...&quot;
  4840. #
  4841. # Subject to use to notify about an invite to a room which has a name.
  4842. #invite_from_person_to_room: &quot;[%(app)s] %(person)s has invited you to join the %(room)s room on %(app)s...&quot;
  4843. #
  4844. # Subject to use to notify about an invite to a room which doesn't have a
  4845. # name.
  4846. #invite_from_person: &quot;[%(app)s] %(person)s has invited you to chat on %(app)s...&quot;
  4847. # Subject for emails related to account administration.
  4848. #
  4849. # On top of the '%(app)s' placeholder, these one can use the
  4850. # '%(server_name)s' placeholder, which will be replaced by the value of the
  4851. # 'server_name' setting in your Synapse configuration.
  4852. #
  4853. # Subject to use when sending a password reset email.
  4854. #password_reset: &quot;[%(server_name)s] Password reset&quot;
  4855. #
  4856. # Subject to use when sending a verification email to assert an address's
  4857. # ownership.
  4858. #email_validation: &quot;[%(server_name)s] Validate your email&quot;
  4859. # Password providers allow homeserver administrators to integrate
  4860. # their Synapse installation with existing authentication methods
  4861. # ex. LDAP, external tokens, etc.
  4862. #
  4863. # For more information and known implementations, please see
  4864. # https://matrix-org.github.io/synapse/latest/password_auth_providers.html
  4865. #
  4866. # Note: instances wishing to use SAML or CAS authentication should
  4867. # instead use the `saml2_config` or `cas_config` options,
  4868. # respectively.
  4869. #
  4870. password_providers:
  4871. # # Example config for an LDAP auth provider
  4872. # - module: &quot;ldap_auth_provider.LdapAuthProvider&quot;
  4873. # config:
  4874. # enabled: true
  4875. # uri: &quot;ldap://ldap.example.com:389&quot;
  4876. # start_tls: true
  4877. # base: &quot;ou=users,dc=example,dc=com&quot;
  4878. # attributes:
  4879. # uid: &quot;cn&quot;
  4880. # mail: &quot;email&quot;
  4881. # name: &quot;givenName&quot;
  4882. # #bind_dn:
  4883. # #bind_password:
  4884. # #filter: &quot;(objectClass=posixAccount)&quot;
  4885. ## Push ##
  4886. push:
  4887. # Clients requesting push notifications can either have the body of
  4888. # the message sent in the notification poke along with other details
  4889. # like the sender, or just the event ID and room ID (`event_id_only`).
  4890. # If clients choose the former, this option controls whether the
  4891. # notification request includes the content of the event (other details
  4892. # like the sender are still included). For `event_id_only` push, it
  4893. # has no effect.
  4894. #
  4895. # For modern android devices the notification content will still appear
  4896. # because it is loaded by the app. iPhone, however will send a
  4897. # notification saying only that a message arrived and who it came from.
  4898. #
  4899. # The default value is &quot;true&quot; to include message details. Uncomment to only
  4900. # include the event ID and room ID in push notification payloads.
  4901. #
  4902. #include_content: false
  4903. # When a push notification is received, an unread count is also sent.
  4904. # This number can either be calculated as the number of unread messages
  4905. # for the user, or the number of *rooms* the user has unread messages in.
  4906. #
  4907. # The default value is &quot;true&quot;, meaning push clients will see the number of
  4908. # rooms with unread messages in them. Uncomment to instead send the number
  4909. # of unread messages.
  4910. #
  4911. #group_unread_count_by_room: false
  4912. ## Rooms ##
  4913. # Controls whether locally-created rooms should be end-to-end encrypted by
  4914. # default.
  4915. #
  4916. # Possible options are &quot;all&quot;, &quot;invite&quot;, and &quot;off&quot;. They are defined as:
  4917. #
  4918. # * &quot;all&quot;: any locally-created room
  4919. # * &quot;invite&quot;: any room created with the &quot;private_chat&quot; or &quot;trusted_private_chat&quot;
  4920. # room creation presets
  4921. # * &quot;off&quot;: this option will take no effect
  4922. #
  4923. # The default value is &quot;off&quot;.
  4924. #
  4925. # Note that this option will only affect rooms created after it is set. It
  4926. # will also not affect rooms created by other servers.
  4927. #
  4928. #encryption_enabled_by_default_for_room_type: invite
  4929. # Uncomment to allow non-server-admin users to create groups on this server
  4930. #
  4931. #enable_group_creation: true
  4932. # If enabled, non server admins can only create groups with local parts
  4933. # starting with this prefix
  4934. #
  4935. #group_creation_prefix: &quot;unofficial_&quot;
  4936. # User Directory configuration
  4937. #
  4938. user_directory:
  4939. # Defines whether users can search the user directory. If false then
  4940. # empty responses are returned to all queries. Defaults to true.
  4941. #
  4942. # Uncomment to disable the user directory.
  4943. #
  4944. #enabled: false
  4945. # Defines whether to search all users visible to your HS when searching
  4946. # the user directory, rather than limiting to users visible in public
  4947. # rooms. Defaults to false.
  4948. #
  4949. # If you set it true, you'll have to rebuild the user_directory search
  4950. # indexes, see:
  4951. # https://matrix-org.github.io/synapse/latest/user_directory.html
  4952. #
  4953. # Uncomment to return search results containing all known users, even if that
  4954. # user does not share a room with the requester.
  4955. #
  4956. #search_all_users: true
  4957. # Defines whether to prefer local users in search query results.
  4958. # If True, local users are more likely to appear above remote users
  4959. # when searching the user directory. Defaults to false.
  4960. #
  4961. # Uncomment to prefer local over remote users in user directory search
  4962. # results.
  4963. #
  4964. #prefer_local_users: true
  4965. # User Consent configuration
  4966. #
  4967. # for detailed instructions, see
  4968. # https://matrix-org.github.io/synapse/latest/consent_tracking.html
  4969. #
  4970. # Parts of this section are required if enabling the 'consent' resource under
  4971. # 'listeners', in particular 'template_dir' and 'version'.
  4972. #
  4973. # 'template_dir' gives the location of the templates for the HTML forms.
  4974. # This directory should contain one subdirectory per language (eg, 'en', 'fr'),
  4975. # and each language directory should contain the policy document (named as
  4976. # '&lt;version&gt;.html') and a success page (success.html).
  4977. #
  4978. # 'version' specifies the 'current' version of the policy document. It defines
  4979. # the version to be served by the consent resource if there is no 'v'
  4980. # parameter.
  4981. #
  4982. # 'server_notice_content', if enabled, will send a user a &quot;Server Notice&quot;
  4983. # asking them to consent to the privacy policy. The 'server_notices' section
  4984. # must also be configured for this to work. Notices will *not* be sent to
  4985. # guest users unless 'send_server_notice_to_guests' is set to true.
  4986. #
  4987. # 'block_events_error', if set, will block any attempts to send events
  4988. # until the user consents to the privacy policy. The value of the setting is
  4989. # used as the text of the error.
  4990. #
  4991. # 'require_at_registration', if enabled, will add a step to the registration
  4992. # process, similar to how captcha works. Users will be required to accept the
  4993. # policy before their account is created.
  4994. #
  4995. # 'policy_name' is the display name of the policy users will see when registering
  4996. # for an account. Has no effect unless `require_at_registration` is enabled.
  4997. # Defaults to &quot;Privacy Policy&quot;.
  4998. #
  4999. #user_consent:
  5000. # template_dir: res/templates/privacy
  5001. # version: 1.0
  5002. # server_notice_content:
  5003. # msgtype: m.text
  5004. # body: &gt;-
  5005. # To continue using this homeserver you must review and agree to the
  5006. # terms and conditions at %(consent_uri)s
  5007. # send_server_notice_to_guests: true
  5008. # block_events_error: &gt;-
  5009. # To continue using this homeserver you must review and agree to the
  5010. # terms and conditions at %(consent_uri)s
  5011. # require_at_registration: false
  5012. # policy_name: Privacy Policy
  5013. #
  5014. # Settings for local room and user statistics collection. See
  5015. # https://matrix-org.github.io/synapse/latest/room_and_user_statistics.html.
  5016. #
  5017. stats:
  5018. # Uncomment the following to disable room and user statistics. Note that doing
  5019. # so may cause certain features (such as the room directory) not to work
  5020. # correctly.
  5021. #
  5022. #enabled: false
  5023. # Server Notices room configuration
  5024. #
  5025. # Uncomment this section to enable a room which can be used to send notices
  5026. # from the server to users. It is a special room which cannot be left; notices
  5027. # come from a special &quot;notices&quot; user id.
  5028. #
  5029. # If you uncomment this section, you *must* define the system_mxid_localpart
  5030. # setting, which defines the id of the user which will be used to send the
  5031. # notices.
  5032. #
  5033. # It's also possible to override the room name, the display name of the
  5034. # &quot;notices&quot; user, and the avatar for the user.
  5035. #
  5036. #server_notices:
  5037. # system_mxid_localpart: notices
  5038. # system_mxid_display_name: &quot;Server Notices&quot;
  5039. # system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  5040. # room_name: &quot;Server Notices&quot;
  5041. # Uncomment to disable searching the public room list. When disabled
  5042. # blocks searching local and remote room lists for local and remote
  5043. # users by always returning an empty list for all queries.
  5044. #
  5045. #enable_room_list_search: false
  5046. # The `alias_creation` option controls who's allowed to create aliases
  5047. # on this server.
  5048. #
  5049. # The format of this option is a list of rules that contain globs that
  5050. # match against user_id, room_id and the new alias (fully qualified with
  5051. # server name). The action in the first rule that matches is taken,
  5052. # which can currently either be &quot;allow&quot; or &quot;deny&quot;.
  5053. #
  5054. # Missing user_id/room_id/alias fields default to &quot;*&quot;.
  5055. #
  5056. # If no rules match the request is denied. An empty list means no one
  5057. # can create aliases.
  5058. #
  5059. # Options for the rules include:
  5060. #
  5061. # user_id: Matches against the creator of the alias
  5062. # alias: Matches against the alias being created
  5063. # room_id: Matches against the room ID the alias is being pointed at
  5064. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5065. #
  5066. # The default is:
  5067. #
  5068. #alias_creation_rules:
  5069. # - user_id: &quot;*&quot;
  5070. # alias: &quot;*&quot;
  5071. # room_id: &quot;*&quot;
  5072. # action: allow
  5073. # The `room_list_publication_rules` option controls who can publish and
  5074. # which rooms can be published in the public room list.
  5075. #
  5076. # The format of this option is the same as that for
  5077. # `alias_creation_rules`.
  5078. #
  5079. # If the room has one or more aliases associated with it, only one of
  5080. # the aliases needs to match the alias rule. If there are no aliases
  5081. # then only rules with `alias: *` match.
  5082. #
  5083. # If no rules match the request is denied. An empty list means no one
  5084. # can publish rooms.
  5085. #
  5086. # Options for the rules include:
  5087. #
  5088. # user_id: Matches against the creator of the alias
  5089. # room_id: Matches against the room ID being published
  5090. # alias: Matches against any current local or canonical aliases
  5091. # associated with the room
  5092. # action: Whether to &quot;allow&quot; or &quot;deny&quot; the request if the rule matches
  5093. #
  5094. # The default is:
  5095. #
  5096. #room_list_publication_rules:
  5097. # - user_id: &quot;*&quot;
  5098. # alias: &quot;*&quot;
  5099. # room_id: &quot;*&quot;
  5100. # action: allow
  5101. ## Opentracing ##
  5102. # These settings enable opentracing, which implements distributed tracing.
  5103. # This allows you to observe the causal chains of events across servers
  5104. # including requests, key lookups etc., across any server running
  5105. # synapse or any other other services which supports opentracing
  5106. # (specifically those implemented with Jaeger).
  5107. #
  5108. opentracing:
  5109. # tracing is disabled by default. Uncomment the following line to enable it.
  5110. #
  5111. #enabled: true
  5112. # The list of homeservers we wish to send and receive span contexts and span baggage.
  5113. # See https://matrix-org.github.io/synapse/latest/opentracing.html.
  5114. #
  5115. # This is a list of regexes which are matched against the server_name of the
  5116. # homeserver.
  5117. #
  5118. # By default, it is empty, so no servers are matched.
  5119. #
  5120. #homeserver_whitelist:
  5121. # - &quot;.*&quot;
  5122. # A list of the matrix IDs of users whose requests will always be traced,
  5123. # even if the tracing system would otherwise drop the traces due to
  5124. # probabilistic sampling.
  5125. #
  5126. # By default, the list is empty.
  5127. #
  5128. #force_tracing_for_users:
  5129. # - &quot;@user1:server_name&quot;
  5130. # - &quot;@user2:server_name&quot;
  5131. # Jaeger can be configured to sample traces at different rates.
  5132. # All configuration options provided by Jaeger can be set here.
  5133. # Jaeger's configuration is mostly related to trace sampling which
  5134. # is documented here:
  5135. # https://www.jaegertracing.io/docs/latest/sampling/.
  5136. #
  5137. #jaeger_config:
  5138. # sampler:
  5139. # type: const
  5140. # param: 1
  5141. # logging:
  5142. # false
  5143. ## Workers ##
  5144. # Disables sending of outbound federation transactions on the main process.
  5145. # Uncomment if using a federation sender worker.
  5146. #
  5147. #send_federation: false
  5148. # It is possible to run multiple federation sender workers, in which case the
  5149. # work is balanced across them.
  5150. #
  5151. # This configuration must be shared between all federation sender workers, and if
  5152. # changed all federation sender workers must be stopped at the same time and then
  5153. # started, to ensure that all instances are running with the same config (otherwise
  5154. # events may be dropped).
  5155. #
  5156. #federation_sender_instances:
  5157. # - federation_sender1
  5158. # When using workers this should be a map from `worker_name` to the
  5159. # HTTP replication listener of the worker, if configured.
  5160. #
  5161. #instance_map:
  5162. # worker1:
  5163. # host: localhost
  5164. # port: 8034
  5165. # Experimental: When using workers you can define which workers should
  5166. # handle event persistence and typing notifications. Any worker
  5167. # specified here must also be in the `instance_map`.
  5168. #
  5169. #stream_writers:
  5170. # events: worker1
  5171. # typing: worker1
  5172. # The worker that is used to run background tasks (e.g. cleaning up expired
  5173. # data). If not provided this defaults to the main process.
  5174. #
  5175. #run_background_tasks_on: worker1
  5176. # A shared secret used by the replication APIs to authenticate HTTP requests
  5177. # from workers.
  5178. #
  5179. # By default this is unused and traffic is not authenticated.
  5180. #
  5181. #worker_replication_secret: &quot;&quot;
  5182. # Configuration for Redis when using workers. This *must* be enabled when
  5183. # using workers (unless using old style direct TCP configuration).
  5184. #
  5185. redis:
  5186. # Uncomment the below to enable Redis support.
  5187. #
  5188. #enabled: true
  5189. # Optional host and port to use to connect to redis. Defaults to
  5190. # localhost and 6379
  5191. #
  5192. #host: localhost
  5193. #port: 6379
  5194. # Optional password if configured on the Redis instance
  5195. #
  5196. #password: &lt;secret_password&gt;
  5197. </code></pre>
  5198. <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>
  5199. <p>Below is a sample logging configuration file. This file can be tweaked to control how your
  5200. homeserver will output logs. A restart of the server is generally required to apply any
  5201. changes made to this file.</p>
  5202. <p>Note that the contents below are <em>not</em> intended to be copied and used as the basis for
  5203. a real homeserver.yaml. Instead, if you are starting from scratch, please generate
  5204. a fresh config using Synapse by following the instructions in
  5205. <a href="usage/configuration/../../setup/installation.html">Installation</a>.</p>
  5206. <pre><code class="language-yaml"># Log configuration for Synapse.
  5207. #
  5208. # This is a YAML file containing a standard Python logging configuration
  5209. # dictionary. See [1] for details on the valid settings.
  5210. #
  5211. # Synapse also supports structured logging for machine readable logs which can
  5212. # be ingested by ELK stacks. See [2] for details.
  5213. #
  5214. # [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema
  5215. # [2]: https://matrix-org.github.io/synapse/latest/structured_logging.html
  5216. version: 1
  5217. formatters:
  5218. precise:
  5219. format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
  5220. handlers:
  5221. file:
  5222. class: logging.handlers.TimedRotatingFileHandler
  5223. formatter: precise
  5224. filename: /var/log/matrix-synapse/homeserver.log
  5225. when: midnight
  5226. backupCount: 3 # Does not include the current log file.
  5227. encoding: utf8
  5228. # Default to buffering writes to log file for efficiency.
  5229. # WARNING/ERROR logs will still be flushed immediately, but there will be a
  5230. # delay (of up to `period` seconds, or until the buffer is full with
  5231. # `capacity` messages) before INFO/DEBUG logs get written.
  5232. buffer:
  5233. class: synapse.logging.handlers.PeriodicallyFlushingMemoryHandler
  5234. target: file
  5235. # The capacity is the maximum number of log lines that are buffered
  5236. # before being written to disk. Increasing this will lead to better
  5237. # performance, at the expensive of it taking longer for log lines to
  5238. # be written to disk.
  5239. # This parameter is required.
  5240. capacity: 10
  5241. # Logs with a level at or above the flush level will cause the buffer to
  5242. # be flushed immediately.
  5243. # Default value: 40 (ERROR)
  5244. # Other values: 50 (CRITICAL), 30 (WARNING), 20 (INFO), 10 (DEBUG)
  5245. flushLevel: 30 # Flush immediately for WARNING logs and higher
  5246. # The period of time, in seconds, between forced flushes.
  5247. # Messages will not be delayed for longer than this time.
  5248. # Default value: 5 seconds
  5249. period: 5
  5250. # A handler that writes logs to stderr. Unused by default, but can be used
  5251. # instead of &quot;buffer&quot; and &quot;file&quot; in the logger handlers.
  5252. console:
  5253. class: logging.StreamHandler
  5254. formatter: precise
  5255. loggers:
  5256. synapse.storage.SQL:
  5257. # beware: increasing this to DEBUG will make synapse log sensitive
  5258. # information such as access tokens.
  5259. level: INFO
  5260. twisted:
  5261. # We send the twisted logging directly to the file handler,
  5262. # to work around https://github.com/matrix-org/synapse/issues/3471
  5263. # when using &quot;buffer&quot; logger. Use &quot;console&quot; to log to stderr instead.
  5264. handlers: [file]
  5265. propagate: false
  5266. root:
  5267. level: INFO
  5268. # Write logs to the `buffer` handler, which will buffer them together in memory,
  5269. # then write them to a file.
  5270. #
  5271. # Replace &quot;buffer&quot; with &quot;console&quot; to log to stderr instead. (Note that you'll
  5272. # also need to update the configuration for the `twisted` logger above, in
  5273. # this case.)
  5274. #
  5275. handlers: [buffer]
  5276. disable_existing_loggers: false
  5277. </code></pre>
  5278. <div style="break-before: page; page-break-before: always;"></div><h1 id="structured-logging"><a class="header" href="#structured-logging">Structured Logging</a></h1>
  5279. <p>A structured logging system can be useful when your logs are destined for a
  5280. machine to parse and process. By maintaining its machine-readable characteristics,
  5281. it enables more efficient searching and aggregations when consumed by software
  5282. such as the &quot;ELK stack&quot;.</p>
  5283. <p>Synapse's structured logging system is configured via the file that Synapse's
  5284. <code>log_config</code> config option points to. The file should include a formatter which
  5285. uses the <code>synapse.logging.TerseJsonFormatter</code> class included with Synapse and a
  5286. handler which uses the above formatter.</p>
  5287. <p>There is also a <code>synapse.logging.JsonFormatter</code> option which does not include
  5288. a timestamp in the resulting JSON. This is useful if the log ingester adds its
  5289. own timestamp.</p>
  5290. <p>A structured logging configuration looks similar to the following:</p>
  5291. <pre><code class="language-yaml">version: 1
  5292. formatters:
  5293. structured:
  5294. class: synapse.logging.TerseJsonFormatter
  5295. handlers:
  5296. file:
  5297. class: logging.handlers.TimedRotatingFileHandler
  5298. formatter: structured
  5299. filename: /path/to/my/logs/homeserver.log
  5300. when: midnight
  5301. backupCount: 3 # Does not include the current log file.
  5302. encoding: utf8
  5303. loggers:
  5304. synapse:
  5305. level: INFO
  5306. handlers: [remote]
  5307. synapse.storage.SQL:
  5308. level: WARNING
  5309. </code></pre>
  5310. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5311. with the SQL layer at 'WARNING', and will log to a file, stored as JSON.</p>
  5312. <p>It is also possible to figure Synapse to log to a remote endpoint by using the
  5313. <code>synapse.logging.RemoteHandler</code> class included with Synapse. It takes the
  5314. following arguments:</p>
  5315. <ul>
  5316. <li><code>host</code>: Hostname or IP address of the log aggregator.</li>
  5317. <li><code>port</code>: Numerical port to contact on the host.</li>
  5318. <li><code>maximum_buffer</code>: (Optional, defaults to 1000) The maximum buffer size to allow.</li>
  5319. </ul>
  5320. <p>A remote structured logging configuration looks similar to the following:</p>
  5321. <pre><code class="language-yaml">version: 1
  5322. formatters:
  5323. structured:
  5324. class: synapse.logging.TerseJsonFormatter
  5325. handlers:
  5326. remote:
  5327. class: synapse.logging.RemoteHandler
  5328. formatter: structured
  5329. host: 10.1.2.3
  5330. port: 9999
  5331. loggers:
  5332. synapse:
  5333. level: INFO
  5334. handlers: [remote]
  5335. synapse.storage.SQL:
  5336. level: WARNING
  5337. </code></pre>
  5338. <p>The above logging config will set Synapse as 'INFO' logging level by default,
  5339. with the SQL layer at 'WARNING', and will log JSON formatted messages to a
  5340. remote endpoint at 10.1.2.3:9999.</p>
  5341. <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>
  5342. <p>Versions of Synapse prior to v1.23.0 included a custom structured logging
  5343. configuration which is deprecated. It used a <code>structured: true</code> flag and
  5344. configured <code>drains</code> instead of <code>handlers</code> and <code>formatters</code>.</p>
  5345. <p>Synapse currently automatically converts the old configuration to the new
  5346. configuration, but this will be removed in a future version of Synapse. The
  5347. following reference can be used to update your configuration. Based on the drain
  5348. <code>type</code>, we can pick a new handler:</p>
  5349. <ol>
  5350. <li>For a type of <code>console</code>, <code>console_json</code>, or <code>console_json_terse</code>: a handler
  5351. with a class of <code>logging.StreamHandler</code> and a <code>stream</code> of <code>ext://sys.stdout</code>
  5352. or <code>ext://sys.stderr</code> should be used.</li>
  5353. <li>For a type of <code>file</code> or <code>file_json</code>: a handler of <code>logging.FileHandler</code> with
  5354. a location of the file path should be used.</li>
  5355. <li>For a type of <code>network_json_terse</code>: a handler of <code>synapse.logging.RemoteHandler</code>
  5356. with the host and port should be used.</li>
  5357. </ol>
  5358. <p>Then based on the drain <code>type</code> we can pick a new formatter:</p>
  5359. <ol>
  5360. <li>For a type of <code>console</code> or <code>file</code> no formatter is necessary.</li>
  5361. <li>For a type of <code>console_json</code> or <code>file_json</code>: a formatter of
  5362. <code>synapse.logging.JsonFormatter</code> should be used.</li>
  5363. <li>For a type of <code>console_json_terse</code> or <code>network_json_terse</code>: a formatter of
  5364. <code>synapse.logging.TerseJsonFormatter</code> should be used.</li>
  5365. </ol>
  5366. <p>For each new handler and formatter they should be added to the logging configuration
  5367. and then assigned to either a logger or the root logger.</p>
  5368. <p>An example legacy configuration:</p>
  5369. <pre><code class="language-yaml">structured: true
  5370. loggers:
  5371. synapse:
  5372. level: INFO
  5373. synapse.storage.SQL:
  5374. level: WARNING
  5375. drains:
  5376. console:
  5377. type: console
  5378. location: stdout
  5379. file:
  5380. type: file_json
  5381. location: homeserver.log
  5382. </code></pre>
  5383. <p>Would be converted into a new configuration:</p>
  5384. <pre><code class="language-yaml">version: 1
  5385. formatters:
  5386. json:
  5387. class: synapse.logging.JsonFormatter
  5388. handlers:
  5389. console:
  5390. class: logging.StreamHandler
  5391. location: ext://sys.stdout
  5392. file:
  5393. class: logging.FileHandler
  5394. formatter: json
  5395. filename: homeserver.log
  5396. loggers:
  5397. synapse:
  5398. level: INFO
  5399. handlers: [console, file]
  5400. synapse.storage.SQL:
  5401. level: WARNING
  5402. </code></pre>
  5403. <p>The new logging configuration is a bit more verbose, but significantly more
  5404. flexible. It allows for configuration that were not previously possible, such as
  5405. sending plain logs over the network, or using different handlers for different
  5406. modules.</p>
  5407. <div style="break-before: page; page-break-before: always;"></div><h1 id="templates"><a class="header" href="#templates">Templates</a></h1>
  5408. <p>Synapse uses parametrised templates to generate the content of emails it sends and
  5409. webpages it shows to users.</p>
  5410. <p>By default, Synapse will use the templates listed <a href="https://github.com/matrix-org/synapse/tree/master/synapse/res/templates">here</a>.
  5411. Server admins can configure an additional directory for Synapse to look for templates
  5412. in, allowing them to specify custom templates:</p>
  5413. <pre><code class="language-yaml">templates:
  5414. custom_templates_directory: /path/to/custom/templates/
  5415. </code></pre>
  5416. <p>If this setting is not set, or the files named below are not found within the directory,
  5417. default templates from within the Synapse package will be used.</p>
  5418. <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>.
  5419. Templates rendered by Jinja 2 can also access two functions on top of the functions
  5420. already available as part of Jinja 2:</p>
  5421. <pre><code class="language-python">format_ts(value: int, format: str) -&gt; str
  5422. </code></pre>
  5423. <p>Formats a timestamp in milliseconds.</p>
  5424. <p>Example: <code>reason.last_sent_ts|format_ts(&quot;%c&quot;)</code></p>
  5425. <pre><code class="language-python">mxc_to_http(value: str, width: int, height: int, resize_method: str = &quot;crop&quot;) -&gt; str
  5426. </code></pre>
  5427. <p>Turns a <code>mxc://</code> URL for media content into an HTTP(S) one using the homeserver's
  5428. <code>public_baseurl</code> configuration setting as the URL's base.</p>
  5429. <p>Example: <code>message.sender_avatar_url|mxc_to_http(32,32)</code></p>
  5430. <h2 id="email-templates"><a class="header" href="#email-templates">Email templates</a></h2>
  5431. <p>Below are the templates Synapse will look for when generating the content of an email:</p>
  5432. <ul>
  5433. <li><code>notif_mail.html</code> and <code>notif_mail.txt</code>: The contents of email notifications of missed
  5434. events.
  5435. When rendering, this template is given the following variables:
  5436. <ul>
  5437. <li><code>user_display_name</code>: the display name for the user receiving the notification</li>
  5438. <li><code>unsubscribe_link</code>: the link users can click to unsubscribe from email notifications</li>
  5439. <li><code>summary_text</code>: a summary of the notification(s). The text used can be customised
  5440. by configuring the various settings in the <code>email.subjects</code> section of the
  5441. configuration file.</li>
  5442. <li><code>rooms</code>: a list of rooms containing events to include in the email. Each element is
  5443. an object with the following attributes:
  5444. <ul>
  5445. <li><code>title</code>: a human-readable name for the room</li>
  5446. <li><code>hash</code>: a hash of the ID of the room</li>
  5447. <li><code>invite</code>: a boolean, which is <code>True</code> if the room is an invite the user hasn't
  5448. accepted yet, <code>False</code> otherwise</li>
  5449. <li><code>notifs</code>: a list of events, or an empty list if <code>invite</code> is <code>True</code>. Each element
  5450. is an object with the following attributes:
  5451. <ul>
  5452. <li><code>link</code>: a <code>matrix.to</code> link to the event</li>
  5453. <li><code>ts</code>: the time in milliseconds at which the event was received</li>
  5454. <li><code>messages</code>: a list of messages containing one message before the event, the
  5455. message in the event, and one message after the event. Each element is an
  5456. object with the following attributes:
  5457. <ul>
  5458. <li><code>event_type</code>: the type of the event</li>
  5459. <li><code>is_historical</code>: a boolean, which is <code>False</code> if the message is the one
  5460. that triggered the notification, <code>True</code> otherwise</li>
  5461. <li><code>id</code>: the ID of the event</li>
  5462. <li><code>ts</code>: the time in milliseconds at which the event was sent</li>
  5463. <li><code>sender_name</code>: the display name for the event's sender</li>
  5464. <li><code>sender_avatar_url</code>: the avatar URL (as a <code>mxc://</code> URL) for the event's
  5465. sender</li>
  5466. <li><code>sender_hash</code>: a hash of the user ID of the sender</li>
  5467. </ul>
  5468. </li>
  5469. </ul>
  5470. </li>
  5471. <li><code>link</code>: a <code>matrix.to</code> link to the room</li>
  5472. </ul>
  5473. </li>
  5474. <li><code>reason</code>: information on the event that triggered the email to be sent. It's an
  5475. object with the following attributes:
  5476. <ul>
  5477. <li><code>room_id</code>: the ID of the room the event was sent in</li>
  5478. <li><code>room_name</code>: a human-readable name for the room the event was sent in</li>
  5479. <li><code>now</code>: the current time in milliseconds</li>
  5480. <li><code>received_at</code>: the time in milliseconds at which the event was received</li>
  5481. <li><code>delay_before_mail_ms</code>: the amount of time in milliseconds Synapse always waits
  5482. before ever emailing about a notification (to give the user a chance to respond
  5483. to other push or notice the window)</li>
  5484. <li><code>last_sent_ts</code>: the time in milliseconds at which a notification was last sent
  5485. for an event in this room</li>
  5486. <li><code>throttle_ms</code>: the minimum amount of time in milliseconds between two
  5487. notifications can be sent for this room</li>
  5488. </ul>
  5489. </li>
  5490. </ul>
  5491. </li>
  5492. <li><code>password_reset.html</code> and <code>password_reset.txt</code>: The contents of password reset emails
  5493. sent by the homeserver.
  5494. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5495. user must click in order to reset their password.</li>
  5496. <li><code>registration.html</code> and <code>registration.txt</code>: The contents of address verification emails
  5497. sent during registration.
  5498. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5499. user must click in order to validate their email address.</li>
  5500. <li><code>add_threepid.html</code> and <code>add_threepid.txt</code>: The contents of address verification emails
  5501. sent when an address is added to a Matrix account.
  5502. When rendering, these templates are given a <code>link</code> variable which contains the link the
  5503. user must click in order to validate their email address.</li>
  5504. </ul>
  5505. <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>
  5506. <p>Below are the templates Synapse will look for when generating pages related to
  5507. registration and password reset:</p>
  5508. <ul>
  5509. <li><code>password_reset_confirmation.html</code>: An HTML page that a user will see when they follow
  5510. the link in the password reset email. The user will be asked to confirm the action
  5511. before their password is reset.
  5512. When rendering, this template is given the following variables:
  5513. <ul>
  5514. <li><code>sid</code>: the session ID for the password reset</li>
  5515. <li><code>token</code>: the token for the password reset</li>
  5516. <li><code>client_secret</code>: the client secret for the password reset</li>
  5517. </ul>
  5518. </li>
  5519. <li><code>password_reset_success.html</code> and <code>password_reset_failure.html</code>: HTML pages for success
  5520. and failure that a user will see when they confirm the password reset flow using the
  5521. page above.
  5522. When rendering, <code>password_reset_success.html</code> is given no variable, and
  5523. <code>password_reset_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5524. for the password reset failure. </li>
  5525. <li><code>registration_success.html</code> and <code>registration_failure.html</code>: HTML pages for success and
  5526. failure that a user will see when they follow the link in an address verification email
  5527. sent during registration.
  5528. When rendering, <code>registration_success.html</code> is given no variable, and
  5529. <code>registration_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5530. for the registration failure.</li>
  5531. <li><code>add_threepid_success.html</code> and <code>add_threepid_failure.html</code>: HTML pages for success and
  5532. failure that a user will see when they follow the link in an address verification email
  5533. sent when an address is added to a Matrix account.
  5534. When rendering, <code>add_threepid_success.html</code> is given no variable, and
  5535. <code>add_threepid_failure.html</code> is given a <code>failure_reason</code>, which contains the reason
  5536. for the registration failure.</li>
  5537. </ul>
  5538. <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>
  5539. <p>Below are the templates Synapse will look for when generating pages related to SSO:</p>
  5540. <ul>
  5541. <li><code>sso_login_idp_picker.html</code>: HTML page to prompt the user to choose an
  5542. Identity Provider during login.
  5543. This is only used if multiple SSO Identity Providers are configured.
  5544. When rendering, this template is given the following variables:
  5545. <ul>
  5546. <li><code>redirect_url</code>: the URL that the user will be redirected to after
  5547. login.</li>
  5548. <li><code>server_name</code>: the homeserver's name.</li>
  5549. <li><code>providers</code>: a list of available Identity Providers. Each element is
  5550. an object with the following attributes:
  5551. <ul>
  5552. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5553. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5554. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5555. for the IdP</li>
  5556. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5557. for the brand of the IdP
  5558. The rendered HTML page should contain a form which submits its results
  5559. back as a GET request, with the following query parameters:</li>
  5560. </ul>
  5561. </li>
  5562. <li><code>redirectUrl</code>: the client redirect URI (ie, the <code>redirect_url</code> passed
  5563. to the template)</li>
  5564. <li><code>idp</code>: the 'idp_id' of the chosen IDP.</li>
  5565. </ul>
  5566. </li>
  5567. <li><code>sso_auth_account_details.html</code>: HTML page to prompt new users to enter a
  5568. userid and confirm other details. This is only shown if the
  5569. SSO implementation (with any <code>user_mapping_provider</code>) does not return
  5570. a localpart.
  5571. When rendering, this template is given the following variables:
  5572. <ul>
  5573. <li><code>server_name</code>: the homeserver's name.</li>
  5574. <li><code>idp</code>: details of the SSO Identity Provider that the user logged in
  5575. with: an object with the following attributes:
  5576. <ul>
  5577. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5578. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5579. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5580. for the IdP</li>
  5581. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5582. for the brand of the IdP</li>
  5583. </ul>
  5584. </li>
  5585. <li><code>user_attributes</code>: an object containing details about the user that
  5586. we received from the IdP. May have the following attributes:
  5587. <ul>
  5588. <li>display_name: the user's display_name</li>
  5589. <li>emails: a list of email addresses
  5590. The template should render a form which submits the following fields:</li>
  5591. </ul>
  5592. </li>
  5593. <li><code>username</code>: the localpart of the user's chosen user id</li>
  5594. </ul>
  5595. </li>
  5596. <li><code>sso_new_user_consent.html</code>: HTML page allowing the user to consent to the
  5597. server's terms and conditions. This is only shown for new users, and only if
  5598. <code>user_consent.require_at_registration</code> is set.
  5599. When rendering, this template is given the following variables:
  5600. <ul>
  5601. <li><code>server_name</code>: the homeserver's name.</li>
  5602. <li><code>user_id</code>: the user's matrix proposed ID.</li>
  5603. <li><code>user_profile.display_name</code>: the user's proposed display name, if any.</li>
  5604. <li>consent_version: the version of the terms that the user will be
  5605. shown</li>
  5606. <li><code>terms_url</code>: a link to the page showing the terms.
  5607. The template should render a form which submits the following fields:</li>
  5608. <li><code>accepted_version</code>: the version of the terms accepted by the user
  5609. (ie, 'consent_version' from the input variables).</li>
  5610. </ul>
  5611. </li>
  5612. <li><code>sso_redirect_confirm.html</code>: HTML page for a confirmation step before redirecting back
  5613. to the client with the login token.
  5614. When rendering, this template is given the following variables:
  5615. <ul>
  5616. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5617. <li><code>display_url</code>: the same as <code>redirect_url</code>, but with the query
  5618. parameters stripped. The intention is to have a
  5619. human-readable URL to show to users, not to use it as
  5620. the final address to redirect to.</li>
  5621. <li><code>server_name</code>: the homeserver's name.</li>
  5622. <li><code>new_user</code>: a boolean indicating whether this is the user's first time
  5623. logging in.</li>
  5624. <li><code>user_id</code>: the user's matrix ID.</li>
  5625. <li><code>user_profile.avatar_url</code>: an MXC URI for the user's avatar, if any.
  5626. <code>None</code> if the user has not set an avatar.</li>
  5627. <li><code>user_profile.display_name</code>: the user's display name. <code>None</code> if the user
  5628. has not set a display name.</li>
  5629. </ul>
  5630. </li>
  5631. <li><code>sso_auth_confirm.html</code>: HTML page which notifies the user that they are authenticating
  5632. to confirm an operation on their account during the user interactive authentication
  5633. process.
  5634. When rendering, this template is given the following variables:
  5635. <ul>
  5636. <li><code>redirect_url</code>: the URL the user is about to be redirected to.</li>
  5637. <li><code>description</code>: the operation which the user is being asked to confirm</li>
  5638. <li><code>idp</code>: details of the Identity Provider that we will use to confirm
  5639. the user's identity: an object with the following attributes:
  5640. <ul>
  5641. <li><code>idp_id</code>: unique identifier for the IdP</li>
  5642. <li><code>idp_name</code>: user-facing name for the IdP</li>
  5643. <li><code>idp_icon</code>: if specified in the IdP config, an MXC URI for an icon
  5644. for the IdP</li>
  5645. <li><code>idp_brand</code>: if specified in the IdP config, a textual identifier
  5646. for the brand of the IdP</li>
  5647. </ul>
  5648. </li>
  5649. </ul>
  5650. </li>
  5651. <li><code>sso_auth_success.html</code>: HTML page shown after a successful user interactive
  5652. authentication session.
  5653. Note that this page must include the JavaScript which notifies of a successful
  5654. authentication (see https://matrix.org/docs/spec/client_server/r0.6.0#fallback).
  5655. This template has no additional variables.</li>
  5656. <li><code>sso_auth_bad_user.html</code>: HTML page shown after a user-interactive authentication
  5657. session which does not map correctly onto the expected user.
  5658. When rendering, this template is given the following variables:
  5659. <ul>
  5660. <li><code>server_name</code>: the homeserver's name.</li>
  5661. <li><code>user_id_to_verify</code>: the MXID of the user that we are trying to
  5662. validate.</li>
  5663. </ul>
  5664. </li>
  5665. <li><code>sso_account_deactivated.html</code>: HTML page shown during single sign-on if a deactivated
  5666. user (according to Synapse's database) attempts to login.
  5667. This template has no additional variables.</li>
  5668. <li><code>sso_error.html</code>: HTML page to display to users if something goes wrong during the
  5669. OpenID Connect authentication process.
  5670. When rendering, this template is given two variables:
  5671. <ul>
  5672. <li><code>error</code>: the technical name of the error</li>
  5673. <li><code>error_description</code>: a human-readable message for the error</li>
  5674. </ul>
  5675. </li>
  5676. </ul>
  5677. <div style="break-before: page; page-break-before: always;"></div><h1 id="user-authentication"><a class="header" href="#user-authentication">User Authentication</a></h1>
  5678. <p>Synapse supports multiple methods of authenticating users, either out-of-the-box or through custom pluggable
  5679. authentication modules.</p>
  5680. <p>Included in Synapse is support for authenticating users via:</p>
  5681. <ul>
  5682. <li>A username and password.</li>
  5683. <li>An email address and password.</li>
  5684. <li>Single Sign-On through the SAML, Open ID Connect or CAS protocols.</li>
  5685. <li>JSON Web Tokens.</li>
  5686. <li>An administrator's shared secret.</li>
  5687. </ul>
  5688. <p>Synapse can additionally be extended to support custom authentication schemes through optional &quot;password auth provider&quot;
  5689. modules.</p>
  5690. <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>
  5691. <p>Synapse can be configured to use an OpenID Connect Provider (OP) for
  5692. authentication, instead of its own local password database.</p>
  5693. <p>Any OP should work with Synapse, as long as it supports the authorization code
  5694. flow. There are a few options for that:</p>
  5695. <ul>
  5696. <li>
  5697. <p>start a local OP. Synapse has been tested with <a href="https://www.ory.sh/docs/hydra/">Hydra</a> and
  5698. <a href="https://github.com/dexidp/dex">Dex</a>. Note that for an OP to work, it should be served under a
  5699. secure (HTTPS) origin. A certificate signed with a self-signed, locally
  5700. trusted CA should work. In that case, start Synapse with a <code>SSL_CERT_FILE</code>
  5701. environment variable set to the path of the CA.</p>
  5702. </li>
  5703. <li>
  5704. <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
  5705. <a href="https://www.okta.com/">Okta</a>. Synapse has been tested with Auth0 and Google.</p>
  5706. </li>
  5707. </ul>
  5708. <p>It may also be possible to use other OAuth2 providers which provide the
  5709. <a href="https://tools.ietf.org/html/rfc6749#section-4.1">authorization code grant type</a>,
  5710. such as <a href="https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps">Github</a>.</p>
  5711. <h2 id="preparing-synapse"><a class="header" href="#preparing-synapse">Preparing Synapse</a></h2>
  5712. <p>The OpenID integration in Synapse uses the
  5713. <a href="https://pypi.org/project/Authlib/"><code>authlib</code></a> library, which must be installed
  5714. as follows:</p>
  5715. <ul>
  5716. <li>
  5717. <p>The relevant libraries are included in the Docker images and Debian packages
  5718. provided by <code>matrix.org</code> so no further action is needed.</p>
  5719. </li>
  5720. <li>
  5721. <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>
  5722. </li>
  5723. <li>
  5724. <p>For other installation mechanisms, see the documentation provided by the
  5725. maintainer.</p>
  5726. </li>
  5727. </ul>
  5728. <p>To enable the OpenID integration, you should then add a section to the <code>oidc_providers</code>
  5729. setting in your configuration file (or uncomment one of the existing examples).
  5730. See <a href="./sample_config.yaml">sample_config.yaml</a> for some sample settings, as well as
  5731. the text below for example configurations for specific providers.</p>
  5732. <h2 id="sample-configs"><a class="header" href="#sample-configs">Sample configs</a></h2>
  5733. <p>Here are a few configs for providers that should work with Synapse.</p>
  5734. <h3 id="microsoft-azure-active-directory"><a class="header" href="#microsoft-azure-active-directory">Microsoft Azure Active Directory</a></h3>
  5735. <p>Azure AD can act as an OpenID Connect Provider. Register a new application under
  5736. <em>App registrations</em> in the Azure AD management console. The RedirectURI for your
  5737. application should point to your matrix server:
  5738. <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5739. <p>Go to <em>Certificates &amp; secrets</em> and register a new client secret. Make note of your
  5740. Directory (tenant) ID as it will be used in the Azure links.
  5741. Edit your Synapse config file and change the <code>oidc_config</code> section:</p>
  5742. <pre><code class="language-yaml">oidc_providers:
  5743. - idp_id: microsoft
  5744. idp_name: Microsoft
  5745. issuer: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/v2.0&quot;
  5746. client_id: &quot;&lt;client id&gt;&quot;
  5747. client_secret: &quot;&lt;client secret&gt;&quot;
  5748. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5749. authorization_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/authorize&quot;
  5750. token_endpoint: &quot;https://login.microsoftonline.com/&lt;tenant id&gt;/oauth2/v2.0/token&quot;
  5751. userinfo_endpoint: &quot;https://graph.microsoft.com/oidc/userinfo&quot;
  5752. user_mapping_provider:
  5753. config:
  5754. localpart_template: &quot;{{ user.preferred_username.split('@')[0] }}&quot;
  5755. display_name_template: &quot;{{ user.name }}&quot;
  5756. </code></pre>
  5757. <h3 id="dex"><a class="header" href="#dex">Dex</a></h3>
  5758. <p><a href="https://github.com/dexidp/dex">Dex</a> is a simple, open-source, certified OpenID Connect Provider.
  5759. Although it is designed to help building a full-blown provider with an
  5760. external database, it can be configured with static passwords in a config file.</p>
  5761. <p>Follow the <a href="https://dexidp.io/docs/getting-started/">Getting Started guide</a>
  5762. to install Dex.</p>
  5763. <p>Edit <code>examples/config-dev.yaml</code> config file from the Dex repo to add a client:</p>
  5764. <pre><code class="language-yaml">staticClients:
  5765. - id: synapse
  5766. secret: secret
  5767. redirectURIs:
  5768. - '[synapse public baseurl]/_synapse/client/oidc/callback'
  5769. name: 'Synapse'
  5770. </code></pre>
  5771. <p>Run with <code>dex serve examples/config-dev.yaml</code>.</p>
  5772. <p>Synapse config:</p>
  5773. <pre><code class="language-yaml">oidc_providers:
  5774. - idp_id: dex
  5775. idp_name: &quot;My Dex server&quot;
  5776. skip_verification: true # This is needed as Dex is served on an insecure endpoint
  5777. issuer: &quot;http://127.0.0.1:5556/dex&quot;
  5778. client_id: &quot;synapse&quot;
  5779. client_secret: &quot;secret&quot;
  5780. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5781. user_mapping_provider:
  5782. config:
  5783. localpart_template: &quot;{{ user.name }}&quot;
  5784. display_name_template: &quot;{{ user.name|capitalize }}&quot;
  5785. </code></pre>
  5786. <h3 id="keycloak"><a class="header" href="#keycloak">Keycloak</a></h3>
  5787. <p><a href="https://www.keycloak.org/docs/latest/server_admin/#sso-protocols">Keycloak</a> is an opensource IdP maintained by Red Hat.</p>
  5788. <p>Follow the <a href="https://www.keycloak.org/getting-started">Getting Started Guide</a> to install Keycloak and set up a realm.</p>
  5789. <ol>
  5790. <li>
  5791. <p>Click <code>Clients</code> in the sidebar and click <code>Create</code></p>
  5792. </li>
  5793. <li>
  5794. <p>Fill in the fields as below:</p>
  5795. </li>
  5796. </ol>
  5797. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5798. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5799. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5800. </tbody></table>
  5801. <ol start="3">
  5802. <li>Click <code>Save</code></li>
  5803. <li>Fill in the fields as below:</li>
  5804. </ol>
  5805. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5806. <tr><td>Client ID</td><td><code>synapse</code></td></tr>
  5807. <tr><td>Enabled</td><td><code>On</code></td></tr>
  5808. <tr><td>Client Protocol</td><td><code>openid-connect</code></td></tr>
  5809. <tr><td>Access Type</td><td><code>confidential</code></td></tr>
  5810. <tr><td>Valid Redirect URIs</td><td><code>[synapse public baseurl]/_synapse/client/oidc/callback</code></td></tr>
  5811. </tbody></table>
  5812. <ol start="5">
  5813. <li>Click <code>Save</code></li>
  5814. <li>On the Credentials tab, update the fields:</li>
  5815. </ol>
  5816. <table><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody>
  5817. <tr><td>Client Authenticator</td><td><code>Client ID and Secret</code></td></tr>
  5818. </tbody></table>
  5819. <ol start="7">
  5820. <li>Click <code>Regenerate Secret</code></li>
  5821. <li>Copy Secret</li>
  5822. </ol>
  5823. <pre><code class="language-yaml">oidc_providers:
  5824. - idp_id: keycloak
  5825. idp_name: &quot;My KeyCloak server&quot;
  5826. issuer: &quot;https://127.0.0.1:8443/auth/realms/{realm_name}&quot;
  5827. client_id: &quot;synapse&quot;
  5828. client_secret: &quot;copy secret generated from above&quot;
  5829. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5830. user_mapping_provider:
  5831. config:
  5832. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5833. display_name_template: &quot;{{ user.name }}&quot;
  5834. </code></pre>
  5835. <h3 id="auth0"><a class="header" href="#auth0">Auth0</a></h3>
  5836. <p><a href="https://auth0.com/">Auth0</a> is a hosted SaaS IdP solution.</p>
  5837. <ol>
  5838. <li>
  5839. <p>Create a regular web application for Synapse</p>
  5840. </li>
  5841. <li>
  5842. <p>Set the Allowed Callback URLs to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></p>
  5843. </li>
  5844. <li>
  5845. <p>Add a rule to add the <code>preferred_username</code> claim.</p>
  5846. <details>
  5847. <summary>Code sample</summary>
  5848. <pre><code class="language-js">function addPersistenceAttribute(user, context, callback) {
  5849. user.user_metadata = user.user_metadata || {};
  5850. user.user_metadata.preferred_username = user.user_metadata.preferred_username || user.user_id;
  5851. context.idToken.preferred_username = user.user_metadata.preferred_username;
  5852. auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
  5853. .then(function(){
  5854. callback(null, user, context);
  5855. })
  5856. .catch(function(err){
  5857. callback(err);
  5858. });
  5859. }
  5860. </code></pre>
  5861. </li>
  5862. </ol>
  5863. </details>
  5864. <p>Synapse config:</p>
  5865. <pre><code class="language-yaml">oidc_providers:
  5866. - idp_id: auth0
  5867. idp_name: Auth0
  5868. issuer: &quot;https://your-tier.eu.auth0.com/&quot; # TO BE FILLED
  5869. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5870. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5871. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5872. user_mapping_provider:
  5873. config:
  5874. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5875. display_name_template: &quot;{{ user.name }}&quot;
  5876. </code></pre>
  5877. <h3 id="github"><a class="header" href="#github">GitHub</a></h3>
  5878. <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
  5879. just a regular OAuth2 provider.</p>
  5880. <p>The <a href="https://developer.github.com/v3/users/#get-the-authenticated-user"><code>/user</code> API endpoint</a>
  5881. can be used to retrieve information on the authenticated user. As the Synapse
  5882. login mechanism needs an attribute to uniquely identify users, and that endpoint
  5883. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  5884. <ol>
  5885. <li>Create a new OAuth application: https://github.com/settings/applications/new.</li>
  5886. <li>Set the callback URL to <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5887. </ol>
  5888. <p>Synapse config:</p>
  5889. <pre><code class="language-yaml">oidc_providers:
  5890. - idp_id: github
  5891. idp_name: Github
  5892. idp_brand: &quot;github&quot; # optional: styling hint for clients
  5893. discover: false
  5894. issuer: &quot;https://github.com/&quot;
  5895. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5896. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5897. authorization_endpoint: &quot;https://github.com/login/oauth/authorize&quot;
  5898. token_endpoint: &quot;https://github.com/login/oauth/access_token&quot;
  5899. userinfo_endpoint: &quot;https://api.github.com/user&quot;
  5900. scopes: [&quot;read:user&quot;]
  5901. user_mapping_provider:
  5902. config:
  5903. subject_claim: &quot;id&quot;
  5904. localpart_template: &quot;{{ user.login }}&quot;
  5905. display_name_template: &quot;{{ user.name }}&quot;
  5906. </code></pre>
  5907. <h3 id="google"><a class="header" href="#google">Google</a></h3>
  5908. <p><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect">Google</a> is an OpenID certified authentication and authorisation provider.</p>
  5909. <ol>
  5910. <li>Set up a project in the Google API Console (see
  5911. https://developers.google.com/identity/protocols/oauth2/openid-connect#appsetup).</li>
  5912. <li>Add an &quot;OAuth Client ID&quot; for a Web Application under &quot;Credentials&quot;.</li>
  5913. <li>Copy the Client ID and Client Secret, and add the following to your synapse config:
  5914. <pre><code class="language-yaml">oidc_providers:
  5915. - idp_id: google
  5916. idp_name: Google
  5917. idp_brand: &quot;google&quot; # optional: styling hint for clients
  5918. issuer: &quot;https://accounts.google.com/&quot;
  5919. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5920. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5921. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  5922. user_mapping_provider:
  5923. config:
  5924. localpart_template: &quot;{{ user.given_name|lower }}&quot;
  5925. display_name_template: &quot;{{ user.name }}&quot;
  5926. </code></pre>
  5927. </li>
  5928. <li>Back in the Google console, add this Authorized redirect URI: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code>.</li>
  5929. </ol>
  5930. <h3 id="twitch"><a class="header" href="#twitch">Twitch</a></h3>
  5931. <ol>
  5932. <li>Setup a developer account on <a href="https://dev.twitch.tv/">Twitch</a></li>
  5933. <li>Obtain the OAuth 2.0 credentials by <a href="https://dev.twitch.tv/console/apps/">creating an app</a></li>
  5934. <li>Add this OAuth Redirect URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5935. </ol>
  5936. <p>Synapse config:</p>
  5937. <pre><code class="language-yaml">oidc_providers:
  5938. - idp_id: twitch
  5939. idp_name: Twitch
  5940. issuer: &quot;https://id.twitch.tv/oauth2/&quot;
  5941. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5942. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5943. client_auth_method: &quot;client_secret_post&quot;
  5944. user_mapping_provider:
  5945. config:
  5946. localpart_template: &quot;{{ user.preferred_username }}&quot;
  5947. display_name_template: &quot;{{ user.name }}&quot;
  5948. </code></pre>
  5949. <h3 id="gitlab"><a class="header" href="#gitlab">GitLab</a></h3>
  5950. <ol>
  5951. <li>Create a <a href="https://gitlab.com/profile/applications">new application</a>.</li>
  5952. <li>Add the <code>read_user</code> and <code>openid</code> scopes.</li>
  5953. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  5954. </ol>
  5955. <p>Synapse config:</p>
  5956. <pre><code class="language-yaml">oidc_providers:
  5957. - idp_id: gitlab
  5958. idp_name: Gitlab
  5959. idp_brand: &quot;gitlab&quot; # optional: styling hint for clients
  5960. issuer: &quot;https://gitlab.com/&quot;
  5961. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5962. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5963. client_auth_method: &quot;client_secret_post&quot;
  5964. scopes: [&quot;openid&quot;, &quot;read_user&quot;]
  5965. user_profile_method: &quot;userinfo_endpoint&quot;
  5966. user_mapping_provider:
  5967. config:
  5968. localpart_template: '{{ user.nickname }}'
  5969. display_name_template: '{{ user.name }}'
  5970. </code></pre>
  5971. <h3 id="facebook"><a class="header" href="#facebook">Facebook</a></h3>
  5972. <p>Like Github, Facebook provide a custom OAuth2 API rather than an OIDC-compliant
  5973. one so requires a little more configuration.</p>
  5974. <ol start="0">
  5975. <li>You will need a Facebook developer account. You can register for one
  5976. <a href="https://developers.facebook.com/async/registration/">here</a>.</li>
  5977. <li>On the <a href="https://developers.facebook.com/apps/">apps</a> page of the developer
  5978. console, &quot;Create App&quot;, and choose &quot;Build Connected Experiences&quot;.</li>
  5979. <li>Once the app is created, add &quot;Facebook Login&quot; and choose &quot;Web&quot;. You don't
  5980. need to go through the whole form here.</li>
  5981. <li>In the left-hand menu, open &quot;Products&quot;/&quot;Facebook Login&quot;/&quot;Settings&quot;.
  5982. <ul>
  5983. <li>Add <code>[synapse public baseurl]/_synapse/client/oidc/callback</code> as an OAuth Redirect
  5984. URL.</li>
  5985. </ul>
  5986. </li>
  5987. <li>In the left-hand menu, open &quot;Settings/Basic&quot;. Here you can copy the &quot;App ID&quot;
  5988. and &quot;App Secret&quot; for use below.</li>
  5989. </ol>
  5990. <p>Synapse config:</p>
  5991. <pre><code class="language-yaml"> - idp_id: facebook
  5992. idp_name: Facebook
  5993. idp_brand: &quot;facebook&quot; # optional: styling hint for clients
  5994. discover: false
  5995. issuer: &quot;https://facebook.com&quot;
  5996. client_id: &quot;your-client-id&quot; # TO BE FILLED
  5997. client_secret: &quot;your-client-secret&quot; # TO BE FILLED
  5998. scopes: [&quot;openid&quot;, &quot;email&quot;]
  5999. authorization_endpoint: https://facebook.com/dialog/oauth
  6000. token_endpoint: https://graph.facebook.com/v9.0/oauth/access_token
  6001. user_profile_method: &quot;userinfo_endpoint&quot;
  6002. userinfo_endpoint: &quot;https://graph.facebook.com/v9.0/me?fields=id,name,email,picture&quot;
  6003. user_mapping_provider:
  6004. config:
  6005. subject_claim: &quot;id&quot;
  6006. display_name_template: &quot;{{ user.name }}&quot;
  6007. </code></pre>
  6008. <p>Relevant documents:</p>
  6009. <ul>
  6010. <li>https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow</li>
  6011. <li>Using Facebook's Graph API: https://developers.facebook.com/docs/graph-api/using-graph-api/</li>
  6012. <li>Reference to the User endpoint: https://developers.facebook.com/docs/graph-api/reference/user</li>
  6013. </ul>
  6014. <h3 id="gitea"><a class="header" href="#gitea">Gitea</a></h3>
  6015. <p>Gitea is, like Github, not an OpenID provider, but just an OAuth2 provider.</p>
  6016. <p>The <a href="https://try.gitea.io/api/swagger#/user/userGetCurrent"><code>/user</code> API endpoint</a>
  6017. can be used to retrieve information on the authenticated user. As the Synapse
  6018. login mechanism needs an attribute to uniquely identify users, and that endpoint
  6019. does not return a <code>sub</code> property, an alternative <code>subject_claim</code> has to be set.</p>
  6020. <ol>
  6021. <li>Create a new application.</li>
  6022. <li>Add this Callback URL: <code>[synapse public baseurl]/_synapse/client/oidc/callback</code></li>
  6023. </ol>
  6024. <p>Synapse config:</p>
  6025. <pre><code class="language-yaml">oidc_providers:
  6026. - idp_id: gitea
  6027. idp_name: Gitea
  6028. discover: false
  6029. issuer: &quot;https://your-gitea.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. client_auth_method: client_secret_post
  6033. scopes: [] # Gitea doesn't support Scopes
  6034. authorization_endpoint: &quot;https://your-gitea.com/login/oauth/authorize&quot;
  6035. token_endpoint: &quot;https://your-gitea.com/login/oauth/access_token&quot;
  6036. userinfo_endpoint: &quot;https://your-gitea.com/api/v1/user&quot;
  6037. user_mapping_provider:
  6038. config:
  6039. subject_claim: &quot;id&quot;
  6040. localpart_template: &quot;{{ user.login }}&quot;
  6041. display_name_template: &quot;{{ user.full_name }}&quot;
  6042. </code></pre>
  6043. <h3 id="xwiki"><a class="header" href="#xwiki">XWiki</a></h3>
  6044. <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>
  6045. <p>Synapse config:</p>
  6046. <pre><code class="language-yaml">oidc_providers:
  6047. - idp_id: xwiki
  6048. idp_name: &quot;XWiki&quot;
  6049. issuer: &quot;https://myxwikihost/xwiki/oidc/&quot;
  6050. client_id: &quot;your-client-id&quot; # TO BE FILLED
  6051. client_auth_method: none
  6052. scopes: [&quot;openid&quot;, &quot;profile&quot;]
  6053. user_profile_method: &quot;userinfo_endpoint&quot;
  6054. user_mapping_provider:
  6055. config:
  6056. localpart_template: &quot;{{ user.preferred_username }}&quot;
  6057. display_name_template: &quot;{{ user.name }}&quot;
  6058. </code></pre>
  6059. <h3 id="apple"><a class="header" href="#apple">Apple</a></h3>
  6060. <p>Configuring &quot;Sign in with Apple&quot; (SiWA) requires an Apple Developer account.</p>
  6061. <p>You will need to create a new &quot;Services ID&quot; for SiWA, and create and download a
  6062. private key with &quot;SiWA&quot; enabled.</p>
  6063. <p>As well as the private key file, you will need:</p>
  6064. <ul>
  6065. <li>Client ID: the &quot;identifier&quot; you gave the &quot;Services ID&quot;</li>
  6066. <li>Team ID: a 10-character ID associated with your developer account.</li>
  6067. <li>Key ID: the 10-character identifier for the key.</li>
  6068. </ul>
  6069. <p>https://help.apple.com/developer-account/?lang=en#/dev77c875b7e has more
  6070. documentation on setting up SiWA.</p>
  6071. <p>The synapse config will look like this:</p>
  6072. <pre><code class="language-yaml"> - idp_id: apple
  6073. idp_name: Apple
  6074. issuer: &quot;https://appleid.apple.com&quot;
  6075. client_id: &quot;your-client-id&quot; # Set to the &quot;identifier&quot; for your &quot;ServicesID&quot;
  6076. client_auth_method: &quot;client_secret_post&quot;
  6077. client_secret_jwt_key:
  6078. key_file: &quot;/path/to/AuthKey_KEYIDCODE.p8&quot; # point to your key file
  6079. jwt_header:
  6080. alg: ES256
  6081. kid: &quot;KEYIDCODE&quot; # Set to the 10-char Key ID
  6082. jwt_payload:
  6083. iss: TEAMIDCODE # Set to the 10-char Team ID
  6084. scopes: [&quot;name&quot;, &quot;email&quot;, &quot;openid&quot;]
  6085. authorization_endpoint: https://appleid.apple.com/auth/authorize?response_mode=form_post
  6086. user_mapping_provider:
  6087. config:
  6088. email_template: &quot;{{ user.email }}&quot;
  6089. </code></pre>
  6090. <h2 id="django-oauth-toolkit"><a class="header" href="#django-oauth-toolkit">Django OAuth Toolkit</a></h2>
  6091. <p><a href="https://github.com/jazzband/django-oauth-toolkit">django-oauth-toolkit</a> is a
  6092. Django application providing out of the box all the endpoints, data and logic
  6093. needed to add OAuth2 capabilities to your Django projects. It supports
  6094. <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/oidc.html">OpenID Connect too</a>.</p>
  6095. <p>Configuration on Django's side:</p>
  6096. <ol>
  6097. <li>Add an application: https://example.com/admin/oauth2_provider/application/add/ and choose parameters like this:</li>
  6098. </ol>
  6099. <ul>
  6100. <li><code>Redirect uris</code>: https://synapse.example.com/_synapse/client/oidc/callback</li>
  6101. <li><code>Client type</code>: <code>Confidential</code></li>
  6102. <li><code>Authorization grant type</code>: <code>Authorization code</code></li>
  6103. <li><code>Algorithm</code>: <code>HMAC with SHA-2 256</code></li>
  6104. </ul>
  6105. <ol start="2">
  6106. <li>
  6107. <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>
  6108. <details>
  6109. <summary>Code sample</summary>
  6110. <pre><code class="language-python">class CustomOAuth2Validator(OAuth2Validator):
  6111. def get_additional_claims(self, request):
  6112. return {
  6113. &quot;sub&quot;: request.user.email,
  6114. &quot;email&quot;: request.user.email,
  6115. &quot;first_name&quot;: request.user.first_name,
  6116. &quot;last_name&quot;: request.user.last_name,
  6117. }
  6118. </code></pre>
  6119. </details>
  6120. </li>
  6121. </ol>
  6122. <p>Your synapse config is then:</p>
  6123. <pre><code class="language-yaml">oidc_providers:
  6124. - idp_id: django_example
  6125. idp_name: &quot;Django Example&quot;
  6126. issuer: &quot;https://example.com/o/&quot;
  6127. client_id: &quot;your-client-id&quot; # CHANGE ME
  6128. client_secret: &quot;your-client-secret&quot; # CHANGE ME
  6129. scopes: [&quot;openid&quot;]
  6130. user_profile_method: &quot;userinfo_endpoint&quot; # needed because oauth-toolkit does not include user information in the authorization response
  6131. user_mapping_provider:
  6132. config:
  6133. localpart_template: &quot;{{ user.email.split('@')[0] }}&quot;
  6134. display_name_template: &quot;{{ user.first_name }} {{ user.last_name }}&quot;
  6135. email_template: &quot;{{ user.email }}&quot;
  6136. </code></pre>
  6137. <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>
  6138. <p>A mapping provider is a Python class (loaded via a Python module) that
  6139. works out how to map attributes of a SSO response to Matrix-specific
  6140. user attributes. Details such as user ID localpart, displayname, and even avatar
  6141. URLs are all things that can be mapped from talking to a SSO service.</p>
  6142. <p>As an example, a SSO service may return the email address
  6143. &quot;john.smith@example.com&quot; for a user, whereas Synapse will need to figure out how
  6144. to turn that into a displayname when creating a Matrix user for this individual.
  6145. It may choose <code>John Smith</code>, or <code>Smith, John [Example.com]</code> or any number of
  6146. variations. As each Synapse configuration may want something different, this is
  6147. where SAML mapping providers come into play.</p>
  6148. <p>SSO mapping providers are currently supported for OpenID and SAML SSO
  6149. configurations. Please see the details below for how to implement your own.</p>
  6150. <p>It is up to the mapping provider whether the user should be assigned a predefined
  6151. Matrix ID based on the SSO attributes, or if the user should be allowed to
  6152. choose their own username.</p>
  6153. <p>In the first case - where users are automatically allocated a Matrix ID - it is
  6154. the responsibility of the mapping provider to normalise the SSO attributes and
  6155. map them to a valid Matrix ID. The <a href="https://matrix.org/docs/spec/appendices#user-identifiers">specification for Matrix
  6156. IDs</a> has some
  6157. information about what is considered valid.</p>
  6158. <p>If the mapping provider does not assign a Matrix ID, then Synapse will
  6159. automatically serve an HTML page allowing the user to pick their own username.</p>
  6160. <p>External mapping providers are provided to Synapse in the form of an external
  6161. Python module. You can retrieve this module from <a href="https://pypi.org">PyPI</a> or elsewhere,
  6162. but it must be importable via Synapse (e.g. it must be in the same virtualenv
  6163. as Synapse). The Synapse config is then modified to point to the mapping provider
  6164. (and optionally provide additional configuration for it).</p>
  6165. <h2 id="openid-mapping-providers"><a class="header" href="#openid-mapping-providers">OpenID Mapping Providers</a></h2>
  6166. <p>The OpenID mapping provider can be customized by editing the
  6167. <code>oidc_config.user_mapping_provider.module</code> config option.</p>
  6168. <p><code>oidc_config.user_mapping_provider.config</code> allows you to provide custom
  6169. configuration options to the module. Check with the module's documentation for
  6170. what options it provides (if any). The options listed by default are for the
  6171. user mapping provider built in to Synapse. If using a custom module, you should
  6172. comment these options out and use those specified by the module instead.</p>
  6173. <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>
  6174. <p>A custom mapping provider must specify the following methods:</p>
  6175. <ul>
  6176. <li><code>__init__(self, parsed_config)</code>
  6177. <ul>
  6178. <li>Arguments:
  6179. <ul>
  6180. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6181. <code>parse_config</code> method. You should set any configuration options needed by
  6182. the module here.</li>
  6183. </ul>
  6184. </li>
  6185. </ul>
  6186. </li>
  6187. <li><code>parse_config(config)</code>
  6188. <ul>
  6189. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6190. <li>Arguments:
  6191. <ul>
  6192. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6193. <code>oidc_config.user_mapping_provider.config</code> homeserver config option.
  6194. Runs on homeserver startup. Providers should extract and validate
  6195. any option values they need here.</li>
  6196. </ul>
  6197. </li>
  6198. <li>Whatever is returned will be passed back to the user mapping provider module's
  6199. <code>__init__</code> method during construction.</li>
  6200. </ul>
  6201. </li>
  6202. <li><code>get_remote_user_id(self, userinfo)</code>
  6203. <ul>
  6204. <li>Arguments:
  6205. <ul>
  6206. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6207. information from.</li>
  6208. </ul>
  6209. </li>
  6210. <li>This method must return a string, which is the unique, immutable identifier
  6211. for the user. Commonly the <code>sub</code> claim of the response.</li>
  6212. </ul>
  6213. </li>
  6214. <li><code>map_user_attributes(self, userinfo, token, failures)</code>
  6215. <ul>
  6216. <li>This method must be async.</li>
  6217. <li>Arguments:
  6218. <ul>
  6219. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6220. information from.</li>
  6221. <li><code>token</code> - A dictionary which includes information necessary to make
  6222. further requests to the OpenID provider.</li>
  6223. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6224. mxid localpart mapping has failed. This should be used
  6225. to create a deduplicated mxid localpart which should be
  6226. returned instead. For example, if this method returns
  6227. <code>john.doe</code> as the value of <code>localpart</code> in the returned
  6228. dict, and that is already taken on the homeserver, this
  6229. method will be called again with the same parameters but
  6230. with failures=1. The method should then return a different
  6231. <code>localpart</code> value, such as <code>john.doe1</code>.</li>
  6232. </ul>
  6233. </li>
  6234. <li>Returns a dictionary with two keys:
  6235. <ul>
  6236. <li><code>localpart</code>: A string, used to generate the Matrix ID. If this is
  6237. <code>None</code>, the user is prompted to pick their own username. This is only used
  6238. during a user's first login. Once a localpart has been associated with a
  6239. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6240. <li><code>displayname</code>: An optional string, the display name for the user.</li>
  6241. </ul>
  6242. </li>
  6243. </ul>
  6244. </li>
  6245. <li><code>get_extra_attributes(self, userinfo, token)</code>
  6246. <ul>
  6247. <li>
  6248. <p>This method must be async.</p>
  6249. </li>
  6250. <li>
  6251. <p>Arguments:</p>
  6252. <ul>
  6253. <li><code>userinfo</code> - A <code>authlib.oidc.core.claims.UserInfo</code> object to extract user
  6254. information from.</li>
  6255. <li><code>token</code> - A dictionary which includes information necessary to make
  6256. further requests to the OpenID provider.</li>
  6257. </ul>
  6258. </li>
  6259. <li>
  6260. <p>Returns a dictionary that is suitable to be serialized to JSON. This
  6261. will be returned as part of the response during a successful login.</p>
  6262. <p>Note that care should be taken to not overwrite any of the parameters
  6263. 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>
  6264. </li>
  6265. </ul>
  6266. </li>
  6267. </ul>
  6268. <h3 id="default-openid-mapping-provider"><a class="header" href="#default-openid-mapping-provider">Default OpenID Mapping Provider</a></h3>
  6269. <p>Synapse has a built-in OpenID mapping provider if a custom provider isn't
  6270. specified in the config. It is located at
  6271. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/oidc.py"><code>synapse.handlers.oidc.JinjaOidcMappingProvider</code></a>.</p>
  6272. <h2 id="saml-mapping-providers"><a class="header" href="#saml-mapping-providers">SAML Mapping Providers</a></h2>
  6273. <p>The SAML mapping provider can be customized by editing the
  6274. <code>saml2_config.user_mapping_provider.module</code> config option.</p>
  6275. <p><code>saml2_config.user_mapping_provider.config</code> allows you to provide custom
  6276. configuration options to the module. Check with the module's documentation for
  6277. what options it provides (if any). The options listed by default are for the
  6278. user mapping provider built in to Synapse. If using a custom module, you should
  6279. comment these options out and use those specified by the module instead.</p>
  6280. <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>
  6281. <p>A custom mapping provider must specify the following methods:</p>
  6282. <ul>
  6283. <li><code>__init__(self, parsed_config, module_api)</code>
  6284. <ul>
  6285. <li>Arguments:
  6286. <ul>
  6287. <li><code>parsed_config</code> - A configuration object that is the return value of the
  6288. <code>parse_config</code> method. You should set any configuration options needed by
  6289. the module here.</li>
  6290. <li><code>module_api</code> - a <code>synapse.module_api.ModuleApi</code> object which provides the
  6291. stable API available for extension modules.</li>
  6292. </ul>
  6293. </li>
  6294. </ul>
  6295. </li>
  6296. <li><code>parse_config(config)</code>
  6297. <ul>
  6298. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6299. <li>Arguments:
  6300. <ul>
  6301. <li><code>config</code> - A <code>dict</code> representing the parsed content of the
  6302. <code>saml_config.user_mapping_provider.config</code> homeserver config option.
  6303. Runs on homeserver startup. Providers should extract and validate
  6304. any option values they need here.</li>
  6305. </ul>
  6306. </li>
  6307. <li>Whatever is returned will be passed back to the user mapping provider module's
  6308. <code>__init__</code> method during construction.</li>
  6309. </ul>
  6310. </li>
  6311. <li><code>get_saml_attributes(config)</code>
  6312. <ul>
  6313. <li>This method should have the <code>@staticmethod</code> decoration.</li>
  6314. <li>Arguments:
  6315. <ul>
  6316. <li><code>config</code> - A object resulting from a call to <code>parse_config</code>.</li>
  6317. </ul>
  6318. </li>
  6319. <li>Returns a tuple of two sets. The first set equates to the SAML auth
  6320. response attributes that are required for the module to function, whereas
  6321. the second set consists of those attributes which can be used if available,
  6322. but are not necessary.</li>
  6323. </ul>
  6324. </li>
  6325. <li><code>get_remote_user_id(self, saml_response, client_redirect_url)</code>
  6326. <ul>
  6327. <li>Arguments:
  6328. <ul>
  6329. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6330. information from.</li>
  6331. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6332. redirected to.</li>
  6333. </ul>
  6334. </li>
  6335. <li>This method must return a string, which is the unique, immutable identifier
  6336. for the user. Commonly the <code>uid</code> claim of the response.</li>
  6337. </ul>
  6338. </li>
  6339. <li><code>saml_response_to_user_attributes(self, saml_response, failures, client_redirect_url)</code>
  6340. <ul>
  6341. <li>
  6342. <p>Arguments:</p>
  6343. <ul>
  6344. <li><code>saml_response</code> - A <code>saml2.response.AuthnResponse</code> object to extract user
  6345. information from.</li>
  6346. <li><code>failures</code> - An <code>int</code> that represents the amount of times the returned
  6347. mxid localpart mapping has failed. This should be used
  6348. to create a deduplicated mxid localpart which should be
  6349. returned instead. For example, if this method returns
  6350. <code>john.doe</code> as the value of <code>mxid_localpart</code> in the returned
  6351. dict, and that is already taken on the homeserver, this
  6352. method will be called again with the same parameters but
  6353. with failures=1. The method should then return a different
  6354. <code>mxid_localpart</code> value, such as <code>john.doe1</code>.</li>
  6355. <li><code>client_redirect_url</code> - A string, the URL that the client will be
  6356. redirected to.</li>
  6357. </ul>
  6358. </li>
  6359. <li>
  6360. <p>This method must return a dictionary, which will then be used by Synapse
  6361. to build a new user. The following keys are allowed:</p>
  6362. <ul>
  6363. <li><code>mxid_localpart</code> - A string, the mxid localpart of the new user. If this is
  6364. <code>None</code>, the user is prompted to pick their own username. This is only used
  6365. during a user's first login. Once a localpart has been associated with a
  6366. remote user ID (see <code>get_remote_user_id</code>) it cannot be updated.</li>
  6367. <li><code>displayname</code> - The displayname of the new user. If not provided, will default to
  6368. the value of <code>mxid_localpart</code>.</li>
  6369. <li><code>emails</code> - A list of emails for the new user. If not provided, will
  6370. default to an empty list.</li>
  6371. </ul>
  6372. <p>Alternatively it can raise a <code>synapse.api.errors.RedirectException</code> to
  6373. redirect the user to another page. This is useful to prompt the user for
  6374. additional information, e.g. if you want them to provide their own username.
  6375. It is the responsibility of the mapping provider to either redirect back
  6376. to <code>client_redirect_url</code> (including any additional information) or to
  6377. complete registration using methods from the <code>ModuleApi</code>.</p>
  6378. </li>
  6379. </ul>
  6380. </li>
  6381. </ul>
  6382. <h3 id="default-saml-mapping-provider"><a class="header" href="#default-saml-mapping-provider">Default SAML Mapping Provider</a></h3>
  6383. <p>Synapse has a built-in SAML mapping provider if a custom provider isn't
  6384. specified in the config. It is located at
  6385. <a href="https://github.com/matrix-org/synapse/blob/develop/synapse/handlers/saml.py"><code>synapse.handlers.saml.DefaultSamlMappingProvider</code></a>.</p>
  6386. <div style="break-before: page; page-break-before: always;"></div><h1 id="password-auth-provider-modules"><a class="header" href="#password-auth-provider-modules">Password auth provider modules</a></h1>
  6387. <p>Password auth providers offer a way for server administrators to
  6388. integrate their Synapse installation with an existing authentication
  6389. system.</p>
  6390. <p>A password auth provider is a Python class which is dynamically loaded
  6391. into Synapse, and provides a number of methods by which it can integrate
  6392. with the authentication system.</p>
  6393. <p>This document serves as a reference for those looking to implement their
  6394. own password auth providers. Additionally, here is a list of known
  6395. password auth provider module implementations:</p>
  6396. <ul>
  6397. <li><a href="https://github.com/matrix-org/matrix-synapse-ldap3/">matrix-synapse-ldap3</a></li>
  6398. <li><a href="https://github.com/devture/matrix-synapse-shared-secret-auth">matrix-synapse-shared-secret-auth</a></li>
  6399. <li><a href="https://github.com/ma1uta/matrix-synapse-rest-password-provider">matrix-synapse-rest-password-provider</a></li>
  6400. </ul>
  6401. <h2 id="required-methods"><a class="header" href="#required-methods">Required methods</a></h2>
  6402. <p>Password auth provider classes must provide the following methods:</p>
  6403. <ul>
  6404. <li>
  6405. <p><code>parse_config(config)</code>
  6406. This method is passed the <code>config</code> object for this module from the
  6407. homeserver configuration file.</p>
  6408. <p>It should perform any appropriate sanity checks on the provided
  6409. configuration, and return an object which is then passed into
  6410. <code>__init__</code>.</p>
  6411. <p>This method should have the <code>@staticmethod</code> decoration.</p>
  6412. </li>
  6413. <li>
  6414. <p><code>__init__(self, config, account_handler)</code></p>
  6415. <p>The constructor is passed the config object returned by
  6416. <code>parse_config</code>, and a <code>synapse.module_api.ModuleApi</code> object which
  6417. allows the password provider to check if accounts exist and/or create
  6418. new ones.</p>
  6419. </li>
  6420. </ul>
  6421. <h2 id="optional-methods"><a class="header" href="#optional-methods">Optional methods</a></h2>
  6422. <p>Password auth provider classes may optionally provide the following methods:</p>
  6423. <ul>
  6424. <li>
  6425. <p><code>get_db_schema_files(self)</code></p>
  6426. <p>This method, if implemented, should return an Iterable of
  6427. <code>(name, stream)</code> pairs of database schema files. Each file is applied
  6428. in turn at initialisation, and a record is then made in the database
  6429. so that it is not re-applied on the next start.</p>
  6430. </li>
  6431. <li>
  6432. <p><code>get_supported_login_types(self)</code></p>
  6433. <p>This method, if implemented, should return a <code>dict</code> mapping from a
  6434. login type identifier (such as <code>m.login.password</code>) to an iterable
  6435. giving the fields which must be provided by the user in the submission
  6436. to <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login">the <code>/login</code> API</a>.
  6437. These fields are passed in the <code>login_dict</code> dictionary to <code>check_auth</code>.</p>
  6438. <p>For example, if a password auth provider wants to implement a custom
  6439. login type of <code>com.example.custom_login</code>, where the client is expected
  6440. to pass the fields <code>secret1</code> and <code>secret2</code>, the provider should
  6441. implement this method and return the following dict:</p>
  6442. <pre><code class="language-python">{&quot;com.example.custom_login&quot;: (&quot;secret1&quot;, &quot;secret2&quot;)}
  6443. </code></pre>
  6444. </li>
  6445. <li>
  6446. <p><code>check_auth(self, username, login_type, login_dict)</code></p>
  6447. <p>This method does the real work. If implemented, it
  6448. will be called for each login attempt where the login type matches one
  6449. of the keys returned by <code>get_supported_login_types</code>.</p>
  6450. <p>It is passed the (possibly unqualified) <code>user</code> field provided by the client,
  6451. the login type, and a dictionary of login secrets passed by the
  6452. client.</p>
  6453. <p>The method should return an <code>Awaitable</code> object, which resolves
  6454. to the canonical <code>@localpart:domain</code> user ID if authentication is
  6455. successful, and <code>None</code> if not.</p>
  6456. <p>Alternatively, the <code>Awaitable</code> can resolve to a <code>(str, func)</code> tuple, in
  6457. which case the second field is a callback which will be called with
  6458. the result from the <code>/login</code> call (including <code>access_token</code>,
  6459. <code>device_id</code>, etc.)</p>
  6460. </li>
  6461. <li>
  6462. <p><code>check_3pid_auth(self, medium, address, password)</code></p>
  6463. <p>This method, if implemented, is called when a user attempts to
  6464. register or log in with a third party identifier, such as email. It is
  6465. passed the medium (ex. &quot;email&quot;), an address (ex.
  6466. &quot;<a href="mailto:jdoe@example.com">jdoe@example.com</a>&quot;) and the user's password.</p>
  6467. <p>The method should return an <code>Awaitable</code> object, which resolves
  6468. to a <code>str</code> containing the user's (canonical) User id if
  6469. authentication was successful, and <code>None</code> if not.</p>
  6470. <p>As with <code>check_auth</code>, the <code>Awaitable</code> may alternatively resolve to a
  6471. <code>(user_id, callback)</code> tuple.</p>
  6472. </li>
  6473. <li>
  6474. <p><code>check_password(self, user_id, password)</code></p>
  6475. <p>This method provides a simpler interface than
  6476. <code>get_supported_login_types</code> and <code>check_auth</code> for password auth
  6477. providers that just want to provide a mechanism for validating
  6478. <code>m.login.password</code> logins.</p>
  6479. <p>If implemented, it will be called to check logins with an
  6480. <code>m.login.password</code> login type. It is passed a qualified
  6481. <code>@localpart:domain</code> user id, and the password provided by the user.</p>
  6482. <p>The method should return an <code>Awaitable</code> object, which resolves
  6483. to <code>True</code> if authentication is successful, and <code>False</code> if not.</p>
  6484. </li>
  6485. <li>
  6486. <p><code>on_logged_out(self, user_id, device_id, access_token)</code></p>
  6487. <p>This method, if implemented, is called when a user logs out. It is
  6488. passed the qualified user ID, the ID of the deactivated device (if
  6489. any: access tokens are occasionally created without an associated
  6490. device ID), and the (now deactivated) access token.</p>
  6491. <p>It may return an <code>Awaitable</code> object; the logout request will
  6492. wait for the <code>Awaitable</code> to complete, but the result is ignored.</p>
  6493. </li>
  6494. </ul>
  6495. <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>
  6496. <p>Synapse comes with a non-standard login type to support
  6497. <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">JSON Web Tokens</a>. In general the
  6498. documentation for
  6499. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#login">the login endpoint</a>
  6500. is still valid (and the mechanism works similarly to the
  6501. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#token-based">token based login</a>).</p>
  6502. <p>To log in using a JSON Web Token, clients should submit a <code>/login</code> request as
  6503. follows:</p>
  6504. <pre><code class="language-json">{
  6505. &quot;type&quot;: &quot;org.matrix.login.jwt&quot;,
  6506. &quot;token&quot;: &quot;&lt;jwt&gt;&quot;
  6507. }
  6508. </code></pre>
  6509. <p>Note that the login type of <code>m.login.jwt</code> is supported, but is deprecated. This
  6510. will be removed in a future version of Synapse.</p>
  6511. <p>The <code>token</code> field should include the JSON web token with the following claims:</p>
  6512. <ul>
  6513. <li>The <code>sub</code> (subject) claim is required and should encode the local part of the
  6514. user ID.</li>
  6515. <li>The expiration time (<code>exp</code>), not before time (<code>nbf</code>), and issued at (<code>iat</code>)
  6516. claims are optional, but validated if present.</li>
  6517. <li>The issuer (<code>iss</code>) claim is optional, but required and validated if configured.</li>
  6518. <li>The audience (<code>aud</code>) claim is optional, but required and validated if configured.
  6519. Providing the audience claim when not configured will cause validation to fail.</li>
  6520. </ul>
  6521. <p>In the case that the token is not valid, the homeserver must respond with
  6522. <code>403 Forbidden</code> and an error code of <code>M_FORBIDDEN</code>.</p>
  6523. <p>As with other login types, there are additional fields (e.g. <code>device_id</code> and
  6524. <code>initial_device_display_name</code>) which can be included in the above request.</p>
  6525. <h2 id="preparing-synapse-1"><a class="header" href="#preparing-synapse-1">Preparing Synapse</a></h2>
  6526. <p>The JSON Web Token integration in Synapse uses the
  6527. <a href="https://pypi.org/project/pyjwt/"><code>PyJWT</code></a> library, which must be installed
  6528. as follows:</p>
  6529. <ul>
  6530. <li>
  6531. <p>The relevant libraries are included in the Docker images and Debian packages
  6532. provided by <code>matrix.org</code> so no further action is needed.</p>
  6533. </li>
  6534. <li>
  6535. <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>
  6536. </li>
  6537. <li>
  6538. <p>For other installation mechanisms, see the documentation provided by the
  6539. maintainer.</p>
  6540. </li>
  6541. </ul>
  6542. <p>To enable the JSON web token integration, you should then add an <code>jwt_config</code> section
  6543. to your configuration file (or uncomment the <code>enabled: true</code> line in the
  6544. existing section). See <a href="./sample_config.yaml">sample_config.yaml</a> for some
  6545. sample settings.</p>
  6546. <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>
  6547. <p>Although JSON Web Tokens are typically generated from an external server, the
  6548. examples below use <a href="https://pyjwt.readthedocs.io/en/latest/">PyJWT</a> directly.</p>
  6549. <ol>
  6550. <li>
  6551. <p>Configure Synapse with JWT logins, note that this example uses a pre-shared
  6552. secret and an algorithm of HS256:</p>
  6553. <pre><code class="language-yaml">jwt_config:
  6554. enabled: true
  6555. secret: &quot;my-secret-token&quot;
  6556. algorithm: &quot;HS256&quot;
  6557. </code></pre>
  6558. </li>
  6559. <li>
  6560. <p>Generate a JSON web token:</p>
  6561. <pre><code class="language-bash">$ pyjwt --key=my-secret-token --alg=HS256 encode sub=test-user
  6562. eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc
  6563. </code></pre>
  6564. </li>
  6565. <li>
  6566. <p>Query for the login types and ensure <code>org.matrix.login.jwt</code> is there:</p>
  6567. <pre><code class="language-bash">curl http://localhost:8080/_matrix/client/r0/login
  6568. </code></pre>
  6569. </li>
  6570. <li>
  6571. <p>Login used the generated JSON web token from above:</p>
  6572. <pre><code class="language-bash">$ curl http://localhost:8082/_matrix/client/r0/login -X POST \
  6573. --data '{&quot;type&quot;:&quot;org.matrix.login.jwt&quot;,&quot;token&quot;:&quot;eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ.Ag71GT8v01UO3w80aqRPTeuVPBIBZkYhNTJJ-_-zQIc&quot;}'
  6574. {
  6575. &quot;access_token&quot;: &quot;&lt;access token&gt;&quot;,
  6576. &quot;device_id&quot;: &quot;ACBDEFGHI&quot;,
  6577. &quot;home_server&quot;: &quot;localhost:8080&quot;,
  6578. &quot;user_id&quot;: &quot;@test-user:localhost:8480&quot;
  6579. }
  6580. </code></pre>
  6581. </li>
  6582. </ol>
  6583. <p>You should now be able to use the returned access token to query the client API.</p>
  6584. <div style="break-before: page; page-break-before: always;"></div><h1 id="overview-2"><a class="header" href="#overview-2">Overview</a></h1>
  6585. <p>A captcha can be enabled on your homeserver to help prevent bots from registering
  6586. accounts. Synapse currently uses Google's reCAPTCHA service which requires API keys
  6587. from Google.</p>
  6588. <h2 id="getting-api-keys"><a class="header" href="#getting-api-keys">Getting API keys</a></h2>
  6589. <ol>
  6590. <li>Create a new site at <a href="https://www.google.com/recaptcha/admin/create">https://www.google.com/recaptcha/admin/create</a></li>
  6591. <li>Set the label to anything you want</li>
  6592. <li>Set the type to reCAPTCHA v2 using the &quot;I'm not a robot&quot; Checkbox option.
  6593. This is the only type of captcha that works with Synapse.</li>
  6594. <li>Add the public hostname for your server, as set in <code>public_baseurl</code>
  6595. in <code>homeserver.yaml</code>, to the list of authorized domains. If you have not set
  6596. <code>public_baseurl</code>, use <code>server_name</code>.</li>
  6597. <li>Agree to the terms of service and submit.</li>
  6598. <li>Copy your site key and secret key and add them to your <code>homeserver.yaml</code>
  6599. configuration file
  6600. <pre><code>recaptcha_public_key: YOUR_SITE_KEY
  6601. recaptcha_private_key: YOUR_SECRET_KEY
  6602. </code></pre>
  6603. </li>
  6604. <li>Enable the CAPTCHA for new registrations
  6605. <pre><code>enable_registration_captcha: true
  6606. </code></pre>
  6607. </li>
  6608. <li>Go to the settings page for the CAPTCHA you just created</li>
  6609. <li>Uncheck the &quot;Verify the origin of reCAPTCHA solutions&quot; checkbox so that the
  6610. captcha can be displayed in any client. If you do not disable this option then you
  6611. must specify the domains of every client that is allowed to display the CAPTCHA.</li>
  6612. </ol>
  6613. <h2 id="configuring-ip-used-for-auth"><a class="header" href="#configuring-ip-used-for-auth">Configuring IP used for auth</a></h2>
  6614. <p>The reCAPTCHA API requires that the IP address of the user who solved the
  6615. CAPTCHA is sent. If the client is connecting through a proxy or load balancer,
  6616. it may be required to use the <code>X-Forwarded-For</code> (XFF) header instead of the origin
  6617. IP address. This can be configured using the <code>x_forwarded</code> directive in the
  6618. listeners section of the <code>homeserver.yaml</code> configuration file.</p>
  6619. <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>
  6620. <p>The registration of new application services depends on the homeserver used.
  6621. In synapse, you need to create a new configuration file for your AS and add it
  6622. to the list specified under the <code>app_service_config_files</code> config
  6623. option in your synapse config.</p>
  6624. <p>For example:</p>
  6625. <pre><code class="language-yaml">app_service_config_files:
  6626. - /home/matrix/.synapse/&lt;your-AS&gt;.yaml
  6627. </code></pre>
  6628. <p>The format of the AS configuration file is as follows:</p>
  6629. <pre><code class="language-yaml">url: &lt;base url of AS&gt;
  6630. as_token: &lt;token AS will add to requests to HS&gt;
  6631. hs_token: &lt;token HS will add to requests to AS&gt;
  6632. sender_localpart: &lt;localpart of AS user&gt;
  6633. namespaces:
  6634. users: # List of users we're interested in
  6635. - exclusive: &lt;bool&gt;
  6636. regex: &lt;regex&gt;
  6637. group_id: &lt;group&gt;
  6638. - ...
  6639. aliases: [] # List of aliases we're interested in
  6640. rooms: [] # List of room ids we're interested in
  6641. </code></pre>
  6642. <p><code>exclusive</code>: If enabled, only this application service is allowed to register users in its namespace(s).
  6643. <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>
  6644. <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>
  6645. <div style="break-before: page; page-break-before: always;"></div><h1 id="server-notices"><a class="header" href="#server-notices">Server Notices</a></h1>
  6646. <p>'Server Notices' are a new feature introduced in Synapse 0.30. They provide a
  6647. channel whereby server administrators can send messages to users on the server.</p>
  6648. <p>They are used as part of communication of the server polices (see
  6649. <a href="consent_tracking.html">Consent Tracking</a>), however the intention is that
  6650. they may also find a use for features such as &quot;Message of the day&quot;.</p>
  6651. <p>This is a feature specific to Synapse, but it uses standard Matrix
  6652. communication mechanisms, so should work with any Matrix client.</p>
  6653. <h2 id="user-experience"><a class="header" href="#user-experience">User experience</a></h2>
  6654. <p>When the user is first sent a server notice, they will get an invitation to a
  6655. room (typically called 'Server Notices', though this is configurable in
  6656. <code>homeserver.yaml</code>). They will be <strong>unable to reject</strong> this invitation -
  6657. attempts to do so will receive an error.</p>
  6658. <p>Once they accept the invitation, they will see the notice message in the room
  6659. history; it will appear to have come from the 'server notices user' (see
  6660. below).</p>
  6661. <p>The user is prevented from sending any messages in this room by the power
  6662. levels.</p>
  6663. <p>Having joined the room, the user can leave the room if they want. Subsequent
  6664. server notices will then cause a new room to be created.</p>
  6665. <h2 id="synapse-configuration"><a class="header" href="#synapse-configuration">Synapse configuration</a></h2>
  6666. <p>Server notices come from a specific user id on the server. Server
  6667. administrators are free to choose the user id - something like <code>server</code> is
  6668. suggested, meaning the notices will come from
  6669. <code>@server:&lt;your_server_name&gt;</code>. Once the Server Notices user is configured, that
  6670. user id becomes a special, privileged user, so administrators should ensure
  6671. that <strong>it is not already allocated</strong>.</p>
  6672. <p>In order to support server notices, it is necessary to add some configuration
  6673. to the <code>homeserver.yaml</code> file. In particular, you should add a <code>server_notices</code>
  6674. section, which should look like this:</p>
  6675. <pre><code class="language-yaml">server_notices:
  6676. system_mxid_localpart: server
  6677. system_mxid_display_name: &quot;Server Notices&quot;
  6678. system_mxid_avatar_url: &quot;mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ&quot;
  6679. room_name: &quot;Server Notices&quot;
  6680. </code></pre>
  6681. <p>The only compulsory setting is <code>system_mxid_localpart</code>, which defines the user
  6682. id of the Server Notices user, as above. <code>room_name</code> defines the name of the
  6683. room which will be created.</p>
  6684. <p><code>system_mxid_display_name</code> and <code>system_mxid_avatar_url</code> can be used to set the
  6685. displayname and avatar of the Server Notices user.</p>
  6686. <h2 id="sending-notices"><a class="header" href="#sending-notices">Sending notices</a></h2>
  6687. <p>To send server notices to users you can use the
  6688. <a href="admin_api/server_notices.html">admin_api</a>.</p>
  6689. <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>
  6690. <p>Synapse 0.30 introduces support for tracking whether users have agreed to the
  6691. terms and conditions set by the administrator of a server - and blocking access
  6692. to the server until they have.</p>
  6693. <p>There are several parts to this functionality; each requires some specific
  6694. configuration in <code>homeserver.yaml</code> to be enabled.</p>
  6695. <p>Note that various parts of the configuation and this document refer to the
  6696. &quot;privacy policy&quot;: agreement with a privacy policy is one particular use of this
  6697. feature, but of course adminstrators can specify other terms and conditions
  6698. unrelated to &quot;privacy&quot; per se.</p>
  6699. <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>
  6700. <p>Synapse can be configured to serve the user a simple policy form with an
  6701. &quot;accept&quot; button. Clicking &quot;Accept&quot; records the user's acceptance in the
  6702. database and shows a success page.</p>
  6703. <p>To enable this, first create templates for the policy and success pages.
  6704. These should be stored on the local filesystem.</p>
  6705. <p>These templates use the <a href="http://jinja.pocoo.org">Jinja2</a> templating language,
  6706. and <a href="https://github.com/matrix-org/synapse/tree/develop/docs/privacy_policy_templates/">docs/privacy_policy_templates</a>
  6707. gives examples of the sort of thing that can be done.</p>
  6708. <p>Note that the templates must be stored under a name giving the language of the
  6709. template - currently this must always be <code>en</code> (for &quot;English&quot;);
  6710. internationalisation support is intended for the future.</p>
  6711. <p>The template for the policy itself should be versioned and named according to
  6712. the version: for example <code>1.0.html</code>. The version of the policy which the user
  6713. has agreed to is stored in the database.</p>
  6714. <p>Once the templates are in place, make the following changes to <code>homeserver.yaml</code>:</p>
  6715. <ol>
  6716. <li>
  6717. <p>Add a <code>user_consent</code> section, which should look like:</p>
  6718. <pre><code class="language-yaml">user_consent:
  6719. template_dir: privacy_policy_templates
  6720. version: 1.0
  6721. </code></pre>
  6722. <p><code>template_dir</code> points to the directory containing the policy
  6723. templates. <code>version</code> defines the version of the policy which will be served
  6724. to the user. In the example above, Synapse will serve
  6725. <code>privacy_policy_templates/en/1.0.html</code>.</p>
  6726. </li>
  6727. <li>
  6728. <p>Add a <code>form_secret</code> setting at the top level:</p>
  6729. <pre><code class="language-yaml">form_secret: &quot;&lt;unique secret&gt;&quot;
  6730. </code></pre>
  6731. <p>This should be set to an arbitrary secret string (try <code>pwgen -y 30</code> to
  6732. generate suitable secrets).</p>
  6733. <p>More on what this is used for below.</p>
  6734. </li>
  6735. <li>
  6736. <p>Add <code>consent</code> wherever the <code>client</code> resource is currently enabled in the
  6737. <code>listeners</code> configuration. For example:</p>
  6738. <pre><code class="language-yaml">listeners:
  6739. - port: 8008
  6740. resources:
  6741. - names:
  6742. - client
  6743. - consent
  6744. </code></pre>
  6745. </li>
  6746. </ol>
  6747. <p>Finally, ensure that <code>jinja2</code> is installed. If you are using a virtualenv, this
  6748. should be a matter of <code>pip install Jinja2</code>. On debian, try <code>apt-get install python-jinja2</code>.</p>
  6749. <p>Once this is complete, and the server has been restarted, try visiting
  6750. <code>https://&lt;server&gt;/_matrix/consent</code>. If correctly configured, this should give
  6751. an error &quot;Missing string query parameter 'u'&quot;. It is now possible to manually
  6752. construct URIs where users can give their consent.</p>
  6753. <h3 id="enabling-consent-tracking-at-registration"><a class="header" href="#enabling-consent-tracking-at-registration">Enabling consent tracking at registration</a></h3>
  6754. <ol>
  6755. <li>
  6756. <p>Add the following to your configuration:</p>
  6757. <pre><code class="language-yaml">user_consent:
  6758. require_at_registration: true
  6759. policy_name: &quot;Privacy Policy&quot; # or whatever you'd like to call the policy
  6760. </code></pre>
  6761. </li>
  6762. <li>
  6763. <p>In your consent templates, make use of the <code>public_version</code> variable to
  6764. see if an unauthenticated user is viewing the page. This is typically
  6765. wrapped around the form that would be used to actually agree to the document:</p>
  6766. <pre><code>{% if not public_version %}
  6767. &lt;!-- The variables used here are only provided when the 'u' param is given to the homeserver --&gt;
  6768. &lt;form method=&quot;post&quot; action=&quot;consent&quot;&gt;
  6769. &lt;input type=&quot;hidden&quot; name=&quot;v&quot; value=&quot;{{version}}&quot;/&gt;
  6770. &lt;input type=&quot;hidden&quot; name=&quot;u&quot; value=&quot;{{user}}&quot;/&gt;
  6771. &lt;input type=&quot;hidden&quot; name=&quot;h&quot; value=&quot;{{userhmac}}&quot;/&gt;
  6772. &lt;input type=&quot;submit&quot; value=&quot;Sure thing!&quot;/&gt;
  6773. &lt;/form&gt;
  6774. {% endif %}
  6775. </code></pre>
  6776. </li>
  6777. <li>
  6778. <p>Restart Synapse to apply the changes.</p>
  6779. </li>
  6780. </ol>
  6781. <p>Visiting <code>https://&lt;server&gt;/_matrix/consent</code> should now give you a view of the privacy
  6782. document. This is what users will be able to see when registering for accounts.</p>
  6783. <h3 id="constructing-the-consent-uri"><a class="header" href="#constructing-the-consent-uri">Constructing the consent URI</a></h3>
  6784. <p>It may be useful to manually construct the &quot;consent URI&quot; for a given user - for
  6785. instance, in order to send them an email asking them to consent. To do this,
  6786. take the base <code>https://&lt;server&gt;/_matrix/consent</code> URL and add the following
  6787. query parameters:</p>
  6788. <ul>
  6789. <li>
  6790. <p><code>u</code>: the user id of the user. This can either be a full MXID
  6791. (<code>@user:server.com</code>) or just the localpart (<code>user</code>).</p>
  6792. </li>
  6793. <li>
  6794. <p><code>h</code>: hex-encoded HMAC-SHA256 of <code>u</code> using the <code>form_secret</code> as a key. It is
  6795. possible to calculate this on the commandline with something like:</p>
  6796. <pre><code class="language-bash">echo -n '&lt;user&gt;' | openssl sha256 -hmac '&lt;form_secret&gt;'
  6797. </code></pre>
  6798. <p>This should result in a URI which looks something like:
  6799. <code>https://&lt;server&gt;/_matrix/consent?u=&lt;user&gt;&amp;h=68a152465a4d...</code>.</p>
  6800. </li>
  6801. </ul>
  6802. <p>Note that not providing a <code>u</code> parameter will be interpreted as wanting to view
  6803. the document from an unauthenticated perspective, such as prior to registration.
  6804. Therefore, the <code>h</code> parameter is not required in this scenario. To enable this
  6805. behaviour, set <code>require_at_registration</code> to <code>true</code> in your <code>user_consent</code> config.</p>
  6806. <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>
  6807. <p>It is possible to configure Synapse to send a <a href="server_notices.html">server
  6808. notice</a> to anybody who has not yet agreed to the current
  6809. version of the policy. To do so:</p>
  6810. <ul>
  6811. <li>
  6812. <p>ensure that the consent resource is configured, as in the previous section</p>
  6813. </li>
  6814. <li>
  6815. <p>ensure that server notices are configured, as in <a href="server_notices.html">the server notice documentation</a>.</p>
  6816. </li>
  6817. <li>
  6818. <p>Add <code>server_notice_content</code> under <code>user_consent</code> in <code>homeserver.yaml</code>. For
  6819. example:</p>
  6820. <pre><code class="language-yaml">user_consent:
  6821. server_notice_content:
  6822. msgtype: m.text
  6823. body: &gt;-
  6824. Please give your consent to the privacy policy at %(consent_uri)s.
  6825. </code></pre>
  6826. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6827. consent uri for that user.</p>
  6828. </li>
  6829. <li>
  6830. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6831. URI that clients use to connect to the server. (It is used to construct
  6832. <code>consent_uri</code> in the server notice.)</p>
  6833. </li>
  6834. </ul>
  6835. <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>
  6836. <p>Synapse can be configured to block any attempts to join rooms or send messages
  6837. until the user has given their agreement to the policy. (Joining the server
  6838. notices room is exempted from this).</p>
  6839. <p>To enable this, add <code>block_events_error</code> under <code>user_consent</code>. For example:</p>
  6840. <pre><code class="language-yaml">user_consent:
  6841. block_events_error: &gt;-
  6842. You can't send any messages until you consent to the privacy policy at
  6843. %(consent_uri)s.
  6844. </code></pre>
  6845. <p>Synapse automatically replaces the placeholder <code>%(consent_uri)s</code> with the
  6846. consent uri for that user.</p>
  6847. <p>ensure that <code>public_baseurl</code> is set in <code>homeserver.yaml</code>, and gives the base
  6848. URI that clients use to connect to the server. (It is used to construct
  6849. <code>consent_uri</code> in the error.)</p>
  6850. <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>
  6851. <p>Design notes on a URL previewing service for Matrix:</p>
  6852. <p>Options are:</p>
  6853. <ol>
  6854. <li>Have an AS which listens for URLs, downloads them, and inserts an event that describes their metadata.</li>
  6855. </ol>
  6856. <ul>
  6857. <li>Pros:
  6858. <ul>
  6859. <li>Decouples the implementation entirely from Synapse.</li>
  6860. <li>Uses existing Matrix events &amp; content repo to store the metadata.</li>
  6861. </ul>
  6862. </li>
  6863. <li>Cons:
  6864. <ul>
  6865. <li>Which AS should provide this service for a room, and why should you trust it?</li>
  6866. <li>Doesn't work well with E2E; you'd have to cut the AS into every room</li>
  6867. <li>the AS would end up subscribing to every room anyway.</li>
  6868. </ul>
  6869. </li>
  6870. </ul>
  6871. <ol start="2">
  6872. <li>Have a generic preview API (nothing to do with Matrix) that provides a previewing service:</li>
  6873. </ol>
  6874. <ul>
  6875. <li>Pros:
  6876. <ul>
  6877. <li>Simple and flexible; can be used by any clients at any point</li>
  6878. </ul>
  6879. </li>
  6880. <li>Cons:
  6881. <ul>
  6882. <li>If each HS provides one of these independently, all the HSes in a room may needlessly DoS the target URI</li>
  6883. <li>We need somewhere to store the URL metadata rather than just using Matrix itself</li>
  6884. <li>We can't piggyback on matrix to distribute the metadata between HSes.</li>
  6885. </ul>
  6886. </li>
  6887. </ul>
  6888. <ol start="3">
  6889. <li>Make the synapse of the sending user responsible for spidering the URL and inserting an event asynchronously which describes the metadata.</li>
  6890. </ol>
  6891. <ul>
  6892. <li>Pros:
  6893. <ul>
  6894. <li>Works transparently for all clients</li>
  6895. <li>Piggy-backs nicely on using Matrix for distributing the metadata.</li>
  6896. <li>No confusion as to which AS</li>
  6897. </ul>
  6898. </li>
  6899. <li>Cons:
  6900. <ul>
  6901. <li>Doesn't work with E2E</li>
  6902. <li>We might want to decouple the implementation of the spider from the HS, given spider behaviour can be quite complicated and evolve much more rapidly than the HS. It's more like a bot than a core part of the server.</li>
  6903. </ul>
  6904. </li>
  6905. </ul>
  6906. <ol start="4">
  6907. <li>Make the sending client use the preview API and insert the event itself when successful.</li>
  6908. </ol>
  6909. <ul>
  6910. <li>Pros:
  6911. <ul>
  6912. <li>Works well with E2E</li>
  6913. <li>No custom server functionality</li>
  6914. <li>Lets the client customise the preview that they send (like on FB)</li>
  6915. </ul>
  6916. </li>
  6917. <li>Cons:
  6918. <ul>
  6919. <li>Entirely specific to the sending client, whereas it'd be nice if /any/ URL was correctly previewed if clients support it.</li>
  6920. </ul>
  6921. </li>
  6922. </ul>
  6923. <ol start="5">
  6924. <li>Have the option of specifying a shared (centralised) previewing service used by a room, to avoid all the different HSes in the room DoSing the target.</li>
  6925. </ol>
  6926. <p>Best solution is probably a combination of both 2 and 4.</p>
  6927. <ul>
  6928. <li>Sending clients do their best to create and send a preview at the point of sending the message, perhaps delaying the message until the preview is computed? (This also lets the user validate the preview before sending)</li>
  6929. <li>Receiving clients have the option of going and creating their own preview if one doesn't arrive soon enough (or if the original sender didn't create one)</li>
  6930. </ul>
  6931. <p>This is a bit magical though in that the preview could come from two entirely different sources - the sending HS or your local one. However, this can always be exposed to users: &quot;Generate your own URL previews if none are available?&quot;</p>
  6932. <p>This is tantamount also to senders calculating their own thumbnails for sending in advance of the main content - we are trusting the sender not to lie about the content in the thumbnail. Whereas currently thumbnails are calculated by the receiving homeserver to avoid this attack.</p>
  6933. <p>However, this kind of phishing attack does exist whether we let senders pick their thumbnails or not, in that a malicious sender can send normal text messages around the attachment claiming it to be legitimate. We could rely on (future) reputation/abuse management to punish users who phish (be it with bogus metadata or bogus descriptions). Bogus metadata is particularly bad though, especially if it's avoidable.</p>
  6934. <p>As a first cut, let's do #2 and have the receiver hit the API to calculate its own previews (as it does currently for image thumbnails). We can then extend/optimise this to option 4 as a special extra if needed.</p>
  6935. <h2 id="api"><a class="header" href="#api">API</a></h2>
  6936. <pre><code>GET /_matrix/media/r0/preview_url?url=http://wherever.com
  6937. 200 OK
  6938. {
  6939. &quot;og:type&quot; : &quot;article&quot;
  6940. &quot;og:url&quot; : &quot;https://twitter.com/matrixdotorg/status/684074366691356672&quot;
  6941. &quot;og:title&quot; : &quot;Matrix on Twitter&quot;
  6942. &quot;og:image&quot; : &quot;https://pbs.twimg.com/profile_images/500400952029888512/yI0qtFi7_400x400.png&quot;
  6943. &quot;og:description&quot; : &quot;“Synapse 0.12 is out! Lots of polishing, performance &amp;amp;amp; bugfixes: /sync API, /r0 prefix, fulltext search, 3PID invites https://t.co/5alhXLLEGP”&quot;
  6944. &quot;og:site_name&quot; : &quot;Twitter&quot;
  6945. }
  6946. </code></pre>
  6947. <ul>
  6948. <li>Downloads the URL
  6949. <ul>
  6950. <li>If HTML, just stores it in RAM and parses it for OG meta tags
  6951. <ul>
  6952. <li>Download any media OG meta tags to the media repo, and refer to them in the OG via mxc:// URIs.</li>
  6953. </ul>
  6954. </li>
  6955. <li>If a media filetype we know we can thumbnail: store it on disk, and hand it to the thumbnailer. Generate OG meta tags from the thumbnailer contents.</li>
  6956. <li>Otherwise, don't bother downloading further.</li>
  6957. </ul>
  6958. </li>
  6959. </ul>
  6960. <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>
  6961. <p>The user directory is currently maintained based on the 'visible' users
  6962. on this particular server - i.e. ones which your account shares a room with, or
  6963. who are present in a publicly viewable room present on the server.</p>
  6964. <p>The directory info is stored in various tables, which can (typically after
  6965. DB corruption) get stale or out of sync. If this happens, for now the
  6966. 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>
  6967. and then restart synapse. This should then start a background task to
  6968. flush the current tables and regenerate the directory.</p>
  6969. <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>
  6970. <p>Synapse admins can enable support for message retention policies on
  6971. their homeserver. Message retention policies exist at a room level,
  6972. follow the semantics described in
  6973. <a href="https://github.com/matrix-org/matrix-doc/blob/matthew/msc1763/proposals/1763-configurable-retention-periods.md">MSC1763</a>,
  6974. and allow server and room admins to configure how long messages should
  6975. be kept in a homeserver's database before being purged from it.
  6976. <strong>Please note that, as this feature isn't part of the Matrix
  6977. specification yet, this implementation is to be considered as
  6978. experimental.</strong> </p>
  6979. <p>A message retention policy is mainly defined by its <code>max_lifetime</code>
  6980. parameter, which defines how long a message can be kept around after
  6981. it was sent to the room. If a room doesn't have a message retention
  6982. policy, and there's no default one for a given server, then no message
  6983. sent in that room is ever purged on that server.</p>
  6984. <p>MSC1763 also specifies semantics for a <code>min_lifetime</code> parameter which
  6985. defines the amount of time after which an event <em>can</em> get purged (after
  6986. it was sent to the room), but Synapse doesn't currently support it
  6987. beyond registering it.</p>
  6988. <p>Both <code>max_lifetime</code> and <code>min_lifetime</code> are optional parameters.</p>
  6989. <p>Note that message retention policies don't apply to state events.</p>
  6990. <p>Once an event reaches its expiry date (defined as the time it was sent
  6991. plus the value for <code>max_lifetime</code> in the room), two things happen:</p>
  6992. <ul>
  6993. <li>Synapse stops serving the event to clients via any endpoint.</li>
  6994. <li>The message gets picked up by the next purge job (see the &quot;Purge jobs&quot;
  6995. section) and is removed from Synapse's database.</li>
  6996. </ul>
  6997. <p>Since purge jobs don't run continuously, this means that an event might
  6998. stay in a server's database for longer than the value for <code>max_lifetime</code>
  6999. in the room would allow, though hidden from clients.</p>
  7000. <p>Similarly, if a server (with support for message retention policies
  7001. enabled) receives from another server an event that should have been
  7002. purged according to its room's policy, then the receiving server will
  7003. process and store that event until it's picked up by the next purge job,
  7004. though it will always hide it from clients.</p>
  7005. <p>Synapse requires at least one message in each room, so it will never
  7006. delete the last message in a room. It will, however, hide it from
  7007. clients.</p>
  7008. <h2 id="server-configuration"><a class="header" href="#server-configuration">Server configuration</a></h2>
  7009. <p>Support for this feature can be enabled and configured in the
  7010. <code>retention</code> section of the Synapse configuration file (see the
  7011. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample file</a>).</p>
  7012. <p>To enable support for message retention policies, set the setting
  7013. <code>enabled</code> in this section to <code>true</code>.</p>
  7014. <h3 id="default-policy"><a class="header" href="#default-policy">Default policy</a></h3>
  7015. <p>A default message retention policy is a policy defined in Synapse's
  7016. configuration that is used by Synapse for every room that doesn't have a
  7017. message retention policy configured in its state. This allows server
  7018. admins to ensure that messages are never kept indefinitely in a server's
  7019. database. </p>
  7020. <p>A default policy can be defined as such, in the <code>retention</code> section of
  7021. the configuration file:</p>
  7022. <pre><code class="language-yaml"> default_policy:
  7023. min_lifetime: 1d
  7024. max_lifetime: 1y
  7025. </code></pre>
  7026. <p>Here, <code>min_lifetime</code> and <code>max_lifetime</code> have the same meaning and level
  7027. of support as previously described. They can be expressed either as a
  7028. duration (using the units <code>s</code> (seconds), <code>m</code> (minutes), <code>h</code> (hours),
  7029. <code>d</code> (days), <code>w</code> (weeks) and <code>y</code> (years)) or as a number of milliseconds.</p>
  7030. <h3 id="purge-jobs"><a class="header" href="#purge-jobs">Purge jobs</a></h3>
  7031. <p>Purge jobs are the jobs that Synapse runs in the background to purge
  7032. expired events from the database. They are only run if support for
  7033. message retention policies is enabled in the server's configuration. If
  7034. no configuration for purge jobs is configured by the server admin,
  7035. Synapse will use a default configuration, which is described in the
  7036. <a href="https://github.com/matrix-org/synapse/blob/v1.36.0/docs/sample_config.yaml#L451-L518">sample configuration file</a>.</p>
  7037. <p>Some server admins might want a finer control on when events are removed
  7038. depending on an event's room's policy. This can be done by setting the
  7039. <code>purge_jobs</code> sub-section in the <code>retention</code> section of the configuration
  7040. file. An example of such configuration could be:</p>
  7041. <pre><code class="language-yaml"> purge_jobs:
  7042. - longest_max_lifetime: 3d
  7043. interval: 12h
  7044. - shortest_max_lifetime: 3d
  7045. longest_max_lifetime: 1w
  7046. interval: 1d
  7047. - shortest_max_lifetime: 1w
  7048. interval: 2d
  7049. </code></pre>
  7050. <p>In this example, we define three jobs:</p>
  7051. <ul>
  7052. <li>one that runs twice a day (every 12 hours) and purges events in rooms
  7053. which policy's <code>max_lifetime</code> is lower or equal to 3 days.</li>
  7054. <li>one that runs once a day and purges events in rooms which policy's
  7055. <code>max_lifetime</code> is between 3 days and a week.</li>
  7056. <li>one that runs once every 2 days and purges events in rooms which
  7057. policy's <code>max_lifetime</code> is greater than a week.</li>
  7058. </ul>
  7059. <p>Note that this example is tailored to show different configurations and
  7060. features slightly more jobs than it's probably necessary (in practice, a
  7061. server admin would probably consider it better to replace the two last
  7062. jobs with one that runs once a day and handles rooms which which
  7063. policy's <code>max_lifetime</code> is greater than 3 days).</p>
  7064. <p>Keep in mind, when configuring these jobs, that a purge job can become
  7065. quite heavy on the server if it targets many rooms, therefore prefer
  7066. having jobs with a low interval that target a limited set of rooms. Also
  7067. make sure to include a job with no minimum and one with no maximum to
  7068. make sure your configuration handles every policy.</p>
  7069. <p>As previously mentioned in this documentation, while a purge job that
  7070. runs e.g. every day means that an expired event might stay in the
  7071. database for up to a day after its expiry, Synapse hides expired events
  7072. from clients as soon as they expire, so the event is not visible to
  7073. local users between its expiry date and the moment it gets purged from
  7074. the server's database.</p>
  7075. <h3 id="lifetime-limits"><a class="header" href="#lifetime-limits">Lifetime limits</a></h3>
  7076. <p>Server admins can set limits on the values of <code>max_lifetime</code> to use when
  7077. purging old events in a room. These limits can be defined as such in the
  7078. <code>retention</code> section of the configuration file:</p>
  7079. <pre><code class="language-yaml"> allowed_lifetime_min: 1d
  7080. allowed_lifetime_max: 1y
  7081. </code></pre>
  7082. <p>The limits are considered when running purge jobs. If necessary, the
  7083. effective value of <code>max_lifetime</code> will be brought between
  7084. <code>allowed_lifetime_min</code> and <code>allowed_lifetime_max</code> (inclusive).
  7085. This means that, if the value of <code>max_lifetime</code> defined in the room's state
  7086. is lower than <code>allowed_lifetime_min</code>, the value of <code>allowed_lifetime_min</code>
  7087. will be used instead. Likewise, if the value of <code>max_lifetime</code> is higher
  7088. than <code>allowed_lifetime_max</code>, the value of <code>allowed_lifetime_max</code> will be
  7089. used instead.</p>
  7090. <p>In the example above, we ensure Synapse never deletes events that are less
  7091. than one day old, and that it always deletes events that are over a year
  7092. old.</p>
  7093. <p>If a default policy is set, and its <code>max_lifetime</code> value is lower than
  7094. <code>allowed_lifetime_min</code> or higher than <code>allowed_lifetime_max</code>, the same
  7095. process applies.</p>
  7096. <p>Both parameters are optional; if one is omitted Synapse won't use it to
  7097. adjust the effective value of <code>max_lifetime</code>.</p>
  7098. <p>Like other settings in this section, these parameters can be expressed
  7099. either as a duration or as a number of milliseconds.</p>
  7100. <h2 id="room-configuration"><a class="header" href="#room-configuration">Room configuration</a></h2>
  7101. <p>To configure a room's message retention policy, a room's admin or
  7102. moderator needs to send a state event in that room with the type
  7103. <code>m.room.retention</code> and the following content:</p>
  7104. <pre><code class="language-json">{
  7105. &quot;max_lifetime&quot;: ...
  7106. }
  7107. </code></pre>
  7108. <p>In this event's content, the <code>max_lifetime</code> parameter has the same
  7109. meaning as previously described, and needs to be expressed in
  7110. milliseconds. The event's content can also include a <code>min_lifetime</code>
  7111. parameter, which has the same meaning and limited support as previously
  7112. described.</p>
  7113. <p>Note that over every server in the room, only the ones with support for
  7114. message retention policies will actually remove expired events. This
  7115. support is currently not enabled by default in Synapse.</p>
  7116. <h2 id="note-on-reclaiming-disk-space"><a class="header" href="#note-on-reclaiming-disk-space">Note on reclaiming disk space</a></h2>
  7117. <p>While purge jobs actually delete data from the database, the disk space
  7118. used by the database might not decrease immediately on the database's
  7119. host. However, even though the database engine won't free up the disk
  7120. space, it will start writing new data into where the purged data was.</p>
  7121. <p>If you want to reclaim the freed disk space anyway and return it to the
  7122. operating system, the server admin needs to run <code>VACUUM FULL;</code> (or
  7123. <code>VACUUM;</code> for SQLite databases) on Synapse's database (see the related
  7124. <a href="https://www.postgresql.org/docs/current/sql-vacuum.html">PostgreSQL documentation</a>).</p>
  7125. <div style="break-before: page; page-break-before: always;"></div><h1 id="modules"><a class="header" href="#modules">Modules</a></h1>
  7126. <p>Synapse supports extending its functionality by configuring external modules.</p>
  7127. <h2 id="using-modules"><a class="header" href="#using-modules">Using modules</a></h2>
  7128. <p>To use a module on Synapse, add it to the <code>modules</code> section of the configuration file:</p>
  7129. <pre><code class="language-yaml">modules:
  7130. - module: my_super_module.MySuperClass
  7131. config:
  7132. do_thing: true
  7133. - module: my_other_super_module.SomeClass
  7134. config: {}
  7135. </code></pre>
  7136. <p>Each module is defined by a path to a Python class as well as a configuration. This
  7137. information for a given module should be available in the module's own documentation.</p>
  7138. <p><strong>Note</strong>: When using third-party modules, you effectively allow someone else to run
  7139. custom code on your Synapse homeserver. Server admins are encouraged to verify the
  7140. provenance of the modules they use on their homeserver and make sure the modules aren't
  7141. running malicious code on their instance.</p>
  7142. <p>Also note that we are currently in the process of migrating module interfaces to this
  7143. system. While some interfaces might be compatible with it, others still require
  7144. configuring modules in another part of Synapse's configuration file. Currently, only the
  7145. spam checker interface is compatible with this new system.</p>
  7146. <h2 id="writing-a-module"><a class="header" href="#writing-a-module">Writing a module</a></h2>
  7147. <p>A module is a Python class that uses Synapse's module API to interact with the
  7148. homeserver. It can register callbacks that Synapse will call on specific operations, as
  7149. well as web resources to attach to Synapse's web server.</p>
  7150. <p>When instantiated, a module is given its parsed configuration as well as an instance of
  7151. the <code>synapse.module_api.ModuleApi</code> class. The configuration is a dictionary, and is
  7152. either the output of the module's <code>parse_config</code> static method (see below), or the
  7153. configuration associated with the module in Synapse's configuration file.</p>
  7154. <p>See the documentation for the <code>ModuleApi</code> class
  7155. <a href="https://github.com/matrix-org/synapse/blob/master/synapse/module_api/__init__.py">here</a>.</p>
  7156. <h3 id="handling-the-modules-configuration"><a class="header" href="#handling-the-modules-configuration">Handling the module's configuration</a></h3>
  7157. <p>A module can implement the following static method:</p>
  7158. <pre><code class="language-python">@staticmethod
  7159. def parse_config(config: dict) -&gt; dict
  7160. </code></pre>
  7161. <p>This method is given a dictionary resulting from parsing the YAML configuration for the
  7162. module. It may modify it (for example by parsing durations expressed as strings (e.g.
  7163. &quot;5d&quot;) into milliseconds, etc.), and return the modified dictionary. It may also verify
  7164. that the configuration is correct, and raise an instance of
  7165. <code>synapse.module_api.errors.ConfigError</code> if not.</p>
  7166. <h3 id="registering-a-web-resource"><a class="header" href="#registering-a-web-resource">Registering a web resource</a></h3>
  7167. <p>Modules can register web resources onto Synapse's web server using the following module
  7168. API method:</p>
  7169. <pre><code class="language-python">def ModuleApi.register_web_resource(path: str, resource: IResource) -&gt; None
  7170. </code></pre>
  7171. <p>The path is the full absolute path to register the resource at. For example, if you
  7172. register a resource for the path <code>/_synapse/client/my_super_module/say_hello</code>, Synapse
  7173. will serve it at <code>http(s)://[HS_URL]/_synapse/client/my_super_module/say_hello</code>. Note
  7174. that Synapse does not allow registering resources for several sub-paths in the <code>/_matrix</code>
  7175. namespace (such as anything under <code>/_matrix/client</code> for example). It is strongly
  7176. recommended that modules register their web resources under the <code>/_synapse/client</code>
  7177. namespace.</p>
  7178. <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>
  7179. interface (such as <a href="https://twistedmatrix.com/documents/current/api/twisted.web.resource.Resource.html">Resource</a>).</p>
  7180. <p>Only one resource can be registered for a given path. If several modules attempt to
  7181. register a resource for the same path, the module that appears first in Synapse's
  7182. configuration file takes priority.</p>
  7183. <p>Modules <strong>must</strong> register their web resources in their <code>__init__</code> method.</p>
  7184. <h3 id="registering-a-callback"><a class="header" href="#registering-a-callback">Registering a callback</a></h3>
  7185. <p>Modules can use Synapse's module API to register callbacks. Callbacks are functions that
  7186. Synapse will call when performing specific actions. Callbacks must be asynchronous, and
  7187. are split in categories. A single module may implement callbacks from multiple categories,
  7188. and is under no obligation to implement all callbacks from the categories it registers
  7189. callbacks for.</p>
  7190. <p>Modules can register callbacks using one of the module API's <code>register_[...]_callbacks</code>
  7191. methods. The callback functions are passed to these methods as keyword arguments, with
  7192. the callback name as the argument name and the function as its value. This is demonstrated
  7193. in the example below. A <code>register_[...]_callbacks</code> method exists for each module type
  7194. documented in this section.</p>
  7195. <h4 id="spam-checker-callbacks"><a class="header" href="#spam-checker-callbacks">Spam checker callbacks</a></h4>
  7196. <p>Spam checker callbacks allow module developers to implement spam mitigation actions for
  7197. Synapse instances. Spam checker callbacks can be registered using the module API's
  7198. <code>register_spam_checker_callbacks</code> method.</p>
  7199. <p>The available spam checker callbacks are:</p>
  7200. <pre><code class="language-python">async def check_event_for_spam(event: &quot;synapse.events.EventBase&quot;) -&gt; Union[bool, str]
  7201. </code></pre>
  7202. <p>Called when receiving an event from a client or via federation. The module can return
  7203. either a <code>bool</code> to indicate whether the event must be rejected because of spam, or a <code>str</code>
  7204. to indicate the event must be rejected because of spam and to give a rejection reason to
  7205. forward to clients.</p>
  7206. <pre><code class="language-python">async def user_may_invite(inviter: str, invitee: str, room_id: str) -&gt; bool
  7207. </code></pre>
  7208. <p>Called when processing an invitation. The module must return a <code>bool</code> indicating whether
  7209. the inviter can invite the invitee to the given room. Both inviter and invitee are
  7210. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7211. <pre><code class="language-python">async def user_may_create_room(user: str) -&gt; bool
  7212. </code></pre>
  7213. <p>Called when processing a room creation request. The module must return a <code>bool</code> indicating
  7214. whether the given user (represented by their Matrix user ID) is allowed to create a room.</p>
  7215. <pre><code class="language-python">async def user_may_create_room_alias(user: str, room_alias: &quot;synapse.types.RoomAlias&quot;) -&gt; bool
  7216. </code></pre>
  7217. <p>Called when trying to associate an alias with an existing room. The module must return a
  7218. <code>bool</code> indicating whether the given user (represented by their Matrix user ID) is allowed
  7219. to set the given alias.</p>
  7220. <pre><code class="language-python">async def user_may_publish_room(user: str, room_id: str) -&gt; bool
  7221. </code></pre>
  7222. <p>Called when trying to publish a room to the homeserver's public rooms directory. The
  7223. module must return a <code>bool</code> indicating whether the given user (represented by their
  7224. Matrix user ID) is allowed to publish the given room.</p>
  7225. <pre><code class="language-python">async def check_username_for_spam(user_profile: Dict[str, str]) -&gt; bool
  7226. </code></pre>
  7227. <p>Called when computing search results in the user directory. The module must return a
  7228. <code>bool</code> indicating whether the given user profile can appear in search results. The profile
  7229. is represented as a dictionary with the following keys:</p>
  7230. <ul>
  7231. <li><code>user_id</code>: The Matrix ID for this user.</li>
  7232. <li><code>display_name</code>: The user's display name.</li>
  7233. <li><code>avatar_url</code>: The <code>mxc://</code> URL to the user's avatar.</li>
  7234. </ul>
  7235. <p>The module is given a copy of the original dictionary, so modifying it from within the
  7236. module cannot modify a user's profile when included in user directory search results.</p>
  7237. <pre><code class="language-python">async def check_registration_for_spam(
  7238. email_threepid: Optional[dict],
  7239. username: Optional[str],
  7240. request_info: Collection[Tuple[str, str]],
  7241. auth_provider_id: Optional[str] = None,
  7242. ) -&gt; &quot;synapse.spam_checker_api.RegistrationBehaviour&quot;
  7243. </code></pre>
  7244. <p>Called when registering a new user. The module must return a <code>RegistrationBehaviour</code>
  7245. indicating whether the registration can go through or must be denied, or whether the user
  7246. may be allowed to register but will be shadow banned.</p>
  7247. <p>The arguments passed to this callback are:</p>
  7248. <ul>
  7249. <li><code>email_threepid</code>: The email address used for registering, if any.</li>
  7250. <li><code>username</code>: The username the user would like to register. Can be <code>None</code>, meaning that
  7251. Synapse will generate one later.</li>
  7252. <li><code>request_info</code>: A collection of tuples, which first item is a user agent, and which
  7253. second item is an IP address. These user agents and IP addresses are the ones that were
  7254. used during the registration process.</li>
  7255. <li><code>auth_provider_id</code>: The identifier of the SSO authentication provider, if any.</li>
  7256. </ul>
  7257. <pre><code class="language-python">async def check_media_file_for_spam(
  7258. file_wrapper: &quot;synapse.rest.media.v1.media_storage.ReadableFileWrapper&quot;,
  7259. file_info: &quot;synapse.rest.media.v1._base.FileInfo&quot;,
  7260. ) -&gt; bool
  7261. </code></pre>
  7262. <p>Called when storing a local or remote file. The module must return a boolean indicating
  7263. whether the given file can be stored in the homeserver's media store.</p>
  7264. <h4 id="account-validity-callbacks"><a class="header" href="#account-validity-callbacks">Account validity callbacks</a></h4>
  7265. <p>Account validity callbacks allow module developers to add extra steps to verify the
  7266. validity on an account, i.e. see if a user can be granted access to their account on the
  7267. Synapse instance. Account validity callbacks can be registered using the module API's
  7268. <code>register_account_validity_callbacks</code> method.</p>
  7269. <p>The available account validity callbacks are:</p>
  7270. <pre><code class="language-python">async def is_user_expired(user: str) -&gt; Optional[bool]
  7271. </code></pre>
  7272. <p>Called when processing any authenticated request (except for logout requests). The module
  7273. can return a <code>bool</code> to indicate whether the user has expired and should be locked out of
  7274. their account, or <code>None</code> if the module wasn't able to figure it out. The user is
  7275. represented by their Matrix user ID (e.g. <code>@alice:example.com</code>).</p>
  7276. <p>If the module returns <code>True</code>, the current request will be denied with the error code
  7277. <code>ORG_MATRIX_EXPIRED_ACCOUNT</code> and the HTTP status code 403. Note that this doesn't
  7278. invalidate the user's access token.</p>
  7279. <pre><code class="language-python">async def on_user_registration(user: str) -&gt; None
  7280. </code></pre>
  7281. <p>Called after successfully registering a user, in case the module needs to perform extra
  7282. operations to keep track of them. (e.g. add them to a database table). The user is
  7283. represented by their Matrix user ID.</p>
  7284. <h4 id="third-party-rules-callbacks"><a class="header" href="#third-party-rules-callbacks">Third party rules callbacks</a></h4>
  7285. <p>Third party rules callbacks allow module developers to add extra checks to verify the
  7286. validity of incoming events. Third party event rules callbacks can be registered using
  7287. the module API's <code>register_third_party_rules_callbacks</code> method.</p>
  7288. <p>The available third party rules callbacks are:</p>
  7289. <pre><code class="language-python">async def check_event_allowed(
  7290. event: &quot;synapse.events.EventBase&quot;,
  7291. state_events: &quot;synapse.types.StateMap&quot;,
  7292. ) -&gt; Tuple[bool, Optional[dict]]
  7293. </code></pre>
  7294. <p><strong><span style="color:red">
  7295. This callback is very experimental and can and will break without notice. Module developers
  7296. are encouraged to implement <code>check_event_for_spam</code> from the spam checker category instead.
  7297. </span></strong></p>
  7298. <p>Called when processing any incoming event, with the event and a <code>StateMap</code>
  7299. representing the current state of the room the event is being sent into. A <code>StateMap</code> is
  7300. a dictionary that maps tuples containing an event type and a state key to the
  7301. corresponding state event. For example retrieving the room's <code>m.room.create</code> event from
  7302. the <code>state_events</code> argument would look like this: <code>state_events.get((&quot;m.room.create&quot;, &quot;&quot;))</code>.
  7303. The module must return a boolean indicating whether the event can be allowed.</p>
  7304. <p>Note that this callback function processes incoming events coming via federation
  7305. traffic (on top of client traffic). This means denying an event might cause the local
  7306. copy of the room's history to diverge from that of remote servers. This may cause
  7307. federation issues in the room. It is strongly recommended to only deny events using this
  7308. callback function if the sender is a local user, or in a private federation in which all
  7309. servers are using the same module, with the same configuration.</p>
  7310. <p>If the boolean returned by the module is <code>True</code>, it may also tell Synapse to replace the
  7311. event with new data by returning the new event's data as a dictionary. In order to do
  7312. that, it is recommended the module calls <code>event.get_dict()</code> to get the current event as a
  7313. dictionary, and modify the returned dictionary accordingly.</p>
  7314. <p>Note that replacing the event only works for events sent by local users, not for events
  7315. received over federation.</p>
  7316. <pre><code class="language-python">async def on_create_room(
  7317. requester: &quot;synapse.types.Requester&quot;,
  7318. request_content: dict,
  7319. is_requester_admin: bool,
  7320. ) -&gt; None
  7321. </code></pre>
  7322. <p>Called when processing a room creation request, with the <code>Requester</code> object for the user
  7323. performing the request, a dictionary representing the room creation request's JSON body
  7324. (see <a href="https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-createroom">the spec</a>
  7325. for a list of possible parameters), and a boolean indicating whether the user performing
  7326. the request is a server admin.</p>
  7327. <p>Modules can modify the <code>request_content</code> (by e.g. adding events to its <code>initial_state</code>),
  7328. or deny the room's creation by raising a <code>module_api.errors.SynapseError</code>.</p>
  7329. <h4 id="presence-router-callbacks"><a class="header" href="#presence-router-callbacks">Presence router callbacks</a></h4>
  7330. <p>Presence router callbacks allow module developers to specify additional users (local or remote)
  7331. to receive certain presence updates from local users. Presence router callbacks can be
  7332. registered using the module API's <code>register_presence_router_callbacks</code> method.</p>
  7333. <p>The available presence router callbacks are:</p>
  7334. <pre><code class="language-python">async def get_users_for_states(
  7335. self,
  7336. state_updates: Iterable[&quot;synapse.api.UserPresenceState&quot;],
  7337. ) -&gt; Dict[str, Set[&quot;synapse.api.UserPresenceState&quot;]]:
  7338. </code></pre>
  7339. <p><strong>Requires</strong> <code>get_interested_users</code> to also be registered</p>
  7340. <p>Called when processing updates to the presence state of one or more users. This callback can
  7341. be used to instruct the server to forward that presence state to specific users. The module
  7342. must return a dictionary that maps from Matrix user IDs (which can be local or remote) to the
  7343. <code>UserPresenceState</code> changes that they should be forwarded.</p>
  7344. <p>Synapse will then attempt to send the specified presence updates to each user when possible.</p>
  7345. <pre><code class="language-python">async def get_interested_users(
  7346. self,
  7347. user_id: str
  7348. ) -&gt; Union[Set[str], &quot;synapse.module_api.PRESENCE_ALL_USERS&quot;]
  7349. </code></pre>
  7350. <p><strong>Requires</strong> <code>get_users_for_states</code> to also be registered</p>
  7351. <p>Called when determining which users someone should be able to see the presence state of. This
  7352. callback should return complementary results to <code>get_users_for_state</code> or the presence information
  7353. may not be properly forwarded.</p>
  7354. <p>The callback is given the Matrix user ID for a local user that is requesting presence data and
  7355. should return the Matrix user IDs of the users whose presence state they are allowed to
  7356. query. The returned users can be local or remote. </p>
  7357. <p>Alternatively the callback can return <code>synapse.module_api.PRESENCE_ALL_USERS</code>
  7358. to indicate that the user should receive updates from all known users.</p>
  7359. <p>For example, if the user <code>@alice:example.org</code> is passed to this method, and the Set
  7360. <code>{&quot;@bob:example.com&quot;, &quot;@charlie:somewhere.org&quot;}</code> is returned, this signifies that Alice
  7361. should receive presence updates sent by Bob and Charlie, regardless of whether these users
  7362. share a room.</p>
  7363. <h3 id="porting-an-existing-module-that-uses-the-old-interface"><a class="header" href="#porting-an-existing-module-that-uses-the-old-interface">Porting an existing module that uses the old interface</a></h3>
  7364. <p>In order to port a module that uses Synapse's old module interface, its author needs to:</p>
  7365. <ul>
  7366. <li>ensure the module's callbacks are all asynchronous.</li>
  7367. <li>register their callbacks using one or more of the <code>register_[...]_callbacks</code> methods
  7368. from the <code>ModuleApi</code> class in the module's <code>__init__</code> method (see <a href="modules.html#registering-a-callback">this section</a>
  7369. for more info).</li>
  7370. </ul>
  7371. <p>Additionally, if the module is packaged with an additional web resource, the module
  7372. should register this resource in its <code>__init__</code> method using the <code>register_web_resource</code>
  7373. method from the <code>ModuleApi</code> class (see <a href="modules.html#registering-a-web-resource">this section</a> for
  7374. more info).</p>
  7375. <p>The module's author should also update any example in the module's configuration to only
  7376. use the new <code>modules</code> section in Synapse's configuration file (see <a href="modules.html#using-modules">this section</a>
  7377. for more info).</p>
  7378. <h3 id="example"><a class="header" href="#example">Example</a></h3>
  7379. <p>The example below is a module that implements the spam checker callback
  7380. <code>user_may_create_room</code> to deny room creation to user <code>@evilguy:example.com</code>, and registers
  7381. a web resource to the path <code>/_synapse/client/demo/hello</code> that returns a JSON object.</p>
  7382. <pre><code class="language-python">import json
  7383. from twisted.web.resource import Resource
  7384. from twisted.web.server import Request
  7385. from synapse.module_api import ModuleApi
  7386. class DemoResource(Resource):
  7387. def __init__(self, config):
  7388. super(DemoResource, self).__init__()
  7389. self.config = config
  7390. def render_GET(self, request: Request):
  7391. name = request.args.get(b&quot;name&quot;)[0]
  7392. request.setHeader(b&quot;Content-Type&quot;, b&quot;application/json&quot;)
  7393. return json.dumps({&quot;hello&quot;: name})
  7394. class DemoModule:
  7395. def __init__(self, config: dict, api: ModuleApi):
  7396. self.config = config
  7397. self.api = api
  7398. self.api.register_web_resource(
  7399. path=&quot;/_synapse/client/demo/hello&quot;,
  7400. resource=DemoResource(self.config),
  7401. )
  7402. self.api.register_spam_checker_callbacks(
  7403. user_may_create_room=self.user_may_create_room,
  7404. )
  7405. @staticmethod
  7406. def parse_config(config):
  7407. return config
  7408. async def user_may_create_room(self, user: str) -&gt; bool:
  7409. if user == &quot;@evilguy:example.com&quot;:
  7410. return False
  7411. return True
  7412. </code></pre>
  7413. <div style="break-before: page; page-break-before: always;"></div><h2 style="color:red">
  7414. This page of the Synapse documentation is now deprecated. For up to date
  7415. documentation on setting up or writing a spam checker module, please see
  7416. <a href="modules.html">this page</a>.
  7417. </h2>
  7418. <h1 id="handling-spam-in-synapse"><a class="header" href="#handling-spam-in-synapse">Handling spam in Synapse</a></h1>
  7419. <p>Synapse has support to customize spam checking behavior. It can plug into a
  7420. variety of events and affect how they are presented to users on your homeserver.</p>
  7421. <p>The spam checking behavior is implemented as a Python class, which must be
  7422. able to be imported by the running Synapse.</p>
  7423. <h2 id="python-spam-checker-class"><a class="header" href="#python-spam-checker-class">Python spam checker class</a></h2>
  7424. <p>The Python class is instantiated with two objects:</p>
  7425. <ul>
  7426. <li>Any configuration (see below).</li>
  7427. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7428. </ul>
  7429. <p>It then implements methods which return a boolean to alter behavior in Synapse.
  7430. All the methods must be defined.</p>
  7431. <p>There's a generic method for checking every event (<code>check_event_for_spam</code>), as
  7432. well as some specific methods:</p>
  7433. <ul>
  7434. <li><code>user_may_invite</code></li>
  7435. <li><code>user_may_create_room</code></li>
  7436. <li><code>user_may_create_room_alias</code></li>
  7437. <li><code>user_may_publish_room</code></li>
  7438. <li><code>check_username_for_spam</code></li>
  7439. <li><code>check_registration_for_spam</code></li>
  7440. <li><code>check_media_file_for_spam</code></li>
  7441. </ul>
  7442. <p>The details of each of these methods (as well as their inputs and outputs)
  7443. are documented in the <code>synapse.events.spamcheck.SpamChecker</code> class.</p>
  7444. <p>The <code>ModuleApi</code> class provides a way for the custom spam checker class to
  7445. call back into the homeserver internals.</p>
  7446. <p>Additionally, a <code>parse_config</code> method is mandatory and receives the plugin config
  7447. dictionary. After parsing, It must return an object which will be
  7448. passed to <code>__init__</code> later.</p>
  7449. <h3 id="example-1"><a class="header" href="#example-1">Example</a></h3>
  7450. <pre><code class="language-python">from synapse.spam_checker_api import RegistrationBehaviour
  7451. class ExampleSpamChecker:
  7452. def __init__(self, config, api):
  7453. self.config = config
  7454. self.api = api
  7455. @staticmethod
  7456. def parse_config(config):
  7457. return config
  7458. async def check_event_for_spam(self, foo):
  7459. return False # allow all events
  7460. async def user_may_invite(self, inviter_userid, invitee_userid, room_id):
  7461. return True # allow all invites
  7462. async def user_may_create_room(self, userid):
  7463. return True # allow all room creations
  7464. async def user_may_create_room_alias(self, userid, room_alias):
  7465. return True # allow all room aliases
  7466. async def user_may_publish_room(self, userid, room_id):
  7467. return True # allow publishing of all rooms
  7468. async def check_username_for_spam(self, user_profile):
  7469. return False # allow all usernames
  7470. async def check_registration_for_spam(
  7471. self,
  7472. email_threepid,
  7473. username,
  7474. request_info,
  7475. auth_provider_id,
  7476. ):
  7477. return RegistrationBehaviour.ALLOW # allow all registrations
  7478. async def check_media_file_for_spam(self, file_wrapper, file_info):
  7479. return False # allow all media
  7480. </code></pre>
  7481. <h2 id="configuration-2"><a class="header" href="#configuration-2">Configuration</a></h2>
  7482. <p>Modify the <code>spam_checker</code> section of your <code>homeserver.yaml</code> in the following
  7483. manner:</p>
  7484. <p>Create a list entry with the keys <code>module</code> and <code>config</code>.</p>
  7485. <ul>
  7486. <li>
  7487. <p><code>module</code> should point to the fully qualified Python class that implements your
  7488. custom logic, e.g. <code>my_module.ExampleSpamChecker</code>.</p>
  7489. </li>
  7490. <li>
  7491. <p><code>config</code> is a dictionary that gets passed to the spam checker class.</p>
  7492. </li>
  7493. </ul>
  7494. <h3 id="example-2"><a class="header" href="#example-2">Example</a></h3>
  7495. <p>This section might look like:</p>
  7496. <pre><code class="language-yaml">spam_checker:
  7497. - module: my_module.ExampleSpamChecker
  7498. config:
  7499. # Enable or disable a specific option in ExampleSpamChecker.
  7500. my_custom_option: true
  7501. </code></pre>
  7502. <p>More spam checkers can be added in tandem by appending more items to the list. An
  7503. action is blocked when at least one of the configured spam checkers flags it.</p>
  7504. <h2 id="examples"><a class="header" href="#examples">Examples</a></h2>
  7505. <p>The <a href="https://github.com/matrix-org/mjolnir">Mjolnir</a> project is a full fledged
  7506. example using the Synapse spam checking API, including a bot for dynamic
  7507. configuration.</p>
  7508. <div style="break-before: page; page-break-before: always;"></div><h2 style="color:red">
  7509. This page of the Synapse documentation is now deprecated. For up to date
  7510. documentation on setting up or writing a presence router module, please see
  7511. <a href="modules.html">this page</a>.
  7512. </h2>
  7513. <h1 id="presence-router-module"><a class="header" href="#presence-router-module">Presence Router Module</a></h1>
  7514. <p>Synapse supports configuring a module that can specify additional users
  7515. (local or remote) to should receive certain presence updates from local
  7516. users.</p>
  7517. <p>Note that routing presence via Application Service transactions is not
  7518. currently supported.</p>
  7519. <p>The presence routing module is implemented as a Python class, which will
  7520. be imported by the running Synapse.</p>
  7521. <h2 id="python-presence-router-class"><a class="header" href="#python-presence-router-class">Python Presence Router Class</a></h2>
  7522. <p>The Python class is instantiated with two objects:</p>
  7523. <ul>
  7524. <li>A configuration object of some type (see below).</li>
  7525. <li>An instance of <code>synapse.module_api.ModuleApi</code>.</li>
  7526. </ul>
  7527. <p>It then implements methods related to presence routing.</p>
  7528. <p>Note that one method of <code>ModuleApi</code> that may be useful is:</p>
  7529. <pre><code class="language-python">async def ModuleApi.send_local_online_presence_to(users: Iterable[str]) -&gt; None
  7530. </code></pre>
  7531. <p>which can be given a list of local or remote MXIDs to broadcast known, online user
  7532. presence to (for those users that the receiving user is considered interested in).
  7533. It does not include state for users who are currently offline, and it can only be
  7534. called on workers that support sending federation. Additionally, this method must
  7535. only be called from the process that has been configured to write to the
  7536. the <a href="workers.html#stream-writers">presence stream</a>.
  7537. By default, this is the main process, but another worker can be configured to do
  7538. so.</p>
  7539. <h3 id="module-structure"><a class="header" href="#module-structure">Module structure</a></h3>
  7540. <p>Below is a list of possible methods that can be implemented, and whether they are
  7541. required.</p>
  7542. <h4 id="parse_config"><a class="header" href="#parse_config"><code>parse_config</code></a></h4>
  7543. <pre><code class="language-python">def parse_config(config_dict: dict) -&gt; Any
  7544. </code></pre>
  7545. <p><strong>Required.</strong> A static method that is passed a dictionary of config options, and
  7546. should return a validated config object. This method is described further in
  7547. <a href="presence_router_module.html#configuration">Configuration</a>.</p>
  7548. <h4 id="get_users_for_states"><a class="header" href="#get_users_for_states"><code>get_users_for_states</code></a></h4>
  7549. <pre><code class="language-python">async def get_users_for_states(
  7550. self,
  7551. state_updates: Iterable[UserPresenceState],
  7552. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7553. </code></pre>
  7554. <p><strong>Required.</strong> An asynchronous method that is passed an iterable of user presence
  7555. state. This method can determine whether a given presence update should be sent to certain
  7556. users. It does this by returning a dictionary with keys representing local or remote
  7557. Matrix User IDs, and values being a python set
  7558. of <code>synapse.handlers.presence.UserPresenceState</code> instances.</p>
  7559. <p>Synapse will then attempt to send the specified presence updates to each user when
  7560. possible.</p>
  7561. <h4 id="get_interested_users"><a class="header" href="#get_interested_users"><code>get_interested_users</code></a></h4>
  7562. <pre><code class="language-python">async def get_interested_users(self, user_id: str) -&gt; Union[Set[str], str]
  7563. </code></pre>
  7564. <p><strong>Required.</strong> An asynchronous method that is passed a single Matrix User ID. This
  7565. method is expected to return the users that the passed in user may be interested in the
  7566. presence of. Returned users may be local or remote. The presence routed as a result of
  7567. what this method returns is sent in addition to the updates already sent between users
  7568. that share a room together. Presence updates are deduplicated.</p>
  7569. <p>This method should return a python set of Matrix User IDs, or the object
  7570. <code>synapse.events.presence_router.PresenceRouter.ALL_USERS</code> to indicate that the passed
  7571. user should receive presence information for <em>all</em> known users.</p>
  7572. <p>For clarity, if the user <code>@alice:example.org</code> is passed to this method, and the Set
  7573. <code>{&quot;@bob:example.com&quot;, &quot;@charlie:somewhere.org&quot;}</code> is returned, this signifies that Alice
  7574. should receive presence updates sent by Bob and Charlie, regardless of whether these
  7575. users share a room.</p>
  7576. <h3 id="example-3"><a class="header" href="#example-3">Example</a></h3>
  7577. <p>Below is an example implementation of a presence router class.</p>
  7578. <pre><code class="language-python">from typing import Dict, Iterable, Set, Union
  7579. from synapse.events.presence_router import PresenceRouter
  7580. from synapse.handlers.presence import UserPresenceState
  7581. from synapse.module_api import ModuleApi
  7582. class PresenceRouterConfig:
  7583. def __init__(self):
  7584. # Config options with their defaults
  7585. # A list of users to always send all user presence updates to
  7586. self.always_send_to_users = [] # type: List[str]
  7587. # A list of users to ignore presence updates for. Does not affect
  7588. # shared-room presence relationships
  7589. self.blacklisted_users = [] # type: List[str]
  7590. class ExamplePresenceRouter:
  7591. &quot;&quot;&quot;An example implementation of synapse.presence_router.PresenceRouter.
  7592. Supports routing all presence to a configured set of users, or a subset
  7593. of presence from certain users to members of certain rooms.
  7594. Args:
  7595. config: A configuration object.
  7596. module_api: An instance of Synapse's ModuleApi.
  7597. &quot;&quot;&quot;
  7598. def __init__(self, config: PresenceRouterConfig, module_api: ModuleApi):
  7599. self._config = config
  7600. self._module_api = module_api
  7601. @staticmethod
  7602. def parse_config(config_dict: dict) -&gt; PresenceRouterConfig:
  7603. &quot;&quot;&quot;Parse a configuration dictionary from the homeserver config, do
  7604. some validation and return a typed PresenceRouterConfig.
  7605. Args:
  7606. config_dict: The configuration dictionary.
  7607. Returns:
  7608. A validated config object.
  7609. &quot;&quot;&quot;
  7610. # Initialise a typed config object
  7611. config = PresenceRouterConfig()
  7612. always_send_to_users = config_dict.get(&quot;always_send_to_users&quot;)
  7613. blacklisted_users = config_dict.get(&quot;blacklisted_users&quot;)
  7614. # Do some validation of config options... otherwise raise a
  7615. # synapse.config.ConfigError.
  7616. config.always_send_to_users = always_send_to_users
  7617. config.blacklisted_users = blacklisted_users
  7618. return config
  7619. async def get_users_for_states(
  7620. self,
  7621. state_updates: Iterable[UserPresenceState],
  7622. ) -&gt; Dict[str, Set[UserPresenceState]]:
  7623. &quot;&quot;&quot;Given an iterable of user presence updates, determine where each one
  7624. needs to go. Returned results will not affect presence updates that are
  7625. sent between users who share a room.
  7626. Args:
  7627. state_updates: An iterable of user presence state updates.
  7628. Returns:
  7629. A dictionary of user_id -&gt; set of UserPresenceState that the user should
  7630. receive.
  7631. &quot;&quot;&quot;
  7632. destination_users = {} # type: Dict[str, Set[UserPresenceState]
  7633. # Ignore any updates for blacklisted users
  7634. desired_updates = set()
  7635. for update in state_updates:
  7636. if update.state_key not in self._config.blacklisted_users:
  7637. desired_updates.add(update)
  7638. # Send all presence updates to specific users
  7639. for user_id in self._config.always_send_to_users:
  7640. destination_users[user_id] = desired_updates
  7641. return destination_users
  7642. async def get_interested_users(
  7643. self,
  7644. user_id: str,
  7645. ) -&gt; Union[Set[str], PresenceRouter.ALL_USERS]:
  7646. &quot;&quot;&quot;
  7647. Retrieve a list of users that `user_id` is interested in receiving the
  7648. presence of. This will be in addition to those they share a room with.
  7649. Optionally, the object PresenceRouter.ALL_USERS can be returned to indicate
  7650. that this user should receive all incoming local and remote presence updates.
  7651. Note that this method will only be called for local users.
  7652. Args:
  7653. user_id: A user requesting presence updates.
  7654. Returns:
  7655. A set of user IDs to return additional presence updates for, or
  7656. PresenceRouter.ALL_USERS to return presence updates for all other users.
  7657. &quot;&quot;&quot;
  7658. if user_id in self._config.always_send_to_users:
  7659. return PresenceRouter.ALL_USERS
  7660. return set()
  7661. </code></pre>
  7662. <h4 id="a-note-on-get_users_for_states-and-get_interested_users"><a class="header" href="#a-note-on-get_users_for_states-and-get_interested_users">A note on <code>get_users_for_states</code> and <code>get_interested_users</code></a></h4>
  7663. <p>Both of these methods are effectively two different sides of the same coin. The logic
  7664. regarding which users should receive updates for other users should be the same
  7665. between them.</p>
  7666. <p><code>get_users_for_states</code> is called when presence updates come in from either federation
  7667. or local users, and is used to either direct local presence to remote users, or to
  7668. wake up the sync streams of local users to collect remote presence.</p>
  7669. <p>In contrast, <code>get_interested_users</code> is used to determine the users that presence should
  7670. be fetched for when a local user is syncing. This presence is then retrieved, before
  7671. being fed through <code>get_users_for_states</code> once again, with only the syncing user's
  7672. routing information pulled from the resulting dictionary.</p>
  7673. <p>Their routing logic should thus line up, else you may run into unintended behaviour.</p>
  7674. <h2 id="configuration-3"><a class="header" href="#configuration-3">Configuration</a></h2>
  7675. <p>Once you've crafted your module and installed it into the same Python environment as
  7676. Synapse, amend your homeserver config file with the following.</p>
  7677. <pre><code class="language-yaml">presence:
  7678. enabled: true
  7679. presence_router:
  7680. module: my_module.ExamplePresenceRouter
  7681. config:
  7682. # Any configuration options for your module. The below is an example.
  7683. # of setting options for ExamplePresenceRouter.
  7684. always_send_to_users: [&quot;@presence_gobbler:example.org&quot;]
  7685. blacklisted_users:
  7686. - &quot;@alice:example.com&quot;
  7687. - &quot;@bob:example.com&quot;
  7688. ...
  7689. </code></pre>
  7690. <p>The contents of <code>config</code> will be passed as a Python dictionary to the static
  7691. <code>parse_config</code> method of your class. The object returned by this method will
  7692. then be passed to the <code>__init__</code> method of your module as <code>config</code>.</p>
  7693. <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>
  7694. <p>For small instances it recommended to run Synapse in the default monolith mode.
  7695. For larger instances where performance is a concern it can be helpful to split
  7696. out functionality into multiple separate python processes. These processes are
  7697. called 'workers', and are (eventually) intended to scale horizontally
  7698. independently.</p>
  7699. <p>Synapse's worker support is under active development and subject to change as
  7700. we attempt to rapidly scale ever larger Synapse instances. However we are
  7701. documenting it here to help admins needing a highly scalable Synapse instance
  7702. similar to the one running <code>matrix.org</code>.</p>
  7703. <p>All processes continue to share the same database instance, and as such,
  7704. workers only work with PostgreSQL-based Synapse deployments. SQLite should only
  7705. be used for demo purposes and any admin considering workers should already be
  7706. running PostgreSQL.</p>
  7707. <p>See also <a href="https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability">Matrix.org blog post</a>
  7708. for a higher level overview.</p>
  7709. <h2 id="main-processworker-communication"><a class="header" href="#main-processworker-communication">Main process/worker communication</a></h2>
  7710. <p>The processes communicate with each other via a Synapse-specific protocol called
  7711. 'replication' (analogous to MySQL- or Postgres-style database replication) which
  7712. feeds streams of newly written data between processes so they can be kept in
  7713. sync with the database state.</p>
  7714. <p>When configured to do so, Synapse uses a
  7715. <a href="https://redis.io/topics/pubsub">Redis pub/sub channel</a> to send the replication
  7716. stream between all configured Synapse processes. Additionally, processes may
  7717. make HTTP requests to each other, primarily for operations which need to wait
  7718. for a reply ─ such as sending an event.</p>
  7719. <p>Redis support was added in v1.13.0 with it becoming the recommended method in
  7720. v1.18.0. It replaced the old direct TCP connections (which is deprecated as of
  7721. v1.18.0) to the main process. With Redis, rather than all the workers connecting
  7722. to the main process, all the workers and the main process connect to Redis,
  7723. which relays replication commands between processes. This can give a significant
  7724. cpu saving on the main process and will be a prerequisite for upcoming
  7725. performance improvements.</p>
  7726. <p>If Redis support is enabled Synapse will use it as a shared cache, as well as a
  7727. pub/sub mechanism.</p>
  7728. <p>See the <a href="workers.html#architectural-diagram">Architectural diagram</a> section at the end for
  7729. a visualisation of what this looks like.</p>
  7730. <h2 id="setting-up-workers"><a class="header" href="#setting-up-workers">Setting up workers</a></h2>
  7731. <p>A Redis server is required to manage the communication between the processes.
  7732. The Redis server should be installed following the normal procedure for your
  7733. distribution (e.g. <code>apt install redis-server</code> on Debian). It is safe to use an
  7734. existing Redis deployment if you have one.</p>
  7735. <p>Once installed, check that Redis is running and accessible from the host running
  7736. Synapse, for example by executing <code>echo PING | nc -q1 localhost 6379</code> and seeing
  7737. a response of <code>+PONG</code>.</p>
  7738. <p>The appropriate dependencies must also be installed for Synapse. If using a
  7739. virtualenv, these can be installed with:</p>
  7740. <pre><code class="language-sh">pip install &quot;matrix-synapse[redis]&quot;
  7741. </code></pre>
  7742. <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
  7743. <code>matrix.org</code> and in the docker images at
  7744. https://hub.docker.com/r/matrixdotorg/synapse/.</p>
  7745. <p>To make effective use of the workers, you will need to configure an HTTP
  7746. reverse-proxy such as nginx or haproxy, which will direct incoming requests to
  7747. the correct worker, or to the main synapse instance. See
  7748. <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a reverse
  7749. proxy.</p>
  7750. <p>When using workers, each worker process has its own configuration file which
  7751. contains settings specific to that worker, such as the HTTP listener that it
  7752. provides (if any), logging configuration, etc.</p>
  7753. <p>Normally, the worker processes are configured to read from a shared
  7754. configuration file as well as the worker-specific configuration files. This
  7755. makes it easier to keep common configuration settings synchronised across all
  7756. the processes.</p>
  7757. <p>The main process is somewhat special in this respect: it does not normally
  7758. need its own configuration file and can take all of its configuration from the
  7759. shared configuration file.</p>
  7760. <h3 id="shared-configuration"><a class="header" href="#shared-configuration">Shared configuration</a></h3>
  7761. <p>Normally, only a couple of changes are needed to make an existing configuration
  7762. file suitable for use with workers. First, you need to enable an &quot;HTTP replication
  7763. listener&quot; for the main process; and secondly, you need to enable redis-based
  7764. replication. Optionally, a shared secret can be used to authenticate HTTP
  7765. traffic between workers. For example:</p>
  7766. <pre><code class="language-yaml"># extend the existing `listeners` section. This defines the ports that the
  7767. # main process will listen on.
  7768. listeners:
  7769. # The HTTP replication port
  7770. - port: 9093
  7771. bind_address: '127.0.0.1'
  7772. type: http
  7773. resources:
  7774. - names: [replication]
  7775. # Add a random shared secret to authenticate traffic.
  7776. worker_replication_secret: &quot;&quot;
  7777. redis:
  7778. enabled: true
  7779. </code></pre>
  7780. <p>See the sample config for the full documentation of each option.</p>
  7781. <p>Under <strong>no circumstances</strong> should the replication listener be exposed to the
  7782. public internet; it has no authentication and is unencrypted.</p>
  7783. <h3 id="worker-configuration"><a class="header" href="#worker-configuration">Worker configuration</a></h3>
  7784. <p>In the config file for each worker, you must specify the type of worker
  7785. application (<code>worker_app</code>), and you should specify a unique name for the worker
  7786. (<code>worker_name</code>). The currently available worker applications are listed below.
  7787. You must also specify the HTTP replication endpoint that it should talk to on
  7788. the main synapse process. <code>worker_replication_host</code> should specify the host of
  7789. the main synapse and <code>worker_replication_http_port</code> should point to the HTTP
  7790. replication port. If the worker will handle HTTP requests then the
  7791. <code>worker_listeners</code> option should be set with a <code>http</code> listener, in the same way
  7792. as the <code>listeners</code> option in the shared config.</p>
  7793. <p>For example:</p>
  7794. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  7795. worker_name: worker1
  7796. # The replication listener on the main synapse process.
  7797. worker_replication_host: 127.0.0.1
  7798. worker_replication_http_port: 9093
  7799. worker_listeners:
  7800. - type: http
  7801. port: 8083
  7802. resources:
  7803. - names:
  7804. - client
  7805. - federation
  7806. worker_log_config: /home/matrix/synapse/config/worker1_log_config.yaml
  7807. </code></pre>
  7808. <p>...is a full configuration for a generic worker instance, which will expose a
  7809. plain HTTP endpoint on port 8083 separately serving various endpoints, e.g.
  7810. <code>/sync</code>, which are listed below.</p>
  7811. <p>Obviously you should configure your reverse-proxy to route the relevant
  7812. endpoints to the worker (<code>localhost:8083</code> in the above example).</p>
  7813. <h3 id="running-synapse-with-workers"><a class="header" href="#running-synapse-with-workers">Running Synapse with workers</a></h3>
  7814. <p>Finally, you need to start your worker processes. This can be done with either
  7815. <code>synctl</code> or your distribution's preferred service manager such as <code>systemd</code>. We
  7816. recommend the use of <code>systemd</code> where available: for information on setting up
  7817. <code>systemd</code> to start synapse workers, see
  7818. <a href="systemd-with-workers">Systemd with Workers</a>. To use <code>synctl</code>, see
  7819. <a href="synctl_workers.html">Using synctl with Workers</a>.</p>
  7820. <h2 id="available-worker-applications"><a class="header" href="#available-worker-applications">Available worker applications</a></h2>
  7821. <h3 id="synapseappgeneric_worker"><a class="header" href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a></h3>
  7822. <p>This worker can handle API requests matching the following regular
  7823. expressions:</p>
  7824. <pre><code># Sync requests
  7825. ^/_matrix/client/(v2_alpha|r0)/sync$
  7826. ^/_matrix/client/(api/v1|v2_alpha|r0)/events$
  7827. ^/_matrix/client/(api/v1|r0)/initialSync$
  7828. ^/_matrix/client/(api/v1|r0)/rooms/[^/]+/initialSync$
  7829. # Federation requests
  7830. ^/_matrix/federation/v1/event/
  7831. ^/_matrix/federation/v1/state/
  7832. ^/_matrix/federation/v1/state_ids/
  7833. ^/_matrix/federation/v1/backfill/
  7834. ^/_matrix/federation/v1/get_missing_events/
  7835. ^/_matrix/federation/v1/publicRooms
  7836. ^/_matrix/federation/v1/query/
  7837. ^/_matrix/federation/v1/make_join/
  7838. ^/_matrix/federation/v1/make_leave/
  7839. ^/_matrix/federation/v1/send_join/
  7840. ^/_matrix/federation/v2/send_join/
  7841. ^/_matrix/federation/v1/send_leave/
  7842. ^/_matrix/federation/v2/send_leave/
  7843. ^/_matrix/federation/v1/invite/
  7844. ^/_matrix/federation/v2/invite/
  7845. ^/_matrix/federation/v1/query_auth/
  7846. ^/_matrix/federation/v1/event_auth/
  7847. ^/_matrix/federation/v1/exchange_third_party_invite/
  7848. ^/_matrix/federation/v1/user/devices/
  7849. ^/_matrix/federation/v1/get_groups_publicised$
  7850. ^/_matrix/key/v2/query
  7851. # Inbound federation transaction request
  7852. ^/_matrix/federation/v1/send/
  7853. # Client API requests
  7854. ^/_matrix/client/(api/v1|r0|unstable)/createRoom$
  7855. ^/_matrix/client/(api/v1|r0|unstable)/publicRooms$
  7856. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/joined_members$
  7857. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/context/.*$
  7858. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/members$
  7859. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state$
  7860. ^/_matrix/client/(api/v1|r0|unstable)/account/3pid$
  7861. ^/_matrix/client/(api/v1|r0|unstable)/devices$
  7862. ^/_matrix/client/(api/v1|r0|unstable)/keys/query$
  7863. ^/_matrix/client/(api/v1|r0|unstable)/keys/changes$
  7864. ^/_matrix/client/versions$
  7865. ^/_matrix/client/(api/v1|r0|unstable)/voip/turnServer$
  7866. ^/_matrix/client/(api/v1|r0|unstable)/joined_groups$
  7867. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups$
  7868. ^/_matrix/client/(api/v1|r0|unstable)/publicised_groups/
  7869. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/event/
  7870. ^/_matrix/client/(api/v1|r0|unstable)/joined_rooms$
  7871. ^/_matrix/client/(api/v1|r0|unstable)/search$
  7872. # Registration/login requests
  7873. ^/_matrix/client/(api/v1|r0|unstable)/login$
  7874. ^/_matrix/client/(r0|unstable)/register$
  7875. ^/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity$
  7876. # Event sending requests
  7877. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/redact
  7878. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/send
  7879. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/state/
  7880. ^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
  7881. ^/_matrix/client/(api/v1|r0|unstable)/join/
  7882. ^/_matrix/client/(api/v1|r0|unstable)/profile/
  7883. </code></pre>
  7884. <p>Additionally, the following REST endpoints can be handled for GET requests:</p>
  7885. <pre><code>^/_matrix/federation/v1/groups/
  7886. </code></pre>
  7887. <p>Pagination requests can also be handled, but all requests for a given
  7888. room must be routed to the same instance. Additionally, care must be taken to
  7889. ensure that the purge history admin API is not used while pagination requests
  7890. for the room are in flight:</p>
  7891. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/rooms/.*/messages$
  7892. </code></pre>
  7893. <p>Additionally, the following endpoints should be included if Synapse is configured
  7894. to use SSO (you only need to include the ones for whichever SSO provider you're
  7895. using):</p>
  7896. <pre><code># for all SSO providers
  7897. ^/_matrix/client/(api/v1|r0|unstable)/login/sso/redirect
  7898. ^/_synapse/client/pick_idp$
  7899. ^/_synapse/client/pick_username
  7900. ^/_synapse/client/new_user_consent$
  7901. ^/_synapse/client/sso_register$
  7902. # OpenID Connect requests.
  7903. ^/_synapse/client/oidc/callback$
  7904. # SAML requests.
  7905. ^/_synapse/client/saml2/authn_response$
  7906. # CAS requests.
  7907. ^/_matrix/client/(api/v1|r0|unstable)/login/cas/ticket$
  7908. </code></pre>
  7909. <p>Ensure that all SSO logins go to a single process.
  7910. For multiple workers not handling the SSO endpoints properly, see
  7911. <a href="https://github.com/matrix-org/synapse/issues/7530">#7530</a> and
  7912. <a href="https://github.com/matrix-org/synapse/issues/9427">#9427</a>.</p>
  7913. <p>Note that a HTTP listener with <code>client</code> and <code>federation</code> resources must be
  7914. configured in the <code>worker_listeners</code> option in the worker config.</p>
  7915. <h4 id="load-balancing"><a class="header" href="#load-balancing">Load balancing</a></h4>
  7916. <p>It is possible to run multiple instances of this worker app, with incoming requests
  7917. being load-balanced between them by the reverse-proxy. However, different endpoints
  7918. have different characteristics and so admins
  7919. may wish to run multiple groups of workers handling different endpoints so that
  7920. load balancing can be done in different ways.</p>
  7921. <p>For <code>/sync</code> and <code>/initialSync</code> requests it will be more efficient if all
  7922. requests from a particular user are routed to a single instance. Extracting a
  7923. user ID from the access token or <code>Authorization</code> header is currently left as an
  7924. exercise for the reader. Admins may additionally wish to separate out <code>/sync</code>
  7925. requests that have a <code>since</code> query parameter from those that don't (and
  7926. <code>/initialSync</code>), as requests that don't are known as &quot;initial sync&quot; that happens
  7927. when a user logs in on a new device and can be <em>very</em> resource intensive, so
  7928. isolating these requests will stop them from interfering with other users ongoing
  7929. syncs.</p>
  7930. <p>Federation and client requests can be balanced via simple round robin.</p>
  7931. <p>The inbound federation transaction request <code>^/_matrix/federation/v1/send/</code>
  7932. should be balanced by source IP so that transactions from the same remote server
  7933. go to the same process.</p>
  7934. <p>Registration/login requests can be handled separately purely to help ensure that
  7935. unexpected load doesn't affect new logins and sign ups.</p>
  7936. <p>Finally, event sending requests can be balanced by the room ID in the URI (or
  7937. the full URI, or even just round robin), the room ID is the path component after
  7938. <code>/rooms/</code>. If there is a large bridge connected that is sending or may send lots
  7939. of events, then a dedicated set of workers can be provisioned to limit the
  7940. effects of bursts of events from that bridge on events sent by normal users.</p>
  7941. <h4 id="stream-writers"><a class="header" href="#stream-writers">Stream writers</a></h4>
  7942. <p>Additionally, there is <em>experimental</em> support for moving writing of specific
  7943. streams (such as events) off of the main process to a particular worker. (This
  7944. is only supported with Redis-based replication.)</p>
  7945. <p>Currently supported streams are <code>events</code> and <code>typing</code>.</p>
  7946. <p>To enable this, the worker must have a HTTP replication listener configured,
  7947. have a <code>worker_name</code> and be listed in the <code>instance_map</code> config. For example to
  7948. move event persistence off to a dedicated worker, the shared configuration would
  7949. include:</p>
  7950. <pre><code class="language-yaml">instance_map:
  7951. event_persister1:
  7952. host: localhost
  7953. port: 8034
  7954. stream_writers:
  7955. events: event_persister1
  7956. </code></pre>
  7957. <p>The <code>events</code> stream also experimentally supports having multiple writers, where
  7958. work is sharded between them by room ID. Note that you <em>must</em> restart all worker
  7959. instances when adding or removing event persisters. An example <code>stream_writers</code>
  7960. configuration with multiple writers:</p>
  7961. <pre><code class="language-yaml">stream_writers:
  7962. events:
  7963. - event_persister1
  7964. - event_persister2
  7965. </code></pre>
  7966. <h4 id="background-tasks"><a class="header" href="#background-tasks">Background tasks</a></h4>
  7967. <p>There is also <em>experimental</em> support for moving background tasks to a separate
  7968. worker. Background tasks are run periodically or started via replication. Exactly
  7969. which tasks are configured to run depends on your Synapse configuration (e.g. if
  7970. stats is enabled).</p>
  7971. <p>To enable this, the worker must have a <code>worker_name</code> and can be configured to run
  7972. background tasks. For example, to move background tasks to a dedicated worker,
  7973. the shared configuration would include:</p>
  7974. <pre><code class="language-yaml">run_background_tasks_on: background_worker
  7975. </code></pre>
  7976. <p>You might also wish to investigate the <code>update_user_directory</code> and
  7977. <code>media_instance_running_background_jobs</code> settings.</p>
  7978. <h3 id="synapseapppusher"><a class="header" href="#synapseapppusher"><code>synapse.app.pusher</code></a></h3>
  7979. <p>Handles sending push notifications to sygnal and email. Doesn't handle any
  7980. REST endpoints itself, but you should set <code>start_pushers: False</code> in the
  7981. shared configuration file to stop the main synapse sending push notifications.</p>
  7982. <p>To run multiple instances at once the <code>pusher_instances</code> option should list all
  7983. pusher instances by their worker name, e.g.:</p>
  7984. <pre><code class="language-yaml">pusher_instances:
  7985. - pusher_worker1
  7986. - pusher_worker2
  7987. </code></pre>
  7988. <h3 id="synapseappappservice"><a class="header" href="#synapseappappservice"><code>synapse.app.appservice</code></a></h3>
  7989. <p>Handles sending output traffic to Application Services. Doesn't handle any
  7990. REST endpoints itself, but you should set <code>notify_appservices: False</code> in the
  7991. shared configuration file to stop the main synapse sending appservice notifications.</p>
  7992. <p>Note this worker cannot be load-balanced: only one instance should be active.</p>
  7993. <h3 id="synapseappfederation_sender"><a class="header" href="#synapseappfederation_sender"><code>synapse.app.federation_sender</code></a></h3>
  7994. <p>Handles sending federation traffic to other servers. Doesn't handle any
  7995. REST endpoints itself, but you should set <code>send_federation: False</code> in the
  7996. shared configuration file to stop the main synapse sending this traffic.</p>
  7997. <p>If running multiple federation senders then you must list each
  7998. instance in the <code>federation_sender_instances</code> option by their <code>worker_name</code>.
  7999. All instances must be stopped and started when adding or removing instances.
  8000. For example:</p>
  8001. <pre><code class="language-yaml">federation_sender_instances:
  8002. - federation_sender1
  8003. - federation_sender2
  8004. </code></pre>
  8005. <h3 id="synapseappmedia_repository"><a class="header" href="#synapseappmedia_repository"><code>synapse.app.media_repository</code></a></h3>
  8006. <p>Handles the media repository. It can handle all endpoints starting with:</p>
  8007. <pre><code>/_matrix/media/
  8008. </code></pre>
  8009. <p>... and the following regular expressions matching media-specific administration APIs:</p>
  8010. <pre><code>^/_synapse/admin/v1/purge_media_cache$
  8011. ^/_synapse/admin/v1/room/.*/media.*$
  8012. ^/_synapse/admin/v1/user/.*/media.*$
  8013. ^/_synapse/admin/v1/media/.*$
  8014. ^/_synapse/admin/v1/quarantine_media/.*$
  8015. ^/_synapse/admin/v1/users/.*/media$
  8016. </code></pre>
  8017. <p>You should also set <code>enable_media_repo: False</code> in the shared configuration
  8018. file to stop the main synapse running background jobs related to managing the
  8019. media repository. Note that doing so will prevent the main process from being
  8020. able to handle the above endpoints.</p>
  8021. <p>In the <code>media_repository</code> worker configuration file, configure the http listener to
  8022. expose the <code>media</code> resource. For example:</p>
  8023. <pre><code class="language-yaml"> worker_listeners:
  8024. - type: http
  8025. port: 8085
  8026. resources:
  8027. - names:
  8028. - media
  8029. </code></pre>
  8030. <p>Note that if running multiple media repositories they must be on the same server
  8031. and you must configure a single instance to run the background tasks, e.g.:</p>
  8032. <pre><code class="language-yaml"> media_instance_running_background_jobs: &quot;media-repository-1&quot;
  8033. </code></pre>
  8034. <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>
  8035. <h3 id="synapseappuser_dir"><a class="header" href="#synapseappuser_dir"><code>synapse.app.user_dir</code></a></h3>
  8036. <p>Handles searches in the user directory. It can handle REST endpoints matching
  8037. the following regular expressions:</p>
  8038. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$
  8039. </code></pre>
  8040. <p>When using this worker you must also set <code>update_user_directory: False</code> in the
  8041. shared configuration file to stop the main synapse running background
  8042. jobs related to updating the user directory.</p>
  8043. <h3 id="synapseappfrontend_proxy"><a class="header" href="#synapseappfrontend_proxy"><code>synapse.app.frontend_proxy</code></a></h3>
  8044. <p>Proxies some frequently-requested client endpoints to add caching and remove
  8045. load from the main synapse. It can handle REST endpoints matching the following
  8046. regular expressions:</p>
  8047. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/keys/upload
  8048. </code></pre>
  8049. <p>If <code>use_presence</code> is False in the homeserver config, it can also handle REST
  8050. endpoints matching the following regular expressions:</p>
  8051. <pre><code>^/_matrix/client/(api/v1|r0|unstable)/presence/[^/]+/status
  8052. </code></pre>
  8053. <p>This &quot;stub&quot; presence handler will pass through <code>GET</code> request but make the
  8054. <code>PUT</code> effectively a no-op.</p>
  8055. <p>It will proxy any requests it cannot handle to the main synapse instance. It
  8056. must therefore be configured with the location of the main instance, via
  8057. the <code>worker_main_http_uri</code> setting in the <code>frontend_proxy</code> worker configuration
  8058. file. For example:</p>
  8059. <pre><code>worker_main_http_uri: http://127.0.0.1:8008
  8060. </code></pre>
  8061. <h3 id="historical-apps"><a class="header" href="#historical-apps">Historical apps</a></h3>
  8062. <p><em>Note:</em> Historically there used to be more apps, however they have been
  8063. amalgamated into a single <code>synapse.app.generic_worker</code> app. The remaining apps
  8064. are ones that do specific processing unrelated to requests, e.g. the <code>pusher</code>
  8065. that handles sending out push notifications for new events. The intention is for
  8066. all these to be folded into the <code>generic_worker</code> app and to use config to define
  8067. which processes handle the various proccessing such as push notifications.</p>
  8068. <h2 id="migration-from-old-config"><a class="header" href="#migration-from-old-config">Migration from old config</a></h2>
  8069. <p>There are two main independent changes that have been made: introducing Redis
  8070. support and merging apps into <code>synapse.app.generic_worker</code>. Both these changes
  8071. are backwards compatible and so no changes to the config are required, however
  8072. server admins are encouraged to plan to migrate to Redis as the old style direct
  8073. TCP replication config is deprecated.</p>
  8074. <p>To migrate to Redis add the <code>redis</code> config as above, and optionally remove the
  8075. TCP <code>replication</code> listener from master and <code>worker_replication_port</code> from worker
  8076. config.</p>
  8077. <p>To migrate apps to use <code>synapse.app.generic_worker</code> simply update the
  8078. <code>worker_app</code> option in the worker configs, and where worker are started (e.g.
  8079. in systemd service files, but not required for synctl).</p>
  8080. <h2 id="architectural-diagram"><a class="header" href="#architectural-diagram">Architectural diagram</a></h2>
  8081. <p>The following shows an example setup using Redis and a reverse proxy:</p>
  8082. <pre><code> Clients &amp; Federation
  8083. |
  8084. v
  8085. +-----------+
  8086. | |
  8087. | Reverse |
  8088. | Proxy |
  8089. | |
  8090. +-----------+
  8091. | | |
  8092. | | | HTTP requests
  8093. +-------------------+ | +-----------+
  8094. | +---+ |
  8095. | | |
  8096. v v v
  8097. +--------------+ +--------------+ +--------------+ +--------------+
  8098. | Main | | Generic | | Generic | | Event |
  8099. | Process | | Worker 1 | | Worker 2 | | Persister |
  8100. +--------------+ +--------------+ +--------------+ +--------------+
  8101. ^ ^ | ^ | | ^ | ^ ^
  8102. | | | | | | | | | |
  8103. | | | | | HTTP | | | | |
  8104. | +----------+&lt;--|---|---------+ | | | |
  8105. | | +-------------|--&gt;+----------+ |
  8106. | | | |
  8107. | | | |
  8108. v v v v
  8109. ====================================================================
  8110. Redis pub/sub channel
  8111. </code></pre>
  8112. <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>
  8113. <p>If you want to use <code>synctl</code> to manage your synapse processes, you will need to
  8114. create an an additional configuration file for the main synapse process. That
  8115. configuration should look like this:</p>
  8116. <pre><code class="language-yaml">worker_app: synapse.app.homeserver
  8117. </code></pre>
  8118. <p>Additionally, each worker app must be configured with the name of a &quot;pid file&quot;,
  8119. to which it will write its process ID when it starts. For example, for a
  8120. synchrotron, you might write:</p>
  8121. <pre><code class="language-yaml">worker_pid_file: /home/matrix/synapse/worker1.pid
  8122. </code></pre>
  8123. <p>Finally, to actually run your worker-based synapse, you must pass synctl the <code>-a</code>
  8124. commandline option to tell it to operate on all the worker configurations found
  8125. in the given directory, e.g.:</p>
  8126. <pre><code>synctl -a $CONFIG/workers start
  8127. </code></pre>
  8128. <p>Currently one should always restart all workers when restarting or upgrading
  8129. synapse, unless you explicitly know it's safe not to. For instance, restarting
  8130. synapse without restarting all the synchrotrons may result in broken typing
  8131. notifications.</p>
  8132. <p>To manipulate a specific worker, you pass the -w option to synctl:</p>
  8133. <pre><code>synctl -w $CONFIG/workers/worker1.yaml restart
  8134. </code></pre>
  8135. <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>
  8136. <p>This is a setup for managing synapse with systemd, including support for
  8137. managing workers. It provides a <code>matrix-synapse</code> service for the master, as
  8138. well as a <code>matrix-synapse-worker@</code> service template for any workers you
  8139. require. Additionally, to group the required services, it sets up a
  8140. <code>matrix-synapse.target</code>.</p>
  8141. <p>See the folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/system/">system</a>
  8142. for the systemd unit files.</p>
  8143. <p>The folder <a href="https://github.com/matrix-org/synapse/tree/develop/docs/systemd-with-workers/workers/">workers</a>
  8144. contains an example configuration for the <code>federation_reader</code> worker.</p>
  8145. <h2 id="synapse-configuration-files"><a class="header" href="#synapse-configuration-files">Synapse configuration files</a></h2>
  8146. <p>See <a href="systemd-with-workers/../workers.html">the worker documentation</a> for information on how to set up the
  8147. configuration files and reverse-proxy correctly.
  8148. Below is a sample <code>federation_reader</code> worker configuration file.</p>
  8149. <pre><code class="language-yaml">worker_app: synapse.app.federation_reader
  8150. worker_name: federation_reader1
  8151. worker_replication_host: 127.0.0.1
  8152. worker_replication_http_port: 9093
  8153. worker_listeners:
  8154. - type: http
  8155. port: 8011
  8156. resources:
  8157. - names: [federation]
  8158. worker_log_config: /etc/matrix-synapse/federation-reader-log.yaml
  8159. </code></pre>
  8160. <p>Systemd manages daemonization itself, so ensure that none of the configuration
  8161. files set either <code>daemonize</code> or <code>worker_daemonize</code>.</p>
  8162. <p>The config files of all workers are expected to be located in
  8163. <code>/etc/matrix-synapse/workers</code>. If you want to use a different location, edit
  8164. the provided <code>*.service</code> files accordingly.</p>
  8165. <p>There is no need for a separate configuration file for the master process.</p>
  8166. <h2 id="set-up"><a class="header" href="#set-up">Set up</a></h2>
  8167. <ol>
  8168. <li>Adjust synapse configuration files as above.</li>
  8169. <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>
  8170. to <code>/etc/systemd/system</code>.</li>
  8171. <li>Run <code>systemctl daemon-reload</code> to tell systemd to load the new unit files.</li>
  8172. <li>Run <code>systemctl enable matrix-synapse.service</code>. This will configure the
  8173. synapse master process to be started as part of the <code>matrix-synapse.target</code>
  8174. target.</li>
  8175. <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
  8176. should be a corresponding configuration file.
  8177. <code>/etc/matrix-synapse/workers/&lt;worker_name&gt;.yaml</code>.</li>
  8178. <li>Start all the synapse processes with <code>systemctl start matrix-synapse.target</code>.</li>
  8179. <li>Tell systemd to start synapse on boot with <code>systemctl enable matrix-synapse.target</code>.</li>
  8180. </ol>
  8181. <h2 id="usage"><a class="header" href="#usage">Usage</a></h2>
  8182. <p>Once the services are correctly set up, you can use the following commands
  8183. to manage your synapse installation:</p>
  8184. <pre><code class="language-sh"># Restart Synapse master and all workers
  8185. systemctl restart matrix-synapse.target
  8186. # Stop Synapse and all workers
  8187. systemctl stop matrix-synapse.target
  8188. # Restart the master alone
  8189. systemctl start matrix-synapse.service
  8190. # Restart a specific worker (eg. federation_reader); the master is
  8191. # unaffected by this.
  8192. systemctl restart matrix-synapse-worker@federation_reader.service
  8193. # Add a new worker (assuming all configs are set up already)
  8194. systemctl enable matrix-synapse-worker@federation_writer.service
  8195. systemctl restart matrix-synapse.target
  8196. </code></pre>
  8197. <h2 id="hardening"><a class="header" href="#hardening">Hardening</a></h2>
  8198. <p><strong>Optional:</strong> If further hardening is desired, the file
  8199. <code>override-hardened.conf</code> may be copied from
  8200. <a href="https://github.com/matrix-org/synapse/tree/develop/contrib/systemd/">contrib/systemd/override-hardened.conf</a>
  8201. in this repository to the location
  8202. <code>/etc/systemd/system/matrix-synapse.service.d/override-hardened.conf</code> (the
  8203. directory may have to be created). It enables certain sandboxing features in
  8204. systemd to further secure the synapse service. You may read the comments to
  8205. understand what the override file is doing. The same file will need to be copied to
  8206. <code>/etc/systemd/system/matrix-synapse-worker@.service.d/override-hardened-worker.conf</code>
  8207. (this directory may also have to be created) in order to apply the same
  8208. hardening options to any worker processes.</p>
  8209. <p>Once these files have been copied to their appropriate locations, simply reload
  8210. systemd's manager config files and restart all Synapse services to apply the hardening options. They will automatically
  8211. be applied at every restart as long as the override files are present at the
  8212. specified locations.</p>
  8213. <pre><code class="language-sh">systemctl daemon-reload
  8214. # Restart services
  8215. systemctl restart matrix-synapse.target
  8216. </code></pre>
  8217. <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
  8218. the changes being applied at a glance.</p>
  8219. <div style="break-before: page; page-break-before: always;"></div><h1 id="administration"><a class="header" href="#administration">Administration</a></h1>
  8220. <p>This section contains information on managing your Synapse homeserver. This includes:</p>
  8221. <ul>
  8222. <li>Managing users, rooms and media via the Admin API.</li>
  8223. <li>Setting up metrics and monitoring to give you insight into your homeserver's health.</li>
  8224. <li>Configuring structured logging.</li>
  8225. </ul>
  8226. <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>
  8227. <h2 id="authenticate-as-a-server-admin"><a class="header" href="#authenticate-as-a-server-admin">Authenticate as a server admin</a></h2>
  8228. <p>Many of the API calls in the admin api will require an <code>access_token</code> for a
  8229. server admin. (Note that a server admin is distinct from a room admin.)</p>
  8230. <p>A user can be marked as a server admin by updating the database directly, e.g.:</p>
  8231. <pre><code class="language-sql">UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
  8232. </code></pre>
  8233. <p>A new server admin user can also be created using the <code>register_new_matrix_user</code>
  8234. command. This is a script that is located in the <code>scripts/</code> directory, or possibly
  8235. already on your <code>$PATH</code> depending on how Synapse was installed.</p>
  8236. <p>Finding your user's <code>access_token</code> is client-dependent, but will usually be shown in the client's settings.</p>
  8237. <h2 id="making-an-admin-api-request"><a class="header" href="#making-an-admin-api-request">Making an Admin API request</a></h2>
  8238. <p>Once you have your <code>access_token</code>, you will need to authenticate each request to an Admin API endpoint by
  8239. providing the token as either a query parameter or a request header. To add it as a request header in cURL:</p>
  8240. <pre><code class="language-sh">curl --header &quot;Authorization: Bearer &lt;access_token&gt;&quot; &lt;the_rest_of_your_API_request&gt;
  8241. </code></pre>
  8242. <p>For more details on access tokens in Matrix, please refer to the complete
  8243. <a href="https://matrix.org/docs/spec/client_server/r0.6.1#using-access-tokens">matrix spec documentation</a>.</p>
  8244. <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>
  8245. <p>This API allows a server administrator to manage the validity of an account. To
  8246. use it, you must enable the account validity feature (under
  8247. <code>account_validity</code>) in Synapse's configuration.</p>
  8248. <h2 id="renew-account"><a class="header" href="#renew-account">Renew account</a></h2>
  8249. <p>This API extends the validity of an account by as much time as configured in the
  8250. <code>period</code> parameter from the <code>account_validity</code> configuration.</p>
  8251. <p>The API is:</p>
  8252. <pre><code>POST /_synapse/admin/v1/account_validity/validity
  8253. </code></pre>
  8254. <p>with the following body:</p>
  8255. <pre><code class="language-json">{
  8256. &quot;user_id&quot;: &quot;&lt;user ID for the account to renew&gt;&quot;,
  8257. &quot;expiration_ts&quot;: 0,
  8258. &quot;enable_renewal_emails&quot;: true
  8259. }
  8260. </code></pre>
  8261. <p><code>expiration_ts</code> is an optional parameter and overrides the expiration date,
  8262. which otherwise defaults to now + validity period.</p>
  8263. <p><code>enable_renewal_emails</code> is also an optional parameter and enables/disables
  8264. sending renewal emails to the user. Defaults to true.</p>
  8265. <p>The API returns with the new expiration date for this account, as a timestamp in
  8266. milliseconds since epoch:</p>
  8267. <pre><code class="language-json">{
  8268. &quot;expiration_ts&quot;: 0
  8269. }
  8270. </code></pre>
  8271. <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>
  8272. <p>This API lets a server admin delete a local group. Doing so will kick all
  8273. users out of the group so that their clients will correctly handle the group
  8274. being deleted.</p>
  8275. <p>The API is:</p>
  8276. <pre><code>POST /_synapse/admin/v1/delete_group/&lt;group_id&gt;
  8277. </code></pre>
  8278. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8279. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8280. <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>
  8281. <p>This API returns information about reported events.</p>
  8282. <p>The api is:</p>
  8283. <pre><code>GET /_synapse/admin/v1/event_reports?from=0&amp;limit=10
  8284. </code></pre>
  8285. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8286. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8287. <p>It returns a JSON body like the following:</p>
  8288. <pre><code class="language-json">{
  8289. &quot;event_reports&quot;: [
  8290. {
  8291. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8292. &quot;id&quot;: 2,
  8293. &quot;reason&quot;: &quot;foo&quot;,
  8294. &quot;score&quot;: -100,
  8295. &quot;received_ts&quot;: 1570897107409,
  8296. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8297. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8298. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8299. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8300. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8301. },
  8302. {
  8303. &quot;event_id&quot;: &quot;$3IcdZsDaN_En-S1DF4EMCy3v4gNRKeOJs8W5qTOKj4I&quot;,
  8304. &quot;id&quot;: 3,
  8305. &quot;reason&quot;: &quot;bar&quot;,
  8306. &quot;score&quot;: -100,
  8307. &quot;received_ts&quot;: 1598889612059,
  8308. &quot;canonical_alias&quot;: &quot;#alias2:matrix.org&quot;,
  8309. &quot;room_id&quot;: &quot;!eGvUQuTCkHGVwNMOjv:matrix.org&quot;,
  8310. &quot;name&quot;: &quot;Your room name here&quot;,
  8311. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8312. &quot;user_id&quot;: &quot;@bar:matrix.org&quot;
  8313. }
  8314. ],
  8315. &quot;next_token&quot;: 2,
  8316. &quot;total&quot;: 4
  8317. }
  8318. </code></pre>
  8319. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again with <code>from</code>
  8320. set to the value of <code>next_token</code>. This will return a new page.</p>
  8321. <p>If the endpoint does not return a <code>next_token</code> then there are no more reports to
  8322. paginate through.</p>
  8323. <p><strong>URL parameters:</strong></p>
  8324. <ul>
  8325. <li><code>limit</code>: integer - Is optional but is used for pagination, denoting the maximum number
  8326. of items to return in this call. Defaults to <code>100</code>.</li>
  8327. <li><code>from</code>: integer - Is optional but used for pagination, denoting the offset in the
  8328. returned results. This should be treated as an opaque value and not explicitly set to
  8329. anything other than the return value of <code>next_token</code> from a previous call. Defaults to <code>0</code>.</li>
  8330. <li><code>dir</code>: string - Direction of event report order. Whether to fetch the most recent
  8331. first (<code>b</code>) or the oldest first (<code>f</code>). Defaults to <code>b</code>.</li>
  8332. <li><code>user_id</code>: string - Is optional and filters to only return users with user IDs that
  8333. contain this value. This is the user who reported the event and wrote the reason.</li>
  8334. <li><code>room_id</code>: string - Is optional and filters to only return rooms with room IDs that
  8335. contain this value.</li>
  8336. </ul>
  8337. <p><strong>Response</strong></p>
  8338. <p>The following fields are returned in the JSON response body:</p>
  8339. <ul>
  8340. <li><code>id</code>: integer - ID of event report.</li>
  8341. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8342. report was sent.</li>
  8343. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8344. <li><code>name</code>: string - The name of the room.</li>
  8345. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8346. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8347. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank or <code>null</code>.</li>
  8348. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8349. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;. May be <code>null</code>.</li>
  8350. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8351. was reported.</li>
  8352. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8353. have a canonical alias set.</li>
  8354. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  8355. <li><code>total</code>: integer - Total number of event reports related to the query
  8356. (<code>user_id</code> and <code>room_id</code>).</li>
  8357. </ul>
  8358. <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>
  8359. <p>This API returns information about a specific event report.</p>
  8360. <p>The api is:</p>
  8361. <pre><code>GET /_synapse/admin/v1/event_reports/&lt;report_id&gt;
  8362. </code></pre>
  8363. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8364. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8365. <p>It returns a JSON body like the following:</p>
  8366. <pre><code class="language-jsonc">{
  8367. &quot;event_id&quot;: &quot;$bNUFCwGzWca1meCGkjp-zwslF-GfVcXukvRLI1_FaVY&quot;,
  8368. &quot;event_json&quot;: {
  8369. &quot;auth_events&quot;: [
  8370. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;,
  8371. &quot;$oggsNXxzPFRE3y53SUNd7nsj69-QzKv03a1RucHu-ws&quot;
  8372. ],
  8373. &quot;content&quot;: {
  8374. &quot;body&quot;: &quot;matrix.org: This Week in Matrix&quot;,
  8375. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  8376. &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;,
  8377. &quot;msgtype&quot;: &quot;m.notice&quot;
  8378. },
  8379. &quot;depth&quot;: 546,
  8380. &quot;hashes&quot;: {
  8381. &quot;sha256&quot;: &quot;xK1//xnmvHJIOvbgXlkI8eEqdvoMmihVDJ9J4SNlsAw&quot;
  8382. },
  8383. &quot;origin&quot;: &quot;matrix.org&quot;,
  8384. &quot;origin_server_ts&quot;: 1592291711430,
  8385. &quot;prev_events&quot;: [
  8386. &quot;$YK4arsKKcc0LRoe700pS8DSjOvUT4NDv0HfInlMFw2M&quot;
  8387. ],
  8388. &quot;prev_state&quot;: [],
  8389. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8390. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8391. &quot;signatures&quot;: {
  8392. &quot;matrix.org&quot;: {
  8393. &quot;ed25519:a_JaEG&quot;: &quot;cs+OUKW/iHx5pEidbWxh0UiNNHwe46Ai9LwNz+Ah16aWDNszVIe2gaAcVZfvNsBhakQTew51tlKmL2kspXk/Dg&quot;
  8394. }
  8395. },
  8396. &quot;type&quot;: &quot;m.room.message&quot;,
  8397. &quot;unsigned&quot;: {
  8398. &quot;age_ts&quot;: 1592291711430,
  8399. }
  8400. },
  8401. &quot;id&quot;: &lt;report_id&gt;,
  8402. &quot;reason&quot;: &quot;foo&quot;,
  8403. &quot;score&quot;: -100,
  8404. &quot;received_ts&quot;: 1570897107409,
  8405. &quot;canonical_alias&quot;: &quot;#alias1:matrix.org&quot;,
  8406. &quot;room_id&quot;: &quot;!ERAgBpSOcCCuTJqQPk:matrix.org&quot;,
  8407. &quot;name&quot;: &quot;Matrix HQ&quot;,
  8408. &quot;sender&quot;: &quot;@foobar:matrix.org&quot;,
  8409. &quot;user_id&quot;: &quot;@foo:matrix.org&quot;
  8410. }
  8411. </code></pre>
  8412. <p><strong>URL parameters:</strong></p>
  8413. <ul>
  8414. <li><code>report_id</code>: string - The ID of the event report.</li>
  8415. </ul>
  8416. <p><strong>Response</strong></p>
  8417. <p>The following fields are returned in the JSON response body:</p>
  8418. <ul>
  8419. <li><code>id</code>: integer - ID of event report.</li>
  8420. <li><code>received_ts</code>: integer - The timestamp (in milliseconds since the unix epoch) when this
  8421. report was sent.</li>
  8422. <li><code>room_id</code>: string - The ID of the room in which the event being reported is located.</li>
  8423. <li><code>name</code>: string - The name of the room.</li>
  8424. <li><code>event_id</code>: string - The ID of the reported event.</li>
  8425. <li><code>user_id</code>: string - This is the user who reported the event and wrote the reason.</li>
  8426. <li><code>reason</code>: string - Comment made by the <code>user_id</code> in this report. May be blank.</li>
  8427. <li><code>score</code>: integer - Content is reported based upon a negative score, where -100 is
  8428. &quot;most offensive&quot; and 0 is &quot;inoffensive&quot;.</li>
  8429. <li><code>sender</code>: string - This is the ID of the user who sent the original message/event that
  8430. was reported.</li>
  8431. <li><code>canonical_alias</code>: string - The canonical alias of the room. <code>null</code> if the room does not
  8432. have a canonical alias set.</li>
  8433. <li><code>event_json</code>: object - Details of the original event that was reported.</li>
  8434. </ul>
  8435. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-1"><a class="header" href="#contents-1">Contents</a></h1>
  8436. <ul>
  8437. <li><a href="admin_api/media_admin_api.html#querying-media">Querying media</a>
  8438. <ul>
  8439. <li><a href="admin_api/media_admin_api.html#list-all-media-in-a-room">List all media in a room</a></li>
  8440. <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>
  8441. </ul>
  8442. </li>
  8443. <li><a href="admin_api/media_admin_api.html#quarantine-media">Quarantine media</a>
  8444. <ul>
  8445. <li><a href="admin_api/media_admin_api.html#quarantining-media-by-id">Quarantining media by ID</a></li>
  8446. <li><a href="admin_api/media_admin_api.html#remove-media-from-quarantine-by-id">Remove media from quarantine by ID</a></li>
  8447. <li><a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">Quarantining media in a room</a></li>
  8448. <li><a href="admin_api/media_admin_api.html#quarantining-all-media-of-a-user">Quarantining all media of a user</a></li>
  8449. <li><a href="admin_api/media_admin_api.html#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></li>
  8450. <li><a href="admin_api/media_admin_api.html#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></li>
  8451. </ul>
  8452. </li>
  8453. <li><a href="admin_api/media_admin_api.html#delete-local-media">Delete local media</a>
  8454. <ul>
  8455. <li><a href="admin_api/media_admin_api.html#delete-a-specific-local-media">Delete a specific local media</a></li>
  8456. <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>
  8457. <li><a href="admin_api/media_admin_api.html#delete-media-uploaded-by-a-user">Delete media uploaded by a user</a></li>
  8458. </ul>
  8459. </li>
  8460. <li><a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a></li>
  8461. </ul>
  8462. <h1 id="querying-media"><a class="header" href="#querying-media">Querying media</a></h1>
  8463. <p>These APIs allow extracting media information from the homeserver.</p>
  8464. <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>
  8465. <p>This API gets a list of known media in a room.
  8466. However, it only shows media from unencrypted events or rooms.</p>
  8467. <p>The API is:</p>
  8468. <pre><code>GET /_synapse/admin/v1/room/&lt;room_id&gt;/media
  8469. </code></pre>
  8470. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8471. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8472. <p>The API returns a JSON body like the following:</p>
  8473. <pre><code class="language-json">{
  8474. &quot;local&quot;: [
  8475. &quot;mxc://localhost/xwvutsrqponmlkjihgfedcba&quot;,
  8476. &quot;mxc://localhost/abcdefghijklmnopqrstuvwx&quot;
  8477. ],
  8478. &quot;remote&quot;: [
  8479. &quot;mxc://matrix.org/xwvutsrqponmlkjihgfedcba&quot;,
  8480. &quot;mxc://matrix.org/abcdefghijklmnopqrstuvwx&quot;
  8481. ]
  8482. }
  8483. </code></pre>
  8484. <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>
  8485. <p>Listing all media that has been uploaded by a local user can be achieved through
  8486. the use of the
  8487. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>
  8488. Admin API.</p>
  8489. <h1 id="quarantine-media"><a class="header" href="#quarantine-media">Quarantine media</a></h1>
  8490. <p>Quarantining media means that it is marked as inaccessible by users. It applies
  8491. to any local media, and any locally-cached copies of remote media.</p>
  8492. <p>The media file itself (and any thumbnails) is not deleted from the server.</p>
  8493. <h2 id="quarantining-media-by-id"><a class="header" href="#quarantining-media-by-id">Quarantining media by ID</a></h2>
  8494. <p>This API quarantines a single piece of local or remote media.</p>
  8495. <p>Request:</p>
  8496. <pre><code>POST /_synapse/admin/v1/media/quarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8497. {}
  8498. </code></pre>
  8499. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8500. form of <code>abcdefg12345...</code>.</p>
  8501. <p>Response:</p>
  8502. <pre><code class="language-json">{}
  8503. </code></pre>
  8504. <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>
  8505. <p>This API removes a single piece of local or remote media from quarantine.</p>
  8506. <p>Request:</p>
  8507. <pre><code>POST /_synapse/admin/v1/media/unquarantine/&lt;server_name&gt;/&lt;media_id&gt;
  8508. {}
  8509. </code></pre>
  8510. <p>Where <code>server_name</code> is in the form of <code>example.org</code>, and <code>media_id</code> is in the
  8511. form of <code>abcdefg12345...</code>.</p>
  8512. <p>Response:</p>
  8513. <pre><code class="language-json">{}
  8514. </code></pre>
  8515. <h2 id="quarantining-media-in-a-room"><a class="header" href="#quarantining-media-in-a-room">Quarantining media in a room</a></h2>
  8516. <p>This API quarantines all local and remote media in a room.</p>
  8517. <p>Request:</p>
  8518. <pre><code>POST /_synapse/admin/v1/room/&lt;room_id&gt;/media/quarantine
  8519. {}
  8520. </code></pre>
  8521. <p>Where <code>room_id</code> is in the form of <code>!roomid12345:example.org</code>.</p>
  8522. <p>Response:</p>
  8523. <pre><code class="language-json">{
  8524. &quot;num_quarantined&quot;: 10
  8525. }
  8526. </code></pre>
  8527. <p>The following fields are returned in the JSON response body:</p>
  8528. <ul>
  8529. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8530. </ul>
  8531. <p>Note that there is a legacy endpoint, <code>POST /_synapse/admin/v1/quarantine_media/&lt;room_id&gt;</code>, that operates the same.
  8532. However, it is deprecated and may be removed in a future release.</p>
  8533. <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>
  8534. <p>This API quarantines all <em>local</em> media that a <em>local</em> user has uploaded. That is to say, if
  8535. you would like to quarantine media uploaded by a user on a remote homeserver, you should
  8536. instead use one of the other APIs.</p>
  8537. <p>Request:</p>
  8538. <pre><code>POST /_synapse/admin/v1/user/&lt;user_id&gt;/media/quarantine
  8539. {}
  8540. </code></pre>
  8541. <p>URL Parameters</p>
  8542. <ul>
  8543. <li><code>user_id</code>: string - User ID in the form of <code>@bob:example.org</code></li>
  8544. </ul>
  8545. <p>Response:</p>
  8546. <pre><code class="language-json">{
  8547. &quot;num_quarantined&quot;: 10
  8548. }
  8549. </code></pre>
  8550. <p>The following fields are returned in the JSON response body:</p>
  8551. <ul>
  8552. <li><code>num_quarantined</code>: integer - The number of media items successfully quarantined</li>
  8553. </ul>
  8554. <h2 id="protecting-media-from-being-quarantined"><a class="header" href="#protecting-media-from-being-quarantined">Protecting media from being quarantined</a></h2>
  8555. <p>This API protects a single piece of local media from being quarantined using the
  8556. above APIs. This is useful for sticker packs and other shared media which you do
  8557. not want to get quarantined, especially when
  8558. <a href="admin_api/media_admin_api.html#quarantining-media-in-a-room">quarantining media in a room</a>.</p>
  8559. <p>Request:</p>
  8560. <pre><code>POST /_synapse/admin/v1/media/protect/&lt;media_id&gt;
  8561. {}
  8562. </code></pre>
  8563. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8564. <p>Response:</p>
  8565. <pre><code class="language-json">{}
  8566. </code></pre>
  8567. <h2 id="unprotecting-media-from-being-quarantined"><a class="header" href="#unprotecting-media-from-being-quarantined">Unprotecting media from being quarantined</a></h2>
  8568. <p>This API reverts the protection of a media.</p>
  8569. <p>Request:</p>
  8570. <pre><code>POST /_synapse/admin/v1/media/unprotect/&lt;media_id&gt;
  8571. {}
  8572. </code></pre>
  8573. <p>Where <code>media_id</code> is in the form of <code>abcdefg12345...</code>.</p>
  8574. <p>Response:</p>
  8575. <pre><code class="language-json">{}
  8576. </code></pre>
  8577. <h1 id="delete-local-media"><a class="header" href="#delete-local-media">Delete local media</a></h1>
  8578. <p>This API deletes the <em>local</em> media from the disk of your own server.
  8579. This includes any local thumbnails and copies of media downloaded from
  8580. remote homeservers.
  8581. This API will not affect media that has been uploaded to external
  8582. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).
  8583. See also <a href="admin_api/media_admin_api.html#purge-remote-media-api">Purge Remote Media API</a>.</p>
  8584. <h2 id="delete-a-specific-local-media"><a class="header" href="#delete-a-specific-local-media">Delete a specific local media</a></h2>
  8585. <p>Delete a specific <code>media_id</code>.</p>
  8586. <p>Request:</p>
  8587. <pre><code>DELETE /_synapse/admin/v1/media/&lt;server_name&gt;/&lt;media_id&gt;
  8588. {}
  8589. </code></pre>
  8590. <p>URL Parameters</p>
  8591. <ul>
  8592. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>)</li>
  8593. <li><code>media_id</code>: string - The ID of the media (e.g <code>abcdefghijklmnopqrstuvwx</code>)</li>
  8594. </ul>
  8595. <p>Response:</p>
  8596. <pre><code class="language-json">{
  8597. &quot;deleted_media&quot;: [
  8598. &quot;abcdefghijklmnopqrstuvwx&quot;
  8599. ],
  8600. &quot;total&quot;: 1
  8601. }
  8602. </code></pre>
  8603. <p>The following fields are returned in the JSON response body:</p>
  8604. <ul>
  8605. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8606. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8607. </ul>
  8608. <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>
  8609. <p>Request:</p>
  8610. <pre><code>POST /_synapse/admin/v1/media/&lt;server_name&gt;/delete?before_ts=&lt;before_ts&gt;
  8611. {}
  8612. </code></pre>
  8613. <p>URL Parameters</p>
  8614. <ul>
  8615. <li><code>server_name</code>: string - The name of your local server (e.g <code>matrix.org</code>).</li>
  8616. <li><code>before_ts</code>: string representing a positive integer - Unix timestamp in ms.
  8617. Files that were last used before this timestamp will be deleted. It is the timestamp of
  8618. last access and not the timestamp creation.</li>
  8619. <li><code>size_gt</code>: Optional - string representing a positive integer - Size of the media in bytes.
  8620. Files that are larger will be deleted. Defaults to <code>0</code>.</li>
  8621. <li><code>keep_profiles</code>: Optional - string representing a boolean - Switch to also delete files
  8622. that are still used in image data (e.g user profile, room avatar).
  8623. If <code>false</code> these files will be deleted. Defaults to <code>true</code>.</li>
  8624. </ul>
  8625. <p>Response:</p>
  8626. <pre><code class="language-json">{
  8627. &quot;deleted_media&quot;: [
  8628. &quot;abcdefghijklmnopqrstuvwx&quot;,
  8629. &quot;abcdefghijklmnopqrstuvwz&quot;
  8630. ],
  8631. &quot;total&quot;: 2
  8632. }
  8633. </code></pre>
  8634. <p>The following fields are returned in the JSON response body:</p>
  8635. <ul>
  8636. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  8637. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  8638. </ul>
  8639. <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>
  8640. <p>You can find details of how to delete multiple media uploaded by a user in
  8641. <a href="admin_api/user_admin_api.html#delete-media-uploaded-by-a-user">User Admin API</a>.</p>
  8642. <h1 id="purge-remote-media-api"><a class="header" href="#purge-remote-media-api">Purge Remote Media API</a></h1>
  8643. <p>The purge remote media API allows server admins to purge old cached remote media.</p>
  8644. <p>The API is:</p>
  8645. <pre><code>POST /_synapse/admin/v1/purge_media_cache?before_ts=&lt;unix_timestamp_in_ms&gt;
  8646. {}
  8647. </code></pre>
  8648. <p>URL Parameters</p>
  8649. <ul>
  8650. <li><code>unix_timestamp_in_ms</code>: string representing a positive integer - Unix timestamp in ms.
  8651. All cached media that was last accessed before this timestamp will be removed.</li>
  8652. </ul>
  8653. <p>Response:</p>
  8654. <pre><code class="language-json">{
  8655. &quot;deleted&quot;: 10
  8656. }
  8657. </code></pre>
  8658. <p>The following fields are returned in the JSON response body:</p>
  8659. <ul>
  8660. <li><code>deleted</code>: integer - The number of media items successfully deleted</li>
  8661. </ul>
  8662. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8663. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  8664. <p>If the user re-requests purged remote media, synapse will re-request the media
  8665. from the originating server.</p>
  8666. <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>
  8667. <p>The purge history API allows server admins to purge historic events from their
  8668. database, reclaiming disk space.</p>
  8669. <p>Depending on the amount of history being purged a call to the API may take
  8670. several minutes or longer. During this period users will not be able to
  8671. paginate further back in the room from the point being purged from.</p>
  8672. <p>Note that Synapse requires at least one message in each room, so it will never
  8673. delete the last message in a room.</p>
  8674. <p>The API is:</p>
  8675. <pre><code>POST /_synapse/admin/v1/purge_history/&lt;room_id&gt;[/&lt;event_id&gt;]
  8676. </code></pre>
  8677. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  8678. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  8679. <p>By default, events sent by local users are not deleted, as they may represent
  8680. the only copies of this content in existence. (Events sent by remote users are
  8681. deleted.)</p>
  8682. <p>Room state data (such as joins, leaves, topic) is always preserved.</p>
  8683. <p>To delete local message events as well, set <code>delete_local_events</code> in the body:</p>
  8684. <pre><code>{
  8685. &quot;delete_local_events&quot;: true
  8686. }
  8687. </code></pre>
  8688. <p>The caller must specify the point in the room to purge up to. This can be
  8689. specified by including an event_id in the URI, or by setting a
  8690. <code>purge_up_to_event_id</code> or <code>purge_up_to_ts</code> in the request body. If an event
  8691. id is given, that event (and others at the same graph depth) will be retained.
  8692. If <code>purge_up_to_ts</code> is given, it should be a timestamp since the unix epoch,
  8693. in milliseconds.</p>
  8694. <p>The API starts the purge running, and returns immediately with a JSON body with
  8695. a purge id:</p>
  8696. <pre><code class="language-json">{
  8697. &quot;purge_id&quot;: &quot;&lt;opaque id&gt;&quot;
  8698. }
  8699. </code></pre>
  8700. <h2 id="purge-status-query"><a class="header" href="#purge-status-query">Purge status query</a></h2>
  8701. <p>It is possible to poll for updates on recent purges with a second API;</p>
  8702. <pre><code>GET /_synapse/admin/v1/purge_history_status/&lt;purge_id&gt;
  8703. </code></pre>
  8704. <p>Again, you will need to authenticate by providing an <code>access_token</code> for a
  8705. server admin.</p>
  8706. <p>This API returns a JSON body like the following:</p>
  8707. <pre><code class="language-json">{
  8708. &quot;status&quot;: &quot;active&quot;
  8709. }
  8710. </code></pre>
  8711. <p>The status will be one of <code>active</code>, <code>complete</code>, or <code>failed</code>.</p>
  8712. <h2 id="reclaim-disk-space-postgres"><a class="header" href="#reclaim-disk-space-postgres">Reclaim disk space (Postgres)</a></h2>
  8713. <p>To reclaim the disk space and return it to the operating system, you need to run
  8714. <code>VACUUM FULL;</code> on the database.</p>
  8715. <p><a href="https://www.postgresql.org/docs/current/sql-vacuum.html">https://www.postgresql.org/docs/current/sql-vacuum.html</a></p>
  8716. <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>
  8717. <p>This API allows for the creation of users in an administrative and
  8718. non-interactive way. This is generally used for bootstrapping a Synapse
  8719. instance with administrator accounts.</p>
  8720. <p>To authenticate yourself to the server, you will need both the shared secret
  8721. (<code>registration_shared_secret</code> in the homeserver configuration), and a
  8722. one-time nonce. If the registration shared secret is not configured, this API
  8723. is not enabled.</p>
  8724. <p>To fetch the nonce, you need to request one from the API:</p>
  8725. <pre><code>&gt; GET /_synapse/admin/v1/register
  8726. &lt; {&quot;nonce&quot;: &quot;thisisanonce&quot;}
  8727. </code></pre>
  8728. <p>Once you have the nonce, you can make a <code>POST</code> to the same URL with a JSON
  8729. body containing the nonce, username, password, whether they are an admin
  8730. (optional, False by default), and a HMAC digest of the content. Also you can
  8731. set the displayname (optional, <code>username</code> by default).</p>
  8732. <p>As an example:</p>
  8733. <pre><code>&gt; POST /_synapse/admin/v1/register
  8734. &gt; {
  8735. &quot;nonce&quot;: &quot;thisisanonce&quot;,
  8736. &quot;username&quot;: &quot;pepper_roni&quot;,
  8737. &quot;displayname&quot;: &quot;Pepper Roni&quot;,
  8738. &quot;password&quot;: &quot;pizza&quot;,
  8739. &quot;admin&quot;: true,
  8740. &quot;mac&quot;: &quot;mac_digest_here&quot;
  8741. }
  8742. &lt; {
  8743. &quot;access_token&quot;: &quot;token_here&quot;,
  8744. &quot;user_id&quot;: &quot;@pepper_roni:localhost&quot;,
  8745. &quot;home_server&quot;: &quot;test&quot;,
  8746. &quot;device_id&quot;: &quot;device_id_here&quot;
  8747. }
  8748. </code></pre>
  8749. <p>The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
  8750. the shared secret and the content being the nonce, user, password, either the
  8751. string &quot;admin&quot; or &quot;notadmin&quot;, and optionally the user_type
  8752. each separated by NULs. For an example of generation in Python:</p>
  8753. <pre><code class="language-python">import hmac, hashlib
  8754. def generate_mac(nonce, user, password, admin=False, user_type=None):
  8755. mac = hmac.new(
  8756. key=shared_secret,
  8757. digestmod=hashlib.sha1,
  8758. )
  8759. mac.update(nonce.encode('utf8'))
  8760. mac.update(b&quot;\x00&quot;)
  8761. mac.update(user.encode('utf8'))
  8762. mac.update(b&quot;\x00&quot;)
  8763. mac.update(password.encode('utf8'))
  8764. mac.update(b&quot;\x00&quot;)
  8765. mac.update(b&quot;admin&quot; if admin else b&quot;notadmin&quot;)
  8766. if user_type:
  8767. mac.update(b&quot;\x00&quot;)
  8768. mac.update(user_type.encode('utf8'))
  8769. return mac.hexdigest()
  8770. </code></pre>
  8771. <div style="break-before: page; page-break-before: always;"></div><h1 id="registration-tokens"><a class="header" href="#registration-tokens">Registration Tokens</a></h1>
  8772. <p>This API allows you to manage tokens which can be used to authenticate
  8773. registration requests, as proposed in <a href="https://github.com/govynnus/matrix-doc/blob/token-registration/proposals/3231-token-authenticated-registration.md">MSC3231</a>.
  8774. To use it, you will need to enable the <code>registration_requires_token</code> config
  8775. option, and authenticate by providing an <code>access_token</code> for a server admin:
  8776. see <a href="usage/administration/admin_api/../../usage/administration/admin_api">Admin API</a>.
  8777. Note that this API is still experimental; not all clients may support it yet.</p>
  8778. <h2 id="registration-token-objects"><a class="header" href="#registration-token-objects">Registration token objects</a></h2>
  8779. <p>Most endpoints make use of JSON objects that contain details about tokens.
  8780. These objects have the following fields:</p>
  8781. <ul>
  8782. <li><code>token</code>: The token which can be used to authenticate registration.</li>
  8783. <li><code>uses_allowed</code>: The number of times the token can be used to complete a
  8784. registration before it becomes invalid.</li>
  8785. <li><code>pending</code>: The number of pending uses the token has. When someone uses
  8786. the token to authenticate themselves, the pending counter is incremented
  8787. so that the token is not used more than the permitted number of times.
  8788. When the person completes registration the pending counter is decremented,
  8789. and the completed counter is incremented.</li>
  8790. <li><code>completed</code>: The number of times the token has been used to successfully
  8791. complete a registration.</li>
  8792. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  8793. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  8794. To convert this into a human-readable form you can remove the milliseconds
  8795. and use the <code>date</code> command. For example, <code>date -d '@1625394937'</code>.</li>
  8796. </ul>
  8797. <h2 id="list-all-tokens"><a class="header" href="#list-all-tokens">List all tokens</a></h2>
  8798. <p>Lists all tokens and details about them. If the request is successful, the top
  8799. level JSON object will have a <code>registration_tokens</code> key which is an array of
  8800. registration token objects.</p>
  8801. <pre><code>GET /_synapse/admin/v1/registration_tokens
  8802. </code></pre>
  8803. <p>Optional query parameters:</p>
  8804. <ul>
  8805. <li><code>valid</code>: <code>true</code> or <code>false</code>. If <code>true</code>, only valid tokens are returned.
  8806. If <code>false</code>, only tokens that have expired or have had all uses exhausted are
  8807. returned. If omitted, all tokens are returned regardless of validity.</li>
  8808. </ul>
  8809. <p>Example:</p>
  8810. <pre><code>GET /_synapse/admin/v1/registration_tokens
  8811. </code></pre>
  8812. <pre><code>200 OK
  8813. {
  8814. &quot;registration_tokens&quot;: [
  8815. {
  8816. &quot;token&quot;: &quot;abcd&quot;,
  8817. &quot;uses_allowed&quot;: 3,
  8818. &quot;pending&quot;: 0,
  8819. &quot;completed&quot;: 1,
  8820. &quot;expiry_time&quot;: null
  8821. },
  8822. {
  8823. &quot;token&quot;: &quot;pqrs&quot;,
  8824. &quot;uses_allowed&quot;: 2,
  8825. &quot;pending&quot;: 1,
  8826. &quot;completed&quot;: 1,
  8827. &quot;expiry_time&quot;: null
  8828. },
  8829. {
  8830. &quot;token&quot;: &quot;wxyz&quot;,
  8831. &quot;uses_allowed&quot;: null,
  8832. &quot;pending&quot;: 0,
  8833. &quot;completed&quot;: 9,
  8834. &quot;expiry_time&quot;: 1625394937000 // 2021-07-04 10:35:37 UTC
  8835. }
  8836. ]
  8837. }
  8838. </code></pre>
  8839. <p>Example using the <code>valid</code> query parameter:</p>
  8840. <pre><code>GET /_synapse/admin/v1/registration_tokens?valid=false
  8841. </code></pre>
  8842. <pre><code>200 OK
  8843. {
  8844. &quot;registration_tokens&quot;: [
  8845. {
  8846. &quot;token&quot;: &quot;pqrs&quot;,
  8847. &quot;uses_allowed&quot;: 2,
  8848. &quot;pending&quot;: 1,
  8849. &quot;completed&quot;: 1,
  8850. &quot;expiry_time&quot;: null
  8851. },
  8852. {
  8853. &quot;token&quot;: &quot;wxyz&quot;,
  8854. &quot;uses_allowed&quot;: null,
  8855. &quot;pending&quot;: 0,
  8856. &quot;completed&quot;: 9,
  8857. &quot;expiry_time&quot;: 1625394937000 // 2021-07-04 10:35:37 UTC
  8858. }
  8859. ]
  8860. }
  8861. </code></pre>
  8862. <h2 id="get-one-token"><a class="header" href="#get-one-token">Get one token</a></h2>
  8863. <p>Get details about a single token. If the request is successful, the response
  8864. body will be a registration token object.</p>
  8865. <pre><code>GET /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  8866. </code></pre>
  8867. <p>Path parameters:</p>
  8868. <ul>
  8869. <li><code>token</code>: The registration token to return details of.</li>
  8870. </ul>
  8871. <p>Example:</p>
  8872. <pre><code>GET /_synapse/admin/v1/registration_tokens/abcd
  8873. </code></pre>
  8874. <pre><code>200 OK
  8875. {
  8876. &quot;token&quot;: &quot;abcd&quot;,
  8877. &quot;uses_allowed&quot;: 3,
  8878. &quot;pending&quot;: 0,
  8879. &quot;completed&quot;: 1,
  8880. &quot;expiry_time&quot;: null
  8881. }
  8882. </code></pre>
  8883. <h2 id="create-token"><a class="header" href="#create-token">Create token</a></h2>
  8884. <p>Create a new registration token. If the request is successful, the newly created
  8885. token will be returned as a registration token object in the response body.</p>
  8886. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  8887. </code></pre>
  8888. <p>The request body must be a JSON object and can contain the following fields:</p>
  8889. <ul>
  8890. <li><code>token</code>: The registration token. A string of no more than 64 characters that
  8891. consists only of characters matched by the regex <code>[A-Za-z0-9-_]</code>.
  8892. Default: randomly generated.</li>
  8893. <li><code>uses_allowed</code>: The integer number of times the token can be used to complete
  8894. a registration before it becomes invalid.
  8895. Default: <code>null</code> (unlimited uses).</li>
  8896. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  8897. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  8898. You could use, for example, <code>date '+%s000' -d 'tomorrow'</code>.
  8899. Default: <code>null</code> (token does not expire).</li>
  8900. <li><code>length</code>: The length of the token randomly generated if <code>token</code> is not
  8901. specified. Must be between 1 and 64 inclusive. Default: <code>16</code>.</li>
  8902. </ul>
  8903. <p>If a field is omitted the default is used.</p>
  8904. <p>Example using defaults:</p>
  8905. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  8906. {}
  8907. </code></pre>
  8908. <pre><code>200 OK
  8909. {
  8910. &quot;token&quot;: &quot;0M-9jbkf2t_Tgiw1&quot;,
  8911. &quot;uses_allowed&quot;: null,
  8912. &quot;pending&quot;: 0,
  8913. &quot;completed&quot;: 0,
  8914. &quot;expiry_time&quot;: null
  8915. }
  8916. </code></pre>
  8917. <p>Example specifying some fields:</p>
  8918. <pre><code>POST /_synapse/admin/v1/registration_tokens/new
  8919. {
  8920. &quot;token&quot;: &quot;defg&quot;,
  8921. &quot;uses_allowed&quot;: 1
  8922. }
  8923. </code></pre>
  8924. <pre><code>200 OK
  8925. {
  8926. &quot;token&quot;: &quot;defg&quot;,
  8927. &quot;uses_allowed&quot;: 1,
  8928. &quot;pending&quot;: 0,
  8929. &quot;completed&quot;: 0,
  8930. &quot;expiry_time&quot;: null
  8931. }
  8932. </code></pre>
  8933. <h2 id="update-token"><a class="header" href="#update-token">Update token</a></h2>
  8934. <p>Update the number of allowed uses or expiry time of a token. If the request is
  8935. successful, the updated token will be returned as a registration token object
  8936. in the response body.</p>
  8937. <pre><code>PUT /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  8938. </code></pre>
  8939. <p>Path parameters:</p>
  8940. <ul>
  8941. <li><code>token</code>: The registration token to update.</li>
  8942. </ul>
  8943. <p>The request body must be a JSON object and can contain the following fields:</p>
  8944. <ul>
  8945. <li><code>uses_allowed</code>: The integer number of times the token can be used to complete
  8946. a registration before it becomes invalid. By setting <code>uses_allowed</code> to <code>0</code>
  8947. the token can be easily made invalid without deleting it.
  8948. If <code>null</code> the token will have an unlimited number of uses.</li>
  8949. <li><code>expiry_time</code>: The latest time the token is valid. Given as the number of
  8950. milliseconds since 1970-01-01 00:00:00 UTC (the start of the Unix epoch).
  8951. If <code>null</code> the token will not expire.</li>
  8952. </ul>
  8953. <p>If a field is omitted its value is not modified.</p>
  8954. <p>Example:</p>
  8955. <pre><code>PUT /_synapse/admin/v1/registration_tokens/defg
  8956. {
  8957. &quot;expiry_time&quot;: 4781243146000 // 2121-07-06 11:05:46 UTC
  8958. }
  8959. </code></pre>
  8960. <pre><code>200 OK
  8961. {
  8962. &quot;token&quot;: &quot;defg&quot;,
  8963. &quot;uses_allowed&quot;: 1,
  8964. &quot;pending&quot;: 0,
  8965. &quot;completed&quot;: 0,
  8966. &quot;expiry_time&quot;: 4781243146000
  8967. }
  8968. </code></pre>
  8969. <h2 id="delete-token"><a class="header" href="#delete-token">Delete token</a></h2>
  8970. <p>Delete a registration token. If the request is successful, the response body
  8971. will be an empty JSON object.</p>
  8972. <pre><code>DELETE /_synapse/admin/v1/registration_tokens/&lt;token&gt;
  8973. </code></pre>
  8974. <p>Path parameters:</p>
  8975. <ul>
  8976. <li><code>token</code>: The registration token to delete.</li>
  8977. </ul>
  8978. <p>Example:</p>
  8979. <pre><code>DELETE /_synapse/admin/v1/registration_tokens/wxyz
  8980. </code></pre>
  8981. <pre><code>200 OK
  8982. {}
  8983. </code></pre>
  8984. <h2 id="errors"><a class="header" href="#errors">Errors</a></h2>
  8985. <p>If a request fails a &quot;standard error response&quot; will be returned as defined in
  8986. the <a href="https://matrix.org/docs/spec/client_server/r0.6.1#api-standards">Matrix Client-Server API specification</a>.</p>
  8987. <p>For example, if the token specified in a path parameter does not exist a
  8988. <code>404 Not Found</code> error will be returned.</p>
  8989. <pre><code>GET /_synapse/admin/v1/registration_tokens/1234
  8990. </code></pre>
  8991. <pre><code>404 Not Found
  8992. {
  8993. &quot;errcode&quot;: &quot;M_NOT_FOUND&quot;,
  8994. &quot;error&quot;: &quot;No such registration token: 1234&quot;
  8995. }
  8996. </code></pre>
  8997. <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>
  8998. <p>This API allows an administrator to join an user account with a given <code>user_id</code>
  8999. to a room with a given <code>room_id_or_alias</code>. You can only modify the membership of
  9000. local users. The server administrator must be in the room and have permission to
  9001. invite users.</p>
  9002. <h2 id="parameters"><a class="header" href="#parameters">Parameters</a></h2>
  9003. <p>The following parameters are available:</p>
  9004. <ul>
  9005. <li><code>user_id</code> - Fully qualified user: for example, <code>@user:server.com</code>.</li>
  9006. <li><code>room_id_or_alias</code> - The room identifier or alias to join: for example,
  9007. <code>!636q39766251:server.com</code>.</li>
  9008. </ul>
  9009. <h2 id="usage-1"><a class="header" href="#usage-1">Usage</a></h2>
  9010. <pre><code>POST /_synapse/admin/v1/join/&lt;room_id_or_alias&gt;
  9011. {
  9012. &quot;user_id&quot;: &quot;@user:server.com&quot;
  9013. }
  9014. </code></pre>
  9015. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9016. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9017. <p>Response:</p>
  9018. <pre><code>{
  9019. &quot;room_id&quot;: &quot;!636q39766251:server.com&quot;
  9020. }
  9021. </code></pre>
  9022. <div style="break-before: page; page-break-before: always;"></div><h1 id="contents-2"><a class="header" href="#contents-2">Contents</a></h1>
  9023. <ul>
  9024. <li><a href="admin_api/rooms.html#list-room-api">List Room API</a></li>
  9025. <li><a href="admin_api/rooms.html#room-details-api">Room Details API</a></li>
  9026. <li><a href="admin_api/rooms.html#room-members-api">Room Members API</a></li>
  9027. <li><a href="admin_api/rooms.html#room-state-api">Room State API</a></li>
  9028. <li><a href="admin_api/rooms.html#delete-room-api">Delete Room API</a>
  9029. <ul>
  9030. <li><a href="admin_api/rooms.html#undoing-room-shutdowns">Undoing room shutdowns</a></li>
  9031. </ul>
  9032. </li>
  9033. <li><a href="admin_api/rooms.html#make-room-admin-api">Make Room Admin API</a></li>
  9034. <li><a href="admin_api/rooms.html#forward-extremities-admin-api">Forward Extremities Admin API</a></li>
  9035. <li><a href="admin_api/rooms.html#event-context-api">Event Context API</a></li>
  9036. </ul>
  9037. <h1 id="list-room-api"><a class="header" href="#list-room-api">List Room API</a></h1>
  9038. <p>The List Room admin API allows server admins to get a list of rooms on their
  9039. server. There are various parameters available that allow for filtering and
  9040. sorting the returned list. This API supports pagination.</p>
  9041. <p><strong>Parameters</strong></p>
  9042. <p>The following query parameters are available:</p>
  9043. <ul>
  9044. <li><code>from</code> - Offset in the returned list. Defaults to <code>0</code>.</li>
  9045. <li><code>limit</code> - Maximum amount of rooms to return. Defaults to <code>100</code>.</li>
  9046. <li><code>order_by</code> - The method in which to sort the returned list of rooms. Valid values are:
  9047. <ul>
  9048. <li><code>alphabetical</code> - Same as <code>name</code>. This is deprecated.</li>
  9049. <li><code>size</code> - Same as <code>joined_members</code>. This is deprecated.</li>
  9050. <li><code>name</code> - Rooms are ordered alphabetically by room name. This is the default.</li>
  9051. <li><code>canonical_alias</code> - Rooms are ordered alphabetically by main alias address of the room.</li>
  9052. <li><code>joined_members</code> - Rooms are ordered by the number of members. Largest to smallest.</li>
  9053. <li><code>joined_local_members</code> - Rooms are ordered by the number of local members. Largest to smallest.</li>
  9054. <li><code>version</code> - Rooms are ordered by room version. Largest to smallest.</li>
  9055. <li><code>creator</code> - Rooms are ordered alphabetically by creator of the room.</li>
  9056. <li><code>encryption</code> - Rooms are ordered alphabetically by the end-to-end encryption algorithm.</li>
  9057. <li><code>federatable</code> - Rooms are ordered by whether the room is federatable.</li>
  9058. <li><code>public</code> - Rooms are ordered by visibility in room list.</li>
  9059. <li><code>join_rules</code> - Rooms are ordered alphabetically by join rules of the room.</li>
  9060. <li><code>guest_access</code> - Rooms are ordered alphabetically by guest access option of the room.</li>
  9061. <li><code>history_visibility</code> - Rooms are ordered alphabetically by visibility of history of the room.</li>
  9062. <li><code>state_events</code> - Rooms are ordered by number of state events. Largest to smallest.</li>
  9063. </ul>
  9064. </li>
  9065. <li><code>dir</code> - Direction of room order. Either <code>f</code> for forwards or <code>b</code> for backwards. Setting
  9066. this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  9067. <li><code>search_term</code> - Filter rooms by their room name. Search term can be contained in any
  9068. part of the room name. Defaults to no filtering.</li>
  9069. </ul>
  9070. <p><strong>Response</strong></p>
  9071. <p>The following fields are possible in the JSON response body:</p>
  9072. <ul>
  9073. <li><code>rooms</code> - An array of objects, each containing information about a room.
  9074. <ul>
  9075. <li>Room objects contain the following fields:
  9076. <ul>
  9077. <li><code>room_id</code> - The ID of the room.</li>
  9078. <li><code>name</code> - The name of the room.</li>
  9079. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  9080. <li><code>joined_members</code> - How many users are currently in the room.</li>
  9081. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  9082. <li><code>version</code> - The version of the room as a string.</li>
  9083. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  9084. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  9085. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  9086. <li><code>public</code> - Whether the room is visible in room directory.</li>
  9087. <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>
  9088. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  9089. <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>
  9090. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  9091. </ul>
  9092. </li>
  9093. </ul>
  9094. </li>
  9095. <li><code>offset</code> - The current pagination offset in rooms. This parameter should be
  9096. used instead of <code>next_token</code> for room offset as <code>next_token</code> is
  9097. not intended to be parsed.</li>
  9098. <li><code>total_rooms</code> - The total number of rooms this query can return. Using this
  9099. and <code>offset</code>, you have enough information to know the current
  9100. progression through the list.</li>
  9101. <li><code>next_batch</code> - If this field is present, we know that there are potentially
  9102. more rooms on the server that did not all fit into this response.
  9103. We can use <code>next_batch</code> to get the &quot;next page&quot; of results. To do
  9104. so, simply repeat your request, setting the <code>from</code> parameter to
  9105. the value of <code>next_batch</code>.</li>
  9106. <li><code>prev_batch</code> - If this field is present, it is possible to paginate backwards.
  9107. Use <code>prev_batch</code> for the <code>from</code> value in the next request to
  9108. get the &quot;previous page&quot; of results.</li>
  9109. </ul>
  9110. <p>The API is:</p>
  9111. <p>A standard request with no filtering:</p>
  9112. <pre><code>GET /_synapse/admin/v1/rooms
  9113. </code></pre>
  9114. <p>A response body like the following is returned:</p>
  9115. <pre><code class="language-jsonc">{
  9116. &quot;rooms&quot;: [
  9117. {
  9118. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  9119. &quot;name&quot;: &quot;Matrix HQ&quot;,
  9120. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  9121. &quot;joined_members&quot;: 8326,
  9122. &quot;joined_local_members&quot;: 2,
  9123. &quot;version&quot;: &quot;1&quot;,
  9124. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9125. &quot;encryption&quot;: null,
  9126. &quot;federatable&quot;: true,
  9127. &quot;public&quot;: true,
  9128. &quot;join_rules&quot;: &quot;invite&quot;,
  9129. &quot;guest_access&quot;: null,
  9130. &quot;history_visibility&quot;: &quot;shared&quot;,
  9131. &quot;state_events&quot;: 93534
  9132. },
  9133. ... (8 hidden items) ...
  9134. {
  9135. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9136. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9137. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9138. &quot;joined_members&quot;: 314,
  9139. &quot;joined_local_members&quot;: 20,
  9140. &quot;version&quot;: &quot;4&quot;,
  9141. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9142. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9143. &quot;federatable&quot;: true,
  9144. &quot;public&quot;: false,
  9145. &quot;join_rules&quot;: &quot;invite&quot;,
  9146. &quot;guest_access&quot;: null,
  9147. &quot;history_visibility&quot;: &quot;shared&quot;,
  9148. &quot;state_events&quot;: 8345
  9149. }
  9150. ],
  9151. &quot;offset&quot;: 0,
  9152. &quot;total_rooms&quot;: 10
  9153. }
  9154. </code></pre>
  9155. <p>Filtering by room name:</p>
  9156. <pre><code>GET /_synapse/admin/v1/rooms?search_term=TWIM
  9157. </code></pre>
  9158. <p>A response body like the following is returned:</p>
  9159. <pre><code class="language-json">{
  9160. &quot;rooms&quot;: [
  9161. {
  9162. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9163. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9164. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9165. &quot;joined_members&quot;: 314,
  9166. &quot;joined_local_members&quot;: 20,
  9167. &quot;version&quot;: &quot;4&quot;,
  9168. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9169. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9170. &quot;federatable&quot;: true,
  9171. &quot;public&quot;: false,
  9172. &quot;join_rules&quot;: &quot;invite&quot;,
  9173. &quot;guest_access&quot;: null,
  9174. &quot;history_visibility&quot;: &quot;shared&quot;,
  9175. &quot;state_events&quot;: 8
  9176. }
  9177. ],
  9178. &quot;offset&quot;: 0,
  9179. &quot;total_rooms&quot;: 1
  9180. }
  9181. </code></pre>
  9182. <p>Paginating through a list of rooms:</p>
  9183. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size
  9184. </code></pre>
  9185. <p>A response body like the following is returned:</p>
  9186. <pre><code class="language-jsonc">{
  9187. &quot;rooms&quot;: [
  9188. {
  9189. &quot;room_id&quot;: &quot;!OGEhHVWSdvArJzumhm:matrix.org&quot;,
  9190. &quot;name&quot;: &quot;Matrix HQ&quot;,
  9191. &quot;canonical_alias&quot;: &quot;#matrix:matrix.org&quot;,
  9192. &quot;joined_members&quot;: 8326,
  9193. &quot;joined_local_members&quot;: 2,
  9194. &quot;version&quot;: &quot;1&quot;,
  9195. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9196. &quot;encryption&quot;: null,
  9197. &quot;federatable&quot;: true,
  9198. &quot;public&quot;: true,
  9199. &quot;join_rules&quot;: &quot;invite&quot;,
  9200. &quot;guest_access&quot;: null,
  9201. &quot;history_visibility&quot;: &quot;shared&quot;,
  9202. &quot;state_events&quot;: 93534
  9203. },
  9204. ... (98 hidden items) ...
  9205. {
  9206. &quot;room_id&quot;: &quot;!xYvNcQPhnkrdUmYczI:matrix.org&quot;,
  9207. &quot;name&quot;: &quot;This Week In Matrix (TWIM)&quot;,
  9208. &quot;canonical_alias&quot;: &quot;#twim:matrix.org&quot;,
  9209. &quot;joined_members&quot;: 314,
  9210. &quot;joined_local_members&quot;: 20,
  9211. &quot;version&quot;: &quot;4&quot;,
  9212. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9213. &quot;encryption&quot;: &quot;m.megolm.v1.aes-sha2&quot;,
  9214. &quot;federatable&quot;: true,
  9215. &quot;public&quot;: false,
  9216. &quot;join_rules&quot;: &quot;invite&quot;,
  9217. &quot;guest_access&quot;: null,
  9218. &quot;history_visibility&quot;: &quot;shared&quot;,
  9219. &quot;state_events&quot;: 8345
  9220. }
  9221. ],
  9222. &quot;offset&quot;: 0,
  9223. &quot;total_rooms&quot;: 150
  9224. &quot;next_token&quot;: 100
  9225. }
  9226. </code></pre>
  9227. <p>The presence of the <code>next_token</code> parameter tells us that there are more rooms
  9228. than returned in this request, and we need to make another request to get them.
  9229. To get the next batch of room results, we repeat our request, setting the <code>from</code>
  9230. parameter to the value of <code>next_token</code>.</p>
  9231. <pre><code>GET /_synapse/admin/v1/rooms?order_by=size&amp;from=100
  9232. </code></pre>
  9233. <p>A response body like the following is returned:</p>
  9234. <pre><code class="language-jsonc">{
  9235. &quot;rooms&quot;: [
  9236. {
  9237. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  9238. &quot;name&quot;: &quot;Music Theory&quot;,
  9239. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  9240. &quot;joined_members&quot;: 127,
  9241. &quot;joined_local_members&quot;: 2,
  9242. &quot;version&quot;: &quot;1&quot;,
  9243. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9244. &quot;encryption&quot;: null,
  9245. &quot;federatable&quot;: true,
  9246. &quot;public&quot;: true,
  9247. &quot;join_rules&quot;: &quot;invite&quot;,
  9248. &quot;guest_access&quot;: null,
  9249. &quot;history_visibility&quot;: &quot;shared&quot;,
  9250. &quot;state_events&quot;: 93534
  9251. },
  9252. ... (48 hidden items) ...
  9253. {
  9254. &quot;room_id&quot;: &quot;!twcBhHVdZlQWuuxBhN:termina.org.uk&quot;,
  9255. &quot;name&quot;: &quot;weechat-matrix&quot;,
  9256. &quot;canonical_alias&quot;: &quot;#weechat-matrix:termina.org.uk&quot;,
  9257. &quot;joined_members&quot;: 137,
  9258. &quot;joined_local_members&quot;: 20,
  9259. &quot;version&quot;: &quot;4&quot;,
  9260. &quot;creator&quot;: &quot;@foo:termina.org.uk&quot;,
  9261. &quot;encryption&quot;: null,
  9262. &quot;federatable&quot;: true,
  9263. &quot;public&quot;: true,
  9264. &quot;join_rules&quot;: &quot;invite&quot;,
  9265. &quot;guest_access&quot;: null,
  9266. &quot;history_visibility&quot;: &quot;shared&quot;,
  9267. &quot;state_events&quot;: 8345
  9268. }
  9269. ],
  9270. &quot;offset&quot;: 100,
  9271. &quot;prev_batch&quot;: 0,
  9272. &quot;total_rooms&quot;: 150
  9273. }
  9274. </code></pre>
  9275. <p>Once the <code>next_token</code> parameter is no longer present, we know we've reached the
  9276. end of the list.</p>
  9277. <h1 id="room-details-api"><a class="header" href="#room-details-api">Room Details API</a></h1>
  9278. <p>The Room Details admin API allows server admins to get all details of a room.</p>
  9279. <p>The following fields are possible in the JSON response body:</p>
  9280. <ul>
  9281. <li><code>room_id</code> - The ID of the room.</li>
  9282. <li><code>name</code> - The name of the room.</li>
  9283. <li><code>topic</code> - The topic of the room.</li>
  9284. <li><code>avatar</code> - The <code>mxc</code> URI to the avatar of the room.</li>
  9285. <li><code>canonical_alias</code> - The canonical (main) alias address of the room.</li>
  9286. <li><code>joined_members</code> - How many users are currently in the room.</li>
  9287. <li><code>joined_local_members</code> - How many local users are currently in the room.</li>
  9288. <li><code>joined_local_devices</code> - How many local devices are currently in the room.</li>
  9289. <li><code>version</code> - The version of the room as a string.</li>
  9290. <li><code>creator</code> - The <code>user_id</code> of the room creator.</li>
  9291. <li><code>encryption</code> - Algorithm of end-to-end encryption of messages. Is <code>null</code> if encryption is not active.</li>
  9292. <li><code>federatable</code> - Whether users on other servers can join this room.</li>
  9293. <li><code>public</code> - Whether the room is visible in room directory.</li>
  9294. <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>
  9295. <li><code>guest_access</code> - Whether guests can join the room. One of: [&quot;can_join&quot;, &quot;forbidden&quot;].</li>
  9296. <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>
  9297. <li><code>state_events</code> - Total number of state_events of a room. Complexity of the room.</li>
  9298. </ul>
  9299. <p>The API is:</p>
  9300. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9301. </code></pre>
  9302. <p>A response body like the following is returned:</p>
  9303. <pre><code class="language-json">{
  9304. &quot;room_id&quot;: &quot;!mscvqgqpHYjBGDxNym:matrix.org&quot;,
  9305. &quot;name&quot;: &quot;Music Theory&quot;,
  9306. &quot;avatar&quot;: &quot;mxc://matrix.org/AQDaVFlbkQoErdOgqWRgiGSV&quot;,
  9307. &quot;topic&quot;: &quot;Theory, Composition, Notation, Analysis&quot;,
  9308. &quot;canonical_alias&quot;: &quot;#musictheory:matrix.org&quot;,
  9309. &quot;joined_members&quot;: 127,
  9310. &quot;joined_local_members&quot;: 2,
  9311. &quot;joined_local_devices&quot;: 2,
  9312. &quot;version&quot;: &quot;1&quot;,
  9313. &quot;creator&quot;: &quot;@foo:matrix.org&quot;,
  9314. &quot;encryption&quot;: null,
  9315. &quot;federatable&quot;: true,
  9316. &quot;public&quot;: true,
  9317. &quot;join_rules&quot;: &quot;invite&quot;,
  9318. &quot;guest_access&quot;: null,
  9319. &quot;history_visibility&quot;: &quot;shared&quot;,
  9320. &quot;state_events&quot;: 93534
  9321. }
  9322. </code></pre>
  9323. <h1 id="room-members-api"><a class="header" href="#room-members-api">Room Members API</a></h1>
  9324. <p>The Room Members admin API allows server admins to get a list of all members of a room.</p>
  9325. <p>The response includes the following fields:</p>
  9326. <ul>
  9327. <li><code>members</code> - A list of all the members that are present in the room, represented by their ids.</li>
  9328. <li><code>total</code> - Total number of members in the room.</li>
  9329. </ul>
  9330. <p>The API is:</p>
  9331. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/members
  9332. </code></pre>
  9333. <p>A response body like the following is returned:</p>
  9334. <pre><code class="language-json">{
  9335. &quot;members&quot;: [
  9336. &quot;@foo:matrix.org&quot;,
  9337. &quot;@bar:matrix.org&quot;,
  9338. &quot;@foobar:matrix.org&quot;
  9339. ],
  9340. &quot;total&quot;: 3
  9341. }
  9342. </code></pre>
  9343. <h1 id="room-state-api"><a class="header" href="#room-state-api">Room State API</a></h1>
  9344. <p>The Room State admin API allows server admins to get a list of all state events in a room.</p>
  9345. <p>The response includes the following fields:</p>
  9346. <ul>
  9347. <li><code>state</code> - The current state of the room at the time of request.</li>
  9348. </ul>
  9349. <p>The API is:</p>
  9350. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/state
  9351. </code></pre>
  9352. <p>A response body like the following is returned:</p>
  9353. <pre><code class="language-json">{
  9354. &quot;state&quot;: [
  9355. {&quot;type&quot;: &quot;m.room.create&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9356. {&quot;type&quot;: &quot;m.room.power_levels&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true},
  9357. {&quot;type&quot;: &quot;m.room.name&quot;, &quot;state_key&quot;: &quot;&quot;, &quot;etc&quot;: true}
  9358. ]
  9359. }
  9360. </code></pre>
  9361. <h1 id="delete-room-api"><a class="header" href="#delete-room-api">Delete Room API</a></h1>
  9362. <p>The Delete Room admin API allows server admins to remove rooms from server
  9363. and block these rooms.</p>
  9364. <p>Shuts down a room. Moves all local users and room aliases automatically to a
  9365. new room if <code>new_room_user_id</code> is set. Otherwise local users only
  9366. leave the room without any information.</p>
  9367. <p>The new room will be created with the user specified by the <code>new_room_user_id</code> parameter
  9368. as room administrator and will contain a message explaining what happened. Users invited
  9369. to the new room will have power level <code>-10</code> by default, and thus be unable to speak.</p>
  9370. <p>If <code>block</code> is <code>True</code> it prevents new joins to the old room.</p>
  9371. <p>This API will remove all trace of the old room from your database after removing
  9372. all local users. If <code>purge</code> is <code>true</code> (the default), all traces of the old room will
  9373. be removed from your database after removing all local users. If you do not want
  9374. this to happen, set <code>purge</code> to <code>false</code>.
  9375. Depending on the amount of history being purged a call to the API may take
  9376. several minutes or longer.</p>
  9377. <p>The local server will only have the power to move local user and room aliases to
  9378. the new room. Users on other servers will be unaffected.</p>
  9379. <p>The API is:</p>
  9380. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id&gt;
  9381. </code></pre>
  9382. <p>with a body of:</p>
  9383. <pre><code class="language-json">{
  9384. &quot;new_room_user_id&quot;: &quot;@someuser:example.com&quot;,
  9385. &quot;room_name&quot;: &quot;Content Violation Notification&quot;,
  9386. &quot;message&quot;: &quot;Bad Room has been shutdown due to content violations on this server. Please review our Terms of Service.&quot;,
  9387. &quot;block&quot;: true,
  9388. &quot;purge&quot;: true
  9389. }
  9390. </code></pre>
  9391. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9392. server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9393. <p>A response body like the following is returned:</p>
  9394. <pre><code class="language-json">{
  9395. &quot;kicked_users&quot;: [
  9396. &quot;@foobar:example.com&quot;
  9397. ],
  9398. &quot;failed_to_kick_users&quot;: [],
  9399. &quot;local_aliases&quot;: [
  9400. &quot;#badroom:example.com&quot;,
  9401. &quot;#evilsaloon:example.com&quot;
  9402. ],
  9403. &quot;new_room_id&quot;: &quot;!newroomid:example.com&quot;
  9404. }
  9405. </code></pre>
  9406. <p><strong>Parameters</strong></p>
  9407. <p>The following parameters should be set in the URL:</p>
  9408. <ul>
  9409. <li><code>room_id</code> - The ID of the room.</li>
  9410. </ul>
  9411. <p>The following JSON body parameters are available:</p>
  9412. <ul>
  9413. <li><code>new_room_user_id</code> - Optional. If set, a new room will be created with this user ID
  9414. as the creator and admin, and all users in the old room will be moved into that
  9415. room. If not set, no new room will be created and the users will just be removed
  9416. from the old room. The user ID must be on the local server, but does not necessarily
  9417. have to belong to a registered user.</li>
  9418. <li><code>room_name</code> - Optional. A string representing the name of the room that new users will be
  9419. invited to. Defaults to <code>Content Violation Notification</code></li>
  9420. <li><code>message</code> - Optional. A string containing the first message that will be sent as
  9421. <code>new_room_user_id</code> in the new room. Ideally this will clearly convey why the
  9422. 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>
  9423. <li><code>block</code> - Optional. If set to <code>true</code>, this room will be added to a blocking list, preventing
  9424. future attempts to join the room. Defaults to <code>false</code>.</li>
  9425. <li><code>purge</code> - Optional. If set to <code>true</code>, it will remove all traces of the room from your database.
  9426. Defaults to <code>true</code>.</li>
  9427. <li><code>force_purge</code> - Optional, and ignored unless <code>purge</code> is <code>true</code>. If set to <code>true</code>, it
  9428. will force a purge to go ahead even if there are local users still in the room. Do not
  9429. use this unless a regular <code>purge</code> operation fails, as it could leave those users'
  9430. clients in a confused state.</li>
  9431. </ul>
  9432. <p>The JSON body must not be empty. The body must be at least <code>{}</code>.</p>
  9433. <p><strong>Response</strong></p>
  9434. <p>The following fields are returned in the JSON response body:</p>
  9435. <ul>
  9436. <li><code>kicked_users</code> - An array of users (<code>user_id</code>) that were kicked.</li>
  9437. <li><code>failed_to_kick_users</code> - An array of users (<code>user_id</code>) that that were not kicked.</li>
  9438. <li><code>local_aliases</code> - An array of strings representing the local aliases that were migrated from
  9439. the old room to the new.</li>
  9440. <li><code>new_room_id</code> - A string representing the room ID of the new room.</li>
  9441. </ul>
  9442. <h2 id="undoing-room-shutdowns"><a class="header" href="#undoing-room-shutdowns">Undoing room shutdowns</a></h2>
  9443. <p><em>Note</em>: This guide may be outdated by the time you read it. By nature of room shutdowns being performed at the database level,
  9444. the structure can and does change without notice.</p>
  9445. <p>First, it's important to understand that a room shutdown is very destructive. Undoing a shutdown is not as simple as pretending it
  9446. 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
  9447. to recover at all:</p>
  9448. <ul>
  9449. <li>If the room was invite-only, your users will need to be re-invited.</li>
  9450. <li>If the room no longer has any members at all, it'll be impossible to rejoin.</li>
  9451. <li>The first user to rejoin will have to do so via an alias on a different server.</li>
  9452. </ul>
  9453. <p>With all that being said, if you still want to try and recover the room:</p>
  9454. <ol>
  9455. <li>For safety reasons, shut down Synapse.</li>
  9456. <li>In the database, run <code>DELETE FROM blocked_rooms WHERE room_id = '!example:example.org';</code>
  9457. <ul>
  9458. <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>
  9459. <li>The room ID is the same one supplied to the shutdown room API, not the Content Violation room.</li>
  9460. </ul>
  9461. </li>
  9462. <li>Restart Synapse.</li>
  9463. </ol>
  9464. <p>You will have to manually handle, if you so choose, the following:</p>
  9465. <ul>
  9466. <li>Aliases that would have been redirected to the Content Violation room.</li>
  9467. <li>Users that would have been booted from the room (and will have been force-joined to the Content Violation room).</li>
  9468. <li>Removal of the Content Violation room if desired.</li>
  9469. </ul>
  9470. <h2 id="deprecated-endpoint"><a class="header" href="#deprecated-endpoint">Deprecated endpoint</a></h2>
  9471. <p>The previous deprecated API will be removed in a future release, it was:</p>
  9472. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id&gt;/delete
  9473. </code></pre>
  9474. <p>It behaves the same way than the current endpoint except the path and the method.</p>
  9475. <h1 id="make-room-admin-api"><a class="header" href="#make-room-admin-api">Make Room Admin API</a></h1>
  9476. <p>Grants another user the highest power available to a local user who is in the room.
  9477. If the user is not in the room, and it is not publicly joinable, then invite the user.</p>
  9478. <p>By default the server admin (the caller) is granted power, but another user can
  9479. optionally be specified, e.g.:</p>
  9480. <pre><code>POST /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/make_room_admin
  9481. {
  9482. &quot;user_id&quot;: &quot;@foo:example.com&quot;
  9483. }
  9484. </code></pre>
  9485. <h1 id="forward-extremities-admin-api"><a class="header" href="#forward-extremities-admin-api">Forward Extremities Admin API</a></h1>
  9486. <p>Enables querying and deleting forward extremities from rooms. When a lot of forward
  9487. extremities accumulate in a room, performance can become degraded. For details, see
  9488. <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.</p>
  9489. <h2 id="check-for-forward-extremities"><a class="header" href="#check-for-forward-extremities">Check for forward extremities</a></h2>
  9490. <p>To check the status of forward extremities for a room:</p>
  9491. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9492. </code></pre>
  9493. <p>A response as follows will be returned:</p>
  9494. <pre><code class="language-json">{
  9495. &quot;count&quot;: 1,
  9496. &quot;results&quot;: [
  9497. {
  9498. &quot;event_id&quot;: &quot;$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdefgh&quot;,
  9499. &quot;state_group&quot;: 439,
  9500. &quot;depth&quot;: 123,
  9501. &quot;received_ts&quot;: 1611263016761
  9502. }
  9503. ]
  9504. }
  9505. </code></pre>
  9506. <h2 id="deleting-forward-extremities"><a class="header" href="#deleting-forward-extremities">Deleting forward extremities</a></h2>
  9507. <p><strong>WARNING</strong>: Please ensure you know what you're doing and have read
  9508. the related issue <a href="https://github.com/matrix-org/synapse/issues/1760">#1760</a>.
  9509. Under no situations should this API be executed as an automated maintenance task!</p>
  9510. <p>If a room has lots of forward extremities, the extra can be
  9511. deleted as follows:</p>
  9512. <pre><code>DELETE /_synapse/admin/v1/rooms/&lt;room_id_or_alias&gt;/forward_extremities
  9513. </code></pre>
  9514. <p>A response as follows will be returned, indicating the amount of forward extremities
  9515. that were deleted.</p>
  9516. <pre><code class="language-json">{
  9517. &quot;deleted&quot;: 1
  9518. }
  9519. </code></pre>
  9520. <h1 id="event-context-api"><a class="header" href="#event-context-api">Event Context API</a></h1>
  9521. <p>This API lets a client find the context of an event. This is designed primarily to investigate abuse reports.</p>
  9522. <pre><code>GET /_synapse/admin/v1/rooms/&lt;room_id&gt;/context/&lt;event_id&gt;
  9523. </code></pre>
  9524. <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>
  9525. <p>Example response:</p>
  9526. <pre><code class="language-json">{
  9527. &quot;end&quot;: &quot;t29-57_2_0_2&quot;,
  9528. &quot;events_after&quot;: [
  9529. {
  9530. &quot;content&quot;: {
  9531. &quot;body&quot;: &quot;This is an example text message&quot;,
  9532. &quot;msgtype&quot;: &quot;m.text&quot;,
  9533. &quot;format&quot;: &quot;org.matrix.custom.html&quot;,
  9534. &quot;formatted_body&quot;: &quot;&lt;b&gt;This is an example text message&lt;/b&gt;&quot;
  9535. },
  9536. &quot;type&quot;: &quot;m.room.message&quot;,
  9537. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9538. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9539. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9540. &quot;origin_server_ts&quot;: 1432735824653,
  9541. &quot;unsigned&quot;: {
  9542. &quot;age&quot;: 1234
  9543. }
  9544. }
  9545. ],
  9546. &quot;event&quot;: {
  9547. &quot;content&quot;: {
  9548. &quot;body&quot;: &quot;filename.jpg&quot;,
  9549. &quot;info&quot;: {
  9550. &quot;h&quot;: 398,
  9551. &quot;w&quot;: 394,
  9552. &quot;mimetype&quot;: &quot;image/jpeg&quot;,
  9553. &quot;size&quot;: 31037
  9554. },
  9555. &quot;url&quot;: &quot;mxc://example.org/JWEIFJgwEIhweiWJE&quot;,
  9556. &quot;msgtype&quot;: &quot;m.image&quot;
  9557. },
  9558. &quot;type&quot;: &quot;m.room.message&quot;,
  9559. &quot;event_id&quot;: &quot;$f3h4d129462ha:example.com&quot;,
  9560. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9561. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9562. &quot;origin_server_ts&quot;: 1432735824653,
  9563. &quot;unsigned&quot;: {
  9564. &quot;age&quot;: 1234
  9565. }
  9566. },
  9567. &quot;events_before&quot;: [
  9568. {
  9569. &quot;content&quot;: {
  9570. &quot;body&quot;: &quot;something-important.doc&quot;,
  9571. &quot;filename&quot;: &quot;something-important.doc&quot;,
  9572. &quot;info&quot;: {
  9573. &quot;mimetype&quot;: &quot;application/msword&quot;,
  9574. &quot;size&quot;: 46144
  9575. },
  9576. &quot;msgtype&quot;: &quot;m.file&quot;,
  9577. &quot;url&quot;: &quot;mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe&quot;
  9578. },
  9579. &quot;type&quot;: &quot;m.room.message&quot;,
  9580. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9581. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9582. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9583. &quot;origin_server_ts&quot;: 1432735824653,
  9584. &quot;unsigned&quot;: {
  9585. &quot;age&quot;: 1234
  9586. }
  9587. }
  9588. ],
  9589. &quot;start&quot;: &quot;t27-54_2_0_2&quot;,
  9590. &quot;state&quot;: [
  9591. {
  9592. &quot;content&quot;: {
  9593. &quot;creator&quot;: &quot;@example:example.org&quot;,
  9594. &quot;room_version&quot;: &quot;1&quot;,
  9595. &quot;m.federate&quot;: true,
  9596. &quot;predecessor&quot;: {
  9597. &quot;event_id&quot;: &quot;$something:example.org&quot;,
  9598. &quot;room_id&quot;: &quot;!oldroom:example.org&quot;
  9599. }
  9600. },
  9601. &quot;type&quot;: &quot;m.room.create&quot;,
  9602. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9603. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9604. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9605. &quot;origin_server_ts&quot;: 1432735824653,
  9606. &quot;unsigned&quot;: {
  9607. &quot;age&quot;: 1234
  9608. },
  9609. &quot;state_key&quot;: &quot;&quot;
  9610. },
  9611. {
  9612. &quot;content&quot;: {
  9613. &quot;membership&quot;: &quot;join&quot;,
  9614. &quot;avatar_url&quot;: &quot;mxc://example.org/SEsfnsuifSDFSSEF&quot;,
  9615. &quot;displayname&quot;: &quot;Alice Margatroid&quot;
  9616. },
  9617. &quot;type&quot;: &quot;m.room.member&quot;,
  9618. &quot;event_id&quot;: &quot;$143273582443PhrSn:example.org&quot;,
  9619. &quot;room_id&quot;: &quot;!636q39766251:example.com&quot;,
  9620. &quot;sender&quot;: &quot;@example:example.org&quot;,
  9621. &quot;origin_server_ts&quot;: 1432735824653,
  9622. &quot;unsigned&quot;: {
  9623. &quot;age&quot;: 1234
  9624. },
  9625. &quot;state_key&quot;: &quot;@alice:example.org&quot;
  9626. }
  9627. ]
  9628. }
  9629. </code></pre>
  9630. <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>
  9631. <p>The API to send notices is as follows:</p>
  9632. <pre><code>POST /_synapse/admin/v1/send_server_notice
  9633. </code></pre>
  9634. <p>or:</p>
  9635. <pre><code>PUT /_synapse/admin/v1/send_server_notice/{txnId}
  9636. </code></pre>
  9637. <p>You will need to authenticate with an access token for an admin user.</p>
  9638. <p>When using the <code>PUT</code> form, retransmissions with the same transaction ID will be
  9639. ignored in the same way as with <code>PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}</code>.</p>
  9640. <p>The request body should look something like the following:</p>
  9641. <pre><code class="language-json">{
  9642. &quot;user_id&quot;: &quot;@target_user:server_name&quot;,
  9643. &quot;content&quot;: {
  9644. &quot;msgtype&quot;: &quot;m.text&quot;,
  9645. &quot;body&quot;: &quot;This is my message&quot;
  9646. }
  9647. }
  9648. </code></pre>
  9649. <p>You can optionally include the following additional parameters:</p>
  9650. <ul>
  9651. <li><code>type</code>: the type of event. Defaults to <code>m.room.message</code>.</li>
  9652. <li><code>state_key</code>: Setting this will result in a state event being sent.</li>
  9653. </ul>
  9654. <p>Once the notice has been sent, the API will return the following response:</p>
  9655. <pre><code class="language-json">{
  9656. &quot;event_id&quot;: &quot;&lt;event_id&gt;&quot;
  9657. }
  9658. </code></pre>
  9659. <p>Note that server notices must be enabled in <code>homeserver.yaml</code> before this API
  9660. can be used. See <a href="admin_api/../server_notices.html">the server notices documentation</a> for more information.</p>
  9661. <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>
  9662. <p>Returns information about all local media usage of users. Gives the
  9663. possibility to filter them by time and user.</p>
  9664. <p>The API is:</p>
  9665. <pre><code>GET /_synapse/admin/v1/statistics/users/media
  9666. </code></pre>
  9667. <p>To use it, you will need to authenticate by providing an <code>access_token</code>
  9668. for a server admin: see <a href="admin_api/../usage/administration/admin_api">Admin API</a>.</p>
  9669. <p>A response body like the following is returned:</p>
  9670. <pre><code class="language-json">{
  9671. &quot;users&quot;: [
  9672. {
  9673. &quot;displayname&quot;: &quot;foo_user_0&quot;,
  9674. &quot;media_count&quot;: 2,
  9675. &quot;media_length&quot;: 134,
  9676. &quot;user_id&quot;: &quot;@foo_user_0:test&quot;
  9677. },
  9678. {
  9679. &quot;displayname&quot;: &quot;foo_user_1&quot;,
  9680. &quot;media_count&quot;: 2,
  9681. &quot;media_length&quot;: 134,
  9682. &quot;user_id&quot;: &quot;@foo_user_1:test&quot;
  9683. }
  9684. ],
  9685. &quot;next_token&quot;: 3,
  9686. &quot;total&quot;: 10
  9687. }
  9688. </code></pre>
  9689. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint
  9690. again with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9691. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  9692. reports to paginate through.</p>
  9693. <p><strong>Parameters</strong></p>
  9694. <p>The following parameters should be set in the URL:</p>
  9695. <ul>
  9696. <li><code>limit</code>: string representing a positive integer - Is optional but is
  9697. used for pagination, denoting the maximum number of items to return
  9698. in this call. Defaults to <code>100</code>.</li>
  9699. <li><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  9700. denoting the offset in the returned results. This should be treated as an opaque value
  9701. and not explicitly set to anything other than the return value of <code>next_token</code> from a
  9702. previous call. Defaults to <code>0</code>.</li>
  9703. <li><code>order_by</code> - string - The method in which to sort the returned list of users. Valid values are:
  9704. <ul>
  9705. <li><code>user_id</code> - Users are ordered alphabetically by <code>user_id</code>. This is the default.</li>
  9706. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9707. <li><code>media_length</code> - Users are ordered by the total size of uploaded media in bytes.
  9708. Smallest to largest.</li>
  9709. <li><code>media_count</code> - Users are ordered by number of uploaded media. Smallest to largest.</li>
  9710. </ul>
  9711. </li>
  9712. <li><code>from_ts</code> - string representing a positive integer - Considers only
  9713. files created at this timestamp or later. Unix timestamp in ms.</li>
  9714. <li><code>until_ts</code> - string representing a positive integer - Considers only
  9715. files created at this timestamp or earlier. Unix timestamp in ms.</li>
  9716. <li><code>search_term</code> - string - Filter users by their user ID localpart <strong>or</strong> displayname.
  9717. The search term can be found in any part of the string.
  9718. Defaults to no filtering.</li>
  9719. <li><code>dir</code> - string - Direction of order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9720. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</li>
  9721. </ul>
  9722. <p><strong>Response</strong></p>
  9723. <p>The following fields are returned in the JSON response body:</p>
  9724. <ul>
  9725. <li><code>users</code> - An array of objects, each containing information
  9726. about the user and their local media. Objects contain the following fields:
  9727. <ul>
  9728. <li><code>displayname</code> - string - Displayname of this user.</li>
  9729. <li><code>media_count</code> - integer - Number of uploaded media by this user.</li>
  9730. <li><code>media_length</code> - integer - Size of uploaded media in bytes by this user.</li>
  9731. <li><code>user_id</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9732. </ul>
  9733. </li>
  9734. <li><code>next_token</code> - integer - Opaque value used for pagination. See above.</li>
  9735. <li><code>total</code> - integer - Total number of users after filtering.</li>
  9736. </ul>
  9737. <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>
  9738. <h2 id="query-user-account"><a class="header" href="#query-user-account">Query User Account</a></h2>
  9739. <p>This API returns information about a specific user account.</p>
  9740. <p>The api is:</p>
  9741. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;
  9742. </code></pre>
  9743. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9744. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9745. <p>It returns a JSON body like the following:</p>
  9746. <pre><code class="language-json">{
  9747. &quot;displayname&quot;: &quot;User&quot;,
  9748. &quot;threepids&quot;: [
  9749. {
  9750. &quot;medium&quot;: &quot;email&quot;,
  9751. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;,
  9752. &quot;added_at&quot;: 1586458409743,
  9753. &quot;validated_at&quot;: 1586458409743
  9754. },
  9755. {
  9756. &quot;medium&quot;: &quot;email&quot;,
  9757. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;,
  9758. &quot;added_at&quot;: 1586458409743,
  9759. &quot;validated_at&quot;: 1586458409743
  9760. }
  9761. ],
  9762. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9763. &quot;admin&quot;: 0,
  9764. &quot;deactivated&quot;: 0,
  9765. &quot;shadow_banned&quot;: 0,
  9766. &quot;password_hash&quot;: &quot;$2b$12$p9B4GkqYdRTPGD&quot;,
  9767. &quot;creation_ts&quot;: 1560432506,
  9768. &quot;appservice_id&quot;: null,
  9769. &quot;consent_server_notice_sent&quot;: null,
  9770. &quot;consent_version&quot;: null,
  9771. &quot;external_ids&quot;: [
  9772. {
  9773. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9774. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9775. },
  9776. {
  9777. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9778. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9779. }
  9780. ]
  9781. }
  9782. </code></pre>
  9783. <p>URL parameters:</p>
  9784. <ul>
  9785. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9786. </ul>
  9787. <h2 id="create-or-modify-account"><a class="header" href="#create-or-modify-account">Create or modify Account</a></h2>
  9788. <p>This API allows an administrator to create or modify a user account with a
  9789. specific <code>user_id</code>.</p>
  9790. <p>This api is:</p>
  9791. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;
  9792. </code></pre>
  9793. <p>with a body of:</p>
  9794. <pre><code class="language-json">{
  9795. &quot;password&quot;: &quot;user_password&quot;,
  9796. &quot;displayname&quot;: &quot;User&quot;,
  9797. &quot;threepids&quot;: [
  9798. {
  9799. &quot;medium&quot;: &quot;email&quot;,
  9800. &quot;address&quot;: &quot;&lt;user_mail_1&gt;&quot;
  9801. },
  9802. {
  9803. &quot;medium&quot;: &quot;email&quot;,
  9804. &quot;address&quot;: &quot;&lt;user_mail_2&gt;&quot;
  9805. }
  9806. ],
  9807. &quot;external_ids&quot;: [
  9808. {
  9809. &quot;auth_provider&quot;: &quot;&lt;provider1&gt;&quot;,
  9810. &quot;external_id&quot;: &quot;&lt;user_id_provider_1&gt;&quot;
  9811. },
  9812. {
  9813. &quot;auth_provider&quot;: &quot;&lt;provider2&gt;&quot;,
  9814. &quot;external_id&quot;: &quot;&lt;user_id_provider_2&gt;&quot;
  9815. }
  9816. ],
  9817. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9818. &quot;admin&quot;: false,
  9819. &quot;deactivated&quot;: false
  9820. }
  9821. </code></pre>
  9822. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9823. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9824. <p>Returns HTTP status code:</p>
  9825. <ul>
  9826. <li><code>201</code> - When a new user object was created.</li>
  9827. <li><code>200</code> - When a user was modified.</li>
  9828. </ul>
  9829. <p>URL parameters:</p>
  9830. <ul>
  9831. <li><code>user_id</code>: fully-qualified user id: for example, <code>@user:server.com</code>.</li>
  9832. </ul>
  9833. <p>Body parameters:</p>
  9834. <ul>
  9835. <li><code>password</code> - string, optional. If provided, the user's password is updated and all
  9836. devices are logged out.</li>
  9837. <li><code>displayname</code> - string, optional, defaults to the value of <code>user_id</code>.</li>
  9838. <li><code>threepids</code> - array, optional, allows setting the third-party IDs (email, msisdn)
  9839. <ul>
  9840. <li><code>medium</code> - string. Kind of third-party ID, either <code>email</code> or <code>msisdn</code>.</li>
  9841. <li><code>address</code> - string. Value of third-party ID.
  9842. belonging to a user.</li>
  9843. </ul>
  9844. </li>
  9845. <li><code>external_ids</code> - array, optional. Allow setting the identifier of the external identity
  9846. provider for SSO (Single sign-on). Details in
  9847. <a href="admin_api/../usage/configuration/homeserver_sample_config.html">Sample Configuration File</a>
  9848. section <code>sso</code> and <code>oidc_providers</code>.
  9849. <ul>
  9850. <li><code>auth_provider</code> - string. ID of the external identity provider. Value of <code>idp_id</code>
  9851. in homeserver configuration.</li>
  9852. <li><code>external_id</code> - string, user ID in the external identity provider.</li>
  9853. </ul>
  9854. </li>
  9855. <li><code>avatar_url</code> - string, optional, must be a
  9856. <a href="https://matrix.org/docs/spec/client_server/r0.6.0#matrix-content-mxc-uris">MXC URI</a>.</li>
  9857. <li><code>admin</code> - bool, optional, defaults to <code>false</code>.</li>
  9858. <li><code>deactivated</code> - bool, optional. If unspecified, deactivation state will be left
  9859. unchanged on existing accounts and set to <code>false</code> for new accounts.
  9860. A user cannot be erased by deactivating with this API. For details on
  9861. deactivating users see <a href="admin_api/user_admin_api.html#deactivate-account">Deactivate Account</a>.</li>
  9862. </ul>
  9863. <p>If the user already exists then optional parameters default to the current value.</p>
  9864. <p>In order to re-activate an account <code>deactivated</code> must be set to <code>false</code>. If
  9865. users do not login via single-sign-on, a new <code>password</code> must be provided.</p>
  9866. <h2 id="list-accounts"><a class="header" href="#list-accounts">List Accounts</a></h2>
  9867. <p>This API returns all local user accounts.
  9868. By default, the response is ordered by ascending user ID.</p>
  9869. <pre><code>GET /_synapse/admin/v2/users?from=0&amp;limit=10&amp;guests=false
  9870. </code></pre>
  9871. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9872. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9873. <p>A response body like the following is returned:</p>
  9874. <pre><code class="language-json">{
  9875. &quot;users&quot;: [
  9876. {
  9877. &quot;name&quot;: &quot;&lt;user_id1&gt;&quot;,
  9878. &quot;is_guest&quot;: 0,
  9879. &quot;admin&quot;: 0,
  9880. &quot;user_type&quot;: null,
  9881. &quot;deactivated&quot;: 0,
  9882. &quot;shadow_banned&quot;: 0,
  9883. &quot;displayname&quot;: &quot;&lt;User One&gt;&quot;,
  9884. &quot;avatar_url&quot;: null,
  9885. &quot;creation_ts&quot;: 1560432668000
  9886. }, {
  9887. &quot;name&quot;: &quot;&lt;user_id2&gt;&quot;,
  9888. &quot;is_guest&quot;: 0,
  9889. &quot;admin&quot;: 1,
  9890. &quot;user_type&quot;: null,
  9891. &quot;deactivated&quot;: 0,
  9892. &quot;shadow_banned&quot;: 0,
  9893. &quot;displayname&quot;: &quot;&lt;User Two&gt;&quot;,
  9894. &quot;avatar_url&quot;: &quot;&lt;avatar_url&gt;&quot;,
  9895. &quot;creation_ts&quot;: 1561550621000
  9896. }
  9897. ],
  9898. &quot;next_token&quot;: &quot;100&quot;,
  9899. &quot;total&quot;: 200
  9900. }
  9901. </code></pre>
  9902. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  9903. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  9904. <p>If the endpoint does not return a <code>next_token</code> then there are no more users
  9905. to paginate through.</p>
  9906. <p><strong>Parameters</strong></p>
  9907. <p>The following parameters should be set in the URL:</p>
  9908. <ul>
  9909. <li>
  9910. <p><code>user_id</code> - Is optional and filters to only return users with user IDs
  9911. that contain this value. This parameter is ignored when using the <code>name</code> parameter.</p>
  9912. </li>
  9913. <li>
  9914. <p><code>name</code> - Is optional and filters to only return users with user ID localparts
  9915. <strong>or</strong> displaynames that contain this value.</p>
  9916. </li>
  9917. <li>
  9918. <p><code>guests</code> - string representing a bool - Is optional and if <code>false</code> will <strong>exclude</strong> guest users.
  9919. Defaults to <code>true</code> to include guest users.</p>
  9920. </li>
  9921. <li>
  9922. <p><code>deactivated</code> - string representing a bool - Is optional and if <code>true</code> will <strong>include</strong> deactivated users.
  9923. Defaults to <code>false</code> to exclude deactivated users.</p>
  9924. </li>
  9925. <li>
  9926. <p><code>limit</code> - string representing a positive integer - Is optional but is used for pagination,
  9927. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  9928. </li>
  9929. <li>
  9930. <p><code>from</code> - string representing a positive integer - Is optional but used for pagination,
  9931. denoting the offset in the returned results. This should be treated as an opaque value and
  9932. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  9933. Defaults to <code>0</code>.</p>
  9934. </li>
  9935. <li>
  9936. <p><code>order_by</code> - The method by which to sort the returned list of users.
  9937. If the ordered field has duplicates, the second order is always by ascending <code>name</code>,
  9938. which guarantees a stable ordering. Valid values are:</p>
  9939. <ul>
  9940. <li><code>name</code> - Users are ordered alphabetically by <code>name</code>. This is the default.</li>
  9941. <li><code>is_guest</code> - Users are ordered by <code>is_guest</code> status.</li>
  9942. <li><code>admin</code> - Users are ordered by <code>admin</code> status.</li>
  9943. <li><code>user_type</code> - Users are ordered alphabetically by <code>user_type</code>.</li>
  9944. <li><code>deactivated</code> - Users are ordered by <code>deactivated</code> status.</li>
  9945. <li><code>shadow_banned</code> - Users are ordered by <code>shadow_banned</code> status.</li>
  9946. <li><code>displayname</code> - Users are ordered alphabetically by <code>displayname</code>.</li>
  9947. <li><code>avatar_url</code> - Users are ordered alphabetically by avatar URL.</li>
  9948. <li><code>creation_ts</code> - Users are ordered by when the users was created in ms.</li>
  9949. </ul>
  9950. </li>
  9951. <li>
  9952. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  9953. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  9954. </li>
  9955. </ul>
  9956. <p>Caution. The database only has indexes on the columns <code>name</code> and <code>creation_ts</code>.
  9957. This means that if a different sort order is used (<code>is_guest</code>, <code>admin</code>,
  9958. <code>user_type</code>, <code>deactivated</code>, <code>shadow_banned</code>, <code>avatar_url</code> or <code>displayname</code>),
  9959. this can cause a large load on the database, especially for large environments.</p>
  9960. <p><strong>Response</strong></p>
  9961. <p>The following fields are returned in the JSON response body:</p>
  9962. <ul>
  9963. <li>
  9964. <p><code>users</code> - An array of objects, each containing information about an user.
  9965. User objects contain the following fields:</p>
  9966. <ul>
  9967. <li><code>name</code> - string - Fully-qualified user ID (ex. <code>@user:server.com</code>).</li>
  9968. <li><code>is_guest</code> - bool - Status if that user is a guest account.</li>
  9969. <li><code>admin</code> - bool - Status if that user is a server administrator.</li>
  9970. <li><code>user_type</code> - string - Type of the user. Normal users are type <code>None</code>.
  9971. This allows user type specific behaviour. There are also types <code>support</code> and <code>bot</code>. </li>
  9972. <li><code>deactivated</code> - bool - Status if that user has been marked as deactivated.</li>
  9973. <li><code>shadow_banned</code> - bool - Status if that user has been marked as shadow banned.</li>
  9974. <li><code>displayname</code> - string - The user's display name if they have set one.</li>
  9975. <li><code>avatar_url</code> - string - The user's avatar URL if they have set one.</li>
  9976. <li><code>creation_ts</code> - integer - The user's creation timestamp in ms.</li>
  9977. </ul>
  9978. </li>
  9979. <li>
  9980. <p><code>next_token</code>: string representing a positive integer - Indication for pagination. See above.</p>
  9981. </li>
  9982. <li>
  9983. <p><code>total</code> - integer - Total number of media.</p>
  9984. </li>
  9985. </ul>
  9986. <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>
  9987. <p>This API returns information about the active sessions for a specific user.</p>
  9988. <p>The endpoints are:</p>
  9989. <pre><code>GET /_synapse/admin/v1/whois/&lt;user_id&gt;
  9990. </code></pre>
  9991. <p>and:</p>
  9992. <pre><code>GET /_matrix/client/r0/admin/whois/&lt;userId&gt;
  9993. </code></pre>
  9994. <p>See also: <a href="https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid">Client Server
  9995. API Whois</a>.</p>
  9996. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  9997. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  9998. <p>It returns a JSON body like the following:</p>
  9999. <pre><code class="language-json">{
  10000. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;,
  10001. &quot;devices&quot;: {
  10002. &quot;&quot;: {
  10003. &quot;sessions&quot;: [
  10004. {
  10005. &quot;connections&quot;: [
  10006. {
  10007. &quot;ip&quot;: &quot;1.2.3.4&quot;,
  10008. &quot;last_seen&quot;: 1417222374433,
  10009. &quot;user_agent&quot;: &quot;Mozilla/5.0 ...&quot;
  10010. },
  10011. {
  10012. &quot;ip&quot;: &quot;1.2.3.10&quot;,
  10013. &quot;last_seen&quot;: 1417222374500,
  10014. &quot;user_agent&quot;: &quot;Dalvik/2.1.0 ...&quot;
  10015. }
  10016. ]
  10017. }
  10018. ]
  10019. }
  10020. }
  10021. }
  10022. </code></pre>
  10023. <p><code>last_seen</code> is measured in milliseconds since the Unix epoch.</p>
  10024. <h2 id="deactivate-account"><a class="header" href="#deactivate-account">Deactivate Account</a></h2>
  10025. <p>This API deactivates an account. It removes active access tokens, resets the
  10026. password, and deletes third-party IDs (to prevent the user requesting a
  10027. password reset).</p>
  10028. <p>It can also mark the user as GDPR-erased. This means messages sent by the
  10029. user will still be visible by anyone that was in the room when these messages
  10030. were sent, but hidden from users joining the room afterwards.</p>
  10031. <p>The api is:</p>
  10032. <pre><code>POST /_synapse/admin/v1/deactivate/&lt;user_id&gt;
  10033. </code></pre>
  10034. <p>with a body of:</p>
  10035. <pre><code class="language-json">{
  10036. &quot;erase&quot;: true
  10037. }
  10038. </code></pre>
  10039. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10040. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10041. <p>The erase parameter is optional and defaults to <code>false</code>.
  10042. An empty body may be passed for backwards compatibility.</p>
  10043. <p>The following actions are performed when deactivating an user:</p>
  10044. <ul>
  10045. <li>Try to unpind 3PIDs from the identity server</li>
  10046. <li>Remove all 3PIDs from the homeserver</li>
  10047. <li>Delete all devices and E2EE keys</li>
  10048. <li>Delete all access tokens</li>
  10049. <li>Delete the password hash</li>
  10050. <li>Removal from all rooms the user is a member of</li>
  10051. <li>Remove the user from the user directory</li>
  10052. <li>Reject all pending invites</li>
  10053. <li>Remove all account validity information related to the user</li>
  10054. </ul>
  10055. <p>The following additional actions are performed during deactivation if <code>erase</code>
  10056. is set to <code>true</code>:</p>
  10057. <ul>
  10058. <li>Remove the user's display name</li>
  10059. <li>Remove the user's avatar URL</li>
  10060. <li>Mark the user as erased</li>
  10061. </ul>
  10062. <h2 id="reset-password"><a class="header" href="#reset-password">Reset password</a></h2>
  10063. <p>Changes the password of another user. This will automatically log the user out of all their devices.</p>
  10064. <p>The api is:</p>
  10065. <pre><code>POST /_synapse/admin/v1/reset_password/&lt;user_id&gt;
  10066. </code></pre>
  10067. <p>with a body of:</p>
  10068. <pre><code class="language-json">{
  10069. &quot;new_password&quot;: &quot;&lt;secret&gt;&quot;,
  10070. &quot;logout_devices&quot;: true
  10071. }
  10072. </code></pre>
  10073. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10074. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10075. <p>The parameter <code>new_password</code> is required.
  10076. The parameter <code>logout_devices</code> is optional and defaults to <code>true</code>.</p>
  10077. <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>
  10078. <p>The api is:</p>
  10079. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  10080. </code></pre>
  10081. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10082. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10083. <p>A response body like the following is returned:</p>
  10084. <pre><code class="language-json">{
  10085. &quot;admin&quot;: true
  10086. }
  10087. </code></pre>
  10088. <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>
  10089. <p>Note that you cannot demote yourself.</p>
  10090. <p>The api is:</p>
  10091. <pre><code>PUT /_synapse/admin/v1/users/&lt;user_id&gt;/admin
  10092. </code></pre>
  10093. <p>with a body of:</p>
  10094. <pre><code class="language-json">{
  10095. &quot;admin&quot;: true
  10096. }
  10097. </code></pre>
  10098. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10099. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10100. <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>
  10101. <p>Gets a list of all <code>room_id</code> that a specific <code>user_id</code> is member.</p>
  10102. <p>The API is:</p>
  10103. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/joined_rooms
  10104. </code></pre>
  10105. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10106. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10107. <p>A response body like the following is returned:</p>
  10108. <pre><code class="language-json"> {
  10109. &quot;joined_rooms&quot;: [
  10110. &quot;!DuGcnbhHGaSZQoNQR:matrix.org&quot;,
  10111. &quot;!ZtSaPCawyWtxfWiIy:matrix.org&quot;
  10112. ],
  10113. &quot;total&quot;: 2
  10114. }
  10115. </code></pre>
  10116. <p>The server returns the list of rooms of which the user and the server
  10117. are member. If the user is local, all the rooms of which the user is
  10118. member are returned.</p>
  10119. <p><strong>Parameters</strong></p>
  10120. <p>The following parameters should be set in the URL:</p>
  10121. <ul>
  10122. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10123. </ul>
  10124. <p><strong>Response</strong></p>
  10125. <p>The following fields are returned in the JSON response body:</p>
  10126. <ul>
  10127. <li><code>joined_rooms</code> - An array of <code>room_id</code>.</li>
  10128. <li><code>total</code> - Number of rooms.</li>
  10129. </ul>
  10130. <h2 id="user-media"><a class="header" href="#user-media">User media</a></h2>
  10131. <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>
  10132. <p>Gets a list of all local media that a specific <code>user_id</code> has created.
  10133. By default, the response is ordered by descending creation date and ascending media ID.
  10134. The newest media is on top. You can change the order with parameters
  10135. <code>order_by</code> and <code>dir</code>.</p>
  10136. <p>The API is:</p>
  10137. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/media
  10138. </code></pre>
  10139. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10140. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10141. <p>A response body like the following is returned:</p>
  10142. <pre><code class="language-json">{
  10143. &quot;media&quot;: [
  10144. {
  10145. &quot;created_ts&quot;: 100400,
  10146. &quot;last_access_ts&quot;: null,
  10147. &quot;media_id&quot;: &quot;qXhyRzulkwLsNHTbpHreuEgo&quot;,
  10148. &quot;media_length&quot;: 67,
  10149. &quot;media_type&quot;: &quot;image/png&quot;,
  10150. &quot;quarantined_by&quot;: null,
  10151. &quot;safe_from_quarantine&quot;: false,
  10152. &quot;upload_name&quot;: &quot;test1.png&quot;
  10153. },
  10154. {
  10155. &quot;created_ts&quot;: 200400,
  10156. &quot;last_access_ts&quot;: null,
  10157. &quot;media_id&quot;: &quot;FHfiSnzoINDatrXHQIXBtahw&quot;,
  10158. &quot;media_length&quot;: 67,
  10159. &quot;media_type&quot;: &quot;image/png&quot;,
  10160. &quot;quarantined_by&quot;: null,
  10161. &quot;safe_from_quarantine&quot;: false,
  10162. &quot;upload_name&quot;: &quot;test2.png&quot;
  10163. }
  10164. ],
  10165. &quot;next_token&quot;: 3,
  10166. &quot;total&quot;: 2
  10167. }
  10168. </code></pre>
  10169. <p>To paginate, check for <code>next_token</code> and if present, call the endpoint again
  10170. with <code>from</code> set to the value of <code>next_token</code>. This will return a new page.</p>
  10171. <p>If the endpoint does not return a <code>next_token</code> then there are no more
  10172. reports to paginate through.</p>
  10173. <p><strong>Parameters</strong></p>
  10174. <p>The following parameters should be set in the URL:</p>
  10175. <ul>
  10176. <li>
  10177. <p><code>user_id</code> - string - fully qualified: for example, <code>@user:server.com</code>.</p>
  10178. </li>
  10179. <li>
  10180. <p><code>limit</code>: string representing a positive integer - Is optional but is used for pagination,
  10181. denoting the maximum number of items to return in this call. Defaults to <code>100</code>.</p>
  10182. </li>
  10183. <li>
  10184. <p><code>from</code>: string representing a positive integer - Is optional but used for pagination,
  10185. denoting the offset in the returned results. This should be treated as an opaque value and
  10186. not explicitly set to anything other than the return value of <code>next_token</code> from a previous call.
  10187. Defaults to <code>0</code>.</p>
  10188. </li>
  10189. <li>
  10190. <p><code>order_by</code> - The method by which to sort the returned list of media.
  10191. If the ordered field has duplicates, the second order is always by ascending <code>media_id</code>,
  10192. which guarantees a stable ordering. Valid values are:</p>
  10193. <ul>
  10194. <li><code>media_id</code> - Media are ordered alphabetically by <code>media_id</code>.</li>
  10195. <li><code>upload_name</code> - Media are ordered alphabetically by name the media was uploaded with.</li>
  10196. <li><code>created_ts</code> - Media are ordered by when the content was uploaded in ms.
  10197. Smallest to largest. This is the default.</li>
  10198. <li><code>last_access_ts</code> - Media are ordered by when the content was last accessed in ms.
  10199. Smallest to largest.</li>
  10200. <li><code>media_length</code> - Media are ordered by length of the media in bytes.
  10201. Smallest to largest.</li>
  10202. <li><code>media_type</code> - Media are ordered alphabetically by MIME-type.</li>
  10203. <li><code>quarantined_by</code> - Media are ordered alphabetically by the user ID that
  10204. initiated the quarantine request for this media.</li>
  10205. <li><code>safe_from_quarantine</code> - Media are ordered by the status if this media is safe
  10206. from quarantining.</li>
  10207. </ul>
  10208. </li>
  10209. <li>
  10210. <p><code>dir</code> - Direction of media order. Either <code>f</code> for forwards or <code>b</code> for backwards.
  10211. Setting this value to <code>b</code> will reverse the above sort order. Defaults to <code>f</code>.</p>
  10212. </li>
  10213. </ul>
  10214. <p>If neither <code>order_by</code> nor <code>dir</code> is set, the default order is newest media on top
  10215. (corresponds to <code>order_by</code> = <code>created_ts</code> and <code>dir</code> = <code>b</code>).</p>
  10216. <p>Caution. The database only has indexes on the columns <code>media_id</code>,
  10217. <code>user_id</code> and <code>created_ts</code>. This means that if a different sort order is used
  10218. (<code>upload_name</code>, <code>last_access_ts</code>, <code>media_length</code>, <code>media_type</code>,
  10219. <code>quarantined_by</code> or <code>safe_from_quarantine</code>), this can cause a large load on the
  10220. database, especially for large environments.</p>
  10221. <p><strong>Response</strong></p>
  10222. <p>The following fields are returned in the JSON response body:</p>
  10223. <ul>
  10224. <li><code>media</code> - An array of objects, each containing information about a media.
  10225. Media objects contain the following fields:
  10226. <ul>
  10227. <li><code>created_ts</code> - integer - Timestamp when the content was uploaded in ms.</li>
  10228. <li><code>last_access_ts</code> - integer - Timestamp when the content was last accessed in ms.</li>
  10229. <li><code>media_id</code> - string - The id used to refer to the media.</li>
  10230. <li><code>media_length</code> - integer - Length of the media in bytes.</li>
  10231. <li><code>media_type</code> - string - The MIME-type of the media.</li>
  10232. <li><code>quarantined_by</code> - string - The user ID that initiated the quarantine request
  10233. for this media.</li>
  10234. <li><code>safe_from_quarantine</code> - bool - Status if this media is safe from quarantining.</li>
  10235. <li><code>upload_name</code> - string - The name the media was uploaded with.</li>
  10236. </ul>
  10237. </li>
  10238. <li><code>next_token</code>: integer - Indication for pagination. See above.</li>
  10239. <li><code>total</code> - integer - Total number of media.</li>
  10240. </ul>
  10241. <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>
  10242. <p>This API deletes the <em>local</em> media from the disk of your own server
  10243. that a specific <code>user_id</code> has created. This includes any local thumbnails.</p>
  10244. <p>This API will not affect media that has been uploaded to external
  10245. media repositories (e.g https://github.com/turt2live/matrix-media-repo/).</p>
  10246. <p>By default, the API deletes media ordered by descending creation date and ascending media ID.
  10247. The newest media is deleted first. You can change the order with parameters
  10248. <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>
  10249. <p>The API is:</p>
  10250. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/media
  10251. </code></pre>
  10252. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10253. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10254. <p>A response body like the following is returned:</p>
  10255. <pre><code class="language-json">{
  10256. &quot;deleted_media&quot;: [
  10257. &quot;abcdefghijklmnopqrstuvwx&quot;
  10258. ],
  10259. &quot;total&quot;: 1
  10260. }
  10261. </code></pre>
  10262. <p>The following fields are returned in the JSON response body:</p>
  10263. <ul>
  10264. <li><code>deleted_media</code>: an array of strings - List of deleted <code>media_id</code></li>
  10265. <li><code>total</code>: integer - Total number of deleted <code>media_id</code></li>
  10266. </ul>
  10267. <p><strong>Note</strong>: There is no <code>next_token</code>. This is not useful for deleting media, because
  10268. after deleting media the remaining media have a new order.</p>
  10269. <p><strong>Parameters</strong></p>
  10270. <p>This API has the same parameters as
  10271. <a href="admin_api/user_admin_api.html#list-media-uploaded-by-a-user">List media uploaded by a user</a>.
  10272. With the parameters you can for example limit the number of files to delete at once or
  10273. delete largest/smallest or newest/oldest files first.</p>
  10274. <h2 id="login-as-a-user"><a class="header" href="#login-as-a-user">Login as a user</a></h2>
  10275. <p>Get an access token that can be used to authenticate as that user. Useful for
  10276. when admins wish to do actions on behalf of a user.</p>
  10277. <p>The API is:</p>
  10278. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/login
  10279. {}
  10280. </code></pre>
  10281. <p>An optional <code>valid_until_ms</code> field can be specified in the request body as an
  10282. integer timestamp that specifies when the token should expire. By default tokens
  10283. do not expire.</p>
  10284. <p>A response body like the following is returned:</p>
  10285. <pre><code class="language-json">{
  10286. &quot;access_token&quot;: &quot;&lt;opaque_access_token_string&gt;&quot;
  10287. }
  10288. </code></pre>
  10289. <p>This API does <em>not</em> generate a new device for the user, and so will not appear
  10290. their <code>/devices</code> list, and in general the target user should not be able to
  10291. tell they have been logged in as.</p>
  10292. <p>To expire the token call the standard <code>/logout</code> API with the token.</p>
  10293. <p>Note: The token will expire if the <em>admin</em> user calls <code>/logout/all</code> from any
  10294. of their devices, but the token will <em>not</em> expire if the target user does the
  10295. same.</p>
  10296. <h2 id="user-devices"><a class="header" href="#user-devices">User devices</a></h2>
  10297. <h3 id="list-all-devices"><a class="header" href="#list-all-devices">List all devices</a></h3>
  10298. <p>Gets information about all devices for a specific <code>user_id</code>.</p>
  10299. <p>The API is:</p>
  10300. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices
  10301. </code></pre>
  10302. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10303. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10304. <p>A response body like the following is returned:</p>
  10305. <pre><code class="language-json">{
  10306. &quot;devices&quot;: [
  10307. {
  10308. &quot;device_id&quot;: &quot;QBUAZIFURK&quot;,
  10309. &quot;display_name&quot;: &quot;android&quot;,
  10310. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10311. &quot;last_seen_ts&quot;: 1474491775024,
  10312. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10313. },
  10314. {
  10315. &quot;device_id&quot;: &quot;AUIECTSRND&quot;,
  10316. &quot;display_name&quot;: &quot;ios&quot;,
  10317. &quot;last_seen_ip&quot;: &quot;1.2.3.5&quot;,
  10318. &quot;last_seen_ts&quot;: 1474491775025,
  10319. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10320. }
  10321. ],
  10322. &quot;total&quot;: 2
  10323. }
  10324. </code></pre>
  10325. <p><strong>Parameters</strong></p>
  10326. <p>The following parameters should be set in the URL:</p>
  10327. <ul>
  10328. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10329. </ul>
  10330. <p><strong>Response</strong></p>
  10331. <p>The following fields are returned in the JSON response body:</p>
  10332. <ul>
  10333. <li>
  10334. <p><code>devices</code> - An array of objects, each containing information about a device.
  10335. Device objects contain the following fields:</p>
  10336. <ul>
  10337. <li><code>device_id</code> - Identifier of device.</li>
  10338. <li><code>display_name</code> - Display name set by the user for this device.
  10339. Absent if no name has been set.</li>
  10340. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10341. (May be a few minutes out of date, for efficiency reasons).</li>
  10342. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10343. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10344. <li><code>user_id</code> - Owner of device.</li>
  10345. </ul>
  10346. </li>
  10347. <li>
  10348. <p><code>total</code> - Total number of user's devices.</p>
  10349. </li>
  10350. </ul>
  10351. <h3 id="delete-multiple-devices"><a class="header" href="#delete-multiple-devices">Delete multiple devices</a></h3>
  10352. <p>Deletes the given devices for a specific <code>user_id</code>, and invalidates
  10353. any access token associated with them.</p>
  10354. <p>The API is:</p>
  10355. <pre><code>POST /_synapse/admin/v2/users/&lt;user_id&gt;/delete_devices
  10356. {
  10357. &quot;devices&quot;: [
  10358. &quot;QBUAZIFURK&quot;,
  10359. &quot;AUIECTSRND&quot;
  10360. ],
  10361. }
  10362. </code></pre>
  10363. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10364. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10365. <p>An empty JSON dict is returned.</p>
  10366. <p><strong>Parameters</strong></p>
  10367. <p>The following parameters should be set in the URL:</p>
  10368. <ul>
  10369. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10370. </ul>
  10371. <p>The following fields are required in the JSON request body:</p>
  10372. <ul>
  10373. <li><code>devices</code> - The list of device IDs to delete.</li>
  10374. </ul>
  10375. <h3 id="show-a-device"><a class="header" href="#show-a-device">Show a device</a></h3>
  10376. <p>Gets information on a single device, by <code>device_id</code> for a specific <code>user_id</code>.</p>
  10377. <p>The API is:</p>
  10378. <pre><code>GET /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10379. </code></pre>
  10380. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10381. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10382. <p>A response body like the following is returned:</p>
  10383. <pre><code class="language-json">{
  10384. &quot;device_id&quot;: &quot;&lt;device_id&gt;&quot;,
  10385. &quot;display_name&quot;: &quot;android&quot;,
  10386. &quot;last_seen_ip&quot;: &quot;1.2.3.4&quot;,
  10387. &quot;last_seen_ts&quot;: 1474491775024,
  10388. &quot;user_id&quot;: &quot;&lt;user_id&gt;&quot;
  10389. }
  10390. </code></pre>
  10391. <p><strong>Parameters</strong></p>
  10392. <p>The following parameters should be set in the URL:</p>
  10393. <ul>
  10394. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10395. <li><code>device_id</code> - The device to retrieve.</li>
  10396. </ul>
  10397. <p><strong>Response</strong></p>
  10398. <p>The following fields are returned in the JSON response body:</p>
  10399. <ul>
  10400. <li><code>device_id</code> - Identifier of device.</li>
  10401. <li><code>display_name</code> - Display name set by the user for this device.
  10402. Absent if no name has been set.</li>
  10403. <li><code>last_seen_ip</code> - The IP address where this device was last seen.
  10404. (May be a few minutes out of date, for efficiency reasons).</li>
  10405. <li><code>last_seen_ts</code> - The timestamp (in milliseconds since the unix epoch) when this
  10406. devices was last seen. (May be a few minutes out of date, for efficiency reasons).</li>
  10407. <li><code>user_id</code> - Owner of device.</li>
  10408. </ul>
  10409. <h3 id="update-a-device"><a class="header" href="#update-a-device">Update a device</a></h3>
  10410. <p>Updates the metadata on the given <code>device_id</code> for a specific <code>user_id</code>.</p>
  10411. <p>The API is:</p>
  10412. <pre><code>PUT /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10413. {
  10414. &quot;display_name&quot;: &quot;My other phone&quot;
  10415. }
  10416. </code></pre>
  10417. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10418. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10419. <p>An empty JSON dict is returned.</p>
  10420. <p><strong>Parameters</strong></p>
  10421. <p>The following parameters should be set in the URL:</p>
  10422. <ul>
  10423. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10424. <li><code>device_id</code> - The device to update.</li>
  10425. </ul>
  10426. <p>The following fields are required in the JSON request body:</p>
  10427. <ul>
  10428. <li><code>display_name</code> - The new display name for this device. If not given,
  10429. the display name is unchanged.</li>
  10430. </ul>
  10431. <h3 id="delete-a-device"><a class="header" href="#delete-a-device">Delete a device</a></h3>
  10432. <p>Deletes the given <code>device_id</code> for a specific <code>user_id</code>,
  10433. and invalidates any access token associated with it.</p>
  10434. <p>The API is:</p>
  10435. <pre><code>DELETE /_synapse/admin/v2/users/&lt;user_id&gt;/devices/&lt;device_id&gt;
  10436. {}
  10437. </code></pre>
  10438. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10439. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10440. <p>An empty JSON dict is returned.</p>
  10441. <p><strong>Parameters</strong></p>
  10442. <p>The following parameters should be set in the URL:</p>
  10443. <ul>
  10444. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10445. <li><code>device_id</code> - The device to delete.</li>
  10446. </ul>
  10447. <h2 id="list-all-pushers"><a class="header" href="#list-all-pushers">List all pushers</a></h2>
  10448. <p>Gets information about all pushers for a specific <code>user_id</code>.</p>
  10449. <p>The API is:</p>
  10450. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/pushers
  10451. </code></pre>
  10452. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10453. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10454. <p>A response body like the following is returned:</p>
  10455. <pre><code class="language-json">{
  10456. &quot;pushers&quot;: [
  10457. {
  10458. &quot;app_display_name&quot;:&quot;HTTP Push Notifications&quot;,
  10459. &quot;app_id&quot;:&quot;m.http&quot;,
  10460. &quot;data&quot;: {
  10461. &quot;url&quot;:&quot;example.com&quot;
  10462. },
  10463. &quot;device_display_name&quot;:&quot;pushy push&quot;,
  10464. &quot;kind&quot;:&quot;http&quot;,
  10465. &quot;lang&quot;:&quot;None&quot;,
  10466. &quot;profile_tag&quot;:&quot;&quot;,
  10467. &quot;pushkey&quot;:&quot;a@example.com&quot;
  10468. }
  10469. ],
  10470. &quot;total&quot;: 1
  10471. }
  10472. </code></pre>
  10473. <p><strong>Parameters</strong></p>
  10474. <p>The following parameters should be set in the URL:</p>
  10475. <ul>
  10476. <li><code>user_id</code> - fully qualified: for example, <code>@user:server.com</code>.</li>
  10477. </ul>
  10478. <p><strong>Response</strong></p>
  10479. <p>The following fields are returned in the JSON response body:</p>
  10480. <ul>
  10481. <li>
  10482. <p><code>pushers</code> - An array containing the current pushers for the user</p>
  10483. <ul>
  10484. <li>
  10485. <p><code>app_display_name</code> - string - A string that will allow the user to identify
  10486. what application owns this pusher.</p>
  10487. </li>
  10488. <li>
  10489. <p><code>app_id</code> - string - This is a reverse-DNS style identifier for the application.
  10490. Max length, 64 chars.</p>
  10491. </li>
  10492. <li>
  10493. <p><code>data</code> - A dictionary of information for the pusher implementation itself.</p>
  10494. <ul>
  10495. <li>
  10496. <p><code>url</code> - string - Required if <code>kind</code> is <code>http</code>. The URL to use to send
  10497. notifications to.</p>
  10498. </li>
  10499. <li>
  10500. <p><code>format</code> - string - The format to use when sending notifications to the
  10501. Push Gateway.</p>
  10502. </li>
  10503. </ul>
  10504. </li>
  10505. <li>
  10506. <p><code>device_display_name</code> - string - A string that will allow the user to identify
  10507. what device owns this pusher.</p>
  10508. </li>
  10509. <li>
  10510. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10511. this pusher executes.</p>
  10512. </li>
  10513. <li>
  10514. <p><code>kind</code> - string - The kind of pusher. &quot;http&quot; is a pusher that sends HTTP pokes.</p>
  10515. </li>
  10516. <li>
  10517. <p><code>lang</code> - string - The preferred language for receiving notifications
  10518. (e.g. 'en' or 'en-US')</p>
  10519. </li>
  10520. <li>
  10521. <p><code>profile_tag</code> - string - This string determines which set of device specific rules
  10522. this pusher executes.</p>
  10523. </li>
  10524. <li>
  10525. <p><code>pushkey</code> - string - This is a unique identifier for this pusher.
  10526. Max length, 512 bytes.</p>
  10527. </li>
  10528. </ul>
  10529. </li>
  10530. <li>
  10531. <p><code>total</code> - integer - Number of pushers.</p>
  10532. </li>
  10533. </ul>
  10534. <p>See also the
  10535. <a href="https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers">Client-Server API Spec on pushers</a>.</p>
  10536. <h2 id="shadow-banning-users"><a class="header" href="#shadow-banning-users">Shadow-banning users</a></h2>
  10537. <p>Shadow-banning is a useful tool for moderating malicious or egregiously abusive users.
  10538. A shadow-banned users receives successful responses to their client-server API requests,
  10539. but the events are not propagated into rooms. This can be an effective tool as it
  10540. (hopefully) takes longer for the user to realise they are being moderated before
  10541. pivoting to another account.</p>
  10542. <p>Shadow-banning a user should be used as a tool of last resort and may lead to confusing
  10543. or broken behaviour for the client. A shadow-banned user will not receive any
  10544. notification and it is generally more appropriate to ban or kick abusive users.
  10545. A shadow-banned user will be unable to contact anyone on the server.</p>
  10546. <p>The API is:</p>
  10547. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/shadow_ban
  10548. </code></pre>
  10549. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10550. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10551. <p>An empty JSON dict is returned.</p>
  10552. <p><strong>Parameters</strong></p>
  10553. <p>The following parameters should be set in the URL:</p>
  10554. <ul>
  10555. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10556. be local.</li>
  10557. </ul>
  10558. <h2 id="override-ratelimiting-for-users"><a class="header" href="#override-ratelimiting-for-users">Override ratelimiting for users</a></h2>
  10559. <p>This API allows to override or disable ratelimiting for a specific user.
  10560. There are specific APIs to set, get and delete a ratelimit.</p>
  10561. <h3 id="get-status-of-ratelimit"><a class="header" href="#get-status-of-ratelimit">Get status of ratelimit</a></h3>
  10562. <p>The API is:</p>
  10563. <pre><code>GET /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10564. </code></pre>
  10565. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10566. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10567. <p>A response body like the following is returned:</p>
  10568. <pre><code class="language-json">{
  10569. &quot;messages_per_second&quot;: 0,
  10570. &quot;burst_count&quot;: 0
  10571. }
  10572. </code></pre>
  10573. <p><strong>Parameters</strong></p>
  10574. <p>The following parameters should be set in the URL:</p>
  10575. <ul>
  10576. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10577. be local.</li>
  10578. </ul>
  10579. <p><strong>Response</strong></p>
  10580. <p>The following fields are returned in the JSON response body:</p>
  10581. <ul>
  10582. <li><code>messages_per_second</code> - integer - The number of actions that can
  10583. be performed in a second. <code>0</code> mean that ratelimiting is disabled for this user.</li>
  10584. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10585. being limited.</li>
  10586. </ul>
  10587. <p>If <strong>no</strong> custom ratelimit is set, an empty JSON dict is returned.</p>
  10588. <pre><code class="language-json">{}
  10589. </code></pre>
  10590. <h3 id="set-ratelimit"><a class="header" href="#set-ratelimit">Set ratelimit</a></h3>
  10591. <p>The API is:</p>
  10592. <pre><code>POST /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10593. </code></pre>
  10594. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10595. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10596. <p>A response body like the following is returned:</p>
  10597. <pre><code class="language-json">{
  10598. &quot;messages_per_second&quot;: 0,
  10599. &quot;burst_count&quot;: 0
  10600. }
  10601. </code></pre>
  10602. <p><strong>Parameters</strong></p>
  10603. <p>The following parameters should be set in the URL:</p>
  10604. <ul>
  10605. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10606. be local.</li>
  10607. </ul>
  10608. <p>Body parameters:</p>
  10609. <ul>
  10610. <li><code>messages_per_second</code> - positive integer, optional. The number of actions that can
  10611. be performed in a second. Defaults to <code>0</code>.</li>
  10612. <li><code>burst_count</code> - positive integer, optional. How many actions that can be performed
  10613. before being limited. Defaults to <code>0</code>.</li>
  10614. </ul>
  10615. <p>To disable users' ratelimit set both values to <code>0</code>.</p>
  10616. <p><strong>Response</strong></p>
  10617. <p>The following fields are returned in the JSON response body:</p>
  10618. <ul>
  10619. <li><code>messages_per_second</code> - integer - The number of actions that can
  10620. be performed in a second.</li>
  10621. <li><code>burst_count</code> - integer - How many actions that can be performed before
  10622. being limited.</li>
  10623. </ul>
  10624. <h3 id="delete-ratelimit"><a class="header" href="#delete-ratelimit">Delete ratelimit</a></h3>
  10625. <p>The API is:</p>
  10626. <pre><code>DELETE /_synapse/admin/v1/users/&lt;user_id&gt;/override_ratelimit
  10627. </code></pre>
  10628. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10629. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10630. <p>An empty JSON dict is returned.</p>
  10631. <pre><code class="language-json">{}
  10632. </code></pre>
  10633. <p><strong>Parameters</strong></p>
  10634. <p>The following parameters should be set in the URL:</p>
  10635. <ul>
  10636. <li><code>user_id</code> - The fully qualified MXID: for example, <code>@user:server.com</code>. The user must
  10637. be local.</li>
  10638. </ul>
  10639. <h3 id="check-username-availability"><a class="header" href="#check-username-availability">Check username availability</a></h3>
  10640. <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
  10641. API</a>
  10642. for more information.</p>
  10643. <p>This endpoint will work even if registration is disabled on the server, unlike
  10644. <code>/_matrix/client/r0/register/available</code>.</p>
  10645. <p>The API is:</p>
  10646. <pre><code>POST /_synapse/admin/v1/username_availabile?username=$localpart
  10647. </code></pre>
  10648. <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>
  10649. <p>To use it, you will need to authenticate by providing an <code>access_token</code> for a
  10650. server admin: <a href="admin_api/../usage/administration/admin_api">Admin API</a></p>
  10651. <div style="break-before: page; page-break-before: always;"></div><h1 id="version-api"><a class="header" href="#version-api">Version API</a></h1>
  10652. <p>This API returns the running Synapse version and the Python version
  10653. on which Synapse is being run. This is useful when a Synapse instance
  10654. is behind a proxy that does not forward the 'Server' header (which also
  10655. contains Synapse version information).</p>
  10656. <p>The api is:</p>
  10657. <pre><code>GET /_synapse/admin/v1/server_version
  10658. </code></pre>
  10659. <p>It returns a JSON body like the following:</p>
  10660. <pre><code class="language-json">{
  10661. &quot;server_version&quot;: &quot;0.99.2rc1 (b=develop, abcdef123)&quot;,
  10662. &quot;python_version&quot;: &quot;3.6.8&quot;
  10663. }
  10664. </code></pre>
  10665. <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>
  10666. <p>The &quot;manhole&quot; allows server administrators to access a Python shell on a running
  10667. Synapse installation. This is a very powerful mechanism for administration and
  10668. debugging.</p>
  10669. <p><strong><em>Security Warning</em></strong></p>
  10670. <p>Note that this will give administrative access to synapse to <strong>all users</strong> with
  10671. shell access to the server. It should therefore <strong>not</strong> be enabled in
  10672. environments where untrusted users have shell access.</p>
  10673. <hr />
  10674. <p>To enable it, first uncomment the <code>manhole</code> listener configuration in
  10675. <code>homeserver.yaml</code>. The configuration is slightly different if you're using docker.</p>
  10676. <h4 id="docker-config"><a class="header" href="#docker-config">Docker config</a></h4>
  10677. <p>If you are using Docker, set <code>bind_addresses</code> to <code>['0.0.0.0']</code> as shown:</p>
  10678. <pre><code class="language-yaml">listeners:
  10679. - port: 9000
  10680. bind_addresses: ['0.0.0.0']
  10681. type: manhole
  10682. </code></pre>
  10683. <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
  10684. <code>manhole</code> port forwarding. The <code>-p 127.0.0.1:9000:9000</code> below is important: it
  10685. ensures that access to the <code>manhole</code> is only possible for local users.</p>
  10686. <pre><code class="language-bash">docker run -d --name synapse \
  10687. --mount type=volume,src=synapse-data,dst=/data \
  10688. -p 8008:8008 \
  10689. -p 127.0.0.1:9000:9000 \
  10690. matrixdotorg/synapse:latest
  10691. </code></pre>
  10692. <h4 id="native-config"><a class="header" href="#native-config">Native config</a></h4>
  10693. <p>If you are not using docker, set <code>bind_addresses</code> to <code>['::1', '127.0.0.1']</code> as shown.
  10694. The <code>bind_addresses</code> in the example below is important: it ensures that access to the
  10695. <code>manhole</code> is only possible for local users).</p>
  10696. <pre><code class="language-yaml">listeners:
  10697. - port: 9000
  10698. bind_addresses: ['::1', '127.0.0.1']
  10699. type: manhole
  10700. </code></pre>
  10701. <h4 id="accessing-synapse-manhole"><a class="header" href="#accessing-synapse-manhole">Accessing synapse manhole</a></h4>
  10702. <p>Then restart synapse, and point an ssh client at port 9000 on localhost, using
  10703. the username <code>matrix</code>:</p>
  10704. <pre><code class="language-bash">ssh -p9000 matrix@localhost
  10705. </code></pre>
  10706. <p>The password is <code>rabbithole</code>.</p>
  10707. <p>This gives a Python REPL in which <code>hs</code> gives access to the
  10708. <code>synapse.server.HomeServer</code> object - which in turn gives access to many other
  10709. parts of the process.</p>
  10710. <p>Note that, prior to Synapse 1.41, any call which returns a coroutine will need to be wrapped in <code>ensureDeferred</code>.</p>
  10711. <p>As a simple example, retrieving an event from the database:</p>
  10712. <pre><code class="language-pycon">&gt;&gt;&gt; from twisted.internet import defer
  10713. &gt;&gt;&gt; defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
  10714. &lt;Deferred at 0x7ff253fc6998 current result: &lt;FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''&gt;&gt;
  10715. </code></pre>
  10716. <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>
  10717. <ol>
  10718. <li>
  10719. <p>Install Prometheus:</p>
  10720. <p>Follow instructions at
  10721. <a href="http://prometheus.io/docs/introduction/install/">http://prometheus.io/docs/introduction/install/</a></p>
  10722. </li>
  10723. <li>
  10724. <p>Enable Synapse metrics:</p>
  10725. <p>There are two methods of enabling metrics in Synapse.</p>
  10726. <p>The first serves the metrics as a part of the usual web server and
  10727. can be enabled by adding the &quot;metrics&quot; resource to the existing
  10728. listener as such:</p>
  10729. <pre><code class="language-yaml"> resources:
  10730. - names:
  10731. - client
  10732. - metrics
  10733. </code></pre>
  10734. <p>This provides a simple way of adding metrics to your Synapse
  10735. installation, and serves under <code>/_synapse/metrics</code>. If you do not
  10736. wish your metrics be publicly exposed, you will need to either
  10737. filter it out at your load balancer, or use the second method.</p>
  10738. <p>The second method runs the metrics server on a different port, in a
  10739. different thread to Synapse. This can make it more resilient to
  10740. heavy load meaning metrics cannot be retrieved, and can be exposed
  10741. to just internal networks easier. The served metrics are available
  10742. over HTTP only, and will be available at <code>/_synapse/metrics</code>.</p>
  10743. <p>Add a new listener to homeserver.yaml:</p>
  10744. <pre><code class="language-yaml"> listeners:
  10745. - type: metrics
  10746. port: 9000
  10747. bind_addresses:
  10748. - '0.0.0.0'
  10749. </code></pre>
  10750. <p>For both options, you will need to ensure that <code>enable_metrics</code> is
  10751. set to <code>True</code>.</p>
  10752. </li>
  10753. <li>
  10754. <p>Restart Synapse.</p>
  10755. </li>
  10756. <li>
  10757. <p>Add a Prometheus target for Synapse.</p>
  10758. <p>It needs to set the <code>metrics_path</code> to a non-default value (under
  10759. <code>scrape_configs</code>):</p>
  10760. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10761. scrape_interval: 15s
  10762. metrics_path: &quot;/_synapse/metrics&quot;
  10763. static_configs:
  10764. - targets: [&quot;my.server.here:port&quot;]
  10765. </code></pre>
  10766. <p>where <code>my.server.here</code> is the IP address of Synapse, and <code>port</code> is
  10767. the listener port configured with the <code>metrics</code> resource.</p>
  10768. <p>If your prometheus is older than 1.5.2, you will need to replace
  10769. <code>static_configs</code> in the above with <code>target_groups</code>.</p>
  10770. </li>
  10771. <li>
  10772. <p>Restart Prometheus.</p>
  10773. </li>
  10774. <li>
  10775. <p>Consider using the <a href="https://github.com/matrix-org/synapse/tree/master/contrib/grafana/">grafana dashboard</a>
  10776. and required <a href="https://github.com/matrix-org/synapse/tree/master/contrib/prometheus/">recording rules</a> </p>
  10777. </li>
  10778. </ol>
  10779. <h2 id="monitoring-workers"><a class="header" href="#monitoring-workers">Monitoring workers</a></h2>
  10780. <p>To monitor a Synapse installation using <a href="workers.html">workers</a>,
  10781. every worker needs to be monitored independently, in addition to
  10782. the main homeserver process. This is because workers don't send
  10783. their metrics to the main homeserver process, but expose them
  10784. directly (if they are configured to do so).</p>
  10785. <p>To allow collecting metrics from a worker, you need to add a
  10786. <code>metrics</code> listener to its configuration, by adding the following
  10787. under <code>worker_listeners</code>:</p>
  10788. <pre><code class="language-yaml"> - type: metrics
  10789. bind_address: ''
  10790. port: 9101
  10791. </code></pre>
  10792. <p>The <code>bind_address</code> and <code>port</code> parameters should be set so that
  10793. the resulting listener can be reached by prometheus, and they
  10794. don't clash with an existing worker.
  10795. With this example, the worker's metrics would then be available
  10796. on <code>http://127.0.0.1:9101</code>.</p>
  10797. <p>Example Prometheus target for Synapse with workers:</p>
  10798. <pre><code class="language-yaml"> - job_name: &quot;synapse&quot;
  10799. scrape_interval: 15s
  10800. metrics_path: &quot;/_synapse/metrics&quot;
  10801. static_configs:
  10802. - targets: [&quot;my.server.here:port&quot;]
  10803. labels:
  10804. instance: &quot;my.server&quot;
  10805. job: &quot;master&quot;
  10806. index: 1
  10807. - targets: [&quot;my.workerserver.here:port&quot;]
  10808. labels:
  10809. instance: &quot;my.server&quot;
  10810. job: &quot;generic_worker&quot;
  10811. index: 1
  10812. - targets: [&quot;my.workerserver.here:port&quot;]
  10813. labels:
  10814. instance: &quot;my.server&quot;
  10815. job: &quot;generic_worker&quot;
  10816. index: 2
  10817. - targets: [&quot;my.workerserver.here:port&quot;]
  10818. labels:
  10819. instance: &quot;my.server&quot;
  10820. job: &quot;media_repository&quot;
  10821. index: 1
  10822. </code></pre>
  10823. <p>Labels (<code>instance</code>, <code>job</code>, <code>index</code>) can be defined as anything.
  10824. The labels are used to group graphs in grafana.</p>
  10825. <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>
  10826. <p>Synapse 1.2 updates the Prometheus metrics to match the naming
  10827. convention of the upstream <code>prometheus_client</code>. The old names are
  10828. considered deprecated and will be removed in a future version of
  10829. Synapse.</p>
  10830. <table><thead><tr><th>New Name</th><th>Old Name</th></tr></thead><tbody>
  10831. <tr><td>python_gc_objects_collected_total</td><td>python_gc_objects_collected</td></tr>
  10832. <tr><td>python_gc_objects_uncollectable_total</td><td>python_gc_objects_uncollectable</td></tr>
  10833. <tr><td>python_gc_collections_total</td><td>python_gc_collections</td></tr>
  10834. <tr><td>process_cpu_seconds_total</td><td>process_cpu_seconds</td></tr>
  10835. <tr><td>synapse_federation_client_sent_transactions_total</td><td>synapse_federation_client_sent_transactions</td></tr>
  10836. <tr><td>synapse_federation_client_events_processed_total</td><td>synapse_federation_client_events_processed</td></tr>
  10837. <tr><td>synapse_event_processing_loop_count_total</td><td>synapse_event_processing_loop_count</td></tr>
  10838. <tr><td>synapse_event_processing_loop_room_count_total</td><td>synapse_event_processing_loop_room_count</td></tr>
  10839. <tr><td>synapse_util_metrics_block_count_total</td><td>synapse_util_metrics_block_count</td></tr>
  10840. <tr><td>synapse_util_metrics_block_time_seconds_total</td><td>synapse_util_metrics_block_time_seconds</td></tr>
  10841. <tr><td>synapse_util_metrics_block_ru_utime_seconds_total</td><td>synapse_util_metrics_block_ru_utime_seconds</td></tr>
  10842. <tr><td>synapse_util_metrics_block_ru_stime_seconds_total</td><td>synapse_util_metrics_block_ru_stime_seconds</td></tr>
  10843. <tr><td>synapse_util_metrics_block_db_txn_count_total</td><td>synapse_util_metrics_block_db_txn_count</td></tr>
  10844. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds_total</td><td>synapse_util_metrics_block_db_txn_duration_seconds</td></tr>
  10845. <tr><td>synapse_util_metrics_block_db_sched_duration_seconds_total</td><td>synapse_util_metrics_block_db_sched_duration_seconds</td></tr>
  10846. <tr><td>synapse_background_process_start_count_total</td><td>synapse_background_process_start_count</td></tr>
  10847. <tr><td>synapse_background_process_ru_utime_seconds_total</td><td>synapse_background_process_ru_utime_seconds</td></tr>
  10848. <tr><td>synapse_background_process_ru_stime_seconds_total</td><td>synapse_background_process_ru_stime_seconds</td></tr>
  10849. <tr><td>synapse_background_process_db_txn_count_total</td><td>synapse_background_process_db_txn_count</td></tr>
  10850. <tr><td>synapse_background_process_db_txn_duration_seconds_total</td><td>synapse_background_process_db_txn_duration_seconds</td></tr>
  10851. <tr><td>synapse_background_process_db_sched_duration_seconds_total</td><td>synapse_background_process_db_sched_duration_seconds</td></tr>
  10852. <tr><td>synapse_storage_events_persisted_events_total</td><td>synapse_storage_events_persisted_events</td></tr>
  10853. <tr><td>synapse_storage_events_persisted_events_sep_total</td><td>synapse_storage_events_persisted_events_sep</td></tr>
  10854. <tr><td>synapse_storage_events_state_delta_total</td><td>synapse_storage_events_state_delta</td></tr>
  10855. <tr><td>synapse_storage_events_state_delta_single_event_total</td><td>synapse_storage_events_state_delta_single_event</td></tr>
  10856. <tr><td>synapse_storage_events_state_delta_reuse_delta_total</td><td>synapse_storage_events_state_delta_reuse_delta</td></tr>
  10857. <tr><td>synapse_federation_server_received_pdus_total</td><td>synapse_federation_server_received_pdus</td></tr>
  10858. <tr><td>synapse_federation_server_received_edus_total</td><td>synapse_federation_server_received_edus</td></tr>
  10859. <tr><td>synapse_handler_presence_notified_presence_total</td><td>synapse_handler_presence_notified_presence</td></tr>
  10860. <tr><td>synapse_handler_presence_federation_presence_out_total</td><td>synapse_handler_presence_federation_presence_out</td></tr>
  10861. <tr><td>synapse_handler_presence_presence_updates_total</td><td>synapse_handler_presence_presence_updates</td></tr>
  10862. <tr><td>synapse_handler_presence_timers_fired_total</td><td>synapse_handler_presence_timers_fired</td></tr>
  10863. <tr><td>synapse_handler_presence_federation_presence_total</td><td>synapse_handler_presence_federation_presence</td></tr>
  10864. <tr><td>synapse_handler_presence_bump_active_time_total</td><td>synapse_handler_presence_bump_active_time</td></tr>
  10865. <tr><td>synapse_federation_client_sent_edus_total</td><td>synapse_federation_client_sent_edus</td></tr>
  10866. <tr><td>synapse_federation_client_sent_pdu_destinations_count_total</td><td>synapse_federation_client_sent_pdu_destinations:count</td></tr>
  10867. <tr><td>synapse_federation_client_sent_pdu_destinations_total</td><td>synapse_federation_client_sent_pdu_destinations:total</td></tr>
  10868. <tr><td>synapse_handlers_appservice_events_processed_total</td><td>synapse_handlers_appservice_events_processed</td></tr>
  10869. <tr><td>synapse_notifier_notified_events_total</td><td>synapse_notifier_notified_events</td></tr>
  10870. <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>
  10871. <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>
  10872. <tr><td>synapse_http_httppusher_http_pushes_processed_total</td><td>synapse_http_httppusher_http_pushes_processed</td></tr>
  10873. <tr><td>synapse_http_httppusher_http_pushes_failed_total</td><td>synapse_http_httppusher_http_pushes_failed</td></tr>
  10874. <tr><td>synapse_http_httppusher_badge_updates_processed_total</td><td>synapse_http_httppusher_badge_updates_processed</td></tr>
  10875. <tr><td>synapse_http_httppusher_badge_updates_failed_total</td><td>synapse_http_httppusher_badge_updates_failed</td></tr>
  10876. </tbody></table>
  10877. <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>
  10878. <p>The duplicated metrics deprecated in Synapse 0.27.0 have been removed.</p>
  10879. <p>All time duration-based metrics have been changed to be seconds. This
  10880. affects:</p>
  10881. <table><thead><tr><th>msec -&gt; sec metrics</th></tr></thead><tbody>
  10882. <tr><td>python_gc_time</td></tr>
  10883. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10884. <tr><td>synapse_storage_query_time</td></tr>
  10885. <tr><td>synapse_storage_schedule_time</td></tr>
  10886. <tr><td>synapse_storage_transaction_time</td></tr>
  10887. </tbody></table>
  10888. <p>Several metrics have been changed to be histograms, which sort entries
  10889. into buckets and allow better analysis. The following metrics are now
  10890. histograms:</p>
  10891. <table><thead><tr><th>Altered metrics</th></tr></thead><tbody>
  10892. <tr><td>python_gc_time</td></tr>
  10893. <tr><td>python_twisted_reactor_pending_calls</td></tr>
  10894. <tr><td>python_twisted_reactor_tick_time</td></tr>
  10895. <tr><td>synapse_http_server_response_time_seconds</td></tr>
  10896. <tr><td>synapse_storage_query_time</td></tr>
  10897. <tr><td>synapse_storage_schedule_time</td></tr>
  10898. <tr><td>synapse_storage_transaction_time</td></tr>
  10899. </tbody></table>
  10900. <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>
  10901. <p>Synapse 0.27.0 begins the process of rationalising the duplicate
  10902. <code>*:count</code> metrics reported for the resource tracking for code blocks and
  10903. HTTP requests.</p>
  10904. <p>At the same time, the corresponding <code>*:total</code> metrics are being renamed,
  10905. as the <code>:total</code> suffix no longer makes sense in the absence of a
  10906. corresponding <code>:count</code> metric.</p>
  10907. <p>To enable a graceful migration path, this release just adds new names
  10908. for the metrics being renamed. A future release will remove the old
  10909. ones.</p>
  10910. <p>The following table shows the new metrics, and the old metrics which
  10911. they are replacing.</p>
  10912. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10913. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_timer:count</td></tr>
  10914. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_utime:count</td></tr>
  10915. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_ru_stime:count</td></tr>
  10916. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_count:count</td></tr>
  10917. <tr><td>synapse_util_metrics_block_count</td><td>synapse_util_metrics_block_db_txn_duration:count</td></tr>
  10918. <tr><td>synapse_util_metrics_block_time_seconds</td><td>synapse_util_metrics_block_timer:total</td></tr>
  10919. <tr><td>synapse_util_metrics_block_ru_utime_seconds</td><td>synapse_util_metrics_block_ru_utime:total</td></tr>
  10920. <tr><td>synapse_util_metrics_block_ru_stime_seconds</td><td>synapse_util_metrics_block_ru_stime:total</td></tr>
  10921. <tr><td>synapse_util_metrics_block_db_txn_count</td><td>synapse_util_metrics_block_db_txn_count:total</td></tr>
  10922. <tr><td>synapse_util_metrics_block_db_txn_duration_seconds</td><td>synapse_util_metrics_block_db_txn_duration:total</td></tr>
  10923. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_requests</td></tr>
  10924. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_time:count</td></tr>
  10925. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_utime:count</td></tr>
  10926. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_ru_stime:count</td></tr>
  10927. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_count:count</td></tr>
  10928. <tr><td>synapse_http_server_response_count</td><td>synapse_http_server_response_db_txn_duration:count</td></tr>
  10929. <tr><td>synapse_http_server_response_time_seconds</td><td>synapse_http_server_response_time:total</td></tr>
  10930. <tr><td>synapse_http_server_response_ru_utime_seconds</td><td>synapse_http_server_response_ru_utime:total</td></tr>
  10931. <tr><td>synapse_http_server_response_ru_stime_seconds</td><td>synapse_http_server_response_ru_stime:total</td></tr>
  10932. <tr><td>synapse_http_server_response_db_txn_count</td><td>synapse_http_server_response_db_txn_count:total</td></tr>
  10933. <tr><td>synapse_http_server_response_db_txn_duration_seconds</td><td>synapse_http_server_response_db_txn_duration:total</td></tr>
  10934. </tbody></table>
  10935. <h2 id="standard-metric-names"><a class="header" href="#standard-metric-names">Standard Metric Names</a></h2>
  10936. <p>As of synapse version 0.18.2, the format of the process-wide metrics has
  10937. been changed to fit prometheus standard naming conventions. Additionally
  10938. the units have been changed to seconds, from miliseconds.</p>
  10939. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10940. <tr><td>process_cpu_user_seconds_total</td><td>process_resource_utime / 1000</td></tr>
  10941. <tr><td>process_cpu_system_seconds_total</td><td>process_resource_stime / 1000</td></tr>
  10942. <tr><td>process_open_fds (no 'type' label)</td><td>process_fds</td></tr>
  10943. </tbody></table>
  10944. <p>The python-specific counts of garbage collector performance have been
  10945. renamed.</p>
  10946. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10947. <tr><td>python_gc_time</td><td>reactor_gc_time</td></tr>
  10948. <tr><td>python_gc_unreachable_total</td><td>reactor_gc_unreachable</td></tr>
  10949. <tr><td>python_gc_counts</td><td>reactor_gc_counts</td></tr>
  10950. </tbody></table>
  10951. <p>The twisted-specific reactor metrics have been renamed.</p>
  10952. <table><thead><tr><th>New name</th><th>Old name</th></tr></thead><tbody>
  10953. <tr><td>python_twisted_reactor_pending_calls</td><td>reactor_pending_calls</td></tr>
  10954. <tr><td>python_twisted_reactor_tick_time</td><td>reactor_tick_time</td></tr>
  10955. </tbody></table>
  10956. <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>
  10957. <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>
  10958. <p>See the following for how to decode the dense data available from the default logging configuration.</p>
  10959. <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]
  10960. -AAAAAAAAAAAAAAAAAAAAA- -BBBBBBBBBBBBBBBBBBBBBB- -C- -DD- -EEEEEE- -FFFFFFFFF- -GG- -HHHHHHHHHHHHHHHHHHHHHHH- -IIIIII- -JJJJJJJ- -KKKKKK-, -LLLLLL- -MMMMMMM- -NNNNNN- O -P- -QQ- -RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR- -SSSSSSSSSSSS- -TTTTTT-
  10961. </code></pre>
  10962. <table><thead><tr><th>Part</th><th>Explanation</th></tr></thead><tbody>
  10963. <tr><td>AAAA</td><td>Timestamp request was logged (not recieved)</td></tr>
  10964. <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>
  10965. <tr><td>CCCC</td><td>Line number in code</td></tr>
  10966. <tr><td>DDDD</td><td>Log Level</td></tr>
  10967. <tr><td>EEEE</td><td>Request Identifier (This identifier is shared by related log lines)</td></tr>
  10968. <tr><td>FFFF</td><td>Source IP (Or X-Forwarded-For if enabled)</td></tr>
  10969. <tr><td>GGGG</td><td>Server Port</td></tr>
  10970. <tr><td>HHHH</td><td>Federated Server or Local User making request (blank if unauthenticated or not supplied)</td></tr>
  10971. <tr><td>IIII</td><td>Total Time to process the request</td></tr>
  10972. <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>
  10973. <tr><td>KKKK</td><td>Userland CPU time</td></tr>
  10974. <tr><td>LLLL</td><td>System CPU time</td></tr>
  10975. <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>
  10976. <tr><td>NNNN</td><td>Total time waiting for response to DB queries across all parallel DB work from this request</td></tr>
  10977. <tr><td>OOOO</td><td>Count of DB transactions performed</td></tr>
  10978. <tr><td>PPPP</td><td>Response body size</td></tr>
  10979. <tr><td>QQQQ</td><td>Response status code (prefixed with ! if the socket was closed before the response was generated)</td></tr>
  10980. <tr><td>RRRR</td><td>Request</td></tr>
  10981. <tr><td>SSSS</td><td>User-agent</td></tr>
  10982. <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>
  10983. </tbody></table>
  10984. <p>MMMM / NNNN can be greater than IIII if there are multiple slow database queries
  10985. running in parallel.</p>
  10986. <p>Some actions can result in multiple identical http requests, which will return
  10987. the same data, but only the first request will report time/transactions in
  10988. <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
  10989. response and will simultaneously return with the first request, but with very
  10990. small processing times.</p>
  10991. <div style="break-before: page; page-break-before: always;"></div><h1 id="contributing"><a class="header" href="#contributing">Contributing</a></h1>
  10992. <p>This document aims to get you started with contributing to Synapse!</p>
  10993. <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>
  10994. <p>Everyone is welcome to contribute code to <a href="https://github.com/matrix-org">matrix.org
  10995. projects</a>, provided that they are willing to
  10996. license their contributions under the same license as the project itself. We
  10997. follow a simple 'inbound=outbound' model for contributions: the act of
  10998. submitting an 'inbound' contribution means that the contributor agrees to
  10999. license the code under the same terms as the project's overall 'outbound'
  11000. license - in our case, this is almost always Apache Software License v2 (see
  11001. <a href="https://github.com/matrix-org/synapse/blob/develop/LICENSE">LICENSE</a>).</p>
  11002. <h1 id="2-what-do-i-need"><a class="header" href="#2-what-do-i-need">2. What do I need?</a></h1>
  11003. <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>
  11004. <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>
  11005. <p>For some tests, you will need <a href="https://docs.docker.com/get-docker/">a recent version of Docker</a>.</p>
  11006. <h1 id="3-get-the-source"><a class="header" href="#3-get-the-source">3. Get the source.</a></h1>
  11007. <p>The preferred and easiest way to contribute changes is to fork the relevant
  11008. 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
  11009. changes into our repo.</p>
  11010. <p>Please base your changes on the <code>develop</code> branch.</p>
  11011. <pre><code class="language-sh">git clone git@github.com:YOUR_GITHUB_USER_NAME/synapse.git
  11012. git checkout develop
  11013. </code></pre>
  11014. <p>If you need help getting started with git, this is beyond the scope of the document, but you
  11015. can find many good git tutorials on the web.</p>
  11016. <h1 id="4-install-the-dependencies"><a class="header" href="#4-install-the-dependencies">4. Install the dependencies</a></h1>
  11017. <h2 id="under-unix-macos-linux-bsd-"><a class="header" href="#under-unix-macos-linux-bsd-">Under Unix (macOS, Linux, BSD, ...)</a></h2>
  11018. <p>Once you have installed Python 3 and added the source, please open a terminal and
  11019. setup a <em>virtualenv</em>, as follows:</p>
  11020. <pre><code class="language-sh">cd path/where/you/have/cloned/the/repository
  11021. python3 -m venv ./env
  11022. source ./env/bin/activate
  11023. pip install -e &quot;.[all,lint,mypy,test]&quot;
  11024. pip install tox
  11025. </code></pre>
  11026. <p>This will install the developer dependencies for the project.</p>
  11027. <h2 id="under-windows"><a class="header" href="#under-windows">Under Windows</a></h2>
  11028. <p>TBD</p>
  11029. <h1 id="5-get-in-touch"><a class="header" href="#5-get-in-touch">5. Get in touch.</a></h1>
  11030. <p>Join our developer community on Matrix: #synapse-dev:matrix.org !</p>
  11031. <h1 id="6-pick-an-issue"><a class="header" href="#6-pick-an-issue">6. Pick an issue.</a></h1>
  11032. <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>
  11033. to work on.</p>
  11034. <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>
  11035. <p>There is a growing amount of documentation located in the
  11036. <a href="https://github.com/matrix-org/synapse/tree/develop/docs"><code>docs</code></a>
  11037. directory, with a rendered version <a href="https://matrix-org.github.io/synapse">available online</a>.
  11038. This documentation is intended primarily for sysadmins running their
  11039. own Synapse instance, as well as developers interacting externally with
  11040. Synapse.
  11041. <a href="https://github.com/matrix-org/synapse/tree/develop/docs/development"><code>docs/development</code></a>
  11042. exists primarily to house documentation for
  11043. Synapse developers.
  11044. <a href="https://github.com/matrix-org/synapse/tree/develop/docs/admin_api"><code>docs/admin_api</code></a> houses documentation
  11045. regarding Synapse's Admin API, which is used mostly by sysadmins and external
  11046. service developers.</p>
  11047. <p>Synapse's code style is documented <a href="development/../code_style.html">here</a>. Please follow
  11048. it, including the conventions for the <a href="development/../code_style.html#configuration-file-format">sample configuration
  11049. file</a>.</p>
  11050. <p>We welcome improvements and additions to our documentation itself! When
  11051. writing new pages, please
  11052. <a href="https://github.com/matrix-org/synapse/tree/develop/docs#adding-to-the-documentation">build <code>docs</code> to a book</a>
  11053. to check that your contributions render correctly. The docs are written in
  11054. <a href="https://guides.github.com/features/mastering-markdown/">GitHub-Flavoured Markdown</a>.</p>
  11055. <p>Some documentation also exists in <a href="https://github.com/matrix-org/synapse/wiki">Synapse's GitHub
  11056. Wiki</a>, although this is primarily
  11057. contributed to by community authors.</p>
  11058. <h1 id="8-test-test-test"><a class="header" href="#8-test-test-test">8. Test, test, test!</a></h1>
  11059. <p><a name="test-test-test"></a></p>
  11060. <p>While you're developing and before submitting a patch, you'll
  11061. want to test your code.</p>
  11062. <h2 id="run-the-linters"><a class="header" href="#run-the-linters">Run the linters.</a></h2>
  11063. <p>The linters look at your code and do two things:</p>
  11064. <ul>
  11065. <li>ensure that your code follows the coding style adopted by the project;</li>
  11066. <li>catch a number of errors in your code.</li>
  11067. </ul>
  11068. <p>They're pretty fast, don't hesitate!</p>
  11069. <pre><code class="language-sh">source ./env/bin/activate
  11070. ./scripts-dev/lint.sh
  11071. </code></pre>
  11072. <p>Note that this script <em>will modify your files</em> to fix styling errors.
  11073. Make sure that you have saved all your files.</p>
  11074. <p>If you wish to restrict the linters to only the files changed since the last commit
  11075. (much faster!), you can instead run:</p>
  11076. <pre><code class="language-sh">source ./env/bin/activate
  11077. ./scripts-dev/lint.sh -d
  11078. </code></pre>
  11079. <p>Or if you know exactly which files you wish to lint, you can instead run:</p>
  11080. <pre><code class="language-sh">source ./env/bin/activate
  11081. ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
  11082. </code></pre>
  11083. <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>
  11084. <p>The unit tests run parts of Synapse, including your changes, to see if anything
  11085. was broken. They are slower than the linters but will typically catch more errors.</p>
  11086. <pre><code class="language-sh">source ./env/bin/activate
  11087. trial tests
  11088. </code></pre>
  11089. <p>If you wish to only run <em>some</em> unit tests, you may specify
  11090. another module instead of <code>tests</code> - or a test class or a method:</p>
  11091. <pre><code class="language-sh">source ./env/bin/activate
  11092. trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
  11093. </code></pre>
  11094. <p>If your tests fail, you may wish to look at the logs (the default log level is <code>ERROR</code>):</p>
  11095. <pre><code class="language-sh">less _trial_temp/test.log
  11096. </code></pre>
  11097. <p>To increase the log level for the tests, set <code>SYNAPSE_TEST_LOG_LEVEL</code>:</p>
  11098. <pre><code class="language-sh">SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
  11099. </code></pre>
  11100. <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>
  11101. <p>The integration tests are a more comprehensive suite of tests. They
  11102. run a full version of Synapse, including your changes, to check if
  11103. anything was broken. They are slower than the unit tests but will
  11104. typically catch more errors.</p>
  11105. <p>The following command will let you run the integration test with the most common
  11106. configuration:</p>
  11107. <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
  11108. </code></pre>
  11109. <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>
  11110. <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>
  11111. <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>
  11112. <p>It's often nice to develop on Synapse and write Complement tests at the same time.
  11113. Here is how to run your local Synapse checkout against your local Complement checkout.</p>
  11114. <p>(checkout <a href="https://github.com/matrix-org/complement"><code>complement</code></a> alongside your <code>synapse</code> checkout)</p>
  11115. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh
  11116. </code></pre>
  11117. <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>
  11118. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory
  11119. </code></pre>
  11120. <p>To run a specific test, you can specify the whole name structure:</p>
  11121. <pre><code class="language-sh">COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory/parallel/Backfilled_historical_events_resolve_with_proper_state_in_correct_order
  11122. </code></pre>
  11123. <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>
  11124. <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>
  11125. <ol>
  11126. <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>
  11127. <li>Start the Complement tests</li>
  11128. <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>
  11129. <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>
  11130. <li>Install sqlite (database driver), <code>apt-get update &amp;&amp; apt-get install -y sqlite3</code></li>
  11131. <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>
  11132. </ol>
  11133. <h1 id="9-submit-your-patch"><a class="header" href="#9-submit-your-patch">9. Submit your patch.</a></h1>
  11134. <p>Once you're happy with your patch, it's time to prepare a Pull Request.</p>
  11135. <p>To prepare a Pull Request, please:</p>
  11136. <ol>
  11137. <li>verify that <a href="development/contributing_guide.html#test-test-test">all the tests pass</a>, including the coding style;</li>
  11138. <li><a href="development/contributing_guide.html#sign-off">sign off</a> your contribution;</li>
  11139. <li><code>git push</code> your commit to your fork of Synapse;</li>
  11140. <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>
  11141. <li>add a <a href="development/contributing_guide.html#changelog">changelog entry</a> and push it to your Pull Request;</li>
  11142. <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>
  11143. <li>if you need to update your PR, please avoid rebasing and just add new commits to your branch.</li>
  11144. </ol>
  11145. <h2 id="changelog"><a class="header" href="#changelog">Changelog</a></h2>
  11146. <p>All changes, even minor ones, need a corresponding changelog / newsfragment
  11147. entry. These are managed by <a href="https://github.com/hawkowl/towncrier">Towncrier</a>.</p>
  11148. <p>To create a changelog entry, make a new file in the <code>changelog.d</code> directory named
  11149. in the format of <code>PRnumber.type</code>. The type can be one of the following:</p>
  11150. <ul>
  11151. <li><code>feature</code></li>
  11152. <li><code>bugfix</code></li>
  11153. <li><code>docker</code> (for updates to the Docker image)</li>
  11154. <li><code>doc</code> (for updates to the documentation)</li>
  11155. <li><code>removal</code> (also used for deprecations)</li>
  11156. <li><code>misc</code> (for internal-only changes)</li>
  11157. </ul>
  11158. <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
  11159. release, so the content of the file should be a short description of your
  11160. change in the same style as the rest of the changelog. The file can contain Markdown
  11161. formatting, and should end with a full stop (.) or an exclamation mark (!) for
  11162. consistency.</p>
  11163. <p>Adding credits to the changelog is encouraged, we value your
  11164. contributions and would like to have you shouted out in the release notes!</p>
  11165. <p>For example, a fix in PR #1234 would have its changelog entry in
  11166. <code>changelog.d/1234.bugfix</code>, and contain content like:</p>
  11167. <blockquote>
  11168. <p>The security levels of Florbs are now validated when received
  11169. via the <code>/federation/florb</code> endpoint. Contributed by Jane Matrix.</p>
  11170. </blockquote>
  11171. <p>If there are multiple pull requests involved in a single bugfix/feature/etc,
  11172. then the content for each <code>changelog.d</code> file should be the same. Towncrier will
  11173. merge the matching files together into a single changelog entry when we come to
  11174. release.</p>
  11175. <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>
  11176. <p>Obviously, you don't know if you should call your newsfile
  11177. <code>1234.bugfix</code> or <code>5678.bugfix</code> until you create the PR, which leads to a
  11178. chicken-and-egg problem.</p>
  11179. <p>There are two options for solving this:</p>
  11180. <ol>
  11181. <li>
  11182. <p>Open the PR without a changelog file, see what number you got, and <em>then</em>
  11183. add the changelog file to your branch (see <a href="development/contributing_guide.html#updating-your-pull-request">Updating your pull
  11184. request</a>), or:</p>
  11185. </li>
  11186. <li>
  11187. <p>Look at the <a href="https://github.com/matrix-org/synapse/issues?q=">list of all
  11188. issues/PRs</a>, add one to the
  11189. highest number you see, and quickly open the PR before somebody else claims
  11190. your number.</p>
  11191. <p><a href="https://github.com/richvdh/scripts/blob/master/next_github_number.sh">This
  11192. script</a>
  11193. might be helpful if you find yourself doing this a lot.</p>
  11194. </li>
  11195. </ol>
  11196. <p>Sorry, we know it's a bit fiddly, but it's <em>really</em> helpful for us when we come
  11197. to put together a release!</p>
  11198. <h3 id="debian-changelog"><a class="header" href="#debian-changelog">Debian changelog</a></h3>
  11199. <p>Changes which affect the debian packaging files (in <code>debian</code>) are an
  11200. exception to the rule that all changes require a <code>changelog.d</code> file.</p>
  11201. <p>In this case, you will need to add an entry to the debian changelog for the
  11202. next release. For this, run the following command:</p>
  11203. <pre><code>dch
  11204. </code></pre>
  11205. <p>This will make up a new version number (if there isn't already an unreleased
  11206. version in flight), and open an editor where you can add a new changelog entry.
  11207. (Our release process will ensure that the version number and maintainer name is
  11208. corrected for the release.)</p>
  11209. <p>If your change affects both the debian packaging <em>and</em> files outside the debian
  11210. directory, you will need both a regular newsfragment <em>and</em> an entry in the
  11211. debian changelog. (Though typically such changes should be submitted as two
  11212. separate pull requests.)</p>
  11213. <h2 id="sign-off"><a class="header" href="#sign-off">Sign off</a></h2>
  11214. <p>In order to have a concrete record that your contribution is intentional
  11215. and you agree to license it under the same terms as the project's license, we've adopted the
  11216. same lightweight approach that the Linux Kernel
  11217. <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>,
  11218. <a href="https://github.com/docker/docker/blob/master/CONTRIBUTING.md">Docker</a>, and many other
  11219. projects use: the DCO (Developer Certificate of Origin:
  11220. http://developercertificate.org/). This is a simple declaration that you wrote
  11221. the contribution or otherwise have the right to contribute it to Matrix:</p>
  11222. <pre><code>Developer Certificate of Origin
  11223. Version 1.1
  11224. Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
  11225. 660 York Street, Suite 102,
  11226. San Francisco, CA 94110 USA
  11227. Everyone is permitted to copy and distribute verbatim copies of this
  11228. license document, but changing it is not allowed.
  11229. Developer's Certificate of Origin 1.1
  11230. By making a contribution to this project, I certify that:
  11231. (a) The contribution was created in whole or in part by me and I
  11232. have the right to submit it under the open source license
  11233. indicated in the file; or
  11234. (b) The contribution is based upon previous work that, to the best
  11235. of my knowledge, is covered under an appropriate open source
  11236. license and I have the right under that license to submit that
  11237. work with modifications, whether created in whole or in part
  11238. by me, under the same open source license (unless I am
  11239. permitted to submit under a different license), as indicated
  11240. in the file; or
  11241. (c) The contribution was provided directly to me by some other
  11242. person who certified (a), (b) or (c) and I have not modified
  11243. it.
  11244. (d) I understand and agree that this project and the contribution
  11245. are public and that a record of the contribution (including all
  11246. personal information I submit with it, including my sign-off) is
  11247. maintained indefinitely and may be redistributed consistent with
  11248. this project or the open source license(s) involved.
  11249. </code></pre>
  11250. <p>If you agree to this for your contribution, then all that's needed is to
  11251. include the line in your commit or pull request comment:</p>
  11252. <pre><code>Signed-off-by: Your Name &lt;your@email.example.org&gt;
  11253. </code></pre>
  11254. <p>We accept contributions under a legally identifiable name, such as
  11255. your name on government documentation or common-law names (names
  11256. claimed by legitimate usage or repute). Unfortunately, we cannot
  11257. accept anonymous contributions at this time.</p>
  11258. <p>Git allows you to add this signoff automatically when using the <code>-s</code>
  11259. flag to <code>git commit</code>, which uses the name and email set in your
  11260. <code>user.name</code> and <code>user.email</code> git configs.</p>
  11261. <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>
  11262. <p>Once the Pull Request is opened, you will see a few things:</p>
  11263. <ol>
  11264. <li>our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;</li>
  11265. <li>one or more of the developers will take a look at your Pull Request and offer feedback.</li>
  11266. </ol>
  11267. <p>From this point, you should:</p>
  11268. <ol>
  11269. <li>Look at the results of the CI pipeline.
  11270. <ul>
  11271. <li>If there is any error, fix the error.</li>
  11272. </ul>
  11273. </li>
  11274. <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>
  11275. <li>Create a new commit with the changes.
  11276. <ul>
  11277. <li>Please do NOT overwrite the history. New commits make the reviewer's life easier.</li>
  11278. <li>Push this commits to your Pull Request.</li>
  11279. </ul>
  11280. </li>
  11281. <li>Back to 1.</li>
  11282. </ol>
  11283. <p>Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!</p>
  11284. <h1 id="11-find-a-new-issue"><a class="header" href="#11-find-a-new-issue">11. Find a new issue.</a></h1>
  11285. <p>By now, you know the drill!</p>
  11286. <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>
  11287. <p>There are some notes for those with commit access to the project on how we
  11288. manage git <a href="development/git.html">here</a>.</p>
  11289. <h1 id="conclusion"><a class="header" href="#conclusion">Conclusion</a></h1>
  11290. <p>That's it! Matrix is a very open and collaborative project as you might expect
  11291. given our obsession with open communication. If we're going to successfully
  11292. matrix together all the fragmented communication technologies out there we are
  11293. reliant on contributions and collaboration from the community to do so. So
  11294. please get involved - and we hope you have as much fun hacking on Matrix as we
  11295. do!</p>
  11296. <div style="break-before: page; page-break-before: always;"></div><h1 id="code-style"><a class="header" href="#code-style">Code Style</a></h1>
  11297. <h2 id="formatting-tools"><a class="header" href="#formatting-tools">Formatting tools</a></h2>
  11298. <p>The Synapse codebase uses a number of code formatting tools in order to
  11299. quickly and automatically check for formatting (and sometimes logical)
  11300. errors in code.</p>
  11301. <p>The necessary tools are detailed below.</p>
  11302. <p>First install them with:</p>
  11303. <pre><code>pip install -e &quot;.[lint,mypy]&quot;
  11304. </code></pre>
  11305. <ul>
  11306. <li>
  11307. <p><strong>black</strong></p>
  11308. <p>The Synapse codebase uses <a href="https://pypi.org/project/black/">black</a>
  11309. as an opinionated code formatter, ensuring all comitted code is
  11310. properly formatted.</p>
  11311. <p>Have <code>black</code> auto-format your code (it shouldn't change any
  11312. functionality) with:</p>
  11313. <pre><code>black . --exclude=&quot;\.tox|build|env&quot;
  11314. </code></pre>
  11315. </li>
  11316. <li>
  11317. <p><strong>flake8</strong></p>
  11318. <p><code>flake8</code> is a code checking tool. We require code to pass <code>flake8</code>
  11319. before being merged into the codebase.</p>
  11320. <p>Check all application and test code with:</p>
  11321. <pre><code>flake8 synapse tests
  11322. </code></pre>
  11323. </li>
  11324. <li>
  11325. <p><strong>isort</strong></p>
  11326. <p><code>isort</code> ensures imports are nicely formatted, and can suggest and
  11327. auto-fix issues such as double-importing.</p>
  11328. <p>Auto-fix imports with:</p>
  11329. <pre><code>isort -rc synapse tests
  11330. </code></pre>
  11331. <p><code>-rc</code> means to recursively search the given directories.</p>
  11332. </li>
  11333. </ul>
  11334. <p>It's worth noting that modern IDEs and text editors can run these tools
  11335. automatically on save. It may be worth looking into whether this
  11336. functionality is supported in your editor for a more convenient
  11337. development workflow. It is not, however, recommended to run <code>flake8</code> on
  11338. save as it takes a while and is very resource intensive.</p>
  11339. <h2 id="general-rules"><a class="header" href="#general-rules">General rules</a></h2>
  11340. <ul>
  11341. <li><strong>Naming</strong>:
  11342. <ul>
  11343. <li>Use camel case for class and type names</li>
  11344. <li>Use underscores for functions and variables.</li>
  11345. </ul>
  11346. </li>
  11347. <li><strong>Docstrings</strong>: should follow the <a href="https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings">google code
  11348. style</a>.
  11349. See the
  11350. <a href="http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html">examples</a>
  11351. in the sphinx documentation.</li>
  11352. <li><strong>Imports</strong>:
  11353. <ul>
  11354. <li>
  11355. <p>Imports should be sorted by <code>isort</code> as described above.</p>
  11356. </li>
  11357. <li>
  11358. <p>Prefer to import classes and functions rather than packages or
  11359. modules.</p>
  11360. <p>Example:</p>
  11361. <pre><code>from synapse.types import UserID
  11362. ...
  11363. user_id = UserID(local, server)
  11364. </code></pre>
  11365. <p>is preferred over:</p>
  11366. <pre><code>from synapse import types
  11367. ...
  11368. user_id = types.UserID(local, server)
  11369. </code></pre>
  11370. <p>(or any other variant).</p>
  11371. <p>This goes against the advice in the Google style guide, but it
  11372. means that errors in the name are caught early (at import time).</p>
  11373. </li>
  11374. <li>
  11375. <p>Avoid wildcard imports (<code>from synapse.types import *</code>) and
  11376. relative imports (<code>from .types import UserID</code>).</p>
  11377. </li>
  11378. </ul>
  11379. </li>
  11380. </ul>
  11381. <h2 id="configuration-file-format"><a class="header" href="#configuration-file-format">Configuration file format</a></h2>
  11382. <p>The <a href="./sample_config.yaml">sample configuration file</a> acts as a
  11383. reference to Synapse's configuration options for server administrators.
  11384. Remember that many readers will be unfamiliar with YAML and server
  11385. administration in general, so that it is important that the file be as
  11386. easy to understand as possible, which includes following a consistent
  11387. format.</p>
  11388. <p>Some guidelines follow:</p>
  11389. <ul>
  11390. <li>
  11391. <p>Sections should be separated with a heading consisting of a single
  11392. line prefixed and suffixed with <code>##</code>. There should be <strong>two</strong> blank
  11393. lines before the section header, and <strong>one</strong> after.</p>
  11394. </li>
  11395. <li>
  11396. <p>Each option should be listed in the file with the following format:</p>
  11397. <ul>
  11398. <li>
  11399. <p>A comment describing the setting. Each line of this comment
  11400. should be prefixed with a hash (<code>#</code>) and a space.</p>
  11401. <p>The comment should describe the default behaviour (ie, what
  11402. happens if the setting is omitted), as well as what the effect
  11403. will be if the setting is changed.</p>
  11404. <p>Often, the comment end with something like &quot;uncomment the
  11405. following to <do action>&quot;.</p>
  11406. </li>
  11407. <li>
  11408. <p>A line consisting of only <code>#</code>.</p>
  11409. </li>
  11410. <li>
  11411. <p>A commented-out example setting, prefixed with only <code>#</code>.</p>
  11412. <p>For boolean (on/off) options, convention is that this example
  11413. should be the <em>opposite</em> to the default (so the comment will end
  11414. with &quot;Uncomment the following to enable [or disable]
  11415. <feature>.&quot; For other options, the example should give some
  11416. non-default value which is likely to be useful to the reader.</p>
  11417. </li>
  11418. </ul>
  11419. </li>
  11420. <li>
  11421. <p>There should be a blank line between each option.</p>
  11422. </li>
  11423. <li>
  11424. <p>Where several settings are grouped into a single dict, <em>avoid</em> the
  11425. convention where the whole block is commented out, resulting in
  11426. comment lines starting <code># #</code>, as this is hard to read and confusing
  11427. to edit. Instead, leave the top-level config option uncommented, and
  11428. follow the conventions above for sub-options. Ensure that your code
  11429. correctly handles the top-level option being set to <code>None</code> (as it
  11430. will be if no sub-options are enabled).</p>
  11431. </li>
  11432. <li>
  11433. <p>Lines should be wrapped at 80 characters.</p>
  11434. </li>
  11435. <li>
  11436. <p>Use two-space indents.</p>
  11437. </li>
  11438. <li>
  11439. <p><code>true</code> and <code>false</code> are spelt thus (as opposed to <code>True</code>, etc.)</p>
  11440. </li>
  11441. <li>
  11442. <p>Use single quotes (<code>'</code>) rather than double-quotes (<code>&quot;</code>) or backticks
  11443. (<code>`</code>) to refer to configuration options.</p>
  11444. </li>
  11445. </ul>
  11446. <p>Example:</p>
  11447. <pre><code>## Frobnication ##
  11448. # The frobnicator will ensure that all requests are fully frobnicated.
  11449. # To enable it, uncomment the following.
  11450. #
  11451. #frobnicator_enabled: true
  11452. # By default, the frobnicator will frobnicate with the default frobber.
  11453. # The following will make it use an alternative frobber.
  11454. #
  11455. #frobincator_frobber: special_frobber
  11456. # Settings for the frobber
  11457. #
  11458. frobber:
  11459. # frobbing speed. Defaults to 1.
  11460. #
  11461. #speed: 10
  11462. # frobbing distance. Defaults to 1000.
  11463. #
  11464. #distance: 100
  11465. </code></pre>
  11466. <p>Note that the sample configuration is generated from the synapse code
  11467. and is maintained by a script, <code>scripts-dev/generate_sample_config</code>.
  11468. Making sure that the output from this script matches the desired format
  11469. is left as an exercise for the reader!</p>
  11470. <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>
  11471. <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>
  11472. <p>In an ideal world, our git commit history would be a linear progression of
  11473. commits each of which contains a single change building on what came
  11474. before. Here, by way of an arbitrary example, is the top of <code>git log --graph b2dba0607</code>:</p>
  11475. <img src="development/img/git/clean.png" alt="clean git graph" width="500px">
  11476. <p>Note how the commit comment explains clearly what is changing and why. Also
  11477. note the <em>absence</em> of merge commits, as well as the absence of commits called
  11478. things like (to pick a few culprits):
  11479. <a href="https://github.com/matrix-org/synapse/commit/84691da6c">“pep8”</a>, <a href="https://github.com/matrix-org/synapse/commit/474810d9d">“fix broken
  11480. test”</a>,
  11481. <a href="https://github.com/matrix-org/synapse/commit/c9d72e457">“oops”</a>,
  11482. <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
  11483. the president?”</a>.</p>
  11484. <p>There are a number of reasons why keeping a clean commit history is a good
  11485. thing:</p>
  11486. <ul>
  11487. <li>
  11488. <p>From time to time, after a change lands, it turns out to be necessary to
  11489. revert it, or to backport it to a release branch. Those operations are
  11490. <em>much</em> easier when the change is contained in a single commit.</p>
  11491. </li>
  11492. <li>
  11493. <p>Similarly, it's much easier to answer questions like “is the fix for
  11494. <code>/publicRooms</code> on the release branch?” if that change consists of a single
  11495. commit.</p>
  11496. </li>
  11497. <li>
  11498. <p>Likewise: “what has changed on this branch in the last week?” is much
  11499. clearer without merges and “pep8” commits everywhere.</p>
  11500. </li>
  11501. <li>
  11502. <p>Sometimes we need to figure out where a bug got introduced, or some
  11503. behaviour changed. One way of doing that is with <code>git bisect</code>: pick an
  11504. arbitrary commit between the known good point and the known bad point, and
  11505. see how the code behaves. However, that strategy fails if the commit you
  11506. chose is the middle of someone's epic branch in which they broke the world
  11507. before putting it back together again.</p>
  11508. </li>
  11509. </ul>
  11510. <p>One counterargument is that it is sometimes useful to see how a PR evolved as
  11511. it went through review cycles. This is true, but that information is always
  11512. 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
  11513. namespace</a>).</p>
  11514. <p>Of course, in reality, things are more complicated than that. We have release
  11515. branches as well as <code>develop</code> and <code>master</code>, and we deliberately merge changes
  11516. between them. Bugs often slip through and have to be fixed later. That's all
  11517. fine: this not a cast-iron rule which must be obeyed, but an ideal to aim
  11518. towards.</p>
  11519. <h2 id="merges-squashes-rebases-wtf"><a class="header" href="#merges-squashes-rebases-wtf">Merges, squashes, rebases: wtf?</a></h2>
  11520. <p>Ok, so that's what we'd like to achieve. How do we achieve it?</p>
  11521. <p>The TL;DR is: when you come to merge a pull request, you <em>probably</em> want to
  11522. “squash and merge”:</p>
  11523. <p><img src="development/img/git/squash.png" alt="squash and merge" />.</p>
  11524. <p>(This applies whether you are merging your own PR, or that of another
  11525. contributor.)</p>
  11526. <p>“Squash and merge”<sup id="a1"><a href="development/git.html#f1">1</a></sup> takes all of the changes in the
  11527. PR, and bundles them into a single commit. GitHub gives you the opportunity to
  11528. edit the commit message before you confirm, and normally you should do so,
  11529. because the default will be useless (again: <code>* woops typo</code> is not a useful
  11530. thing to keep in the historical record).</p>
  11531. <p>The main problem with this approach comes when you have a series of pull
  11532. requests which build on top of one another: as soon as you squash-merge the
  11533. first PR, you'll end up with a stack of conflicts to resolve in all of the
  11534. others. In general, it's best to avoid this situation in the first place by
  11535. trying not to have multiple related PRs in flight at the same time. Still,
  11536. sometimes that's not possible and doing a regular merge is the lesser evil.</p>
  11537. <p>Another occasion in which a regular merge makes more sense is a PR where you've
  11538. deliberately created a series of commits each of which makes sense in its own
  11539. right. For example: <a href="https://github.com/matrix-org/synapse/pull/6837">a PR which gradually propagates a refactoring operation
  11540. through the codebase</a>, or <a href="https://github.com/matrix-org/synapse/pull/5987">a
  11541. PR which is the culmination of several other
  11542. PRs</a>. In this case the ability
  11543. to figure out when a particular change/bug was introduced could be very useful.</p>
  11544. <p>Ultimately: <strong>this is not a hard-and-fast-rule</strong>. If in doubt, ask yourself “do
  11545. each of the commits I am about to merge make sense in their own right”, but
  11546. remember that we're just doing our best to balance “keeping the commit history
  11547. clean” with other factors.</p>
  11548. <h2 id="git-branching-model"><a class="header" href="#git-branching-model">Git branching model</a></h2>
  11549. <p>A <a href="https://nvie.com/posts/a-successful-git-branching-model/">lot</a>
  11550. <a href="http://scottchacon.com/2011/08/31/github-flow.html">of</a>
  11551. <a href="https://www.endoflineblog.com/gitflow-considered-harmful">words</a> have been
  11552. written in the past about git branching models (no really, <a href="https://martinfowler.com/articles/branching-patterns.html">a
  11553. lot</a>). I tend to
  11554. think the whole thing is overblown. Fundamentally, it's not that
  11555. complicated. Here's how we do it.</p>
  11556. <p>Let's start with a picture:</p>
  11557. <p><img src="development/img/git/branches.jpg" alt="branching model" /></p>
  11558. <p>It looks complicated, but it's really not. There's one basic rule: <em>anyone</em> is
  11559. free to merge from <em>any</em> more-stable branch to <em>any</em> less-stable branch at
  11560. <em>any</em> time<sup id="a2"><a href="development/git.html#f2">2</a></sup>. (The principle behind this is that if a
  11561. change is good enough for the more-stable branch, then it's also good enough go
  11562. put in a less-stable branch.)</p>
  11563. <p>Meanwhile, merging (or squashing, as per the above) from a less-stable to a
  11564. more-stable branch is a deliberate action in which you want to publish a change
  11565. or a set of changes to (some subset of) the world: for example, this happens
  11566. when a PR is landed, or as part of our release process.</p>
  11567. <p>So, what counts as a more- or less-stable branch? A little reflection will show
  11568. that our active branches are ordered thus, from more-stable to less-stable:</p>
  11569. <ul>
  11570. <li><code>master</code> (tracks our last release).</li>
  11571. <li><code>release-vX.Y</code> (the branch where we prepare the next release)<sup
  11572. id="a3"><a href="development/git.html#f3">3</a></sup>.</li>
  11573. <li>PR branches which are targeting the release.</li>
  11574. <li><code>develop</code> (our &quot;mainline&quot; branch containing our bleeding-edge).</li>
  11575. <li>regular PR branches.</li>
  11576. </ul>
  11577. <p>The corollary is: if you have a bugfix that needs to land in both
  11578. <code>release-vX.Y</code> <em>and</em> <code>develop</code>, then you should base your PR on
  11579. <code>release-vX.Y</code>, get it merged there, and then merge from <code>release-vX.Y</code> to
  11580. <code>develop</code>. (If a fix lands in <code>develop</code> and we later need it in a
  11581. release-branch, we can of course cherry-pick it, but landing it in the release
  11582. branch first helps reduce the chance of annoying conflicts.)</p>
  11583. <hr />
  11584. <p><b id="f1">[1]</b>: “Squash and merge” is GitHub's term for this
  11585. operation. Given that there is no merge involved, I'm not convinced it's the
  11586. most intuitive name. <a href="development/git.html#a1">^</a></p>
  11587. <p><b id="f2">[2]</b>: Well, anyone with commit access.<a href="development/git.html#a2">^</a></p>
  11588. <p><b id="f3">[3]</b>: Very, very occasionally (I think this has happened once in
  11589. the history of Synapse), we've had two releases in flight at once. Obviously,
  11590. <code>release-v1.2</code> is more-stable than <code>release-v1.3</code>. <a href="development/git.html#a3">^</a></p>
  11591. <div style="break-before: page; page-break-before: always;"></div><h1 id="opentracing"><a class="header" href="#opentracing">OpenTracing</a></h1>
  11592. <h2 id="background"><a class="header" href="#background">Background</a></h2>
  11593. <p>OpenTracing is a semi-standard being adopted by a number of distributed
  11594. tracing platforms. It is a common api for facilitating vendor-agnostic
  11595. tracing instrumentation. That is, we can use the OpenTracing api and
  11596. select one of a number of tracer implementations to do the heavy lifting
  11597. in the background. Our current selected implementation is Jaeger.</p>
  11598. <p>OpenTracing is a tool which gives an insight into the causal
  11599. relationship of work done in and between servers. The servers each track
  11600. events and report them to a centralised server - in Synapse's case:
  11601. Jaeger. The basic unit used to represent events is the span. The span
  11602. roughly represents a single piece of work that was done and the time at
  11603. which it occurred. A span can have child spans, meaning that the work of
  11604. the child had to be completed for the parent span to complete, or it can
  11605. have follow-on spans which represent work that is undertaken as a result
  11606. of the parent but is not depended on by the parent to in order to
  11607. finish.</p>
  11608. <p>Since this is undertaken in a distributed environment a request to
  11609. another server, such as an RPC or a simple GET, can be considered a span
  11610. (a unit or work) for the local server. This causal link is what
  11611. OpenTracing aims to capture and visualise. In order to do this metadata
  11612. about the local server's span, i.e the 'span context', needs to be
  11613. included with the request to the remote.</p>
  11614. <p>It is up to the remote server to decide what it does with the spans it
  11615. creates. This is called the sampling policy and it can be configured
  11616. through Jaeger's settings.</p>
  11617. <p>For OpenTracing concepts see
  11618. <a href="https://opentracing.io/docs/overview/what-is-tracing/">https://opentracing.io/docs/overview/what-is-tracing/</a>.</p>
  11619. <p>For more information about Jaeger's implementation see
  11620. <a href="https://www.jaegertracing.io/docs/">https://www.jaegertracing.io/docs/</a></p>
  11621. <h2 id="setting-up-opentracing"><a class="header" href="#setting-up-opentracing">Setting up OpenTracing</a></h2>
  11622. <p>To receive OpenTracing spans, start up a Jaeger server. This can be done
  11623. using docker like so:</p>
  11624. <pre><code class="language-sh">docker run -d --name jaeger \
  11625. -p 6831:6831/udp \
  11626. -p 6832:6832/udp \
  11627. -p 5778:5778 \
  11628. -p 16686:16686 \
  11629. -p 14268:14268 \
  11630. jaegertracing/all-in-one:1
  11631. </code></pre>
  11632. <p>Latest documentation is probably at
  11633. https://www.jaegertracing.io/docs/latest/getting-started.</p>
  11634. <h2 id="enable-opentracing-in-synapse"><a class="header" href="#enable-opentracing-in-synapse">Enable OpenTracing in Synapse</a></h2>
  11635. <p>OpenTracing is not enabled by default. It must be enabled in the
  11636. homeserver config by uncommenting the config options under <code>opentracing</code>
  11637. as shown in the <a href="./sample_config.yaml">sample config</a>. For example:</p>
  11638. <pre><code class="language-yaml">opentracing:
  11639. enabled: true
  11640. homeserver_whitelist:
  11641. - &quot;mytrustedhomeserver.org&quot;
  11642. - &quot;*.myotherhomeservers.com&quot;
  11643. </code></pre>
  11644. <h2 id="homeserver-whitelisting"><a class="header" href="#homeserver-whitelisting">Homeserver whitelisting</a></h2>
  11645. <p>The homeserver whitelist is configured using regular expressions. A list
  11646. of regular expressions can be given and their union will be compared
  11647. when propagating any spans contexts to another homeserver.</p>
  11648. <p>Though it's mostly safe to send and receive span contexts to and from
  11649. untrusted users since span contexts are usually opaque ids it can lead
  11650. to two problems, namely:</p>
  11651. <ul>
  11652. <li>If the span context is marked as sampled by the sending homeserver
  11653. the receiver will sample it. Therefore two homeservers with wildly
  11654. different sampling policies could incur higher sampling counts than
  11655. intended.</li>
  11656. <li>Sending servers can attach arbitrary data to spans, known as
  11657. 'baggage'. For safety this has been disabled in Synapse but that
  11658. doesn't prevent another server sending you baggage which will be
  11659. logged to OpenTracing's logs.</li>
  11660. </ul>
  11661. <h2 id="configuring-jaeger"><a class="header" href="#configuring-jaeger">Configuring Jaeger</a></h2>
  11662. <p>Sampling strategies can be set as in this document:
  11663. <a href="https://www.jaegertracing.io/docs/latest/sampling/">https://www.jaegertracing.io/docs/latest/sampling/</a>.</p>
  11664. <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>
  11665. <p>Synapse's database schema is stored in the <code>synapse.storage.schema</code> module.</p>
  11666. <h2 id="logical-databases"><a class="header" href="#logical-databases">Logical databases</a></h2>
  11667. <p>Synapse supports splitting its datastore across multiple physical databases (which can
  11668. be useful for large installations), and the schema files are therefore split according
  11669. to the logical database they apply to.</p>
  11670. <p>At the time of writing, the following &quot;logical&quot; databases are supported:</p>
  11671. <ul>
  11672. <li><code>state</code> - used to store Matrix room state (more specifically, <code>state_groups</code>,
  11673. their relationships and contents).</li>
  11674. <li><code>main</code> - stores everything else.</li>
  11675. </ul>
  11676. <p>Additionally, the <code>common</code> directory contains schema files for tables which must be
  11677. present on <em>all</em> physical databases.</p>
  11678. <h2 id="synapse-schema-versions"><a class="header" href="#synapse-schema-versions">Synapse schema versions</a></h2>
  11679. <p>Synapse manages its database schema via &quot;schema versions&quot;. These are mainly used to
  11680. help avoid confusion if the Synapse codebase is rolled back after the database is
  11681. updated. They work as follows:</p>
  11682. <ul>
  11683. <li>
  11684. <p>The Synapse codebase defines a constant <code>synapse.storage.schema.SCHEMA_VERSION</code>
  11685. which represents the expectations made about the database by that version. For
  11686. example, as of Synapse v1.36, this is <code>59</code>.</p>
  11687. </li>
  11688. <li>
  11689. <p>The database stores a &quot;compatibility version&quot; in
  11690. <code>schema_compat_version.compat_version</code> which defines the <code>SCHEMA_VERSION</code> of the
  11691. oldest version of Synapse which will work with the database. On startup, if
  11692. <code>compat_version</code> is found to be newer than <code>SCHEMA_VERSION</code>, Synapse will refuse to
  11693. start.</p>
  11694. <p>Synapse automatically updates this field from
  11695. <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code>.</p>
  11696. </li>
  11697. <li>
  11698. <p>Whenever a backwards-incompatible change is made to the database format (normally
  11699. via a <code>delta</code> file), <code>synapse.storage.schema.SCHEMA_COMPAT_VERSION</code> is also updated
  11700. so that administrators can not accidentally roll back to a too-old version of Synapse.</p>
  11701. </li>
  11702. </ul>
  11703. <p>Generally, the goal is to maintain compatibility with at least one or two previous
  11704. releases of Synapse, so any substantial change tends to require multiple releases and a
  11705. bit of forward-planning to get right.</p>
  11706. <p>As a worked example: we want to remove the <code>room_stats_historical</code> table. Here is how it
  11707. might pan out.</p>
  11708. <ol>
  11709. <li>
  11710. <p>Replace any code that <em>reads</em> from <code>room_stats_historical</code> with alternative
  11711. implementations, but keep writing to it in case of rollback to an earlier version.
  11712. Also, increase <code>synapse.storage.schema.SCHEMA_VERSION</code>. In this
  11713. instance, there is no existing code which reads from <code>room_stats_historical</code>, so
  11714. our starting point is:</p>
  11715. <p>v1.36.0: <code>SCHEMA_VERSION=59</code>, <code>SCHEMA_COMPAT_VERSION=59</code></p>
  11716. </li>
  11717. <li>
  11718. <p>Next (say in Synapse v1.37.0): remove the code that <em>writes</em> to
  11719. <code>room_stats_historical</code>, but don’t yet remove the table in case of rollback to
  11720. v1.36.0. Again, we increase <code>synapse.storage.schema.SCHEMA_VERSION</code>, but
  11721. because we have not broken compatibility with v1.36, we do not yet update
  11722. <code>SCHEMA_COMPAT_VERSION</code>. We now have:</p>
  11723. <p>v1.37.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=59</code>.</p>
  11724. </li>
  11725. <li>
  11726. <p>Later (say in Synapse v1.38.0): we can remove the table altogether. This will
  11727. break compatibility with v1.36.0, so we must update <code>SCHEMA_COMPAT_VERSION</code> accordingly.
  11728. There is no need to update <code>synapse.storage.schema.SCHEMA_VERSION</code>, since there is no
  11729. change to the Synapse codebase here. So we end up with:</p>
  11730. <p>v1.38.0: <code>SCHEMA_VERSION=60</code>, <code>SCHEMA_COMPAT_VERSION=60</code>.</p>
  11731. </li>
  11732. </ol>
  11733. <p>If in doubt about whether to update <code>SCHEMA_VERSION</code> or not, it is generally best to
  11734. lean towards doing so.</p>
  11735. <h2 id="full-schema-dumps"><a class="header" href="#full-schema-dumps">Full schema dumps</a></h2>
  11736. <p>In the <code>full_schemas</code> directories, only the most recently-numbered snapshot is used
  11737. (<code>54</code> at the time of writing). Older snapshots (eg, <code>16</code>) are present for historical
  11738. reference only.</p>
  11739. <h3 id="building-full-schema-dumps"><a class="header" href="#building-full-schema-dumps">Building full schema dumps</a></h3>
  11740. <p>If you want to recreate these schemas, they need to be made from a database that
  11741. has had all background updates run.</p>
  11742. <p>To do so, use <code>scripts-dev/make_full_schema.sh</code>. This will produce new
  11743. <code>full.sql.postgres</code> and <code>full.sql.sqlite</code> files.</p>
  11744. <p>Ensure postgres is installed, then run:</p>
  11745. <pre><code>./scripts-dev/make_full_schema.sh -p postgres_username -o output_dir/
  11746. </code></pre>
  11747. <p>NB at the time of writing, this script predates the split into separate <code>state</code>/<code>main</code>
  11748. databases so will require updates to handle that correctly.</p>
  11749. <h2 id="boolean-columns"><a class="header" href="#boolean-columns">Boolean columns</a></h2>
  11750. <p>Boolean columns require special treatment, since SQLite treats booleans the
  11751. same as integers.</p>
  11752. <p>There are three separate aspects to this:</p>
  11753. <ul>
  11754. <li>
  11755. <p>Any new boolean column must be added to the <code>BOOLEAN_COLUMNS</code> list in
  11756. <code>scripts/synapse_port_db</code>. This tells the port script to cast the integer
  11757. value from SQLite to a boolean before writing the value to the postgres
  11758. database.</p>
  11759. </li>
  11760. <li>
  11761. <p>Before SQLite 3.23, <code>TRUE</code> and <code>FALSE</code> were not recognised as constants by
  11762. SQLite, and the <code>IS [NOT] TRUE</code>/<code>IS [NOT] FALSE</code> operators were not
  11763. supported. This makes it necessary to avoid using <code>TRUE</code> and <code>FALSE</code>
  11764. constants in SQL commands.</p>
  11765. <p>For example, to insert a <code>TRUE</code> value into the database, write:</p>
  11766. <pre><code class="language-python">txn.execute(&quot;INSERT INTO tbl(col) VALUES (?)&quot;, (True, ))
  11767. </code></pre>
  11768. </li>
  11769. <li>
  11770. <p>Default values for new boolean columns present a particular
  11771. difficulty. Generally it is best to create separate schema files for
  11772. Postgres and SQLite. For example:</p>
  11773. <pre><code class="language-sql"># in 00delta.sql.postgres:
  11774. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT FALSE;
  11775. </code></pre>
  11776. <pre><code class="language-sql"># in 00delta.sql.sqlite:
  11777. ALTER TABLE tbl ADD COLUMN col BOOLEAN DEFAULT 0;
  11778. </code></pre>
  11779. <p>Note that there is a particularly insidious failure mode here: the Postgres
  11780. flavour will be accepted by SQLite 3.22, but will give a column whose
  11781. default value is the <strong>string</strong> <code>&quot;FALSE&quot;</code> - which, when cast back to a boolean
  11782. in Python, evaluates to <code>True</code>.</p>
  11783. </li>
  11784. </ul>
  11785. <div style="break-before: page; page-break-before: always;"></div><h1 id="log-contexts"><a class="header" href="#log-contexts">Log Contexts</a></h1>
  11786. <p>To help track the processing of individual requests, synapse uses a
  11787. '<code>log context</code>' to track which request it is handling at any given
  11788. moment. This is done via a thread-local variable; a <code>logging.Filter</code> is
  11789. then used to fish the information back out of the thread-local variable
  11790. and add it to each log record.</p>
  11791. <p>Logcontexts are also used for CPU and database accounting, so that we
  11792. can track which requests were responsible for high CPU use or database
  11793. activity.</p>
  11794. <p>The <code>synapse.logging.context</code> module provides a facilities for managing
  11795. the current log context (as well as providing the <code>LoggingContextFilter</code>
  11796. class).</p>
  11797. <p>Asynchronous functions make the whole thing complicated, so this document describes
  11798. how it all works, and how to write code which follows the rules.</p>
  11799. <p>In this document, &quot;awaitable&quot; refers to any object which can be <code>await</code>ed. In the context of
  11800. Synapse, that normally means either a coroutine or a Twisted
  11801. <a href="https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html"><code>Deferred</code></a>.</p>
  11802. <h2 id="logcontexts-without-asynchronous-code"><a class="header" href="#logcontexts-without-asynchronous-code">Logcontexts without asynchronous code</a></h2>
  11803. <p>In the absence of any asynchronous voodoo, things are simple enough. As with
  11804. any code of this nature, the rule is that our function should leave
  11805. things as it found them:</p>
  11806. <pre><code class="language-python">from synapse.logging import context # omitted from future snippets
  11807. def handle_request(request_id):
  11808. request_context = context.LoggingContext()
  11809. calling_context = context.set_current_context(request_context)
  11810. try:
  11811. request_context.request = request_id
  11812. do_request_handling()
  11813. logger.debug(&quot;finished&quot;)
  11814. finally:
  11815. context.set_current_context(calling_context)
  11816. def do_request_handling():
  11817. logger.debug(&quot;phew&quot;) # this will be logged against request_id
  11818. </code></pre>
  11819. <p>LoggingContext implements the context management methods, so the above
  11820. can be written much more succinctly as:</p>
  11821. <pre><code class="language-python">def handle_request(request_id):
  11822. with context.LoggingContext() as request_context:
  11823. request_context.request = request_id
  11824. do_request_handling()
  11825. logger.debug(&quot;finished&quot;)
  11826. def do_request_handling():
  11827. logger.debug(&quot;phew&quot;)
  11828. </code></pre>
  11829. <h2 id="using-logcontexts-with-awaitables"><a class="header" href="#using-logcontexts-with-awaitables">Using logcontexts with awaitables</a></h2>
  11830. <p>Awaitables break the linear flow of code so that there is no longer a single entry point
  11831. where we should set the logcontext and a single exit point where we should remove it.</p>
  11832. <p>Consider the example above, where <code>do_request_handling</code> needs to do some
  11833. blocking operation, and returns an awaitable:</p>
  11834. <pre><code class="language-python">async def handle_request(request_id):
  11835. with context.LoggingContext() as request_context:
  11836. request_context.request = request_id
  11837. await do_request_handling()
  11838. logger.debug(&quot;finished&quot;)
  11839. </code></pre>
  11840. <p>In the above flow:</p>
  11841. <ul>
  11842. <li>The logcontext is set</li>
  11843. <li><code>do_request_handling</code> is called, and returns an awaitable</li>
  11844. <li><code>handle_request</code> awaits the awaitable</li>
  11845. <li>Execution of <code>handle_request</code> is suspended</li>
  11846. </ul>
  11847. <p>So we have stopped processing the request (and will probably go on to
  11848. start processing the next), without clearing the logcontext.</p>
  11849. <p>To circumvent this problem, synapse code assumes that, wherever you have
  11850. an awaitable, you will want to <code>await</code> it. To that end, whereever
  11851. functions return awaitables, we adopt the following conventions:</p>
  11852. <p><strong>Rules for functions returning awaitables:</strong></p>
  11853. <blockquote>
  11854. <ul>
  11855. <li>If the awaitable is already complete, the function returns with the
  11856. same logcontext it started with.</li>
  11857. <li>If the awaitable is incomplete, the function clears the logcontext
  11858. before returning; when the awaitable completes, it restores the
  11859. logcontext before running any callbacks.</li>
  11860. </ul>
  11861. </blockquote>
  11862. <p>That sounds complicated, but actually it means a lot of code (including
  11863. the example above) &quot;just works&quot;. There are two cases:</p>
  11864. <ul>
  11865. <li>
  11866. <p>If <code>do_request_handling</code> returns a completed awaitable, then the
  11867. logcontext will still be in place. In this case, execution will
  11868. continue immediately after the <code>await</code>; the &quot;finished&quot; line will
  11869. be logged against the right context, and the <code>with</code> block restores
  11870. the original context before we return to the caller.</p>
  11871. </li>
  11872. <li>
  11873. <p>If the returned awaitable is incomplete, <code>do_request_handling</code> clears
  11874. the logcontext before returning. The logcontext is therefore clear
  11875. when <code>handle_request</code> <code>await</code>s the awaitable.</p>
  11876. <p>Once <code>do_request_handling</code>'s awaitable completes, it will reinstate
  11877. the logcontext, before running the second half of <code>handle_request</code>,
  11878. so again the &quot;finished&quot; line will be logged against the right context,
  11879. and the <code>with</code> block restores the original context.</p>
  11880. </li>
  11881. </ul>
  11882. <p>As an aside, it's worth noting that <code>handle_request</code> follows our rules</p>
  11883. <ul>
  11884. <li>though that only matters if the caller has its own logcontext which it
  11885. cares about.</li>
  11886. </ul>
  11887. <p>The following sections describe pitfalls and helpful patterns when
  11888. implementing these rules.</p>
  11889. <h2 id="always-await-your-awaitables"><a class="header" href="#always-await-your-awaitables">Always await your awaitables</a></h2>
  11890. <p>Whenever you get an awaitable back from a function, you should <code>await</code> on
  11891. it as soon as possible. Do not pass go; do not do any logging; do not
  11892. call any other functions.</p>
  11893. <pre><code class="language-python">async def fun():
  11894. logger.debug(&quot;starting&quot;)
  11895. await do_some_stuff() # just like this
  11896. coro = more_stuff()
  11897. result = await coro # also fine, of course
  11898. return result
  11899. </code></pre>
  11900. <p>Provided this pattern is followed all the way back up to the callchain
  11901. to where the logcontext was set, this will make things work out ok:
  11902. provided <code>do_some_stuff</code> and <code>more_stuff</code> follow the rules above, then
  11903. so will <code>fun</code>.</p>
  11904. <p>It's all too easy to forget to <code>await</code>: for instance if we forgot that
  11905. <code>do_some_stuff</code> returned an awaitable, we might plough on regardless. This
  11906. leads to a mess; it will probably work itself out eventually, but not
  11907. before a load of stuff has been logged against the wrong context.
  11908. (Normally, other things will break, more obviously, if you forget to
  11909. <code>await</code>, so this tends not to be a major problem in practice.)</p>
  11910. <p>Of course sometimes you need to do something a bit fancier with your
  11911. awaitable - not all code follows the linear A-then-B-then-C pattern.
  11912. Notes on implementing more complex patterns are in later sections.</p>
  11913. <h2 id="where-you-create-a-new-awaitable-make-it-follow-the-rules"><a class="header" href="#where-you-create-a-new-awaitable-make-it-follow-the-rules">Where you create a new awaitable, make it follow the rules</a></h2>
  11914. <p>Most of the time, an awaitable comes from another synapse function.
  11915. Sometimes, though, we need to make up a new awaitable, or we get an awaitable
  11916. back from external code. We need to make it follow our rules.</p>
  11917. <p>The easy way to do it is by using <code>context.make_deferred_yieldable</code>. Suppose we want to implement
  11918. <code>sleep</code>, which returns a deferred which will run its callbacks after a
  11919. given number of seconds. That might look like:</p>
  11920. <pre><code class="language-python"># not a logcontext-rules-compliant function
  11921. def get_sleep_deferred(seconds):
  11922. d = defer.Deferred()
  11923. reactor.callLater(seconds, d.callback, None)
  11924. return d
  11925. </code></pre>
  11926. <p>That doesn't follow the rules, but we can fix it by calling it through
  11927. <code>context.make_deferred_yieldable</code>:</p>
  11928. <pre><code class="language-python">async def sleep(seconds):
  11929. return await context.make_deferred_yieldable(get_sleep_deferred(seconds))
  11930. </code></pre>
  11931. <h2 id="fire-and-forget"><a class="header" href="#fire-and-forget">Fire-and-forget</a></h2>
  11932. <p>Sometimes you want to fire off a chain of execution, but not wait for
  11933. its result. That might look a bit like this:</p>
  11934. <pre><code class="language-python">async def do_request_handling():
  11935. await foreground_operation()
  11936. # *don't* do this
  11937. background_operation()
  11938. logger.debug(&quot;Request handling complete&quot;)
  11939. async def background_operation():
  11940. await first_background_step()
  11941. logger.debug(&quot;Completed first step&quot;)
  11942. await second_background_step()
  11943. logger.debug(&quot;Completed second step&quot;)
  11944. </code></pre>
  11945. <p>The above code does a couple of steps in the background after
  11946. <code>do_request_handling</code> has finished. The log lines are still logged
  11947. against the <code>request_context</code> logcontext, which may or may not be
  11948. desirable. There are two big problems with the above, however. The first
  11949. problem is that, if <code>background_operation</code> returns an incomplete
  11950. awaitable, it will expect its caller to <code>await</code> immediately, so will have
  11951. cleared the logcontext. In this example, that means that 'Request
  11952. handling complete' will be logged without any context.</p>
  11953. <p>The second problem, which is potentially even worse, is that when the
  11954. awaitable returned by <code>background_operation</code> completes, it will restore
  11955. the original logcontext. There is nothing waiting on that awaitable, so
  11956. the logcontext will leak into the reactor and possibly get attached to
  11957. some arbitrary future operation.</p>
  11958. <p>There are two potential solutions to this.</p>
  11959. <p>One option is to surround the call to <code>background_operation</code> with a
  11960. <code>PreserveLoggingContext</code> call. That will reset the logcontext before
  11961. starting <code>background_operation</code> (so the context restored when the
  11962. deferred completes will be the empty logcontext), and will restore the
  11963. current logcontext before continuing the foreground process:</p>
  11964. <pre><code class="language-python">async def do_request_handling():
  11965. await foreground_operation()
  11966. # start background_operation off in the empty logcontext, to
  11967. # avoid leaking the current context into the reactor.
  11968. with PreserveLoggingContext():
  11969. background_operation()
  11970. # this will now be logged against the request context
  11971. logger.debug(&quot;Request handling complete&quot;)
  11972. </code></pre>
  11973. <p>Obviously that option means that the operations done in
  11974. <code>background_operation</code> would be not be logged against a logcontext
  11975. (though that might be fixed by setting a different logcontext via a
  11976. <code>with LoggingContext(...)</code> in <code>background_operation</code>).</p>
  11977. <p>The second option is to use <code>context.run_in_background</code>, which wraps a
  11978. function so that it doesn't reset the logcontext even when it returns
  11979. an incomplete awaitable, and adds a callback to the returned awaitable to
  11980. reset the logcontext. In other words, it turns a function that follows
  11981. the Synapse rules about logcontexts and awaitables into one which behaves
  11982. more like an external function --- the opposite operation to that
  11983. described in the previous section. It can be used like this:</p>
  11984. <pre><code class="language-python">async def do_request_handling():
  11985. await foreground_operation()
  11986. context.run_in_background(background_operation)
  11987. # this will now be logged against the request context
  11988. logger.debug(&quot;Request handling complete&quot;)
  11989. </code></pre>
  11990. <h2 id="passing-synapse-deferreds-into-third-party-functions"><a class="header" href="#passing-synapse-deferreds-into-third-party-functions">Passing synapse deferreds into third-party functions</a></h2>
  11991. <p>A typical example of this is where we want to collect together two or
  11992. more awaitables via <code>defer.gatherResults</code>:</p>
  11993. <pre><code class="language-python">a1 = operation1()
  11994. a2 = operation2()
  11995. a3 = defer.gatherResults([a1, a2])
  11996. </code></pre>
  11997. <p>This is really a variation of the fire-and-forget problem above, in that
  11998. we are firing off <code>a1</code> and <code>a2</code> without awaiting on them. The difference
  11999. is that we now have third-party code attached to their callbacks. Anyway
  12000. either technique given in the <a href="log_contexts.html#fire-and-forget">Fire-and-forget</a>
  12001. section will work.</p>
  12002. <p>Of course, the new awaitable returned by <code>gather</code> needs to be
  12003. wrapped in order to make it follow the logcontext rules before we can
  12004. yield it, as described in <a href="log_contexts.html#where-you-create-a-new-awaitable-make-it-follow-the-rules">Where you create a new awaitable, make it
  12005. follow the
  12006. rules</a>.</p>
  12007. <p>So, option one: reset the logcontext before starting the operations to
  12008. be gathered:</p>
  12009. <pre><code class="language-python">async def do_request_handling():
  12010. with PreserveLoggingContext():
  12011. a1 = operation1()
  12012. a2 = operation2()
  12013. result = await defer.gatherResults([a1, a2])
  12014. </code></pre>
  12015. <p>In this case particularly, though, option two, of using
  12016. <code>context.run_in_background</code> almost certainly makes more sense, so that
  12017. <code>operation1</code> and <code>operation2</code> are both logged against the original
  12018. logcontext. This looks like:</p>
  12019. <pre><code class="language-python">async def do_request_handling():
  12020. a1 = context.run_in_background(operation1)
  12021. a2 = context.run_in_background(operation2)
  12022. result = await make_deferred_yieldable(defer.gatherResults([a1, a2]))
  12023. </code></pre>
  12024. <h2 id="a-note-on-garbage-collection-of-awaitable-chains"><a class="header" href="#a-note-on-garbage-collection-of-awaitable-chains">A note on garbage-collection of awaitable chains</a></h2>
  12025. <p>It turns out that our logcontext rules do not play nicely with awaitable
  12026. chains which get orphaned and garbage-collected.</p>
  12027. <p>Imagine we have some code that looks like this:</p>
  12028. <pre><code class="language-python">listener_queue = []
  12029. def on_something_interesting():
  12030. for d in listener_queue:
  12031. d.callback(&quot;foo&quot;)
  12032. async def await_something_interesting():
  12033. new_awaitable = defer.Deferred()
  12034. listener_queue.append(new_awaitable)
  12035. with PreserveLoggingContext():
  12036. await new_awaitable
  12037. </code></pre>
  12038. <p>Obviously, the idea here is that we have a bunch of things which are
  12039. waiting for an event. (It's just an example of the problem here, but a
  12040. relatively common one.)</p>
  12041. <p>Now let's imagine two further things happen. First of all, whatever was
  12042. waiting for the interesting thing goes away. (Perhaps the request times
  12043. out, or something <em>even more</em> interesting happens.)</p>
  12044. <p>Secondly, let's suppose that we decide that the interesting thing is
  12045. never going to happen, and we reset the listener queue:</p>
  12046. <pre><code class="language-python">def reset_listener_queue():
  12047. listener_queue.clear()
  12048. </code></pre>
  12049. <p>So, both ends of the awaitable chain have now dropped their references,
  12050. and the awaitable chain is now orphaned, and will be garbage-collected at
  12051. some point. Note that <code>await_something_interesting</code> is a coroutine,
  12052. which Python implements as a generator function. When Python
  12053. garbage-collects generator functions, it gives them a chance to
  12054. clean up by making the <code>async</code> (or <code>yield</code>) raise a <code>GeneratorExit</code>
  12055. exception. In our case, that means that the <code>__exit__</code> handler of
  12056. <code>PreserveLoggingContext</code> will carefully restore the request context, but
  12057. there is now nothing waiting for its return, so the request context is
  12058. never cleared.</p>
  12059. <p>To reiterate, this problem only arises when <em>both</em> ends of a awaitable
  12060. chain are dropped. Dropping the the reference to an awaitable you're
  12061. supposed to be awaiting is bad practice, so this doesn't
  12062. actually happen too much. Unfortunately, when it does happen, it will
  12063. lead to leaked logcontexts which are incredibly hard to track down.</p>
  12064. <div style="break-before: page; page-break-before: always;"></div><h1 id="replication-architecture"><a class="header" href="#replication-architecture">Replication Architecture</a></h1>
  12065. <h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
  12066. <p>We'd like to be able to split some of the work that synapse does into
  12067. multiple python processes. In theory multiple synapse processes could
  12068. share a single postgresql database and we'd scale up by running more
  12069. synapse processes. However much of synapse assumes that only one process
  12070. is interacting with the database, both for assigning unique identifiers
  12071. when inserting into tables, notifying components about new updates, and
  12072. for invalidating its caches.</p>
  12073. <p>So running multiple copies of the current code isn't an option. One way
  12074. to run multiple processes would be to have a single writer process and
  12075. multiple reader processes connected to the same database. In order to do
  12076. this we'd need a way for the reader process to invalidate its in-memory
  12077. caches when an update happens on the writer. One way to do this is for
  12078. the writer to present an append-only log of updates which the readers
  12079. can consume to invalidate their caches and to push updates to listening
  12080. clients or pushers.</p>
  12081. <p>Synapse already stores much of its data as an append-only log so that it
  12082. can correctly respond to <code>/sync</code> requests so the amount of code changes
  12083. needed to expose the append-only log to the readers should be fairly
  12084. minimal.</p>
  12085. <h2 id="architecture"><a class="header" href="#architecture">Architecture</a></h2>
  12086. <h3 id="the-replication-protocol"><a class="header" href="#the-replication-protocol">The Replication Protocol</a></h3>
  12087. <p>See <a href="tcp_replication.html">the TCP replication documentation</a>.</p>
  12088. <h3 id="the-slaved-datastore"><a class="header" href="#the-slaved-datastore">The Slaved DataStore</a></h3>
  12089. <p>There are read-only version of the synapse storage layer in
  12090. <code>synapse/replication/slave/storage</code> that use the response of the
  12091. replication API to invalidate their caches.</p>
  12092. <div style="break-before: page; page-break-before: always;"></div><h1 id="tcp-replication"><a class="header" href="#tcp-replication">TCP Replication</a></h1>
  12093. <h2 id="motivation-1"><a class="header" href="#motivation-1">Motivation</a></h2>
  12094. <p>Previously the workers used an HTTP long poll mechanism to get updates
  12095. from the master, which had the problem of causing a lot of duplicate
  12096. work on the server. This TCP protocol replaces those APIs with the aim
  12097. of increased efficiency.</p>
  12098. <h2 id="overview-3"><a class="header" href="#overview-3">Overview</a></h2>
  12099. <p>The protocol is based on fire and forget, line based commands. An
  12100. example flow would be (where '&gt;' indicates master to worker and
  12101. '&lt;' worker to master flows):</p>
  12102. <pre><code>&gt; SERVER example.com
  12103. &lt; REPLICATE
  12104. &gt; POSITION events master 53 53
  12105. &gt; RDATA events master 54 [&quot;$foo1:bar.com&quot;, ...]
  12106. &gt; RDATA events master 55 [&quot;$foo4:bar.com&quot;, ...]
  12107. </code></pre>
  12108. <p>The example shows the server accepting a new connection and sending its identity
  12109. with the <code>SERVER</code> command, followed by the client server to respond with the
  12110. position of all streams. The server then periodically sends <code>RDATA</code> commands
  12111. which have the format <code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row&gt;</code>, where
  12112. the format of <code>&lt;row&gt;</code> is defined by the individual streams. The
  12113. <code>&lt;instance_name&gt;</code> is the name of the Synapse process that generated the data
  12114. (usually &quot;master&quot;).</p>
  12115. <p>Error reporting happens by either the client or server sending an ERROR
  12116. command, and usually the connection will be closed.</p>
  12117. <p>Since the protocol is a simple line based, its possible to manually
  12118. connect to the server using a tool like netcat. A few things should be
  12119. noted when manually using the protocol:</p>
  12120. <ul>
  12121. <li>The federation stream is only available if federation sending has
  12122. been disabled on the main process.</li>
  12123. <li>The server will only time connections out that have sent a <code>PING</code>
  12124. command. If a ping is sent then the connection will be closed if no
  12125. further commands are receieved within 15s. Both the client and
  12126. server protocol implementations will send an initial PING on
  12127. connection and ensure at least one command every 5s is sent (not
  12128. necessarily <code>PING</code>).</li>
  12129. <li><code>RDATA</code> commands <em>usually</em> include a numeric token, however if the
  12130. stream has multiple rows to replicate per token the server will send
  12131. multiple <code>RDATA</code> commands, with all but the last having a token of
  12132. <code>batch</code>. See the documentation on <code>commands.RdataCommand</code> for
  12133. further details.</li>
  12134. </ul>
  12135. <h2 id="architecture-1"><a class="header" href="#architecture-1">Architecture</a></h2>
  12136. <p>The basic structure of the protocol is line based, where the initial
  12137. word of each line specifies the command. The rest of the line is parsed
  12138. based on the command. For example, the RDATA command is defined as:</p>
  12139. <pre><code>RDATA &lt;stream_name&gt; &lt;instance_name&gt; &lt;token&gt; &lt;row_json&gt;
  12140. </code></pre>
  12141. <p>(Note that &lt;row_json&gt; may contains spaces, but cannot contain
  12142. newlines.)</p>
  12143. <p>Blank lines are ignored.</p>
  12144. <h3 id="keep-alives"><a class="header" href="#keep-alives">Keep alives</a></h3>
  12145. <p>Both sides are expected to send at least one command every 5s or so, and
  12146. should send a <code>PING</code> command if necessary. If either side do not receive
  12147. a command within e.g. 15s then the connection should be closed.</p>
  12148. <p>Because the server may be connected to manually using e.g. netcat, the
  12149. timeouts aren't enabled until an initial <code>PING</code> command is seen. Both
  12150. the client and server implementations below send a <code>PING</code> command
  12151. immediately on connection to ensure the timeouts are enabled.</p>
  12152. <p>This ensures that both sides can quickly realize if the tcp connection
  12153. has gone and handle the situation appropriately.</p>
  12154. <h3 id="start-up"><a class="header" href="#start-up">Start up</a></h3>
  12155. <p>When a new connection is made, the server:</p>
  12156. <ul>
  12157. <li>Sends a <code>SERVER</code> command, which includes the identity of the server,
  12158. allowing the client to detect if its connected to the expected
  12159. server</li>
  12160. <li>Sends a <code>PING</code> command as above, to enable the client to time out
  12161. connections promptly.</li>
  12162. </ul>
  12163. <p>The client:</p>
  12164. <ul>
  12165. <li>Sends a <code>NAME</code> command, allowing the server to associate a human
  12166. friendly name with the connection. This is optional.</li>
  12167. <li>Sends a <code>PING</code> as above</li>
  12168. <li>Sends a <code>REPLICATE</code> to get the current position of all streams.</li>
  12169. <li>On receipt of a <code>SERVER</code> command, checks that the server name
  12170. matches the expected server name.</li>
  12171. </ul>
  12172. <h3 id="error-handling"><a class="header" href="#error-handling">Error handling</a></h3>
  12173. <p>If either side detects an error it can send an <code>ERROR</code> command and close
  12174. the connection.</p>
  12175. <p>If the client side loses the connection to the server it should
  12176. reconnect, following the steps above.</p>
  12177. <h3 id="congestion"><a class="header" href="#congestion">Congestion</a></h3>
  12178. <p>If the server sends messages faster than the client can consume them the
  12179. server will first buffer a (fairly large) number of commands and then
  12180. disconnect the client. This ensures that we don't queue up an unbounded
  12181. number of commands in memory and gives us a potential oppurtunity to
  12182. squawk loudly. When/if the client recovers it can reconnect to the
  12183. server and ask for missed messages.</p>
  12184. <h3 id="reliability"><a class="header" href="#reliability">Reliability</a></h3>
  12185. <p>In general the replication stream should be considered an unreliable
  12186. transport since e.g. commands are not resent if the connection
  12187. disappears.</p>
  12188. <p>The exception to that are the replication streams, i.e. RDATA commands,
  12189. since these include tokens which can be used to restart the stream on
  12190. connection errors.</p>
  12191. <p>The client should keep track of the token in the last RDATA command
  12192. received for each stream so that on reconneciton it can start streaming
  12193. from the correct place. Note: not all RDATA have valid tokens due to
  12194. batching. See <code>RdataCommand</code> for more details.</p>
  12195. <h3 id="example-4"><a class="header" href="#example-4">Example</a></h3>
  12196. <p>An example iteraction is shown below. Each line is prefixed with '&gt;'
  12197. or '&lt;' to indicate which side is sending, these are <em>not</em> included on
  12198. the wire:</p>
  12199. <pre><code>* connection established *
  12200. &gt; SERVER localhost:8823
  12201. &gt; PING 1490197665618
  12202. &lt; NAME synapse.app.appservice
  12203. &lt; PING 1490197665618
  12204. &lt; REPLICATE
  12205. &gt; POSITION events master 1 1
  12206. &gt; POSITION backfill master 1 1
  12207. &gt; POSITION caches master 1 1
  12208. &gt; RDATA caches master 2 [&quot;get_user_by_id&quot;,[&quot;@01register-user:localhost:8823&quot;],1490197670513]
  12209. &gt; RDATA events master 14 [&quot;$149019767112vOHxz:localhost:8823&quot;,
  12210. &quot;!AFDCvgApUmpdfVjIXm:localhost:8823&quot;,&quot;m.room.guest_access&quot;,&quot;&quot;,null]
  12211. &lt; PING 1490197675618
  12212. &gt; ERROR server stopping
  12213. * connection closed by server *
  12214. </code></pre>
  12215. <p>The <code>POSITION</code> command sent by the server is used to set the clients
  12216. position without needing to send data with the <code>RDATA</code> command.</p>
  12217. <p>An example of a batched set of <code>RDATA</code> is:</p>
  12218. <pre><code>&gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test:localhost:8823&quot;],1490197670513]
  12219. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test2:localhost:8823&quot;],1490197670513]
  12220. &gt; RDATA caches master batch [&quot;get_user_by_id&quot;,[&quot;@test3:localhost:8823&quot;],1490197670513]
  12221. &gt; RDATA caches master 54 [&quot;get_user_by_id&quot;,[&quot;@test4:localhost:8823&quot;],1490197670513]
  12222. </code></pre>
  12223. <p>In this case the client shouldn't advance their caches token until it
  12224. sees the the last <code>RDATA</code>.</p>
  12225. <h3 id="list-of-commands"><a class="header" href="#list-of-commands">List of commands</a></h3>
  12226. <p>The list of valid commands, with which side can send it: server (S) or
  12227. client (C):</p>
  12228. <h4 id="server-s"><a class="header" href="#server-s">SERVER (S)</a></h4>
  12229. <p>Sent at the start to identify which server the client is talking to</p>
  12230. <h4 id="rdata-s"><a class="header" href="#rdata-s">RDATA (S)</a></h4>
  12231. <p>A single update in a stream</p>
  12232. <h4 id="position-s"><a class="header" href="#position-s">POSITION (S)</a></h4>
  12233. <p>On receipt of a POSITION command clients should check if they have missed any
  12234. updates, and if so then fetch them out of band. Sent in response to a
  12235. REPLICATE command (but can happen at any time).</p>
  12236. <p>The POSITION command includes the source of the stream. Currently all streams
  12237. are written by a single process (usually &quot;master&quot;). If fetching missing
  12238. updates via HTTP API, rather than via the DB, then processes should make the
  12239. request to the appropriate process.</p>
  12240. <p>Two positions are included, the &quot;new&quot; position and the last position sent respectively.
  12241. This allows servers to tell instances that the positions have advanced but no
  12242. data has been written, without clients needlessly checking to see if they
  12243. have missed any updates.</p>
  12244. <h4 id="error-s-c"><a class="header" href="#error-s-c">ERROR (S, C)</a></h4>
  12245. <p>There was an error</p>
  12246. <h4 id="ping-s-c"><a class="header" href="#ping-s-c">PING (S, C)</a></h4>
  12247. <p>Sent periodically to ensure the connection is still alive</p>
  12248. <h4 id="name-c"><a class="header" href="#name-c">NAME (C)</a></h4>
  12249. <p>Sent at the start by client to inform the server who they are</p>
  12250. <h4 id="replicate-c"><a class="header" href="#replicate-c">REPLICATE (C)</a></h4>
  12251. <p>Asks the server for the current position of all streams.</p>
  12252. <h4 id="user_sync-c"><a class="header" href="#user_sync-c">USER_SYNC (C)</a></h4>
  12253. <p>A user has started or stopped syncing on this process.</p>
  12254. <h4 id="clear_user_sync-c"><a class="header" href="#clear_user_sync-c">CLEAR_USER_SYNC (C)</a></h4>
  12255. <p>The server should clear all associated user sync data from the worker.</p>
  12256. <p>This is used when a worker is shutting down.</p>
  12257. <h4 id="federation_ack-c"><a class="header" href="#federation_ack-c">FEDERATION_ACK (C)</a></h4>
  12258. <p>Acknowledge receipt of some federation data</p>
  12259. <h3 id="remote_server_up-s-c"><a class="header" href="#remote_server_up-s-c">REMOTE_SERVER_UP (S, C)</a></h3>
  12260. <p>Inform other processes that a remote server may have come back online.</p>
  12261. <p>See <code>synapse/replication/tcp/commands.py</code> for a detailed description and
  12262. the format of each command.</p>
  12263. <h3 id="cache-invalidation-stream"><a class="header" href="#cache-invalidation-stream">Cache Invalidation Stream</a></h3>
  12264. <p>The cache invalidation stream is used to inform workers when they need
  12265. to invalidate any of their caches in the data store. This is done by
  12266. streaming all cache invalidations done on master down to the workers,
  12267. assuming that any caches on the workers also exist on the master.</p>
  12268. <p>Each individual cache invalidation results in a row being sent down
  12269. replication, which includes the cache name (the name of the function)
  12270. and they key to invalidate. For example:</p>
  12271. <pre><code>&gt; RDATA caches master 550953771 [&quot;get_user_by_id&quot;, [&quot;@bob:example.com&quot;], 1550574873251]
  12272. </code></pre>
  12273. <p>Alternatively, an entire cache can be invalidated by sending down a <code>null</code>
  12274. instead of the key. For example:</p>
  12275. <pre><code>&gt; RDATA caches master 550953772 [&quot;get_user_by_id&quot;, null, 1550574873252]
  12276. </code></pre>
  12277. <p>However, there are times when a number of caches need to be invalidated
  12278. at the same time with the same key. To reduce traffic we batch those
  12279. invalidations into a single poke by defining a special cache name that
  12280. workers understand to mean to expand to invalidate the correct caches.</p>
  12281. <p>Currently the special cache names are declared in
  12282. <code>synapse/storage/_base.py</code> and are:</p>
  12283. <ol>
  12284. <li><code>cs_cache_fake</code> ─ invalidates caches that depend on the current
  12285. state</li>
  12286. </ol>
  12287. <div style="break-before: page; page-break-before: always;"></div><h1 id="internal-documentation"><a class="header" href="#internal-documentation">Internal Documentation</a></h1>
  12288. <p>This section covers implementation documentation for various parts of Synapse.</p>
  12289. <p>If a developer is planning to make a change to a feature of Synapse, it can be useful for
  12290. general documentation of how that feature is implemented to be available. This saves the
  12291. developer time in place of needing to understand how the feature works by reading the
  12292. code.</p>
  12293. <p>Documentation that would be more useful for the perspective of a system administrator,
  12294. rather than a developer who's intending to change to code, should instead be placed
  12295. under the Usage section of the documentation.</p>
  12296. <div style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-saml-as-a-developer-without-a-server"><a class="header" href="#how-to-test-saml-as-a-developer-without-a-server">How to test SAML as a developer without a server</a></h1>
  12297. <p>https://capriza.github.io/samling/samling.html (https://github.com/capriza/samling) is a great
  12298. resource for being able to tinker with the SAML options within Synapse without needing to
  12299. deploy and configure a complicated software stack.</p>
  12300. <p>To make Synapse (and therefore Riot) use it:</p>
  12301. <ol>
  12302. <li>Use the samling.html URL above or deploy your own and visit the IdP Metadata tab.</li>
  12303. <li>Copy the XML to your clipboard.</li>
  12304. <li>On your Synapse server, create a new file <code>samling.xml</code> next to your <code>homeserver.yaml</code> with
  12305. the XML from step 2 as the contents.</li>
  12306. <li>Edit your <code>homeserver.yaml</code> to include:
  12307. <pre><code class="language-yaml">saml2_config:
  12308. sp_config:
  12309. allow_unknown_attributes: true # Works around a bug with AVA Hashes: https://github.com/IdentityPython/pysaml2/issues/388
  12310. metadata:
  12311. local: [&quot;samling.xml&quot;]
  12312. </code></pre>
  12313. </li>
  12314. <li>Ensure that your <code>homeserver.yaml</code> has a setting for <code>public_baseurl</code>:
  12315. <pre><code class="language-yaml">public_baseurl: http://localhost:8080/
  12316. </code></pre>
  12317. </li>
  12318. <li>Run <code>apt-get install xmlsec1</code> and <code>pip install --upgrade --force 'pysaml2&gt;=4.5.0'</code> to ensure
  12319. the dependencies are installed and ready to go.</li>
  12320. <li>Restart Synapse.</li>
  12321. </ol>
  12322. <p>Then in Riot:</p>
  12323. <ol>
  12324. <li>Visit the login page with a Riot pointing at your homeserver.</li>
  12325. <li>Click the Single Sign-On button.</li>
  12326. <li>On the samling page, enter a Name Identifier and add a SAML Attribute for <code>uid=your_localpart</code>.
  12327. The response must also be signed.</li>
  12328. <li>Click &quot;Next&quot;.</li>
  12329. <li>Click &quot;Post Response&quot; (change nothing).</li>
  12330. <li>You should be logged in.</li>
  12331. </ol>
  12332. <p>If you try and repeat this process, you may be automatically logged in using the information you
  12333. gave previously. To fix this, open your developer console (<code>F12</code> or <code>Ctrl+Shift+I</code>) while on the
  12334. samling page and clear the site data. In Chrome, this will be a button on the Application tab.</p>
  12335. <div style="break-before: page; page-break-before: always;"></div><h1 id="how-to-test-cas-as-a-developer-without-a-server"><a class="header" href="#how-to-test-cas-as-a-developer-without-a-server">How to test CAS as a developer without a server</a></h1>
  12336. <p>The <a href="https://github.com/jbittel/django-mama-cas">django-mama-cas</a> project is an
  12337. easy to run CAS implementation built on top of Django.</p>
  12338. <h2 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h2>
  12339. <ol>
  12340. <li>Create a new virtualenv: <code>python3 -m venv &lt;your virtualenv&gt;</code></li>
  12341. <li>Activate your virtualenv: <code>source /path/to/your/virtualenv/bin/activate</code></li>
  12342. <li>Install Django and django-mama-cas:
  12343. <pre><code>python -m pip install &quot;django&lt;3&quot; &quot;django-mama-cas==2.4.0&quot;
  12344. </code></pre>
  12345. </li>
  12346. <li>Create a Django project in the current directory:
  12347. <pre><code>django-admin startproject cas_test .
  12348. </code></pre>
  12349. </li>
  12350. <li>Follow the <a href="https://django-mama-cas.readthedocs.io/en/latest/installation.html#configuring">install directions</a> for django-mama-cas</li>
  12351. <li>Setup the SQLite database: <code>python manage.py migrate</code></li>
  12352. <li>Create a user:
  12353. <pre><code>python manage.py createsuperuser
  12354. </code></pre>
  12355. <ol>
  12356. <li>Use whatever you want as the username and password.</li>
  12357. <li>Leave the other fields blank.</li>
  12358. </ol>
  12359. </li>
  12360. <li>Use the built-in Django test server to serve the CAS endpoints on port 8000:
  12361. <pre><code>python manage.py runserver
  12362. </code></pre>
  12363. </li>
  12364. </ol>
  12365. <p>You should now have a Django project configured to serve CAS authentication with
  12366. a single user created.</p>
  12367. <h2 id="configure-synapse-and-element-to-use-cas"><a class="header" href="#configure-synapse-and-element-to-use-cas">Configure Synapse (and Element) to use CAS</a></h2>
  12368. <ol>
  12369. <li>Modify your <code>homeserver.yaml</code> to enable CAS and point it to your locally
  12370. running Django test server:
  12371. <pre><code class="language-yaml">cas_config:
  12372. enabled: true
  12373. server_url: &quot;http://localhost:8000&quot;
  12374. service_url: &quot;http://localhost:8081&quot;
  12375. #displayname_attribute: name
  12376. #required_attributes:
  12377. # name: value
  12378. </code></pre>
  12379. </li>
  12380. <li>Restart Synapse.</li>
  12381. </ol>
  12382. <p>Note that the above configuration assumes the homeserver is running on port 8081
  12383. and that the CAS server is on port 8000, both on localhost.</p>
  12384. <h2 id="testing-the-configuration"><a class="header" href="#testing-the-configuration">Testing the configuration</a></h2>
  12385. <p>Then in Element:</p>
  12386. <ol>
  12387. <li>Visit the login page with a Element pointing at your homeserver.</li>
  12388. <li>Click the Single Sign-On button.</li>
  12389. <li>Login using the credentials created with <code>createsuperuser</code>.</li>
  12390. <li>You should be logged in.</li>
  12391. </ol>
  12392. <p>If you want to repeat this process you'll need to manually logout first:</p>
  12393. <ol>
  12394. <li>http://localhost:8000/admin/</li>
  12395. <li>Click &quot;logout&quot; in the top right.</li>
  12396. </ol>
  12397. <div style="break-before: page; page-break-before: always;"></div><h1 id="room-dag-concepts"><a class="header" href="#room-dag-concepts">Room DAG concepts</a></h1>
  12398. <h2 id="edges"><a class="header" href="#edges">Edges</a></h2>
  12399. <p>The word &quot;edge&quot; comes from graph theory lingo. An edge is just a connection
  12400. between two events. In Synapse, we connect events by specifying their
  12401. <code>prev_events</code>. A subsequent event points back at a previous event.</p>
  12402. <pre><code>A (oldest) &lt;---- B &lt;---- C (most recent)
  12403. </code></pre>
  12404. <h2 id="depth-and-stream-ordering"><a class="header" href="#depth-and-stream-ordering">Depth and stream ordering</a></h2>
  12405. <p>Events are normally sorted by <code>(topological_ordering, stream_ordering)</code> where
  12406. <code>topological_ordering</code> is just <code>depth</code>. In other words, we first sort by <code>depth</code>
  12407. and then tie-break based on <code>stream_ordering</code>. <code>depth</code> is incremented as new
  12408. messages are added to the DAG. Normally, <code>stream_ordering</code> is an auto
  12409. incrementing integer, but backfilled events start with <code>stream_ordering=-1</code> and decrement.</p>
  12410. <hr />
  12411. <ul>
  12412. <li><code>/sync</code> returns things in the order they arrive at the server (<code>stream_ordering</code>).</li>
  12413. <li><code>/messages</code> (and <code>/backfill</code> in the federation API) return them in the order determined by the event graph <code>(topological_ordering, stream_ordering)</code>.</li>
  12414. </ul>
  12415. <p>The general idea is that, if you're following a room in real-time (i.e.
  12416. <code>/sync</code>), you probably want to see the messages as they arrive at your server,
  12417. rather than skipping any that arrived late; whereas if you're looking at a
  12418. historical section of timeline (i.e. <code>/messages</code>), you want to see the best
  12419. representation of the state of the room as others were seeing it at the time.</p>
  12420. <h2 id="forward-extremity"><a class="header" href="#forward-extremity">Forward extremity</a></h2>
  12421. <p>Most-recent-in-time events in the DAG which are not referenced by any other events' <code>prev_events</code> yet.</p>
  12422. <p>The forward extremities of a room are used as the <code>prev_events</code> when the next event is sent.</p>
  12423. <h2 id="backwards-extremity"><a class="header" href="#backwards-extremity">Backwards extremity</a></h2>
  12424. <p>The current marker of where we have backfilled up to and will generally be the
  12425. oldest-in-time events we know of in the DAG.</p>
  12426. <p>This is an event where we haven't fetched all of the <code>prev_events</code> for.</p>
  12427. <p>Once we have fetched all of its <code>prev_events</code>, it's unmarked as a backwards
  12428. extremity (although we may have formed new backwards extremities from the prev
  12429. events during the backfilling process).</p>
  12430. <h2 id="outliers"><a class="header" href="#outliers">Outliers</a></h2>
  12431. <p>We mark an event as an <code>outlier</code> when we haven't figured out the state for the
  12432. room at that point in the DAG yet.</p>
  12433. <p>We won't <em>necessarily</em> have the <code>prev_events</code> of an <code>outlier</code> in the database,
  12434. but it's entirely possible that we <em>might</em>. The status of whether we have all of
  12435. the <code>prev_events</code> is marked as a <a href="development/room-dag-concepts.html#backwards-extremity">backwards extremity</a>.</p>
  12436. <p>For example, when we fetch the event auth chain or state for a given event, we
  12437. mark all of those claimed auth events as outliers because we haven't done the
  12438. state calculation ourself.</p>
  12439. <h2 id="state-groups"><a class="header" href="#state-groups">State groups</a></h2>
  12440. <p>For every non-outlier event we need to know the state at that event. Instead of
  12441. storing the full state for each event in the DB (i.e. a <code>event_id -&gt; state</code>
  12442. mapping), which is <em>very</em> space inefficient when state doesn't change, we
  12443. instead assign each different set of state a &quot;state group&quot; and then have
  12444. mappings of <code>event_id -&gt; state_group</code> and <code>state_group -&gt; state</code>.</p>
  12445. <h3 id="stage-group-edges"><a class="header" href="#stage-group-edges">Stage group edges</a></h3>
  12446. <p>TODO: <code>state_group_edges</code> is a further optimization...
  12447. notes from @Azrenbeth, https://pastebin.com/seUGVGeT</p>
  12448. <div style="break-before: page; page-break-before: always;"></div><h1 id="auth-chain-difference-algorithm"><a class="header" href="#auth-chain-difference-algorithm">Auth Chain Difference Algorithm</a></h1>
  12449. <p>The auth chain difference algorithm is used by V2 state resolution, where a
  12450. naive implementation can be a significant source of CPU and DB usage.</p>
  12451. <h3 id="definitions"><a class="header" href="#definitions">Definitions</a></h3>
  12452. <p>A <em>state set</em> is a set of state events; e.g. the input of a state resolution
  12453. algorithm is a collection of state sets.</p>
  12454. <p>The <em>auth chain</em> of a set of events are all the events' auth events and <em>their</em>
  12455. auth events, recursively (i.e. the events reachable by walking the graph induced
  12456. by an event's auth events links).</p>
  12457. <p>The <em>auth chain difference</em> of a collection of state sets is the union minus the
  12458. intersection of the sets of auth chains corresponding to the state sets, i.e an
  12459. event is in the auth chain difference if it is reachable by walking the auth
  12460. event graph from at least one of the state sets but not from <em>all</em> of the state
  12461. sets.</p>
  12462. <h2 id="breadth-first-walk-algorithm"><a class="header" href="#breadth-first-walk-algorithm">Breadth First Walk Algorithm</a></h2>
  12463. <p>A way of calculating the auth chain difference without calculating the full auth
  12464. chains for each state set is to do a parallel breadth first walk (ordered by
  12465. depth) of each state set's auth chain. By tracking which events are reachable
  12466. from each state set we can finish early if every pending event is reachable from
  12467. every state set.</p>
  12468. <p>This can work well for state sets that have a small auth chain difference, but
  12469. can be very inefficient for larger differences. However, this algorithm is still
  12470. used if we don't have a chain cover index for the room (e.g. because we're in
  12471. the process of indexing it).</p>
  12472. <h2 id="chain-cover-index"><a class="header" href="#chain-cover-index">Chain Cover Index</a></h2>
  12473. <p>Synapse computes auth chain differences by pre-computing a &quot;chain cover&quot; index
  12474. for the auth chain in a room, allowing efficient reachability queries like &quot;is
  12475. event A in the auth chain of event B&quot;. This is done by assigning every event a
  12476. <em>chain ID</em> and <em>sequence number</em> (e.g. <code>(5,3)</code>), and having a map of <em>links</em>
  12477. between chains (e.g. <code>(5,3) -&gt; (2,4)</code>) such that A is reachable by B (i.e. <code>A</code>
  12478. is in the auth chain of <code>B</code>) if and only if either:</p>
  12479. <ol>
  12480. <li>A and B have the same chain ID and <code>A</code>'s sequence number is less than <code>B</code>'s
  12481. sequence number; or</li>
  12482. <li>there is a link <code>L</code> between <code>B</code>'s chain ID and <code>A</code>'s chain ID such that
  12483. <code>L.start_seq_no</code> &lt;= <code>B.seq_no</code> and <code>A.seq_no</code> &lt;= <code>L.end_seq_no</code>.</li>
  12484. </ol>
  12485. <p>There are actually two potential implementations, one where we store links from
  12486. each chain to every other reachable chain (the transitive closure of the links
  12487. graph), and one where we remove redundant links (the transitive reduction of the
  12488. links graph) e.g. if we have chains <code>C3 -&gt; C2 -&gt; C1</code> then the link <code>C3 -&gt; C1</code>
  12489. would not be stored. Synapse uses the former implementations so that it doesn't
  12490. need to recurse to test reachability between chains.</p>
  12491. <h3 id="example-5"><a class="header" href="#example-5">Example</a></h3>
  12492. <p>An example auth graph would look like the following, where chains have been
  12493. formed based on type/state_key and are denoted by colour and are labelled with
  12494. <code>(chain ID, sequence number)</code>. Links are denoted by the arrows (links in grey
  12495. are those that would be remove in the second implementation described above).</p>
  12496. <p><img src="auth_chain_diff.dot.png" alt="Example" /></p>
  12497. <p>Note that we don't include all links between events and their auth events, as
  12498. most of those links would be redundant. For example, all events point to the
  12499. create event, but each chain only needs the one link from it's base to the
  12500. create event.</p>
  12501. <h2 id="using-the-index"><a class="header" href="#using-the-index">Using the Index</a></h2>
  12502. <p>This index can be used to calculate the auth chain difference of the state sets
  12503. by looking at the chain ID and sequence numbers reachable from each state set:</p>
  12504. <ol>
  12505. <li>For every state set lookup the chain ID/sequence numbers of each state event</li>
  12506. <li>Use the index to find all chains and the maximum sequence number reachable
  12507. from each state set.</li>
  12508. <li>The auth chain difference is then all events in each chain that have sequence
  12509. numbers between the maximum sequence number reachable from <em>any</em> state set and
  12510. the minimum reachable by <em>all</em> state sets (if any).</li>
  12511. </ol>
  12512. <p>Note that steps 2 is effectively calculating the auth chain for each state set
  12513. (in terms of chain IDs and sequence numbers), and step 3 is calculating the
  12514. difference between the union and intersection of the auth chains.</p>
  12515. <h3 id="worked-example"><a class="header" href="#worked-example">Worked Example</a></h3>
  12516. <p>For example, given the above graph, we can calculate the difference between
  12517. state sets consisting of:</p>
  12518. <ol>
  12519. <li><code>S1</code>: Alice's invite <code>(4,1)</code> and Bob's second join <code>(2,2)</code>; and</li>
  12520. <li><code>S2</code>: Alice's second join <code>(4,3)</code> and Bob's first join <code>(2,1)</code>.</li>
  12521. </ol>
  12522. <p>Using the index we see that the following auth chains are reachable from each
  12523. state set:</p>
  12524. <ol>
  12525. <li><code>S1</code>: <code>(1,1)</code>, <code>(2,2)</code>, <code>(3,1)</code> &amp; <code>(4,1)</code></li>
  12526. <li><code>S2</code>: <code>(1,1)</code>, <code>(2,1)</code>, <code>(3,2)</code> &amp; <code>(4,3)</code></li>
  12527. </ol>
  12528. <p>And so, for each the ranges that are in the auth chain difference:</p>
  12529. <ol>
  12530. <li>Chain 1: None, (since everything can reach the create event).</li>
  12531. <li>Chain 2: The range <code>(1, 2]</code> (i.e. just <code>2</code>), as <code>1</code> is reachable by all state
  12532. sets and the maximum reachable is <code>2</code> (corresponding to Bob's second join).</li>
  12533. <li>Chain 3: Similarly the range <code>(1, 2]</code> (corresponding to the second power
  12534. level).</li>
  12535. <li>Chain 4: The range <code>(1, 3]</code> (corresponding to both of Alice's joins).</li>
  12536. </ol>
  12537. <p>So the final result is: Bob's second join <code>(2,2)</code>, the second power level
  12538. <code>(3,2)</code> and both of Alice's joins <code>(4,2)</code> &amp; <code>(4,3)</code>.</p>
  12539. <div style="break-before: page; page-break-before: always;"></div><h1 id="media-repository"><a class="header" href="#media-repository">Media Repository</a></h1>
  12540. <p><em>Synapse implementation-specific details for the media repository</em></p>
  12541. <p>The media repository is where attachments and avatar photos are stored.
  12542. It stores attachment content and thumbnails for media uploaded by local users.
  12543. It caches attachment content and thumbnails for media uploaded by remote users.</p>
  12544. <h2 id="storage"><a class="header" href="#storage">Storage</a></h2>
  12545. <p>Each item of media is assigned a <code>media_id</code> when it is uploaded.
  12546. The <code>media_id</code> is a randomly chosen, URL safe 24 character string.</p>
  12547. <p>Metadata such as the MIME type, upload time and length are stored in the
  12548. sqlite3 database indexed by <code>media_id</code>.</p>
  12549. <p>Content is stored on the filesystem under a <code>&quot;local_content&quot;</code> directory.</p>
  12550. <p>Thumbnails are stored under a <code>&quot;local_thumbnails&quot;</code> directory.</p>
  12551. <p>The item with <code>media_id</code> <code>&quot;aabbccccccccdddddddddddd&quot;</code> is stored under
  12552. <code>&quot;local_content/aa/bb/ccccccccdddddddddddd&quot;</code>. Its thumbnail with width
  12553. <code>128</code> and height <code>96</code> and type <code>&quot;image/jpeg&quot;</code> is stored under
  12554. <code>&quot;local_thumbnails/aa/bb/ccccccccdddddddddddd/128-96-image-jpeg&quot;</code></p>
  12555. <p>Remote content is cached under <code>&quot;remote_content&quot;</code> directory. Each item of
  12556. remote content is assigned a local <code>&quot;filesystem_id&quot;</code> to ensure that the
  12557. directory structure <code>&quot;remote_content/server_name/aa/bb/ccccccccdddddddddddd&quot;</code>
  12558. is appropriate. Thumbnails for remote content are stored under
  12559. <code>&quot;remote_thumbnails/server_name/...&quot;</code></p>
  12560. <div style="break-before: page; page-break-before: always;"></div><h1 id="room-and-user-statistics"><a class="header" href="#room-and-user-statistics">Room and User Statistics</a></h1>
  12561. <p>Synapse maintains room and user statistics in various tables. These can be used
  12562. for administrative purposes but are also used when generating the public room
  12563. directory.</p>
  12564. <h1 id="synapse-developer-documentation"><a class="header" href="#synapse-developer-documentation">Synapse Developer Documentation</a></h1>
  12565. <h2 id="high-level-concepts"><a class="header" href="#high-level-concepts">High-Level Concepts</a></h2>
  12566. <h3 id="definitions-1"><a class="header" href="#definitions-1">Definitions</a></h3>
  12567. <ul>
  12568. <li><strong>subject</strong>: Something we are tracking stats about – currently a room or user.</li>
  12569. <li><strong>current row</strong>: An entry for a subject in the appropriate current statistics
  12570. table. Each subject can have only one.</li>
  12571. </ul>
  12572. <h3 id="overview-4"><a class="header" href="#overview-4">Overview</a></h3>
  12573. <p>Stats correspond to the present values. Current rows contain the most up-to-date
  12574. statistics for a room. Each subject can only have one entry.</p>
  12575. <div style="break-before: page; page-break-before: always;"></div><h1 id="deprecation-policy-for-platform-dependencies"><a class="header" href="#deprecation-policy-for-platform-dependencies">Deprecation Policy for Platform Dependencies</a></h1>
  12576. <p>Synapse has a number of platform dependencies, including Python and PostgreSQL.
  12577. This document outlines the policy towards which versions we support, and when we
  12578. drop support for versions in the future.</p>
  12579. <h2 id="policy"><a class="header" href="#policy">Policy</a></h2>
  12580. <p>Synapse follows the upstream support life cycles for Python and PostgreSQL,
  12581. i.e. when a version reaches End of Life Synapse will withdraw support for that
  12582. version in future releases.</p>
  12583. <p>Details on the upstream support life cycles for Python and PostgreSQL are
  12584. documented at https://endoflife.date/python and
  12585. https://endoflife.date/postgresql.</p>
  12586. <h2 id="context"><a class="header" href="#context">Context</a></h2>
  12587. <p>It is important for system admins to have a clear understanding of the platform
  12588. requirements of Synapse and its deprecation policies so that they can
  12589. effectively plan upgrading their infrastructure ahead of time. This is
  12590. especially important in contexts where upgrading the infrastructure requires
  12591. auditing and approval from a security team, or where otherwise upgrading is a
  12592. long process.</p>
  12593. <p>By following the upstream support life cycles Synapse can ensure that its
  12594. dependencies continue to get security patches, while not requiring system admins
  12595. to constantly update their platform dependencies to the latest versions.</p>
  12596. </main>
  12597. <nav class="nav-wrapper" aria-label="Page navigation">
  12598. <!-- Mobile navigation buttons -->
  12599. <div style="clear: both"></div>
  12600. </nav>
  12601. </div>
  12602. </div>
  12603. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  12604. </nav>
  12605. </div>
  12606. <script type="text/javascript">
  12607. window.playground_copyable = true;
  12608. </script>
  12609. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  12610. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  12611. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  12612. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  12613. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  12614. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  12615. <!-- Custom JS scripts -->
  12616. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  12617. <script type="text/javascript" src="docs/website_files/version-picker.js"></script>
  12618. <script type="text/javascript" src="docs/website_files/version.js"></script>
  12619. <script type="text/javascript">
  12620. window.addEventListener('load', function() {
  12621. window.setTimeout(window.print, 100);
  12622. });
  12623. </script>
  12624. </body>
  12625. </html>