Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 4171854

Browse files
committed
Make www root and URLs configurable, fix hardcoded CA variables.
1 parent 6cebd30 commit 4171854

File tree

4 files changed

+110
-33
lines changed

4 files changed

+110
-33
lines changed

filter_plugins/pronounce.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from ansible.module_utils.common.text.converters import to_text
2+
from ansible.errors import AnsibleError
3+
4+
class FilterModule(object):
5+
def filters(self):
6+
return {
7+
'pronounce': self.pronounce
8+
}
9+
10+
def pronounce(self, value):
11+
"""
12+
Jinja2 filter for Ansible to pronounce positive numbers less than 13 in English.
13+
14+
Example of usage in a Jinja2 template:
15+
{{ 13 | pronounce }} -> "13"
16+
{{ 12 | pronounce }} -> "twelve"
17+
{{ 0 | pronounce }} -> "zero"
18+
{{ -1 | pronounce }} -> AnsibleError("Cannot pronounce negative numbers.")
19+
20+
:param value: value to be pronounced
21+
:return: the pronunciation of the value, or the number itself if the value is greater than 12
22+
:rtype: str
23+
:raises AnsibleError: if the value is negative or the value is not an integer
24+
"""
25+
if value < 0:
26+
raise AnsibleError("Cannot pronounce negative numbers.")
27+
try:
28+
pronounciation = {
29+
0: "zero",
30+
1: "one",
31+
2: "two",
32+
3: "three",
33+
4: "four",
34+
5: "five",
35+
6: "six",
36+
7: "seven",
37+
8: "eight",
38+
9: "nine",
39+
10: "ten",
40+
11: "eleven",
41+
12: "twelve",
42+
}.get(int(value)) or value
43+
return to_text(pronounciation)
44+
except ValueError:
45+
raise AnsibleError('Cannot parse ' + value + ' as an integer.')

roles/installation_manual/files/chapters/installation.rst.j2

+16-16
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ Create {{ server.name }}
7272

7373
#. Create a folder where the repository files should be stored::
7474

75-
New-Item -Path "C:\inetpub" -Name "pki" -ItemType "directory"
75+
New-Item -Path "{{ server.www_root | default('C:\inetpub')}}" -Name "pki" -ItemType "directory"
7676

7777
#. Create a new website for the repository::
7878

79-
New-IISSite -Name PKI -PhysicalPath "C:\inetpub\pki" -Protocol http -BindingInformation "*:80:" -Force
79+
New-IISSite -Name PKI -PhysicalPath "{{ server.www_root | default('C:\inetpub')}}\pki" -Protocol http -BindingInformation "*:80:" -Force
8080
Remove-IISSite -Name "Default Web Site"
8181
Start-IISSite -Name PKI
8282

@@ -89,14 +89,14 @@ Create {{ server.name }}
8989

9090
#. Create an SMB share using PowerShell::
9191

92-
New-SmbShare -Name "PKI Repository" -Path "C:\inetpub\pki"
92+
New-SmbShare -Name "PKI Repository" -Path "{{ server.www_root | default('C:\inetpub')}}\pki"
9393

9494
#. Grant NTFS and SMB share permissions::
9595

96-
$Acl = Get-ACL "C:\inetpub\pki\"
96+
$Acl = Get-ACL "{{ server.www_root | default('C:\inetpub')}}\pki\"
9797
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("Everyone", "FullControl", "ContainerInherit,Objectinherit", "None", "Allow")
9898
$Acl.AddAccessRule($AccessRule)
99-
Set-ACL "C:\inetpub\pki\" $Acl
99+
Set-ACL "{{ server.www_root | default('C:\inetpub')}}\pki\" $Acl
100100
{% if server.connected_to_ad %}
101101
Grant-SmbShareAccess -Name "PKI Repository" -AccountName "{{ customer.domain.split('.')[0].upper() }}\{{ accounts.service.user }}" -AccessRight Full -Force
102102
{% else %}
@@ -184,9 +184,9 @@ Create the root CA
184184
#. Create a root CA using PowerShell::
185185

186186
{% if servers.root_ca.policy.key_specification == 'P256' %}
187-
Install-AdcsCertificationAuthority -CAType StandaloneRootCa -CryptoProviderName "ECDSA_P256#{{ servers.root_ca.policy.key_storage_provider }}" -KeyLength 256 -HashAlgorithmName SHA256 -ValidityPeriod Years -ValidityPeriodUnits 25 -CACommonName "R1" -CADistinguishedNameSuffix "O={{ customer.name }},C={{ customer.country }}" -DatabaseDirectory $(Join-Path $env:SystemRoot "System32\CertLog") -Force
187+
Install-AdcsCertificationAuthority -CAType StandaloneRootCa -CryptoProviderName "ECDSA_P256#{{ servers.root_ca.policy.key_storage_provider }}" -KeyLength 256 -HashAlgorithmName SHA256 -ValidityPeriod Years -ValidityPeriodUnits 25 -CACommonName "{{ servers.root_ca.cn }}" -CADistinguishedNameSuffix "O={{ customer.name }},C={{ customer.country }}" -DatabaseDirectory $(Join-Path $env:SystemRoot "System32\CertLog") -Force
188188
{% elif servers.root_ca.policy.key_specification == 'RSA4096' %}
189-
Install-AdcsCertificationAuthority -CAType StandaloneRootCa -CryptoProviderName "RSA#{{ servers.root_ca.policy.key_storage_provider }}" -KeyLength 4096 -HashAlgorithmName SHA256 -ValidityPeriod Years -ValidityPeriodUnits 25 -CACommonName "R1" -CADistinguishedNameSuffix "O={{ customer.name }},C={{ customer.country }}" -DatabaseDirectory $(Join-Path $env:SystemRoot "System32\CertLog") -Force
189+
Install-AdcsCertificationAuthority -CAType StandaloneRootCa -CryptoProviderName "RSA#{{ servers.root_ca.policy.key_storage_provider }}" -KeyLength 4096 -HashAlgorithmName SHA256 -ValidityPeriod Years -ValidityPeriodUnits 25 -CACommonName "{{ servers.root_ca.cn }}" -CADistinguishedNameSuffix "O={{ customer.name }},C={{ customer.country }}" -DatabaseDirectory $(Join-Path $env:SystemRoot "System32\CertLog") -Force
190190
{% else %}
191191
Unknown key specification '{{ servers.root_ca.policy.key_specification }}'.
192192
{% endif %}
@@ -223,22 +223,22 @@ Publish root CA artefacts
223223

224224
#. Export a copy of the root CA certificate::
225225

226-
CertUtil "-ca.cert" "C:\R1.crt"
226+
CertUtil "-ca.cert" "C:\{{ servers.root_ca.cn }}.crt"
227227

228228
#. Issue a CRL from the root CA::
229229

230230
CertUtil -crl
231231

232232
{% for server in servers.repositories %}
233-
#. Transfer the files ``C:\R1.crt`` and ``C:\R1.crl`` to ``C:\inetpub\pki`` on {{ server.name }}.
233+
#. Transfer the files ``C:\{{ servers.root_ca.cn }}.crt`` and ``C:\{{ servers.root_ca.cn }}.crl`` to ``{{ server.www_root | default('C:\inetpub')}}\pki`` on {{ server.name }}.
234234
{% endfor %}
235235

236236
{% if servers.root_ca.location.existing_backup is not defined %}
237-
#. Transfer ``C:\R1.crt`` to servers.issuing_cas[0] and log in to servers.issuing_cas[0] using RDP.
237+
#. Transfer ``C:\{{ servers.root_ca.cn }}.crt`` to servers.issuing_cas[0] and log in to servers.issuing_cas[0] using RDP.
238238

239239
#. Publish the root CA certificate to AD::
240240

241-
CertUtil -dspublish -f C:\R1.crt
241+
CertUtil -dspublish -f C:\{{ servers.root_ca.cn }}.crt
242242

243243
{% endif %}
244244
{% endif %}
@@ -328,7 +328,7 @@ Activate {{ issuing_ca.cn }} and restore a backup
328328
CertUtil "-ca.cert" "C:\{{ issuing_ca.cn }}.crt"
329329

330330
{% for server in servers.repositories %}
331-
#. Transfer the file ``C:\{{ issuing_ca.cn }}.crt`` to ``C:\inetpub\pki`` on {{ server.name }}.
331+
#. Transfer the file ``C:\{{ issuing_ca.cn }}.crt`` to ``{{ server.www_root | default('C:\inetpub')}}\pki`` on {{ server.name }}.
332332
{% endfor %}
333333

334334
{% endif %}
@@ -354,18 +354,18 @@ Sign the CA certificate
354354

355355
#. Submit the CSR for {{ issuing_ca.cn }} and save the request ID::
356356

357-
$request = CertReq -submit -config - C:\ICA1.csr | Out-String | Select-String 'RequestId: (\d+)'
357+
$request = CertReq -submit -config - C:\{{ issuing_ca.cn }}.csr | Out-String | Select-String 'RequestId: (\d+)'
358358
$requestId = $request.Matches[0].Groups[1].Value.Trim()
359359

360360
#. Accept the request and retrieve a copy of the issuing CA certificate::
361361

362362
CertUtil -resubmit $requestId
363363
CertReq -retrieve -config - $requestId C:\{{ issuing_ca.cn }}.crt
364364

