All Projects → developer-guy → container-image-sign-and-verify-with-cosign-and-opa

developer-guy / container-image-sign-and-verify-with-cosign-and-opa

Licence: other
This is just a proof-of-concept project that aims to sign and verify container images using cosign and OPA (Open Policy Agent)

Programming Languages

go
31211 projects - #10 most used programming language
Open Policy Agent
39 projects

Projects that are alternatives of or similar to container-image-sign-and-verify-with-cosign-and-opa

awesome-opa
A curated list of OPA related tools, frameworks and articles
Stars: ✭ 316 (+485.19%)
Mutual labels:  opa, open-policy-agent
opal
Policy and data administration, distribution, and real-time updates on top of Open Policy Agent
Stars: ✭ 459 (+750%)
Mutual labels:  opa, open-policy-agent
dotnet-opa-wasm
Call Open Policy Agent (OPA) policies in WASM (Web Assembly) from .NET Core
Stars: ✭ 36 (-33.33%)
Mutual labels:  opa, open-policy-agent
OPA-python-client
Python client for Open Policy Agent
Stars: ✭ 24 (-55.56%)
Mutual labels:  opa, open-policy-agent
Opa
An open source, general-purpose policy engine.
Stars: ✭ 5,939 (+10898.15%)
Mutual labels:  opa, open-policy-agent
opa-kafka-plugin
Open Policy Agent (OPA) plug-in for Kafka authorization
Stars: ✭ 46 (-14.81%)
Mutual labels:  opa, open-policy-agent
k8s-opa-boilerplate
Boilerplate example of managing OPA with kustomize
Stars: ✭ 14 (-74.07%)
Mutual labels:  opa, open-policy-agent
cryptographic-protocols-arduino-and-PC
This project demonstrates how cryptographic protocols can be implemented for the case when an Arduino board and a PC communicate. Primitives implemented: AES, RSA and Diffie–Hellman key exchange.
Stars: ✭ 46 (-14.81%)
Mutual labels:  proof-of-concept
Umbraco-RCE
Umbraco CMS 7.12.4 - (Authenticated) Remote Code Execution
Stars: ✭ 61 (+12.96%)
Mutual labels:  proof-of-concept
opa-java-spring-client
Simple Spring client for working with the Open Policy Agent
Stars: ✭ 19 (-64.81%)
Mutual labels:  opa
sigstore
Common go library shared across sigstore services and clients
Stars: ✭ 285 (+427.78%)
Mutual labels:  cosign
react-mvp
Model-View-Presenter Proof of Concept in React
Stars: ✭ 38 (-29.63%)
Mutual labels:  proof-of-concept
busysteg
👻 Hide information content into busy areas of images, optimally
Stars: ✭ 62 (+14.81%)
Mutual labels:  proof-of-concept
advisories
Advisories and Proofs of Concept by BlackArrow
Stars: ✭ 17 (-68.52%)
Mutual labels:  proof-of-concept
clean-ddd-php-poc-contacts
A simple contact manager API to demonstrate the concepts of Clean Architecture and DDD with PHP 7.4+.
Stars: ✭ 31 (-42.59%)
Mutual labels:  proof-of-concept
ReflectivePELoader
Reflective PE loader for DLL injection
Stars: ✭ 130 (+140.74%)
Mutual labels:  proof-of-concept
s3-proxy
S3 Reverse Proxy with GET, PUT and DELETE methods and authentication (OpenID Connect and Basic Auth)
Stars: ✭ 106 (+96.3%)
Mutual labels:  opa
policies
A set of shared policies for use with Conftest and other Open Policy Agent tools
Stars: ✭ 61 (+12.96%)
Mutual labels:  open-policy-agent
order-management-system
Ecommerce demo microservice platform, a proof of concept for microservices architecture
Stars: ✭ 15 (-72.22%)
Mutual labels:  proof-of-concept
regolibrary
The rego library package contains the controls Kubescape uses for detecting miss-configurations in Kubernetes manifests
Stars: ✭ 45 (-16.67%)
Mutual labels:  opa

Sign Container Images with cosign and Verify signature by using Open Policy Agent (OPA)

demo

In the beginning, I believe it is worth saying that this project is just a proof-of-concept project that shows people how they can use cosign and OPA (Open Policy Agent) together to implement the signing and verifying container image process together.

In most basic form, cosign is a container signing tool; it helps us to sign and verify container images by using the signature algorithm (ECDSA-P256) and payload format (Red Hat Simple Signing).

Dan Lorenc, who is one of the maintainers of the project, wrote an excellent article about what cosign is and the motivation behind it; you can follow the link to access it.

On the other hand side, the Open Policy Agent (OPA, pronounced "oh-pa") is an open-source, general-purpose policy engine that unifies policy enforcement across the stack. So, the motivation behind using this kind of policy engine is providing an easy way of enforcing organizational policies across the stack.

What is the motivation for combining both cosign and OPA?

Let's assume that we have to ensure only the images that have valid signatures can be deployed into production-grade Kubernetes clusters. So, to implement this kind of scenario is that we can use OPA's http.send built-in function to call some external service an HTTP server that exposes /verify endpoint and uses cosign under the hood to verify the signature of an image.

Tutorial

High-Level Overview

This is what we want to achieve at the end of the day:

Prerequisites

Demonstration

Create sample Rego Policy

  1. Define the package:
package signature
  1. Assign default value to the verified rule:
default verified = false
  1. Create the rule body:
verified {
    # read the `image` from the `input` that will be verified
    body := { "image": input.image }
    
    # hardcoded consts
    headers_json := { "Content-Type": "application/json" }
    cosignHTTPWrapperURL := "http://localhost:8080/verify"

    # send HTTP POST request to cosign-wrapper
    output := http.send({"method": "post", "url": cosignHTTPWrapperURL, "headers": headers_json, "body": body})
    
    # check if result verified
    output.body.verified
}

P.S: In this demo, we used the http, and ignored the authentication process. Better use the https.

Run the OPA Server with pre-loaded Rego policies

$ opa run --server rego

{"addrs":[":8181"],"diagnostic-addrs":[],"level":"info","msg":"Initializing server.","time":"2021-07-14T23:19:49+03:00"}

Generate Key-Pair using Cosign

$ cosign generate-key-pair

Test

input.json:

{ "input": { "image": "gcr.io/developerguy-311909/ubuntu:unsigned"} }
  • Test with unsigned image:
$ curl -X POST :8181/v1/data/signature/verified -H "Content-Type: application/json" -d "@input.json"
{"result":false}

# OPA Log
{"client_addr":"[::1]:62078","level":"info","msg":"Sent response.","req_id":2,"req_method":"POST","req_path":"/v1/data/signature/verified","resp_bytes":16,"resp_duration":2.107975,"resp_status":200,"time":"2021-07-14T23:22:47+03:00"}
  • Sign:
$ cosign sign -key cosign.key $IMAGE
Pushing signature to: ...
  • Test with signed image:
$ curl -X POST :8181/v1/data/signature/verified -H "Content-Type: application/json" -d "@input.json"
{"result":true}

Furthermore

You should notice that we worked on the local environment to make that happen; of course, there is an alternative way of implementing this kind of demonstration. You can do the same in the Kubernetes environment. To do that, you can use OPA Gatekeeper, which is a customizable AdmissionWebhook, instead of using just OPA in the bare minimum and running cosign-http-wrapper as a Pod.

Conclusion

You can implement a way of protecting Kubernetes clusters from an unsigned image by just using cosign and OPA seamlessly.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].