Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
29b0da1
initial commit
Dec 17, 2021
b65b0aa
fixed build logic
Dec 17, 2021
9959fc4
adding actions
Dec 17, 2021
d0d24a6
action fixes
Dec 17, 2021
3f0e2cb
more logging
Dec 17, 2021
a87c09d
switch region for self test
Dec 17, 2021
69f460f
adding deployment action
Dec 23, 2021
b248dfb
release stuff
Dec 23, 2021
afda619
trying
Dec 23, 2021
95261b6
clean up dependencies
Dec 23, 2021
e414cef
build magic
Dec 23, 2021
a18e516
work work
Dec 23, 2021
d943a34
work work
Dec 23, 2021
6c54b31
work work
Dec 23, 2021
dc82d8e
working now
Dec 23, 2021
bc29f51
working now
Dec 23, 2021
7242223
working now
Dec 23, 2021
fbe710c
looks complete
Dec 23, 2021
87e37af
working on the readme
Dec 23, 2021
e9c4d39
improved readme, clean up dependencies, build with java matrix
Dec 30, 2021
26d33e7
improvements based on xxz's comments
Dec 30, 2021
94735b7
do not fail if git remote is unknown
Jan 5, 2022
9732a40
addressing review comments
Jan 6, 2022
7416eef
addressing next round of comments
Jan 7, 2022
5e1305a
updating gitignore
Jan 7, 2022
9c43535
fix debug message
Jan 10, 2022
030823e
bug fixes and making the git folder not required for package scans
Jan 11, 2022
c71b9f4
changing long param name from repository to root-dir
Jan 11, 2022
4966c48
typo
Jan 11, 2022
c974590
bugfix
Jan 11, 2022
9b31d0a
remove unnecessary field
Jan 11, 2022
6976f2d
typo
Jan 12, 2022
de2f054
upgrading to aws sdk v2 and some bug fixes from the builder toolbox v…
Jan 19, 2022
92500e1
Better error handling if association fails. Support for KMS keys
Jan 20, 2022
2d6d824
Addressing xxz's comments
Jan 21, 2022
12ca35b
Merge branch 'main' of https://github.com/martinschaef/aws-codeguru-c…
Feb 2, 2022
4c414c4
Updating readme and removing the hard requirement on the bucket name …
Feb 3, 2022
bc7ed68
Update README.md
martinschaef Feb 3, 2022
7751653
Update Main.java
martinschaef Feb 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/guru-reviewer.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Created using https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample
name: Analyze with CodeGuru Reviewer

on: [push]
on: [push, pull_request, workflow_dispatch]

permissions:
id-token: write
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/self-test-and-release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Created using https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample
name: Self-test and release

on:
push:
branches:
- main
on: [push, pull_request, workflow_dispatch]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last time I had both of push and pull_request enabled (unrestricted, like here, for both events in all branches), I quickly realized that doing so triggered a LOT of analyses. Every push to a feature branch with an open PR also counts as a pull_request event, so you end up running 2x Guru for each push to any PR.

Have you considered unrestricted pull_request, but push only for main?


permissions:
id-token: write
Expand Down
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,53 @@ located under `./src`. The option `--output ./output` specifies where CodeGuru s
CodeGuru produces a Json and Html report.

You can provide your own bucket name using the `--bucket-name` option. Note that, currently, CodeGuru Reviewer only
accepts bucket names that start with the prefix `codeguru-reviewer-`.
supports bucket names that start with the prefix `codeguru-reviewer-` out of the box. If you choose a different naming
pattern for your bucket you need to:
1. Grant `S3:GetObject` permissions on their S3 bucket to `codeguru-reviewer.amazonaws.com`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/their/the/ ?

2. If you are using SSE on the S3 bucket, Grant `KMS::Decrypt` permissions to `codeguru-reviewer.amazonaws.com`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/Grant/grant/


### Using Encryption

CodeGuru Reviewer allows you to use a customer managed key (CMCMK) to encrypt content of the S3 bucket that is used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/to encrypt content of the/to encrypt the content of the/

to store source and build artifacts, and all metadata and recommendations that are produced by CodeGuru Reviewer.
First, create a customer owned key in KMS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to grant CodeGuru Reviewer permission to decrypt artifacts with this key by adding the
following Statement to your Key policy:

```json
{
"Sid": "Allow CodeGuru to use the key to decrypt artifact",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: replace "artifact" with "artifacts" (or with "the artifact" if just one)

"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"kms:Decrypt",
"kms:DescribeKey"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:ViaService": "codeguru-reviewer.amazonaws.com",
"kms:CallerAccount": [Your AWS ACCOUNT ID]
}
}
}
```
Then, enable server-side for the bucket that you are using with CodeGuru Reviewer. The bucket name should be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/enable server-side/enable server-side encryption/

`codeguru-reviewer-cli-[YOUR ACCOUNT]-[YOUR REGION]`, unless you provided a custom name. For encryption, use the
KMS key that you created in the previous step.

Now you can analyze a repository by providing the KMS key ID (not the alias). For example:
```
codeguru-reviewer -r ./ -kms 12345678-abcd-abcd-1234-1234567890ab
```
The first time you analyze a repository with the CodeGuru Reviewer CLI, a new association will be created and
the provided key will be associated with this repository. Fur subsequent scans, you do not need to provide the
key again. Note that you can start using a key after the repository is already associated. If you want to switch
from not using a key to using a key, you need to delete the existing association first in the AWS Console and
then trigger a new scan with the CLI where you provide the key.


### Running from CI/CD

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/amazonaws/gurureviewercli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ protected GitMetaData readGitMetaData(final Configuration config, final Path rep

private void validateInitialConfig(final Configuration config) {
if (config.getBucketName() != null && !config.getBucketName().startsWith("codeguru-reviewer-")) {
throw new GuruCliException(ErrorCodes.BAD_BUCKET_NAME,
config.getBucketName() + " is not a valid bucket name for CodeGuru.");
Log.warn("CodeGuru Reviewer has default settings only for buckets that are prefixed with "
+ "codeguru-reviewer. If you choose a different name, read the instructions in the README.");
}
if (!Paths.get(repoDir).toFile().isDirectory()) {
throw new GuruCliException(ErrorCodes.DIR_NOT_FOUND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public static RepositoryAssociation getAssociatedGuruRepo(final Configuration co
private static RepositoryAssociation createBucketAndAssociation(final Configuration config) {
final String bucketName;
if (config.getBucketName() != null) {
if (!config.getBucketName().startsWith("codeguru-reviewer-")) {
throw new GuruCliException(ErrorCodes.BAD_BUCKET_NAME,
config.getBucketName() + " is not a valid bucket name for CodeGuru.");
}
bucketName = config.getBucketName();
} else {
bucketName = String.format(BUCKET_NAME_PATTERN, config.getAccountId(), config.getRegion());
Expand Down