From a45e48c2bc5fd5ee5fe13f8ddffdc86899b5d43b Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Sat, 30 Jan 2021 16:21:27 +0100 Subject: [PATCH] user the user module's password parameter --- README.md | 8 ++ group_vars/all/user_vault | 119 +++++++++++++++++------------- hash_passwd.py | 16 ++++ roles/create_users/tasks/main.yml | 8 +- 4 files changed, 92 insertions(+), 59 deletions(-) create mode 100755 hash_passwd.py diff --git a/README.md b/README.md index 4e1a988..fa1483e 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,11 @@ The mapping vault-id@password-file is done in ansible.cfg under [defaults] in va To create a new vault with an id and password registered in ansible.cfg: `ansible-vault create --encrypt-vault-id user_vault group_vars/all/user_vault` + +## User managment + +The user managment role allows to manage user. + +Especially, it generate the described users on each hosts. + +The password are stored in the variables in there hash form. The script `hash_passwd.py` can give you the hash of a password. diff --git a/group_vars/all/user_vault b/group_vars/all/user_vault index c2228aa..256983f 100644 --- a/group_vars/all/user_vault +++ b/group_vars/all/user_vault @@ -1,53 +1,68 @@ $ANSIBLE_VAULT;1.2;AES256;user_vault -34333237343737396239323234633763636637663932633963353264353038643938353638376238 -3932643331316536613330633461306437326433343031310a396433363538353666333931393437 -31363534373165353839356633666461356637626131613233646331393037393238656164323833 -3536643932646138640a616135316332613830343136343166613038316662656330383836643262 -33623331356234393434656361643835373530336335613030373662323063663565666363633663 -37633132623366386434633837666238626664386564336261343530643036373931366238313464 -66343163626432666430343934333434643263666536643761313762353062313065303164303661 -61323431303063613439666137616166333936636637656636303263386333313433623433383063 -66353964636335636465613666656663343763626262346162373934393138343732363638346231 -33393337663530383066663638373333313138363733383731303533663235666135656433393239 -39643837666332636662623434363338313862323638316133366134656361633530333333316534 -32643639623338303136353739643861633161633962303666653331623436623931376462306235 -66373262373938616434316564363937633664326434633338613065663261326231383134656431 -65376432353661613531643566393730323736663564303630633962626230356531343239303737 -39386266353634626465373866343865656333363937306261313164376130306138373436313165 -39646331393837386664636262356133306531383764306461316137633439343432336561613631 -63373865393833333861373030316436623836373961616366636634623362633438323439333336 -33613234613536366461633230396164353466393235376333336437363465343036346534666666 -39396166326233313931386465623734336538666137366562336363343763306534666562363966 -35396261383666616438626562396536366135613861313430316133666231666133316164323036 -38376333393636313063393733333132313939393537363336633665343835326130363963633335 -65333435306531326433323063623032326637323531323530666534613461373637383966306662 -63393038636234313130643562363938383561383236626133643035616335316363346630333764 -36313864623830663233636134653436383363363731323332306564336566386639323739336265 -32383432383835366134656365633166373330313666323366636161326539353438626537303763 -65326137616538326238613965636534376332393731646631336534613633393064626561636639 -32373632343539663864373737336262656539376266613235316130636135336261373164633831 -35623938663361323435363334633535656263396162343835383263626537343039633864363934 -66343734643638373463663764363132643731663463613266316265373839306339323032653063 -35613535343362346162643938346461396434373866343139306633393434393533623830383564 -35303433343538396432386562306264613864373864326631643131396234373437313636636237 -62653030613735633531333430663365353330636636636635316365356363353034393333333534 -62326663316536363765393464343266303535623839306264613331343039326665393530363739 -39363332626336656362633634303439636135363061376434323637333233383736363939326363 -35353532396336623437353431306435636461633330356564616330623834653533646130343135 -61346364363761353332373365383666623062396230663936623130663862353465653835313634 -63643139393835623634653864643761633866306431363337643962386430393265393933303538 -39623933333132353963336630353639363932393931643134353766656161336431656463333337 -39306661336430303531363131373333383234653137333338366236353135343562316264396436 -33663861323461343835376162333064383666623033343138363865356666306361383163336663 -66633032323831336462326261303961353462316433376565653337653234643461663566366634 -32373936306439646633646163613564333436653762366634313338353166633030376331633362 -38313862323932396265653434336665663262653361623737333831356661643739353538323236 -66636234623838326437663064363734373765356261383038613035383538306431326336323933 -38643232333935633335323132373564376262313334653233656563363133383038363562613031 -65303735616235316139373334666363653064313730336530343463613362346461313561626131 -33626362616466396233643263336335653665373662616533376566383037643663363532343539 -32626439353464393264396362346434353962656436343466653238343636323437356339646264 -33373937383561663937326665313035643365643862363631353364613665633166633031633533 -33613633626666646638303062383762333331626139303934323762633266626432613937313836 -30316133313338363662346639386362336538356434656238336466383334333131626235383666 -37643938353166396130 +38363435323834653536616230643831633239356637393261373339393165643437363532626364 +3837376562396330623166356664386663633634633838330a626662386266666364393639303465 +34386562373936643030653762376138646366623036386235623362633261336437636131643930 +3739356332333961630a316130376262643562633733633861636238663033396237613338373939 +35633038393563633435646338383065613636393861353261613963636466613032356638326236 +63633566353664643934316435636632383364363864613761326436393837333866303637386633 +36363566633132336634393263343765356131396131373861383333336665656132303163353231 +38383437396436613737353738396232633766306566336334376136376432653461363031633663 +63326637346262303832373038363666303132643534343664373566336261306537636636333032 +63393361323331343264366232393961333665393437356334393765396338373032356661306664 +32333565616530313835623532623831396530396531306438646533666537326631626230656666 +30343062636132393361666237613562636636616436623466343361326530346138326266343637 +33333237306564623839336130373562346165343034663532396164633139333261656635323636 +36313561386639313766373366333864306162643134643665343563643330316634383836396461 +37646530666665333763336263373036666361396236383763383937663865393964653538313330 +64643939656233386537326465366263333833656130613434626264366531373638393263373838 +64666137373632626561656639666461303435623332633264663332346665656333393839336536 +63643339346236383930393064316431373461643966393762363262643834346362636130363238 +39376633393562653364666638316136663830646664653665343436646364353162343432373430 +39343830316233613961373261336130303738663136663131363366346566313063333838613063 +39353862613762633566666236306137386438636135303663333364386437343134633231333138 +65326338616666653237643035343261376636653561653665643962636139623030636366623337 +38313066306635666166643438353337306433336235343335306635656666613232373538333466 +30343565353764613134666364373234656661396663346138396139353763656262313664353630 +32396432356162613831623331336130303339353337633866343531303234633439373631383563 +36313231653638623434383933393238323465626565623133643537326231323336353931633831 +32343932376337623262396433633230313462373332633337396333333439353833323862303763 +63616164363762646534393436613462356361313334316466656237333838326361653538313131 +35353938613734613133646334653135346362393538316534303563646136303063383938666535 +65616137643832663436353562343838306333666638643233366266386161373936633064353635 +32376435643362643533653666313030633462306662656334343636613631656330623037363164 +66666663323761303961346334643266396533656631393662656631333731643435653961373862 +62646236313066636431326164663765646664376334393638303066386435366163663132653261 +31653331333934333265646236363631336334613866326162653364336263663034373930393437 +62623765346437613764643434396438386162333263666530313837636139303435343536353839 +34656233333037303635616666626233323436643333313231623563323338353638396139636536 +31646337613634663834353836393839333539303733336363356136323761616161353636303735 +31313561353937636234313063643831663930656562353335393237393434336532383231656138 +36643866396162356435316566616137353935336130646664376239663032346563613062386337 +32613833356532633965666433363464386464333238306335663532373433646161326638323435 +65623331393333663136653330356231323830656363323236626436333534306162323063343830 +39623332363430623635663635663134383563393364363162616661336136626433376331643962 +62653666366662643732623365643363613963613034653238326136303537386436356433366230 +30306435656438653532313230393438323230313562656431623631323963333839336131333331 +39623631646562656135653931383265323930333566316163343134643436343162393262366136 +65383138363865376431616237393935653133613633633866643335313331333065353830633361 +35653537343164363262353030663531366631333133356262373031373432313065656531316638 +34326634393766366165313632343638656161353764313265323063653332373935356564306666 +31626631393235323361386232386137616661636662353164333435663033363465306636353737 +34343637613263626564373537663733356364346161303366306535373761613564323432356266 +31343936343035336361666165343239396135303066373535643137633038373638363737376131 +32653731306636393235666435373862653862316638393633656361643030653361653132353035 +35646132336263653564366162636464646232346339326232623933333632653530376539613165 +39393863323331643265636265386435336230613837623938636666636438323665376263326631 +63623131336234346137393135393431653066333763306663376464663261353562356664393631 +39326534376465383262653139376432353032616165663164373762643065653534383238313063 +37366134303435306366313561373566613435653234306432626561366233373339373030303366 +34643835633262646262346630366339383935373731343435323966656535333563623065333536 +37356563343433346139626362373663663235383234323566323466613465333233353631336633 +39376264353862326134346162366265633966643663323461346464663162346261303439663864 +37396338396531366337326231643231643533623730313437383764656461663463313839393066 +32636431383463353064633064306434326332386631343634616539376530643264363732306439 +30396662633731356538393738636231373138623731323537653661383739343434373864366235 +66313732326433356630303937323163666531353431656135363232363963346339336566373766 +38336137373338636132343734303663313433336363656663313362333336333464626663613566 +63343130333236626539313032383437353330363632353533393263373563386261393532373932 +356437656137383837643465353033346436 diff --git a/hash_passwd.py b/hash_passwd.py new file mode 100755 index 0000000..01068fd --- /dev/null +++ b/hash_passwd.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +#coding: utf-8 + +import crypt +import getpass +import secrets # Better than random for security purpose +import string + +def gen_salt(dictionnary=string.ascii_letters, length=8): + return ''.join([secrets.choice(dictionnary) for _ in range(length)]) + +pwd = getpass.getpass("new password: ") +randomsalt = gen_salt() +hashed_password = crypt.crypt(pwd, '$6${}$'.format(randomsalt)) + +print(hashed_password) diff --git a/roles/create_users/tasks/main.yml b/roles/create_users/tasks/main.yml index d32afc8..a86416d 100644 --- a/roles/create_users/tasks/main.yml +++ b/roles/create_users/tasks/main.yml @@ -5,13 +5,7 @@ name: "{{ item.name }}" groups: "{{ item.groups }}" shell: "{{ item.shell }}" - loop: "{{ uservault_users }}" - -- name: Set the passwords - replace: - path: /etc/shadow - regexp: '^{{ item.name }}:(.*?):(.*)' - replace: '{{ item.name }}:{{ item.password_hash }}:\2' + password: "{{ item.password_hash }}" loop: "{{ uservault_users }}" - name: Create .ssh file