Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reporter/s3): support minio #1930

Merged
merged 2 commits into from
May 28, 2024
Merged

feat(reporter/s3): support minio #1930

merged 2 commits into from
May 28, 2024

Conversation

MaineK00n
Copy link
Collaborator

@MaineK00n MaineK00n commented May 22, 2024

What did you implement:

Fixes #1605

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

setup

$ docker run --rm --name minio -p 9000:9000 -p 9001:9001 quay.io/minio/minio server /data --console-address ":9001"
$ docker exec -it minio bash
bash-5.1# mc config host add local http://localhost:9000 minioadmin minioadmin
bash-5.1# mc mb local/vuls

public access

bucket policy

$ docker exec -it minio bash
bash-5.1# mc anonymous set public local/vuls
bash-5.1# mc anonymous get-json local/vuls
{
 "Statement": [
  {
   "Action": [
    "s3:GetBucketLocation",
    "s3:ListBucket",
    "s3:ListBucketMultipartUploads"
   ],
   "Effect": "Allow",
   "Principal": {
    "AWS": [
     "*"
    ]
   },
   "Resource": [
    "arn:aws:s3:::vuls"
   ]
  },
  {
   "Action": [
    "s3:AbortMultipartUpload",
    "s3:DeleteObject",
    "s3:GetObject",
    "s3:ListMultipartUploadParts",
    "s3:PutObject"
   ],
   "Effect": "Allow",
   "Principal": {
    "AWS": [
     "*"
    ]
   },
   "Resource": [
    "arn:aws:s3:::vuls/*"
   ]
  }
 ],
 "Version": "2012-10-17"
}

run

$ cat config.toml
[aws]
s3Endpoint = "http://localhost:9000"
region = "us-east-1"
credentialProvider = "anonymous"
s3Bucket = "vuls"
s3UsePathStyle = true

$ vuls report --to-s3

$ docker exec -it minio bash
bash-5.1# mc ls local/vuls/2024-05-21T17:49:09+09:00/
[2024-05-22 12:17:52 UTC]   605B STANDARD pseudo_short.txt

credential: envvar

bucket policy

$ docker exec -it minio bash
bash-5.1# mc anonymous set private local/vuls
bash-5.1# mc anonymous get-json local/vuls
{}

run

$ cat config.toml
[aws]
s3Endpoint = "http://localhost:9000"
region = "us-east-1"
s3Bucket = "vuls"
s3UsePathStyle = true

$ AWS_ACCESS_KEY_ID=minioadmin AWS_SECRET_ACCESS_KEY=minioadmin vuls report -to-s3

$ docker exec -it minio bash
bash-5.1# mc ls local/vuls/2024-05-21T17:49:09+09:00/
[2024-05-22 12:26:49 UTC]   605B STANDARD pseudo_short.txt

credential: file

bucket policy

$ docker exec -it minio bash
bash-5.1# mc anonymous set private local/vuls
bash-5.1# mc anonymous get-json local/vuls
{}

run

$ cat config.toml
[aws]
s3Endpoint = "http://localhost:9000"
region = "us-east-1"
s3Bucket = "vuls"
s3UsePathStyle = true

$ cat ~/.aws/credentials
[default]
aws_access_key_id=minioadmin
aws_secret_access_key=minioadmin

$ vuls report -to-s3

$ docker exec -it minio bash
bash-5.1# mc ls local/vuls/2024-05-21T17:49:09+09:00/
[2024-05-22 13:08:05 UTC]   605B STANDARD pseudo_short.txt
$ cat config.toml
[aws]
s3Endpoint = "http://localhost:9000"
region = "us-east-1"
credentialFiles = ["minio-credentials"]
s3Bucket = "vuls"
s3UsePathStyle = true

$ cat minio-credentials
[default]
aws_access_key_id=minioadmin
aws_secret_access_key=minioadmin


$ vuls report -to-s3

$ docker exec -it minio bash
bash-5.1# mc ls local/vuls/2024-05-21T17:49:09+09:00/
[2024-05-22 12:32:28 UTC]   605B STANDARD pseudo_short.txt

credential: static

