@backstage/plugin-auth-backend 0.6.0 → 0.6.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @backstage/plugin-auth-backend
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e0e57817d2: Added Google Cloud Identity-Aware Proxy as an identity provider.
8
+ - Updated dependencies
9
+ - @backstage/backend-common@0.10.2
10
+
3
11
  ## 0.6.0
4
12
 
5
13
  ### Minor Changes
package/dist/index.cjs.js CHANGED
@@ -24,6 +24,7 @@ var openidClient = require('openid-client');
24
24
  var passportOktaOauth = require('passport-okta-oauth');
25
25
  var passportOneloginOauth = require('passport-onelogin-oauth');
26
26
  var passportSaml = require('passport-saml');
27
+ var googleAuthLibrary = require('google-auth-library');
27
28
  var catalogClient = require('@backstage/catalog-client');
28
29
  var uuid = require('uuid');
29
30
  var luxon = require('luxon');
@@ -865,7 +866,7 @@ const createAuth0Provider = (options) => {
865
866
  };
866
867
 
867
868
  const ALB_JWT_HEADER = "x-amzn-oidc-data";
868
- const ALB_ACCESSTOKEN_HEADER = "x-amzn-oidc-accesstoken";
869
+ const ALB_ACCESS_TOKEN_HEADER = "x-amzn-oidc-accesstoken";
869
870
  const getJWTHeaders = (input) => {
870
871
  const encoded = input.split(".")[0];
871
872
  return JSON.parse(Buffer.from(encoded, "base64").toString("utf8"));
@@ -900,12 +901,12 @@ class AwsAlbAuthProvider {
900
901
  }
901
902
  async getResult(req) {
902
903
  const jwt = req.header(ALB_JWT_HEADER);
903
- const accessToken = req.header(ALB_ACCESSTOKEN_HEADER);
904
+ const accessToken = req.header(ALB_ACCESS_TOKEN_HEADER);
904
905
  if (jwt === void 0) {
905
906
  throw new errors.AuthenticationError(`Missing ALB OIDC header: ${ALB_JWT_HEADER}`);
906
907
  }
907
908
  if (accessToken === void 0) {
908
- throw new errors.AuthenticationError(`Missing ALB OIDC header: ${ALB_ACCESSTOKEN_HEADER}`);
909
+ throw new errors.AuthenticationError(`Missing ALB OIDC header: ${ALB_ACCESS_TOKEN_HEADER}`);
909
910
  }
910
911
  try {
911
912
  const headers = getJWTHeaders(jwt);
@@ -2404,6 +2405,96 @@ const createSamlProvider = (options) => {
2404
2405
  };
2405
2406
  };
2406
2407
 
2408
+ const IAP_JWT_HEADER = "x-goog-iap-jwt-assertion";
2409
+
2410
+ function createTokenValidator(audience, mockClient) {
2411
+ const client = mockClient != null ? mockClient : new googleAuthLibrary.OAuth2Client();
2412
+ return async function tokenValidator(token) {
2413
+ const response = await client.getIapPublicKeys();
2414
+ const ticket = await client.verifySignedJwtWithCertsAsync(token, response.pubkeys, audience, ["https://cloud.google.com/iap"]);
2415
+ const payload = ticket.getPayload();
2416
+ if (!payload) {
2417
+ throw new TypeError("Token had no payload");
2418
+ }
2419
+ return payload;
2420
+ };
2421
+ }
2422
+ async function parseRequestToken(jwtToken, tokenValidator) {
2423
+ if (typeof jwtToken !== "string" || !jwtToken) {
2424
+ throw new errors.AuthenticationError(`Missing Google IAP header: ${IAP_JWT_HEADER}`);
2425
+ }
2426
+ let payload;
2427
+ try {
2428
+ payload = await tokenValidator(jwtToken);
2429
+ } catch (e) {
2430
+ throw new errors.AuthenticationError(`Google IAP token verification failed, ${e}`);
2431
+ }
2432
+ if (!payload.sub || !payload.email) {
2433
+ throw new errors.AuthenticationError("Google IAP token payload is missing sub and/or email claim");
2434
+ }
2435
+ return {
2436
+ iapToken: {
2437
+ ...payload,
2438
+ sub: payload.sub,
2439
+ email: payload.email
2440
+ }
2441
+ };
2442
+ }
2443
+ const defaultAuthHandler = async ({
2444
+ iapToken
2445
+ }) => ({ profile: { email: iapToken.email } });
2446
+
2447
+ class GcpIapProvider {
2448
+ constructor(options) {
2449
+ this.authHandler = options.authHandler;
2450
+ this.signInResolver = options.signInResolver;
2451
+ this.tokenValidator = options.tokenValidator;
2452
+ this.tokenIssuer = options.tokenIssuer;
2453
+ this.catalogIdentityClient = options.catalogIdentityClient;
2454
+ this.logger = options.logger;
2455
+ }
2456
+ async start() {
2457
+ }
2458
+ async frameHandler() {
2459
+ }
2460
+ async refresh(req, res) {
2461
+ const result = await parseRequestToken(req.header(IAP_JWT_HEADER), this.tokenValidator);
2462
+ const { profile } = await this.authHandler(result);
2463
+ const backstageIdentity = await this.signInResolver({ profile, result }, {
2464
+ tokenIssuer: this.tokenIssuer,
2465
+ catalogIdentityClient: this.catalogIdentityClient,
2466
+ logger: this.logger
2467
+ });
2468
+ const response = {
2469
+ providerInfo: { iapToken: result.iapToken },
2470
+ profile,
2471
+ backstageIdentity: prepareBackstageIdentityResponse(backstageIdentity)
2472
+ };
2473
+ res.json(response);
2474
+ }
2475
+ }
2476
+ function createGcpIapProvider(options) {
2477
+ return ({ config, tokenIssuer, catalogApi, logger }) => {
2478
+ var _a;
2479
+ const audience = config.getString("audience");
2480
+ const authHandler = (_a = options.authHandler) != null ? _a : defaultAuthHandler;
2481
+ const signInResolver = options.signIn.resolver;
2482
+ const tokenValidator = createTokenValidator(audience);
2483
+ const catalogIdentityClient = new CatalogIdentityClient({
2484
+ catalogApi,
2485
+ tokenIssuer
2486
+ });
2487
+ return new GcpIapProvider({
2488
+ authHandler,
2489
+ signInResolver,
2490
+ tokenValidator,
2491
+ tokenIssuer,
2492
+ catalogIdentityClient,
2493
+ logger
2494
+ });
2495
+ };
2496
+ }
2497
+
2407
2498
  const factories = {
2408
2499
  google: createGoogleProvider(),
2409
2500
  github: createGithubProvider(),
@@ -2872,6 +2963,7 @@ exports.createAtlassianProvider = createAtlassianProvider;
2872
2963
  exports.createAuth0Provider = createAuth0Provider;
2873
2964
  exports.createAwsAlbProvider = createAwsAlbProvider;
2874
2965
  exports.createBitbucketProvider = createBitbucketProvider;
2966
+ exports.createGcpIapProvider = createGcpIapProvider;
2875
2967
  exports.createGithubProvider = createGithubProvider;
2876
2968
  exports.createGitlabProvider = createGitlabProvider;
2877
2969
  exports.createGoogleProvider = createGoogleProvider;