Download public key from S3 with AWS credential#47
Conversation
🦋 Changeset detectedLatest commit: cc5ce32 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
f598f89 to
99c0a2b
Compare
99c0a2b to
b0f394f
Compare
SHession
left a comment
There was a problem hiding this comment.
These changes make sense, have they been tested using npm-link on any of the consuming apps?
Looks like a most consumer may be a few version behind so it may be some work to get the up-to-date: https://www.npmjs.com/package/@guardian/pan-domain-node?activeTab=versions
src/panda.ts
Outdated
| s3Client: S3; | ||
|
|
||
| constructor(cookieName: string, region: string, bucket: string, keyFile: string, validateUser: ValidateUserFn) { | ||
| constructor(cookieName: string, region: string, bucket: string, keyFile: string, validateUser: ValidateUserFn, localDev : boolean = false) { |
There was a problem hiding this comment.
Can we update the README with some detail about this change? What local credentials and level of access will people need for this to work?
There was a problem hiding this comment.
Good point, I'll update the README.
At the moment, we grant the GetObject permission on the bucket to any IAM under a (fairly broad) list of AWS accounts (such as composer, cms-fronts, mobile etc). So the execution environment requires credential of any IAM users under these account. I'll add this to the README.
src/panda.ts
Outdated
| this.publicKey = fetchPublicKey(region, bucket, keyFile); | ||
| const standardAwsConfig = { | ||
| region: region, | ||
| credentials: localDev? fromIni({ profile: LOCAL_PROFILE }): fromNodeProviderChain(), |
There was a problem hiding this comment.
Presumably any environment running this in AWS will need to be configured with read access to S3 bucket. In some cases will require cross-account permissions to be set up. This would be worth mentioning in the documentation.
yes, I tested the changes locally with these consuming apps: ten_four-quiz-builder and image URL signing. They were on version 0.4 and so, yes, I need to make changes for bumping their pan-domain-node to 1.0. |
This is great! I was planning to do some testing myself, but looks like you're way ahead of me. |
README.md
Outdated
| The library requires AWS credential to read the public key files from the S3 bucket `pan-domain-auth-settings` in `Workflow` account. Please ensure that the execution environment has AWS credential for an IAM profile that has read access to the bucket. | ||
|
|
||
| Currently, the bucket has been configured to allow access from any IAM users under a (fairly broad) list of AWS accounts (such as composer, cms-fronts, mobile etc). Please get in touch with Workflow and Collaboration team if you need to get the read permission on the `pan-domain-auth-settings` bucket for your AWS acount. |
There was a problem hiding this comment.
It might be worth clarifying your description a bit. Technically we are using a bucket in the Workflow account. However, this package is publicly available and could be utilised by others who are using Panda in a non-guardian environment. Therefore we can't assume that consumers of this library are going to be using the Guardian bucket.
To avoid this assumption, we could remove references to the specific account and bucket and just mention bucket / object access is required. We could also link to the Panda documentation if that would be useful: https://github.com/guardian/pan-domain-authentication.
There was a problem hiding this comment.
A very good point. I've updated the readme to make it more general.
I've also added an argument to PanDomainAuthentication for the AWS profile name, which is used when the application is running locally. Previously I assumed that it was Workflow.
src/panda.ts
Outdated
| s3Client: S3; | ||
|
|
||
| constructor(cookieName: string, region: string, bucket: string, keyFile: string, validateUser: ValidateUserFn, localDev : boolean = false) { | ||
| constructor(cookieName: string, region: string, bucket: string, keyFile: string, validateUser: ValidateUserFn, localDev : boolean = false, localProfile?: string) { |
There was a problem hiding this comment.
I hadn't thought about this but it makes sense to change this too!
I was wondering if we should have a single argument to control both. For example localDev being an optional string, which when provided overrides the nodeProviderChain. I'm not quite sure on this, but two arguments which are co-dependent also feels a little clunky.
Maybe the argument should be an optional credentials type for greater flexibility?
There was a problem hiding this comment.
A good idea! I've made the change in the last commit.
There was a problem hiding this comment.
Looks great! Can we update the README to reflect this too
There was a problem hiding this comment.
Sure, I've updated the README.
d48e64b to
325284a
Compare
…DomainAuthentication
325284a to
cc5ce32
Compare
Context
We are looking to address the FSBP high severity security issue about the S3 bucket "pan-domain-auth-settings" not blocking public access.
From S3 access log, we spotted that there were successful, unauthenticated requests to read some objects in this bucket from our applications.
We found that the public settings files there (which were S3 objects with a suffix "settings.public" were configured to allow public access and this client library,
pan-domain-node, read these objects via direct HTTP requests without any AWS credential.Therefore, we have to change the way we access these public setting file before we can turn on "Block all public access" option on the bucket.
What does this change?
This pull request changes the library to read the public key file via AWS SDK S3 client instead of making direct HTTP requests. To achieve this, it makes the following changes:
localDevargument.How to test
I modified the app
image-url-signing-serviceto pull in the local version of this library and started the app locally.