Skip to content

Agent Mesh

controlplane, console: tell the root admin from an OIDC subject named root-admin

Tomas Tormo9fd1a41a1517
diff --git a/internal/console/public/app.js b/internal/console/public/app.js
index a5fa5211..05cbea51 100644
--- a/internal/console/public/app.js
+++ b/internal/console/public/app.js
@@ -829,7 +829,7 @@ function showGeneratedToken(res) {
const panel = document.getElementById('token-result');
const input = document.getElementById('token-result-value');
input.value = res.token;
- document.getElementById('token-result-owner').textContent = res.owner_id || 'you';
+ document.getElementById('token-result-owner').textContent = res.owner_id || 'none';
document.getElementById('token-result-cmd').textContent =
'agentmesh-node join --bootstrap-token ' + res.token + ' <control-plane-url>';
panel.hidden = false;
diff --git a/internal/console/public/index.html b/internal/console/public/index.html
index 66efd133..0853e629 100644
--- a/internal/console/public/index.html
+++ b/internal/console/public/index.html
@@ -343,7 +343,7 @@
</form>
<div id="token-result" class="token-result" hidden>
<div class="token-result-note">
- Token generated for owner <code id="token-result-owner"></code>. Copy it now &mdash; it is not stored and will not be shown again.
+ Token generated. Owner: <code id="token-result-owner"></code>. Copy it now &mdash; it is not stored and will not be shown again.
</div>
<div class="token-result-row">
<input type="text" id="token-result-value" class="token-result-value" readonly onfocus="this.select();">
diff --git a/internal/controlplane/server.go b/internal/controlplane/server.go
index fdcdd3c7..0480ffdf 100644
--- a/internal/controlplane/server.go
+++ b/internal/controlplane/server.go
@@ -2345,8 +2345,9 @@ var errIdentityBanned = errors.New("identity is banned")
// /user/* or /admin/*.
var errWorkloadIdentity = errors.New("workload tokens are not permitted on user endpoints")
-// rootAdminID is the session of the --admin-token holder. It has no users row,
-// so nothing may reference it as an owner.
+// rootAdminID is the user ID of the --admin-token holder. It has no users row and,
+// unlike every OIDC user, no issuer, which tells it apart from an OIDC subject that
+// happens to be named root-admin.
const rootAdminID = "root-admin"
func (s *Server) authenticateUser(r *http.Request) (*storage.User, error) {
@@ -3262,12 +3263,11 @@ func (s *Server) HandleUserBootstrapTokens(w http.ResponseWriter, r *http.Reques
// resolveTokenOwner determines which user a bootstrap token is issued on behalf of.
// The owner defaults to the caller, or to none for the root admin; only admins may
-// override it, and only with a user that already exists. Returns the owner plus an
-// HTTP status to use on error.
+// override it, and only with a user that already exists.
func (s *Server) resolveTokenOwner(ctx context.Context, caller *storage.User, requested string) (string, int, error) {
requested = strings.TrimSpace(requested)
if requested == "" || requested == caller.ID {
- if caller.ID == rootAdminID {
+ if caller.ID == rootAdminID && caller.Issuer == "" {
return "", 0, nil
}
return caller.ID, 0, nil
diff --git a/tests/integration/bootstrap_token_owner_test.go b/tests/integration/bootstrap_token_owner_test.go
index 25131144..5c56b9f9 100644
--- a/tests/integration/bootstrap_token_owner_test.go
+++ b/tests/integration/bootstrap_token_owner_test.go
@@ -187,6 +187,20 @@ func TestBootstrapTokenOwnership(t *testing.T) {
}
})
+ t.Run("an OIDC subject named root-admin owns its token", func(t *testing.T) {
+ jwt := mintToken(map[string]interface{}{"sub": "root-admin", "email": "[email protected]"})
+ status, res, body := requestBootstrapToken(t, baseURL, jwt, map[string]interface{}{
+ "role": api.RoleNode,
+ })
+ if status != http.StatusCreated {
+ t.Fatalf("expected 201, got %d: %s", status, body)
+ }
+ if res.OwnerID != "root-admin" {
+ t.Errorf("expected owner %q, got %q", "root-admin", res.OwnerID)
+ }
+ assertStoredOwner(t, ctx, store, res.ID, "root-admin")
+ })
+
t.Run("admin token session owns no token", func(t *testing.T) {
status, res, body := requestBootstrapToken(t, baseURL, "test-admin-token", map[string]interface{}{
"role": api.RoleNode,
diff --git a/tests/ui/console.spec.js b/tests/ui/console.spec.js
index 07999c5e..7911d889 100644
--- a/tests/ui/console.spec.js
+++ b/tests/ui/console.spec.js
@@ -82,7 +82,7 @@ test('generating a token shows a copyable value and lists it', async ({ page })
await expect(tokenField).toHaveValue(/^mesh-bt-[0-9a-f]{32}$/);
const token = await tokenField.inputValue();
- await expect(page.locator('#token-result-owner')).toHaveText('root-admin');
+ await expect(page.locator('#token-result-owner')).toHaveText('none');
await expect(page.locator('#token-result-cmd')).toContainText(token);
// The copy affordance is the whole point of the panel; prove it works.
@@ -92,18 +92,18 @@ test('generating a token shows a copyable value and lists it', async ({ page })
expect(clipboard).toBe(token);
// The new token must appear in the active token list after the refresh.
- await expect(page.locator('#table-bootstrap')).toContainText('root-admin');
await expect(page.locator('#table-bootstrap')).toContainText('mesh:role:node');
});
-test('omitting the owner attributes the token to the session user', async ({ page }) => {
+// The admin token has no users row to own a token, so the token is unowned.
+test('omitting the owner as the root admin leaves the token unowned', async ({ page }) => {
await login(page);
await page.click('.nav-item[data-target="bootstrap"]');
await expect(page.locator('#token-owner')).toHaveValue('');
await page.click('#form-generate-token button[type="submit"]');
- await expect(page.locator('#token-result-owner')).toHaveText('root-admin');
+ await expect(page.locator('#token-result-owner')).toHaveText('none');
});
// The console holds mesh admin credentials. If they were reachable from JS, a
@@ -154,9 +154,9 @@ test('the search box filters rendered rows', async ({ page }) => {
// its text there instead of into the search box.
await page.click('#form-generate-token button[type="submit"]');
await expect(page.locator('#token-result')).toBeVisible();
- await expect(page.locator('#table-bootstrap')).toContainText('root-admin');
+ await expect(page.locator('#table-bootstrap')).toContainText('mesh:role:node');
- await page.fill('#resource-search', 'root-admin');
+ await page.fill('#resource-search', 'mesh:role:node');
await expect(page.locator('#table-bootstrap tr:visible')).not.toHaveCount(0);
await expect(page.locator('#table-bootstrap tr[data-filter-empty]')).toHaveCount(0);
@@ -165,7 +165,7 @@ test('the search box filters rendered rows', async ({ page }) => {
await page.fill('#resource-search', '');
await expect(page.locator('#table-bootstrap tr[data-filter-empty]')).toHaveCount(0);
- await expect(page.locator('#table-bootstrap')).toContainText('root-admin');
+ await expect(page.locator('#table-bootstrap')).toContainText('mesh:role:node');
});
// The policy textarea is the one place in the console where a stray click can