-
Notifications
You must be signed in to change notification settings - Fork 26
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
Increasing security posture of HTC Grid by enforcing and fixing relevant encryption, authentication and RBAC issues #78
Conversation
…compProfile and disabled allowPrivilegeEscalation
…-root Dockerfiles, fixed HTCGRID_ECR_REPO, named CloudFormation stack outputs and support for updating existing init_grid stack
… CMK KMS Keys for the DLQs per each SQS Queue
…naming/references
…agent, fix AWS partition and DNS Suffix usage
d050e97
to
93a029d
Compare
policy_arn = "arn:${local.partition}:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" | ||
} | ||
|
||
resource "aws_api_gateway_account" "apigateway_account" { |
Check warning
Code scanning / tflint
Missing version constraint for provider "aws" in required_providers Warning
|
||
for i, r in enumerate(results): | ||
# print(i, (abs(all_expected_results[i] - results[i])), all_expected_results[i], results[i]) | ||
assert (abs(all_expected_results[i] - results[i]) < 0.000001) | ||
assert abs(all_expected_results[i] - results[i]) < 0.000001 |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note
stdout=f_stdout, | ||
stderr=f_stderr, | ||
shell=False) | ||
proc = subprocess.Popen(command, stdout=f_stdout, stderr=f_stderr, shell=False) |
Check notice
Code scanning / Bandit
subprocess call - check for execution of untrusted input. Note
logging.info("Could not acquire a task from the queue, backing off for {}". | ||
format(timeout) | ||
) | ||
timeout = random.uniform( |
Check notice
Code scanning / Bandit
Standard pseudo-random generators are not suitable for security/cryptographic purposes. Note
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
KUBE_FILEPATH = '/tmp/kubeconfig' | ||
region = os.environ['AWS_REGION'] | ||
KUBE_FILEPATH = "/tmp/kubeconfig" |
Check warning
Code scanning / Bandit
Probable insecure usage of temp file/directory. Warning
|
||
else: | ||
errlog.log("Unimplemented path, exiting") | ||
assert(False) | ||
assert False |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note
|
||
|
||
def get_time_now_ms(): | ||
return int(round(time.time() * 1000)) | ||
|
||
|
||
def get_tasks_statuses_in_session(session_id): | ||
|
||
assert(session_id is not None) | ||
assert session_id is not None |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note
|
||
else: | ||
errlog.log("Uniplemented path, exiting") | ||
assert(False) | ||
assert False |
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note
395e14d
to
4689e66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Flamur,
Thank you for your work.
I been running the happy path section (from my laptop) and I got error from multiple sections:
REGION not set
after differentmake
commandMallformed policy
during the deployment- bucket not fully emptied during the cleaning process
Can you please take a look at this ?
lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
ImageTFStateBucket: | ||
Type: 'AWS::S3::Bucket' | ||
DeletionPolicy: Delete | ||
Properties: | ||
BucketName: !Sub | ||
- '${BucketTag}-tfstate-htc-grid-${RANDOM}' | ||
- '${BucketTag}-htc-grid-image-tfstate-${RANDOM}' | ||
- RANDOM: !Select [0, !Split ['-', !Select [2, !Split ['/', !Ref 'AWS::StackId' ]]]] | ||
DeletionPolicy: Delete | ||
LambdaUnitHtcGrid: | ||
PublicAccessBlockConfiguration: | ||
BlockPublicAcls: true | ||
BlockPublicPolicy: true | ||
IgnorePublicAcls: true | ||
RestrictPublicBuckets: true | ||
VersioningConfiguration: | ||
Status: Enabled | ||
BucketEncryption: | ||
ServerSideEncryptionConfiguration: | ||
- BucketKeyEnabled: true | ||
ServerSideEncryptionByDefault: | ||
SSEAlgorithm: 'aws:kms' | ||
KMSMasterKeyID: !Sub 'arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:${HTCStateS3KeyAlias}' |
Check notice
Code scanning / Trivy
S3 Bucket Logging Low
Type: cloudformation
Vulnerability AVD-AWS-0089
Severity: LOW
Message: Bucket has logging disabled
Link: AVD-AWS-0089
LambdaLayerBucket: | ||
Type: 'AWS::S3::Bucket' | ||
DeletionPolicy: Delete | ||
Properties: | ||
BucketName: !Sub | ||
- '${BucketTag}-lambda-unit-htc-grid-${RANDOM}' | ||
- '${BucketTag}-htc-grid-lambda-layer-${RANDOM}' | ||
- RANDOM: !Select [0, !Split ['-', !Select [2, !Split ['/', !Ref 'AWS::StackId' ]]]] | ||
DeletionPolicy: Delete | ||
PublicAccessBlockConfiguration: | ||
BlockPublicAcls: true | ||
BlockPublicPolicy: true | ||
IgnorePublicAcls: true | ||
RestrictPublicBuckets: true | ||
VersioningConfiguration: | ||
Status: Enabled | ||
BucketEncryption: | ||
ServerSideEncryptionConfiguration: | ||
- BucketKeyEnabled: true | ||
ServerSideEncryptionByDefault: | ||
SSEAlgorithm: 'aws:kms' | ||
KMSMasterKeyID: !Sub 'arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:${HTCStateS3KeyAlias}' |
Check notice
Code scanning / Trivy
S3 Bucket Logging Low
Type: cloudformation
Vulnerability AVD-AWS-0089
Severity: LOW
Message: Bucket has logging disabled
Link: AVD-AWS-0089
GridTFStateBucket: | ||
Type: 'AWS::S3::Bucket' | ||
DeletionPolicy: Delete | ||
Properties: | ||
BucketName: !Sub | ||
- '${BucketTag}-image-tfstate-htc-grid-${RANDOM}' | ||
- '${BucketTag}-htc-grid-tfstate-${RANDOM}' | ||
- RANDOM: !Select [0, !Split ['-', !Select [2, !Split ['/', !Ref 'AWS::StackId' ]]]] | ||
DeletionPolicy: Delete | ||
TfstateHtcGrid: | ||
PublicAccessBlockConfiguration: | ||
BlockPublicAcls: true | ||
BlockPublicPolicy: true | ||
IgnorePublicAcls: true | ||
RestrictPublicBuckets: true | ||
VersioningConfiguration: | ||
Status: Enabled | ||
BucketEncryption: | ||
ServerSideEncryptionConfiguration: | ||
- BucketKeyEnabled: true | ||
ServerSideEncryptionByDefault: | ||
SSEAlgorithm: 'aws:kms' | ||
KMSMasterKeyID: !Sub 'arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:${HTCStateS3KeyAlias}' |
Check notice
Code scanning / Trivy
S3 Bucket Logging Low
Type: cloudformation
Vulnerability AVD-AWS-0089
Severity: LOW
Message: Bucket has logging disabled
Link: AVD-AWS-0089
@@ -1,20 +1,22 @@ | |||
FROM python:3.7.7-slim-buster | |||
ARG HTCGRID_ECR_REPO |
Check notice
Code scanning / Trivy
No HEALTHCHECK defined Low
Type: dockerfile
Vulnerability DS026
Severity: LOW
Message: Add HEALTHCHECK instruction in your Dockerfile
Link: DS026
RUN yum install -d1 -y make gcc-c++ zip | ||
RUN mkdir -p /app | ||
WORKDIR /app | ||
ARG HTCGRID_ECR_REPO |
Check notice
Code scanning / Trivy
No HEALTHCHECK defined Low
Type: dockerfile
Vulnerability DS026
Severity: LOW
Message: Add HEALTHCHECK instruction in your Dockerfile
Link: DS026
@@ -1,21 +1,26 @@ | |||
FROM python:3.7.7-slim-buster | |||
ARG HTCGRID_ECR_REPO |
Check notice
Code scanning / Trivy
No HEALTHCHECK defined Low
Type: dockerfile
Vulnerability DS026
Severity: LOW
Message: Add HEALTHCHECK instruction in your Dockerfile
Link: DS026
@@ -1,41 +1,54 @@ | |||
FROM python:3.7.7-slim-buster | |||
#Builder Container |
Check notice
Code scanning / Trivy
No HEALTHCHECK defined Low
Type: dockerfile
Vulnerability DS026
Severity: LOW
Message: Add HEALTHCHECK instruction in your Dockerfile
Link: DS026
ENV LAYER_NAME lambda | ||
ENV LAYER_VERSION 1 | ||
ENV LAYER_ROOT . | ||
ARG HTCGRID_ECR_REPO |
Check notice
Code scanning / Trivy
No HEALTHCHECK defined Low
Type: dockerfile
Vulnerability DS026
Severity: LOW
Message: Add HEALTHCHECK instruction in your Dockerfile
Link: DS026
resource "aws_api_gateway_method_settings" "htc_public_api_method_settings" { | ||
#checkov:skip=CKV_AWS_308: API Gateway method setting caching encryption wouldn't work for this API | ||
#checkov:skip=CKV_AWS_225: API Gateway method setting caching wouldn't work for this API | ||
|
||
rest_api_id = aws_api_gateway_rest_api.htc_public_api.id | ||
stage_name = aws_api_gateway_stage.htc_public_api_stage.stage_name | ||
|
||
method_path = "*/*" | ||
|
||
settings { | ||
metrics_enabled = true | ||
logging_level = "ERROR" | ||
} | ||
} |
Check notice
Code scanning / Trivy
Ensure that response caching is enabled for your Amazon API Gateway REST APIs. Low
Type: terraform
Vulnerability AVD-AWS-0190
Severity: LOW
Message: Cache data is not enabled.
Link: AVD-AWS-0190
resource "aws_api_gateway_method_settings" "htc_private_api_method_settings" { | ||
#checkov:skip=CKV_AWS_308: API Gateway method setting caching encryption wouldn't work for this API | ||
#checkov:skip=CKV_AWS_225: API Gateway method setting caching wouldn't work for this API | ||
|
||
rest_api_id = aws_api_gateway_rest_api.htc_private_api.id | ||
stage_name = aws_api_gateway_stage.htc_private_api_stage.stage_name | ||
|
||
method_path = "*/*" | ||
|
||
settings { | ||
metrics_enabled = true | ||
logging_level = "ERROR" | ||
} | ||
} |
Check notice
Code scanning / Trivy
Ensure that response caching is enabled for your Amazon API Gateway REST APIs. Low
Type: terraform
Vulnerability AVD-AWS-0190
Severity: LOW
Message: Cache data is not enabled.
Link: AVD-AWS-0190
Description
This pull request fixes all the relevant security issues in the current code base, as detected by cfn_lint, trivy, checkov and ScoutSuite.
Terraform State:
init_grid
state and Lambda buckets.AccessControls
and useBucketPolicy
to keep the bucket private.init_grid
stack.init_grid
Makefile to handle initial and deletion cases better.HTC Grid Containers:
runAsNonRoot
, defaultseccompProfile
, and disabledallowPrivilegeEscalation
.readOnlyFileSystem
and seccomp profile to HTC Agent, fix and cleanup code.HTC Grid Control Plane:
control_plane
.Decrypt
andGenerateDataKey
permissions to Lambda and Agent permissions.jq
onto lambda images and fix the bootstrap script.AWSServiceRoleForAutoScaling
already exists.securityContext
for OpenAPI.General:
cfn_lint
,trivy
, andcheckov
.random_password
to align with pipelines.Cloud9:
Checklist
README.md
, or thedocs
directory)area/controlplane
) and kind (e.g.kind/improvement
)BONUS POINTS checklist: