@naylence/advanced-security 0.4.5 → 0.4.7
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/dist/browser/index.cjs +503 -16
- package/dist/browser/index.mjs +504 -17
- package/dist/cjs/advanced-security-isomorphic.js +1 -1
- package/dist/cjs/advanced-security-isomorphic.js.map +1 -1
- package/dist/cjs/naylence/fame/factory-manifest.js +2 -0
- package/dist/cjs/naylence/fame/factory-manifest.js.map +1 -1
- package/dist/cjs/naylence/fame/security/auth/index.js +2 -0
- package/dist/cjs/naylence/fame/security/auth/index.js.map +1 -1
- package/dist/cjs/naylence/fame/security/auth/policy/auth-policy-server-cli.js +47 -0
- package/dist/cjs/naylence/fame/security/auth/policy/auth-policy-server-cli.js.map +1 -0
- package/dist/cjs/naylence/fame/security/auth/policy/auth-policy-server.js +562 -0
- package/dist/cjs/naylence/fame/security/auth/policy/auth-policy-server.js.map +1 -0
- package/dist/cjs/naylence/fame/security/auth/policy/http-authorization-policy-source-factory.js +108 -0
- package/dist/cjs/naylence/fame/security/auth/policy/http-authorization-policy-source-factory.js.map +1 -0
- package/dist/cjs/naylence/fame/security/auth/policy/http-authorization-policy-source.js +367 -0
- package/dist/cjs/naylence/fame/security/auth/policy/http-authorization-policy-source.js.map +1 -0
- package/dist/cjs/naylence/fame/security/auth/policy/index.js +4 -2
- package/dist/cjs/naylence/fame/security/auth/policy/index.js.map +1 -1
- package/dist/cjs/naylence/fame/security/auth/policy-http-authorization-profile.js +78 -0
- package/dist/cjs/naylence/fame/security/auth/policy-http-authorization-profile.js.map +1 -0
- package/dist/cjs/naylence/fame/security/register-advanced-security-factories.js +2 -0
- package/dist/cjs/naylence/fame/security/register-advanced-security-factories.js.map +1 -1
- package/dist/cjs/version.js +2 -2
- package/dist/esm/advanced-security-isomorphic.js +1 -1
- package/dist/esm/advanced-security-isomorphic.js.map +1 -1
- package/dist/esm/naylence/fame/factory-manifest.js +2 -0
- package/dist/esm/naylence/fame/factory-manifest.js.map +1 -1
- package/dist/esm/naylence/fame/security/auth/index.js +2 -0
- package/dist/esm/naylence/fame/security/auth/index.js.map +1 -1
- package/dist/esm/naylence/fame/security/auth/policy/auth-policy-server-cli.js +47 -0
- package/dist/esm/naylence/fame/security/auth/policy/auth-policy-server-cli.js.map +1 -0
- package/dist/esm/naylence/fame/security/auth/policy/auth-policy-server.js +562 -0
- package/dist/esm/naylence/fame/security/auth/policy/auth-policy-server.js.map +1 -0
- package/dist/esm/naylence/fame/security/auth/policy/http-authorization-policy-source-factory.js +108 -0
- package/dist/esm/naylence/fame/security/auth/policy/http-authorization-policy-source-factory.js.map +1 -0
- package/dist/esm/naylence/fame/security/auth/policy/http-authorization-policy-source.js +367 -0
- package/dist/esm/naylence/fame/security/auth/policy/http-authorization-policy-source.js.map +1 -0
- package/dist/esm/naylence/fame/security/auth/policy/index.js +4 -2
- package/dist/esm/naylence/fame/security/auth/policy/index.js.map +1 -1
- package/dist/esm/naylence/fame/security/auth/policy-http-authorization-profile.js +78 -0
- package/dist/esm/naylence/fame/security/auth/policy-http-authorization-profile.js.map +1 -0
- package/dist/esm/naylence/fame/security/register-advanced-security-factories.js +2 -0
- package/dist/esm/naylence/fame/security/register-advanced-security-factories.js.map +1 -1
- package/dist/esm/version.js +2 -2
- package/dist/node/index.cjs +578 -125
- package/dist/node/index.mjs +572 -94
- package/dist/node/node.cjs +589 -51
- package/dist/node/node.mjs +582 -19
- package/dist/types/advanced-security-isomorphic.d.ts +0 -1
- package/dist/types/advanced-security-isomorphic.d.ts.map +1 -1
- package/dist/types/naylence/fame/factory-manifest.d.ts +1 -1
- package/dist/types/naylence/fame/factory-manifest.d.ts.map +1 -1
- package/dist/types/naylence/fame/security/auth/index.d.ts +1 -0
- package/dist/types/naylence/fame/security/auth/index.d.ts.map +1 -1
- package/dist/types/naylence/fame/security/auth/policy/auth-policy-server-cli.d.ts +20 -0
- package/dist/types/naylence/fame/security/auth/policy/auth-policy-server-cli.d.ts.map +1 -0
- package/dist/types/naylence/fame/security/auth/policy/auth-policy-server.d.ts +75 -0
- package/dist/types/naylence/fame/security/auth/policy/auth-policy-server.d.ts.map +1 -0
- package/dist/types/naylence/fame/security/auth/policy/http-authorization-policy-source-factory.d.ts +81 -0
- package/dist/types/naylence/fame/security/auth/policy/http-authorization-policy-source-factory.d.ts.map +1 -0
- package/dist/types/naylence/fame/security/auth/policy/http-authorization-policy-source.d.ts +150 -0
- package/dist/types/naylence/fame/security/auth/policy/http-authorization-policy-source.d.ts.map +1 -0
- package/dist/types/naylence/fame/security/auth/policy/index.d.ts +2 -1
- package/dist/types/naylence/fame/security/auth/policy/index.d.ts.map +1 -1
- package/dist/types/naylence/fame/security/auth/policy-http-authorization-profile.d.ts +17 -0
- package/dist/types/naylence/fame/security/auth/policy-http-authorization-profile.d.ts.map +1 -0
- package/dist/types/naylence/fame/security/register-advanced-security-factories.d.ts +1 -0
- package/dist/types/naylence/fame/security/register-advanced-security-factories.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -2
package/dist/node/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { KNOWN_POLICY_FIELDS, VALID_EFFECTS, compileGlobOnlyScopeRequirement, KNOWN_RULE_FIELDS, VALID_ACTIONS, compileGlobPattern, VALID_ORIGIN_TYPES, AUTHORIZATION_POLICY_FACTORY_BASE_TYPE, AuthorizationPolicyFactory, getLogger, EncryptionResult, urlsafeBase64Decode, sealedDecrypt, sealedEncrypt, FIXED_PREFIX_LEN, urlsafeBase64Encode, EncryptionManagerFactory, ENCRYPTION_MANAGER_FACTORY_BASE_TYPE, requireCryptoSupport, SECURE_CHANNEL_MANAGER_FACTORY_BASE_TYPE, SecureChannelManagerFactory, ENVELOPE_SIGNER_FACTORY_BASE_TYPE, EnvelopeSignerFactory, SigningConfigClass, validateSigningKey, JWKValidationError, decodeBase64Url, canonicalJson, secureDigest, frameDigest, immutableHeaders, encodeUtf8, ENVELOPE_VERIFIER_FACTORY_BASE_TYPE, EnvelopeVerifierFactory, TrustStoreProviderFactory, TaskSpawner, getKeyStore, DefaultKeyManager, validateJwkComplete, currentTraceId, DeliveryOriginType, KEY_MANAGER_FACTORY_BASE_TYPE, KeyManagerFactory, KeyStoreFactory, BaseNodeEventListener, LOAD_BALANCER_STICKINESS_MANAGER_FACTORY_BASE_TYPE, LoadBalancerStickinessManagerFactory, REPLICA_STICKINESS_MANAGER_FACTORY_BASE_TYPE, ReplicaStickinessManagerFactory, color, AnsiColor, validateHostLogicals, HTTP_CONNECTION_GRANT_TYPE, formatTimestamp, jsonDumps, WELCOME_SERVICE_FACTORY_BASE_TYPE, WelcomeServiceFactory, NodePlacementStrategyFactory, TransportProvisionerFactory, TokenIssuerFactory, AuthorizerFactory,
|
|
1
|
+
import { Expressions, ExtensionManager, Registry, AbstractResourceFactory } from '@naylence/factory';
|
|
2
|
+
import { KNOWN_POLICY_FIELDS, VALID_EFFECTS, compileGlobOnlyScopeRequirement, KNOWN_RULE_FIELDS, VALID_ACTIONS, compileGlobPattern, VALID_ORIGIN_TYPES, AUTHORIZATION_POLICY_FACTORY_BASE_TYPE, AuthorizationPolicyFactory, getLogger, AUTHORIZATION_POLICY_SOURCE_FACTORY_BASE_TYPE, AuthorizationPolicySourceFactory, TokenProviderFactory, registerProfile, AUTHORIZER_FACTORY_BASE_TYPE, EncryptionResult, urlsafeBase64Decode, sealedDecrypt, sealedEncrypt, FIXED_PREFIX_LEN, urlsafeBase64Encode, EncryptionManagerFactory, ENCRYPTION_MANAGER_FACTORY_BASE_TYPE, requireCryptoSupport, SECURE_CHANNEL_MANAGER_FACTORY_BASE_TYPE, SecureChannelManagerFactory, ENVELOPE_SIGNER_FACTORY_BASE_TYPE, EnvelopeSignerFactory, SigningConfigClass, validateSigningKey, JWKValidationError, decodeBase64Url, canonicalJson, secureDigest, frameDigest, immutableHeaders, encodeUtf8, ENVELOPE_VERIFIER_FACTORY_BASE_TYPE, EnvelopeVerifierFactory, TrustStoreProviderFactory, TaskSpawner, getKeyStore, DefaultKeyManager, validateJwkComplete, currentTraceId, DeliveryOriginType, KEY_MANAGER_FACTORY_BASE_TYPE, KeyManagerFactory, KeyStoreFactory, BaseNodeEventListener, LOAD_BALANCER_STICKINESS_MANAGER_FACTORY_BASE_TYPE, LoadBalancerStickinessManagerFactory, REPLICA_STICKINESS_MANAGER_FACTORY_BASE_TYPE, ReplicaStickinessManagerFactory, color, AnsiColor, validateHostLogicals, HTTP_CONNECTION_GRANT_TYPE, formatTimestamp, jsonDumps, WELCOME_SERVICE_FACTORY_BASE_TYPE, WelcomeServiceFactory, NodePlacementStrategyFactory, TransportProvisionerFactory, TokenIssuerFactory, AuthorizerFactory, SECURITY_MANAGER_FACTORY_BASE_TYPE, validateHostLogical, AuthInjectionStrategyFactory, CERTIFICATE_MANAGER_FACTORY_BASE_TYPE, CertificateManagerFactory, TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE } from '@naylence/runtime';
|
|
3
3
|
import { AsnConvert, OctetString } from '@peculiar/asn1-schema';
|
|
4
4
|
import { Attributes, CertificationRequestInfo, CertificationRequest } from '@peculiar/asn1-csr';
|
|
5
5
|
import { Certificate, SubjectAlternativeName, NameConstraints, id_ce_subjectAltName, id_ce_nameConstraints, SubjectPublicKeyInfo, GeneralName, Extensions, Extension, Attribute, AlgorithmIdentifier, Name, RelativeDistinguishedName, AttributeTypeAndValue, AttributeValue, BasicConstraints, id_ce_basicConstraints, KeyUsageFlags, id_ce_keyUsage, KeyUsage, id_ce_subjectKeyIdentifier, SubjectKeyIdentifier, id_ce_authorityKeyIdentifier, AuthorityKeyIdentifier, KeyIdentifier, GeneralSubtrees, GeneralSubtree, TBSCertificate, Validity, Version, id_ce_extKeyUsage, ExtendedKeyUsage, id_kp_clientAuth, id_kp_serverAuth } from '@peculiar/asn1-x509';
|
|
@@ -7,6 +7,7 @@ import { verify, etc } from '@noble/ed25519';
|
|
|
7
7
|
import { sha256 as sha256$1, sha512 } from '@noble/hashes/sha2.js';
|
|
8
8
|
import { generateFingerprintSync, localDeliveryContext, createFameEnvelope, generateId, formatAddress, FameAddress, SigningMaterial, DeliveryOriginType as DeliveryOriginType$1 } from '@naylence/core';
|
|
9
9
|
import { sha256 } from '@noble/hashes/sha2';
|
|
10
|
+
import { parse as parse$1 } from 'yaml';
|
|
10
11
|
import { chacha20poly1305 } from '@noble/ciphers/chacha.js';
|
|
11
12
|
import { x25519 } from '@noble/curves/ed25519.js';
|
|
12
13
|
import { hkdf } from '@noble/hashes/hkdf.js';
|
|
@@ -16,12 +17,12 @@ import { sha256 as sha256$2 } from '@noble/hashes/sha256.js';
|
|
|
16
17
|
import { X509Certificate } from '@peculiar/x509';
|
|
17
18
|
|
|
18
19
|
// This file is auto-generated during build - do not edit manually
|
|
19
|
-
// Generated from package.json version: 0.4.
|
|
20
|
+
// Generated from package.json version: 0.4.7
|
|
20
21
|
/**
|
|
21
22
|
* The package version, injected at build time.
|
|
22
23
|
* @internal
|
|
23
24
|
*/
|
|
24
|
-
const VERSION = '0.4.
|
|
25
|
+
const VERSION = '0.4.7';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Abstract Syntax Tree (AST) node types for the expression language.
|
|
@@ -108,55 +109,6 @@ function calculateAstDepth(node) {
|
|
|
108
109
|
Math.max(calculateAstDepth(node.condition), calculateAstDepth(node.consequent), calculateAstDepth(node.alternate)));
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Returns a human-readable representation of an AST node for debugging.
|
|
113
|
-
*/
|
|
114
|
-
function astToString(node, indent = 0) {
|
|
115
|
-
const prefix = " ".repeat(indent);
|
|
116
|
-
switch (node.type) {
|
|
117
|
-
case "StringLiteral":
|
|
118
|
-
return `${prefix}String: "${node.value}"`;
|
|
119
|
-
case "NumberLiteral":
|
|
120
|
-
return `${prefix}Number: ${node.value}`;
|
|
121
|
-
case "BooleanLiteral":
|
|
122
|
-
return `${prefix}Boolean: ${node.value}`;
|
|
123
|
-
case "NullLiteral":
|
|
124
|
-
return `${prefix}Null`;
|
|
125
|
-
case "ArrayLiteral":
|
|
126
|
-
return (`${prefix}Array:\n` +
|
|
127
|
-
node.elements.map((e) => astToString(e, indent + 1)).join("\n"));
|
|
128
|
-
case "Identifier":
|
|
129
|
-
return `${prefix}Identifier: ${node.name}`;
|
|
130
|
-
case "MemberAccess":
|
|
131
|
-
return (`${prefix}MemberAccess: .${node.property}\n` +
|
|
132
|
-
astToString(node.object, indent + 1));
|
|
133
|
-
case "IndexAccess":
|
|
134
|
-
return (`${prefix}IndexAccess:\n` +
|
|
135
|
-
`${prefix} object:\n` +
|
|
136
|
-
astToString(node.object, indent + 2) +
|
|
137
|
-
`\n${prefix} index:\n` +
|
|
138
|
-
astToString(node.index, indent + 2));
|
|
139
|
-
case "FunctionCall":
|
|
140
|
-
return (`${prefix}FunctionCall: ${node.name}\n` +
|
|
141
|
-
node.args.map((a) => astToString(a, indent + 1)).join("\n"));
|
|
142
|
-
case "UnaryOp":
|
|
143
|
-
return (`${prefix}UnaryOp: ${node.operator}\n` +
|
|
144
|
-
astToString(node.operand, indent + 1));
|
|
145
|
-
case "BinaryOp":
|
|
146
|
-
return (`${prefix}BinaryOp: ${node.operator}\n` +
|
|
147
|
-
astToString(node.left, indent + 1) +
|
|
148
|
-
"\n" +
|
|
149
|
-
astToString(node.right, indent + 1));
|
|
150
|
-
case "TernaryOp":
|
|
151
|
-
return (`${prefix}TernaryOp:\n` +
|
|
152
|
-
`${prefix} condition:\n` +
|
|
153
|
-
astToString(node.condition, indent + 2) +
|
|
154
|
-
`\n${prefix} consequent:\n` +
|
|
155
|
-
astToString(node.consequent, indent + 2) +
|
|
156
|
-
`\n${prefix} alternate:\n` +
|
|
157
|
-
astToString(node.alternate, indent + 2));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
112
|
|
|
161
113
|
/**
|
|
162
114
|
* Error types for the expression evaluation engine.
|
|
@@ -223,18 +175,6 @@ class TypeError extends EvaluationError {
|
|
|
223
175
|
this.actual = actual;
|
|
224
176
|
}
|
|
225
177
|
}
|
|
226
|
-
/**
|
|
227
|
-
* Error thrown when expression limits are exceeded.
|
|
228
|
-
*/
|
|
229
|
-
class LimitExceededError extends ExpressionError {
|
|
230
|
-
constructor(limitName, limit, actual) {
|
|
231
|
-
super(`Limit exceeded: ${limitName} (limit: ${limit}, actual: ${actual})`);
|
|
232
|
-
this.name = "LimitExceededError";
|
|
233
|
-
this.limitName = limitName;
|
|
234
|
-
this.limit = limit;
|
|
235
|
-
this.actual = actual;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
178
|
/**
|
|
239
179
|
* Error thrown when a built-in function encounters an error.
|
|
240
180
|
*/
|
|
@@ -1551,12 +1491,6 @@ function callBuiltin(name, args, context, functions = BUILTIN_FUNCTIONS) {
|
|
|
1551
1491
|
}
|
|
1552
1492
|
return fn(args, context);
|
|
1553
1493
|
}
|
|
1554
|
-
/**
|
|
1555
|
-
* Checks if a name is a built-in function.
|
|
1556
|
-
*/
|
|
1557
|
-
function isBuiltinFunction(name, functions = BUILTIN_FUNCTIONS) {
|
|
1558
|
-
return functions.has(name);
|
|
1559
|
-
}
|
|
1560
1494
|
|
|
1561
1495
|
/**
|
|
1562
1496
|
* Expression evaluator.
|
|
@@ -1903,24 +1837,6 @@ class Evaluator {
|
|
|
1903
1837
|
return false;
|
|
1904
1838
|
}
|
|
1905
1839
|
}
|
|
1906
|
-
/**
|
|
1907
|
-
* Evaluates an AST against a context and returns the result.
|
|
1908
|
-
*
|
|
1909
|
-
* @param ast - The AST to evaluate
|
|
1910
|
-
* @param context - The evaluation context with bindings
|
|
1911
|
-
* @returns The evaluation result
|
|
1912
|
-
*/
|
|
1913
|
-
function evaluate(ast, context) {
|
|
1914
|
-
try {
|
|
1915
|
-
const evaluator = new Evaluator(context);
|
|
1916
|
-
const value = evaluator.evaluate(ast);
|
|
1917
|
-
return { value, success: true };
|
|
1918
|
-
}
|
|
1919
|
-
catch (error) {
|
|
1920
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
1921
|
-
return { value: null, success: false, error: message };
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
1840
|
/**
|
|
1925
1841
|
* Evaluates an AST as a boolean condition.
|
|
1926
1842
|
*
|
|
@@ -2873,7 +2789,7 @@ function getModule() {
|
|
|
2873
2789
|
}
|
|
2874
2790
|
return modulePromise;
|
|
2875
2791
|
}
|
|
2876
|
-
function normalizeConfig$
|
|
2792
|
+
function normalizeConfig$6(config) {
|
|
2877
2793
|
if (!config) {
|
|
2878
2794
|
throw new Error("AdvancedAuthorizationPolicyFactory requires a configuration with a policyDefinition");
|
|
2879
2795
|
}
|
|
@@ -2902,7 +2818,7 @@ function normalizeConfig$5(config) {
|
|
|
2902
2818
|
/**
|
|
2903
2819
|
* Factory metadata for registration.
|
|
2904
2820
|
*/
|
|
2905
|
-
const FACTORY_META$
|
|
2821
|
+
const FACTORY_META$f = {
|
|
2906
2822
|
base: AUTHORIZATION_POLICY_FACTORY_BASE_TYPE,
|
|
2907
2823
|
key: "AdvancedAuthorizationPolicy",
|
|
2908
2824
|
};
|
|
@@ -2921,7 +2837,7 @@ class AdvancedAuthorizationPolicyFactory extends AuthorizationPolicyFactory {
|
|
|
2921
2837
|
* @returns The created authorization policy
|
|
2922
2838
|
*/
|
|
2923
2839
|
async create(config) {
|
|
2924
|
-
const normalized = normalizeConfig$
|
|
2840
|
+
const normalized = normalizeConfig$6(config);
|
|
2925
2841
|
const { AdvancedAuthorizationPolicy } = await getModule();
|
|
2926
2842
|
return new AdvancedAuthorizationPolicy({
|
|
2927
2843
|
policyDefinition: normalized.policyDefinition,
|
|
@@ -2934,10 +2850,569 @@ class AdvancedAuthorizationPolicyFactory extends AuthorizationPolicyFactory {
|
|
|
2934
2850
|
var advancedAuthorizationPolicyFactory = /*#__PURE__*/Object.freeze({
|
|
2935
2851
|
__proto__: null,
|
|
2936
2852
|
AdvancedAuthorizationPolicyFactory: AdvancedAuthorizationPolicyFactory,
|
|
2937
|
-
FACTORY_META: FACTORY_META$
|
|
2853
|
+
FACTORY_META: FACTORY_META$f,
|
|
2938
2854
|
default: AdvancedAuthorizationPolicyFactory
|
|
2939
2855
|
});
|
|
2940
2856
|
|
|
2857
|
+
/**
|
|
2858
|
+
* HTTP-based authorization policy source.
|
|
2859
|
+
*
|
|
2860
|
+
* Loads authorization policies from an HTTP endpoint supporting JSON or YAML.
|
|
2861
|
+
* Supports bearer authentication via TokenProvider and HTTP caching via ETag.
|
|
2862
|
+
*
|
|
2863
|
+
* This is a Node.js-only implementation.
|
|
2864
|
+
*
|
|
2865
|
+
* @packageDocumentation
|
|
2866
|
+
*/
|
|
2867
|
+
const logger$i = getLogger("naylence.fame.security.auth.policy.http_authorization_policy_source");
|
|
2868
|
+
function isPlainObject(value) {
|
|
2869
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2870
|
+
}
|
|
2871
|
+
function parseJson(content) {
|
|
2872
|
+
const parsed = JSON.parse(content);
|
|
2873
|
+
if (!isPlainObject(parsed)) {
|
|
2874
|
+
throw new Error("Parsed JSON policy must be an object");
|
|
2875
|
+
}
|
|
2876
|
+
return parsed;
|
|
2877
|
+
}
|
|
2878
|
+
function parseYamlContent(content) {
|
|
2879
|
+
const parsed = parse$1(content ?? "");
|
|
2880
|
+
if (parsed == null) {
|
|
2881
|
+
return {};
|
|
2882
|
+
}
|
|
2883
|
+
if (!isPlainObject(parsed)) {
|
|
2884
|
+
throw new Error("Parsed YAML policy must be an object");
|
|
2885
|
+
}
|
|
2886
|
+
return parsed;
|
|
2887
|
+
}
|
|
2888
|
+
/**
|
|
2889
|
+
* Detect whether content is JSON or YAML based on Content-Type header.
|
|
2890
|
+
* Falls back to sniffing the content if Content-Type is not definitive.
|
|
2891
|
+
*/
|
|
2892
|
+
function detectFormat(contentType, content) {
|
|
2893
|
+
if (contentType) {
|
|
2894
|
+
const lower = contentType.toLowerCase();
|
|
2895
|
+
if (lower.includes("application/json") ||
|
|
2896
|
+
lower.includes("text/json")) {
|
|
2897
|
+
return "json";
|
|
2898
|
+
}
|
|
2899
|
+
if (lower.includes("application/yaml") ||
|
|
2900
|
+
lower.includes("application/x-yaml") ||
|
|
2901
|
+
lower.includes("text/yaml") ||
|
|
2902
|
+
lower.includes("text/x-yaml")) {
|
|
2903
|
+
return "yaml";
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
// Sniff by first non-whitespace character
|
|
2907
|
+
const trimmed = content.trimStart();
|
|
2908
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
2909
|
+
return "json";
|
|
2910
|
+
}
|
|
2911
|
+
// Default to YAML
|
|
2912
|
+
return "yaml";
|
|
2913
|
+
}
|
|
2914
|
+
/**
|
|
2915
|
+
* Parse Cache-Control header to extract max-age value.
|
|
2916
|
+
*/
|
|
2917
|
+
function parseMaxAge(cacheControl) {
|
|
2918
|
+
if (!cacheControl) {
|
|
2919
|
+
return undefined;
|
|
2920
|
+
}
|
|
2921
|
+
const match = cacheControl.match(/max-age\s*=\s*(\d+)/i);
|
|
2922
|
+
if (match && match[1]) {
|
|
2923
|
+
const seconds = parseInt(match[1], 10);
|
|
2924
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
2925
|
+
return seconds;
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
return undefined;
|
|
2929
|
+
}
|
|
2930
|
+
/**
|
|
2931
|
+
* An authorization policy source that loads policy definitions from an HTTP endpoint.
|
|
2932
|
+
*
|
|
2933
|
+
* Supports JSON and YAML formats, bearer authentication via TokenProvider,
|
|
2934
|
+
* and HTTP caching via ETag and Cache-Control headers.
|
|
2935
|
+
*
|
|
2936
|
+
* This is a Node.js-only implementation that uses fetch.
|
|
2937
|
+
*/
|
|
2938
|
+
class HttpAuthorizationPolicySource {
|
|
2939
|
+
constructor(options) {
|
|
2940
|
+
this.cachedState = null;
|
|
2941
|
+
this.inflightFetch = null;
|
|
2942
|
+
if (!options.url || typeof options.url !== "string") {
|
|
2943
|
+
throw new Error("HttpAuthorizationPolicySource requires a valid URL");
|
|
2944
|
+
}
|
|
2945
|
+
this.url = options.url;
|
|
2946
|
+
this.method = options.method ?? "GET";
|
|
2947
|
+
this.timeoutMs = options.timeoutMs ?? 30000;
|
|
2948
|
+
this.headers = { ...options.headers };
|
|
2949
|
+
this.tokenProvider = options.tokenProvider;
|
|
2950
|
+
this.bearerPrefix = options.bearerPrefix ?? "Bearer ";
|
|
2951
|
+
this.policyFactoryConfig = options.policyFactory;
|
|
2952
|
+
this.cacheTtlMs = options.cacheTtlMs ?? 300000; // 5 minutes default
|
|
2953
|
+
}
|
|
2954
|
+
/**
|
|
2955
|
+
* Loads the authorization policy from the configured HTTP endpoint.
|
|
2956
|
+
*
|
|
2957
|
+
* Returns a cached policy if still fresh (based on TTL or cache headers).
|
|
2958
|
+
* Multiple concurrent calls are de-duplicated (single-flight pattern).
|
|
2959
|
+
*
|
|
2960
|
+
* @returns The loaded authorization policy
|
|
2961
|
+
*/
|
|
2962
|
+
async loadPolicy() {
|
|
2963
|
+
// Return cached policy if still fresh
|
|
2964
|
+
if (this.cachedState && this.isCacheFresh()) {
|
|
2965
|
+
logger$i.debug("returning_cached_policy", {
|
|
2966
|
+
url: this.url,
|
|
2967
|
+
fetchedAt: this.cachedState.metadata.fetchedAt,
|
|
2968
|
+
expiresAt: this.cachedState.metadata.expiresAt,
|
|
2969
|
+
});
|
|
2970
|
+
return this.cachedState.policy;
|
|
2971
|
+
}
|
|
2972
|
+
// De-duplicate concurrent requests
|
|
2973
|
+
if (this.inflightFetch) {
|
|
2974
|
+
return this.inflightFetch;
|
|
2975
|
+
}
|
|
2976
|
+
this.inflightFetch = this.fetchPolicy(false);
|
|
2977
|
+
try {
|
|
2978
|
+
return await this.inflightFetch;
|
|
2979
|
+
}
|
|
2980
|
+
finally {
|
|
2981
|
+
this.inflightFetch = null;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
/**
|
|
2985
|
+
* Forces a reload of the policy from the HTTP endpoint.
|
|
2986
|
+
*
|
|
2987
|
+
* Bypasses cache freshness checks and always fetches from the server.
|
|
2988
|
+
* If the fetch fails, the existing cached policy is preserved and the error is thrown.
|
|
2989
|
+
*
|
|
2990
|
+
* @returns The reloaded authorization policy
|
|
2991
|
+
*/
|
|
2992
|
+
async reloadPolicy() {
|
|
2993
|
+
// Clear inflight to force a new request
|
|
2994
|
+
this.inflightFetch = null;
|
|
2995
|
+
return this.fetchPolicy(true);
|
|
2996
|
+
}
|
|
2997
|
+
/**
|
|
2998
|
+
* Clears the cached policy, forcing a fresh fetch on the next loadPolicy() call.
|
|
2999
|
+
*/
|
|
3000
|
+
clearCache() {
|
|
3001
|
+
this.cachedState = null;
|
|
3002
|
+
this.inflightFetch = null;
|
|
3003
|
+
}
|
|
3004
|
+
/**
|
|
3005
|
+
* Returns metadata about the last successful fetch.
|
|
3006
|
+
*
|
|
3007
|
+
* Useful for verification, monitoring, or debugging.
|
|
3008
|
+
*/
|
|
3009
|
+
getMetadata() {
|
|
3010
|
+
return this.cachedState?.metadata;
|
|
3011
|
+
}
|
|
3012
|
+
/**
|
|
3013
|
+
* Returns the raw policy definition from the last successful fetch.
|
|
3014
|
+
*
|
|
3015
|
+
* Useful for verification or reprocessing.
|
|
3016
|
+
*/
|
|
3017
|
+
getRawDefinition() {
|
|
3018
|
+
return this.cachedState?.rawDefinition;
|
|
3019
|
+
}
|
|
3020
|
+
isCacheFresh() {
|
|
3021
|
+
if (!this.cachedState) {
|
|
3022
|
+
return false;
|
|
3023
|
+
}
|
|
3024
|
+
const now = Date.now();
|
|
3025
|
+
const { expiresAt } = this.cachedState.metadata;
|
|
3026
|
+
if (expiresAt !== undefined) {
|
|
3027
|
+
return now < expiresAt;
|
|
3028
|
+
}
|
|
3029
|
+
// No expiration info, check against default TTL
|
|
3030
|
+
const fetchedAt = this.cachedState.metadata.fetchedAt;
|
|
3031
|
+
return now < fetchedAt + this.cacheTtlMs;
|
|
3032
|
+
}
|
|
3033
|
+
async fetchPolicy(forceRefresh) {
|
|
3034
|
+
logger$i.debug("fetching_policy", {
|
|
3035
|
+
url: this.url,
|
|
3036
|
+
method: this.method,
|
|
3037
|
+
forceRefresh,
|
|
3038
|
+
});
|
|
3039
|
+
const requestHeaders = {
|
|
3040
|
+
Accept: "application/json, application/yaml, text/yaml, */*",
|
|
3041
|
+
...this.headers,
|
|
3042
|
+
};
|
|
3043
|
+
// Add bearer token if token provider is configured
|
|
3044
|
+
if (this.tokenProvider) {
|
|
3045
|
+
try {
|
|
3046
|
+
const token = await this.tokenProvider.getToken();
|
|
3047
|
+
if (token && token.value) {
|
|
3048
|
+
requestHeaders["Authorization"] = `${this.bearerPrefix}${token.value}`;
|
|
3049
|
+
logger$i.debug("added_bearer_token", { url: this.url });
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
catch (error) {
|
|
3053
|
+
logger$i.warning("token_provider_failed", {
|
|
3054
|
+
url: this.url,
|
|
3055
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3056
|
+
});
|
|
3057
|
+
// Continue without token - let the server decide if auth is required
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
// Add If-None-Match header for conditional request if we have a cached ETag
|
|
3061
|
+
// and this is not a forced refresh
|
|
3062
|
+
if (!forceRefresh && this.cachedState?.metadata.etag) {
|
|
3063
|
+
requestHeaders["If-None-Match"] = this.cachedState.metadata.etag;
|
|
3064
|
+
}
|
|
3065
|
+
const controller = new AbortController();
|
|
3066
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
3067
|
+
try {
|
|
3068
|
+
const response = await fetch(this.url, {
|
|
3069
|
+
method: this.method,
|
|
3070
|
+
headers: requestHeaders,
|
|
3071
|
+
signal: controller.signal,
|
|
3072
|
+
});
|
|
3073
|
+
clearTimeout(timeoutId);
|
|
3074
|
+
// Handle 304 Not Modified - return cached policy
|
|
3075
|
+
if (response.status === 304 && this.cachedState) {
|
|
3076
|
+
logger$i.debug("policy_not_modified", {
|
|
3077
|
+
url: this.url,
|
|
3078
|
+
etag: this.cachedState.metadata.etag,
|
|
3079
|
+
});
|
|
3080
|
+
// Update freshness timestamps
|
|
3081
|
+
const now = Date.now();
|
|
3082
|
+
const cacheControl = response.headers.get("Cache-Control");
|
|
3083
|
+
const maxAgeSeconds = parseMaxAge(cacheControl);
|
|
3084
|
+
const expiresAt = maxAgeSeconds !== undefined
|
|
3085
|
+
? now + maxAgeSeconds * 1000
|
|
3086
|
+
: now + this.cacheTtlMs;
|
|
3087
|
+
this.cachedState = {
|
|
3088
|
+
...this.cachedState,
|
|
3089
|
+
metadata: {
|
|
3090
|
+
...this.cachedState.metadata,
|
|
3091
|
+
fetchedAt: now,
|
|
3092
|
+
maxAgeSeconds,
|
|
3093
|
+
expiresAt,
|
|
3094
|
+
},
|
|
3095
|
+
};
|
|
3096
|
+
return this.cachedState.policy;
|
|
3097
|
+
}
|
|
3098
|
+
if (!response.ok) {
|
|
3099
|
+
const errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
3100
|
+
logger$i.error("policy_fetch_failed", {
|
|
3101
|
+
url: this.url,
|
|
3102
|
+
status: response.status,
|
|
3103
|
+
statusText: response.statusText,
|
|
3104
|
+
});
|
|
3105
|
+
// If we have a cached policy, preserve it and throw
|
|
3106
|
+
if (this.cachedState) {
|
|
3107
|
+
throw new Error(`Failed to fetch policy from ${this.url}: ${errorMessage}. ` +
|
|
3108
|
+
"Using last known good policy.");
|
|
3109
|
+
}
|
|
3110
|
+
throw new Error(`Failed to fetch policy from ${this.url}: ${errorMessage}`);
|
|
3111
|
+
}
|
|
3112
|
+
// Parse the response
|
|
3113
|
+
const contentType = response.headers.get("Content-Type");
|
|
3114
|
+
const content = await response.text();
|
|
3115
|
+
const format = detectFormat(contentType, content);
|
|
3116
|
+
let policyDefinition;
|
|
3117
|
+
try {
|
|
3118
|
+
if (format === "json") {
|
|
3119
|
+
policyDefinition = parseJson(content);
|
|
3120
|
+
}
|
|
3121
|
+
else {
|
|
3122
|
+
policyDefinition = parseYamlContent(content);
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
catch (parseError) {
|
|
3126
|
+
const message = parseError instanceof Error
|
|
3127
|
+
? parseError.message
|
|
3128
|
+
: String(parseError);
|
|
3129
|
+
logger$i.error("policy_parse_failed", {
|
|
3130
|
+
url: this.url,
|
|
3131
|
+
format,
|
|
3132
|
+
error: message,
|
|
3133
|
+
});
|
|
3134
|
+
// Preserve cached policy on parse failure
|
|
3135
|
+
if (this.cachedState) {
|
|
3136
|
+
throw new Error(`Failed to parse policy from ${this.url}: ${message}. ` +
|
|
3137
|
+
"Using last known good policy.");
|
|
3138
|
+
}
|
|
3139
|
+
throw new Error(`Failed to parse policy from ${this.url}: ${message}`);
|
|
3140
|
+
}
|
|
3141
|
+
logger$i.debug("parsed_policy_definition", {
|
|
3142
|
+
url: this.url,
|
|
3143
|
+
format,
|
|
3144
|
+
hasType: "type" in policyDefinition,
|
|
3145
|
+
});
|
|
3146
|
+
// Build the policy using the factory
|
|
3147
|
+
const policy = await this.buildPolicy(policyDefinition);
|
|
3148
|
+
// Update cache
|
|
3149
|
+
const now = Date.now();
|
|
3150
|
+
const etag = response.headers.get("ETag") ?? undefined;
|
|
3151
|
+
const cacheControl = response.headers.get("Cache-Control");
|
|
3152
|
+
const maxAgeSeconds = parseMaxAge(cacheControl);
|
|
3153
|
+
const expiresAt = maxAgeSeconds !== undefined
|
|
3154
|
+
? now + maxAgeSeconds * 1000
|
|
3155
|
+
: now + this.cacheTtlMs;
|
|
3156
|
+
this.cachedState = {
|
|
3157
|
+
policy,
|
|
3158
|
+
rawDefinition: policyDefinition,
|
|
3159
|
+
metadata: {
|
|
3160
|
+
url: this.url,
|
|
3161
|
+
status: response.status,
|
|
3162
|
+
etag,
|
|
3163
|
+
fetchedAt: now,
|
|
3164
|
+
maxAgeSeconds,
|
|
3165
|
+
expiresAt,
|
|
3166
|
+
},
|
|
3167
|
+
};
|
|
3168
|
+
logger$i.info("loaded_policy_from_http", {
|
|
3169
|
+
url: this.url,
|
|
3170
|
+
status: response.status,
|
|
3171
|
+
format,
|
|
3172
|
+
etag,
|
|
3173
|
+
maxAgeSeconds,
|
|
3174
|
+
});
|
|
3175
|
+
return policy;
|
|
3176
|
+
}
|
|
3177
|
+
catch (error) {
|
|
3178
|
+
clearTimeout(timeoutId);
|
|
3179
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
3180
|
+
const timeoutError = new Error(`Request to ${this.url} timed out after ${this.timeoutMs}ms`);
|
|
3181
|
+
logger$i.error("policy_fetch_timeout", {
|
|
3182
|
+
url: this.url,
|
|
3183
|
+
timeoutMs: this.timeoutMs,
|
|
3184
|
+
});
|
|
3185
|
+
// Preserve cached policy on timeout
|
|
3186
|
+
if (this.cachedState) {
|
|
3187
|
+
throw timeoutError;
|
|
3188
|
+
}
|
|
3189
|
+
throw timeoutError;
|
|
3190
|
+
}
|
|
3191
|
+
throw error;
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
async buildPolicy(policyDefinition) {
|
|
3195
|
+
// Determine the factory configuration to use
|
|
3196
|
+
const factoryConfig = this.policyFactoryConfig ?? policyDefinition;
|
|
3197
|
+
// Ensure we have a type field for the factory
|
|
3198
|
+
if (!("type" in factoryConfig) || typeof factoryConfig.type !== "string") {
|
|
3199
|
+
logger$i.warning("policy_type_missing_defaulting_to_basic", {
|
|
3200
|
+
url: this.url,
|
|
3201
|
+
});
|
|
3202
|
+
factoryConfig.type = "BasicAuthorizationPolicy";
|
|
3203
|
+
}
|
|
3204
|
+
// Build the factory config with the policy definition
|
|
3205
|
+
// The response content IS the policy definition, so we extract the type
|
|
3206
|
+
// and wrap the remaining content as the policyDefinition
|
|
3207
|
+
const { type: definitionType, ...restOfDefinition } = policyDefinition;
|
|
3208
|
+
const resolvedType = typeof definitionType === "string" && definitionType.trim().length > 0
|
|
3209
|
+
? definitionType
|
|
3210
|
+
: factoryConfig.type;
|
|
3211
|
+
const mergedConfig = this.policyFactoryConfig != null
|
|
3212
|
+
? { ...this.policyFactoryConfig, policyDefinition }
|
|
3213
|
+
: { type: resolvedType, policyDefinition: restOfDefinition };
|
|
3214
|
+
const policy = await AuthorizationPolicyFactory.createAuthorizationPolicy(mergedConfig);
|
|
3215
|
+
if (!policy) {
|
|
3216
|
+
throw new Error(`Failed to create authorization policy from ${this.url}`);
|
|
3217
|
+
}
|
|
3218
|
+
return policy;
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
var httpAuthorizationPolicySource = /*#__PURE__*/Object.freeze({
|
|
3223
|
+
__proto__: null,
|
|
3224
|
+
HttpAuthorizationPolicySource: HttpAuthorizationPolicySource
|
|
3225
|
+
});
|
|
3226
|
+
|
|
3227
|
+
/**
|
|
3228
|
+
* Factory for creating HttpAuthorizationPolicySource instances.
|
|
3229
|
+
*
|
|
3230
|
+
* @packageDocumentation
|
|
3231
|
+
*/
|
|
3232
|
+
let httpModulePromise = null;
|
|
3233
|
+
async function getHttpModule() {
|
|
3234
|
+
if (!httpModulePromise) {
|
|
3235
|
+
httpModulePromise = Promise.resolve().then(function () { return httpAuthorizationPolicySource; });
|
|
3236
|
+
}
|
|
3237
|
+
return httpModulePromise;
|
|
3238
|
+
}
|
|
3239
|
+
function normalizeConfig$5(config) {
|
|
3240
|
+
if (!config) {
|
|
3241
|
+
throw new Error("HttpAuthorizationPolicySourceFactory requires a configuration with a url");
|
|
3242
|
+
}
|
|
3243
|
+
const candidate = config;
|
|
3244
|
+
const url = candidate.url;
|
|
3245
|
+
if (typeof url !== "string" || url.trim().length === 0) {
|
|
3246
|
+
throw new Error("HttpAuthorizationPolicySourceConfig requires a non-empty url");
|
|
3247
|
+
}
|
|
3248
|
+
// Support both camelCase and snake_case
|
|
3249
|
+
const method = candidate.method ?? "GET";
|
|
3250
|
+
if (!["GET", "POST", "PUT"].includes(method)) {
|
|
3251
|
+
throw new Error(`Invalid method "${String(method)}". Must be "GET", "POST", or "PUT"`);
|
|
3252
|
+
}
|
|
3253
|
+
const timeoutMs = candidate.timeout_ms ??
|
|
3254
|
+
candidate.timeoutMs ??
|
|
3255
|
+
30000;
|
|
3256
|
+
if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
3257
|
+
throw new Error("timeout_ms must be a positive number");
|
|
3258
|
+
}
|
|
3259
|
+
const headers = candidate.headers;
|
|
3260
|
+
if (headers !== undefined && typeof headers !== "object") {
|
|
3261
|
+
throw new Error("headers must be an object");
|
|
3262
|
+
}
|
|
3263
|
+
const tokenProviderConfig = candidate.token_provider ??
|
|
3264
|
+
candidate.tokenProvider;
|
|
3265
|
+
const bearerPrefix = candidate.bearer_prefix ??
|
|
3266
|
+
candidate.bearerPrefix ??
|
|
3267
|
+
"Bearer ";
|
|
3268
|
+
const policyFactory = candidate.policy_factory ??
|
|
3269
|
+
candidate.policyFactory;
|
|
3270
|
+
const cacheTtlMs = candidate.cache_ttl_ms ??
|
|
3271
|
+
candidate.cacheTtlMs ??
|
|
3272
|
+
300000;
|
|
3273
|
+
if (typeof cacheTtlMs !== "number" || !Number.isFinite(cacheTtlMs) || cacheTtlMs < 0) {
|
|
3274
|
+
throw new Error("cache_ttl_ms must be a non-negative number");
|
|
3275
|
+
}
|
|
3276
|
+
return {
|
|
3277
|
+
url: url.trim(),
|
|
3278
|
+
method,
|
|
3279
|
+
timeoutMs,
|
|
3280
|
+
headers,
|
|
3281
|
+
tokenProviderConfig,
|
|
3282
|
+
bearerPrefix,
|
|
3283
|
+
policyFactory,
|
|
3284
|
+
cacheTtlMs,
|
|
3285
|
+
};
|
|
3286
|
+
}
|
|
3287
|
+
/**
|
|
3288
|
+
* Factory metadata for registration.
|
|
3289
|
+
*/
|
|
3290
|
+
const FACTORY_META$e = {
|
|
3291
|
+
base: AUTHORIZATION_POLICY_SOURCE_FACTORY_BASE_TYPE,
|
|
3292
|
+
key: "HttpAuthorizationPolicySource",
|
|
3293
|
+
};
|
|
3294
|
+
/**
|
|
3295
|
+
* Factory for creating HttpAuthorizationPolicySource instances.
|
|
3296
|
+
*
|
|
3297
|
+
* This factory uses lazy loading to avoid pulling in Node.js-specific
|
|
3298
|
+
* code (fetch operations) in browser environments where it may not work.
|
|
3299
|
+
*/
|
|
3300
|
+
class HttpAuthorizationPolicySourceFactory extends AuthorizationPolicySourceFactory {
|
|
3301
|
+
constructor() {
|
|
3302
|
+
super(...arguments);
|
|
3303
|
+
this.type = "HttpAuthorizationPolicySource";
|
|
3304
|
+
}
|
|
3305
|
+
/**
|
|
3306
|
+
* Creates an HttpAuthorizationPolicySource from the given configuration.
|
|
3307
|
+
*
|
|
3308
|
+
* @param config - Configuration specifying the policy URL and options
|
|
3309
|
+
* @returns The created policy source
|
|
3310
|
+
*/
|
|
3311
|
+
async create(config) {
|
|
3312
|
+
const normalized = normalizeConfig$5(config);
|
|
3313
|
+
// Create token provider if configured
|
|
3314
|
+
let tokenProvider;
|
|
3315
|
+
if (normalized.tokenProviderConfig) {
|
|
3316
|
+
tokenProvider = await TokenProviderFactory.createTokenProvider(normalized.tokenProviderConfig);
|
|
3317
|
+
}
|
|
3318
|
+
const { HttpAuthorizationPolicySource } = await getHttpModule();
|
|
3319
|
+
const options = {
|
|
3320
|
+
url: normalized.url,
|
|
3321
|
+
method: normalized.method,
|
|
3322
|
+
timeoutMs: normalized.timeoutMs,
|
|
3323
|
+
headers: normalized.headers,
|
|
3324
|
+
tokenProvider,
|
|
3325
|
+
bearerPrefix: normalized.bearerPrefix,
|
|
3326
|
+
policyFactory: normalized.policyFactory,
|
|
3327
|
+
cacheTtlMs: normalized.cacheTtlMs,
|
|
3328
|
+
};
|
|
3329
|
+
return new HttpAuthorizationPolicySource(options);
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
|
|
3333
|
+
var httpAuthorizationPolicySourceFactory = /*#__PURE__*/Object.freeze({
|
|
3334
|
+
__proto__: null,
|
|
3335
|
+
FACTORY_META: FACTORY_META$e,
|
|
3336
|
+
HttpAuthorizationPolicySourceFactory: HttpAuthorizationPolicySourceFactory,
|
|
3337
|
+
default: HttpAuthorizationPolicySourceFactory
|
|
3338
|
+
});
|
|
3339
|
+
|
|
3340
|
+
/**
|
|
3341
|
+
* HTTP Policy Authorization Profile
|
|
3342
|
+
*
|
|
3343
|
+
* Provides the 'policy-http' authorization profile for loading policies over HTTP(S).
|
|
3344
|
+
* This profile is similar to 'policy-localfile' from the runtime package but uses
|
|
3345
|
+
* the HttpAuthorizationPolicySource instead of LocalFileAuthorizationPolicySource.
|
|
3346
|
+
*/
|
|
3347
|
+
// Environment variable names for HTTP policy source
|
|
3348
|
+
const ENV_VAR_AUTH_POLICY_URL = "FAME_AUTH_POLICY_URL";
|
|
3349
|
+
const ENV_VAR_AUTH_POLICY_TIMEOUT_MS = "FAME_AUTH_POLICY_TIMEOUT_MS";
|
|
3350
|
+
const ENV_VAR_AUTH_POLICY_CACHE_TTL_MS = "FAME_AUTH_POLICY_CACHE_TTL_MS";
|
|
3351
|
+
const ENV_VAR_AUTH_POLICY_TOKEN_URL = "FAME_AUTH_POLICY_TOKEN_URL";
|
|
3352
|
+
const ENV_VAR_AUTH_POLICY_CLIENT_ID = "FAME_AUTH_POLICY_CLIENT_ID";
|
|
3353
|
+
const ENV_VAR_AUTH_POLICY_CLIENT_SECRET = "FAME_AUTH_POLICY_CLIENT_SECRET";
|
|
3354
|
+
const ENV_VAR_AUTH_POLICY_AUDIENCE = "FAME_AUTH_POLICY_AUDIENCE";
|
|
3355
|
+
// Legacy environment variable for backwards compatibility
|
|
3356
|
+
const ENV_VAR_AUTH_POLICY_BEARER_TOKEN = "FAME_AUTH_POLICY_BEARER_TOKEN";
|
|
3357
|
+
// Profile name constant
|
|
3358
|
+
const PROFILE_NAME_POLICY_HTTP = "policy-http";
|
|
3359
|
+
// Re-use JWT verifier env vars from runtime
|
|
3360
|
+
const ENV_VAR_JWKS_URL = "FAME_JWKS_URL";
|
|
3361
|
+
const ENV_VAR_JWT_TRUSTED_ISSUER = "FAME_JWT_TRUSTED_ISSUER";
|
|
3362
|
+
/**
|
|
3363
|
+
* Default token verifier configuration using JWKS.
|
|
3364
|
+
*/
|
|
3365
|
+
const DEFAULT_VERIFIER_CONFIG = {
|
|
3366
|
+
type: "JWKSJWTTokenVerifier",
|
|
3367
|
+
jwks_url: Expressions.env(ENV_VAR_JWKS_URL),
|
|
3368
|
+
issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER),
|
|
3369
|
+
};
|
|
3370
|
+
/**
|
|
3371
|
+
* Creates OAuth2 token provider configuration for HTTP policy source.
|
|
3372
|
+
*
|
|
3373
|
+
* Uses environment variables for OAuth2 client credentials flow.
|
|
3374
|
+
*/
|
|
3375
|
+
function createOAuth2TokenProviderConfig() {
|
|
3376
|
+
const tokenUrl = Expressions.env(ENV_VAR_AUTH_POLICY_TOKEN_URL);
|
|
3377
|
+
const clientId = Expressions.env(ENV_VAR_AUTH_POLICY_CLIENT_ID);
|
|
3378
|
+
const clientSecret = Expressions.env(ENV_VAR_AUTH_POLICY_CLIENT_SECRET);
|
|
3379
|
+
const audience = Expressions.env(ENV_VAR_AUTH_POLICY_AUDIENCE);
|
|
3380
|
+
return {
|
|
3381
|
+
type: "OAuth2ClientCredentialsTokenProvider",
|
|
3382
|
+
token_url: tokenUrl,
|
|
3383
|
+
tokenUrl,
|
|
3384
|
+
client_id: clientId,
|
|
3385
|
+
clientId,
|
|
3386
|
+
client_secret: clientSecret,
|
|
3387
|
+
clientSecret,
|
|
3388
|
+
scopes: ["policy.read"],
|
|
3389
|
+
audience,
|
|
3390
|
+
};
|
|
3391
|
+
}
|
|
3392
|
+
/**
|
|
3393
|
+
* Default HTTP policy source configuration.
|
|
3394
|
+
*
|
|
3395
|
+
* Uses environment variables for URL, timeout, and OAuth2 client credentials.
|
|
3396
|
+
*/
|
|
3397
|
+
const DEFAULT_HTTP_POLICY_SOURCE = {
|
|
3398
|
+
type: "HttpAuthorizationPolicySource",
|
|
3399
|
+
url: Expressions.env(ENV_VAR_AUTH_POLICY_URL),
|
|
3400
|
+
timeout_ms: Expressions.env(ENV_VAR_AUTH_POLICY_TIMEOUT_MS, "30000"),
|
|
3401
|
+
cache_ttl_ms: Expressions.env(ENV_VAR_AUTH_POLICY_CACHE_TTL_MS, "300000"),
|
|
3402
|
+
// OAuth2 client credentials token provider
|
|
3403
|
+
token_provider: createOAuth2TokenProviderConfig(),
|
|
3404
|
+
};
|
|
3405
|
+
const POLICY_HTTP_PROFILE = {
|
|
3406
|
+
type: "PolicyAuthorizer",
|
|
3407
|
+
verifier: DEFAULT_VERIFIER_CONFIG,
|
|
3408
|
+
policy_source: DEFAULT_HTTP_POLICY_SOURCE,
|
|
3409
|
+
};
|
|
3410
|
+
// Register the policy-http profile
|
|
3411
|
+
registerProfile(AUTHORIZER_FACTORY_BASE_TYPE, PROFILE_NAME_POLICY_HTTP, POLICY_HTTP_PROFILE, {
|
|
3412
|
+
source: "advanced-security:policy-http-authorization-profile",
|
|
3413
|
+
allowOverride: true,
|
|
3414
|
+
});
|
|
3415
|
+
|
|
2941
3416
|
const logger$h = getLogger("naylence.fame.security.cert.util");
|
|
2942
3417
|
const CACHE_LIMIT = 512;
|
|
2943
3418
|
const OID_ED25519 = "1.3.101.112";
|
|
@@ -8986,6 +9461,7 @@ var advancedWelcomeServiceFactory = /*#__PURE__*/Object.freeze({
|
|
|
8986
9461
|
*/
|
|
8987
9462
|
const MODULES = [
|
|
8988
9463
|
"./security/auth/policy/advanced-authorization-policy-factory.js",
|
|
9464
|
+
"./security/auth/policy/http-authorization-policy-source-factory.js",
|
|
8989
9465
|
"./security/cert/default-ca-service-factory.js",
|
|
8990
9466
|
"./security/cert/default-certificate-manager-factory.js",
|
|
8991
9467
|
"./security/cert/trust-store/browser-trust-store-provider-factory.js",
|
|
@@ -9003,6 +9479,7 @@ const MODULES = [
|
|
|
9003
9479
|
];
|
|
9004
9480
|
const MODULE_LOADERS = {
|
|
9005
9481
|
"./security/auth/policy/advanced-authorization-policy-factory.js": () => Promise.resolve().then(function () { return advancedAuthorizationPolicyFactory; }),
|
|
9482
|
+
"./security/auth/policy/http-authorization-policy-source-factory.js": () => Promise.resolve().then(function () { return httpAuthorizationPolicySourceFactory; }),
|
|
9006
9483
|
"./security/cert/default-ca-service-factory.js": () => Promise.resolve().then(function () { return defaultCaServiceFactory; }),
|
|
9007
9484
|
"./security/cert/default-certificate-manager-factory.js": () => Promise.resolve().then(function () { return defaultCertificateManagerFactory; }),
|
|
9008
9485
|
"./security/cert/trust-store/browser-trust-store-provider-factory.js": () => Promise.resolve().then(function () { return browserTrustStoreProviderFactory; }),
|
|
@@ -9092,6 +9569,7 @@ const SECURITY_PREFIX = "./security/";
|
|
|
9092
9569
|
const SECURITY_MODULES = MODULES.filter((spec) => spec.startsWith(SECURITY_PREFIX));
|
|
9093
9570
|
const EXTRA_MODULES = MODULES.filter((spec) => !spec.startsWith(SECURITY_PREFIX));
|
|
9094
9571
|
const NODE_ONLY_MODULES = new Set([
|
|
9572
|
+
"./security/auth/policy/http-authorization-policy-source-factory.js",
|
|
9095
9573
|
"./security/cert/default-ca-service-factory.js",
|
|
9096
9574
|
"./security/cert/trust-store/node-trust-store-provider-factory.js",
|
|
9097
9575
|
]);
|
|
@@ -12845,4 +13323,4 @@ var plugin = /*#__PURE__*/Object.freeze({
|
|
|
12845
13323
|
registerAdvancedSecurityPluginFactories: registerAdvancedSecurityPluginFactories
|
|
12846
13324
|
});
|
|
12847
13325
|
|
|
12848
|
-
export { FACTORY_META$
|
|
13326
|
+
export { FACTORY_META$f as ADVANCED_AUTHORIZATION_POLICY_FACTORY_META, FACTORY_META$9 as ADVANCED_EDDSA_ENVELOPE_SIGNER_FACTORY_META, FACTORY_META$8 as ADVANCED_EDDSA_ENVELOPE_VERIFIER_FACTORY_META, FACTORY_META$4 as ADVANCED_WELCOME_FACTORY_META, AFTHelper, AFTLoadBalancerStickinessManager, AFTLoadBalancerStickinessManagerFactory, AFTReplicaStickinessManager, AFTReplicaStickinessManagerFactory, FACTORY_META$6 as AFT_LOAD_BALANCER_FACTORY_META, FACTORY_META$5 as AFT_REPLICA_FACTORY_META, AdvancedAuthorizationPolicy, AdvancedAuthorizationPolicyFactory, AdvancedEdDSAEnvelopeSignerFactory, AdvancedEdDSAEnvelopeVerifierFactory, AdvancedWelcomeService, AdvancedWelcomeServiceFactory, CAServiceClient, CompositeEncryptionManager, CompositeEncryptionManagerFactory, FACTORY_META$b as DEFAULT_SECURE_CHANNEL_MANAGER_FACTORY_META, DEFAULT_STICKINESS_SECURITY_LEVEL, DefaultSecureChannelManager, DefaultSecureChannelManagerFactory, ENV_VAR_AUTH_POLICY_BEARER_TOKEN, ENV_VAR_AUTH_POLICY_CACHE_TTL_MS, ENV_VAR_AUTH_POLICY_TIMEOUT_MS, ENV_VAR_AUTH_POLICY_URL, ENV_VAR_FAME_CA_SERVICE_URL, EdDSAEnvelopeVerifier, GRANT_PURPOSE_CA_SIGN, FACTORY_META$e as HTTP_AUTHORIZATION_POLICY_SOURCE_FACTORY_META, HttpAuthorizationPolicySource, HttpAuthorizationPolicySourceFactory, NoAFTSigner, PROFILE_NAME_POLICY_HTTP, SidOnlyAFTVerifier, SignedAFTSigner, SignedOptionalAFTVerifier, StickinessMode, StrictAFTVerifier, UnsignedAFTSigner, VERSION, X5CKeyManager, X5CKeyManagerFactory, FACTORY_META$7 as X5C_KEY_MANAGER_FACTORY_META, __advancedSecurityPluginLoader, base64UrlDecode, base64UrlEncode, index as channelEncryption, createAftHelper, createAftPayload, createAftReplicaStickinessManager, createAftSigner, createAftVerifier, createEd25519Csr, extractCertificateInfo, formatCertificateInfo, normalizeStickinessMode, publicKeyFromX5c, registerAdvancedSecurityFactories, index$1 as sealedEncryption, serializeAftClaims, serializeAftHeader, utf8Decode, validateJwkX5cCertificate };
|