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

fix(authn/basic): Enable basic auth in gate #675

Merged
merged 18 commits into from
Jan 7, 2019

Conversation

german-muzquiz
Copy link
Contributor

@german-muzquiz german-muzquiz commented Nov 29, 2018

This PR is for being able to use plain basic authentication in gate.
Example gate-local.yml:

security:
  basicform:
    enabled: true
  user:
    name: {some username}
    password: {some password}

@spinnakerbot
Copy link
Contributor

We prefer that non-test backend code be written in Java or Kotlin, rather than Groovy. The following files have been added and written in Groovy:

  • gate-basic/src/main/groovy/com/netflix/spinnaker/gate/security/basic/BasicSsoConfig.groovy

See our server-side commit conventions here.

@spinnakerbot
Copy link
Contributor

The following commits need their title changed:

469f8ea: Enable basic auth

Please format your commit title into the form:

<type>(<scope>): <subject>, e.g. fix(kubernetes): address NPE in status check

This allows us to easily generate changelogs & determine semantic version numbers when cutting releases. You can read more about commit conventions here.

@ethanfrogers
Copy link
Contributor

cc @ttomsu

@EnableWebSecurity
@SuppportsMultiAuth
@Order(Ordered.LOWEST_PRECEDENCE)
class BasicSsoConfig extends WebSecurityConfigurerAdapter {
Copy link
Member

Choose a reason for hiding this comment

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

Rm "Sso" - nothing SSO about HTTP Basic auth.

@Configuration
@SpinnakerAuthConfig
@EnableWebSecurity
@SuppportsMultiAuth
Copy link
Member

Choose a reason for hiding this comment

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

I think you'll want to remove this - it's for use with X509, and I think the standalone X509 one should already hook into the Basic config done in AuthConfig


@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin()
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. This is more than just HTTP Basic auth - it's actually just simple in memory auth that happens to (maybe) also enable HTTP Basic.

Given that, I think you'll want to rename the module and classes to something like "Simple" or "NonProd". Thoughts on naming @stewchen @dibyom ?

protected void configure(HttpSecurity http) throws Exception {
http.formLogin()
authConfig.configure(http)
additionalAuthProviders?.each {
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned above, I don't think you want to mix this auth mechanism with other ones, so you should probably remove this

@ttomsu
Copy link
Member

ttomsu commented Nov 30, 2018

@lwander FYI

@german-muzquiz
Copy link
Contributor Author

@ttomsu I removed multi-auth for this module if it's not needed to coexist with X509. Yeah, basically this is an "in-memory" authentication, so let me know what name would be better suited.

Copy link
Member

@dibyom dibyom left a comment

Choose a reason for hiding this comment

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

I like BasicAuth or maybe "Simple" for the name

@@ -1,2 +1,2 @@
org.gradle.parallel=true
includeProviders=iap,ldap,oauth2,saml,x509
includeProviders=iap,ldap,oauth2,saml,x509,basic
Copy link
Member

Choose a reason for hiding this comment

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

Very minor nit...arrange in alphabetical order

settings.gradle Outdated
@@ -23,7 +23,8 @@ include "gate-core",
"gate-proxy",
"gate-saml",
"gate-web",
"gate-x509"
"gate-x509",
"gate-basic"
Copy link
Member

Choose a reason for hiding this comment

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

Very minor nit...arrange in alphabetical order

@german-muzquiz
Copy link
Contributor Author

@ttomsu all feedback has been implemented unless there's a better name than "BasicAuth" for this functionality. Do you think this PR is ready to merge?

@ttomsu
Copy link
Member

ttomsu commented Dec 12, 2018

Could you add a @GateSystemTest like https://github.com/spinnaker/gate/blob/master/gate-web/src/test/groovy/com/netflix/spinnaker/gate/security/ldap/LdapAuthSpec.groovy to prove it's working as you'd expect?

@german-muzquiz
Copy link
Contributor Author

Tests were added and looks that everything is ok.

Copy link
Member

@robzienert robzienert left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Some small stuff to address.

@@ -0,0 +1,60 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Please refrain from introducing new Groovy files in the main source set, as the spinnakerbot called out.

String password = authentication.getCredentials()?.toString()

if (securityProperties.user == null) {
throw new AuthenticationServiceException("User credentials are not configured for the service")
Copy link
Member

Choose a reason for hiding this comment

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

I'd remove for the service, as it's redundant.

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, this looks like a configuration error that should be caught on startup, rather than asserted every authenticate invocation. I'd move this check into the constructor and force gate to fail on start up.

AuthConfig authConfig

@Autowired
BasicAuthProvider authProvider
Copy link
Member

Choose a reason for hiding this comment

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

Also, we're trying to steer people away from autowired properties in favor of autowired constructors.

@@ -43,6 +43,7 @@ dependencies {
compileOnly spinnaker.dependency("lombok")

testCompile project(":gate-ldap") // TODO: Move system tests to own module
testCompile project(":gate-basic")
Copy link
Member

Choose a reason for hiding this comment

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

I think you'll want this to be compile project(":gate-basic"), otherwise the functionality won't be included in the compiled jar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For that case, all gate auth modules are already included as runtime dependencies, and the list of those is built from gradle.properties: https://github.com/spinnaker/gate/pull/675/files/36ed77203133a36a5a25e83b77e67965138db711#diff-503f218d646c10f484fdc9d6315bf2e3R2
These test dependencies are only there because of some tests written against ldap and basic implementations.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right on thanks!

Copy link
Member

@robzienert robzienert left a comment

Choose a reason for hiding this comment

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

lgtm. another one-over @ttomsu ?

Copy link
Member

@ttomsu ttomsu left a comment

Choose a reason for hiding this comment

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

One more thing: have you tested this out with another auth provider enabled, such as Oauth? I know we use security.basic.enabled to allow the monitoring daemon access to Gate in a kubernetes environment.

@german-muzquiz
Copy link
Contributor Author

@ttomsu I see, I did a test with oauth2 enabled and basic security is taking precedence, because security.basic.enabled is already set to true by some other mechanism.
Given that we have full control over this property name to enable/disable basic auth, I did a test changing it to some other name and oauth2 worked, so instead of security.basic.enabled we could use something like security.basicform.enabled.
What do you think?

@german-muzquiz
Copy link
Contributor Author

@ttomsu @robzienert I went ahead and changed the activation property name for this feature to security.basicform.enabled to not collide with other auth configurations. Also made sure that it works properly with security.basic enabled/disabled.

@ethanfrogers
Copy link
Contributor

I'm going to go ahead and merge this since it's been doubly approved.

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