Skip to content

Commit 22ae41f

Browse files
committed
Add EKS and AKS values, clarify secret managers instructions and best practices
1 parent 230395e commit 22ae41f

File tree

11 files changed

+263
-231
lines changed

11 files changed

+263
-231
lines changed

CONTRIBUTING.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Contributing to PRevent
2+
3+
Thank you for your interest in contributing!
4+
Please follow these simple steps to ensure a smooth contribution process.
5+
6+
---
7+
8+
## Workflow
9+
1. **Fork and Clone**:
10+
```bash
11+
git clone https://github.com/apiiro/PRevent.git
12+
cd PRevent
13+
```
14+
2. **Create a Branch**:
15+
```bash
16+
git checkout -b feature/branch-name
17+
```
18+
3. **Make Changes**:
19+
- Thoroughly test live with GitHub.
20+
- If your changes affect the scan, test on at least 3 large repositories and languages.
21+
- If your changes affect the scan, ensure an extremely low false-positive rate is kept.
22+
4. **Commit**:
23+
Commits must be signed.
24+
Write a clear, descriptive commit message:
25+
```bash
26+
git commit -S -m "Added config parameters validation on container initialization"
27+
```
28+
5. **Push and Submit PR**:
29+
```bash
30+
git push origin rule/your-branch-name
31+
```
32+
- Provide a concise description in the pull request.
33+
34+
---
35+
36+
## Reporting Issues
37+
- Make sure the issue isn't referenced in known-limitations.
38+
- Make sure the issue doesn't exist already.
39+
- Clearly describe the issue.
40+
- Include a reproducible example if applicable.
41+
- Submit via [GitHub Issues](https://github.com/apiiro/PRevent/issues).
42+
43+
---
44+
45+
## Licensing
46+
By contributing, you agree to license your work under the [MIT License](LICENSE).
47+
48+
Thank you for helping improve Malicious-Code-Ruleset!

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Deployment:
4747
- Supports containerization.
4848
- Non-containerized deployment is fully automated with an interactive setup script.
4949
- To manage GitHub key (required for any GitHub app), multiple secret managers are supported:
50-
- HashiCorp Vault
5150
- AWS Secrets Manager
5251
- Azure Key Vault
5352
- Google Cloud Secret Manager
53+
- HashiCorp Vault
5454
- Local HashiCorp Vault (for development and testing)
5555

5656
![merge blocking](https://github.com/user-attachments/assets/4abf58ce-90e9-4624-841b-b5d60bb8dcbb)
@@ -133,7 +133,7 @@ The application handles all parameters exclusively through the secret manager (s
133133

134134
#### Secret Manager Setup Instructions
135135

136-
First, set **SECRET_MANAGER** in your secret manager to either: vault, aws, azure, gcloud, or local.
136+
First, set **SECRET_MANAGER** in your secret manager to either: aws, azure, gcloud, vault, or local.
137137

138138
Dedicate a section in your secret manager for this app, separated from the rest. Create an app role with minimal permissions, to access the dedicated section only. If you are not sure how, try the following instructions:
139139
```bash
@@ -142,11 +142,11 @@ python3 setup/secret_managers/print_instructions.py SECRET_MANAGER
142142

143143
Permissions required to operate the role:
144144

145-
| Permission | Vault | AWS | Azure | GCloud |
146-
|------------|------------------------|-------------------------------|---------------------------|---------------------------|
147-
| read | read | secretsmanager:GetSecretValue | KeyVaultSecret:Get | secretmanager.secrets.get |
148-
| write | create, update | secretsmanager:PutSecretValue | KeyVaultSecret:Set | secretmanager.secrets.add |
149-
| scope | path = "prevent-app/*" | resource = "prevent-app/*" | secret = "prevent-app/*" | secret = "prevent-app/*" |
145+
| Permission | AWS | Azure | GCloud | Vault |
146+
|------------|-------------------------------|---------------------------|---------------------------|------------------------|
147+
| read | secretsmanager:GetSecretValue | KeyVaultSecret:Get | secretmanager.secrets.get | read |
148+
| write | secretsmanager:PutSecretValue | KeyVaultSecret:Set | secretmanager.secrets.add | create, update |
149+
| scope | resource = "prevent-app/*" | secret = "prevent-app/*" | secret = "prevent-app/*" | path = "prevent-app/*" |
150150

151151

152152
### 2. GitHub App

helm/README.md

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,6 @@ kubectl create secret generic k8s-credentials \
2929
--namespace=<namespace>
3030
```
3131

32-
### Vault
33-
34-
Credentials required to operate Vault with your dedicated AppRole to restrict access:
35-
- ROLE_ID
36-
- SECRET_ID
37-
38-
```shell
39-
kubectl create secret generic vault-approle-credentials \
40-
--from-literal=role-id=<role-id-value> \
41-
--from-literal=secret-id=<secret-id-value> \
42-
--namespace=<namespace>
43-
```
44-
45-
Credentials required to operate Vault without a dedicated AppRole:
46-
- VAULT_ADDR
47-
- VAULT_TOKEN
48-
49-
```shell
50-
kubectl create secret generic vault-approle-credentials \
51-
--from-literal=vault-addr=<vault-addr-value> \
52-
--from-literal=vault-token=<vault-token-value> \
53-
--namespace=<namespace>
54-
```
55-
5632
### AWS
5733

5834
Credentials required to operate your AWS Secret Manager:
@@ -109,6 +85,21 @@ kubectl create secret generic gcloud-credentials \
10985
To use with a dedicated GCP role to restrict access:
11086
Associate the GCP IAM role with the K8S service account (e.g., using Workload Identity for GKE).
11187

88+
### Vault
89+
90+
Credentials required to operate Vault, preferably generated with a dedicated AppRole:
91+
- VAULT_ADDR
92+
- VAULT_TOKEN
93+
94+
```shell
95+
kubectl create secret generic vault-approle-credentials \
96+
--from-literal=vault-addr=<vault-addr-value> \
97+
--from-literal=vault-token=<vault-token-value> \
98+
--namespace=<namespace>
99+
```
100+
101+
The best practice is to use Vault Agent with Auto-Auth or Kubernetes Auth to dynamically authenticate and securely retrieve tokens, avoiding static token storage. This is currently unsupported – contributions are welcome.
102+
112103
## Step 2 - Helm deploy
113104

114105
1. Edit [values.yaml](values.yaml).

helm/templates/_helpers.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
{{- end }}
2020

2121
{{- define "env-secrets" }}
22-
{{- if eq .secreteManagerType "vault" }}
23-
{{- include "secret-keyref-required" (dict "name" "vault-credentials" "key" "vault-addr" "env" "VAULT_ADDR") }}
24-
{{- include "secret-keyref-required" (dict "name" "vault-credentials" "key" "vault-token" "env" "VAULT_TOKEN") }}
25-
{{- end }}
2622
{{- if eq .secreteManagerType "aws" }}
2723
{{- include "secret-keyref-required" (dict "name" "aws-credentials" "key" "aws-access-key-id" "env" "AWS_ACCESS_KEY_ID") }}
2824
{{- include "secret-keyref-required" (dict "name" "aws-credentials" "key" "aws-secret-access-key" "env" "AWS_SECRET_ACCESS_KEY") }}
@@ -38,6 +34,10 @@
3834
{{- include "secret-keyref-optional" (dict "name" "gcloud-credentials" "key" "google-cloud-region" "env" "GOOGLE_CLOUD_REGION" "namespace" .namespace) }}
3935
{{- include "secret-keyref-optional" (dict "name" "gcloud-credentials" "key" "google-api-key" "env" "GOOGLE_API_KEY" "namespace" .namespace) }}
4036
{{- end }}
37+
{{- if eq .secreteManagerType "vault" }}
38+
{{- include "secret-keyref-required" (dict "name" "vault-credentials" "key" "vault-addr" "env" "VAULT_ADDR") }}
39+
{{- include "secret-keyref-required" (dict "name" "vault-credentials" "key" "vault-token" "env" "VAULT_TOKEN") }}
40+
{{- end }}
4141
{{- if eq .secreteManagerType "k8s" }}
4242
{{- include "secret-keyref-required" (dict "name" "k8s-credentials" "key" "github-app-private-key" "env" "GITHUB_APP_PRIVATE_KEY") }}
4343
{{- include "secret-keyref-required" (dict "name" "k8s-credentials" "key" "github-app-integration-id" "env" "GITHUB_APP_INTEGRATION_ID") }}

helm/values.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ service:
2323
targetPort: 8080
2424
app:
2525
config:
26-
# Options secretManager: gcloud, aws, azure, vault, k8s
26+
# Options secretManager: k8s, aws, azure, gcloud, vault
2727
secretManager: k8s
2828
blockPr: false
2929
fpStrict: false
@@ -49,23 +49,17 @@ externalIngress:
4949
#spec:
5050
# frontendConfigSpec:
5151
# item1: value1
52-
aws:
52+
eks:
5353
enabled: false
5454
annotations:
5555
#- alb.ingress.kubernetes.io/scheme: internet-facing
5656
#- alb.ingress.kubernetes.io/target-type: ip
5757
certificateArn: ""
58-
azure:
58+
aks:
5959
enabled: false
6060
annotations:
6161
#- appgw.ingress.kubernetes.io/use-private-ip: "false"
6262
#- appgw.ingress.kubernetes.io/request-timeout: "300"
6363
managedCertificate:
6464
enabled: false
6565
domain: ""
66-
vault:
67-
enabled: false
68-
annotations:
69-
#- service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
70-
service:
71-
type: LoadBalancer

setup/secret_managers/configure_cli.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,6 @@
77
from src.config import write_setting
88

99

10-
# Vault is used for two options, remote and local
11-
def configure_vault(local=False):
12-
print("Configuring access: executing `vault login` (temporarily leaving the script)")
13-
try:
14-
subprocess.run(["vault", "login"], check=True)
15-
print("(verify inputs for typos, white-spaces and correct format)")
16-
if local:
17-
address = getpass(
18-
"Insert you Vault server address: ['http://127.0.0.1:8200']\n"
19-
) or 'http://127.0.0.1:8200'
20-
else:
21-
address = getpass("Insert you Vault server address: ") or ''
22-
if address:
23-
vault_url_path = f"{CONFIG_DIR}/vault-address"
24-
with open(vault_url_path, 'w') as f:
25-
f.write(address)
26-
print(f"Successfully written Vault address to {vault_url_path}")
27-
else:
28-
print("No Vault address was received.")
29-
print("It's possible to define the env var VAULT_ADDR instead,")
30-
print("but it might not persist.")
31-
print("Vault access configured successfully.")
32-
except subprocess.CalledProcessError:
33-
print("Failed to login to Vault.")
34-
print("Ensure Vault CLI is installed, login, and rerun setup.py to continue")
35-
36-
3710
def configure_aws():
3811
print("Configuring access: executing `aws configure` (temporarily leaving the script)")
3912
try:
@@ -82,12 +55,39 @@ def configure_gcloud():
8255
print("Ensure it's installed, configure it, and rerun setup.py to continue")
8356

8457

58+
# Vault is used for two options, remote and local
59+
def configure_vault(local=False):
60+
print("Configuring access: executing `vault login` (temporarily leaving the script)")
61+
try:
62+
subprocess.run(["vault", "login"], check=True)
63+
print("(verify inputs for typos, white-spaces and correct format)")
64+
if local:
65+
address = getpass(
66+
"Insert you Vault server address: ['http://127.0.0.1:8200']\n"
67+
) or 'http://127.0.0.1:8200'
68+
else:
69+
address = getpass("Insert you Vault server address: ") or ''
70+
if address:
71+
vault_url_path = f"{CONFIG_DIR}/vault-address"
72+
with open(vault_url_path, 'w') as f:
73+
f.write(address)
74+
print(f"Successfully written Vault address to {vault_url_path}")
75+
else:
76+
print("No Vault address was received.")
77+
print("It's possible to define the env var VAULT_ADDR instead,")
78+
print("but it might not persist.")
79+
print("Vault access configured successfully.")
80+
except subprocess.CalledProcessError:
81+
print("Failed to login to Vault.")
82+
print("Ensure Vault CLI is installed, login, and rerun setup.py to continue")
83+
84+
8585
def configure_sm(manager: str):
8686
config_map = {
87-
"vault": configure_vault,
8887
"aws": configure_aws,
8988
"azure": configure_azure,
9089
"gcloud": configure_gcloud,
90+
"vault": configure_vault,
9191
"local": lambda: configure_vault(local=True),
9292
}
9393
config_map.get(manager, lambda: None)()
@@ -133,10 +133,10 @@ def add_to_toml(package: str) -> None:
133133
# Install the secret manager's Python package, and add it to pyproject.toml
134134
def manage_secret_manager_dependency(manager: str) -> None:
135135
dependencies = {
136-
"vault": "[email protected]",
137136
138137
"azure": "[email protected]",
139138
"gcloud": "[email protected]",
139+
"vault": "[email protected]",
140140
"local": "[email protected]"
141141
}
142142
package: str = dependencies.get(manager)
@@ -153,10 +153,10 @@ def choose_secrets_manager() -> str:
153153
print("This app can install a local manager for you (option 5).")
154154
print("However, it's highly recommended to use a remote secret manager.\n")
155155
print("Select the secret sm you use:")
156-
print("1) HashiCorp Vault")
157-
print("2) AWS Secrets Manager")
158-
print("3) Azure Key Vault Secrets")
159-
print("4) Google Cloud Secret Manager")
156+
print("1) AWS Secrets Manager")
157+
print("2) Azure Key Vault Secrets")
158+
print("3) Google Cloud Secret Manager")
159+
print("4) HashiCorp Vault")
160160
print("5) Easy local storage with HashiCorp Vault (insecure)")
161161

162162
choice = input("Enter the number corresponding to your choice: ")
@@ -170,10 +170,10 @@ def choose_secrets_manager() -> str:
170170
return choose_secrets_manager()
171171

172172
sm_types = {
173-
1: "vault",
174-
2: "aws",
175-
3: "azure",
176-
4: "gcloud",
173+
1: "aws",
174+
2: "azure",
175+
3: "gcloud",
176+
4: "vault",
177177
5: "local"
178178
}
179179

0 commit comments

Comments
 (0)