365-
#. Transfer the files ``C:\{{ issuing_ca.cn }}.crt`` and ``C:\R1.crt`` to {{ issuing_ca.name }}.
365+
#. Transfer the files ``C:\{{ issuing_ca.cn }}.crt`` and ``C:\{{ servers.root_ca.cn }}.crt`` to {{ issuing_ca.name }}.
366366

367367
{% for server in servers.repositories %}
368-
#. Transfer the file ``C:\{{ issuing_ca.cn }}.crt`` to ``C:\inetpub\pki`` on {{ server.name }}.
368+
#. Transfer the file ``C:\{{ issuing_ca.cn }}.crt`` to ``{{ server.www_root | default('C:\inetpub')}}\pki`` on {{ server.name }}.
369369
{% endfor %}
370370

371371
Import the CA certificate
@@ -375,7 +375,7 @@ Import the CA certificate
375375

376376
#. Install the CA certificate chain::
377377

378-
Import-Certificate -FilePath C:\R1.crt -CertStoreLocation Cert:\LocalMachine\Root
378+
Import-Certificate -FilePath C:\{{ servers.root_ca.cn }}.crt -CertStoreLocation Cert:\LocalMachine\Root
379379
CertUtil -installcert "C:\{{ issuing_ca.cn }}.crt"
380380

381381
Configure registry settings

roles/installation_manual/files/chapters/system-overview.rst.j2

+38-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ The following servers are a part of the PKI. For details, refer to *Appendix B*.
3434
Topology
3535
--------
3636

37-
The PKI has been implemented as a two-tier CA hierachy with one root CA and one issuing CA.
37+
{% if servers.issuing_cas | length == 1 %}
38+
The PKI has been implemented as a two-tier CA hierachy with a root CA and a single issuing CA.
39+
{% else %}
40+
The PKI has been implemented as a two-tier CA hierachy with a root CA and {{ servers.issuing_cas | length | pronounce }} issuing CAs.
41+
{% endif %}
3842

3943
The root CA signs the CA certificate for the issuing CA, and is stored offline when not in use. If the private key for the issuing CA is compromised, it is possible to revoke the issuing CA using the root CA without having to create a new CA hierarchy.
4044

@@ -88,10 +92,24 @@ The following endpoints are used for distribution of *Certificate Revocation Lis
8892

8993
* - Certificate Authority
9094
- CRL Distribution Point
91-
* - R1
92-
- ``http://pki.{{ customer.domain }}/R1.crl``
93-
* - ICA1
95+
{% if servers.root_ca is defined %}
96+
{% if servers.root_ca.urls is defined %}
97+
* - {{ servers.root_ca.cn }}
98+
- ``{{ servers.root_ca.urls.cdp }}``
99+
{% else %}
100+
* - {{ servers.root_ca.cn }}
101+
- ``http://pki.{{ customer.domain }}/{{ servers.root_ca.cn }}.crl``
102+
{% endif %}
103+
{% endif %}
104+
{% for issuing_ca in servers.issuing_cas %}
105+
{% if issuing_ca.urls is defined %}
106+
* - {{ issuing_ca.cn }}
107+
- ``{{ issuing_ca.urls.aia }}``
108+
{% else %}
109+
* - {{ issuing_ca.cn }}
94110
- ``http://pki.{{ customer.domain }}/ICA1-<CRLNameSuffix>.crl``
111+
{% endif %}
112+
{% endfor %}
95113

96114
The appropriate URLs are put in the *CRL Distribution Points* certificate extension (2.5.29.31) of issued certificates.
97115

@@ -104,10 +122,24 @@ The following endpoints are used for distribution of CA certificates.
104122
:widths: 1 3
105123
:header-rows: 1
106124

107-
* - R1
125+
{% if servers.root_ca is defined %}
126+
{% if servers.root_ca.urls is defined %}
127+
* - {{ servers.root_ca.cn }}
128+
- ``{{ servers.root_ca.urls.cdp }}``
129+
{% else %}
130+
* - {{ servers.root_ca.cn }}
108131
- ``http://pki.{{ customer.domain }}/R1.crt``
109-
* - ICA1
132+
{% endif %}
133+
{% endif %}
134+
{% for issuing_ca in servers.issuing_cas %}
135+
{% if issuing_ca.urls is defined %}
136+
* - {{ issuing_ca.cn }}
137+
- ``{{ issuing_ca.urls.aia }}``
138+
{% else %}
139+
* - {{ issuing_ca.cn }}
110140
- ``http://pki.{{ customer.domain }}/<CertificateName>.crt``
141+
{% endif %}
142+
{% endfor %}
111143

112144
The appropriate URLs are put in the *Authority Information Access* certificate extension (1.3.6.1.5.5.7.1.1) of issued certificates.
113145

roles/operations_manual/files/chapters/operations.rst.j2

