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

Dat feat awsmp sleek rebase #193

Draft
wants to merge 85 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
e7990ea
feat: new chart for aws marketplace product. The product supports lic…
Sep 6, 2022
6397cdd
fix: qoute productSKU value; add logs for checkout license
Sep 6, 2022
b658876
refactor: upgrade values.yaml with updated image pushed to aws mp pro…
Sep 6, 2022
0640270
fix: support region, product, fingerprint and debug env variables; re…
Sep 7, 2022
fdc41c2
fix: run license cron job on @daily. fix values naming bug
Sep 7, 2022
8ebf020
fix: upgrade image in aws mp helm chart values
Sep 7, 2022
17e6251
fix: remove awsmp-... chart. datree-admission-webhook chart should ho…
Sep 12, 2022
e0a348b
fix: add * to ignore luanch.json file
Sep 12, 2022
5289408
fix: remove ** to ignore luanch.json file
Sep 12, 2022
275e001
fix: accidently deleted gh-pages values file with awsmp values file. …
Sep 21, 2022
eeaa96b
fix: added aws.values
Sep 21, 2022
5e73163
feat: added validation for value.yaml file
Sep 12, 2022
2abeacc
fix: combine charts and added values.yaml for each option
Sep 19, 2022
cc12656
feat: script for packaing
Sep 19, 2022
2ccc1f3
fix: added script package for free-datree
Sep 19, 2022
595a75e
feat: added chart
Sep 20, 2022
42fbd5e
feat: charts file structure
Sep 20, 2022
f896fba
fix: combine charts and added values.yaml for each option
Sep 19, 2022
6489875
feat: script for packaing
Sep 19, 2022
150fba7
fix: added script package for free-datree
Sep 19, 2022
002513b
feat: added chart
Sep 20, 2022
f650e64
fix: move tempaltes to lib template
shmu3l Sep 28, 2022
448011f
fix: remove templates use include from lib
shmu3l Sep 28, 2022
b43ef0f
fix: remove templates use include from lib
shmu3l Sep 28, 2022
771c57a
fix: add dynamic webhook server alt name to cert
shmu3l Oct 2, 2022
2002a8d
fix: clear datree webhook values and update schema
shmu3l Oct 2, 2022
9b446e7
feat: awsmp datree use datree lib
shmu3l Oct 2, 2022
af85f57
fix: awsmp file structure
shmu3l Oct 2, 2022
d1ef809
feat: add release admission webhook script
shmu3l Oct 3, 2022
121763b
fix: release admission webhook
shmu3l Oct 3, 2022
37a828d
release chart 0.1.3
shmu3l Oct 3, 2022
8ddb66f
fix: release admission webhook helm script update
shmu3l Oct 6, 2022
23a42d7
fix: update .gitignore
Oct 6, 2022
30c96e4
fix: change messages
Oct 6, 2022
572c8c5
fix: release admission webhook path scripts
shmu3l Oct 6, 2022
a13fabc
fix: release admission webhook path scripts
shmu3l Oct 6, 2022
57a809a
fix: release admission webhook path scripts
shmu3l Oct 6, 2022
b79e351
fix: rename script
Oct 6, 2022
edfa70f
fix: change the order of helm file creations
Oct 6, 2022
88d5416
fix: remove files
Oct 6, 2022
7e60bf9
fix: release file index yaml
Oct 6, 2022
2d54188
fix: dont stash pop
Oct 6, 2022
56e619f
feat: certificate alternative names use datree.namespace template.
Oct 18, 2022
c02ba66
fix: bump lib chart version
Oct 18, 2022
7132337
fix: added dynamic namespace installation. Rename chart according to …
Oct 24, 2022
883f25c
fix: aligned charts with aws-marketplace ECR repositories.
Nov 3, 2022
d4c0867
feat: pull bitnami-kubectl from private ecr registry
Nov 3, 2022
a09986d
fix: updated bitnami in free offer chart
Nov 3, 2022
378ef6a
feat: added new binary in cmd folder for init container
Nov 7, 2022
a5e0e21
wip
Nov 8, 2022
7d9411c
wip: poc of webhook race condition
Nov 9, 2022
076b597
fix: working product on minikube. NOTE: very slow
Nov 10, 2022
d4cd131
fix: working version
Nov 13, 2022
a1d8ba3
fix: wokring production version on minikube
Nov 13, 2022
4e504da
fix: working production version. Minikube. 3minutes sleep time
Nov 13, 2022
956b584
fix: working version ECR repositories on Faragate.
Nov 13, 2022
3cfe527
feat: support uninstall Datree product
Nov 13, 2022
d2eab5f
fix: working version in AWS Marketplace. Datree product
Nov 13, 2022
58e430c
feat: working version. Datree Free product. version 1.0.1-rc.1
Nov 13, 2022
7ba108f
feat: check for webhook existence, wait for running pods. Refactor
Nov 15, 2022
1f1d134
fix: wait for all deployment replicas to be ready. updated ecr images
Nov 15, 2022
07f0a82
fix: update aws mp Chart
Nov 16, 2022
d51dfde
fix: remove .vscode luanch.json
Nov 16, 2022
cb90d7b
fix: update Dockerfiles
Nov 16, 2022
c3a79b2
fix: remove comments
Nov 16, 2022
09fc506
test: added tests for cert-generator
Nov 16, 2022
f5593a7
test: wip
Nov 20, 2022
4ccf30e
test: fixed table testing for k8sClient
Nov 20, 2022
8161364
test: cert-generator tests
Nov 21, 2022
1e4697b
fix: structure packages in webhook-init to not use one another, only …
Nov 21, 2022
a550115
fix: updated makefile
Nov 21, 2022
52ce8b7
test: ensure empty env variables has defaults
Nov 21, 2022
4b57836
fix: bump images versions, working product on minikube.
Nov 21, 2022
f893b31
fix: make code build succesfully
Nov 21, 2022
b3867fe
fix: fix import position to remove changes
Nov 21, 2022
93c7cd2
fix: remove unused script
Nov 21, 2022
5f8e5ee
fix: remove unnessecary changes in gitignore
Nov 21, 2022
c0a13b7
fix: remove luanch.json
Nov 21, 2022
55bacc5
fix: merge manifests conflicts
Nov 22, 2022
e8a9f87
fix: user logger correctly
Nov 22, 2022
3dbba7d
fix: pass env var for webhook pods selector
Nov 22, 2022
65fe7f0
test: test main flow of cer-generator
Nov 22, 2022
8ecc47c
fix: added deploy in makefile
Nov 27, 2022
7f36170
fix: bump images version in chart
Nov 27, 2022
9938af2
fix Makefile to deploy all binaries for awsmp. Ensure TOKEN isnt requ…
Nov 27, 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
Prev Previous commit
Next Next commit
fix: support region, product, fingerprint and debug env variables; re…
…factore initK8sMetadata
  • Loading branch information
