This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Vault

Vault

The root //:vault and //:vault.* labels delegate to wrappers in //tools/vault/cmd/workspace, using //tools/al:config. //tools/vault:vault is the standalone CLI; the wrappers add the existing AL environment injection.

The pinned upstream binary is owned by third_party/com_hashicorp_vault.

cmd/ssh_key creates or reuses an Ed25519 SSH pair directly in Vault KV v2. Callers select its mount and path and own deployment; the tool preserves the cached identity and refuses implicit rotation.

1 - Backup

Run backup for Vault

2 - Forgejo login

Get a short-lived Forgejo token using OIDC

Plugin data supplies the default Forgejo URL, OIDC source, Vault connection, and Vault authentication. One selected plugin_call may override nonempty configuration fields, for example vault_auth = "forgejo_registration", while inheriting the remaining defaults. Calls without overrides preserve the defaults. Multiple calls with overrides and malformed configuration are rejected before authentication; configuration values are omitted from errors.

The plugin registers token removal before issuance, using a unique token name. Startup failure and normal shutdown attempt removal through the authenticated Forgejo browser session, including when creation did not return a usable token. Cleanup parses the complete applications settings page and verifies token absence after deletion. It then logs out the invocation’s browser session and verifies that the retained original cookie no longer accesses authenticated settings. Cleanup failures are reported.

The parser follows the Forgejo 15.0.3 applications template: all tokens appear on one page, each in a flex-item row with a title and a matching delete button. It requires the applications page marker and new-token link before accepting an empty list. Login pages, invalid token IDs, duplicates, and responses larger than 4 MiB fail closed. A changed upstream template may require a parser update. Network requests have a ten-second timeout and honor cancellation. Forced process termination or an unavailable Forgejo server can prevent cleanup; Forgejo tokens do not acquire an expiry merely because this plugin created them.

2.1 - api

Proto docs for api.proto
load("@rules_java//java:defs.bzl", "java_library")

java_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/forgejo_login:api_java_library",
    ],
)
load("@rules_go//go:def.bzl", "go_library")

go_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/forgejo_login:forgejo_login",
    ],
)
syntax = "proto3";

package com.alwaldend.src.tools.vault.forgejo_login.forgejo_login_proto;

option go_package = "git.alwaldend.com/alwaldend/src/tools/vault/forgejo_login/forgejo_login_proto";

message Config {
  string forgejo_url = 1;
  string forgejo_oauth_name = 2;
  string vault_conn = 3;
  string vault_auth = 4;
}

3 - Gen client cert

Generate a client certificate

4 - Gen root token

Generate a root token for Vault

5 - Harbor login

Create a harbor session using OIDC

The plugin destroys its Harbor session on normal shutdown and checks that the original session ID is rejected by the current-user API. Cleanup uses Harbor’s /c/oidc/logout endpoint (available in newer Harbor releases) and does not follow the optional identity-provider logout redirect. Unsupported endpoints, network failures, or sessions that remain valid are reported as cleanup errors. Session expiry remains server-controlled; forced termination cannot guarantee logout.

The session destruction behavior is defined by Harbor’s OIDC controller. Vault tokens created by the invocation are revoked after session cleanup.

5.1 - api

Proto docs for api.proto
load("@rules_java//java:defs.bzl", "java_library")

java_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/harbor_login:api_java_library",
    ],
)
load("@rules_go//go:def.bzl", "go_library")

go_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/harbor_login:harbor_login",
    ],
)
syntax = "proto3";

package com.alwaldend.src.tools.vault.harbor_login.harbor_login_proto;

option go_package = "git.alwaldend.com/alwaldend/src/tools/vault/harbor_login/harbor_login_proto";

message Config {
  string harbor_url = 1;
  string vault_conn = 2;
  string vault_auth = 3;
}

6 - PVE login

Get a login ticket using OIDC

The plugin requests an API token with a one-hour expiry and deletes that token on shutdown using the retained login ticket and CSRF token. The token name is registered for cleanup before creation, so cleanup is attempted even when a creation response is lost or malformed. Failures to delete are reported; expiry is the fallback when shutdown cannot complete. Pre-existing credentials are not revoked. Vault tokens created by the invocation are revoked after token cleanup.

Token deletion uses the Proxmox user token API.

6.1 - api

Proto docs for api.proto
load("@rules_java//java:defs.bzl", "java_library")

java_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/pve_login:api_java_library",
    ],
)
load("@rules_go//go:def.bzl", "go_library")

go_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/pve_login:pve_login",
    ],
)
syntax = "proto3";