+11-11
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ When configuring Windows, configure the name of the server to be ``{{ servers.ro
139139
#. Restore the CA certificate and private key::
140140

141141
$BackupPassword = Read-Host -AsSecureString
142-
Install-AdcsCertificationAuthority -CAType StandaloneRootCa -CertFile 'C:\Backup\R1.p12' -CertFilePassword $BackupPassword -DatabaseDirectory $(Join-Path $env:SystemRoot "System32\CertLog") -Force
142+
Install-AdcsCertificationAuthority -CAType StandaloneRootCa -CertFile 'C:\Backup\{{ servers.root_ca.cn}}.p12' -CertFilePassword $BackupPassword -DatabaseDirectory $(Join-Path $env:SystemRoot "System32\CertLog") -Force
143143

144144
#. Restore the CA database using CertUtil::
145145

@@ -169,7 +169,7 @@ Issue a new root CA CRL
169169
CertUtil -crl
170170

171171
{% for server in servers.repositories %}
172-
#. Transfer the file ``C:\R1.crt`` to ``C:\inetpub\pki`` on {{ server.name }}.
172+
#. Transfer the file ``C:\{{ servers.root_ca.cn }}.crt`` to ``{{ server.www_root | default('C:\inetpub') }}\pki`` on {{ server.name }}.
173173
{% endfor %}
174174

175175
#. Turn off ``{{ servers.root_ca.name }}``.
@@ -214,7 +214,7 @@ Renew the root CA
214214

215215
#. Click on **OK** to add the snap-in.
216216

217-
#. Expand **Certification Authority (Local)** the left pane, right-click on **R1** and choose **All Tasks → Renew CA Certificate...**.
217+
#. Expand **Certification Authority (Local)** the left pane, right-click on **{{ servers.root_ca.cn }}** and choose **All Tasks → Renew CA Certificate...**.
218218

219219
#. Click **Yes** to stop ADCS.
220220

@@ -226,15 +226,15 @@ Renew the root CA
226226

227227
#. Export the new root CA certificate to a file::
228228

229-
CertUtil "-ca.cert" "C:\R1.crt"
229+
CertUtil "-ca.cert" "C:\{{ servers.root_ca.cn }}.crt"
230230

231231
{% for server in servers.repositories %}
232-
#. Transfer the files ``C:\R1.crt`` and ``C:\R1.crl`` to ``C:\inetpub\pki`` on {{ server.name }}.
232+
#. Transfer the files ``C:\{{ servers.root_ca.cn }}.crt`` and ``C:\{{ servers.root_ca.cn }}.crl`` to ``{{ server.www_root | default('C:\inetpub') }}\pki`` on {{ server.name }}.
233233
{% endfor %}
234234

235-
#. Transfer the file `C:\R1.crt`` to {{ servers.issuing_cas[0].name }} and publish the root CA certificate to AD::
235+
#. Transfer the file `C:\{{ servers.root_ca.cn }}.crt`` to {{ servers.issuing_cas[0].name }} and publish the root CA certificate to AD::
236236

237-
CertUtil -dspublish -f C:\R1.crt
237+
CertUtil -dspublish -f C:\{{ servers.root_ca.cn }}.crt
238238

239239
{% endif %}
240240

@@ -288,8 +288,8 @@ Renew {{ issuing_ca.cn }} and create a new keypair
288288

289289
CertUtil -installcert "C:\{{ issuing_ca.cn }}-G2.crt"
290290

291-
{% for repository in servers.repositories %}
292-
#. Transfer the file ``C:\{{ issuing_ca.cn }}-G2.crt`` to ``C:\inetpub\pki`` on {{ repository.name }}.
291+
{% for server in servers.repositories %}
292+
#. Transfer the file ``C:\{{ issuing_ca.cn }}-G2.crt`` to ``{{ server.www_root | default('C:\inetpub') }}\pki`` on {{ server.name }}.
293293
{% endfor %}
294294

295295
#. Update the CDP and AIA paths to point to the new CRL and CA certificate::
@@ -362,8 +362,8 @@ Renew {{ issuing_ca.cn }} with an existing keypair
362362
CertUtil -crl
363363
Start-ScheduledTask -TaskName "CopyCRL"
364364

365-
{% for repository in servers.repositories %}
366-
#. Transfer the file ``C:\{{ issuing_ca.cn }}.crt`` to ``C:\inetpub\pki`` on {{ repository.name }}. Replace the existing file.
365+
{% for server in servers.repositories %}
366+
#. Transfer the file ``C:\{{ issuing_ca.cn }}.crt`` to ``{{ server.www_root | default('C:\inetpub') }}\pki`` on {{ server.name }}. Replace the existing file.
367367
{% endfor %}
368368

369369
{% endfor %}

0 commit comments

Comments
 (0)