Noaa Barki authored and Noaa Barki committed Nov 21, 2022
commit 0640270e7265ef90caf6aa3813ff27e2725122e8
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -20,8 +20,10 @@
"args": ["upgrade"],
"buildFlags": "-tags=staging",
"env": {
"AWS_MP_ENABLE_CHECKOUT_LICENSE": "true",
"AWS_MP_PRODUCT_SKU": "ad0ee0c8-f50f-464a-9bc4-d6270592dd36"
"AWS_MP_ENABLE_CHECK_ENTITLEMENT": "true",
"AWS_MP_PRODUCT_ID": "ad0ee0c8-f50f-464a-9bc4-d6270592dd36",
"AWS_MP_KEY_FINGERPRINT": "aws:294406891311:AWS/Marketplace:issuer-fingerprint",
"AWS_MP_REGION": "us-east-1"
}
}
]
26 changes: 17 additions & 9 deletions charts/awsmp-datree-admission-webhook/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -49,6 +49,9 @@ spec:
# caution: don't change the order of the environment variables
# changing the order will harm resource patching
env:
- name: DEBUG
value: "{{ .Values.debug }}"
# Datree webhook varaibles
- name: DATREE_TOKEN
value: {{.Values.datree.token}}
- name: DATREE_POLICY
@@ -59,34 +62,39 @@ spec:
value: {{.Values.datree.output}}
- name: DATREE_NO_RECORD
value: {{.Values.datree.noRecord}}
- name: AWS_MP_PRODUCT_SKU
value: {{.Values.aws.productSku}}
- name: AWS_MP_ENABLE_CHECKOUT_LICENSE
value: {{.Values.aws.enableCheckoutLicense | quote}}
{{- if .Values.aws.mpLicenseSecretName }}
# AWS Marketplace varaibles
- name: AWS_MP_PRODUCT_ID
value: {{ .Values.aws.productId }}
- name: AWS_MP_KEY_FINGERPRINT
value: {{ .Values.aws.issuerKey }}
- name: AWS_MP_ENABLE_CHECK_ENTITLEMENT
value: "{{.Values.aws.enableCheckEntitlement}}"
- name: AWS_MP_REGION
value: {{.Values.aws.region}}
{{- if .Values.aws.licenseConfigSecretName }}
- name: AWS_WEB_IDENTITY_REFRESH_TOKEN_FILE
value: "/var/run/secrets/awsmp-product-license/license_token"
- name: AWS_ROLE_ARN
valueFrom:
secretKeyRef:
name: {{ .Values.aws.mpLicenseSecretName }}
name: {{ .Values.aws.licenseConfigSecretName }}
key: iam_role
{{- end}}
# add aws marketplace license config to the licensed container application env
volumeMounts:
- name: webhook-tls-certs
mountPath: /run/secrets/tls
readOnly: true
{{- if .Values.aws.mpLicenseSecretName }}
{{- if .Values.aws.licenseConfigSecretName }}
- name: awsmp-product-license
mountPath: "/var/run/secrets/awsmp-product-license"
{{- end}}
volumes:
- name: webhook-tls-certs
secret:
secretName: webhook-server-tls
{{- if .Values.aws.mpLicenseSecretName }}
{{- if .Values.aws.licenseConfigSecretName }}
- name: awsmp-product-license
secret:
secretName: {{ .Values.aws.mpLicenseSecretName }}
secretName: {{ .Values.aws.licenseConfigSecretName }}
{{- end}}
26 changes: 14 additions & 12 deletions charts/awsmp-datree-admission-webhook/values.yaml
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@ customLabels: {}
# Additional annotations to add to all resources.
customAnnotations: {}

