Skip to content

Commit

Permalink
Using the server's basePath when building the SAML ACS (#51391)
Browse files Browse the repository at this point in the history
* Using the server's basePath when building the SAML ACS

* Fixing getACS call
  • Loading branch information
kobelb committed Nov 25, 2019
1 parent d2b7f96 commit 74fd765
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,11 @@ describe('SAMLAuthenticationProvider', () => {
sinon.assert.calledWithExactly(
mockOptions.client.callAsInternalUser,
'shield.samlPrepare',
{ body: { acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml' } }
{
body: {
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);

expect(mockOptions.logger.warn).not.toHaveBeenCalled();
Expand Down Expand Up @@ -572,7 +576,11 @@ describe('SAMLAuthenticationProvider', () => {
sinon.assert.calledWithExactly(
mockOptions.client.callAsInternalUser,
'shield.samlPrepare',
{ body: { acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml' } }
{
body: {
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);

expect(mockOptions.logger.warn).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -610,7 +618,11 @@ describe('SAMLAuthenticationProvider', () => {
sinon.assert.calledWithExactly(
mockOptions.client.callAsInternalUser,
'shield.samlPrepare',
{ body: { acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml' } }
{
body: {
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);

expect(mockOptions.logger.warn).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -686,7 +698,11 @@ describe('SAMLAuthenticationProvider', () => {
sinon.assert.calledWithExactly(
mockOptions.client.callAsInternalUser,
'shield.samlPrepare',
{ body: { acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml' } }
{
body: {
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);

expect(authenticationResult.failed()).toBe(true);
Expand Down Expand Up @@ -752,7 +768,9 @@ describe('SAMLAuthenticationProvider', () => {
const authenticationResult = await provider.authenticate(request);

sinon.assert.calledWithExactly(mockOptions.client.callAsInternalUser, 'shield.samlPrepare', {
body: { acs: `test-protocol://test-hostname:1234/base-path/api/security/v1/saml` },
body: {
acs: `test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml`,
},
});

expect(authenticationResult.redirected()).toBe(true);
Expand All @@ -773,7 +791,9 @@ describe('SAMLAuthenticationProvider', () => {
const authenticationResult = await provider.authenticate(request, null);

sinon.assert.calledWithExactly(mockOptions.client.callAsInternalUser, 'shield.samlPrepare', {
body: { acs: `test-protocol://test-hostname:1234/base-path/api/security/v1/saml` },
body: {
acs: `test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml`,
},
});

expect(authenticationResult.failed()).toBe(true);
Expand Down Expand Up @@ -983,7 +1003,9 @@ describe('SAMLAuthenticationProvider', () => {
const authenticationResult = await provider.authenticate(request, state);

sinon.assert.calledWithExactly(mockOptions.client.callAsInternalUser, 'shield.samlPrepare', {
body: { acs: `test-protocol://test-hostname:1234/base-path/api/security/v1/saml` },
body: {
acs: `test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml`,
},
});

expect(mockOptions.logger.warn).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -1053,7 +1075,9 @@ describe('SAMLAuthenticationProvider', () => {
const authenticationResult = await provider.authenticate(request, state);

sinon.assert.calledWithExactly(mockOptions.client.callAsInternalUser, 'shield.samlPrepare', {
body: { acs: `test-protocol://test-hostname:1234/base-path/api/security/v1/saml` },
body: {
acs: `test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml`,
},
});

expect(mockOptions.logger.warn).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -1184,7 +1208,7 @@ describe('SAMLAuthenticationProvider', () => {
{
body: {
queryString: 'SAMLRequest=xxx%20yyy',
acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml',
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);
Expand Down Expand Up @@ -1287,7 +1311,7 @@ describe('SAMLAuthenticationProvider', () => {
{
body: {
queryString: 'SAMLRequest=xxx%20yyy',
acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml',
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);
Expand All @@ -1312,7 +1336,7 @@ describe('SAMLAuthenticationProvider', () => {
{
body: {
queryString: 'SAMLRequest=xxx%20yyy',
acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml',
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);
Expand Down Expand Up @@ -1364,7 +1388,7 @@ describe('SAMLAuthenticationProvider', () => {
{
body: {
queryString: 'SAMLRequest=xxx%20yyy',
acs: 'test-protocol://test-hostname:1234/base-path/api/security/v1/saml',
acs: 'test-protocol://test-hostname:1234/mock-server-basepath/api/security/v1/saml',
},
}
);
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/security/server/authentication/providers/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider {

try {
// Prefer realm name if it's specified, otherwise fallback to ACS.
const preparePayload = this.realm ? { realm: this.realm } : { acs: this.getACS(request) };
const preparePayload = this.realm ? { realm: this.realm } : { acs: this.getACS() };

// This operation should be performed on behalf of the user with a privilege that normal
// user usually doesn't have `cluster:admin/xpack/security/saml/prepare`.
Expand Down Expand Up @@ -572,7 +572,7 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider {
this.logger.debug('Single logout has been initiated by the Identity Provider.');

// Prefer realm name if it's specified, otherwise fallback to ACS.
const invalidatePayload = this.realm ? { realm: this.realm } : { acs: this.getACS(request) };
const invalidatePayload = this.realm ? { realm: this.realm } : { acs: this.getACS() };

// This operation should be performed on behalf of the user with a privilege that normal
// user usually doesn't have `cluster:admin/xpack/security/saml/invalidate`.
Expand All @@ -592,10 +592,10 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider {
/**
* Constructs and returns Kibana's Assertion consumer service URL.
*/
private getACS(request: KibanaRequest) {
return `${this.options.getServerBaseURL()}${this.options.basePath.get(
request
)}/api/security/v1/saml`;
private getACS() {
return `${this.options.getServerBaseURL()}${
this.options.basePath.serverBasePath
}/api/security/v1/saml`;
}

/**
Expand Down

0 comments on commit 74fd765

Please sign in to comment.