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

[7.5] Using the server's basePath when building the SAML ACS (#51391) #51638

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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