# Run the webhook-server in debug mode, this will log debug information to the console.
debug: false

# Create ClusterRoles, ClusterRoleBindings, and ServiceAccount for datree-webhook-server
rbac:
serviceAccount:
@@ -25,6 +28,7 @@ rbac:
# The ClusterRole name
name: datree-webhook-server-read

# Datree webhook configuration, checkout more details at htttps://hub.datree.com
datree:
# The token used to link the CLI to your dashboard.
token: <DATREE_TOKEN>
@@ -73,16 +77,14 @@ hooks:
pullPolicy: IfNotPresent

# AWS Marketplace configuration
# awsmp:
# # The name of the secret that contains the license configuration.
# licenseConfigSecretName: "aws-marketplace-license-config"
# # The license identity token in the secret.
# licenseToken: <LICENSE_TOKEN>
# # The AWS Identity and Access Management role.
# iamRole: <IAM_ROLE>

# add aws marketplace license config for on-prem deployments
aws:
mpLicenseSecretName: ""
productSku: "ad0ee0c8-f50f-464a-9bc4-d6270592dd36"
enableCheckoutLicense: "true"
# The name of the secret that contains the license configuration.
licenseConfigSecretName: ""
# The AWS Region
region: "us-east-1"
# Enable AWS Marketplace license checkout, this is relevant for paid products only.
enableCheckAccountEntitlement: true
# The application’s Product SKU (Product ID)
productId: "ad0ee0c8-f50f-464a-9bc4-d6270592dd36"
# The trusted issuer of the license (AWS Marketplace)
issuerKey: "aws:294406891311:AWS/Marketplace:issuer-fingerprint"
21 changes: 12 additions & 9 deletions pkg/enums/enums.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package enums

const (
Token = "DATREE_TOKEN"
ClientId = "DATREE_CLIENT_ID"
Policy = "DATREE_POLICY"
Verbose = "DATREE_VERBOSE"
NoRecord = "DATREE_NO_RECORD"
Output = "DATREE_OUTPUT"
Enforce = "DATREE_ENFORCE"
AWSMarketplaceProductSKU = "AWS_MP_PRODUCT_SKU"
AWSMarketplaceEnableCheckoutLicense = "AWS_MP_ENABLE_CHECKOUT_LICENSE"
Token = "DATREE_TOKEN"
ClientId = "DATREE_CLIENT_ID"
Policy = "DATREE_POLICY"
Verbose = "DATREE_VERBOSE"
NoRecord = "DATREE_NO_RECORD"
Output = "DATREE_OUTPUT"
Enforce = "DATREE_ENFORCE"
AWSMarketplaceProductID = "AWS_MP_PRODUCT_ID"
AWSMarketplaceEnableCheckEntitlement = "AWS_MP_ENABLE_CHECK_ENTITLEMENT"
AWSMarketplaceRegion = "AWS_MP_REGION"
AWSMarketplaceKeyFingerprint = "AWS_MP_KEY_FINGERPRINT"
Debug = "DEBUG"
)
85 changes: 49 additions & 36 deletions pkg/k8sMetadataUtil/k8sMetadataUtil.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"os"
"time"

