-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
featlinter): generate RuleSet from a Bundle. (#5)
- Loading branch information
Showing
13 changed files
with
631 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,3 +143,93 @@ echo '{"app/qa/security/harp/v1.0.0/server/database/credentials":{}}' \ | |
| harp-linter bundle lint --spec test/fixtures/ruleset/valid/database-secret-validator.yaml | ||
{"level":"fatal","@timestamp":"2021-02-23T10:31:24.287Z","@caller":"[email protected]/command.go:856","@message":"unable to execute task","@appName":"harp-bundle-lint","@version":"","@revision":"8ebf40d","@appID":"7pflS7bCAAsDcAiPJWm36pypWY3nHhqOQwCc9Vp1ABCm8ZUWbmGinGL5zbP1EWvn","@fields":{"error":"unable to validate given bundle: package 'app/qa/security/harp/v1.0.0/server/database/credentials' doesn't validate rule 'HARP-SRV-0002'"}} | ||
``` | ||
|
||
### Generate a ruleset from a bundle | ||
|
||
It will use the input bundle structure to generate a `RuleSet`. | ||
|
||
```sh | ||
harp-linter ruleset from-bundle --in customer.bundle | ||
``` | ||
|
||
```yaml | ||
api_version: harp.elastic.co/linter/v1 | ||
kind: RuleSet | ||
meta: | ||
description: Generated from bundle content | ||
name: vjz70BPFJuQhm_7quRGNt1ybocQU6DeXCn8h1o4aPm80CI4pM8lNwVBTDqH8SpW0W1r-8dXSVQK67pO-vtgS_Q | ||
spec: | ||
rules: | ||
- constraints: | ||
- p.has_secret("API_KEY") | ||
name: LINT-vjz70B-1 | ||
path: app/production/customer1/ece/v1.0.0/adminconsole/authentication/otp/okta_api_key | ||
- constraints: | ||
- p.has_secret("host") | ||
- p.has_secret("port") | ||
- p.has_secret("options") | ||
- p.has_secret("username") | ||
- p.has_secret("password") | ||
- p.has_secret("dbname") | ||
name: LINT-vjz70B-2 | ||
path: app/production/customer1/ece/v1.0.0/adminconsole/database/usage_credentials | ||
- constraints: | ||
- p.has_secret("cookieEncryptionKey") | ||
- p.has_secret("sessionSaltSeed") | ||
- p.has_secret("jwtHmacKey") | ||
name: LINT-vjz70B-3 | ||
path: app/production/customer1/ece/v1.0.0/adminconsole/http/session | ||
- constraints: | ||
- p.has_secret("API_KEY") | ||
name: LINT-vjz70B-4 | ||
path: app/production/customer1/ece/v1.0.0/adminconsole/mailing/sender/mailgun_api_key | ||
- constraints: | ||
- p.has_secret("emailHashPepperSeedKey") | ||
name: LINT-vjz70B-5 | ||
path: app/production/customer1/ece/v1.0.0/adminconsole/privacy/anonymizer | ||
- constraints: | ||
- p.has_secret("host") | ||
- p.has_secret("port") | ||
- p.has_secret("options") | ||
- p.has_secret("username") | ||
- p.has_secret("password") | ||
- p.has_secret("dbname") | ||
name: LINT-vjz70B-6 | ||
path: app/production/customer1/ece/v1.0.0/userconsole/database/usage_credentials | ||
- constraints: | ||
- p.has_secret("privateKey") | ||
- p.has_secret("publicKey") | ||
name: LINT-vjz70B-7 | ||
path: app/production/customer1/ece/v1.0.0/userconsole/http/certificate | ||
- constraints: | ||
- p.has_secret("cookieEncryptionKey") | ||
- p.has_secret("sessionSaltSeed") | ||
- p.has_secret("jwtHmacKey") | ||
name: LINT-vjz70B-8 | ||
path: app/production/customer1/ece/v1.0.0/userconsole/http/session | ||
- constraints: | ||
- p.has_secret("user") | ||
- p.has_secret("password") | ||
name: LINT-vjz70B-9 | ||
path: infra/aws/essp-customer1/us-east-1/rds/adminconsole/accounts/root_credentials | ||
- constraints: | ||
- p.has_secret("API_KEY") | ||
- p.has_secret("ca.pem") | ||
name: LINT-vjz70B-10 | ||
path: platform/production/customer1/us-east-1/billing/recurly/vendor_api_key | ||
- constraints: | ||
- p.has_secret("username") | ||
- p.has_secret("password") | ||
name: LINT-vjz70B-11 | ||
path: platform/production/customer1/us-east-1/postgresql/admiconsole/admin_credentials | ||
- constraints: | ||
- p.has_secret("username") | ||
- p.has_secret("password") | ||
name: LINT-vjz70B-12 | ||
path: platform/production/customer1/us-east-1/zookeeper/accounts/admin_credentials | ||
- constraints: | ||
- p.has_secret("privateKey") | ||
- p.has_secret("publicKey") | ||
name: LINT-vjz70B-13 | ||
path: product/ece/v1.0.0/artifact/signature/key | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
var rulesetCmd = func() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "ruleset", | ||
Aliases: []string{"rs"}, | ||
Short: "RuleSet commands", | ||
} | ||
|
||
// Bundle commands | ||
cmd.AddCommand(rulesetFromBundle()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
|
||
"github.com/elastic/harp-plugins/cmd/harp-linter/pkg/tasks/ruleset" | ||
"github.com/elastic/harp/pkg/sdk/cmdutil" | ||
"github.com/elastic/harp/pkg/sdk/log" | ||
) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
var rulesetFromBundle = func() *cobra.Command { | ||
var ( | ||
inputPath string | ||
outputPath string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "from-bundle", | ||
Short: "Genereate a RuleSet descriptor from a Bundle", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Initialize logger and context | ||
ctx, cancel := cmdutil.Context(cmd.Context(), "harp-ruleset-from-bundle", conf.Debug.Enable, conf.Instrumentation.Logs.Level) | ||
defer cancel() | ||
|
||
// Prepare task | ||
t := &ruleset.FromBundleTask{ | ||
ContainerReader: cmdutil.FileReader(inputPath), | ||
OutputWriter: cmdutil.FileWriter(outputPath), | ||
} | ||
|
||
// Run the task | ||
if err := t.Run(ctx); err != nil { | ||
log.For(ctx).Fatal("unable to execute task", zap.Error(err)) | ||
} | ||
}, | ||
} | ||
|
||
// Parameters | ||
cmd.Flags().StringVar(&inputPath, "in", "-", "Container input ('-' for stdin or filename)") | ||
cmd.Flags().StringVar(&outputPath, "out", "", "Output RuleSet specification path ('' for stdout or filename)") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.