add an ssh ca to bao, agent ssh certificates and a target module
This commit is contained in:
parent
ac01ef1bdb
commit
0afb111862
1 changed files with 1056 additions and 17 deletions
|
|
@ -182,6 +182,7 @@ let
|
|||
"swarm-bao-services-issuer-policy"
|
||||
"swarm-bao-nats-tls-policy"
|
||||
"swarm-bao-agent-pki"
|
||||
"swarm-bao-agent-ssh-policy"
|
||||
"swarm-bao-nats-auth-policy"
|
||||
"swarm-bao-operator-viewer-policy"
|
||||
"swarm-bao-hive-leaf-policy"
|
||||
|
|
@ -1340,7 +1341,7 @@ let
|
|||
{
|
||||
# The granter's grants, whole. Pinned as the full list, because an added
|
||||
# path or capability is exactly what a presence check misses.
|
||||
name = "the granter's policy is exactly these twenty stanzas";
|
||||
name = "the granter's policy is exactly these twenty-four stanzas";
|
||||
ok =
|
||||
let
|
||||
cu = [
|
||||
|
|
@ -1420,6 +1421,22 @@ let
|
|||
path = "pki-agents/roles/swarm-*";
|
||||
caps = cu;
|
||||
}
|
||||
{
|
||||
path = "sys/mounts/ssh-agents";
|
||||
caps = cu;
|
||||
}
|
||||
{
|
||||
path = "ssh-agents/issuers";
|
||||
caps = [ "list" ];
|
||||
}
|
||||
{
|
||||
path = "ssh-agents/config/ca";
|
||||
caps = cu;
|
||||
}
|
||||
{
|
||||
path = "ssh-agents/roles/swarm-*";
|
||||
caps = cu;
|
||||
}
|
||||
{
|
||||
path = "auth/oidc/config";
|
||||
caps = cu;
|
||||
|
|
@ -2806,6 +2823,94 @@ let
|
|||
&& !(lib.any (a: !a.assertion && names a) baoGrantHere.assertions);
|
||||
}
|
||||
|
||||
{
|
||||
# The SSH CA is the trust every target machine holds by value, so it is
|
||||
# made once, only when the mount lists no issuer, and the granter can
|
||||
# neither read it back nor delete it. The presence arms: the same unit
|
||||
# does write the mount, the CA and the role.
|
||||
name = "the agent SSH CA is generated once from an ed25519 key, only when the mount has no issuer, and nothing deletes it";
|
||||
ok =
|
||||
let
|
||||
s = baoGrantHere.systemd.services.swarm-bao-agent-ssh-policy.script;
|
||||
generate = "ssh-agents/config/ca";
|
||||
in
|
||||
lib.length (lib.splitString generate s) == 2
|
||||
&& lib.hasInfix "generate_signing_key=true" s
|
||||
&& lib.hasInfix "key_type=ssh-ed25519" s
|
||||
&& lib.hasInfix "bao secrets enable -path=ssh-agents ssh" s
|
||||
&& lib.hasInfix "elif [ \"$issuers\" = '{}' ]; then" s
|
||||
&& !(lib.hasInfix "bao delete" s)
|
||||
&&
|
||||
(grantFor granterGrants "ssh-agents/config/ca").caps == [
|
||||
"create"
|
||||
"update"
|
||||
]
|
||||
&& grantFor granterGrants "ssh-agents/sign/swarm-agent" == null
|
||||
&& grantFor granterGrants "ssh-agents/roles/other" == null;
|
||||
}
|
||||
{
|
||||
# What keeps an agent from a certificate for another agent: the
|
||||
# principal is the caller's entity name, requested or not, and the role
|
||||
# signs nothing but ed25519 user keys with one extension. The role is
|
||||
# a single JSON document, so each fragment below is one property of it.
|
||||
name = "the agent SSH role names the caller's own entity as the only principal, signs ed25519 user keys for an hour, and one unit writes it";
|
||||
ok =
|
||||
let
|
||||
s = baoGrantHere.systemd.services.swarm-bao-agent-ssh-policy.script;
|
||||
roleWriters = lib.filter (u: matches "bao write '?ssh-agents/roles/" (u.script or "") != [ ]) (
|
||||
lib.attrValues baoGrantHere.systemd.services
|
||||
);
|
||||
in
|
||||
lib.all (t: lib.hasInfix t s) [
|
||||
''"allowed_users":"{{identity.entity.name}}"''
|
||||
''"allowed_users_template":true''
|
||||
''"default_user":"{{identity.entity.name}}"''
|
||||
''"default_user_template":true''
|
||||
''"allow_user_certificates":true''
|
||||
''"allow_host_certificates":false''
|
||||
''"allow_user_key_ids":false''
|
||||
''"allowed_user_key_lengths":{"ssh-ed25519":0}''
|
||||
''"allowed_extensions":"permit-pty"''
|
||||
''"key_type":"ca"''
|
||||
''"ttl":"60m"''
|
||||
''"max_ttl":"180m"''
|
||||
"bao write ssh-agents/roles/swarm-agent -"
|
||||
]
|
||||
&& lib.length roleWriters == 1;
|
||||
}
|
||||
{
|
||||
# The agents' `update` on the sign path comes from the shared agent
|
||||
# policy (swarm-secret-client), not from a unit here. Of the policies
|
||||
# these units write, only the granter's names the mount: the controller,
|
||||
# which writes the shared one, holds nothing on it.
|
||||
name = "of the policies the host writes, only the granter's has a grant on the agent SSH mount";
|
||||
ok =
|
||||
let
|
||||
cg = grantsIn baoGrantHere.systemd.services.swarm-bao-controller-policy.script;
|
||||
onMount = lib.filter (g: lib.hasPrefix "ssh-agents" g.path);
|
||||
in
|
||||
onMount cg == [ ]
|
||||
# The control: the granter's grants do name the mount.
|
||||
&& onMount granterGrants != [ ]
|
||||
&& lib.all (u: onMount (grantsIn baoGrantHere.systemd.services.${u}.script) == [ ]) (
|
||||
lib.filter (u: u != "swarm-bao-agent-ssh-policy") grantingUnitNames
|
||||
);
|
||||
}
|
||||
{
|
||||
# The shared agent policy (swarm-secret-client) names the mount and the
|
||||
# role; the unit above and the agent module spell the same two strings
|
||||
# from ../host-modules/lib/ssh-agent-ca.nix.
|
||||
name = "the SSH mount and role the shared agent policy names are the ones the swarm writes";
|
||||
ok =
|
||||
let
|
||||
ca = import ../host-modules/lib/ssh-agent-ca.nix { };
|
||||
policy = builtins.readFile ../../swarm-secret-client/src/policy.rs;
|
||||
in
|
||||
lib.hasInfix ''pub const SSH_MOUNT: &str = "${ca.mountPath}";'' policy
|
||||
&& lib.hasInfix ''pub const SSH_ROLE: &str = "${ca.roleName}";'' policy
|
||||
&& lib.hasInfix "bao write ssh-agents/roles/${ca.roleName} -" baoGrantHere.systemd.services.swarm-bao-agent-ssh-policy.script;
|
||||
}
|
||||
|
||||
# ── the UI's OIDC login ─────────────────────────────────────────────────
|
||||
{
|
||||
# What an `admins` login through the UI holds: the key tree, KV
|
||||
|
|
|
|||
Loading…
Reference in a new issue