Skip to content

Commit 5f3a559

Browse files
feat: Add support for Vault namespaces to Vault modules (#554)
## Description Adds support for accessing auth mounts/secret engines located in a non root namespace. Namespaces is a feature of Vault Enterprise. ## Type of Change - [ ] New module - [ ] New template - [ ] Bug fix - [x] Feature/enhancement - [ ] Documentation - [ ] Other ## Module Information **Path:** `registry/coder/modules/vault-github` **New version:** `v1.1.0` **Breaking change:** [ ] Yes [x] No **Path:** `registry/coder/modules/vault-jwt` **New version:** `v1.2.0` **Breaking change:** [ ] Yes [x] No **Path:** `registry/coder/modules/vault-token` **New version:** `v1.3.0` **Breaking change:** [ ] Yes [x] No ## Testing & Validation - [x] Tests pass (`bun test`) - [x] Code formatted (`bun fmt`) - [x] Changes tested locally ## Related Issues None --------- Co-authored-by: DevCats <christofer@coder.com>
1 parent b4c162d commit 5f3a559

File tree

9 files changed

+59
-12
lines changed

9 files changed

+59
-12
lines changed

registry/coder/modules/vault-github/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This module lets you authenticate with [Hashicorp Vault](https://www.vaultprojec
1414
module "vault" {
1515
count = data.coder_workspace.me.start_count
1616
source = "registry.coder.com/coder/vault-github/coder"
17-
version = "1.0.31"
17+
version = "1.1.0"
1818
agent_id = coder_agent.example.id
1919
vault_addr = "https://vault.example.com"
2020
}
@@ -46,7 +46,7 @@ To configure the Vault module, you must set up a Vault GitHub auth method. See t
4646
module "vault" {
4747
count = data.coder_workspace.me.start_count
4848
source = "registry.coder.com/coder/vault-github/coder"
49-
version = "1.0.31"
49+
version = "1.1.0"
5050
agent_id = coder_agent.example.id
5151
vault_addr = "https://vault.example.com"
5252
coder_github_auth_id = "my-github-auth-id"
@@ -59,7 +59,7 @@ module "vault" {
5959
module "vault" {
6060
count = data.coder_workspace.me.start_count
6161
source = "registry.coder.com/coder/vault-github/coder"
62-
version = "1.0.31"
62+
version = "1.1.0"
6363
agent_id = coder_agent.example.id
6464
vault_addr = "https://vault.example.com"
6565
coder_github_auth_id = "my-github-auth-id"
@@ -73,7 +73,7 @@ module "vault" {
7373
module "vault" {
7474
count = data.coder_workspace.me.start_count
7575
source = "registry.coder.com/coder/vault-github/coder"
76-
version = "1.0.31"
76+
version = "1.1.0"
7777
agent_id = coder_agent.example.id
7878
vault_addr = "https://vault.example.com"
7979
vault_cli_version = "1.15.0"

registry/coder/modules/vault-github/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ variable "vault_github_auth_path" {
3232
default = "github"
3333
}
3434

35+
variable "vault_namespace" {
36+
type = string
37+
description = "The Vault Enterprise namespace that contains the GitHub auth mount."
38+
default = null
39+
}
40+
3541
variable "vault_cli_version" {
3642
type = string
3743
description = "The version of Vault to install."
@@ -52,6 +58,7 @@ resource "coder_script" "vault" {
5258
AUTH_PATH : var.vault_github_auth_path,
5359
GITHUB_EXTERNAL_AUTH_ID : data.coder_external_auth.github.id,
5460
INSTALL_VERSION : var.vault_cli_version,
61+
VAULT_NAMESPACE : var.vault_namespace != null ? var.vault_namespace : "",
5562
})
5663
run_on_start = true
5764
start_blocks_login = true
@@ -63,6 +70,13 @@ resource "coder_env" "vault_addr" {
6370
value = var.vault_addr
6471
}
6572

73+
resource "coder_env" "vault_namespace" {
74+
count = var.vault_namespace == null ? 0 : 1
75+
agent_id = var.agent_id
76+
name = "VAULT_NAMESPACE"
77+
value = var.vault_namespace
78+
}
79+
6680
data "coder_external_auth" "github" {
6781
id = var.coder_github_auth_id
6882
}

registry/coder/modules/vault-github/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
INSTALL_VERSION=${INSTALL_VERSION}
55
GITHUB_EXTERNAL_AUTH_ID=${GITHUB_EXTERNAL_AUTH_ID}
66
AUTH_PATH=${AUTH_PATH}
7+
VAULT_NAMESPACE=${VAULT_NAMESPACE}
78

89
fetch() {
910
dest="$1"
@@ -104,6 +105,11 @@ if ! (
104105
fi
105106
rm -rf "$TMP"
106107

108+
if [ -n "$${VAULT_NAMESPACE}" ]; then
109+
export VAULT_NAMESPACE
110+
printf "📁 Using Vault namespace: %s\n\n" "$${VAULT_NAMESPACE}"
111+
fi
112+
107113
# Authenticate with Vault
108114
printf "🔑 Authenticating with Vault ...\n\n"
109115
GITHUB_TOKEN=$(coder external-auth access-token "$${GITHUB_EXTERNAL_AUTH_ID}")

registry/coder/modules/vault-jwt/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This module lets you authenticate with [Hashicorp Vault](https://www.vaultprojec
1414
module "vault" {
1515
count = data.coder_workspace.me.start_count
1616
source = "registry.coder.com/coder/vault-jwt/coder"
17-
version = "1.1.1"
17+
version = "1.2.0"
1818
agent_id = coder_agent.example.id
1919
vault_addr = "https://vault.example.com"
2020
vault_jwt_role = "coder" # The Vault role to use for authentication
@@ -42,7 +42,7 @@ curl -H "X-Vault-Token: ${VAULT_TOKEN}" -X GET "${VAULT_ADDR}/v1/coder/secrets/d
4242
module "vault" {
4343
count = data.coder_workspace.me.start_count
4444
source = "registry.coder.com/coder/vault-jwt/coder"
45-
version = "1.1.1"
45+
version = "1.2.0"
4646
agent_id = coder_agent.example.id
4747
vault_addr = "https://vault.example.com"
4848
vault_jwt_auth_path = "oidc"
@@ -58,7 +58,7 @@ data "coder_workspace_owner" "me" {}
5858
module "vault" {
5959
count = data.coder_workspace.me.start_count
6060
source = "registry.coder.com/coder/vault-jwt/coder"
61-
version = "1.1.1"
61+
version = "1.2.0"
6262
agent_id = coder_agent.example.id
6363
vault_addr = "https://vault.example.com"
6464
vault_jwt_role = data.coder_workspace_owner.me.groups[0]
@@ -71,7 +71,7 @@ module "vault" {
7171
module "vault" {
7272
count = data.coder_workspace.me.start_count
7373
source = "registry.coder.com/coder/vault-jwt/coder"
74-
version = "1.1.1"
74+
version = "1.2.0"
7575
agent_id = coder_agent.example.id
7676
vault_addr = "https://vault.example.com"
7777
vault_jwt_role = "coder" # The Vault role to use for authentication
@@ -132,7 +132,7 @@ resource "jwt_signed_token" "vault" {
132132
module "vault" {
133133
count = data.coder_workspace.me.start_count
134134
source = "registry.coder.com/coder/vault-jwt/coder"
135-
version = "1.1.1"
135+
version = "1.2.0"
136136
agent_id = coder_agent.example.id
137137
vault_addr = "https://vault.example.com"
138138
vault_jwt_role = "coder" # The Vault role to use for authentication

registry/coder/modules/vault-jwt/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ variable "vault_jwt_role" {
3838
description = "The name of the Vault role to use for authentication."
3939
}
4040

41+
variable "vault_namespace" {
42+
type = string
43+
description = "The Vault Enterprise namespace that contains the JWT auth mount."
44+
default = null
45+
}
46+
4147
variable "vault_cli_version" {
4248
type = string
4349
description = "The version of Vault to install."
@@ -57,6 +63,7 @@ resource "coder_script" "vault" {
5763
VAULT_JWT_AUTH_PATH : var.vault_jwt_auth_path,
5864
VAULT_JWT_ROLE : var.vault_jwt_role,
5965
VAULT_CLI_VERSION : var.vault_cli_version,
66+
VAULT_NAMESPACE : var.vault_namespace != null ? var.vault_namespace : "",
6067
})
6168
run_on_start = true
6269
start_blocks_login = true
@@ -68,4 +75,11 @@ resource "coder_env" "vault_addr" {
6875
value = var.vault_addr
6976
}
7077

78+
resource "coder_env" "vault_namespace" {
79+
count = var.vault_namespace == null ? 0 : 1
80+
agent_id = var.agent_id
81+
name = "VAULT_NAMESPACE"
82+
value = var.vault_namespace
83+
}
84+
7185
data "coder_workspace_owner" "me" {}

registry/coder/modules/vault-jwt/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
VAULT_CLI_VERSION=${VAULT_CLI_VERSION}
55
VAULT_JWT_AUTH_PATH=${VAULT_JWT_AUTH_PATH}
66
VAULT_JWT_ROLE=${VAULT_JWT_ROLE}
7+
VAULT_NAMESPACE=${VAULT_NAMESPACE}
78
CODER_OIDC_ACCESS_TOKEN=${CODER_OIDC_ACCESS_TOKEN}
89

910
fetch() {
@@ -105,6 +106,11 @@ if ! (
105106
fi
106107
rm -rf "$TMP"
107108

109+
if [ -n "$${VAULT_NAMESPACE}" ]; then
110+
export VAULT_NAMESPACE
111+
printf "📁 Using Vault namespace: %s\n\n" "$${VAULT_NAMESPACE}"
112+
fi
113+
108114
# Authenticate with Vault
109115
printf "🔑 Authenticating with Vault ...\n\n"
110116
echo "$${CODER_OIDC_ACCESS_TOKEN}" | vault write -field=token auth/"$${VAULT_JWT_AUTH_PATH}"/login role="$${VAULT_JWT_ROLE}" jwt=- | vault login -

registry/coder/modules/vault-token/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ variable "vault_token" {
1919
2020
module "vault" {
2121
source = "registry.coder.com/coder/vault-token/coder"
22-
version = "1.2.2"
22+
version = "1.3.0"
2323
agent_id = coder_agent.example.id
2424
vault_token = var.token # optional
2525
vault_addr = "https://vault.example.com"
@@ -73,7 +73,7 @@ variable "vault_token" {
7373
7474
module "vault" {
7575
source = "registry.coder.com/coder/vault-token/coder"
76-
version = "1.2.2"
76+
version = "1.3.0"
7777
agent_id = coder_agent.example.id
7878
vault_addr = "https://vault.example.com"
7979
vault_token = var.token

registry/coder/modules/vault-token/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ resource "coder_script" "vault" {
5050
icon = "/icon/vault.svg"
5151
script = templatefile("${path.module}/run.sh", {
5252
INSTALL_VERSION : var.vault_cli_version,
53+
VAULT_NAMESPACE : var.vault_namespace != null ? var.vault_namespace : "",
5354
})
5455
run_on_start = true
5556
start_blocks_login = true
@@ -73,4 +74,4 @@ resource "coder_env" "vault_namespace" {
7374
agent_id = var.agent_id
7475
name = "VAULT_NAMESPACE"
7576
value = var.vault_namespace
76-
}
77+
}

registry/coder/modules/vault-token/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Convert all templated variables to shell variables
44
INSTALL_VERSION=${INSTALL_VERSION}
5+
VAULT_NAMESPACE=${VAULT_NAMESPACE}
56

67
fetch() {
78
dest="$1"
@@ -101,3 +102,8 @@ if ! (
101102
exit 1
102103
fi
103104
rm -rf "$TMP"
105+
106+
if [ -n "$${VAULT_NAMESPACE}" ]; then
107+
export VAULT_NAMESPACE
108+
printf "📁 Using Vault namespace: %s\n\n" "$${VAULT_NAMESPACE}"
109+
fi

0 commit comments

Comments
 (0)