Skip to content
代码片段 群组 项目
未验证 提交 1542c786 编辑于 作者: Artur Fedorov's avatar Artur Fedorov 提交者: GitLab
浏览文件

Merge branch '432513-policies-existing-policy-scope-yaml' into 'master'

Add new query and extend validation for security polices

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/144685



Merged-by: default avatarArtur Fedorov <afedorov@gitlab.com>
Approved-by: default avatarOlena Horal-Koretska <ohoralkoretska@gitlab.com>
Approved-by: default avatarRoss Byrne <robyrne@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -77,13 +77,14 @@ export const fromYaml = ({ manifest, validateRuleMode = false }) => { ...@@ -77,13 +77,14 @@ export const fromYaml = ({ manifest, validateRuleMode = false }) => {
actionsKeys.push('ci_configuration'); actionsKeys.push('ci_configuration');
} }
const hasPolicyScope =
gon?.features?.securityPoliciesPolicyScope ||
gon?.features?.securityPoliciesPolicyScopeProject;
/** /**
* Can be removed after ff is enabled * Can be removed after ff is enabled
*/ */
const primaryKeys = PRIMARY_POLICY_KEYS; const primaryKeys = [...PRIMARY_POLICY_KEYS, ...(hasPolicyScope ? ['policy_scope'] : [])];
if (gon?.features?.securityPoliciesPolicyScope) {
primaryKeys.push('policy_scope');
}
return isValidPolicy({ policy, primaryKeys, rulesKeys, actionsKeys }) && return isValidPolicy({ policy, primaryKeys, rulesKeys, actionsKeys }) &&
!hasInvalidCron(policy) && !hasInvalidCron(policy) &&
......
...@@ -24,10 +24,11 @@ export const fromYaml = ({ manifest, validateRuleMode = false }) => { ...@@ -24,10 +24,11 @@ export const fromYaml = ({ manifest, validateRuleMode = false }) => {
* the UI for new attributes may not be available. * the UI for new attributes may not be available.
*/ */
const primaryKeys = [ const hasPolicyScope =
...PRIMARY_POLICY_KEYS, gon?.features?.securityPoliciesPolicyScope ||
...(gon?.features?.securityPoliciesPolicyScope ? ['policy_scope'] : []), gon?.features?.securityPoliciesPolicyScopeProject;
];
const primaryKeys = [...PRIMARY_POLICY_KEYS, ...(hasPolicyScope ? ['policy_scope'] : [])];
const rulesKeys = [ const rulesKeys = [
'type', 'type',
'branches', 'branches',
......
query getSppLinkedProjectsNamespaces($fullPath: ID!) {
project(fullPath: $fullPath) {
id
securityPolicyProjectLinkedProjects {
nodes {
id
name
}
}
securityPolicyProjectLinkedNamespaces {
nodes {
id
name
}
}
}
}
...@@ -34,6 +34,8 @@ describe('fromYaml', () => { ...@@ -34,6 +34,8 @@ describe('fromYaml', () => {
${'returns the policy object for branch exceptions'} | ${{ manifest: mockBranchExceptionsExecutionManifest, validateRuleMode: true }} | ${mockBranchExceptionsScanExecutionObject} | ${{}} ${'returns the policy object for branch exceptions'} | ${{ manifest: mockBranchExceptionsExecutionManifest, validateRuleMode: true }} | ${mockBranchExceptionsScanExecutionObject} | ${{}}
${'returns the policy object for project scope with disabled ff'} | ${{ manifest: mockPolicyScopeExecutionManifest, validateRuleMode: true }} | ${{ error: true }} | ${{ securityPoliciesPolicyScope: false }} ${'returns the policy object for project scope with disabled ff'} | ${{ manifest: mockPolicyScopeExecutionManifest, validateRuleMode: true }} | ${{ error: true }} | ${{ securityPoliciesPolicyScope: false }}
${'returns the policy object for project scope with enabled ff'} | ${{ manifest: mockPolicyScopeExecutionManifest, validateRuleMode: true }} | ${mockPolicyScopeScanExecutionObject} | ${{ securityPoliciesPolicyScope: true }} ${'returns the policy object for project scope with enabled ff'} | ${{ manifest: mockPolicyScopeExecutionManifest, validateRuleMode: true }} | ${mockPolicyScopeScanExecutionObject} | ${{ securityPoliciesPolicyScope: true }}
${'returns the policy object for project scope with disabled ff for project'} | ${{ manifest: mockPolicyScopeExecutionManifest, validateRuleMode: true }} | ${{ error: true }} | ${{ securityPoliciesPolicyScopeProject: false }}
${'returns the policy object for project scope with enabled ff for project'} | ${{ manifest: mockPolicyScopeExecutionManifest, validateRuleMode: true }} | ${mockPolicyScopeScanExecutionObject} | ${{ securityPoliciesPolicyScopeProject: true }}
${'returns the policy object for custom code block with file path with enabled ff'} | ${{ manifest: mockCodeBlockFilePathScanExecutionManifest, validateRuleMode: true }} | ${mockCodeBlockFilePathScanExecutionObject} | ${{ compliancePipelineInPolicies: true }} ${'returns the policy object for custom code block with file path with enabled ff'} | ${{ manifest: mockCodeBlockFilePathScanExecutionManifest, validateRuleMode: true }} | ${mockCodeBlockFilePathScanExecutionObject} | ${{ compliancePipelineInPolicies: true }}
${'returns the policy object for custom code block with file path with disabled ff'} | ${{ manifest: mockCodeBlockFilePathScanExecutionManifest, validateRuleMode: true }} | ${{ error: true }} | ${{ compliancePipelineInPolicies: false }} ${'returns the policy object for custom code block with file path with disabled ff'} | ${{ manifest: mockCodeBlockFilePathScanExecutionManifest, validateRuleMode: true }} | ${{ error: true }} | ${{ compliancePipelineInPolicies: false }}
`('$title', ({ input, output, features }) => { `('$title', ({ input, output, features }) => {
......
...@@ -89,6 +89,7 @@ describe('createPolicyObject', () => { ...@@ -89,6 +89,7 @@ describe('createPolicyObject', () => {
${'returns the policy object for a manifest with `approval_settings` with the `scanResultPoliciesBlockUnprotectingBranches` feature flag on'} | ${{ scanResultPoliciesBlockUnprotectingBranches: true }} | ${mockApprovalSettingsScanResultManifest} | ${{ policy: mockApprovalSettingsScanResultObject, hasParsingError: false }} ${'returns the policy object for a manifest with `approval_settings` with the `scanResultPoliciesBlockUnprotectingBranches` feature flag on'} | ${{ scanResultPoliciesBlockUnprotectingBranches: true }} | ${mockApprovalSettingsScanResultManifest} | ${{ policy: mockApprovalSettingsScanResultObject, hasParsingError: false }}
${'returns the policy object for a manifest with `approval_settings` containing permitted invalid settings and the `scanResultPoliciesBlockUnprotectingBranches` feature flag on'} | ${{ scanResultPoliciesBlockUnprotectingBranches: true }} | ${mockApprovalSettingsPermittedInvalidScanResultManifest} | ${{ policy: mockApprovalSettingsPermittedInvalidScanResultObject, hasParsingError: false }} ${'returns the policy object for a manifest with `approval_settings` containing permitted invalid settings and the `scanResultPoliciesBlockUnprotectingBranches` feature flag on'} | ${{ scanResultPoliciesBlockUnprotectingBranches: true }} | ${mockApprovalSettingsPermittedInvalidScanResultManifest} | ${{ policy: mockApprovalSettingsPermittedInvalidScanResultObject, hasParsingError: false }}
${'returns the policy object for a manifest with `policy_scope` feature flag on'} | ${{ securityPoliciesPolicyScope: true }} | ${mockPolicyScopeScanResultManifest} | ${{ policy: mockPolicyScopeScanResultObject, hasParsingError: false }} ${'returns the policy object for a manifest with `policy_scope` feature flag on'} | ${{ securityPoliciesPolicyScope: true }} | ${mockPolicyScopeScanResultManifest} | ${{ policy: mockPolicyScopeScanResultObject, hasParsingError: false }}
${'returns the policy object for a manifest with `policy_scope` feature flag on for project'} | ${{ securityPoliciesPolicyScopeProject: true }} | ${mockPolicyScopeScanResultManifest} | ${{ policy: mockPolicyScopeScanResultObject, hasParsingError: false }}
${'returns the error object for a manifest with `approval_settings` containing permitted invalid settings and the `scanResultPoliciesBlockUnprotectingBranches` feature flag off'} | ${{}} | ${mockApprovalSettingsPermittedInvalidScanResultManifest} | ${{ policy: mockApprovalSettingsPermittedInvalidScanResultObject, hasParsingError: false }} ${'returns the error object for a manifest with `approval_settings` containing permitted invalid settings and the `scanResultPoliciesBlockUnprotectingBranches` feature flag off'} | ${{}} | ${mockApprovalSettingsPermittedInvalidScanResultManifest} | ${{ policy: mockApprovalSettingsPermittedInvalidScanResultObject, hasParsingError: false }}
${'returns the policy object for a manifest with `approval_settings` with all feature flags off'} | ${{}} | ${mockApprovalSettingsScanResultManifest} | ${{ policy: mockApprovalSettingsScanResultObject, hasParsingError: false }} ${'returns the policy object for a manifest with `approval_settings` with all feature flags off'} | ${{}} | ${mockApprovalSettingsScanResultManifest} | ${{ policy: mockApprovalSettingsScanResultObject, hasParsingError: false }}
${'returns the error object for a manifest with `policy_scope` feature flag off'} | ${{}} | ${mockPolicyScopeScanResultManifest} | ${{ policy: { error: true }, hasParsingError: true }} ${'returns the error object for a manifest with `policy_scope` feature flag off'} | ${{}} | ${mockPolicyScopeScanResultManifest} | ${{ policy: { error: true }, hasParsingError: true }}
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册