@norskvideo/ctl-product-template-schema 0.1.83 → 0.1.85

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-product-template-schema",
3
- "version": "0.1.83",
3
+ "version": "0.1.85",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,7 +3,7 @@ export { isSecretReference, parseSecretReference, SECRET_PLACEHOLDER, SECRET_REF
3
3
  export { activeSecretsProfile, type LoadSecretProvidersOptions, loadSecretProviders, PRODUCTION_SECRETS_PROFILE, RESERVED_PROVIDER_NAMES, SECRETS_PROFILE_ENV, SecretProfileSchema, type SecretProvidersConfig, SecretProvidersConfigSchema, secretsProfileNotice, } from "./config.js";
4
4
  export { type DelegateOptions, delegateResolver } from "./delegate.js";
5
5
  export { INVALID_SECRET_NAME_MESSAGE, MAX_SECRET_VALUE_BYTES, validSecretName } from "./names.js";
6
- export { deobfuscate, isObfuscated, OBFUSCATED_PREFIX, obfuscate } from "./obfuscation.js";
6
+ export { deobfuscate, freshObfuscationParams, isObfuscated, OBFUSCATED_PREFIX, obfuscate, obfuscationParams, } from "./obfuscation.js";
7
7
  export type { SecretProvider, SecretProviders, SecretResolutionError } from "./provider.js";
8
8
  export { type AwsSecretProviderOptions, awsSecretProvider } from "./providers/aws.js";
9
9
  export { envSecretProvider } from "./providers/env.js";
package/secrets/index.js CHANGED
@@ -13,7 +13,7 @@ export { isSecretReference, parseSecretReference, SECRET_PLACEHOLDER, SECRET_REF
13
13
  export { activeSecretsProfile, loadSecretProviders, PRODUCTION_SECRETS_PROFILE, RESERVED_PROVIDER_NAMES, SECRETS_PROFILE_ENV, SecretProfileSchema, SecretProvidersConfigSchema, secretsProfileNotice, } from "./config.js";
14
14
  export { delegateResolver } from "./delegate.js";
15
15
  export { INVALID_SECRET_NAME_MESSAGE, MAX_SECRET_VALUE_BYTES, validSecretName } from "./names.js";
16
- export { deobfuscate, isObfuscated, OBFUSCATED_PREFIX, obfuscate } from "./obfuscation.js";
16
+ export { deobfuscate, freshObfuscationParams, isObfuscated, OBFUSCATED_PREFIX, obfuscate, obfuscationParams, } from "./obfuscation.js";
17
17
  export { awsSecretProvider } from "./providers/aws.js";
18
18
  export { envSecretProvider } from "./providers/env.js";
19
19
  export { execSecretProvider } from "./providers/exec.js";
@@ -1,6 +1,14 @@
1
1
  import { type Result } from "@norskvideo/ctl-foundation";
2
2
  export declare const OBFUSCATED_PREFIX = "nsob:v1:";
3
3
  export declare function isObfuscated(text: string): boolean;
4
- export declare function obfuscate(value: string): string;
4
+ /** A fresh salt and nonce, `<salt>:<nonce>` in base64url, for a holder that
5
+ * must re-send one value's envelope unchanged (norsk-mgr's delivery to jobs). */
6
+ export declare function freshObfuscationParams(): string;
7
+ /** The salt and nonce of an envelope, as `freshObfuscationParams` gives them. */
8
+ export declare function obfuscationParams(text: string): string | undefined;
9
+ /** With `params`, the envelope is deterministic: the same value gives the same
10
+ * bytes. Only ever reuse params for the SAME value; a fresh value gets fresh
11
+ * ones. */
12
+ export declare function obfuscate(value: string, params?: string): string;
5
13
  /** The value, or an error that never contains any of the text it was given. */
6
14
  export declare function deobfuscate(text: string): Result<string, string>;
@@ -4,6 +4,12 @@
4
4
  // ticket or an agent reading the file does not show the value; GCM's tag also
5
5
  // rejects a damaged record. A later version whose key comes from a real key
6
6
  // source takes the next version slot (RFC 0011 §3.4).
7
+ //
8
+ // The Norsk Manager opens and writes this envelope too (norsk
9
+ // `server/src/Norsk/Manager/SecretRefs.erl`): it resolves
10
+ // `secretref:norsk:<name>` from norsk-mgr's records in its key/value store,
11
+ // for the secrets it uses itself (a microVM host agent's token). Its test
12
+ // opens an envelope written here; change the format in both places.
7
13
  import { createCipheriv, createDecipheriv, hkdfSync, randomBytes } from "node:crypto";
8
14
  import { err, tryResult } from "@norskvideo/ctl-foundation";
9
15
  export const OBFUSCATED_PREFIX = "nsob:v1:";
@@ -15,9 +21,35 @@ const keyFor = (salt) => Buffer.from(hkdfSync("sha256", CONSTANT, salt, "nsob:v1
15
21
  export function isObfuscated(text) {
16
22
  return text.startsWith(OBFUSCATED_PREFIX);
17
23
  }
18
- export function obfuscate(value) {
19
- const salt = randomBytes(SALT_BYTES);
20
- const nonce = randomBytes(NONCE_BYTES);
24
+ /** A fresh salt and nonce, `<salt>:<nonce>` in base64url, for a holder that
25
+ * must re-send one value's envelope unchanged (norsk-mgr's delivery to jobs). */
26
+ export function freshObfuscationParams() {
27
+ return `${randomBytes(SALT_BYTES).toString("base64url")}:${randomBytes(NONCE_BYTES).toString("base64url")}`;
28
+ }
29
+ /** The salt and nonce of an envelope, as `freshObfuscationParams` gives them. */
30
+ export function obfuscationParams(text) {
31
+ if (!isObfuscated(text))
32
+ return undefined;
33
+ const parts = text.slice(OBFUSCATED_PREFIX.length).split(":");
34
+ if (parts.length !== 3)
35
+ return undefined;
36
+ return parsedParams(`${parts[0]}:${parts[1]}`) ? `${parts[0]}:${parts[1]}` : undefined;
37
+ }
38
+ function parsedParams(params) {
39
+ const [salt, nonce, extra] = params.split(":").map((p) => Buffer.from(p, "base64url"));
40
+ if (!salt || !nonce || extra || salt.length !== SALT_BYTES || nonce.length !== NONCE_BYTES)
41
+ return undefined;
42
+ return { salt, nonce };
43
+ }
44
+ /** With `params`, the envelope is deterministic: the same value gives the same
45
+ * bytes. Only ever reuse params for the SAME value; a fresh value gets fresh
46
+ * ones. */
47
+ export function obfuscate(value, params) {
48
+ const given = params === undefined ? undefined : parsedParams(params);
49
+ if (params !== undefined && !given)
50
+ throw new Error("malformed obfuscation parameters");
51
+ const salt = given?.salt ?? randomBytes(SALT_BYTES);
52
+ const nonce = given?.nonce ?? randomBytes(NONCE_BYTES);
21
53
  const cipher = createCipheriv("aes-256-gcm", keyFor(salt), nonce);
22
54
  const body = Buffer.concat([cipher.update(value, "utf-8"), cipher.final(), cipher.getAuthTag()]);
23
55
  return `${OBFUSCATED_PREFIX}${[salt, nonce, body].map((b) => b.toString("base64url")).join(":")}`;