Phase 1: identity, sessions, audit, frontend shell
AD sign-in over LDAPS (search with the service account, bind as the user, nested groups through LDAP_MATCHING_RULE_IN_CHAIN, disabled accounts refused), roles as the union of PS-* groups mapped by a table derived from the seeded departments. Server-side sessions with idle, lock and absolute timeouts, Origin and X-Requested-With check, step-up unlock. Optional Argon2id PIN set with the domain password; PIN sign-in by employee ID on registered devices only; five wrong attempts disable the PIN, three wrong at unlock or signature end the session. Rate limits per account and per address before any bind. Devices, signatures table and sign helper, audit rows for every identity event, SSE over LISTEN/NOTIFY with presence. Account settings and Admin APIs and screens (AD view, devices, PIN clearing, group map with missing-group flags, refresh from AD now). CLI ad-groups --list and ad-refresh. Migration 0002. Frontend: real sign-in (password tab, PIN keypad on registered devices), lock screen, role switcher, Account settings, Admin shell, screen placeholders. CI: Samba AD DC container (PSTEST.LOCAL) with a generated CA, 49 of the 50 groups plus one extra, 17 test users; wired into the CI compose overlay and the Gitea workflow; Playwright sign-in scenario. Verified on docker-1: 171 server tests green inside the CI stack against PostgreSQL and the Samba DC, 48 frontend tests, 8 Playwright scenarios against the live stack (password and PIN sign-in, lock and unlock, Admin group map). Findings recorded in the docs: the DC needs CAP_SYS_ADMIN, a hidden tab locks only after a minute as the old build did, and the app uses the alias ps-app for Playwright because "app" is on Chromium's HSTS preload list. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
# Throwaway Samba Active Directory domain controller for CI and local end-to-end runs.
|
||||
# Domain PSTEST.LOCAL. Never used outside the CI stack. Never points at PESCO's AD.
|
||||
# The integrating session may pin this base by digest:
|
||||
# docker buildx imagetools inspect debian:bookworm-slim
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# samba brings samba-tool and its python3 bindings. winbind is started by the DC.
|
||||
# ldb-tools gives ldbmodify for employeeID. openssl makes the CA and the server certificate.
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
samba samba-ad-provision samba-dsdb-modules samba-vfs-modules winbind ldb-tools krb5-user \
|
||||
openssl ca-certificates tini \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -f /etc/samba/smb.conf
|
||||
|
||||
COPY entrypoint.sh seed.sh healthcheck.sh /usr/local/bin/
|
||||
COPY groups.txt /usr/local/share/pstest/groups.txt
|
||||
RUN chmod 0755 /usr/local/bin/entrypoint.sh /usr/local/bin/seed.sh /usr/local/bin/healthcheck.sh
|
||||
|
||||
VOLUME ["/var/lib/samba", "/export"]
|
||||
EXPOSE 389 636
|
||||
|
||||
HEALTHCHECK --interval=10s --timeout=10s --start-period=120s --retries=30 \
|
||||
CMD ["/usr/local/bin/healthcheck.sh"]
|
||||
|
||||
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"]
|
||||
+142
-11
@@ -1,15 +1,146 @@
|
||||
# Samba AD DC for CI (phase 1)
|
||||
# Samba AD DC for CI
|
||||
|
||||
Placeholder. Phase 1 builds a throwaway Samba Active Directory domain controller here
|
||||
so CI and local end-to-end runs exercise real LDAP over TLS.
|
||||
A throwaway Active Directory domain controller for CI and local end-to-end runs. It lets
|
||||
sign-in run over real LDAPS against a real directory without touching PESCO's AD.
|
||||
It is only ever started by `deploy/compose.ci.yaml`. Nothing here is used by the test or
|
||||
production stacks.
|
||||
|
||||
Planned contents:
|
||||
## What it is
|
||||
|
||||
- `Dockerfile` from `debian:bookworm-slim` with samba, provisioned as `PSTEST.LOCAL`.
|
||||
- Its generated CA exported to `deploy/ci/ci-secrets/ca.pem`, which becomes `LDAP_CA_BUNDLE`.
|
||||
- `seed.sh`: the OU tree, the 50 PS-* groups from `packetstation ad-groups --list` (one left
|
||||
out and one extra, to test the reconcile report), and test users per role. Also multi-role,
|
||||
nested, disabled, no-employeeID, duplicate-employeeID and no-role users.
|
||||
- Domain `PSTEST.LOCAL`, NetBIOS `PSTEST`, base `DC=pstest,DC=local`, host `dc1.pstest.local`.
|
||||
- Debian bookworm with the distribution's Samba. Built from `Dockerfile` in this folder.
|
||||
- No published port. The app reaches it on the internal `backend` network as
|
||||
`ldaps://dc1.pstest.local:636`. Port 389 also answers, for STARTTLS tests.
|
||||
- Simple binds work only over TLS (`ldap server require strong auth = allow_sasl_over_tls`).
|
||||
A plain LDAP simple bind is refused, as on PESCO's DCs.
|
||||
|
||||
Open question 15: whether the Gitea runner can run this container (overlayfs xattrs,
|
||||
possibly `SYS_ADMIN`). If not, CI uses a runner with the Docker socket on docker-1.
|
||||
## Files
|
||||
|
||||
| File | Job |
|
||||
|---|---|
|
||||
| `Dockerfile` | Debian bookworm-slim, samba, ldb-tools, openssl, tini. |
|
||||
| `entrypoint.sh` | Provisions on first start, makes the TLS certificates, seeds once, refreshes `/export`, runs samba in the foreground. |
|
||||
| `seed.sh` | OU tree, service account, groups, test users, `users.json`. |
|
||||
| `healthcheck.sh` | Healthy once seeded, exported, and LDAPS verifies against the exported CA. |
|
||||
| `groups.txt` | The 50 group names, a copy of `packetstation ad-groups --list`. A server test keeps them equal. |
|
||||
|
||||
## First start
|
||||
|
||||
1. `samba-tool domain provision` with `--use-rfc2307 --dns-backend=NONE`.
|
||||
The Administrator password comes from the compose secret `samba_admin_password`.
|
||||
Setting the sysvol NT ACLs needs `security.*` xattrs, so the service runs with
|
||||
`cap_add: [SYS_ADMIN]` (verified on docker-1 with Samba 4.17; without it the provision
|
||||
step fails with access denied).
|
||||
2. openssl makes a CA (`PSTEST CI CA`) and a server certificate for `dc1.pstest.local` and
|
||||
`dc1`, valid 10 years, under `/var/lib/samba/private/tls/`. smb.conf points at them.
|
||||
3. The password policy is relaxed: no complexity, no age, no history.
|
||||
4. `seed.sh` runs once against the local `sam.ldb`, before samba starts.
|
||||
5. smb.conf is kept on the data volume (`/var/lib/samba/etc/smb.conf`), so a recreated
|
||||
container starts from the same domain.
|
||||
|
||||
Provisioning and seeding take about one to two minutes. The healthcheck allows 120 seconds of
|
||||
start period and 30 retries after that.
|
||||
|
||||
Later starts skip provisioning and seeding but always refresh the export.
|
||||
|
||||
## What seed.sh creates
|
||||
|
||||
- `OU=PESCO_FARMINGTON` with `OU=Groups`, `OU=Groups` -> `OU=PacketStation`, and `OU=Users`.
|
||||
`OU=Admin` -> `OU=System_Accounts`.
|
||||
- `CN=svc-packetstation,OU=System_Accounts,OU=Admin,DC=pstest,DC=local`. Its password is the
|
||||
`ldap_bind_password` compose secret, the same one the app reads. It never expires.
|
||||
- In `OU=PacketStation`: the 50 groups from `groups.txt` except `PS-14-Electrical-Lead`
|
||||
(missing on purpose), plus `PS-Extra-Legacy` (extra on purpose). Global security groups.
|
||||
- In `OU=Groups`: `Shop-Welders-Nested`, a member of `PS-10-WeldAssembly-Worker`.
|
||||
- In `OU=Users`: the 17 test users from the phase 1 contract. CN is the account name.
|
||||
employeeID and displayName are set with `ldbmodify`. `nested.ned` is only in the nested
|
||||
group. `disabled.dan` is disabled. `noemp.nora` has no employeeID. `dup.dave` and
|
||||
`dup.dina` share 9001. `norole.nick` is in no group.
|
||||
|
||||
Every user gets a new random password on each seed. Nothing secret is committed.
|
||||
|
||||
## The export volume
|
||||
|
||||
The DC writes to the `ci-dc-export` volume, mounted at `/export`:
|
||||
|
||||
- `ca.pem`: the CI CA. migrate, app and worker mount the volume at `/etc/ssl/pstest`, and
|
||||
`ci.env` sets `LDAP_CA_BUNDLE=/etc/ssl/pstest/ca.pem`.
|
||||
- `users.json`: the test accounts, mode 0444.
|
||||
`{"domain": "pstest.local", "users": {"<sam>": {"password", "emp_no", "display_name"}}}`.
|
||||
`emp_no` is `null` for `noemp.nora`.
|
||||
- `seeded`: the time of the seed. The healthcheck waits for it.
|
||||
|
||||
The Playwright service mounts the same volume read-only and reads `E2E_DC_USERS_FILE`.
|
||||
|
||||
## Running the CI stack on docker-1
|
||||
|
||||
From the repository root:
|
||||
|
||||
```bash
|
||||
bash deploy/ci/make-secrets.sh
|
||||
CI="docker compose -p packetstation-ci --env-file deploy/ci/ci.env -f deploy/compose.yaml -f deploy/compose.ci.yaml"
|
||||
$CI up -d --build --wait --wait-timeout 300
|
||||
$CI --profile e2e run --rm playwright # report in tests/e2e/playwright-report
|
||||
$CI logs samba-dc # provisioning and seeding log, no secrets
|
||||
$CI --profile e2e down -v
|
||||
```
|
||||
|
||||
To run the server's DC-backed tests from docker-1 against this DC, copy the export out:
|
||||
|
||||
```bash
|
||||
mkdir -p tests/fixtures/local/dc
|
||||
docker run --rm -v packetstation-ci_ci-dc-export:/export:ro -v "$PWD/tests/fixtures/local/dc:/out" \
|
||||
debian:bookworm-slim cp /export/ca.pem /export/users.json /out/
|
||||
```
|
||||
|
||||
`tests/fixtures/local/` is ignored by git. The DC publishes no port, so those tests must run in
|
||||
a container on the stack's `backend` network (for example `$CI run --rm --entrypoint pytest app`
|
||||
with the tests mounted), with `TEST_LDAP_URL=ldaps://dc1.pstest.local:636`,
|
||||
`TEST_DC_USERS_FILE` and the other `TEST_LDAP_*` values set.
|
||||
|
||||
## What CI does today
|
||||
|
||||
- The `e2e` job in `.gitea/workflows/ci.yml` builds this DC with the stack, runs the
|
||||
Playwright scenarios in `tests/e2e/`, uploads the report and tears down with `down -v`.
|
||||
- The `server` job does not start the DC. Its DC-backed tests skip because `TEST_LDAP_URL`
|
||||
is unset. Follow-up: run them against the DC, either as a job service or inside the e2e stack.
|
||||
|
||||
## Running the server suite against the DC by hand
|
||||
|
||||
On docker-1, with the CI stack up, run the suite from a container on the stack's `backend`
|
||||
network (it is internal, so bake pytest into a derived image first):
|
||||
|
||||
```bash
|
||||
printf "FROM packetstation:ci
|
||||
USER root
|
||||
RUN pip install -q pytest==9.1.1 anyio==4.15.1
|
||||
" | docker build -q -t packetstation:ci-test -
|
||||
docker run --rm --user root --network packetstation-ci_backend -v "$PWD/tests:/work/tests:ro" -v "$PWD/pyproject.toml:/work/pyproject.toml:ro" -v "$PWD/server:/work/server:ro" -v "$PWD/deploy/samba/groups.txt:/work/deploy/samba/groups.txt:ro" -v packetstation-ci_ci-dc-export:/export:ro -v "$PWD/deploy/ci/ci-secrets:/secrets:ro" -w /work -e STACK=ci -e TEST_LDAP_URL=ldaps://dc1.pstest.local:636 -e TEST_LDAP_BASE_DN=DC=pstest,DC=local -e TEST_LDAP_BIND_DN=CN=svc-packetstation,OU=System_Accounts,OU=Admin,DC=pstest,DC=local -e TEST_LDAP_PASSWORD_FILE=/secrets/ldap_bind_password -e TEST_LDAP_GROUP_BASE_DN=OU=PacketStation,OU=Groups,OU=PESCO_FARMINGTON,DC=pstest,DC=local -e TEST_LDAP_CA_BUNDLE=/export/ca.pem -e TEST_DC_USERS_FILE=/export/users.json -e TEST_PG_SUPERUSER_URL=postgresql://postgres:PW@some-other-postgres:5432/postgres --entrypoint python packetstation:ci-test -m pytest -q
|
||||
```
|
||||
|
||||
Point `TEST_PG_SUPERUSER_URL` at a throwaway PostgreSQL, never at the stack's own. The
|
||||
`pg_settings` fixture resets the `ps_app` and `ps_migrate` passwords on the server it is given,
|
||||
which breaks the running app and worker (seen on docker-1 on 2026-10-16; `down -v` and `up`
|
||||
repair it). Omit the variable to run only the DC tests that need no database.
|
||||
|
||||
## Open question 15
|
||||
|
||||
Whether the Gitea runner can run this container. Status: verified on docker-1 (Docker 29,
|
||||
Ubuntu 24.04) on 2026-10-16; not yet tried on the Gitea runner.
|
||||
|
||||
What it needs:
|
||||
|
||||
- A Docker daemon that can run a root container with `cap_add: [SYS_ADMIN]`. Provisioning
|
||||
sets NT ACLs on sysvol, which needs `security.*` xattrs; without the capability Samba 4.17
|
||||
fails with access denied (tried on docker-1). The volume's filesystem must support xattrs
|
||||
and POSIX ACLs (ext4 and xfs under `/var/lib/docker/volumes` do). If provisioning fails,
|
||||
the provision log tail is printed in `$CI logs samba-dc`.
|
||||
- Debian bookworm's `samba-ad-provision` package, which the Dockerfile installs (the schema
|
||||
files live there, not in `samba`).
|
||||
- Bind mounts that resolve. The base stack bind-mounts `deploy/ci/ci-secrets/` (secrets),
|
||||
`deploy/postgres/initdb` and `tests/e2e`. If act_runner runs the job inside a container that
|
||||
talks to the host daemon through its socket, those paths must exist on the host at the same
|
||||
place. If they do not, use a runner on docker-1 in host mode, or one whose workdir is
|
||||
mounted at the same path on the host.
|
||||
- Outbound HTTPS from the playwright container to the npm registry and from the builder to
|
||||
the Debian mirrors.
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env bash
|
||||
# Samba AD DC for CI. Provisions PSTEST.LOCAL on first start, makes the TLS certificates,
|
||||
# seeds the OU tree, groups and users once, refreshes /export, then runs samba in the foreground.
|
||||
# Never prints a password. Run as root (Samba needs it). tini is PID 1.
|
||||
set -euo pipefail
|
||||
|
||||
REALM=PSTEST.LOCAL
|
||||
DOMAIN=PSTEST
|
||||
HOST=dc1
|
||||
FQDN=dc1.pstest.local
|
||||
STATE=/var/lib/samba
|
||||
PRIVATE=$STATE/private
|
||||
TLS=$PRIVATE/tls
|
||||
CONF_DIR=$STATE/etc # smb.conf lives on the volume so it survives a recreated container
|
||||
CONF=$CONF_DIR/smb.conf
|
||||
EXPORT=/export
|
||||
ADMIN_SECRET=/run/secrets/samba_admin_password
|
||||
|
||||
log() { echo "samba-dc: $*"; }
|
||||
|
||||
read_secret() {
|
||||
# One line, CR stripped. Never echoed.
|
||||
local f=$1
|
||||
if [ ! -s "$f" ]; then
|
||||
log "missing or empty secret file $f" >&2
|
||||
exit 1
|
||||
fi
|
||||
head -n 1 "$f" | tr -d '\r\n'
|
||||
}
|
||||
|
||||
make_tls() {
|
||||
log "making the CI CA and the server certificate"
|
||||
mkdir -p "$TLS"
|
||||
local tmp
|
||||
tmp=$(mktemp -d)
|
||||
openssl req -x509 -new -nodes -newkey rsa:3072 -sha256 -days 3650 \
|
||||
-keyout "$TLS/ca.key" -out "$TLS/ca.pem" -subj "/CN=PSTEST CI CA" \
|
||||
-addext "basicConstraints=critical,CA:TRUE" \
|
||||
-addext "keyUsage=critical,keyCertSign,cRLSign" \
|
||||
-addext "subjectKeyIdentifier=hash" 2>/dev/null
|
||||
openssl req -new -nodes -newkey rsa:3072 -sha256 \
|
||||
-keyout "$TLS/key.pem" -out "$tmp/server.csr" -subj "/CN=$FQDN" 2>/dev/null
|
||||
cat > "$tmp/server.ext" <<EXT
|
||||
basicConstraints=critical,CA:FALSE
|
||||
keyUsage=critical,digitalSignature,keyEncipherment
|
||||
extendedKeyUsage=serverAuth
|
||||
subjectAltName=DNS:$FQDN,DNS:$HOST
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid,issuer
|
||||
EXT
|
||||
openssl x509 -req -sha256 -days 3650 -in "$tmp/server.csr" \
|
||||
-CA "$TLS/ca.pem" -CAkey "$TLS/ca.key" -CAcreateserial -CAserial "$tmp/ca.srl" \
|
||||
-extfile "$tmp/server.ext" -out "$TLS/cert.pem" 2>/dev/null
|
||||
rm -rf "$tmp"
|
||||
# Samba refuses a private key that others can read.
|
||||
chmod 0600 "$TLS/key.pem" "$TLS/ca.key"
|
||||
chmod 0644 "$TLS/ca.pem" "$TLS/cert.pem"
|
||||
openssl verify -CAfile "$TLS/ca.pem" "$TLS/cert.pem" >/dev/null
|
||||
}
|
||||
|
||||
set_global() {
|
||||
# Add lines right after [global] in smb.conf.
|
||||
local line
|
||||
for line in "$@"; do
|
||||
sed -i "/^\[global\]/a $line" "$CONF"
|
||||
done
|
||||
}
|
||||
|
||||
provision() {
|
||||
log "provisioning $REALM (first start)"
|
||||
local adminpass
|
||||
adminpass=$(read_secret "$ADMIN_SECRET")
|
||||
rm -f /etc/samba/smb.conf
|
||||
mkdir -p "$CONF_DIR"
|
||||
# The sysvol ACL step needs security.* xattrs, so the container runs with CAP_SYS_ADMIN
|
||||
# (compose.ci.yaml). Samba 4.17 has no --use-xattrs option. --dns-backend=NONE: the stack
|
||||
# resolves names itself.
|
||||
samba-tool domain provision \
|
||||
--use-rfc2307 \
|
||||
--realm="$REALM" \
|
||||
--domain="$DOMAIN" \
|
||||
--host-name="$HOST" \
|
||||
--server-role=dc \
|
||||
--dns-backend=NONE \
|
||||
--adminpass="$adminpass" >/var/log/samba-provision.log 2>&1 || {
|
||||
log "provision failed; last lines of the log follow" >&2
|
||||
tail -n 40 /var/log/samba-provision.log >&2
|
||||
exit 1
|
||||
}
|
||||
unset adminpass
|
||||
mv /etc/samba/smb.conf "$CONF"
|
||||
ln -sf "$CONF" /etc/samba/smb.conf
|
||||
|
||||
make_tls
|
||||
# Simple binds only over TLS (LDAPS or STARTTLS), like PESCO's DCs. Plain LDAP simple binds fail.
|
||||
set_global \
|
||||
"ldap server require strong auth = allow_sasl_over_tls" \
|
||||
"tls keyfile = $TLS/key.pem" \
|
||||
"tls certfile = $TLS/cert.pem" \
|
||||
"tls cafile = $TLS/ca.pem" \
|
||||
"tls enabled = yes"
|
||||
|
||||
# Relaxed policy: CI passwords are random per run and never change.
|
||||
samba-tool domain passwordsettings set \
|
||||
--complexity=off --min-pwd-age=0 --max-pwd-age=0 --history-length=0 >/dev/null
|
||||
cp "$PRIVATE/krb5.conf" /etc/krb5.conf 2>/dev/null || true
|
||||
log "provisioned"
|
||||
}
|
||||
|
||||
if [ ! -f "$PRIVATE/sam.ldb" ]; then
|
||||
provision
|
||||
else
|
||||
log "already provisioned; skipping"
|
||||
ln -sf "$CONF" /etc/samba/smb.conf
|
||||
cp "$PRIVATE/krb5.conf" /etc/krb5.conf 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Seed once, offline, before samba starts. samba-tool writes sam.ldb directly.
|
||||
if [ ! -f "$PRIVATE/.seeded" ]; then
|
||||
/usr/local/bin/seed.sh
|
||||
date -u +%Y-%m-%dT%H:%M:%SZ > "$PRIVATE/.seeded"
|
||||
else
|
||||
log "already seeded; skipping"
|
||||
fi
|
||||
|
||||
# Refresh the export on every start: the CA, the users file and the seeded marker.
|
||||
mkdir -p "$EXPORT"
|
||||
chmod 0755 "$EXPORT"
|
||||
rm -f "$EXPORT/seeded"
|
||||
install -m 0444 "$TLS/ca.pem" "$EXPORT/ca.pem"
|
||||
install -m 0444 "$PRIVATE/users.json" "$EXPORT/users.json"
|
||||
cp "$PRIVATE/.seeded" "$EXPORT/seeded"
|
||||
chmod 0444 "$EXPORT/seeded"
|
||||
log "exported ca.pem and users.json to $EXPORT"
|
||||
|
||||
log "starting samba"
|
||||
exec samba -i -F --no-process-group
|
||||
@@ -0,0 +1,50 @@
|
||||
PS-Admins
|
||||
PS-Clerical
|
||||
PS-Clerical-Supervisor
|
||||
PS-Warehouse
|
||||
PS-Warehouse-Supervisor
|
||||
PS-QC
|
||||
PS-QC-Supervisor
|
||||
PS-ProjectMgmt
|
||||
PS-01-Layout-Worker
|
||||
PS-01-Layout-Lead
|
||||
PS-01-Layout-Supervisor
|
||||
PS-02-SouthLayout-Worker
|
||||
PS-02-SouthLayout-Lead
|
||||
PS-02-SouthLayout-Supervisor
|
||||
PS-03-WeldParts-Worker
|
||||
PS-03-WeldParts-Lead
|
||||
PS-03-WeldParts-Supervisor
|
||||
PS-04-SouthWeld-Worker
|
||||
PS-04-SouthWeld-Lead
|
||||
PS-04-SouthWeld-Supervisor
|
||||
PS-05-SouthWeldSS-Worker
|
||||
PS-05-SouthWeldSS-Lead
|
||||
PS-05-SouthWeldSS-Supervisor
|
||||
PS-06-CodeBldg2-Worker
|
||||
PS-06-CodeBldg2-Lead
|
||||
PS-06-CodeBldg2-Supervisor
|
||||
PS-07-CodeBldg3-Worker
|
||||
PS-07-CodeBldg3-Lead
|
||||
PS-07-CodeBldg3-Supervisor
|
||||
PS-08-Subassembly-Worker
|
||||
PS-08-Subassembly-Lead
|
||||
PS-08-Subassembly-Supervisor
|
||||
PS-09-Hydro-Worker
|
||||
PS-09-Hydro-Lead
|
||||
PS-09-Hydro-Supervisor
|
||||
PS-10-WeldAssembly-Worker
|
||||
PS-10-WeldAssembly-Lead
|
||||
PS-10-WeldAssembly-Supervisor
|
||||
PS-11-FinalAssyNorth-Worker
|
||||
PS-11-FinalAssyNorth-Lead
|
||||
PS-11-FinalAssyNorth-Supervisor
|
||||
PS-12-FinalAssySouth-Worker
|
||||
PS-12-FinalAssySouth-Lead
|
||||
PS-12-FinalAssySouth-Supervisor
|
||||
PS-13-PaintSandblast-Worker
|
||||
PS-13-PaintSandblast-Lead
|
||||
PS-13-PaintSandblast-Supervisor
|
||||
PS-14-Electrical-Worker
|
||||
PS-14-Electrical-Lead
|
||||
PS-14-Electrical-Supervisor
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# Healthy only when the domain is seeded, the export is written and LDAPS answers
|
||||
# with a certificate that verifies against the exported CA for dc1.pstest.local.
|
||||
set -eu
|
||||
|
||||
test -f /export/seeded
|
||||
test -s /export/ca.pem
|
||||
test -s /export/users.json
|
||||
|
||||
# TLS on 636: the handshake must verify the chain and the host name.
|
||||
openssl s_client -connect 127.0.0.1:636 -servername dc1.pstest.local \
|
||||
-CAfile /export/ca.pem -verify_hostname dc1.pstest.local -verify_return_error \
|
||||
</dev/null >/dev/null 2>&1
|
||||
|
||||
# The directory answers: the service account exists in the seeded tree.
|
||||
ldbsearch -H /var/lib/samba/private/sam.ldb \
|
||||
-b "OU=System_Accounts,OU=Admin,DC=pstest,DC=local" \
|
||||
"(sAMAccountName=svc-packetstation)" dn 2>/dev/null | grep -q '^dn: '
|
||||
@@ -0,0 +1,167 @@
|
||||
#!/usr/bin/env bash
|
||||
# Seed the CI domain: the OU tree, the service account, the PS-* groups and the test users.
|
||||
# Runs once from entrypoint.sh, before samba starts, against the local sam.ldb.
|
||||
# Safe to rerun: "already exists" is ignored and every user gets a new random password.
|
||||
# Never prints a password. Writes $PRIVATE/users.json (0600); the entrypoint exports it.
|
||||
set -euo pipefail
|
||||
|
||||
BASE="DC=pstest,DC=local"
|
||||
PRIVATE=/var/lib/samba/private
|
||||
SAM=$PRIVATE/sam.ldb
|
||||
GROUPS_FILE=/usr/local/share/pstest/groups.txt
|
||||
BIND_SECRET=/run/secrets/ldap_bind_password
|
||||
PS_OU="OU=PacketStation,OU=Groups,OU=PESCO_FARMINGTON"
|
||||
USERS_OU="OU=Users,OU=PESCO_FARMINGTON"
|
||||
MISSING_GROUP="PS-14-Electrical-Lead" # left out on purpose: the reconcile report must flag it
|
||||
EXTRA_GROUP="PS-Extra-Legacy" # added on purpose: the reconcile report must list it
|
||||
NESTED_GROUP="Shop-Welders-Nested"
|
||||
|
||||
log() { echo "samba-dc seed: $*"; }
|
||||
|
||||
# Run a command. Ignore "already exists". On any other failure show its output and stop.
|
||||
# Callers never pass a password in a way that ends up in this output.
|
||||
try() {
|
||||
local out
|
||||
if out=$("$@" 2>&1); then
|
||||
return 0
|
||||
fi
|
||||
if printf '%s' "$out" | grep -qiE 'already exists|ENTRY_ALREADY_EXISTS|already a member'; then
|
||||
return 0
|
||||
fi
|
||||
log "failed: $1 $2 $3" >&2
|
||||
printf '%s\n' "$out" | sed 's/^/ /' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
add_ou() {
|
||||
local dn="$1,$BASE"
|
||||
local ldif
|
||||
ldif=$(mktemp)
|
||||
printf 'dn: %s\nobjectClass: top\nobjectClass: organizationalUnit\n' "$dn" > "$ldif"
|
||||
try ldbadd -H "$SAM" "$ldif"
|
||||
rm -f "$ldif"
|
||||
}
|
||||
|
||||
random_password() {
|
||||
# 24 random base64 characters plus a fixed tail with upper, lower, digit and symbol.
|
||||
printf '%s-Pa9' "$(openssl rand -base64 18 | tr -d '\n')"
|
||||
}
|
||||
|
||||
set_password() {
|
||||
# $1 sam, $2 password. Not logged. Visible only inside this container's process list.
|
||||
try samba-tool user setpassword "$1" --newpassword="$2"
|
||||
}
|
||||
|
||||
set_attrs() {
|
||||
# $1 dn, $2 display name, $3 employeeID or empty.
|
||||
local ldif
|
||||
ldif=$(mktemp)
|
||||
{
|
||||
printf 'dn: %s\nchangetype: modify\n' "$1"
|
||||
printf 'replace: displayName\ndisplayName: %s\n-\n' "$2"
|
||||
if [ -n "$3" ]; then
|
||||
printf 'replace: employeeID\nemployeeID: %s\n-\n' "$3"
|
||||
fi
|
||||
} > "$ldif"
|
||||
try ldbmodify -H "$SAM" "$ldif"
|
||||
rm -f "$ldif"
|
||||
}
|
||||
|
||||
# ---- OU tree, mirroring PESCO ----
|
||||
log "OU tree"
|
||||
add_ou "OU=PESCO_FARMINGTON"
|
||||
add_ou "OU=Groups,OU=PESCO_FARMINGTON"
|
||||
add_ou "$PS_OU"
|
||||
add_ou "$USERS_OU"
|
||||
add_ou "OU=Admin"
|
||||
add_ou "OU=System_Accounts,OU=Admin"
|
||||
|
||||
# ---- Service account (password = the app's ldap_bind_password secret) ----
|
||||
log "service account svc-packetstation"
|
||||
if [ ! -s "$BIND_SECRET" ]; then
|
||||
log "missing or empty secret file $BIND_SECRET" >&2
|
||||
exit 1
|
||||
fi
|
||||
try samba-tool user create svc-packetstation --random-password --use-username-as-cn \
|
||||
--userou="OU=System_Accounts,OU=Admin" --description="Packet Station service account (CI)"
|
||||
set_password svc-packetstation "$(head -n 1 "$BIND_SECRET" | tr -d '\r\n')"
|
||||
try samba-tool user setexpiry svc-packetstation --noexpiry
|
||||
|
||||
# ---- Groups ----
|
||||
log "PacketStation groups"
|
||||
count=0
|
||||
while IFS= read -r name || [ -n "$name" ]; do
|
||||
name=$(printf '%s' "$name" | tr -d '\r' | sed 's/[[:space:]]*$//')
|
||||
[ -z "$name" ] && continue
|
||||
[ "$name" = "$MISSING_GROUP" ] && continue
|
||||
try samba-tool group add "$name" --groupou="$PS_OU" \
|
||||
--group-scope=Global --group-type=Security --description="Packet Station: $name"
|
||||
count=$((count + 1))
|
||||
done < "$GROUPS_FILE"
|
||||
try samba-tool group add "$EXTRA_GROUP" --groupou="$PS_OU" \
|
||||
--group-scope=Global --group-type=Security --description="Packet Station: $EXTRA_GROUP"
|
||||
try samba-tool group add "$NESTED_GROUP" --groupou="OU=Groups,OU=PESCO_FARMINGTON" \
|
||||
--group-scope=Global --group-type=Security --description="Helper group for the nested membership test"
|
||||
try samba-tool group addmembers PS-10-WeldAssembly-Worker "$NESTED_GROUP"
|
||||
log "created $count mapped groups (without $MISSING_GROUP), plus $EXTRA_GROUP and $NESTED_GROUP"
|
||||
|
||||
# ---- Users: sam|given|surname|employeeID|groups (comma separated) ----
|
||||
ROSTER='admin.ann|Ann|Admin|1001|PS-Admins
|
||||
clerk.clara|Clara|Clerk|4001|PS-Clerical
|
||||
clerk.leo|Leo|Lead|4002|PS-Clerical-Supervisor
|
||||
wh.wade|Wade|Warehouse|6001|PS-Warehouse
|
||||
qc.quinn|Quinn|QC|5001|PS-QC
|
||||
pm.paula|Paula|PM|7001|PS-ProjectMgmt
|
||||
weld.andy|Andy|Welder|3003|PS-03-WeldParts-Worker
|
||||
lead.lou|Lou|Lead|3002|PS-03-WeldParts-Lead
|
||||
sup.wes|Wes|Super|2003|PS-03-WeldParts-Supervisor
|
||||
multi.mia|Mia|Multi|2006|PS-Clerical,PS-06-CodeBldg2-Supervisor
|
||||
nested.ned|Ned|Nested|3010|Shop-Welders-Nested
|
||||
both.bo|Bo|Both|3011|PS-03-WeldParts-Worker,PS-03-WeldParts-Supervisor
|
||||
disabled.dan|Dan|Disabled|3004|PS-03-WeldParts-Worker
|
||||
noemp.nora|Nora|NoEmp||PS-Warehouse
|
||||
dup.dave|Dave|Dup|9001|PS-03-WeldParts-Worker
|
||||
dup.dina|Dina|Dup|9001|PS-Warehouse
|
||||
norole.nick|Nick|NoRole|8001|'
|
||||
|
||||
umask 077
|
||||
rows=$(mktemp) # sam, password, emp, display; tab separated; 0600; removed below
|
||||
log "users"
|
||||
while IFS='|' read -r sam given surname emp groups; do
|
||||
[ -z "$sam" ] && continue
|
||||
display="$given $surname"
|
||||
dn="CN=$sam,$USERS_OU,$BASE"
|
||||
try samba-tool user create "$sam" --random-password --use-username-as-cn \
|
||||
--userou="$USERS_OU" --given-name="$given" --surname="$surname" \
|
||||
--mail-address="$sam@pstest.local"
|
||||
pw=$(random_password)
|
||||
set_password "$sam" "$pw"
|
||||
set_attrs "$dn" "$display" "$emp"
|
||||
if [ -n "$groups" ]; then
|
||||
IFS=',' read -r -a list <<< "$groups"
|
||||
for g in "${list[@]}"; do
|
||||
try samba-tool group addmembers "$g" "$sam"
|
||||
done
|
||||
fi
|
||||
printf '%s\t%s\t%s\t%s\n' "$sam" "$pw" "$emp" "$display" >> "$rows"
|
||||
unset pw
|
||||
log " $sam"
|
||||
done <<< "$ROSTER"
|
||||
|
||||
try samba-tool user disable disabled.dan
|
||||
|
||||
# ---- users.json, the format in the phase 1 contract ----
|
||||
python3 - "$rows" "$PRIVATE/users.json" <<'PY'
|
||||
import json, sys
|
||||
users = {}
|
||||
with open(sys.argv[1], encoding="utf-8") as f:
|
||||
for line in f:
|
||||
sam, password, emp, display = line.rstrip("\n").split("\t")
|
||||
users[sam] = {"password": password, "emp_no": emp or None, "display_name": display}
|
||||
with open(sys.argv[2], "w", encoding="utf-8") as f:
|
||||
json.dump({"domain": "pstest.local", "users": users}, f, indent=2, sort_keys=True)
|
||||
f.write("\n")
|
||||
PY
|
||||
rm -f "$rows"
|
||||
chmod 0600 "$PRIVATE/users.json"
|
||||
log "done: $(grep -c '"password"' "$PRIVATE/users.json") users written to users.json"
|
||||
Reference in New Issue
Block a user