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

feature[v2]: enabling authentication for metric api scaler #1137

Merged
merged 5 commits into from
Oct 9, 2020

Conversation

aman-bansal
Copy link
Contributor

@aman-bansal aman-bansal commented Sep 10, 2020

Signed-off-by: aman-bansal bansalaman2905@gmail.com

This PR is to add authentication for metric_api_scaler. Three methods have been added. They will be identified on the basis of authMode parameter.

  1. API Key Based auth: auth mode would apiKeyAuth. API key needs to be provided. Default behaviour would be to send it in headers. This can be changed via method and header/query param keys can be changed via keyParamName.

  2. Basic Auth: auth mode would basicAuth. Username is compulsory. Password isn't. This is based on experience over basic auth. Some people just put api key as the username to ease out authentication at their end.

  3. Client Certification: auth mode would tlsAuth. cert, cacert and key needs to be provided.

Checklist

  • Commits are signed with Developer Certificate of Origin (DCO)
  • Tests have been added
  • A PR is opened to update the documentation on https://github.com/kedacore/keda-docs
  • Changelog has been updated

Relates to #1082 #1083 #1084

[Edit]
Docs PR attached kedacore/keda-docs#260

@aman-bansal aman-bansal marked this pull request as draft September 10, 2020 11:45
@aman-bansal aman-bansal marked this pull request as ready for review September 10, 2020 12:26
@aman-bansal
Copy link
Contributor Author

@tomkerkhove please review this PR and do suggest if I missed something. This will enable metric api scaler to authentication via api key, basic auth, and client certificates. In the meantime, I am working on docs.

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

Thanks, minor nits

pkg/scalers/tls_config.go Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@turbaszek
Copy link
Contributor

@aman-bansal have you tested it locally? If not, I can help over the weekend or you may find this useful: turbaszek/keda-example#1 (sorry for no docs)

@zroubalik
Copy link
Member

@aman-bansal have you tested it locally? If not, I can help over the weekend or you may find this useful: turbaszek/keda-example#1 (sorry for no docs)

We should have e2e test for this scaler probably

@aman-bansal
Copy link
Contributor Author

@aman-bansal have you tested it locally? If not, I can help over the weekend or you may find this useful: turbaszek/keda-example#1 (sorry for no docs)

This is great! I was actually looking for ways to test this. I'll try to create one sample for each authorization. If there is any doubt I will raise in this thread itself.

@aman-bansal
Copy link
Contributor Author

@aman-bansal have you tested it locally? If not, I can help over the weekend or you may find this useful: turbaszek/keda-example#1 (sorry for no docs)

We should have e2e test for this scaler probably

This will be tricky. We have to add one sample app which can provide support for each authorization method. Will need a bit help in this case.

@turbaszek
Copy link
Contributor

We should have e2e test for this scaler probably

@zroubalik I agree that e2e would be awesome. Do we have any documentation on how we approach such testing?

This will be tricky. We have to add one sample app which can provide support for each authorization method. Will need a bit help in this case.

I would say that one app with 4 endpoints, each with different auth methods should serve the purpose. And I'm happy to help with doing this :)

@zroubalik
Copy link
Member

zroubalik commented Sep 10, 2020

We should have e2e test for this scaler probably

@zroubalik I agree that e2e would be awesome. Do we have any documentation on how we approach such testing?

This will be tricky. We have to add one sample app which can provide support for each authorization method. Will need a bit help in this case.

I would say that one app with 4 endpoints, each with different auth methods should serve the purpose. And I'm happy to help with doing this :)

Thanks! Great, it can definititely be a separate PR :)

@aman-bansal
Copy link
Contributor Author

Took time but finally, build HTTP authentication example, I will add the documentation in some time. But do check if you get the time. https://github.com/aman-bansal/keda-http-auth-example

Comment on lines 58 to 60
apiKeyAuth authenticationType = "apiKeyAuth"
basicAuth = "basicAuth"
tlsAuth = "tlsAuth"
Copy link
Contributor

@turbaszek turbaszek Sep 13, 2020

Choose a reason for hiding this comment

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

I'm not 100% but I think we should add authenticationType to two other methods, otherwise go will resolve the type from assigned value as string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh didn't know that automatic type assignment works for zero indexed type declaration i.e. with iota. In testing, this didn't get caught because of its string representation.

Copy link
Contributor

@turbaszek turbaszek left a comment

Choose a reason for hiding this comment

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

Few nits but otherwise it looks good to me! 👏

@aman-bansal
Copy link
Contributor Author

Few nits but otherwise it looks good to me! 👏

Thank you so much @turbaszek. Great learning. Will be more careful with future PRs. :)

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM([]byte(caCert))
config.RootCAs = caCertPool
config.InsecureSkipVerify = true
Copy link
Contributor

Choose a reason for hiding this comment

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

According to code scanning

InsecureSkipVerify should not be used in production code.

@tomkerkhove how should we address this feedback?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we need to skip verification if we're setting the RootCAs on the config. I haven't tried it, but I'd think it shouldn't be needed. Maybe we just need to append the system ca certs first

caCertPool, err := x509.SystemCertPool()
if err != nil {
    ....
}
caCertPool.AppendCertsFromPEM([]byte(caCert))
...

source

Copy link
Contributor

Choose a reason for hiding this comment

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

@aman-bansal what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, I am back finally.
So I believe we shouldn't use this because keda when running in the production systems this could lead to issues. But should we make this configurable?

Secondly, I believe the system ca cert is not required for this. We need system ca cert only if using self-signed cert. I believe we should let the clients specify if they need this via configuration. Because some clients might need this.

Copy link
Member

Choose a reason for hiding this comment

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

@aman-bansal I agree

@turbaszek
Copy link
Contributor

@tomkerkhove @zroubalik is there any blocker to merging this PR other than rebasing it?

@tomkerkhove
Copy link
Member

I'll leave it up to @ahmelsayed @zroubalik for reviewing this

@aman-bansal
Copy link
Contributor Author

@ahmelsayed @zroubalik can we have a final review over this. I am back in 100% capacity and would love to complete this so that I can pick something next :).

@zroubalik
Copy link
Member

@aman-bansal could you please rebase this PR, there's a conflict. I think that we are good to go with the merge and then we can address the config.InsecureSkipVerify = true problem in a separate issue.

Signed-off-by: aman-bansal <bansalaman2905@gmail.com>
Signed-off-by: aman-bansal <bansalaman2905@gmail.com>
Signed-off-by: aman-bansal <bansalaman2905@gmail.com>
Signed-off-by: aman-bansal <bansalaman2905@gmail.com>
@aman-bansal aman-bansal force-pushed the metric_scaler_auth branch 2 times, most recently from 9cf397d to 06d18f1 Compare October 8, 2020 15:22
Signed-off-by: aman-bansal <bansalaman2905@gmail.com>
@aman-bansal
Copy link
Contributor Author

@zroubalik @ahmelsayed Merge conflicts have been resolved.

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

LGTM thanks @aman-bansal !

@zroubalik zroubalik merged commit b2abfaf into kedacore:v2 Oct 9, 2020
silenceper pushed a commit to silenceper/keda that referenced this pull request Oct 10, 2020
Signed-off-by: aman-bansal <bansalaman2905@gmail.com>
SpiritZhou pushed a commit to SpiritZhou/keda that referenced this pull request Jul 18, 2023
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
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.

5 participants