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

Standardize crypto errors #7558

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

chaitanyab2311
Copy link

@chaitanyab2311 chaitanyab2311 commented Feb 23, 2024

Description

Enriched errors in cryptography API. This is still a draft as unit tests need to be updated and integration tests need to be added

Issue reference

Please reference the issue this PR will close: #7491

Checklist

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing

@chaitanyab2311 chaitanyab2311 requested review from a team as code owners February 23, 2024 03:42
@chaitanyab2311 chaitanyab2311 marked this pull request as draft February 23, 2024 03:42
@chaitanyab2311
Copy link
Author

@cicoyle I am getting some errors related to MockActors in http_test while running tests locally. Am i missing something

pkg/api/errors/cryptography.go Outdated Show resolved Hide resolved
pkg/api/errors/cryptography.go Outdated Show resolved Hide resolved
pkg/api/errors/cryptography.go Outdated Show resolved Hide resolved
pkg/api/errors/cryptography.go Outdated Show resolved Hide resolved
pkg/api/errors/cryptography.go Outdated Show resolved Hide resolved
@ItalyPaleAle
Copy link
Contributor

Please note that with crypto operations, errors are sensitive as they can disclose information to users that can be used for attacks (side channel).

Please make sure errors from the crypto components are never returned to callers. They are ok to log, but not returned in the API response - return a generic "failed to perform operation" error instead.

@cicoyle
Copy link
Contributor

cicoyle commented Feb 23, 2024

@cicoyle I am getting some errors related to MockActors in http_test while running tests locally. Am i missing something

I believe you might need the tags in your Go Tool Args. When you run the tests in Dapr you will likely need to add these tags: -tags=stablecomponents,unit

Here is a screenshot of my Goland IDE config I use.
image

Once you get to the integration tests too, you will need a tag: go test -v -race -tags integration ./tests/integration -focus errors, where errors might change pending what you'd like to 'focus' on

Build()
}

func CryptoNotFound(name string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here. There is a generic NotFound you can use here: https://github.com/dapr/dapr/blob/master/pkg/api/errors/errors.go#L11

Build()
}

func CryptoProviderGetKey(name string, err string) error {
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
func CryptoProviderGetKey(name string, err string) error {
func CryptoProviderGetKey(name string, msg string) error {

Then you can get rid of the message := err line below :)

Or if the intent was to use the string version of the initial error, then it should be of type error when passed in

@cicoyle
Copy link
Contributor

cicoyle commented Feb 23, 2024

This is off to a great start! 🎉

If the tags don't fix your MockActors issues, then please comment and add the error you are seeing.

Also, when you commit, if you do git commit -s then the DCO step in CI will pass.

Chaitanya Bhangale added 2 commits February 23, 2024 15:44
Signed-off-by: Chaitanya Bhangale <chaitanyabhangale@Chaitanyas-MacBook-Pro-2.local>
Signed-off-by: Chaitanya Bhangale <chaitanyabhangale@Chaitanyas-MacBook-Pro-2.local>
Comment on lines 166 to 167
err = fmt.Errorf("failed to encrypt")
err = apierrors.CryptoProviderEncryptOperation(in.ComponentName, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: use errors.New if there's no format (like, no %s), which is faster (same below)

Suggested change
err = fmt.Errorf("failed to encrypt")
err = apierrors.CryptoProviderEncryptOperation(in.ComponentName, err)
err = apierrors.CryptoProviderEncryptOperation(in.ComponentName, errors.New("failed to encrypt"))

Comment on lines 199 to 200
err = fmt.Errorf("failed to decrypt")
err = apierrors.CryptoProviderDecryptOperation(in.ComponentName, err)
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
err = fmt.Errorf("failed to decrypt")
err = apierrors.CryptoProviderDecryptOperation(in.ComponentName, err)
err = apierrors.CryptoProviderDecryptOperation(in.ComponentName, errors.New("failed to decrypt"))

Comment on lines 242 to 243
err = fmt.Errorf("failed to wrap key")
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, err)
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
err = fmt.Errorf("failed to wrap key")
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, err)
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, errors.New("failed to wrap key"))

Comment on lines 275 to 276
err = fmt.Errorf("failed to unwrap key")
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, err)
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
err = fmt.Errorf("failed to unwrap key")
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, err)
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, errors.New("failed to unwrap key"))

Comment on lines 317 to 318
err = fmt.Errorf("failed to sign")
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, err)
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
err = fmt.Errorf("failed to sign")
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, err)
err = apierrors.CryptoProviderKeyOperation(in.ComponentName, errors.New("failed to sign"))

Comment on lines 349 to 350
err = fmt.Errorf("failed to verify signature: ")
err = apierrors.CryptoProviderVerifySignatureOperation(in.ComponentName, err)
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
err = fmt.Errorf("failed to verify signature: ")
err = apierrors.CryptoProviderVerifySignatureOperation(in.ComponentName, err)
err = apierrors.CryptoProviderVerifySignatureOperation(in.ComponentName, errors.New("failed to verify signature"))

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nit, I'd name this "crypto.go" since that's how all other files are named

@dapr-bot
Copy link
Collaborator

This pull request has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@dapr-bot dapr-bot added the stale Issues and PRs without response label Apr 24, 2024
@dapr-bot
Copy link
Collaborator

dapr-bot commented May 1, 2024

This pull request has been automatically closed because it has not had activity in the last 67 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@dapr-bot dapr-bot closed this May 1, 2024
@yaron2 yaron2 reopened this May 1, 2024
@yaron2
Copy link
Member

yaron2 commented May 1, 2024

@chaitanyab2311 are you planning to take this PR out of draft?

@dapr-bot dapr-bot removed the stale Issues and PRs without response label May 1, 2024
@chaitanyab2311 chaitanyab2311 marked this pull request as ready for review May 1, 2024 21:09
@daixiang0
Copy link
Member

ping @chaitanyab2311

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.

Error Standardization: Cryptography API
6 participants