package com.alwaldend.src.tools.vault.pve_login.pve_login_proto;

option go_package = "git.alwaldend.com/alwaldend/src/tools/vault/pve_login/pve_login_proto";

message Config {
  string pve_base_url = 1;
  string pve_redirect_url = 2;
  string pve_realm = 3;
  string vault_conn = 4;
  string vault_auth = 5;
}

7 - Tf backend

Http terraform backend backed by Vault

The plugin tracks each running backend for shutdown, including backends created before a later call fails. Shutdown drains HTTP requests before revoking the backend’s invocation-owned Vault credentials. If the shutdown deadline expires, connections are forcibly closed and the timeout is reported. Normal HTTP server closure is not an error. Vault requests use their incoming request context. The HTTP listener accepts state and lock payloads of up to 32 MiB and returns HTTP 413 for larger bodies. The limit matches the default Vault TCP listener request limit. A new Vault record is initialized with a create-only write.

Use vault_tf_backend(path = ..., labels = ...) from :defs.bzl to construct an al_config plugin-call dictionary. The helper owns the plugin binding and the default secrets mount; callers own their backend path and selection labels. Optional vault_auth, vault_conn, and mount select other named inputs. The shared //tools/al:config registers the executable and propagates runfiles.

7.1 - api

Proto docs for api.proto
load("@rules_java//java:defs.bzl", "java_library")

java_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/tf_backend:api_java_library",
    ],
)
load("@rules_go//go:def.bzl", "go_library")

go_library(
    name = "name",
    deps = [
        "@com_alwaldend_src//tools/vault/tf_backend:tf_backend",
    ],
)
syntax = "proto3";

package com.alwaldend.src.tools.vault.tf_backend.tf_backend_proto;

option go_package = "git.alwaldend.com/alwaldend/src/tools/vault/tf_backend/tf_backend_proto";

message Config {
  string vault_conn = 1;
  string vault_auth = 2;
  string vault_secret = 3;
  string vault_secret_mount = 4;
}

8 - Unseal

Unseal the vault

9 - Vault certificate login

Go command for Vault login with a PKCS#11 hardware certificate

The Go command authenticates once using the selected hardware certificate, then atomically replaces ~/.vault-token with mode 0600. Authentication or response validation failures preserve the previous token. Tokens and server response bodies are never printed. Curl’s normal TLS diagnostics and provider PIN prompts remain visible on stderr; verbose HTTP logging is not enabled.

bazel run //tools/vault/login -- <role-name>

The existing AL wrapper injects VAULT_ADDR and VAULT_CACERT without requiring an existing Vault token. The address must use HTTPS. The role name is the name configured in Vault’s certificate authentication method.

Automatic discovery ignores trust modules and examines public certificates on hardware tokens. It excludes CA certificates, expired or not-yet-valid certificates, and certificates unsuitable for TLS client authentication. It prefers certificates whose common name or DNS identity matches the role name (exactly or as the first DNS label), choosing the newest valid matching certificate. A sole usable hardware certificate can also be selected when the role has a different name. Selection does not depend on token enumeration order. The private key is selected by the certificate’s object ID; a certificate’s label is not reused as a private-key label. To override automatic selection, provide the certificate’s PKCS#11 URI:

bazel run //tools/vault/login -- <role-name> \
  --certificate-uri 'pkcs11:token=example;id=%01;type=cert'

Provider mode (--certificate-type PROV) is the default and supports OpenSSL 4. Use --certificate-type ENG only for an older engine-based installation. Both certificate and private-key loading use the selected mode. PIN handling belongs to the native PKCS#11 provider and its controlling terminal; do not put a PIN in the certificate URI. No global OpenSSL configuration is changed.

The Go binary invokes the existing host p11tool for automatic discovery and curl for PKCS#11 TLS signing. It does not invoke a shell, jq, grep, awk, or tail. Curl configuration files are disabled for this request; certificate settings, HTTPS, JSON encoding, bounded response size, and the request timeout are explicit. Login does not follow redirects or retry. Raw trailing curl arguments have been replaced by typed options. --timeout defaults to one minute; --token-file selects a different destination. Existing symbolic-link destinations are rejected.

bazel test //tools/vault/login:login_test
bazel build //tools/vault/login

The command test uses native-tool fixtures written in Go and synthetic tokens. It verifies provider/engine selection, hardware and role selection, certificate validity and usage filtering, response rejection, timeout, secret-free diagnostics, token preservation, and private atomic replacement. Its undeclared test outputs contain login-results.json. These checks do not prove a live hardware login; that requires the real certificate and Vault role.