cliClient "github.com/datreeio/admission-webhook-datree/pkg/clients"
cliclient "github.com/datreeio/admission-webhook-datree/pkg/clients"
"github.com/datreeio/admission-webhook-datree/pkg/enums"
licensemanagerclient "github.com/datreeio/admission-webhook-datree/pkg/licenseManagerClient"
"github.com/datreeio/admission-webhook-datree/pkg/loggerUtil"
@@ -20,34 +20,50 @@ import (
)

func InitK8sMetadataUtil() {

validator := networkValidator.NewNetworkValidator()
cliClient := cliClient.NewCliServiceClient(deploymentConfig.URL, validator)
k8sClient, err := getClientSet()
cliClient := cliclient.NewCliServiceClient(deploymentConfig.URL, validator)

var clusterUuid k8sTypes.UID
k8sClient, err := getClientSet()
if err != nil {
sendK8sMetadata(-1, err, clusterUuid, cliClient)
loggerUtil.Log(fmt.Sprint("failed getting k8s client set", err))
cliClient.ReportK8sMetadata(&cliclient.ReportK8sMetadataRequest{
ClusterUuid: "",
Token: os.Getenv(enums.Token),
NodesCount: -1,
NodesCountErr: err.Error(),
})
return
}

clusterUuid, err = getClusterUuid(k8sClient)
clusterUuid, err := getClusterUuid(k8sClient)
if err != nil {
sendK8sMetadata(-1, err, clusterUuid, cliClient)
cliClient.ReportK8sMetadata(&cliclient.ReportK8sMetadataRequest{
ClusterUuid: clusterUuid,
Token: os.Getenv(enums.Token),
NodesCount: -1,
NodesCountErr: err.Error(),
})
}

runHourlyNodesCountCronJob(k8sClient, cliClient, clusterUuid)

if os.Getenv(enums.AWSMarketplaceEnableCheckEntitlement) == "true" {
runDailyAWSCheckoutLicenseCronJob(k8sClient, cliClient, clusterUuid)
}

}

func runHourlyNodesCountCronJob(k8sClient *kubernetes.Clientset, cliClient *cliclient.CliClient, clusterUuid k8sTypes.UID) {
cornJob := cron.New(cron.WithLocation(time.UTC))
cornJob.AddFunc("@hourly", func() {
nodesCount, nodesCountErr := getNodesCount(k8sClient)
sendK8sMetadata(nodesCount, nodesCountErr, clusterUuid, cliClient)
cliClient.ReportK8sMetadata(&cliclient.ReportK8sMetadataRequest{
ClusterUuid: clusterUuid,
Token: os.Getenv(enums.Token),
NodesCount: nodesCount,
NodesCountErr: nodesCountErr.Error(),
})
})
cornJob.Start()

if os.Getenv(enums.AWSMarketplaceEnableCheckoutLicense) == "true" {
runDailyAWSCheckoutLicenseCronJob(k8sClient)
}

}

