-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Removes deprecated platform security v1 routes #203915
Open
jeramysoucy
wants to merge
4
commits into
elastic:main
Choose a base branch
from
jeramysoucy:remove-deprecated-v1-apis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−417
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6252d20
Removes deprecated v1 routes
jeramysoucy 91bb224
Merge branch 'main' into remove-deprecated-v1-apis
jeramysoucy 825dedc
Merge branch 'main' into remove-deprecated-v1-apis
jeramysoucy 973b4bf
Replaces v1 saml endpoint in saml provider acs and tests
jeramysoucy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
import type { TypeOf } from '@kbn/config-schema'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { parseNextURL } from '@kbn/std'; | ||
|
||
import type { RouteDefinitionParams } from '..'; | ||
|
@@ -36,124 +35,67 @@ export function defineCommonRoutes({ | |
buildFlavor, | ||
docLinks, | ||
}: RouteDefinitionParams) { | ||
// Generate two identical routes with new and deprecated URL and issue a warning if route with deprecated URL is ever used. | ||
// For a serverless build, do not register deprecated versioned routes | ||
for (const path of [ | ||
'/api/security/logout', | ||
...(buildFlavor !== 'serverless' ? ['/api/security/v1/logout'] : []), | ||
]) { | ||
const isDeprecated = path === '/api/security/v1/logout'; | ||
router.get( | ||
{ | ||
path, | ||
security: { | ||
authz: { | ||
enabled: false, | ||
reason: 'This route must remain accessible to 3rd-party IdPs', | ||
}, | ||
}, | ||
// Allow unknown query parameters as this endpoint can be hit by the 3rd-party with any | ||
// set of query string parameters (e.g. SAML/OIDC logout request/response parameters). | ||
validate: { query: schema.object({}, { unknowns: 'allow' }) }, | ||
options: { | ||
access: 'public', | ||
excludeFromOAS: true, | ||
authRequired: false, | ||
tags: [ROUTE_TAG_CAN_REDIRECT, ROUTE_TAG_AUTH_FLOW], | ||
...(isDeprecated && { | ||
deprecated: { | ||
documentationUrl: docLinks.links.security.deprecatedV1Endpoints, | ||
severity: 'warning', | ||
message: i18n.translate('xpack.security.deprecations.logoutRouteMessage', { | ||
defaultMessage: | ||
'The "{path}" URL is deprecated and will be removed in the next major version. Use "/api/security/logout" instead.', | ||
values: { path }, | ||
}), | ||
reason: { | ||
type: 'migrate', | ||
newApiMethod: 'GET', | ||
newApiPath: '/api/security/logout', | ||
}, | ||
}, | ||
}), | ||
router.get( | ||
{ | ||
path: '/api/security/logout', | ||
security: { | ||
authz: { | ||
enabled: false, | ||
reason: 'This route must remain accessible to 3rd-party IdPs', | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
const serverBasePath = basePath.serverBasePath; | ||
if (isDeprecated) { | ||
logger.warn( | ||
`The "${serverBasePath}${path}" URL is deprecated and will stop working in the next major version. Use "${serverBasePath}/api/security/logout" URL instead.`, | ||
{ tags: ['deprecation'] } | ||
); | ||
} | ||
// Allow unknown query parameters as this endpoint can be hit by the 3rd-party with any | ||
// set of query string parameters (e.g. SAML/OIDC logout request/response parameters). | ||
validate: { query: schema.object({}, { unknowns: 'allow' }) }, | ||
options: { | ||
access: 'public', | ||
excludeFromOAS: true, | ||
authRequired: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: while you're here, would you mind replacing deprecated |
||
tags: [ROUTE_TAG_CAN_REDIRECT, ROUTE_TAG_AUTH_FLOW], | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
const serverBasePath = basePath.serverBasePath; | ||
if (!canRedirectRequest(request)) { | ||
return response.badRequest({ | ||
body: 'Client should be able to process redirect response.', | ||
}); | ||
} | ||
|
||
if (!canRedirectRequest(request)) { | ||
return response.badRequest({ | ||
body: 'Client should be able to process redirect response.', | ||
}); | ||
try { | ||
const deauthenticationResult = await getAuthenticationService().logout(request); | ||
if (deauthenticationResult.failed()) { | ||
return response.customError(wrapIntoCustomErrorResponse(deauthenticationResult.error)); | ||
} | ||
|
||
try { | ||
const deauthenticationResult = await getAuthenticationService().logout(request); | ||
if (deauthenticationResult.failed()) { | ||
return response.customError(wrapIntoCustomErrorResponse(deauthenticationResult.error)); | ||
} | ||
|
||
return response.redirected({ | ||
headers: { location: deauthenticationResult.redirectURL || `${serverBasePath}/` }, | ||
}); | ||
} catch (error) { | ||
return response.customError(wrapIntoCustomErrorResponse(error)); | ||
} | ||
return response.redirected({ | ||
headers: { location: deauthenticationResult.redirectURL || `${serverBasePath}/` }, | ||
}); | ||
} catch (error) { | ||
return response.customError(wrapIntoCustomErrorResponse(error)); | ||
} | ||
); | ||
} | ||
} | ||
); | ||
|
||
// Generate two identical routes with new and deprecated URL and issue a warning if route with deprecated URL is ever used. | ||
// For a serverless build, do not register deprecated versioned routes | ||
for (const path of [ | ||
'/internal/security/me', | ||
...(buildFlavor !== 'serverless' ? ['/api/security/v1/me'] : []), | ||
]) { | ||
const isDeprecated = path === '/api/security/v1/me'; | ||
router.get( | ||
{ | ||
path, | ||
security: { | ||
authz: { | ||
enabled: false, | ||
reason: `This route delegates authorization to Core's security service; there must be an authenticated user for this route to return information`, | ||
}, | ||
}, | ||
validate: false, | ||
options: { | ||
access: isDeprecated ? 'public' : 'internal', | ||
...(isDeprecated && { | ||
deprecated: { | ||
documentationUrl: docLinks.links.security.deprecatedV1Endpoints, | ||
severity: 'warning', | ||
message: i18n.translate('xpack.security.deprecations.meRouteMessage', { | ||
defaultMessage: | ||
'The "{path}" endpoint is deprecated and will be removed in the next major version.', | ||
values: { path }, | ||
}), | ||
reason: { type: 'remove' }, | ||
}, | ||
}), | ||
router.get( | ||
{ | ||
path: '/internal/security/me', | ||
security: { | ||
authz: { | ||
enabled: false, | ||
reason: `This route delegates authorization to Core's security service; there must be an authenticated user for this route to return information`, | ||
}, | ||
}, | ||
createLicensedRouteHandler(async (context, request, response) => { | ||
if (isDeprecated) { | ||
logger.warn( | ||
`The "${basePath.serverBasePath}${path}" endpoint is deprecated and will be removed in the next major version.`, | ||
{ tags: ['deprecation'] } | ||
); | ||
} | ||
const { security: coreSecurity } = await context.core; | ||
return response.ok({ body: coreSecurity.authc.getCurrentUser()! }); | ||
}) | ||
); | ||
} | ||
validate: false, | ||
options: { | ||
access: 'internal', | ||
}, | ||
}, | ||
createLicensedRouteHandler(async (context, request, response) => { | ||
const { security: coreSecurity } = await context.core; | ||
return response.ok({ body: coreSecurity.authc.getCurrentUser()! }); | ||
}) | ||
); | ||
|
||
const basicParamsSchema = schema.object({ | ||
username: schema.string({ minLength: 1 }), | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.