Skip to content

Commit

Permalink
feat(proxy-sigv4-backend): add region and service options (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: jsecchiero <[email protected]>
  • Loading branch information
jsecchiero authored Oct 23, 2024
1 parent d9eb5b0 commit d05d196
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
12 changes: 9 additions & 3 deletions plugins/proxy-sigv4-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,22 @@ proxysigv4:
### Expanded form
The expanded form is necessary when an `AssumeRole` call _is_ required, _or_ if the target API service and region cannot
be automatically derived from the URL (commonplace when a custom domain name has been configured for an API Gateway
endpoint).
The expanded form is necessary when:
- `AssumeRole` call _is_ required, _or_ if the target API service and region cannot
be automatically derived from the URL (commonplace when a custom domain name has been configured for an API Gateway
endpoint).
- The service if not possible to determine it automatically.
- The region if not possible to determine it automatically.

```yaml
proxysigv4:
'/some-local-path':
target: 'https://<API ID>.execute-api.<region>.amazonaws.com'
roleArn: 'arn:aws:iam::<account>:role/<name>'
roleSessionName: tempAssumeRoleSession ## optional
service: '<service>' ## optional
region: '<region>' ## optional
```

### New Auth Services - Unauthorized Requests
Expand Down
8 changes: 8 additions & 0 deletions plugins/proxy-sigv4-backend/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export interface Config {
* Use this session name when performing the STS:AssumeRole call for roleArn. Default: 'tempAssumeRoleSession'.
*/
roleSessionName?: string;
/**
* Name of the AWS service if is not possible to determine it automatically
*/
service?: string;
/**
* Name of the AWS region if is not possible to determine it automatically
*/
region?: string;
};
};
}
15 changes: 14 additions & 1 deletion plugins/proxy-sigv4-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export interface RouteConfig {
target: string;
roleArn?: string;
roleSessionName?: string;
// TODO: support specifying/overriding `service` and `region` for CNAME'd endpoints
service?: string;
region?: string;
// TODO: support specifying additional allowed forward headers
}

Expand All @@ -71,6 +72,14 @@ export function normalizeRouteConfig(config: any): RouteConfig {
throw new TypeError(`Route target must be a string`);
}

if (fullConfig.service && typeof fullConfig.service !== 'string') {
throw new TypeError(`Route service must be a string`);
}

if (fullConfig.region && typeof fullConfig.region !== 'string') {
throw new TypeError(`Route region must be a string`);
}

try {
// eslint-disable-next-line no-new
new URL(fullConfig.target! as string);
Expand Down Expand Up @@ -122,6 +131,8 @@ export async function buildMiddleware(
target,
roleArn,
roleSessionName = 'backstage-plugin-proxy-sigv4-backend',
region,
service,
} = routeConfig;

const credentialsProvider = roleArn
Expand Down Expand Up @@ -187,6 +198,8 @@ export async function buildMiddleware(
host: targetUrl.host,
path: req.url, // path + search
headers: requestHeaders,
service: service,
region: region,
};

// TODO: support other content types with bodies
Expand Down

0 comments on commit d05d196

Please sign in to comment.