@kustodian/plugin-1password 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @kustodian/plugin-1password
2
+
3
+ 1Password secret provider plugin for [Kustodian](https://github.com/lucasilverentand/kustodian). Securely inject secrets from 1Password into your Kubernetes manifests using the 1Password CLI.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @kustodian/plugin-1password
9
+ ```
10
+
11
+ ## Prerequisites
12
+
13
+ - [1Password CLI](https://developer.1password.com/docs/cli/) (`op`) installed and available in your PATH
14
+ - Authentication configured via service account token or interactive sign-in
15
+
16
+ ## Usage
17
+
18
+ ### As a Kustodian Plugin
19
+
20
+ ```typescript
21
+ import { create_onepassword_plugin } from '@kustodian/plugin-1password';
22
+
23
+ const plugin = create_onepassword_plugin({
24
+ service_account_token: process.env.OP_SERVICE_ACCOUNT_TOKEN,
25
+ timeout: 30000,
26
+ fail_on_missing: true,
27
+ });
28
+ ```
29
+
30
+ ### Direct Secret Access
31
+
32
+ ```typescript
33
+ import { op_read, op_read_batch, check_op_available } from '@kustodian/plugin-1password';
34
+
35
+ // Check CLI availability
36
+ const check = await check_op_available();
37
+ if (check.success) {
38
+ console.log(`1Password CLI version: ${check.value}`);
39
+ }
40
+
41
+ // Read a single secret
42
+ const secret = await op_read('op://vault/item/field');
43
+
44
+ // Read multiple secrets
45
+ const secrets = await op_read_batch([
46
+ 'op://vault/item/username',
47
+ 'op://vault/item/password',
48
+ ]);
49
+ ```
50
+
51
+ ### Secret Reference Format
52
+
53
+ Secrets are referenced using the standard 1Password URI format:
54
+
55
+ ```
56
+ op://vault/item/field
57
+ op://vault/item/section/field
58
+ ```
59
+
60
+ ## Configuration Options
61
+
62
+ | Option | Type | Default | Description |
63
+ |--------|------|---------|-------------|
64
+ | `service_account_token` | `string` | `undefined` | Service account token (can also use `OP_SERVICE_ACCOUNT_TOKEN` env var) |
65
+ | `timeout` | `number` | `30000` | CLI operation timeout in milliseconds |
66
+ | `fail_on_missing` | `boolean` | `true` | Whether to fail when a secret is not found |
67
+
68
+ ## CLI Commands
69
+
70
+ The plugin provides CLI commands when registered with Kustodian:
71
+
72
+ - `1password check` - Verify CLI availability and authentication
73
+ - `1password test <ref>` - Test reading a secret reference
74
+
75
+ ## License
76
+
77
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kustodian/plugin-1password",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "1Password secret provider plugin for Kustodian",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -37,9 +37,9 @@
37
37
  "registry": "https://npm.pkg.github.com"
38
38
  },
39
39
  "dependencies": {
40
- "@kustodian/core": "workspace:*",
41
- "@kustodian/plugins": "workspace:*",
42
- "@kustodian/schema": "workspace:*"
40
+ "@kustodian/core": "1.1.0",
41
+ "@kustodian/plugins": "1.0.1",
42
+ "@kustodian/schema": "1.3.0"
43
43
  },
44
44
  "devDependencies": {}
45
45
  }
package/src/resolver.ts CHANGED
@@ -7,6 +7,7 @@ import type { OnePasswordPluginOptionsType } from './types.js';
7
7
 
8
8
  /**
9
9
  * Resolves 1Password substitutions to actual secret values.
10
+ * Supports both full references and shorthand with cluster defaults.
10
11
  * Returns a map from substitution name to resolved value.
11
12
  */
12
13
  export async function resolve_onepassword_substitutions(
@@ -20,7 +21,36 @@ export async function resolve_onepassword_substitutions(
20
21
  const results: Record<string, string> = {};
21
22
 
22
23
  for (const sub of substitutions) {
23
- const result = await op_read(sub.ref, options);
24
+ // Build the reference string
25
+ let ref: string;
26
+
27
+ if (sub.ref) {
28
+ // Full reference provided
29
+ ref = sub.ref;
30
+ } else if (sub.item && sub.field) {
31
+ // Shorthand reference - need cluster vault
32
+ const vault = options.cluster_defaults?.vault;
33
+ if (!vault) {
34
+ return failure({
35
+ code: 'MISSING_1PASSWORD_VAULT',
36
+ message: `1Password substitution '${sub.name}' uses shorthand but no cluster vault configured`,
37
+ });
38
+ }
39
+
40
+ // Build op:// reference
41
+ if (sub.section) {
42
+ ref = `op://${vault}/${sub.item}/${sub.section}/${sub.field}`;
43
+ } else {
44
+ ref = `op://${vault}/${sub.item}/${sub.field}`;
45
+ }
46
+ } else {
47
+ return failure({
48
+ code: 'INVALID_1PASSWORD_REFERENCE',
49
+ message: `1Password substitution '${sub.name}' must specify either 'ref' or 'item'+'field'`,
50
+ });
51
+ }
52
+
53
+ const result = await op_read(ref, options);
24
54
 
25
55
  if (!result.success) {
26
56
  // If we have a default and fail_on_missing is false, use the default
package/src/types.ts CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Cluster-level 1Password defaults.
3
+ */
4
+ export interface OnePasswordClusterDefaultsType {
5
+ /** Default vault name or ID */
6
+ vault?: string | undefined;
7
+ }
8
+
1
9
  /**
2
10
  * Options for the 1Password plugin.
3
11
  */
@@ -8,6 +16,8 @@ export interface OnePasswordPluginOptionsType {
8
16
  timeout?: number | undefined;
9
17
  /** Whether to fail on missing secrets (default: true) */
10
18
  fail_on_missing?: boolean | undefined;
19
+ /** Cluster-level defaults for vault */
20
+ cluster_defaults?: OnePasswordClusterDefaultsType | undefined;
11
21
  }
12
22
 
13
23
  /**
@@ -37,20 +47,31 @@ export function parse_onepassword_ref(ref: string): OnePasswordRefType | undefin
37
47
  return undefined;
38
48
  }
39
49
 
40
- const [, vault, item, section, field] = match;
50
+ const vault = match[1];
51
+ const item = match[2];
52
+ const section = match[3];
53
+ const field = match[4];
41
54
 
42
55
  // If section is undefined, the field is in position 3
43
56
  if (field === undefined) {
57
+ // When there's no section, match[3] contains the field
58
+ if (!vault || !item || !section) {
59
+ return undefined;
60
+ }
44
61
  return {
45
- vault: vault!,
46
- item: item!,
47
- field: section!,
62
+ vault,
63
+ item,
64
+ field: section,
48
65
  };
49
66
  }
50
67
 
68
+ if (!vault || !item || !field) {
69
+ return undefined;
70
+ }
71
+
51
72
  return {
52
- vault: vault!,
53
- item: item!,
73
+ vault,
74
+ item,
54
75
  section,
55
76
  field,
56
77
  };