Code Monkey home page Code Monkey logo

copper's People

Contributors

amitsaha avatar kasia66 avatar khash avatar lvangool avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

copper's Issues

Add ES6 javascript engine for validators

I think right now the ES5 javascript engine is being used for the validators. And by using the ES6 engine it would be much easier to write some validation rules due to the additional features ES6 comes with.

Return code only reflects validation of the last segment

When running on a multi-template file, it seems the return code only reflects the last segment. For example, this output corresponds to a return code 1:

Validating part 0
	ApiV1Only - FAIL
Validating part 1
	ApiV1Only - PASS
Validating part 2
	ApiV1Only - FAIL

...while this output corresponds to a return code 0:

Validating part 0
	ApiV1Only - FAIL
Validating part 1
	ApiV1Only - PASS
Validating part 2
	ApiV1Only - PASS

I would expect a return code 0 only when all validations pass, and a 1 otherwise.

I will look at making this change and opening a PR - just wanted to document it here first!

Rules for validating the filename and/or path

I don't see a way to write Copper rules on the filename. We have a policy that the .yaml manifest file must be named in a certain way. For example, NAME-TYPE.yaml where NAME must match .spec.metadata.name. and TYPE must match .spec.kind.

Similarly, I might want to enforce rules on the parent directories of the manifest. For example, if the directory structure has some correspondence on the .spec.medata.labels values.

Would that be possible to implement, perhaps by exposing the raw filepath to a rule?

basic example fails with (<unknown>): mapping values are not allowed in this context at line 11 column 22 (Psych::SyntaxError)

Hi There!

I just installed ruby and copper on my mac to give this a try. I am using the basic example as described in https://copper.sh/ and I get the error shown below. Am I doing something wrong? Yes I am a ruby newbie...

Carltons-MacBook-Pro:rendered-armada.d ckmason$ cat cop-deploy.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    namespace: foobar
    name: foo
spec:
    template:
        spec:
            containers:
            - name: mysql
                image: index.docker.io/library/mysql:6.5.0
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$ cat my_rules.cop
rule NoLatest ensure {  // use of latest as image tag is not allowed
    fetch("$.spec.template.spec.containers..image")
        .as(:image)
        .pick(:tag)
        .contains("latest") == false
    }
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$
Carltons-MacBook-Pro:rendered-armada.d ckmason$ copper check --rules my_rules.cop --file cop-deploy.yaml
Validating part 0
Traceback (most recent call last):
	15: from /usr/local/lib/ruby/gems/2.5.0/bin/copper:23:in `<main>'
	14: from /usr/local/lib/ruby/gems/2.5.0/bin/copper:23:in `load'
	13: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:7:in `<top (required)>'
	12: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:121:in `<module:Copper>'
	11: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
	10: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
	 9: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
	 8: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
	 7: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `check'
	 6: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `each_with_index'
	 5: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `each'
	 4: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:75:in `block in check'
	 3: from /usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:263:in `load'
	 2: from /usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:350:in `parse'
	 1: from /usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:402:in `parse_stream'
/usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/psych.rb:402:in `parse': (<unknown>): mapping values are not allowed in this context at line 11 column 22 (Psych::SyntaxError)

Copper handles yaml files beginning with `---` incorrectly

YAML files can optionally being with 3 dashes, e.g ---. Copper will parse that as a resource. For example, given the manifest:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: busybox
spec:
  template:
    spec:
      containers:
      - image: busybox
        name: busybox

and rule:

rule DeploymentApiVersion ensure {
    fetch("$[?(@['kind'] == 'Deployment')].apiVersion").first == "apps/v1"
}

copper will fail for the opening dashes:

$ copper check --rules rule.cop --file deployment.yaml 
Validating part 0
	DeploymentApiVersion - FAIL
Validating part 1
	DeploymentApiVersion - PASS

problem reading annotations, e.g. can't modify frozen String (FrozenError)

Hello Again,

I am trying to validate that a simple Ingress .yaml contains a certain ingress class in its annotations yet, I get:

/usr/local/lib/ruby/gems/2.5.0/gems/jsonpath-0.9.8/lib/jsonpath.rb:39:in `initialize': can't modify frozen String (FrozenError)

I think it has something to do with the . and / in my annotation values.

Here is my input yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: eurekap
spec:
  backend:
    serviceName: public-gdpr-data-deletion
    servicePort: 443

Here is my Copper rule file:

rule IngressAnnotation ensure {
    fetch("$.metadata.annotations.kubernetes.io/ingress.class").first == "eurekap"
}

And when I run Copper, I get the following error:

Carltons-MacBook-Pro:rendered-armada.d ckmason$ copper check  --rules ingress.cop --file ingress-good.yaml
Validating part 0
Traceback (most recent call last):
	23: from /usr/local/lib/ruby/gems/2.5.0/bin/copper:23:in `<main>'
	22: from /usr/local/lib/ruby/gems/2.5.0/bin/copper:23:in `load'
	21: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:7:in `<top (required)>'
	20: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:121:in `<module:Copper>'
	19: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
	18: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
	17: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
	16: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
	15: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `check'
	14: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `each_with_index'
	13: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:73:in `each'
	12: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:76:in `block in check'
	11: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/bin/copper:85:in `validate'
	10: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/copper.rb:12:in `execute'
	 9: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/root.rb:5:in `value'
	 8: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/root.rb:5:in `each'
	 7: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/root.rb:6:in `block in value'
	 6: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/rule_definition.rb:11:in `value'
	 5: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/logic.rb:6:in `value'
	 4: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/comparison.rb:5:in `value'
	 3: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/expression.rb:5:in `value'
	 2: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/functions/fetch.rb:14:in `value'
	 1: from /usr/local/lib/ruby/gems/2.5.0/gems/c66-copper-0.0.7/lib/copper/functions/fetch.rb:14:in `new'
/usr/local/lib/ruby/gems/2.5.0/gems/jsonpath-0.9.8/lib/jsonpath.rb:39:in `initialize': can't modify frozen String (FrozenError)

If I modify both my .yaml and the rule to get rid of the slashes and dots in the annotation element, it works. I can't use that as a solution though. So, its got something to do with the format of my annotation and not sure how to get it to read them properly.

For example, if I modify my .yaml and rule to change my annotation from kubernetes.io/ingress.class to ingress-class it works.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress-class: eurekap
spec:
  backend:
    serviceName: public-gdpr-data-deletion
    servicePort: 443

The Copper rule to be:

rule IngressAnnotation ensure {
    fetch("$.metadata.annotations.ingress-class").first == "eurekap"
}

Then it works:

Carltons-MacBook-Pro:rendered-armada.d ckmason$ copper check  --rules ingress.cop --file ingress-good.yaml
Validating part 0
	IngressAnnotation - PASS

Thanks for your help.

kubetest

I came across copper via Kubernetes SIG Apps. What is the differentiator to kubetest?

interface {} is []interface {}, not []map[string]interface {}

If a validator doesn't find at least one violation, it'll result in an error:
interface {} is []interface {}, not []map[string]interface {}

This can be reproduced easily by modifying the (sample)[https://github.com/cloud66-oss/copper/blob/2.0.0/samples/sample.yml] by either of the following:

  • remove the Deployment object entirely from the yaml
  • change latest into any other string

gem ships binaries that conflict

c66-copper's executable "console" conflicts with countries
Overwrite the executable? [yN]  y
c66-copper's executable "setup" conflicts with paper_trail-background
Overwrite the executable? [yN]  y

Documentation off

Under the jsonpath part, it says:

fetch("$.spec.spec.containers[?(@.name == 'mysql')]") // will return ["index.docker.io/library/ubuntu:latest"]

But I think it should be something like (not sure if it's missing a dot):

fetch("$.spec.spec.containers[?(@.name == 'mysql')].image") // will return ["quay.io/mysql:2.3.0"]

How to filter by object type

If I have a fake concatenated manifest (in this case the output of `helm template), the I find it tricky to filter on object types.

---
apiVersion: v1
kind: ConfigMap
---
apiVersion: v1
kind: ConfigMap
---
apiVersion: v1
kind: ConfigMap
---
apiVersion: v1
kind: Service
---
apiVersion: apps/v1beta1
kind: Deployment
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy

Aside, the tool recognizes the first element as an empty doc, I think.

How do I enforce things for kind: Service only?

add lodash to libjs

I think it would be a nice addition to add lodash to the libjs library.

Filtering, mapping, etc. is quite a lot of work in ES5, lodash can make this a lot easier for people.

reading yml files from directory

Is there a way to read bunch of yaml files from directory instead just a file to apply the rule. I currently have yml files stored in "files" directory and --file option isn't reading all the files.

copper check --rules myrule.cop --file files/*.yml

tried
copper check --rules myrule.cop --dir files/*.yml , but no worky.

ERROR: "copper check" was called with arguments ["--dir", "files/elastic_scc.yml", "files/test-admin.yml"]
Usage: "copper check"

Current getting started doc formats to an emdash, appearing to be the wrong syntax for CLI parameters

The current version of getting started contains
$ copper check –rules my_rule.cop –file service.yml
This looks like the command uses one dash (-rules) rather than two (--rules), which is probably a quirk of the formatter.

This is exacerbated by there being some problems in CLI syntax handling, meaning the output is an unhelpful
$ copper check -rules foo -file bar ERROR: "copper check" was called with arguments ["-rules", "foo", "-file", "bar"] Usage: "copper check"
However, copper check also doesn't suggest what the problem is:
$ copper check ~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/c66-copper-0.0.4/bin/copper:39:in ``exists?': no implicit conversion of nil into String (TypeError)...`

To work around, someone can check the source and see what it's expecting, but this could be a bit of a speedbump for people ramping up on copper. The website doesn't appear to be part of the repo or I'd make a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.