Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18f53d3c9e | ||
|
|
273538003e |
@@ -32,7 +32,7 @@ namespace GitHub.Actions.WorkflowParser.Conversion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var effectiveMax = explicitMax ?? CreatePermissionsFromPolicy(context, permissionsPolicy, includeIdToken: isTrusted, includeModels: context.GetFeatures().AllowModelsPermission);
|
var effectiveMax = explicitMax ?? CreatePermissionsFromPolicy(context, permissionsPolicy, includeIdToken: isTrusted, includeModels: context.GetFeatures().AllowModelsPermission, includeWorkflows: context.GetFeatures().AllowWorkflowsPermission);
|
||||||
|
|
||||||
if (requested.ViolatesMaxPermissions(effectiveMax, out var permissionLevelViolations))
|
if (requested.ViolatesMaxPermissions(effectiveMax, out var permissionLevelViolations))
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,8 @@ namespace GitHub.Actions.WorkflowParser.Conversion
|
|||||||
TemplateContext context,
|
TemplateContext context,
|
||||||
string permissionsPolicy,
|
string permissionsPolicy,
|
||||||
bool includeIdToken,
|
bool includeIdToken,
|
||||||
bool includeModels)
|
bool includeModels,
|
||||||
|
bool includeWorkflows)
|
||||||
{
|
{
|
||||||
switch (permissionsPolicy)
|
switch (permissionsPolicy)
|
||||||
{
|
{
|
||||||
@@ -70,7 +71,7 @@ namespace GitHub.Actions.WorkflowParser.Conversion
|
|||||||
Packages = PermissionLevel.Read,
|
Packages = PermissionLevel.Read,
|
||||||
};
|
};
|
||||||
case WorkflowConstants.PermissionsPolicy.Write:
|
case WorkflowConstants.PermissionsPolicy.Write:
|
||||||
return new Permissions(PermissionLevel.Write, includeIdToken: includeIdToken, includeAttestations: true, includeModels: includeModels);
|
return new Permissions(PermissionLevel.Write, includeIdToken: includeIdToken, includeAttestations: true, includeModels: includeModels, includeWorkflows: includeWorkflows);
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException($"Unexpected permission policy: '{permissionsPolicy}'");
|
throw new ArgumentException($"Unexpected permission policy: '{permissionsPolicy}'");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1877,7 +1877,7 @@ namespace GitHub.Actions.WorkflowParser.Conversion
|
|||||||
permissionsStr.AssertUnexpectedValue(permissionsStr.Value);
|
permissionsStr.AssertUnexpectedValue(permissionsStr.Value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return new Permissions(permissionLevel, includeIdToken: true, includeAttestations: true, includeModels: context.GetFeatures().AllowModelsPermission);
|
return new Permissions(permissionLevel, includeIdToken: true, includeAttestations: true, includeModels: context.GetFeatures().AllowModelsPermission, includeWorkflows: context.GetFeatures().AllowWorkflowsPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapping = token.AssertMapping("permissions");
|
var mapping = token.AssertMapping("permissions");
|
||||||
@@ -1957,6 +1957,24 @@ namespace GitHub.Actions.WorkflowParser.Conversion
|
|||||||
context.Error(key, $"The permission 'models' is not allowed");
|
context.Error(key, $"The permission 'models' is not allowed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "workflows":
|
||||||
|
if (context.GetFeatures().AllowWorkflowsPermission)
|
||||||
|
{
|
||||||
|
// Workflows only supports write; downgrade read to none
|
||||||
|
if (permissionLevel == PermissionLevel.Read)
|
||||||
|
{
|
||||||
|
permissions.Workflows = PermissionLevel.NoAccess;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
permissions.Workflows = permissionLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Error(key, $"The permission 'workflows' is not allowed");
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using GitHub.Actions.WorkflowParser.Conversion;
|
using GitHub.Actions.WorkflowParser.Conversion;
|
||||||
@@ -17,7 +17,7 @@ namespace GitHub.Actions.WorkflowParser
|
|||||||
public Permissions(Permissions copy)
|
public Permissions(Permissions copy)
|
||||||
{
|
{
|
||||||
Actions = copy.Actions;
|
Actions = copy.Actions;
|
||||||
ArtifactMetadata = copy.ArtifactMetadata;
|
ArtifactMetadata = copy.ArtifactMetadata;
|
||||||
Attestations = copy.Attestations;
|
Attestations = copy.Attestations;
|
||||||
Checks = copy.Checks;
|
Checks = copy.Checks;
|
||||||
Contents = copy.Contents;
|
Contents = copy.Contents;
|
||||||
@@ -32,16 +32,18 @@ namespace GitHub.Actions.WorkflowParser
|
|||||||
SecurityEvents = copy.SecurityEvents;
|
SecurityEvents = copy.SecurityEvents;
|
||||||
IdToken = copy.IdToken;
|
IdToken = copy.IdToken;
|
||||||
Models = copy.Models;
|
Models = copy.Models;
|
||||||
|
Workflows = copy.Workflows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Permissions(
|
public Permissions(
|
||||||
PermissionLevel permissionLevel,
|
PermissionLevel permissionLevel,
|
||||||
bool includeIdToken,
|
bool includeIdToken,
|
||||||
bool includeAttestations,
|
bool includeAttestations,
|
||||||
bool includeModels)
|
bool includeModels,
|
||||||
|
bool includeWorkflows = false)
|
||||||
{
|
{
|
||||||
Actions = permissionLevel;
|
Actions = permissionLevel;
|
||||||
ArtifactMetadata = permissionLevel;
|
ArtifactMetadata = permissionLevel;
|
||||||
Attestations = includeAttestations ? permissionLevel : PermissionLevel.NoAccess;
|
Attestations = includeAttestations ? permissionLevel : PermissionLevel.NoAccess;
|
||||||
Checks = permissionLevel;
|
Checks = permissionLevel;
|
||||||
Contents = permissionLevel;
|
Contents = permissionLevel;
|
||||||
@@ -59,6 +61,10 @@ namespace GitHub.Actions.WorkflowParser
|
|||||||
Models = includeModels
|
Models = includeModels
|
||||||
? (permissionLevel == PermissionLevel.Write ? PermissionLevel.Read : permissionLevel)
|
? (permissionLevel == PermissionLevel.Write ? PermissionLevel.Read : permissionLevel)
|
||||||
: PermissionLevel.NoAccess;
|
: PermissionLevel.NoAccess;
|
||||||
|
// Workflows is write-only, so only grant it when permissionLevel is Write
|
||||||
|
Workflows = includeWorkflows && permissionLevel == PermissionLevel.Write
|
||||||
|
? PermissionLevel.Write
|
||||||
|
: PermissionLevel.NoAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static KeyValuePair<string, (PermissionLevel, PermissionLevel)>[] ComparisonKeyMapping(Permissions left, Permissions right)
|
private static KeyValuePair<string, (PermissionLevel, PermissionLevel)>[] ComparisonKeyMapping(Permissions left, Permissions right)
|
||||||
@@ -81,6 +87,7 @@ namespace GitHub.Actions.WorkflowParser
|
|||||||
new KeyValuePair<string, (PermissionLevel, PermissionLevel)>("security-events", (left.SecurityEvents, right.SecurityEvents)),
|
new KeyValuePair<string, (PermissionLevel, PermissionLevel)>("security-events", (left.SecurityEvents, right.SecurityEvents)),
|
||||||
new KeyValuePair<string, (PermissionLevel, PermissionLevel)>("id-token", (left.IdToken, right.IdToken)),
|
new KeyValuePair<string, (PermissionLevel, PermissionLevel)>("id-token", (left.IdToken, right.IdToken)),
|
||||||
new KeyValuePair<string, (PermissionLevel, PermissionLevel)>("models", (left.Models, right.Models)),
|
new KeyValuePair<string, (PermissionLevel, PermissionLevel)>("models", (left.Models, right.Models)),
|
||||||
|
new KeyValuePair<string, (PermissionLevel, PermissionLevel)>("workflows", (left.Workflows, right.Workflows)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +203,13 @@ namespace GitHub.Actions.WorkflowParser
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DataMember(Name = "workflows", EmitDefaultValue = false)]
|
||||||
|
public PermissionLevel Workflows
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
public Permissions Clone()
|
public Permissions Clone()
|
||||||
{
|
{
|
||||||
return new Permissions(this);
|
return new Permissions(this);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -41,6 +41,13 @@ namespace GitHub.Actions.WorkflowParser
|
|||||||
[DataMember(EmitDefaultValue = false)]
|
[DataMember(EmitDefaultValue = false)]
|
||||||
public bool AllowModelsPermission { get; set; }
|
public bool AllowModelsPermission { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether users may use the "workflows" permission.
|
||||||
|
/// Used during parsing only.
|
||||||
|
/// </summary>
|
||||||
|
[DataMember(EmitDefaultValue = false)]
|
||||||
|
public bool AllowWorkflowsPermission { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether the expression function fromJson performs strict JSON parsing.
|
/// Gets or sets a value indicating whether the expression function fromJson performs strict JSON parsing.
|
||||||
/// Used during evaluation only.
|
/// Used during evaluation only.
|
||||||
@@ -67,6 +74,7 @@ namespace GitHub.Actions.WorkflowParser
|
|||||||
Snapshot = false, // Default to false since this feature is still in an experimental phase
|
Snapshot = false, // Default to false since this feature is still in an experimental phase
|
||||||
StrictJsonParsing = false, // Default to false since this is temporary for telemetry purposes only
|
StrictJsonParsing = false, // Default to false since this is temporary for telemetry purposes only
|
||||||
AllowModelsPermission = false, // Default to false since we want this to be disabled for all non-production environments
|
AllowModelsPermission = false, // Default to false since we want this to be disabled for all non-production environments
|
||||||
|
AllowWorkflowsPermission = false, // Default to false; gated by feature flag for controlled rollout
|
||||||
AllowServiceContainerCommand = false, // Default to false since this feature is gated by actions_service_container_command
|
AllowServiceContainerCommand = false, // Default to false since this feature is gated by actions_service_container_command
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user