bucket policy

$ docker exec -it minio bash
bash-5.1# mc anonymous set private local/vuls
bash-5.1# mc anonymous get-json local/vuls
{}

run

$ cat config.toml
[aws]
s3Endpoint = "http://localhost:9000"
region = "us-east-1"
credentialProvider = "static"
accessKeyID = "minioadmin"
secretAccessKey = "minioadmin"
s3Bucket = "vuls"
s3UsePathStyle = true

$ vuls report -to-s3

$ docker exec -it minio bash
bash-5.1# mc ls local/vuls/2024-05-21T17:49:09+09:00/
[2024-05-22 12:37:03 UTC]   605B STANDARD pseudo_short.txt

credential: endpoint

bucket policy

$ docker exec -it minio bash
bash-5.1# mc anonymous set private local/vuls
bash-5.1# mc anonymous get-json local/vuls
{}

run

$ python -m http.server 8000
$ curl http://localhost:8000/minio-credential.json
{
    "AccessKeyId" : "minioadmin",
    "SecretAccessKey" : "minioadmin"   
}

$ cat config.toml
[aws]
s3Endpoint = "http://localhost:9000"
region = "us-east-1"
credentialProvider = "endpoint"
credentialEndpoint = "http://localhost:8000/minio-credential.json"
s3Bucket = "vuls"
s3UsePathStyle = true

$ vuls report -to-s3

$ docker exec -it minio bash
bash-5.1# mc ls local/vuls/2024-05-21T17:49:09+09:00/
[2024-05-22 12:45:29 UTC]   605B STANDARD pseudo_short.txt

allow s3:PutObject only

bucket policy

$ docker exec -it minio bash
bash-5.1# mc anonymous set-json /policy.json local/vuls
bash-5.1# mc anonymous get-json local/vuls
{
 "Statement": [
  {
   "Action": [
    "s3:PutObject"
   ],
   "Effect": "Allow",
   "Principal": {
    "AWS": [
     "*"
    ]
   },
   "Resource": [
    "arn:aws:s3:::vuls/*"
   ]
  }
 ],
 "Version": "2012-10-17"
}

run

$ cat config.toml
[aws]
s3Endpoint = "http://localhost:9000"
region = "us-east-1"
credentialProvider = "anonymous"
s3Bucket = "vuls"
s3UsePathStyle = true

$ vuls report --to-s3
...
[May 22 22:00:00]  WARN [localhost] bucket: vuls cannot check the existence because s3:ListBucket or s3:ListAllMyBuckets is not allowed
...

$ docker exec -it minio bash
bash-5.1# mc ls local/vuls/2024-05-21T17:49:09+09:00/
[2024-05-22 13:00:00 UTC]   605B STANDARD pseudo_short.txt

Checklist:

You don't have to satisfy all of the following.

  • Write tests
  • Write documentation
  • Check that there aren't other open pull requests for the same issue/feature
  • Format your source code by make fmt
  • Pass the test by make test
  • Provide verification config / commands
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES

Reference

@MaineK00n MaineK00n linked an issue May 22, 2024 that may be closed by this pull request
@MaineK00n MaineK00n force-pushed the MaineK00n/aws-sdk-go-v2 branch from fa4c559 to 8f49be1 Compare May 22, 2024 20:16
@MaineK00n MaineK00n force-pushed the MaineK00n/aws-sdk-go-v2 branch from 8f49be1 to b9fa428 Compare May 24, 2024 08:14
Base automatically changed from MaineK00n/aws-sdk-go-v2 to master May 24, 2024 10:08
@MaineK00n MaineK00n self-assigned this May 24, 2024
@MaineK00n MaineK00n requested a review from shino May 24, 2024 10:10
@MaineK00n MaineK00n marked this pull request as ready for review May 24, 2024 10:10
Copy link
Collaborator

@shino shino left a comment

Choose a reason for hiding this comment

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

Happy anonymous access!

@shino shino merged commit db2c502 into master May 28, 2024
7 checks passed
@shino shino deleted the MaineK00n/minio branch May 28, 2024 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support to upload report to custom S3 (minio)
2 participants