1${ 2 [1].map(i => { 3 const type = `${fake.helpers.randomize(['kubernetes', 'jwt', 'oidc'])}`; 4 const cert = `-----BEGIN CERTIFICATE----- 5MIIH/TCCBeWgAwIBAgIQaBYE3/M08XHYCnNVmcFBcjANBgkqhkiG9w0BAQsFADBy 6MQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVGV4YXMxEDAOBgNVBAcMB0hvdXN0b24x 7ETAPBgNVBAoMCFNTTCBDb3JwMS4wLAYDVQQDDCVTU0wuY29tIEVWIFNTTCBJbnRl 8cm1lZGlhdGUgQ0EgUlNBIFIzMB4XDTIwMDQwMTAwNTgzM1oXDTIxMDcxNjAwNTgz 9M1owgb0xCzAJBgNVBAYTAlVTMQ4wDAYDVQQIDAVUZXhhczEQMA4GA1UEBwwHSG91 10c3RvbjERMA8GA1UECgwIU1NMIENvcnAxFjAUBgNVBAUTDU5WMjAwODE2MTQyNDMx 11FDASBgNVBAMMC3d3dy5zc2wuY29tMR0wGwYDVQQPDBRQcml2YXRlIE9yZ2FuaXph 12dGlvbjEXMBUGCysGAQQBgjc8AgECDAZOZXZhZGExEzARBgsrBgEEAYI3PAIBAxMC 13VVMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDHheRkbb1FCc7xRKst 14wK0JIGaKY8t7JbS2bQ2b6YIJDgnHuIYHqBrCUV79oelikkokRkFvcvpaKinFHDQH 15UpWEI6RUERYmSCg3O8Wi42uOcV2B5ZabmXCkwdxY5Ecl51BbM8UnGdoAGbdNmiRm 16SmTjcs+lhMxg4fFY6lBpiEVFiGUjGRR+61R67Lz6U4KJeLNcCm07QwFYKBmpi08g 17-----END CERTIFICATE-----`; 18 let sourceType; 19 20 if (type !== 'kubernetes') { 21 sourceType = `${fake.helpers.randomize(['JWTValidationPubKeys', 'JWKSURL', 'OIDCDiscoveryURL'])}`; 22 } 23 24 const claimMappings = { 25 "http://example.com/example-1": `${fake.hacker.noun()}`, 26 "http://example.com/example-2": `${fake.hacker.noun()}` 27 } 28 const listClaimMappings = { 29 "http://example.com/example-1": `${fake.hacker.noun()}` 30 } 31 const namespaceRules = `[ 32 { 33 "Selector": "${fake.hacker.noun()} in list.group", 34 "BindNamespace": "dc-1" 35 }, 36 { 37 "Selector": "serviceaccount.namespace!=${fake.hacker.noun()}", 38 "BindNamespace": "dc-2" 39 }, 40 { 41 "Selector": "serviceaccount.namespace==${fake.hacker.noun()}", 42 "BindNamespace": "dc-3" 43 } 44 ]`; 45 46 let config = {}; 47 switch(type) { 48 case 'kubernetes': 49 config = { 50 Host: `https://${fake.internet.ip()}:8443`, 51 CACert: cert, 52 ServiceAccountJWT: `eyJhbGciOiJ${fake.internet.password(25)}.eyJ${fake.internet.password(61)}.${fake.internet.password(32)}` 53 }; 54 break; 55 case 'oidc': 56 config = { 57 OIDCDiscoveryURL: `https://${fake.internet.ip()}:8443`, 58 OIDCDiscoveryCACert: cert, 59 OIDCClientID: `${fake.hacker.noun()}-ID`, 60 OIDCClientSecret: `${fake.hacker.noun()}-secret`, 61 BoundAudiences: ["aud_example_0", "aud_example_1"], 62 OIDCScopes: ["scope_01", "scope_02", "scope_03"], 63 JWTSupportedAlgs: ["RS256", "RS257"], 64 VerboseOIDCLogging: true, 65 AllowedRedirectURIs: ["http://example.com/example-1", "http://example.com/example-2", "http://example.com/example-3"], 66 ClaimMappings: claimMappings, 67 ListClaimMappings: listClaimMappings 68 }; 69 break; 70 case 'jwt': 71 config = { 72 JWTSupportedAlgs: ["RS256", "RS257"], 73 BoundAudiences: ["aud_example_0", "aud_example_1"], 74 BoundIssuer: `${fake.hacker.noun()}-issuer`, 75 ExpirationLeeway: `${fake.random.number({min: 0, max: 60})}`, 76 NotBeforeLeeway: `${fake.random.number({min: 0, max: 60})}`, 77 ClockSkewLeeway: `${fake.random.number({min: 0, max: 60})}`, 78 ClaimMappings: claimMappings, 79 ListClaimMappings: listClaimMappings 80 }; 81 break; 82 } 83 84 switch(sourceType) { 85 case 'JWTValidationPubKeys': 86 config.JWTValidationPubKeys = cert; 87 break; 88 case 'JWKSURL': 89 config.JWKSURL = `https://${fake.internet.ip()}:8443`; 90 config.JWKSCACert = cert; 91 break; 92 case 'OIDCDiscoveryURL': 93 config.OIDCDiscoveryURL = `https://${fake.internet.ip()}:8443`; 94 break; 95 } 96 97 return `{ 98 "Name": "${location.pathname.get(3)}", 99 "Namespace": "${ 100 typeof location.search.ns !== 'undefined' ? location.search.ns : 101 typeof http.body.Namespace !== 'undefined' ? http.body.Namespace : 'default' 102 }", 103 "Type": "${type}", 104 "Description": "${fake.lorem.sentence()}", 105 "DisplayName": "${fake.hacker.noun()}", 106 "MaxTokenTTL": "${fake.random.number({min: 0, max: 60})}m${fake.random.number({min: 0, max: 60})}s", 107 "TokenLocality": "${fake.helpers.randomize(['local', 'global', ''])}", 108 "NamespaceRules": ${namespaceRules}, 109 "Config": ${JSON.stringify(config)}, 110 "CreateIndex": ${fake.random.number()}, 111 "ModifyIndex": 10 112 }` 113 }) 114} 115