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

AN-614: Allowed security scheme must exist in config.json #1102

Merged
merged 8 commits into from
May 19, 2022

Conversation

acenolaza
Copy link
Contributor

AN-614: used zod.superRefine() in order to validate that the security scheme enabled under ois.apiSpecifications.security is defined in ois.apiSpecifications.components.

@acenolaza acenolaza added adapter About the @airnode/adapter package validator About the @airnode/validator package labels May 17, 2022
@acenolaza acenolaza requested a review from a team May 17, 2022 18:44
@acenolaza acenolaza self-assigned this May 17, 2022
@acenolaza acenolaza force-pushed the an614-security-scheme-validation branch from a7554cf to 7dc733c Compare May 17, 2022 19:18
Copy link
Contributor

@Siegrift Siegrift left a comment

Choose a reason for hiding this comment

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

👍 LGTM.

I think we should also verify that the the security scheme value is set via the apiCredentials https://docs.api3.org/airnode/v0.6/grp-providers/guides/build-an-airnode/api-security.html#step-3-specify-the-values-for-the-defined-security-schemes but we can do that as a separate issue? WDYT?

@acenolaza
Copy link
Contributor Author

+1 LGTM.

I think we should also verify that the the security scheme value is set via the apiCredentials https://docs.api3.org/airnode/v0.6/grp-providers/guides/build-an-airnode/api-security.html#step-3-specify-the-values-for-the-defined-security-schemes but we can do that as a separate issue? WDYT?

Right, I thought about doing that at first but then I realized that securityScheme is optional in apiCredentials but maybe I could still do a one-way check (if apiCredentials.securitySchemeName is defined then check if ois.apiSpecifications.components.securitySchemeName is also defined. WDYT?

@Siegrift
Copy link
Contributor

Siegrift commented May 18, 2022

Mhh, actually maybe we can bring this up at the call. I can imagine an user taking full OAS of their API, making a few changes to convert it to OIS and enable only a subset of triggers and security schemes. That suggests we should not do this check and allow "unused" security schemes. But for other users this will be an annoying error they'll need to debug 🤷 .

However, for enabled security schemes (via the security field) we need make sure that the value is defined in apiCredentials.

@acenolaza
Copy link
Contributor Author

Mhh, actually maybe we can bring this up at the call. I can imagine an user taking full OAS of their API, making a few changes to convert it to OIS and enable only a subset of triggers and security schemes. That suggests we should not do this check and allow "unused" security schemes. But for other users this will be an annoying error they'll need to debug shrug .

Yes, and this has been how I've been approaching "reference" validation in Airkeeper and Airkeeper. For those config files I'm only adding checks for things being referenced but unused things are not being validated for convenience since having those config values there don't really hurt and makes testing easier when switching between config values.

However, for enabled security schemes (via the security field) we need make sure that the value is defined in apiCredentials.

The thing is that we only care about apiCredentials.securitySchemeValue being set when securityScheme.type is apiKey or http 🤔

@Siegrift
Copy link
Contributor

The thing is that we only care about apiCredentials.securitySchemeValue being set when securityScheme.type is apiKey or http 🤔

No. I mean when you have a security scheme that is defined and also enabled. Such as this then we should verify the value is also supplied in apiCredentials (here). Essentially, making sure that user defined the step 3 from the docs.

@acenolaza
Copy link
Contributor Author

The thing is that we only care about apiCredentials.securitySchemeValue being set when securityScheme.type is apiKey or http thinking

No. I mean when you have a security scheme that is defined and also enabled. Such as this then we should verify the value is also supplied in apiCredentials (here). Essentially, making sure that user defined the step 3 from the docs.

But what if the Airnode is only relaying metadata using securitySchemes? https://docs.api3.org/airnode/v0.4/grp-providers/guides/build-an-airnode/api-security.html#relayed-meta-data-security-schemes

@Siegrift
Copy link
Contributor

Oh, I see what you mean now. Yes, we only care about those two. But if they are defined and used, there should be a value defined for them in apiCredentials

@acenolaza acenolaza force-pushed the an614-security-scheme-validation branch from 78e2ef4 to fcaa29e Compare May 18, 2022 20:47
@acenolaza acenolaza requested a review from Siegrift May 18, 2022 20:48
packages/airnode-validator/src/config/config.test.ts Outdated Show resolved Hide resolved
packages/airnode-validator/src/config/config.test.ts Outdated Show resolved Hide resolved
packages/airnode-validator/src/config/config.test.ts Outdated Show resolved Hide resolved
packages/airnode-validator/src/config/config.test.ts Outdated Show resolved Hide resolved
packages/airnode-validator/src/config/config.ts Outdated Show resolved Hide resolved
packages/airnode-validator/src/config/config.ts Outdated Show resolved Hide resolved
@acenolaza acenolaza requested a review from Siegrift May 19, 2022 13:30
@acenolaza
Copy link
Contributor Author

Thanks for the thorough and detailed code review @Siegrift 🙏🏻

@acenolaza acenolaza requested a review from Siegrift May 19, 2022 13:50
@acenolaza acenolaza force-pushed the an614-security-scheme-validation branch from fd2f848 to e236447 Compare May 19, 2022 14:11
@acenolaza acenolaza force-pushed the an614-security-scheme-validation branch from e236447 to decc200 Compare May 19, 2022 16:59
Copy link
Contributor

@Siegrift Siegrift left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@acenolaza acenolaza merged commit 7c20bf6 into master May 19, 2022
@acenolaza acenolaza deleted the an614-security-scheme-validation branch May 19, 2022 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapter About the @airnode/adapter package validator About the @airnode/validator package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants