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

feat: Assertion verification #452

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

elizabethhealy
Copy link
Member

@elizabethhealy elizabethhealy commented Dec 9, 2024

Adds option to provide assertion verification keys and support for signing keys on assertion input
(supports rs256 and hs256 keys)
Includes bats tests for both key types

@elizabethhealy elizabethhealy marked this pull request as ready for review December 10, 2024 15:00
@elizabethhealy elizabethhealy requested a review from a team as a code owner December 10, 2024 15:00
Copy link
Contributor

@jentfoo jentfoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying the keys directly as arguments puts the key at more risk of exposure. Arguments will be recorded to disk in the command history, could be exposed on multi-tenant systems, logged, etc. This is particularly concerning since you appear to be supporting not just public keys, but private keys as well.

@elizabethhealy Would it be reasonable to accept a file path or use environment variables instead of specifying the keys as arguments?

pkg/handlers/tdf.go Outdated Show resolved Hide resolved
@jakedoublev
Copy link
Contributor

Specifying the keys directly as arguments puts the key at more risk of exposure. Arguments will be recorded to disk in the command history, could be exposed on multi-tenant systems, logged, etc. This is particularly concerning since you appear to be supporting not just public keys, but private keys as well.

@elizabethhealy Would it be reasonable to accept a file path or use environment variables instead of specifying the keys as arguments?

This suggestion from @jentfoo aligns with an open issue we have to generally improve CLI security: #417

@elizabethhealy
Copy link
Member Author

elizabethhealy commented Dec 10, 2024

@jentfoo @jakedoublev
using a file name as input instead makes sense, so in that case the format of the assertions provided would be [{"id":"assertion1","type":"handling","scope":"tdo","appliesToState":"encrypted","statement":{"format":"json+stanag5636","schema":"urn:nato:stanag:5636:A:1:elements:json","value":"{\"ocl\":\"2024-10-21T20:47:36Z\"}"},"signingKey":{"alg":"RS256","key":"my_private_rs256key.pem"}}] and just require that whats in the key field is a path to a file
or should we support an additional field within "signingKey" like "key_file" where a user would pass the pem?

@jakedoublev
Copy link
Contributor

@jentfoo @jakedoublev using a file name as input instead makes sense, so in that case the format of the assertions provided would be [{"id":"assertion1","type":"handling","scope":"tdo","appliesToState":"encrypted","statement":{"format":"json+stanag5636","schema":"urn:nato:stanag:5636:A:1:elements:json","value":"{\"ocl\":\"2024-10-21T20:47:36Z\"}"},"signingKey":{"alg":"RS256","key":"my_private_rs256key.pem"}}]

@elizabethhealy Could the entire assertion JSON be stored and read into the command from a file instead of just the keys referenced by the assertions? I'm thinking that would be aligned with what the CLI does for client credentials so --with-client-creds-file creds.json expects the entire {"clientId":"id","clientSecret":"client_secret"} stored in ./creds.json instead of --with-client-creds-file '{"clientId":"id","clientSecret":"secret_file.txt"}' where just the secret is present in ./secret_file.txt.

@elizabethhealy
Copy link
Member Author

elizabethhealy commented Dec 10, 2024

@jakedoublev i like that, so --with-assertions, --with-assertions-from-file, --with-assertion-verification-keys, --with-assertion-verificiation-keys-from-file and its up to the user to decide whichever is best for them, it will still support passing in keys directly but also give a safer option

@jakedoublev
Copy link
Contributor

@elizabethhealy and I discussed and we will update --with-assertions to parse either from JSON (backwards-compatible) or try to read from a file (more secure) before reporting an error if neither is successful. This new decrypt flag --with-assertion-verification-keys will only read the entire JSON (including in-lined PEMs) from a file and not support JSON in the flag value/argument.

docs/man/decrypt/_index.md Outdated Show resolved Hide resolved
docs/man/encrypt/_index.md Outdated Show resolved Hide resolved
pkg/handlers/tdf.go Outdated Show resolved Hide resolved
pkg/handlers/tdf.go Outdated Show resolved Hide resolved
return bytes, nil
}

func correctKeyType(assertionKey sdk.AssertionKey, public bool) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this functionality could be exposed within provided platform lib/SDK functionality instead of recreated within each Go PEP?

Copy link
Member Author

@elizabethhealy elizabethhealy Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like most go packages that deal with crypto just take in args that are already typed rsa.PrivateKey or rsa.PublicKey, they assume you already have the key and if not they expect you to load it yourself. i think the cli has a bit extra code since the whole assertion object is being passed in as a string which isnt how it would normally be done in a go pep. i assume the pep would just construct the assertion similar to https://github.com/opentdf/platform/blob/7d55a909ac03e5a1234709d9051f906d9efd469e/sdk/tdf_test.go#L400-L425 and would just load the key from pem; also the cli has extra conditions to handle private vs public where as i assume a pep would know if it was a private key or public key they were loading. so TLDR i think the cli is more of an outlier in how its passing in assertions and the extra steps needed to parse them and want to avoid adding specific logic to the sdk just for the cli.
but if its determined that other peps have this need as well we can re-assess

@@ -27,7 +27,7 @@ command:
default: /kas
- name: with-assertions
description: >
EXPERIMENTAL: JSON string of assertions to bind metadata to the TDF. See examples for more information.
EXPERIMENTAL: JSON string or path to JSON file of assertions to bind metadata to the TDF. See examples for more information.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only support the file method. A user may not be aware of the risks of specifying the key as a command argument.

We could consider adding argument support after #417 is implemented.

Copy link
Member Author

@elizabethhealy elizabethhealy Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think keeping the json string options was just to maintain backward compatability, we can add some more documentation here to emphasize that its deprecated and the file path is the more safe option

pkg/handlers/tdf.go Outdated Show resolved Hide resolved
pkg/utils/read.go Outdated Show resolved Hide resolved
@@ -57,6 +81,18 @@ teardown_file(){
./otdfctl decrypt --host $HOST --tls-no-verify $DEBUG_LEVEL $WITH_CREDS $OUTFILE_TXT | grep "$SECRET_TEXT"
}

@test "roundtrip TDF3, assertions with HS265 keys and verificaion, file" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test "roundtrip TDF3, assertions with HS265 keys and verificaion, file" {
@test "roundtrip TDF3, assertions with HS265 keys and verification, file" {

diff $INFILE_GO_MOD $RESULTFILE_GO_MOD
}

@test "roundtrip TDF3, assertions with RS256 keys and verificaion, file" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test "roundtrip TDF3, assertions with RS256 keys and verificaion, file" {
@test "roundtrip TDF3, assertions with RS256 keys and verification, file" {

}

@test "roundtrip TDF3, assertions with RS256 keys and verificaion, file" {
./otdfctl encrypt -o $OUTFILE_GO_MOD --host $HOST --tls-no-verify $DEBUG_LEVEL $WITH_CREDS -a $FQN --with-assertions $SIGNED_ASSERTIONS_RS256 --tdf-type tdf3 $INFILE_GO_MOD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are assertions present in the manifest? If so, can we add a test with ./otdfctl inspect that asserts they were found present in the TDF created?

}
}
for i, config := range assertionConfigs {
if (config.SigningKey != sdk.AssertionKey{}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this comparison struct equality evaluate as expected? It seems like you'd need to compare struct fields for this equality check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants