Skip to content

Commit 4c414c4

Browse files
author
Martin Schaef
committed
Updating readme and removing the hard requirement on the bucket name prefix
1 parent 12ca35b commit 4c414c4

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

.github/workflows/guru-reviewer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Created using https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample
22
name: Analyze with CodeGuru Reviewer
33

4-
on: [push]
4+
on: [push, pull_request, workflow_dispatch]
55

66
permissions:
77
id-token: write

.github/workflows/self-test-and-release.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# Created using https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample
22
name: Self-test and release
33

4-
on:
5-
push:
6-
branches:
7-
- main
4+
on: [push, pull_request, workflow_dispatch]
85

96
permissions:
107
id-token: write

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,53 @@ located under `./src`. The option `--output ./output` specifies where CodeGuru s
7272
CodeGuru produces a Json and Html report.
7373

7474
You can provide your own bucket name using the `--bucket-name` option. Note that, currently, CodeGuru Reviewer only
75-
accepts bucket names that start with the prefix `codeguru-reviewer-`.
75+
supports bucket names that start with the prefix `codeguru-reviewer-` out of the box. If you choose a different naming
76+
pattern for your bucket you need to:
77+
1. Grant `S3:GetObject` permissions on their S3 bucket to `codeguru-reviewer.amazonaws.com`
78+
2. If you are using SSE on the S3 bucket, Grant `KMS::Decrypt` permissions to `codeguru-reviewer.amazonaws.com`
79+
80+
### Using Encryption
81+
82+
CodeGuru Reviewer allows you to use a customer managed key (CMCMK) to encrypt content of the S3 bucket that is used
83+
store source and build artifacts, and all metadata and recommendations that are produced by CodeGuru Reviewer.
84+
First, create a customer owned key in KMS.
85+
You need to grant CodeGuru Reviewer permission to decrypt artifacts with this key by adding the
86+
following Statement to your Key policy:
87+
88+
```json
89+
{
90+
"Sid": "Allow CodeGuru to use the key to decrypt artifact",
91+
"Effect": "Allow",
92+
"Principal": {
93+
"AWS": "*"
94+
},
95+
"Action": [
96+
"kms:Decrypt",
97+
"kms:DescribeKey"
98+
],
99+
"Resource": "*",
100+
"Condition": {
101+
"StringEquals": {
102+
"kms:ViaService": "codeguru-reviewer.amazonaws.com",
103+
"kms:CallerAccount": [Your AWS ACCOUNT ID]
104+
}
105+
}
106+
}
107+
```
108+
Then, enable server-side for the bucket that you are using with CodeGuru Reviewer. The bucket name should be
109+
`codeguru-reviewer-cli-[YOUR ACCOUNT]-[YOUR REGION]`, unless you provided a custom name. For encryption, use the
110+
KMS key that you created in the previous step.
111+
112+
Now you can analyze a repository by providing the KMS key ID (not the alias). For example:
113+
```
114+
codeguru-reviewer -r ./ -kms 12345678-abcd-abcd-1234-1234567890ab
115+
```
116+
The first time you analyze a repository with the CodeGuru Reviewer CLI, a new association will be created and
117+
the provided key will be associated with this repository. Fur subsequent scans, you do not need to provide the
118+
key again. Note that you can start using a key after the repository is already associated. If you want to switch
119+
from not using a key to using a key, you need to delete the existing association first in the AWS Console and
120+
then trigger a new scan with the CLI where you provide the key.
121+
76122

77123
### Running from CI/CD
78124

src/main/java/com/amazonaws/gurureviewercli/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ protected GitMetaData readGitMetaData(final Configuration config, final Path rep
169169

170170
private void validateInitialConfig(final Configuration config) {
171171
if (config.getBucketName() != null && !config.getBucketName().startsWith("codeguru-reviewer-")) {
172-
throw new GuruCliException(ErrorCodes.BAD_BUCKET_NAME,
173-
config.getBucketName() + " is not a valid bucket name for CodeGuru.");
172+
Log.warn("CodeGuru Reviewer has default settings only for buckets that are prefixed with "
173+
+ "codeguru-reviewer. If you choose a different, read the instructions in the README.");
174174
}
175175
if (!Paths.get(repoDir).toFile().isDirectory()) {
176176
throw new GuruCliException(ErrorCodes.DIR_NOT_FOUND,

src/main/java/com/amazonaws/gurureviewercli/adapter/AssociationAdapter.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ public static RepositoryAssociation getAssociatedGuruRepo(final Configuration co
7878
private static RepositoryAssociation createBucketAndAssociation(final Configuration config) {
7979
final String bucketName;
8080
if (config.getBucketName() != null) {
81-
if (!config.getBucketName().startsWith("codeguru-reviewer-")) {
82-
throw new GuruCliException(ErrorCodes.BAD_BUCKET_NAME,
83-
config.getBucketName() + " is not a valid bucket name for CodeGuru.");
84-
}
8581
bucketName = config.getBucketName();
8682
} else {
8783
bucketName = String.format(BUCKET_NAME_PATTERN, config.getAccountId(), config.getRegion());

0 commit comments

Comments
 (0)