@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/node.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ExtensionManager, Expressions, Registry, AbstractResourceFactory, createResource, createDefaultResource } from '@naylence/factory';
|
|
2
|
-
import { getLogger, ENCRYPTION_MANAGER_FACTORY_BASE_TYPE, registerProfile, SECURITY_MANAGER_FACTORY_BASE_TYPE, KNOWN_POLICY_FIELDS, VALID_EFFECTS, compileGlobOnlyScopeRequirement, KNOWN_RULE_FIELDS, VALID_ACTIONS, compileGlobPattern, VALID_ORIGIN_TYPES, AUTHORIZATION_POLICY_FACTORY_BASE_TYPE, AuthorizationPolicyFactory, EncryptionResult, urlsafeBase64Decode, sealedDecrypt, sealedEncrypt, FIXED_PREFIX_LEN, urlsafeBase64Encode, EncryptionManagerFactory, 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 as TrustStoreProviderFactory$1, 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, formatTimestamp, AnsiColor, jsonDumps, validateHostLogicals, HTTP_CONNECTION_GRANT_TYPE, WELCOME_SERVICE_FACTORY_BASE_TYPE, WelcomeServiceFactory, NodePlacementStrategyFactory, TransportProvisionerFactory, TokenIssuerFactory, AuthorizerFactory, AuthInjectionStrategyFactory, CERTIFICATE_MANAGER_FACTORY_BASE_TYPE, CertificateManagerFactory, TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE as TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE$1, validateHostLogical } from '@naylence/runtime';
|
|
2
|
+
import { getLogger, ENCRYPTION_MANAGER_FACTORY_BASE_TYPE, registerProfile, SECURITY_MANAGER_FACTORY_BASE_TYPE, AUTHORIZER_FACTORY_BASE_TYPE, KNOWN_POLICY_FIELDS, VALID_EFFECTS, compileGlobOnlyScopeRequirement, KNOWN_RULE_FIELDS, VALID_ACTIONS, compileGlobPattern, VALID_ORIGIN_TYPES, AUTHORIZATION_POLICY_FACTORY_BASE_TYPE, AuthorizationPolicyFactory, AUTHORIZATION_POLICY_SOURCE_FACTORY_BASE_TYPE, AuthorizationPolicySourceFactory, TokenProviderFactory, EncryptionResult, urlsafeBase64Decode, sealedDecrypt, sealedEncrypt, FIXED_PREFIX_LEN, urlsafeBase64Encode, EncryptionManagerFactory, 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 as TrustStoreProviderFactory$1, 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, formatTimestamp, AnsiColor, jsonDumps, validateHostLogicals, HTTP_CONNECTION_GRANT_TYPE, WELCOME_SERVICE_FACTORY_BASE_TYPE, WelcomeServiceFactory, NodePlacementStrategyFactory, TransportProvisionerFactory, TokenIssuerFactory, AuthorizerFactory, AuthInjectionStrategyFactory, CERTIFICATE_MANAGER_FACTORY_BASE_TYPE, CertificateManagerFactory, TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE as TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE$1, validateHostLogical } from '@naylence/runtime';
|
|
3
3
|
import { sha256 } from '@noble/hashes/sha2';
|
|
4
4
|
import { generateFingerprintSync, localDeliveryContext, createFameEnvelope, FameAddress, generateId, formatAddress, SigningMaterial, DeliveryOriginType as DeliveryOriginType$1 } from '@naylence/core';
|
|
5
|
+
import { parse as parse$1 } from 'yaml';
|
|
5
6
|
import { AsnConvert, OctetString } from '@peculiar/asn1-schema';
|
|
6
7
|
import { Certificate, id_ce_subjectAltName, SubjectAlternativeName, id_ce_nameConstraints, NameConstraints, Name, RelativeDistinguishedName, AttributeTypeAndValue, AttributeValue, SubjectPublicKeyInfo, GeneralName, Extensions, Extension, Attribute, AlgorithmIdentifier, TBSCertificate, Validity, Version, BasicConstraints, id_ce_basicConstraints, KeyUsageFlags, KeyUsage, id_ce_keyUsage, SubjectKeyIdentifier, id_ce_subjectKeyIdentifier, AuthorityKeyIdentifier, KeyIdentifier, id_ce_authorityKeyIdentifier, GeneralSubtrees, GeneralSubtree, ExtendedKeyUsage, id_kp_clientAuth, id_kp_serverAuth, id_ce_extKeyUsage } from '@peculiar/asn1-x509';
|
|
7
8
|
import { sha512, sha256 as sha256$1 } from '@noble/hashes/sha2.js';
|
|
@@ -23,6 +24,7 @@ import { sha256 as sha256$2 } from '@noble/hashes/sha256.js';
|
|
|
23
24
|
*/
|
|
24
25
|
const MODULES = [
|
|
25
26
|
"./security/auth/policy/advanced-authorization-policy-factory.js",
|
|
27
|
+
"./security/auth/policy/http-authorization-policy-source-factory.js",
|
|
26
28
|
"./security/cert/default-ca-service-factory.js",
|
|
27
29
|
"./security/cert/default-certificate-manager-factory.js",
|
|
28
30
|
"./security/cert/trust-store/browser-trust-store-provider-factory.js",
|
|
@@ -40,6 +42,7 @@ const MODULES = [
|
|
|
40
42
|
];
|
|
41
43
|
const MODULE_LOADERS = {
|
|
42
44
|
"./security/auth/policy/advanced-authorization-policy-factory.js": () => Promise.resolve().then(function () { return advancedAuthorizationPolicyFactory; }),
|
|
45
|
+
"./security/auth/policy/http-authorization-policy-source-factory.js": () => Promise.resolve().then(function () { return httpAuthorizationPolicySourceFactory; }),
|
|
43
46
|
"./security/cert/default-ca-service-factory.js": () => Promise.resolve().then(function () { return defaultCaServiceFactory; }),
|
|
44
47
|
"./security/cert/default-certificate-manager-factory.js": () => Promise.resolve().then(function () { return defaultCertificateManagerFactory; }),
|
|
45
48
|
"./security/cert/trust-store/browser-trust-store-provider-factory.js": () => Promise.resolve().then(function () { return browserTrustStoreProviderFactory; }),
|
|
@@ -56,7 +59,7 @@ const MODULE_LOADERS = {
|
|
|
56
59
|
"./welcome/advanced-welcome-service-factory.js": () => Promise.resolve().then(function () { return advancedWelcomeServiceFactory; }),
|
|
57
60
|
};
|
|
58
61
|
|
|
59
|
-
const logger$
|
|
62
|
+
const logger$i = getLogger("naylence.fame.security.encryption.encryption_manager_registry");
|
|
60
63
|
class EncryptionManagerFactoryRegistry {
|
|
61
64
|
constructor(autoDiscover = true) {
|
|
62
65
|
this.factories = [];
|
|
@@ -78,7 +81,7 @@ class EncryptionManagerFactoryRegistry {
|
|
|
78
81
|
let registeredCount = 0;
|
|
79
82
|
for (const [factoryName, info] of extensionInfos) {
|
|
80
83
|
if (factoryName === "CompositeEncryptionManager") {
|
|
81
|
-
logger$
|
|
84
|
+
logger$i.debug("skipping_composite_factory_to_avoid_circular_dependency", {
|
|
82
85
|
factory_name: factoryName,
|
|
83
86
|
});
|
|
84
87
|
continue;
|
|
@@ -88,7 +91,7 @@ class EncryptionManagerFactoryRegistry {
|
|
|
88
91
|
ExtensionManager.getGlobalFactory(ENCRYPTION_MANAGER_FACTORY_BASE_TYPE, factoryName));
|
|
89
92
|
this.registerFactory(factoryInstance, { autoDiscovered: true });
|
|
90
93
|
registeredCount += 1;
|
|
91
|
-
logger$
|
|
94
|
+
logger$i.debug("auto_discovered_factory", {
|
|
92
95
|
factory_name: factoryName,
|
|
93
96
|
factory_class: factoryInstance.constructor.name,
|
|
94
97
|
algorithms: factoryInstance.getSupportedAlgorithms(),
|
|
@@ -97,21 +100,21 @@ class EncryptionManagerFactoryRegistry {
|
|
|
97
100
|
});
|
|
98
101
|
}
|
|
99
102
|
catch (error) {
|
|
100
|
-
logger$
|
|
103
|
+
logger$i.warning("failed_to_auto_register_factory", {
|
|
101
104
|
factory_name: factoryName,
|
|
102
105
|
error: error instanceof Error ? error.message : String(error),
|
|
103
106
|
});
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
this.autoDiscovered = true;
|
|
107
|
-
logger$
|
|
110
|
+
logger$i.debug("completed_auto_discovery", {
|
|
108
111
|
registered_factories: registeredCount,
|
|
109
112
|
total_discovered: extensionInfos.size,
|
|
110
113
|
skipped_composite: true,
|
|
111
114
|
});
|
|
112
115
|
}
|
|
113
116
|
catch (error) {
|
|
114
|
-
logger$
|
|
117
|
+
logger$i.warning("failed_auto_discovery_of_factories", {
|
|
115
118
|
error: error instanceof Error ? error.message : String(error),
|
|
116
119
|
});
|
|
117
120
|
}
|
|
@@ -129,7 +132,7 @@ class EncryptionManagerFactoryRegistry {
|
|
|
129
132
|
const existing = this.algorithmToFactory.get(algorithm);
|
|
130
133
|
if (!existing || factory.getPriority() > existing.getPriority()) {
|
|
131
134
|
this.algorithmToFactory.set(algorithm, factory);
|
|
132
|
-
logger$
|
|
135
|
+
logger$i.debug("registered_algorithm_mapping", {
|
|
133
136
|
algorithm,
|
|
134
137
|
factory: factory.constructor.name,
|
|
135
138
|
priority: factory.getPriority(),
|
|
@@ -141,7 +144,7 @@ class EncryptionManagerFactoryRegistry {
|
|
|
141
144
|
typeFactories.push(factory);
|
|
142
145
|
typeFactories.sort((a, b) => b.getPriority() - a.getPriority());
|
|
143
146
|
this.typeToFactories.set(encryptionType, typeFactories);
|
|
144
|
-
logger$
|
|
147
|
+
logger$i.debug("registered_encryption_manager_factory", {
|
|
145
148
|
factory: factory.constructor.name,
|
|
146
149
|
encryption_type: encryptionType,
|
|
147
150
|
algorithms: factory.getSupportedAlgorithms(),
|
|
@@ -157,14 +160,14 @@ class EncryptionManagerFactoryRegistry {
|
|
|
157
160
|
this.ensureAutoDiscovery();
|
|
158
161
|
for (const factory of this.factories) {
|
|
159
162
|
if (factory.supportsOptions(opts ?? undefined)) {
|
|
160
|
-
logger$
|
|
163
|
+
logger$i.debug("found_factory_for_options", {
|
|
161
164
|
factory: factory.constructor.name,
|
|
162
165
|
encryption_type: factory.getEncryptionType(),
|
|
163
166
|
});
|
|
164
167
|
return factory;
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
|
-
logger$
|
|
170
|
+
logger$i.debug("no_factory_found_for_options", { opts });
|
|
168
171
|
return undefined;
|
|
169
172
|
}
|
|
170
173
|
getFactoriesByType(encryptionType) {
|
|
@@ -289,10 +292,87 @@ var strictOverlaySecurityProfile = /*#__PURE__*/Object.freeze({
|
|
|
289
292
|
PROFILE_NAME_STRICT_OVERLAY: PROFILE_NAME_STRICT_OVERLAY
|
|
290
293
|
});
|
|
291
294
|
|
|
295
|
+
/**
|
|
296
|
+
* HTTP Policy Authorization Profile
|
|
297
|
+
*
|
|
298
|
+
* Provides the 'policy-http' authorization profile for loading policies over HTTP(S).
|
|
299
|
+
* This profile is similar to 'policy-localfile' from the runtime package but uses
|
|
300
|
+
* the HttpAuthorizationPolicySource instead of LocalFileAuthorizationPolicySource.
|
|
301
|
+
*/
|
|
302
|
+
// Environment variable names for HTTP policy source
|
|
303
|
+
const ENV_VAR_AUTH_POLICY_URL = "FAME_AUTH_POLICY_URL";
|
|
304
|
+
const ENV_VAR_AUTH_POLICY_TIMEOUT_MS = "FAME_AUTH_POLICY_TIMEOUT_MS";
|
|
305
|
+
const ENV_VAR_AUTH_POLICY_CACHE_TTL_MS = "FAME_AUTH_POLICY_CACHE_TTL_MS";
|
|
306
|
+
const ENV_VAR_AUTH_POLICY_TOKEN_URL = "FAME_AUTH_POLICY_TOKEN_URL";
|
|
307
|
+
const ENV_VAR_AUTH_POLICY_CLIENT_ID = "FAME_AUTH_POLICY_CLIENT_ID";
|
|
308
|
+
const ENV_VAR_AUTH_POLICY_CLIENT_SECRET = "FAME_AUTH_POLICY_CLIENT_SECRET";
|
|
309
|
+
const ENV_VAR_AUTH_POLICY_AUDIENCE = "FAME_AUTH_POLICY_AUDIENCE";
|
|
310
|
+
// Legacy environment variable for backwards compatibility
|
|
311
|
+
const ENV_VAR_AUTH_POLICY_BEARER_TOKEN = "FAME_AUTH_POLICY_BEARER_TOKEN";
|
|
312
|
+
// Profile name constant
|
|
313
|
+
const PROFILE_NAME_POLICY_HTTP = "policy-http";
|
|
314
|
+
// Re-use JWT verifier env vars from runtime
|
|
315
|
+
const ENV_VAR_JWKS_URL = "FAME_JWKS_URL";
|
|
316
|
+
const ENV_VAR_JWT_TRUSTED_ISSUER = "FAME_JWT_TRUSTED_ISSUER";
|
|
317
|
+
/**
|
|
318
|
+
* Default token verifier configuration using JWKS.
|
|
319
|
+
*/
|
|
320
|
+
const DEFAULT_VERIFIER_CONFIG = {
|
|
321
|
+
type: "JWKSJWTTokenVerifier",
|
|
322
|
+
jwks_url: Expressions.env(ENV_VAR_JWKS_URL),
|
|
323
|
+
issuer: Expressions.env(ENV_VAR_JWT_TRUSTED_ISSUER),
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Creates OAuth2 token provider configuration for HTTP policy source.
|
|
327
|
+
*
|
|
328
|
+
* Uses environment variables for OAuth2 client credentials flow.
|
|
329
|
+
*/
|
|
330
|
+
function createOAuth2TokenProviderConfig() {
|
|
331
|
+
const tokenUrl = Expressions.env(ENV_VAR_AUTH_POLICY_TOKEN_URL);
|
|
332
|
+
const clientId = Expressions.env(ENV_VAR_AUTH_POLICY_CLIENT_ID);
|
|
333
|
+
const clientSecret = Expressions.env(ENV_VAR_AUTH_POLICY_CLIENT_SECRET);
|
|
334
|
+
const audience = Expressions.env(ENV_VAR_AUTH_POLICY_AUDIENCE);
|
|
335
|
+
return {
|
|
336
|
+
type: "OAuth2ClientCredentialsTokenProvider",
|
|
337
|
+
token_url: tokenUrl,
|
|
338
|
+
tokenUrl,
|
|
339
|
+
client_id: clientId,
|
|
340
|
+
clientId,
|
|
341
|
+
client_secret: clientSecret,
|
|
342
|
+
clientSecret,
|
|
343
|
+
scopes: ["policy.read"],
|
|
344
|
+
audience,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Default HTTP policy source configuration.
|
|
349
|
+
*
|
|
350
|
+
* Uses environment variables for URL, timeout, and OAuth2 client credentials.
|
|
351
|
+
*/
|
|
352
|
+
const DEFAULT_HTTP_POLICY_SOURCE = {
|
|
353
|
+
type: "HttpAuthorizationPolicySource",
|
|
354
|
+
url: Expressions.env(ENV_VAR_AUTH_POLICY_URL),
|
|
355
|
+
timeout_ms: Expressions.env(ENV_VAR_AUTH_POLICY_TIMEOUT_MS, "30000"),
|
|
356
|
+
cache_ttl_ms: Expressions.env(ENV_VAR_AUTH_POLICY_CACHE_TTL_MS, "300000"),
|
|
357
|
+
// OAuth2 client credentials token provider
|
|
358
|
+
token_provider: createOAuth2TokenProviderConfig(),
|
|
359
|
+
};
|
|
360
|
+
const POLICY_HTTP_PROFILE = {
|
|
361
|
+
type: "PolicyAuthorizer",
|
|
362
|
+
verifier: DEFAULT_VERIFIER_CONFIG,
|
|
363
|
+
policy_source: DEFAULT_HTTP_POLICY_SOURCE,
|
|
364
|
+
};
|
|
365
|
+
// Register the policy-http profile
|
|
366
|
+
registerProfile(AUTHORIZER_FACTORY_BASE_TYPE, PROFILE_NAME_POLICY_HTTP, POLICY_HTTP_PROFILE, {
|
|
367
|
+
source: "advanced-security:policy-http-authorization-profile",
|
|
368
|
+
allowOverride: true,
|
|
369
|
+
});
|
|
370
|
+
|
|
292
371
|
const SECURITY_PREFIX = "./security/";
|
|
293
372
|
const SECURITY_MODULES = MODULES.filter((spec) => spec.startsWith(SECURITY_PREFIX));
|
|
294
373
|
const EXTRA_MODULES = MODULES.filter((spec) => !spec.startsWith(SECURITY_PREFIX));
|
|
295
374
|
const NODE_ONLY_MODULES = new Set([
|
|
375
|
+
"./security/auth/policy/http-authorization-policy-source-factory.js",
|
|
296
376
|
"./security/cert/default-ca-service-factory.js",
|
|
297
377
|
"./security/cert/trust-store/node-trust-store-provider-factory.js",
|
|
298
378
|
]);
|
|
@@ -573,12 +653,12 @@ async function registerAdvancedSecurityFactories(registrar = Registry, options)
|
|
|
573
653
|
}
|
|
574
654
|
|
|
575
655
|
// This file is auto-generated during build - do not edit manually
|
|
576
|
-
// Generated from package.json version: 0.4.
|
|
656
|
+
// Generated from package.json version: 0.4.7
|
|
577
657
|
/**
|
|
578
658
|
* The package version, injected at build time.
|
|
579
659
|
* @internal
|
|
580
660
|
*/
|
|
581
|
-
const VERSION = '0.4.
|
|
661
|
+
const VERSION = '0.4.7';
|
|
582
662
|
|
|
583
663
|
async function registerAdvancedSecurityPluginFactories(registrar = Registry) {
|
|
584
664
|
await registerAdvancedSecurityFactories(registrar, { includeExtras: true });
|
|
@@ -3484,7 +3564,7 @@ function getModule() {
|
|
|
3484
3564
|
}
|
|
3485
3565
|
return modulePromise;
|
|
3486
3566
|
}
|
|
3487
|
-
function normalizeConfig$
|
|
3567
|
+
function normalizeConfig$6(config) {
|
|
3488
3568
|
if (!config) {
|
|
3489
3569
|
throw new Error("AdvancedAuthorizationPolicyFactory requires a configuration with a policyDefinition");
|
|
3490
3570
|
}
|
|
@@ -3513,7 +3593,7 @@ function normalizeConfig$5(config) {
|
|
|
3513
3593
|
/**
|
|
3514
3594
|
* Factory metadata for registration.
|
|
3515
3595
|
*/
|
|
3516
|
-
const FACTORY_META$
|
|
3596
|
+
const FACTORY_META$g = {
|
|
3517
3597
|
base: AUTHORIZATION_POLICY_FACTORY_BASE_TYPE,
|
|
3518
3598
|
key: "AdvancedAuthorizationPolicy",
|
|
3519
3599
|
};
|
|
@@ -3532,7 +3612,7 @@ class AdvancedAuthorizationPolicyFactory extends AuthorizationPolicyFactory {
|
|
|
3532
3612
|
* @returns The created authorization policy
|
|
3533
3613
|
*/
|
|
3534
3614
|
async create(config) {
|
|
3535
|
-
const normalized = normalizeConfig$
|
|
3615
|
+
const normalized = normalizeConfig$6(config);
|
|
3536
3616
|
const { AdvancedAuthorizationPolicy } = await getModule();
|
|
3537
3617
|
return new AdvancedAuthorizationPolicy({
|
|
3538
3618
|
policyDefinition: normalized.policyDefinition,
|
|
@@ -3545,10 +3625,493 @@ class AdvancedAuthorizationPolicyFactory extends AuthorizationPolicyFactory {
|
|
|
3545
3625
|
var advancedAuthorizationPolicyFactory = /*#__PURE__*/Object.freeze({
|
|
3546
3626
|
__proto__: null,
|
|
3547
3627
|
AdvancedAuthorizationPolicyFactory: AdvancedAuthorizationPolicyFactory,
|
|
3548
|
-
FACTORY_META: FACTORY_META$
|
|
3628
|
+
FACTORY_META: FACTORY_META$g,
|
|
3549
3629
|
default: AdvancedAuthorizationPolicyFactory
|
|
3550
3630
|
});
|
|
3551
3631
|
|
|
3632
|
+
/**
|
|
3633
|
+
* HTTP-based authorization policy source.
|
|
3634
|
+
*
|
|
3635
|
+
* Loads authorization policies from an HTTP endpoint supporting JSON or YAML.
|
|
3636
|
+
* Supports bearer authentication via TokenProvider and HTTP caching via ETag.
|
|
3637
|
+
*
|
|
3638
|
+
* This is a Node.js-only implementation.
|
|
3639
|
+
*
|
|
3640
|
+
* @packageDocumentation
|
|
3641
|
+
*/
|
|
3642
|
+
const logger$h = getLogger("naylence.fame.security.auth.policy.http_authorization_policy_source");
|
|
3643
|
+
function isPlainObject(value) {
|
|
3644
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3645
|
+
}
|
|
3646
|
+
function parseJson(content) {
|
|
3647
|
+
const parsed = JSON.parse(content);
|
|
3648
|
+
if (!isPlainObject(parsed)) {
|
|
3649
|
+
throw new Error("Parsed JSON policy must be an object");
|
|
3650
|
+
}
|
|
3651
|
+
return parsed;
|
|
3652
|
+
}
|
|
3653
|
+
function parseYamlContent(content) {
|
|
3654
|
+
const parsed = parse$1(content ?? "");
|
|
3655
|
+
if (parsed == null) {
|
|
3656
|
+
return {};
|
|
3657
|
+
}
|
|
3658
|
+
if (!isPlainObject(parsed)) {
|
|
3659
|
+
throw new Error("Parsed YAML policy must be an object");
|
|
3660
|
+
}
|
|
3661
|
+
return parsed;
|
|
3662
|
+
}
|
|
3663
|
+
/**
|
|
3664
|
+
* Detect whether content is JSON or YAML based on Content-Type header.
|
|
3665
|
+
* Falls back to sniffing the content if Content-Type is not definitive.
|
|
3666
|
+
*/
|
|
3667
|
+
function detectFormat(contentType, content) {
|
|
3668
|
+
if (contentType) {
|
|
3669
|
+
const lower = contentType.toLowerCase();
|
|
3670
|
+
if (lower.includes("application/json") ||
|
|
3671
|
+
lower.includes("text/json")) {
|
|
3672
|
+
return "json";
|
|
3673
|
+
}
|
|
3674
|
+
if (lower.includes("application/yaml") ||
|
|
3675
|
+
lower.includes("application/x-yaml") ||
|
|
3676
|
+
lower.includes("text/yaml") ||
|
|
3677
|
+
lower.includes("text/x-yaml")) {
|
|
3678
|
+
return "yaml";
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
// Sniff by first non-whitespace character
|
|
3682
|
+
const trimmed = content.trimStart();
|
|
3683
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
3684
|
+
return "json";
|
|
3685
|
+
}
|
|
3686
|
+
// Default to YAML
|
|
3687
|
+
return "yaml";
|
|
3688
|
+
}
|
|
3689
|
+
/**
|
|
3690
|
+
* Parse Cache-Control header to extract max-age value.
|
|
3691
|
+
*/
|
|
3692
|
+
function parseMaxAge(cacheControl) {
|
|
3693
|
+
if (!cacheControl) {
|
|
3694
|
+
return undefined;
|
|
3695
|
+
}
|
|
3696
|
+
const match = cacheControl.match(/max-age\s*=\s*(\d+)/i);
|
|
3697
|
+
if (match && match[1]) {
|
|
3698
|
+
const seconds = parseInt(match[1], 10);
|
|
3699
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
3700
|
+
return seconds;
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
return undefined;
|
|
3704
|
+
}
|
|
3705
|
+
/**
|
|
3706
|
+
* An authorization policy source that loads policy definitions from an HTTP endpoint.
|
|
3707
|
+
*
|
|
3708
|
+
* Supports JSON and YAML formats, bearer authentication via TokenProvider,
|
|
3709
|
+
* and HTTP caching via ETag and Cache-Control headers.
|
|
3710
|
+
*
|
|
3711
|
+
* This is a Node.js-only implementation that uses fetch.
|
|
3712
|
+
*/
|
|
3713
|
+
class HttpAuthorizationPolicySource {
|
|
3714
|
+
constructor(options) {
|
|
3715
|
+
this.cachedState = null;
|
|
3716
|
+
this.inflightFetch = null;
|
|
3717
|
+
if (!options.url || typeof options.url !== "string") {
|
|
3718
|
+
throw new Error("HttpAuthorizationPolicySource requires a valid URL");
|
|
3719
|
+
}
|
|
3720
|
+
this.url = options.url;
|
|
3721
|
+
this.method = options.method ?? "GET";
|
|
3722
|
+
this.timeoutMs = options.timeoutMs ?? 30000;
|
|
3723
|
+
this.headers = { ...options.headers };
|
|
3724
|
+
this.tokenProvider = options.tokenProvider;
|
|
3725
|
+
this.bearerPrefix = options.bearerPrefix ?? "Bearer ";
|
|
3726
|
+
this.policyFactoryConfig = options.policyFactory;
|
|
3727
|
+
this.cacheTtlMs = options.cacheTtlMs ?? 300000; // 5 minutes default
|
|
3728
|
+
}
|
|
3729
|
+
/**
|
|
3730
|
+
* Loads the authorization policy from the configured HTTP endpoint.
|
|
3731
|
+
*
|
|
3732
|
+
* Returns a cached policy if still fresh (based on TTL or cache headers).
|
|
3733
|
+
* Multiple concurrent calls are de-duplicated (single-flight pattern).
|
|
3734
|
+
*
|
|
3735
|
+
* @returns The loaded authorization policy
|
|
3736
|
+
*/
|
|
3737
|
+
async loadPolicy() {
|
|
3738
|
+
// Return cached policy if still fresh
|
|
3739
|
+
if (this.cachedState && this.isCacheFresh()) {
|
|
3740
|
+
logger$h.debug("returning_cached_policy", {
|
|
3741
|
+
url: this.url,
|
|
3742
|
+
fetchedAt: this.cachedState.metadata.fetchedAt,
|
|
3743
|
+
expiresAt: this.cachedState.metadata.expiresAt,
|
|
3744
|
+
});
|
|
3745
|
+
return this.cachedState.policy;
|
|
3746
|
+
}
|
|
3747
|
+
// De-duplicate concurrent requests
|
|
3748
|
+
if (this.inflightFetch) {
|
|
3749
|
+
return this.inflightFetch;
|
|
3750
|
+
}
|
|
3751
|
+
this.inflightFetch = this.fetchPolicy(false);
|
|
3752
|
+
try {
|
|
3753
|
+
return await this.inflightFetch;
|
|
3754
|
+
}
|
|
3755
|
+
finally {
|
|
3756
|
+
this.inflightFetch = null;
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
/**
|
|
3760
|
+
* Forces a reload of the policy from the HTTP endpoint.
|
|
3761
|
+
*
|
|
3762
|
+
* Bypasses cache freshness checks and always fetches from the server.
|
|
3763
|
+
* If the fetch fails, the existing cached policy is preserved and the error is thrown.
|
|
3764
|
+
*
|
|
3765
|
+
* @returns The reloaded authorization policy
|
|
3766
|
+
*/
|
|
3767
|
+
async reloadPolicy() {
|
|
3768
|
+
// Clear inflight to force a new request
|
|
3769
|
+
this.inflightFetch = null;
|
|
3770
|
+
return this.fetchPolicy(true);
|
|
3771
|
+
}
|
|
3772
|
+
/**
|
|
3773
|
+
* Clears the cached policy, forcing a fresh fetch on the next loadPolicy() call.
|
|
3774
|
+
*/
|
|
3775
|
+
clearCache() {
|
|
3776
|
+
this.cachedState = null;
|
|
3777
|
+
this.inflightFetch = null;
|
|
3778
|
+
}
|
|
3779
|
+
/**
|
|
3780
|
+
* Returns metadata about the last successful fetch.
|
|
3781
|
+
*
|
|
3782
|
+
* Useful for verification, monitoring, or debugging.
|
|
3783
|
+
*/
|
|
3784
|
+
getMetadata() {
|
|
3785
|
+
return this.cachedState?.metadata;
|
|
3786
|
+
}
|
|
3787
|
+
/**
|
|
3788
|
+
* Returns the raw policy definition from the last successful fetch.
|
|
3789
|
+
*
|
|
3790
|
+
* Useful for verification or reprocessing.
|
|
3791
|
+
*/
|
|
3792
|
+
getRawDefinition() {
|
|
3793
|
+
return this.cachedState?.rawDefinition;
|
|
3794
|
+
}
|
|
3795
|
+
isCacheFresh() {
|
|
3796
|
+
if (!this.cachedState) {
|
|
3797
|
+
return false;
|
|
3798
|
+
}
|
|
3799
|
+
const now = Date.now();
|
|
3800
|
+
const { expiresAt } = this.cachedState.metadata;
|
|
3801
|
+
if (expiresAt !== undefined) {
|
|
3802
|
+
return now < expiresAt;
|
|
3803
|
+
}
|
|
3804
|
+
// No expiration info, check against default TTL
|
|
3805
|
+
const fetchedAt = this.cachedState.metadata.fetchedAt;
|
|
3806
|
+
return now < fetchedAt + this.cacheTtlMs;
|
|
3807
|
+
}
|
|
3808
|
+
async fetchPolicy(forceRefresh) {
|
|
3809
|
+
logger$h.debug("fetching_policy", {
|
|
3810
|
+
url: this.url,
|
|
3811
|
+
method: this.method,
|
|
3812
|
+
forceRefresh,
|
|
3813
|
+
});
|
|
3814
|
+
const requestHeaders = {
|
|
3815
|
+
Accept: "application/json, application/yaml, text/yaml, */*",
|
|
3816
|
+
...this.headers,
|
|
3817
|
+
};
|
|
3818
|
+
// Add bearer token if token provider is configured
|
|
3819
|
+
if (this.tokenProvider) {
|
|
3820
|
+
try {
|
|
3821
|
+
const token = await this.tokenProvider.getToken();
|
|
3822
|
+
if (token && token.value) {
|
|
3823
|
+
requestHeaders["Authorization"] = `${this.bearerPrefix}${token.value}`;
|
|
3824
|
+
logger$h.debug("added_bearer_token", { url: this.url });
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
catch (error) {
|
|
3828
|
+
logger$h.warning("token_provider_failed", {
|
|
3829
|
+
url: this.url,
|
|
3830
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3831
|
+
});
|
|
3832
|
+
// Continue without token - let the server decide if auth is required
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
// Add If-None-Match header for conditional request if we have a cached ETag
|
|
3836
|
+
// and this is not a forced refresh
|
|
3837
|
+
if (!forceRefresh && this.cachedState?.metadata.etag) {
|
|
3838
|
+
requestHeaders["If-None-Match"] = this.cachedState.metadata.etag;
|
|
3839
|
+
}
|
|
3840
|
+
const controller = new AbortController();
|
|
3841
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
3842
|
+
try {
|
|
3843
|
+
const response = await fetch(this.url, {
|
|
3844
|
+
method: this.method,
|
|
3845
|
+
headers: requestHeaders,
|
|
3846
|
+
signal: controller.signal,
|
|
3847
|
+
});
|
|
3848
|
+
clearTimeout(timeoutId);
|
|
3849
|
+
// Handle 304 Not Modified - return cached policy
|
|
3850
|
+
if (response.status === 304 && this.cachedState) {
|
|
3851
|
+
logger$h.debug("policy_not_modified", {
|
|
3852
|
+
url: this.url,
|
|
3853
|
+
etag: this.cachedState.metadata.etag,
|
|
3854
|
+
});
|
|
3855
|
+
// Update freshness timestamps
|
|
3856
|
+
const now = Date.now();
|
|
3857
|
+
const cacheControl = response.headers.get("Cache-Control");
|
|
3858
|
+
const maxAgeSeconds = parseMaxAge(cacheControl);
|
|
3859
|
+
const expiresAt = maxAgeSeconds !== undefined
|
|
3860
|
+
? now + maxAgeSeconds * 1000
|
|
3861
|
+
: now + this.cacheTtlMs;
|
|
3862
|
+
this.cachedState = {
|
|
3863
|
+
...this.cachedState,
|
|
3864
|
+
metadata: {
|
|
3865
|
+
...this.cachedState.metadata,
|
|
3866
|
+
fetchedAt: now,
|
|
3867
|
+
maxAgeSeconds,
|
|
3868
|
+
expiresAt,
|
|
3869
|
+
},
|
|
3870
|
+
};
|
|
3871
|
+
return this.cachedState.policy;
|
|
3872
|
+
}
|
|
3873
|
+
if (!response.ok) {
|
|
3874
|
+
const errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
3875
|
+
logger$h.error("policy_fetch_failed", {
|
|
3876
|
+
url: this.url,
|
|
3877
|
+
status: response.status,
|
|
3878
|
+
statusText: response.statusText,
|
|
3879
|
+
});
|
|
3880
|
+
// If we have a cached policy, preserve it and throw
|
|
3881
|
+
if (this.cachedState) {
|
|
3882
|
+
throw new Error(`Failed to fetch policy from ${this.url}: ${errorMessage}. ` +
|
|
3883
|
+
"Using last known good policy.");
|
|
3884
|
+
}
|
|
3885
|
+
throw new Error(`Failed to fetch policy from ${this.url}: ${errorMessage}`);
|
|
3886
|
+
}
|
|
3887
|
+
// Parse the response
|
|
3888
|
+
const contentType = response.headers.get("Content-Type");
|
|
3889
|
+
const content = await response.text();
|
|
3890
|
+
const format = detectFormat(contentType, content);
|
|
3891
|
+
let policyDefinition;
|
|
3892
|
+
try {
|
|
3893
|
+
if (format === "json") {
|
|
3894
|
+
policyDefinition = parseJson(content);
|
|
3895
|
+
}
|
|
3896
|
+
else {
|
|
3897
|
+
policyDefinition = parseYamlContent(content);
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
catch (parseError) {
|
|
3901
|
+
const message = parseError instanceof Error
|
|
3902
|
+
? parseError.message
|
|
3903
|
+
: String(parseError);
|
|
3904
|
+
logger$h.error("policy_parse_failed", {
|
|
3905
|
+
url: this.url,
|
|
3906
|
+
format,
|
|
3907
|
+
error: message,
|
|
3908
|
+
});
|
|
3909
|
+
// Preserve cached policy on parse failure
|
|
3910
|
+
if (this.cachedState) {
|
|
3911
|
+
throw new Error(`Failed to parse policy from ${this.url}: ${message}. ` +
|
|
3912
|
+
"Using last known good policy.");
|
|
3913
|
+
}
|
|
3914
|
+
throw new Error(`Failed to parse policy from ${this.url}: ${message}`);
|
|
3915
|
+
}
|
|
3916
|
+
logger$h.debug("parsed_policy_definition", {
|
|
3917
|
+
url: this.url,
|
|
3918
|
+
format,
|
|
3919
|
+
hasType: "type" in policyDefinition,
|
|
3920
|
+
});
|
|
3921
|
+
// Build the policy using the factory
|
|
3922
|
+
const policy = await this.buildPolicy(policyDefinition);
|
|
3923
|
+
// Update cache
|
|
3924
|
+
const now = Date.now();
|
|
3925
|
+
const etag = response.headers.get("ETag") ?? undefined;
|
|
3926
|
+
const cacheControl = response.headers.get("Cache-Control");
|
|
3927
|
+
const maxAgeSeconds = parseMaxAge(cacheControl);
|
|
3928
|
+
const expiresAt = maxAgeSeconds !== undefined
|
|
3929
|
+
? now + maxAgeSeconds * 1000
|
|
3930
|
+
: now + this.cacheTtlMs;
|
|
3931
|
+
this.cachedState = {
|
|
3932
|
+
policy,
|
|
3933
|
+
rawDefinition: policyDefinition,
|
|
3934
|
+
metadata: {
|
|
3935
|
+
url: this.url,
|
|
3936
|
+
status: response.status,
|
|
3937
|
+
etag,
|
|
3938
|
+
fetchedAt: now,
|
|
3939
|
+
maxAgeSeconds,
|
|
3940
|
+
expiresAt,
|
|
3941
|
+
},
|
|
3942
|
+
};
|
|
3943
|
+
logger$h.info("loaded_policy_from_http", {
|
|
3944
|
+
url: this.url,
|
|
3945
|
+
status: response.status,
|
|
3946
|
+
format,
|
|
3947
|
+
etag,
|
|
3948
|
+
maxAgeSeconds,
|
|
3949
|
+
});
|
|
3950
|
+
return policy;
|
|
3951
|
+
}
|
|
3952
|
+
catch (error) {
|
|
3953
|
+
clearTimeout(timeoutId);
|
|
3954
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
3955
|
+
const timeoutError = new Error(`Request to ${this.url} timed out after ${this.timeoutMs}ms`);
|
|
3956
|
+
logger$h.error("policy_fetch_timeout", {
|
|
3957
|
+
url: this.url,
|
|
3958
|
+
timeoutMs: this.timeoutMs,
|
|
3959
|
+
});
|
|
3960
|
+
// Preserve cached policy on timeout
|
|
3961
|
+
if (this.cachedState) {
|
|
3962
|
+
throw timeoutError;
|
|
3963
|
+
}
|
|
3964
|
+
throw timeoutError;
|
|
3965
|
+
}
|
|
3966
|
+
throw error;
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
async buildPolicy(policyDefinition) {
|
|
3970
|
+
// Determine the factory configuration to use
|
|
3971
|
+
const factoryConfig = this.policyFactoryConfig ?? policyDefinition;
|
|
3972
|
+
// Ensure we have a type field for the factory
|
|
3973
|
+
if (!("type" in factoryConfig) || typeof factoryConfig.type !== "string") {
|
|
3974
|
+
logger$h.warning("policy_type_missing_defaulting_to_basic", {
|
|
3975
|
+
url: this.url,
|
|
3976
|
+
});
|
|
3977
|
+
factoryConfig.type = "BasicAuthorizationPolicy";
|
|
3978
|
+
}
|
|
3979
|
+
// Build the factory config with the policy definition
|
|
3980
|
+
// The response content IS the policy definition, so we extract the type
|
|
3981
|
+
// and wrap the remaining content as the policyDefinition
|
|
3982
|
+
const { type: definitionType, ...restOfDefinition } = policyDefinition;
|
|
3983
|
+
const resolvedType = typeof definitionType === "string" && definitionType.trim().length > 0
|
|
3984
|
+
? definitionType
|
|
3985
|
+
: factoryConfig.type;
|
|
3986
|
+
const mergedConfig = this.policyFactoryConfig != null
|
|
3987
|
+
? { ...this.policyFactoryConfig, policyDefinition }
|
|
3988
|
+
: { type: resolvedType, policyDefinition: restOfDefinition };
|
|
3989
|
+
const policy = await AuthorizationPolicyFactory.createAuthorizationPolicy(mergedConfig);
|
|
3990
|
+
if (!policy) {
|
|
3991
|
+
throw new Error(`Failed to create authorization policy from ${this.url}`);
|
|
3992
|
+
}
|
|
3993
|
+
return policy;
|
|
3994
|
+
}
|
|
3995
|
+
}
|
|
3996
|
+
|
|
3997
|
+
var httpAuthorizationPolicySource = /*#__PURE__*/Object.freeze({
|
|
3998
|
+
__proto__: null,
|
|
3999
|
+
HttpAuthorizationPolicySource: HttpAuthorizationPolicySource
|
|
4000
|
+
});
|
|
4001
|
+
|
|
4002
|
+
/**
|
|
4003
|
+
* Factory for creating HttpAuthorizationPolicySource instances.
|
|
4004
|
+
*
|
|
4005
|
+
* @packageDocumentation
|
|
4006
|
+
*/
|
|
4007
|
+
let httpModulePromise = null;
|
|
4008
|
+
async function getHttpModule() {
|
|
4009
|
+
if (!httpModulePromise) {
|
|
4010
|
+
httpModulePromise = Promise.resolve().then(function () { return httpAuthorizationPolicySource; });
|
|
4011
|
+
}
|
|
4012
|
+
return httpModulePromise;
|
|
4013
|
+
}
|
|
4014
|
+
function normalizeConfig$5(config) {
|
|
4015
|
+
if (!config) {
|
|
4016
|
+
throw new Error("HttpAuthorizationPolicySourceFactory requires a configuration with a url");
|
|
4017
|
+
}
|
|
4018
|
+
const candidate = config;
|
|
4019
|
+
const url = candidate.url;
|
|
4020
|
+
if (typeof url !== "string" || url.trim().length === 0) {
|
|
4021
|
+
throw new Error("HttpAuthorizationPolicySourceConfig requires a non-empty url");
|
|
4022
|
+
}
|
|
4023
|
+
// Support both camelCase and snake_case
|
|
4024
|
+
const method = candidate.method ?? "GET";
|
|
4025
|
+
if (!["GET", "POST", "PUT"].includes(method)) {
|
|
4026
|
+
throw new Error(`Invalid method "${String(method)}". Must be "GET", "POST", or "PUT"`);
|
|
4027
|
+
}
|
|
4028
|
+
const timeoutMs = candidate.timeout_ms ??
|
|
4029
|
+
candidate.timeoutMs ??
|
|
4030
|
+
30000;
|
|
4031
|
+
if (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
4032
|
+
throw new Error("timeout_ms must be a positive number");
|
|
4033
|
+
}
|
|
4034
|
+
const headers = candidate.headers;
|
|
4035
|
+
if (headers !== undefined && typeof headers !== "object") {
|
|
4036
|
+
throw new Error("headers must be an object");
|
|
4037
|
+
}
|
|
4038
|
+
const tokenProviderConfig = candidate.token_provider ??
|
|
4039
|
+
candidate.tokenProvider;
|
|
4040
|
+
const bearerPrefix = candidate.bearer_prefix ??
|
|
4041
|
+
candidate.bearerPrefix ??
|
|
4042
|
+
"Bearer ";
|
|
4043
|
+
const policyFactory = candidate.policy_factory ??
|
|
4044
|
+
candidate.policyFactory;
|
|
4045
|
+
const cacheTtlMs = candidate.cache_ttl_ms ??
|
|
4046
|
+
candidate.cacheTtlMs ??
|
|
4047
|
+
300000;
|
|
4048
|
+
if (typeof cacheTtlMs !== "number" || !Number.isFinite(cacheTtlMs) || cacheTtlMs < 0) {
|
|
4049
|
+
throw new Error("cache_ttl_ms must be a non-negative number");
|
|
4050
|
+
}
|
|
4051
|
+
return {
|
|
4052
|
+
url: url.trim(),
|
|
4053
|
+
method,
|
|
4054
|
+
timeoutMs,
|
|
4055
|
+
headers,
|
|
4056
|
+
tokenProviderConfig,
|
|
4057
|
+
bearerPrefix,
|
|
4058
|
+
policyFactory,
|
|
4059
|
+
cacheTtlMs,
|
|
4060
|
+
};
|
|
4061
|
+
}
|
|
4062
|
+
/**
|
|
4063
|
+
* Factory metadata for registration.
|
|
4064
|
+
*/
|
|
4065
|
+
const FACTORY_META$f = {
|
|
4066
|
+
base: AUTHORIZATION_POLICY_SOURCE_FACTORY_BASE_TYPE,
|
|
4067
|
+
key: "HttpAuthorizationPolicySource",
|
|
4068
|
+
};
|
|
4069
|
+
/**
|
|
4070
|
+
* Factory for creating HttpAuthorizationPolicySource instances.
|
|
4071
|
+
*
|
|
4072
|
+
* This factory uses lazy loading to avoid pulling in Node.js-specific
|
|
4073
|
+
* code (fetch operations) in browser environments where it may not work.
|
|
4074
|
+
*/
|
|
4075
|
+
class HttpAuthorizationPolicySourceFactory extends AuthorizationPolicySourceFactory {
|
|
4076
|
+
constructor() {
|
|
4077
|
+
super(...arguments);
|
|
4078
|
+
this.type = "HttpAuthorizationPolicySource";
|
|
4079
|
+
}
|
|
4080
|
+
/**
|
|
4081
|
+
* Creates an HttpAuthorizationPolicySource from the given configuration.
|
|
4082
|
+
*
|
|
4083
|
+
* @param config - Configuration specifying the policy URL and options
|
|
4084
|
+
* @returns The created policy source
|
|
4085
|
+
*/
|
|
4086
|
+
async create(config) {
|
|
4087
|
+
const normalized = normalizeConfig$5(config);
|
|
4088
|
+
// Create token provider if configured
|
|
4089
|
+
let tokenProvider;
|
|
4090
|
+
if (normalized.tokenProviderConfig) {
|
|
4091
|
+
tokenProvider = await TokenProviderFactory.createTokenProvider(normalized.tokenProviderConfig);
|
|
4092
|
+
}
|
|
4093
|
+
const { HttpAuthorizationPolicySource } = await getHttpModule();
|
|
4094
|
+
const options = {
|
|
4095
|
+
url: normalized.url,
|
|
4096
|
+
method: normalized.method,
|
|
4097
|
+
timeoutMs: normalized.timeoutMs,
|
|
4098
|
+
headers: normalized.headers,
|
|
4099
|
+
tokenProvider,
|
|
4100
|
+
bearerPrefix: normalized.bearerPrefix,
|
|
4101
|
+
policyFactory: normalized.policyFactory,
|
|
4102
|
+
cacheTtlMs: normalized.cacheTtlMs,
|
|
4103
|
+
};
|
|
4104
|
+
return new HttpAuthorizationPolicySource(options);
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
|
|
4108
|
+
var httpAuthorizationPolicySourceFactory = /*#__PURE__*/Object.freeze({
|
|
4109
|
+
__proto__: null,
|
|
4110
|
+
FACTORY_META: FACTORY_META$f,
|
|
4111
|
+
HttpAuthorizationPolicySourceFactory: HttpAuthorizationPolicySourceFactory,
|
|
4112
|
+
default: HttpAuthorizationPolicySourceFactory
|
|
4113
|
+
});
|
|
4114
|
+
|
|
3552
4115
|
/**
|
|
3553
4116
|
* Advanced authorization policy module exports.
|
|
3554
4117
|
*
|
|
@@ -3557,7 +4120,7 @@ var advancedAuthorizationPolicyFactory = /*#__PURE__*/Object.freeze({
|
|
|
3557
4120
|
*
|
|
3558
4121
|
* @packageDocumentation
|
|
3559
4122
|
*/
|
|
3560
|
-
//
|
|
4123
|
+
// Expression authorization policy
|
|
3561
4124
|
|
|
3562
4125
|
/**
|
|
3563
4126
|
* Advanced security authentication/authorization module exports.
|
|
@@ -13182,4 +13745,4 @@ if (isNode && proc && proc.env) {
|
|
|
13182
13745
|
}
|
|
13183
13746
|
}
|
|
13184
13747
|
|
|
13185
|
-
export { FACTORY_META$
|
|
13748
|
+
export { FACTORY_META$g as ADVANCED_AUTHORIZATION_POLICY_FACTORY_META, FACTORY_META$a as ADVANCED_EDDSA_ENVELOPE_SIGNER_FACTORY_META, FACTORY_META$9 as ADVANCED_EDDSA_ENVELOPE_VERIFIER_FACTORY_META, FACTORY_META$5 as ADVANCED_WELCOME_FACTORY_META, AFTHelper, AFTLoadBalancerStickinessManager, AFTLoadBalancerStickinessManagerFactory, AFTReplicaStickinessManager, AFTReplicaStickinessManagerFactory, FACTORY_META$7 as AFT_LOAD_BALANCER_FACTORY_META, FACTORY_META$6 as AFT_REPLICA_FACTORY_META, AdvancedAuthorizationPolicy, AdvancedAuthorizationPolicyFactory, AdvancedEdDSAEnvelopeSignerFactory, AdvancedEdDSAEnvelopeVerifierFactory, AdvancedWelcomeService, AdvancedWelcomeServiceFactory, FACTORY_META$2 as BROWSER_TRUST_STORE_PROVIDER_FACTORY_META, BrowserTrustStoreProviderFactory, CAService, CAServiceClient, CAServiceFactory, CASigningService, CA_SERVICE_FACTORY_BASE_TYPE, CertificateRequestError, CompositeEncryptionManager, CompositeEncryptionManagerFactory, FACTORY_META$4 as DEFAULT_CERTIFICATE_MANAGER_FACTORY_META, FACTORY_META$c as DEFAULT_SECURE_CHANNEL_MANAGER_FACTORY_META, DEFAULT_STICKINESS_SECURITY_LEVEL, DefaultCAService, DefaultCAServiceFactory, DefaultCertificateManager, DefaultCertificateManagerFactory, DefaultSecureChannelManager, DefaultSecureChannelManagerFactory, ENV_FAME_CA_CERT_FILE, ENV_FAME_CA_CERT_PEM, ENV_FAME_CA_KEY_FILE, ENV_FAME_CA_KEY_PEM, ENV_FAME_INTERMEDIATE_CHAIN_FILE, ENV_FAME_INTERMEDIATE_CHAIN_PEM, ENV_FAME_SIGNING_CERT_FILE, ENV_FAME_SIGNING_CERT_PEM, ENV_FAME_SIGNING_KEY_FILE, ENV_FAME_SIGNING_KEY_PEM, FACTORY_META$3 as ENV_TRUST_STORE_PROVIDER_FACTORY_META, 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, EnvTrustStoreProviderFactory, GRANT_PURPOSE_CA_SIGN, FACTORY_META$f as HTTP_AUTHORIZATION_POLICY_SOURCE_FACTORY_META, HttpAuthorizationPolicySource, HttpAuthorizationPolicySourceFactory, LOGICALS_OID, NODE_ID_OID, NoAFTSigner, NullTrustStoreProvider, PROFILE_NAME_POLICY_HTTP, PROFILE_NAME_STRICT_OVERLAY, SID_OID, SidOnlyAFTVerifier, SignedAFTSigner, SignedOptionalAFTVerifier, StickinessMode, StrictAFTVerifier, TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE, TrustStoreProviderFactory, UnsignedAFTSigner, VERSION, X5CKeyManager, X5CKeyManagerFactory, FACTORY_META$8 as X5C_KEY_MANAGER_FACTORY_META, __advancedSecurityPluginLoader, base64UrlDecode, base64UrlEncode, index as channelEncryption, createAftHelper, createAftPayload, createAftReplicaStickinessManager, createAftSigner, createAftVerifier, createEd25519Csr, createEd25519CsrFromPem, createTestCA, extractCertificateInfo, extractLogicalHostsFromCert, extractNodeIdFromCert, extractSidFromCert, extractSidFromSpiffeId, extractSpiffeIdFromCert, formatCertificateInfo, normalizeStickinessMode, publicKeyFromX5c, registerAdvancedSecurityFactories, index$1 as sealedEncryption, serializeAftClaims, serializeAftHeader, utf8Decode, validateJwkX5cCertificate, verifyCertSidIntegrity };
|