forked from mtusi2026/mtusi2026lab7
wip: apply pki-ingress-mtls groups 1-4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,286 @@
|
||||
# PKI стенда: скрипт оператора (change `pki-ingress-mtls`)
|
||||
|
||||
Дата: 2026-11-16. Код: рабочее дерево поверх `44fe711` (apply change, до коммита).
|
||||
Хост: macOS, `openssl` в `PATH` — OpenSSL 4.1.0 (Homebrew), `/usr/bin/openssl` —
|
||||
LibreSSL 3.3.6. Скрипт — `infra/pki/pki.sh`, конфигурация — `infra/pki/openssl.cnf`,
|
||||
список identity — `infra/pki/identities.conf`.
|
||||
|
||||
Сценарии спека `pki` на временных каталогах (задача 1.2): `PKI_OPERATOR_DIR=$S/op`,
|
||||
`PKI_STAND_DIR=$S/stand`, `$S` — каталог в scratchpad сессии, удалён после прогона. Рабочий
|
||||
каталог оператора и `.pki/stand/` не затрагивались. Отпечатки SHA-256 сокращены до четырёх
|
||||
байт (`…`), путь репозитория — `<repo>`, `rc` — код выхода команды.
|
||||
|
||||
## Сценарии скрипта
|
||||
|
||||
### Неподходящий openssl (LibreSSL) — до любых файлов
|
||||
|
||||
```
|
||||
$ OPENSSL=/usr/bin/openssl <repo>/infra/pki/pki.sh init
|
||||
pki: '/usr/bin/openssl' is 'LibreSSL 3.3.6', OpenSSL 3+ is required; set OPENSSL
|
||||
rc=1
|
||||
$ ls -A $S
|
||||
all-output.txt # файлы самого прогона проверки; op/ и stand/ не созданы
|
||||
out
|
||||
```
|
||||
|
||||
### Создание CA
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh init
|
||||
CA created
|
||||
CA: serial 2132B97A41EB797A461BA4BB9A16A3BF39F66F0F, not after 2029-11-15 03:29:11Z, sha256 BD:A9:F1:33:…, $S/op/ca.crt
|
||||
rc=0
|
||||
$ stat -f '%Sp %N' $S/op $S/op/ca.key $S/op/ca.crt
|
||||
drwx------ $S/op
|
||||
-rw------- $S/op/ca.key
|
||||
-rw------- $S/op/ca.crt
|
||||
$ openssl x509 -in $S/op/ca.crt -noout -subject -startdate -enddate -ext basicConstraints,keyUsage
|
||||
subject=CN=MTUSI lab7 operator CA
|
||||
notBefore=Nov 16 03:29:11 2026 GMT
|
||||
notAfter=Nov 15 03:29:11 2029 GMT
|
||||
X509v3 Basic Constraints: critical
|
||||
CA:TRUE, pathlen:0
|
||||
X509v3 Key Usage: critical
|
||||
Certificate Sign, CRL Sign
|
||||
$ openssl pkey -in $S/op/ca.key -noout -text_pub | sed -n '1p;/NIST/p'
|
||||
Public-Key: (256 bit field, 128 bit security level)
|
||||
NIST CURVE: P-256
|
||||
```
|
||||
|
||||
### Повторный init — те же SHA-256
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh init
|
||||
CA exists, unchanged
|
||||
CA: serial 2132B97A41EB797A461BA4BB9A16A3BF39F66F0F, not after 2029-11-15 03:29:11Z, sha256 BD:A9:F1:33…, $S/op/ca.crt
|
||||
rc=0
|
||||
$ shasum -a 256 ca.key ca.crt # до и после, первые 16 символов
|
||||
… ca.key
|
||||
… ca.crt
|
||||
unchanged # diff до/после пуст
|
||||
```
|
||||
|
||||
### Выпуск файлов стенда
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh stand
|
||||
CA exists, unchanged
|
||||
CA: serial 2132B97A…, not after 2029-11-15 03:29:11Z, sha256 BD:A9:F1:33…, $S/op/ca.crt
|
||||
CA certificate copied to $S/stand/ca.crt
|
||||
CRL: next update 2026-12-16 03:29:11Z, $S/stand/crl.pem
|
||||
reissue haproxy: missing
|
||||
issued haproxy (client, SAN haproxy): serial 01B9C127DAA85E18B8CD68682417F4E9, not after 2027-02-14 03:29:11Z, sha256 B8:D6:32:63…, $S/stand/haproxy.crt
|
||||
reissue api: missing
|
||||
issued api (server, SAN api): serial 01B9C127DAA85E18B8CD68682417F4EA, not after 2027-02-14 03:29:11Z, sha256 36:EA:C0:D6…, $S/stand/api.crt
|
||||
reissue ingress: missing
|
||||
issued ingress (server, SAN localhost): serial 01B9C127DAA85E18B8CD68682417F4EB, not after 2027-02-14 03:29:11Z, sha256 F0:D5:E3:58…, $S/stand/ingress.crt
|
||||
rc=0
|
||||
$ stat -f '%Sp %N' $S/stand $S/stand/*
|
||||
drwx------ $S/stand
|
||||
-rw------- $S/stand/api.crt
|
||||
-rw------- $S/stand/api.key
|
||||
-rw------- $S/stand/ca.crt
|
||||
-rw------- $S/stand/crl.pem
|
||||
-rw------- $S/stand/haproxy.crt
|
||||
-rw------- $S/stand/haproxy.key
|
||||
-rw------- $S/stand/haproxy.pem
|
||||
-rw------- $S/stand/ingress.crt
|
||||
-rw------- $S/stand/ingress.key
|
||||
-rw------- $S/stand/ingress.pem
|
||||
$ openssl verify -CAfile $S/stand/ca.crt $S/stand/<identity>.crt; openssl x509 … -ext subjectAltName,extendedKeyUsage
|
||||
$S/stand/haproxy.crt: OK
|
||||
subject=CN=haproxy notAfter=Feb 14 03:29:11 2027 GMT X509v3 Extended Key Usage: TLS Web Client Authentication X509v3 Subject Alternative Name: DNS:haproxy
|
||||
$S/stand/api.crt: OK
|
||||
subject=CN=api notAfter=Feb 14 03:29:11 2027 GMT X509v3 Extended Key Usage: TLS Web Server Authentication X509v3 Subject Alternative Name: DNS:api
|
||||
$S/stand/ingress.crt: OK
|
||||
subject=CN=ingress notAfter=Feb 14 03:29:11 2027 GMT X509v3 Extended Key Usage: TLS Web Server Authentication X509v3 Subject Alternative Name: DNS:localhost
|
||||
$ ls $S/op/certs; grep -c PRIVATE $S/op/certs/* # база CA: только сертификаты
|
||||
01B9C127DAA85E18B8CD68682417F4E9.pem :0
|
||||
01B9C127DAA85E18B8CD68682417F4EA.pem :0
|
||||
01B9C127DAA85E18B8CD68682417F4EB.pem :0
|
||||
```
|
||||
|
||||
Ключи leaf — EC P-256 (`genpkey ec_paramgen_curve:P-256`), срок leaf — 90 дней (до
|
||||
2027-02-14), CRL — 30 дней.
|
||||
|
||||
### Повторный выпуск без изменений
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh stand
|
||||
CA exists, unchanged
|
||||
CA: serial 2132B97A…, …
|
||||
CRL: next update 2026-12-16 03:29:11Z, $S/stand/crl.pem
|
||||
valid haproxy: serial 01B9C127DAA85E18B8CD68682417F4E9, not after 2027-02-14 03:29:11Z, sha256 B8:D6:32:63…, $S/stand/haproxy.crt
|
||||
valid api: serial 01B9C127DAA85E18B8CD68682417F4EA, not after 2027-02-14 03:29:11Z, sha256 36:EA:C0:D6…, $S/stand/api.crt
|
||||
valid ingress: serial 01B9C127DAA85E18B8CD68682417F4EB, not after 2027-02-14 03:29:11Z, sha256 F0:D5:E3:58…, $S/stand/ingress.crt
|
||||
rc=0
|
||||
$ diff before after # серийные номера и SHA-256 всех .crt, .key, .pem leaf
|
||||
serials, certificates and keys unchanged
|
||||
```
|
||||
|
||||
CRL выпускается заново при каждом `stand` (спек: «`make pki_stand` SHALL выпускать CRL
|
||||
заново при каждом запуске»), поэтому в сравнение leaf он не входит.
|
||||
|
||||
### Перевыпуск истекающего leaf и статус сроков
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh issue api --profile server --san api --days 10 --out $S/stand
|
||||
issued api (server, SAN api): serial 01B9C127DAA85E18B8CD68682417F4EC, not after 2026-11-26 03:29:11Z, sha256 93:11:62:77…, $S/stand/api.crt
|
||||
$ <repo>/infra/pki/pki.sh status
|
||||
CA: not after 2029-11-15 03:29:11Z (1095 days, ok), sha256 BD:A9:F1:33…, $S/op/ca.crt
|
||||
leaf haproxy: serial 01B9C127DAA85E18B8CD68682417F4E9, not after 2027-02-14 03:29:11Z (90 days, ok), sha256 B8:D6:32:63…, $S/stand/haproxy.crt
|
||||
leaf api: serial 01B9C127DAA85E18B8CD68682417F4EC, not after 2026-11-26 03:29:11Z (10 days, EXPIRES SOON (< 30 days)), sha256 93:11:62:77…, $S/stand/api.crt
|
||||
leaf ingress: serial 01B9C127DAA85E18B8CD68682417F4EB, not after 2027-02-14 03:29:11Z (90 days, ok), sha256 F0:D5:E3:58…, $S/stand/ingress.crt
|
||||
CRL: next update 2026-12-16 03:29:11Z (30 days, ok), revoked 0, $S/stand/crl.pem
|
||||
$ <repo>/infra/pki/pki.sh stand
|
||||
…
|
||||
valid haproxy: serial 01B9C127DAA85E18B8CD68682417F4E9, …
|
||||
reissue api: expires in less than 30 days
|
||||
issued api (server, SAN api): serial 01B9C127DAA85E18B8CD68682417F4ED, not after 2027-02-14 03:29:12Z, sha256 D1:3B:EC:EA…, $S/stand/api.crt
|
||||
valid ingress: serial 01B9C127DAA85E18B8CD68682417F4EB, …
|
||||
$ diff before after # серийные номера трёх leaf
|
||||
< api serial=01B9C127DAA85E18B8CD68682417F4EC
|
||||
> api serial=01B9C127DAA85E18B8CD68682417F4ED
|
||||
```
|
||||
|
||||
Отметка у CRL — меньше 7 дней (`CRL_WARN_DAYS`), у CA и leaf — меньше 30.
|
||||
|
||||
### Перевыпуск leaf другого CA
|
||||
|
||||
```
|
||||
$ PKI_OPERATOR_DIR=$S/other-op PKI_STAND_DIR=$S/other pki.sh stand >/dev/null && cp $S/other/ingress.{crt,key,pem} $S/stand/
|
||||
ingress replaced by a leaf of another CA
|
||||
$ <repo>/infra/pki/pki.sh stand | grep -E 'reissue|issued'
|
||||
reissue ingress: not signed by current CA
|
||||
issued ingress (server, SAN localhost): serial 01B9C127DAA85E18B8CD68682417F4EE, not after 2027-02-14 03:29:12Z, sha256 BD:0D:FD:B4…, $S/stand/ingress.crt
|
||||
$ diff before after
|
||||
< ingress serial=01E70A75C60FC47529DD392C05DE99AD
|
||||
> ingress serial=01B9C127DAA85E18B8CD68682417F4EE
|
||||
```
|
||||
|
||||
### Новая identity строкой списка
|
||||
|
||||
```
|
||||
$ tail -1 $S/ids.conf # копия infra/pki/identities.conf плюс строка
|
||||
worker client worker,worker.internal split
|
||||
$ PKI_IDENTITIES=$S/ids.conf <repo>/infra/pki/pki.sh stand | grep worker
|
||||
reissue worker: missing
|
||||
issued worker (client, SAN worker,worker.internal): serial 01B9C127DAA85E18B8CD68682417F4EF, not after 2027-02-14 03:29:13Z, sha256 B0:F8:3B:DD…, $S/stand/worker.crt
|
||||
$ openssl x509 -in $S/stand/worker.crt -noout -ext subjectAltName,extendedKeyUsage
|
||||
X509v3 Extended Key Usage: TLS Web Client Authentication X509v3 Subject Alternative Name: DNS:worker, DNS:worker.internal
|
||||
```
|
||||
|
||||
Скрипт при этом не правился (тот же файл `infra/pki/pki.sh`).
|
||||
|
||||
### Выпуск в другой каталог
|
||||
|
||||
```
|
||||
$ PKI_STAND_DIR=$S/elsewhere <repo>/infra/pki/pki.sh stand | grep -cE 'issued'
|
||||
3
|
||||
$ ls $S/elsewhere; diff before after # ls -A и SHA-256 всех файлов $S/stand
|
||||
api.crt api.key ca.crt crl.pem haproxy.crt haproxy.key haproxy.pem ingress.crt ingress.key ingress.pem
|
||||
stand dir unchanged
|
||||
```
|
||||
|
||||
### Разовая identity для проверки
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh issue mtls-probe --profile client --san mtls-probe --days 1 --out $S/probe
|
||||
issued mtls-probe (client, SAN mtls-probe): serial 01B9C127DAA85E18B8CD68682417F4F3, not after 2026-11-17 03:29:13Z, sha256 DE:31:DA:B2…, $S/probe/mtls-probe.crt
|
||||
$ ls $S/probe; openssl x509 -in $S/probe/mtls-probe.crt -noout -startdate -enddate -ext subjectAltName,extendedKeyUsage
|
||||
mtls-probe.crt
|
||||
mtls-probe.key
|
||||
notBefore=Nov 16 03:29:13 2026 GMT notAfter=Nov 17 03:29:13 2026 GMT X509v3 Extended Key Usage: TLS Web Client Authentication X509v3 Subject Alternative Name: DNS:mtls-probe
|
||||
$ ls $S/stand | grep -c mtls-probe
|
||||
0
|
||||
```
|
||||
|
||||
### Отозванный leaf в CRL
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh revoke haproxy
|
||||
revoked haproxy: serial 01B9C127DAA85E18B8CD68682417F4E9
|
||||
revoked haproxy: serial 01B9C127DAA85E18B8CD68682417F4F0
|
||||
CRL: next update 2026-12-16 03:29:13Z, $S/stand/crl.pem
|
||||
rc=0
|
||||
$ openssl crl -in $S/stand/crl.pem -noout -text | grep -A1 'Serial Number' | grep -c 01B9C127DAA85E18B8CD68682417F4E9
|
||||
1
|
||||
$ openssl verify -crl_check -CAfile $S/stand/ca.crt -CRLfile $S/stand/crl.pem $S/stand/haproxy.crt
|
||||
CN=haproxy
|
||||
error 23 at 0 depth lookup: certificate revoked
|
||||
error $S/stand/haproxy.crt: verification failed
|
||||
rc=2
|
||||
$ openssl verify -crl_check … $S/stand/api.crt
|
||||
$S/stand/api.crt: OK
|
||||
$ openssl verify -crl_check … $S/stand/ingress.crt
|
||||
$S/stand/ingress.crt: OK
|
||||
$ <repo>/infra/pki/pki.sh stand | grep -E 'reissue|issued'
|
||||
reissue haproxy: revoked
|
||||
issued haproxy (client, SAN haproxy): serial 01B9C127DAA85E18B8CD68682417F4F4, not after 2027-02-14 03:29:13Z, sha256 00:C4:F4:EF…, $S/stand/haproxy.crt
|
||||
```
|
||||
|
||||
`revoke` отзывает **все** действующие leaf identity в базе CA: второй серийный номер —
|
||||
leaf `haproxy`, выпущенный тем же CA в другой каталог (сценарий «Выпуск в другой
|
||||
каталог»). Отозванный leaf стенда `stand` перевыпускает (проверка `verify -crl_check`).
|
||||
|
||||
### Отзыв неизвестной identity
|
||||
|
||||
```
|
||||
$ <repo>/infra/pki/pki.sh revoke nosuch
|
||||
pki: no valid certificate of identity 'nosuch'; nothing changed
|
||||
rc=1
|
||||
$ diff before after # SHA-256 index.txt, serial, crlnumber, crl.pem
|
||||
CA database and CRL unchanged
|
||||
$ pki.sh revoke mtls-probe; pki.sh revoke mtls-probe
|
||||
revoked mtls-probe: serial 01B9C127DAA85E18B8CD68682417F4F3
|
||||
CRL: next update 2026-12-16 03:29:13Z, $S/stand/crl.pem
|
||||
pki: no valid certificate of identity 'mtls-probe'; nothing changed
|
||||
rc=1
|
||||
```
|
||||
|
||||
## Цели make на рабочем каталоге (задача 1.3)
|
||||
|
||||
Первый запуск — каталога оператора ещё нет; второй — без изменений:
|
||||
|
||||
```
|
||||
$ ls ~/.config/mtusi-lab7
|
||||
ls: /Users/<user>/.config/mtusi-lab7: No such file or directory
|
||||
$ make pki_stand
|
||||
infra/pki/pki.sh stand
|
||||
CA created
|
||||
CA: serial 4BD17777A530B84F354BA57FA7509896091A6459, not after 2029-11-15 03:31:31Z, sha256 51:62:A6:E4…, ~/.config/mtusi-lab7/operator/ca.crt
|
||||
CA certificate copied to <repo>/.pki/stand/ca.crt
|
||||
CRL: next update 2026-12-16 03:31:32Z, <repo>/.pki/stand/crl.pem
|
||||
reissue haproxy: missing
|
||||
issued haproxy (client, SAN haproxy): serial 01A9A23205315927156C54D25B0DFAD8, not after 2027-02-14 03:31:32Z, sha256 E1:60:8D:30…, <repo>/.pki/stand/haproxy.crt
|
||||
reissue api: missing
|
||||
issued api (server, SAN api): serial 01A9A23205315927156C54D25B0DFAD9, not after 2027-02-14 03:31:32Z, sha256 BF:61:89:81…, <repo>/.pki/stand/api.crt
|
||||
reissue ingress: missing
|
||||
issued ingress (server, SAN localhost): serial 01A9A23205315927156C54D25B0DFADA, not after 2027-02-14 03:31:32Z, sha256 65:EF:C9:43…, <repo>/.pki/stand/ingress.crt
|
||||
$ make pki_stand
|
||||
infra/pki/pki.sh stand
|
||||
CA exists, unchanged
|
||||
CA: serial 4BD17777A530B84F354BA57FA7509896091A6459, …
|
||||
CRL: next update 2026-12-16 03:31:32Z, <repo>/.pki/stand/crl.pem
|
||||
valid haproxy: serial 01A9A23205315927156C54D25B0DFAD8, not after 2027-02-14 03:31:32Z, sha256 E1:60:8D:30…, <repo>/.pki/stand/haproxy.crt
|
||||
valid api: serial 01A9A23205315927156C54D25B0DFAD9, not after 2027-02-14 03:31:32Z, sha256 BF:61:89:81…, <repo>/.pki/stand/api.crt
|
||||
valid ingress: serial 01A9A23205315927156C54D25B0DFADA, not after 2027-02-14 03:31:32Z, sha256 65:EF:C9:43…, <repo>/.pki/stand/ingress.crt
|
||||
$ git status --ignored --short | grep pki
|
||||
?? infra/pki/
|
||||
!! .pki/
|
||||
$ git ls-files -co --exclude-standard | grep -c '^\.pki'
|
||||
0
|
||||
$ stat -f '%Sp %N' ~/.config/mtusi-lab7/operator .pki/stand
|
||||
drwx------ ~/.config/mtusi-lab7/operator
|
||||
drwx------ .pki/stand
|
||||
```
|
||||
|
||||
## Вывод без ключей
|
||||
|
||||
Весь вывод команд `pki.sh` прогона сценариев собран в один файл:
|
||||
|
||||
```
|
||||
$ wc -l < $S/all-output.txt; grep -c 'PRIVATE KEY' $S/all-output.txt
|
||||
125
|
||||
0
|
||||
```
|
||||
Reference in New Issue
Block a user