-
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
Shutdown Kibana on usages of PKCS12 truststore/keystore config #192627
Changes from 4 commits
04e960f
1246d98
aeb94dd
dbbbb34
92aeabf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,28 +9,70 @@ | |
|
||
import type { Logger } from '@kbn/logging'; | ||
import { getFips } from 'crypto'; | ||
import { SecurityServiceConfigType } from '../utils'; | ||
import { PKCS12ConfigType, SecurityServiceConfigType } from '../utils'; | ||
|
||
export function isFipsEnabled(config: SecurityServiceConfigType): boolean { | ||
return config?.experimental?.fipsMode?.enabled ?? false; | ||
} | ||
|
||
export function checkFipsConfig(config: SecurityServiceConfigType, logger: Logger) { | ||
export function checkFipsConfig( | ||
config: SecurityServiceConfigType, | ||
elasticsearchConfig: PKCS12ConfigType, | ||
serverConfig: PKCS12ConfigType, | ||
logger: Logger | ||
) { | ||
const isFipsConfigEnabled = isFipsEnabled(config); | ||
const isNodeRunningWithFipsEnabled = getFips() === 1; | ||
|
||
// Check if FIPS is enabled in either setting | ||
if (isFipsConfigEnabled || isNodeRunningWithFipsEnabled) { | ||
// FIPS must be enabled on both or log and error an exit Kibana | ||
const definedPKCS12ConfigOptions = findDefinedPKCS12ConfigOptions( | ||
elasticsearchConfig, | ||
serverConfig | ||
); | ||
// FIPS must be enabled on both, or, log/error an exit Kibana | ||
if (isFipsConfigEnabled !== isNodeRunningWithFipsEnabled) { | ||
logger.error( | ||
`Configuration mismatch error. xpack.security.experimental.fipsMode.enabled is set to ${isFipsConfigEnabled} and the configured Node.js environment has FIPS ${ | ||
isNodeRunningWithFipsEnabled ? 'enabled' : 'disabled' | ||
}` | ||
); | ||
|
||
process.exit(78); | ||
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. Nit: I know Happy to stick with the current approach, my primary thought was just to give Core the chance to run the shutdown lifecycle and might make testing a little bit easier 🤷🏻 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. I like the 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. ++ added in latest commit - thank you for the guidance!!! It is way cleaner 🚀 |
||
} else if (definedPKCS12ConfigOptions.length > 0) { | ||
definedPKCS12ConfigOptions.forEach((option) => { | ||
logger.error( | ||
`Configuration mismatch error: ${option} is set, PKCS12 configurations are not allowed while running in FIPS mode.` | ||
); | ||
}); | ||
|
||
process.exit(78); | ||
} else { | ||
logger.info('Kibana is running in FIPS mode.'); | ||
} | ||
} | ||
} | ||
|
||
function findDefinedPKCS12ConfigOptions( | ||
elasticsearchConfig: PKCS12ConfigType, | ||
serverConfig: PKCS12ConfigType | ||
): string[] { | ||
const result = []; | ||
if (elasticsearchConfig?.ssl?.keystore?.path) { | ||
result.push('elasticsearch.ssl.keystore.path'); | ||
} | ||
|
||
if (elasticsearchConfig?.ssl?.truststore?.path) { | ||
result.push('elasticsearch.ssl.truststore.path'); | ||
} | ||
|
||
if (serverConfig?.ssl?.keystore?.path) { | ||
result.push('server.ssl.keystore.path'); | ||
} | ||
|
||
if (serverConfig?.ssl?.truststore?.path) { | ||
result.push('server.ssl.truststore.path'); | ||
} | ||
|
||
return result; | ||
} |
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.
nit: what do you think about adding this on the next line?
(ditto for other try catches like this)
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.
++ added in latest commit