func getNodesCount(clientset *kubernetes.Clientset) (int, error) {
@@ -84,38 +100,35 @@ func getClusterUuid(clientset *kubernetes.Clientset) (k8sTypes.UID, error) {
return clusterMetadata.UID, nil
}

func sendK8sMetadata(nodesCount int, nodesCountErr error, clusterUuid k8sTypes.UID, client *cliClient.CliClient) {
token := os.Getenv(enums.Token)

var nodesCountErrString string
if nodesCountErr != nil {
nodesCountErrString = nodesCountErr.Error()
}

client.ReportK8sMetadata(&cliClient.ReportK8sMetadataRequest{
ClusterUuid: clusterUuid,
Token: token,
NodesCount: nodesCount,
NodesCountErr: nodesCountErrString,
})
}

// run chckout license cron job daily to check if aws marketplace license is valid with the nodes number
func runDailyAWSCheckoutLicenseCronJob(k8sClient *kubernetes.Clientset) {
func runDailyAWSCheckoutLicenseCronJob(k8sClient *kubernetes.Clientset, cliClient *cliclient.CliClient, clusterUuid k8sTypes.UID) {
licenseManagerClient := licensemanagerclient.NewLicenseManagerClient()

licenseCheckerCornJob := cron.New(cron.WithLocation(time.UTC))
// @daily means run once a day, midnight
licenseCheckerCornJob.AddFunc("@daily", func() {
licenseCheckerCornJob.AddFunc("@every 1m", func() {
nodesCount, err := getNodesCount(k8sClient)
if err != nil {
loggerUtil.Log(fmt.Sprint("failed counting nodes for checkout", err))
loggerUtil.Debug(fmt.Sprint("failed counting nodes for checkout", err))
cliClient.ReportK8sMetadata(&cliclient.ReportK8sMetadataRequest{
ClusterUuid: clusterUuid,
Token: os.Getenv(enums.Token),
NodesCount: -1,
NodesCountErr: err.Error(),
})
return
}

fmt.Println("checking aws marketplace license with nodes count", nodesCount)
loggerUtil.Debug(fmt.Sprint("checking aws marketplace license with nodes count", nodesCount))
err = licenseManagerClient.CheckoutLicense(nodesCount)
if err != nil {
loggerUtil.Log(fmt.Sprint("checkout license failed: ", err))
loggerUtil.Debug(fmt.Sprint("checkout license failed: ", err))
cliClient.ReportK8sMetadata(&cliclient.ReportK8sMetadataRequest{
ClusterUuid: clusterUuid,
Token: os.Getenv(enums.Token),
NodesCount: -1,
NodesCountErr: err.Error(),
})
}
})
licenseCheckerCornJob.Start()
21 changes: 11 additions & 10 deletions pkg/licenseManagerClient/client.go
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ import (
"github.com/google/uuid"
)

const awsMarketplaceIssuer = "aws:294406891311:AWS/Marketplace:issuer-fingerprint"

type LicenseManager struct {
client *licensemanager.LicenseManager
awsMarketplaceProductID string
@@ -21,24 +19,27 @@ type LicenseManager struct {

func NewLicenseManagerClient() *LicenseManager {
clientSession := session.Must(session.NewSession())
awsClient := licensemanager.New(clientSession, aws.NewConfig().WithRegion("us-east-1"))
awsClient := licensemanager.New(clientSession, aws.NewConfig().WithRegion(os.Getenv(enums.AWSMarketplaceRegion)))
return &LicenseManager{
client: awsClient,
awsMarketplaceProductID: os.Getenv(enums.AWSMarketplaceProductSKU),
awsMarketplaceFingerprint: awsMarketplaceIssuer,
awsMarketplaceProductID: os.Getenv(enums.AWSMarketplaceProductID),
awsMarketplaceFingerprint: os.Getenv(enums.AWSMarketplaceKeyFingerprint),
}
}

// Checkout the account license according to number of nodes, if everything goes well, the license will be checked out,
// otherwise an error will returned.
func (l *LicenseManager) CheckoutLicense(entititlementValue int) error {
// Checkout the account license according to quantity of units the account consumes.
// If everything goes well, the license will be checked out, otherwise an error will returned.
func (l *LicenseManager) CheckoutLicense(consumedUnitsCount int) error {
_, err := l.client.CheckoutLicense(&licensemanager.CheckoutLicenseInput{
ClientToken: aws.String(uuid.New().String()),
ClientToken: aws.String(uuid.New().String()),
// "PROVISIONAL" checkout type enables to temporarily draw a unit and return it back to the license pool when the application is stopped.
CheckoutType: aws.String("PROVISIONAL"),
Entitlements: []*licensemanager.EntitlementData{
{
// The entitilement name is the contract API name defined in the product.
// The contract API name is defined in the product "load form" in the AWS Marketplace management protal
Name: aws.String("Datree"),
Value: aws.String(fmt.Sprint(entititlementValue)),
Value: aws.String(fmt.Sprint(consumedUnitsCount)),
Unit: aws.String("Count"),
},
},