routeros: read-only monitoring users + api-ssl, two-slot rotation published by Terraform (#139) #143

Merged
ginjiruu merged 3 commits from routeros-monitoring-user into master 2026-11-17 21:21:45 +00:00
Owner

The router half of #139, on the design recorded in the new ADR-0011 (orchestration across GitOps loops: converge first, a controller last). The first draft, which used an ESO generator and PushSecret, is replaced. It had a login-failure window on every rotation and needed the repos merged in a fixed order.

Design (routeros/modules/monitoring, called by all three roots)

  • Two read-only users per device, monitoring-a and monitoring-b, in group monitoring (policy read,api). Login, and api-ssl on 8729, are allowed only from mini's pod pool 10.44.0.0/16. The service uses the device's www-ssl cert.

  • They rotate alternately. The period is v = floor(plantimestamp / 15d): slot a holds the last even v, slot b the last odd one. Every plan agrees on these numbers without storing anything, and each slot keeps working for a full period after the other one rotates.

  • One writer, in graph order. For the slot that rotates:

    1. an ephemeral random_password goes to OpenBao secret/routeros-monitoring/<dev>/<slot> (write-only data_json_wo);
    2. the router gets what OpenBao holds, through an ephemeral read and the provider's write-only password_wo;
    3. only then is <dev>/active pointed at that slot.

    A retry after a partial failure re-sends the stored value, and active always names a slot the router accepts.

  • No password in state or plans. No runner env. No dependency on the clusters repo for merge order.

Other changes

  • vault/runners-k8s.tf: new policy runner-routeros-monitoring (create/read/update/delete on secret/routeros-monitoring/* only) added to role tf-routeros.
  • vault/eso-mini.tf: ESO gets read-only access to secret/routeros-monitoring/*.
  • crs309 root: gets the vault provider, with the same ServiceAccount JWT login as the routers. The sim provider override gets it too.
  • Roots: required_version >= 1.11, plus random ~> 3.7 and time ~> 0.11.
  • render.py and gate.sh: the users and the OpenBao entries are gate-allowlisted creates. /user is never rendered and is skipped by coverage. The gate checks api-ssl's address restriction (available-from on RouterOS 7.25) and that both slot users exist. lib.sh points the sim at the harness's infra KV mount and adds ROUTEROS_TOFURC for testing unreleased provider builds.
  • Docs: docs/routeros/README.md, docs/adr/0011-orchestration-layers.md, and the guard header.

Tests

  • Module on a CHR with a dev OpenBao, PASS:
    1. First apply: both slots log in over the binary API, and no password is in state.
    2. Re-plan in the same period: empty.
    3. Next period: only slot b rotates. The old slot a still works, and the old b password is refused and absent from the saved plan.
    4. Partial failure, using -target to write OpenBao only: active doesn't move and the router is unchanged; the retry sends exactly OpenBao's value.
    5. Converged.
  • Round-trip gate PASS for rb5009-a (208 objects imported with no change, residue a no-op, converged, coverage PASS) and crs309 (24). tofu validate passes for all three roots. The gate used provider 1.99.1004 through dev_overrides, with the module constraint relaxed locally only, because the locks still pin 1.99.1003.

Before merge

  1. Publish provider 1.99.1004 (lab/release.sh 1.99.1004; tag v1.99.1004 is pushed, and the registry push needs a package-writing token).
  2. Relock the three roots on this branch (tofu init -upgrade with routeros/tofu.rc): routeros 1.99.1004, plus random and time.
  3. Then merge. The openbao-config root applies the policies. Each router root, on its next interval, writes OpenBao and creates the users and api-ssl, one rb5009 at a time (fuse). lab/clusters#1720 can merge in either order.
The router half of #139, on the design recorded in the new **ADR-0011** (orchestration across GitOps loops: converge first, a controller last). The first draft, which used an ESO generator and PushSecret, is replaced. It had a login-failure window on every rotation and needed the repos merged in a fixed order. ## Design (`routeros/modules/monitoring`, called by all three roots) - Two read-only users per device, `monitoring-a` and `monitoring-b`, in group `monitoring` (policy `read,api`). Login, and `api-ssl` on 8729, are allowed only from mini's pod pool `10.44.0.0/16`. The service uses the device's www-ssl cert. - They rotate alternately. The period is `v = floor(plantimestamp / 15d)`: slot a holds the last even `v`, slot b the last odd one. Every plan agrees on these numbers without storing anything, and each slot keeps working for a full period after the other one rotates. - One writer, in graph order. For the slot that rotates: 1. an ephemeral `random_password` goes to OpenBao `secret/routeros-monitoring/<dev>/<slot>` (write-only `data_json_wo`); 2. the router gets **what OpenBao holds**, through an ephemeral read and the provider's write-only `password_wo`; 3. only then is `<dev>/active` pointed at that slot. A retry after a partial failure re-sends the stored value, and `active` always names a slot the router accepts. - No password in state or plans. No runner env. No dependency on the clusters repo for merge order. ## Other changes - `vault/runners-k8s.tf`: new policy `runner-routeros-monitoring` (create/read/update/delete on `secret/routeros-monitoring/*` only) added to role `tf-routeros`. - `vault/eso-mini.tf`: ESO gets read-only access to `secret/routeros-monitoring/*`. - crs309 root: gets the vault provider, with the same ServiceAccount JWT login as the routers. The sim provider override gets it too. - Roots: `required_version >= 1.11`, plus `random ~> 3.7` and `time ~> 0.11`. - `render.py` and `gate.sh`: the users and the OpenBao entries are gate-allowlisted creates. `/user` is never rendered and is skipped by coverage. The gate checks api-ssl's address restriction (`available-from` on RouterOS 7.25) and that both slot users exist. `lib.sh` points the sim at the harness's `infra` KV mount and adds `ROUTEROS_TOFURC` for testing unreleased provider builds. - Docs: `docs/routeros/README.md`, `docs/adr/0011-orchestration-layers.md`, and the guard header. ## Tests - **Module on a CHR with a dev OpenBao, PASS:** 1. First apply: both slots log in over the binary API, and no password is in state. 2. Re-plan in the same period: empty. 3. Next period: only slot b rotates. The old slot a still works, and the old b password is refused and absent from the saved plan. 4. Partial failure, using `-target` to write OpenBao only: `active` doesn't move and the router is unchanged; the retry sends exactly OpenBao's value. 5. Converged. - **Round-trip gate PASS for rb5009-a** (208 objects imported with no change, residue a no-op, converged, coverage PASS) **and crs309** (24). `tofu validate` passes for all three roots. The gate used provider 1.99.1004 through `dev_overrides`, with the module constraint relaxed locally only, because the locks still pin 1.99.1003. ## Before merge 1. Publish provider 1.99.1004 (`lab/release.sh 1.99.1004`; tag `v1.99.1004` is pushed, and the registry push needs a package-writing token). 2. Relock the three roots on this branch (`tofu init -upgrade` with `routeros/tofu.rc`): routeros 1.99.1004, plus random and time. 3. Then merge. The openbao-config root applies the policies. Each router root, on its next interval, writes OpenBao and creates the users and api-ssl, one rb5009 at a time (fuse). lab/clusters#1720 can merge in either order.
Collaborator

tf-controller plan output:


OpenTofu used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place (current -> planned)

OpenTofu will perform the following actions:

  # vault_policy.mini_external_secrets will be updated in-place
  ~ resource "vault_policy" "mini_external_secrets" {
        id     = "mini-external-secrets"
        name   = "mini-external-secrets"
      ~ policy = <<-EOT
          - # ESO on mini (ClusterSecretStore `openbao`): read-only.
          + # ESO on mini (ClusterSecretStore `openbao`): read-only, except the
          + # PushSecret target routeros-monitoring below.
            # RouterOS Terraform vars (flux-clusters clusters/mini/iac/routeros-*-vars.yaml).
            path "secret/data/routeros-secrets" {
              capabilities = ["read"]
            }
            
            path "secret/metadata/routeros-secrets" {
              capabilities = ["read"]
            }
          + 
          + # RouterOS monitoring user passwords (lab/iac#139): generated by ESO's
          + # password generator in flux-system, pushed here by a PushSecret,
          + # read back by mktxp's ExternalSecret in monitoring. The only path ESO
          + # may write. ESO marks pushed secrets in custom metadata
          + # (managed-by: external-secrets) and refuses to overwrite unmarked ones,
          + # hence write on metadata too.
          + path "secret/data/routeros-monitoring" {
          +   capabilities = ["create", "update", "read"]
          + }
          + 
          + path "secret/metadata/routeros-monitoring" {
          +   capabilities = ["create", "update", "read"]
          + }
        EOT
    }

Plan: 0 to add, 1 to change, 0 to destroy.

To apply this plan, please merge this pull request.

tf-controller plan output: ```hcl OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place (current -> planned) OpenTofu will perform the following actions: # vault_policy.mini_external_secrets will be updated in-place ~ resource "vault_policy" "mini_external_secrets" { id = "mini-external-secrets" name = "mini-external-secrets" ~ policy = <<-EOT - # ESO on mini (ClusterSecretStore `openbao`): read-only. + # ESO on mini (ClusterSecretStore `openbao`): read-only, except the + # PushSecret target routeros-monitoring below. # RouterOS Terraform vars (flux-clusters clusters/mini/iac/routeros-*-vars.yaml). path "secret/data/routeros-secrets" { capabilities = ["read"] } path "secret/metadata/routeros-secrets" { capabilities = ["read"] } + + # RouterOS monitoring user passwords (lab/iac#139): generated by ESO's + # password generator in flux-system, pushed here by a PushSecret, + # read back by mktxp's ExternalSecret in monitoring. The only path ESO + # may write. ESO marks pushed secrets in custom metadata + # (managed-by: external-secrets) and refuses to overwrite unmarked ones, + # hence write on metadata too. + path "secret/data/routeros-monitoring" { + capabilities = ["create", "update", "read"] + } + + path "secret/metadata/routeros-monitoring" { + capabilities = ["create", "update", "read"] + } EOT } Plan: 0 to add, 1 to change, 0 to destroy. ``` To apply this plan, please **merge** this pull request.
Collaborator

tf-controller plan output:


OpenTofu used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
  ~ update in-place (current -> planned)

OpenTofu will perform the following actions:

  # vault_jwt_auth_backend_role.mini_runner["tf-routeros"] will be updated in-place
  ~ resource "vault_jwt_auth_backend_role" "mini_runner" {
        id                           = "auth/kubernetes-mini/role/tf-routeros"
      ~ token_policies               = [
          + "runner-routeros-monitoring",
            # (1 unchanged element hidden)
        ]
        # (25 unchanged attributes hidden)
    }

  # vault_policy.mini_external_secrets will be updated in-place
  ~ resource "vault_policy" "mini_external_secrets" {
        id     = "mini-external-secrets"
        name   = "mini-external-secrets"
      ~ policy = <<-EOT
            # ESO on mini (ClusterSecretStore `openbao`): read-only.
            # RouterOS Terraform vars (flux-clusters clusters/mini/iac/routeros-*-vars.yaml).
            path "secret/data/routeros-secrets" {
              capabilities = ["read"]
            }
            
            path "secret/metadata/routeros-secrets" {
              capabilities = ["read"]
            }
          + 
          + # RouterOS monitoring passwords (lab/iac#139): written by the routeros
          + # roots (modules/monitoring), read by mktxp's ExternalSecret.
          + path "secret/data/routeros-monitoring/*" {
          +   capabilities = ["read"]
          + }
          + 
          + path "secret/metadata/routeros-monitoring/*" {
          +   capabilities = ["read"]
          + }
        EOT
    }

  # vault_policy.runner_routeros_monitoring will be created
  + resource "vault_policy" "runner_routeros_monitoring" {
      + id     = (known after apply)
      + name   = "runner-routeros-monitoring"
      + policy = <<-EOT
            path "secret/data/routeros-monitoring/*" {
              capabilities = ["create", "read", "update", "delete"]
            }
            
            path "secret/metadata/routeros-monitoring/*" {
              capabilities = ["read", "update", "delete"]
            }
        EOT
    }

Plan: 1 to add, 2 to change, 0 to destroy.

To apply this plan, please merge this pull request.

tf-controller plan output: ```hcl OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create ~ update in-place (current -> planned) OpenTofu will perform the following actions: # vault_jwt_auth_backend_role.mini_runner["tf-routeros"] will be updated in-place ~ resource "vault_jwt_auth_backend_role" "mini_runner" { id = "auth/kubernetes-mini/role/tf-routeros" ~ token_policies = [ + "runner-routeros-monitoring", # (1 unchanged element hidden) ] # (25 unchanged attributes hidden) } # vault_policy.mini_external_secrets will be updated in-place ~ resource "vault_policy" "mini_external_secrets" { id = "mini-external-secrets" name = "mini-external-secrets" ~ policy = <<-EOT # ESO on mini (ClusterSecretStore `openbao`): read-only. # RouterOS Terraform vars (flux-clusters clusters/mini/iac/routeros-*-vars.yaml). path "secret/data/routeros-secrets" { capabilities = ["read"] } path "secret/metadata/routeros-secrets" { capabilities = ["read"] } + + # RouterOS monitoring passwords (lab/iac#139): written by the routeros + # roots (modules/monitoring), read by mktxp's ExternalSecret. + path "secret/data/routeros-monitoring/*" { + capabilities = ["read"] + } + + path "secret/metadata/routeros-monitoring/*" { + capabilities = ["read"] + } EOT } # vault_policy.runner_routeros_monitoring will be created + resource "vault_policy" "runner_routeros_monitoring" { + id = (known after apply) + name = "runner-routeros-monitoring" + policy = <<-EOT path "secret/data/routeros-monitoring/*" { capabilities = ["create", "read", "update", "delete"] } path "secret/metadata/routeros-monitoring/*" { capabilities = ["read", "update", "delete"] } EOT } Plan: 1 to add, 2 to change, 0 to destroy. ``` To apply this plan, please **merge** this pull request.
Collaborator

tf-controller plan output:


OpenTofu used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
  ~ update in-place (current -> planned)

OpenTofu will perform the following actions:

  # vault_jwt_auth_backend_role.mini_runner["tf-routeros"] will be updated in-place
  ~ resource "vault_jwt_auth_backend_role" "mini_runner" {
        id                           = "auth/kubernetes-mini/role/tf-routeros"
      ~ token_policies               = [
          + "runner-routeros-monitoring",
            # (1 unchanged element hidden)
        ]
        # (25 unchanged attributes hidden)
    }

  # vault_policy.mini_external_secrets will be updated in-place
  ~ resource "vault_policy" "mini_external_secrets" {
        id     = "mini-external-secrets"
        name   = "mini-external-secrets"
      ~ policy = <<-EOT
            # ESO on mini (ClusterSecretStore `openbao`): read-only.
            # RouterOS Terraform vars (flux-clusters clusters/mini/iac/routeros-*-vars.yaml).
            path "secret/data/routeros-secrets" {
              capabilities = ["read"]
            }
            
            path "secret/metadata/routeros-secrets" {
              capabilities = ["read"]
            }
          + 
          + # RouterOS monitoring passwords (lab/iac#139): written by the routeros
          + # roots (modules/monitoring), read by mktxp's ExternalSecret.
          + path "secret/data/routeros-monitoring/*" {
          +   capabilities = ["read"]
          + }
          + 
          + path "secret/metadata/routeros-monitoring/*" {
          +   capabilities = ["read"]
          + }
        EOT
    }

  # vault_policy.runner_routeros_monitoring will be created
  + resource "vault_policy" "runner_routeros_monitoring" {
      + id     = (known after apply)
      + name   = "runner-routeros-monitoring"
      + policy = <<-EOT
            path "secret/data/routeros-monitoring/*" {
              capabilities = ["create", "read", "update", "delete"]
            }
            
            path "secret/metadata/routeros-monitoring/*" {
              capabilities = ["read", "update", "delete"]
            }
        EOT
    }

Plan: 1 to add, 2 to change, 0 to destroy.

To apply this plan, please merge this pull request.

tf-controller plan output: ```hcl OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create ~ update in-place (current -> planned) OpenTofu will perform the following actions: # vault_jwt_auth_backend_role.mini_runner["tf-routeros"] will be updated in-place ~ resource "vault_jwt_auth_backend_role" "mini_runner" { id = "auth/kubernetes-mini/role/tf-routeros" ~ token_policies = [ + "runner-routeros-monitoring", # (1 unchanged element hidden) ] # (25 unchanged attributes hidden) } # vault_policy.mini_external_secrets will be updated in-place ~ resource "vault_policy" "mini_external_secrets" { id = "mini-external-secrets" name = "mini-external-secrets" ~ policy = <<-EOT # ESO on mini (ClusterSecretStore `openbao`): read-only. # RouterOS Terraform vars (flux-clusters clusters/mini/iac/routeros-*-vars.yaml). path "secret/data/routeros-secrets" { capabilities = ["read"] } path "secret/metadata/routeros-secrets" { capabilities = ["read"] } + + # RouterOS monitoring passwords (lab/iac#139): written by the routeros + # roots (modules/monitoring), read by mktxp's ExternalSecret. + path "secret/data/routeros-monitoring/*" { + capabilities = ["read"] + } + + path "secret/metadata/routeros-monitoring/*" { + capabilities = ["read"] + } EOT } # vault_policy.runner_routeros_monitoring will be created + resource "vault_policy" "runner_routeros_monitoring" { + id = (known after apply) + name = "runner-routeros-monitoring" + policy = <<-EOT path "secret/data/routeros-monitoring/*" { capabilities = ["create", "read", "update", "delete"] } path "secret/metadata/routeros-monitoring/*" { capabilities = ["read", "update", "delete"] } EOT } Plan: 1 to add, 2 to change, 0 to destroy. ``` To apply this plan, please **merge** this pull request.
ginjiruu changed title from WIP: routeros: read-only monitoring user + api-ssl, ESO-generated write-only password (#139) to routeros: read-only monitoring users + api-ssl, two-slot rotation published by Terraform (#139) 2026-11-17 21:21:44 +00:00
ginjiruu merged commit 2ff9e33f48 into master 2026-11-17 21:21:45 +00:00
ginjiruu deleted branch routeros-monitoring-user 2026-11-17 21:21:45 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/iac!143
No description provided.