-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from PaloAltoNetworks/auto-discover
Add infra for discovering protections, identify LegacyServiceAccountToken feature gates
- Loading branch information
Showing
9 changed files
with
86 additions
and
14 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package policy | ||
import data.police_builtins as pb | ||
import future.keywords.in | ||
|
||
describe[{"desc": desc, "severity": severity}] { | ||
desc := "SAs and nodes that can list secrets cluster-wide may access confidential information, and in some cases serviceAccount tokens" | ||
severity := "Low" | ||
} | ||
checkServiceAccounts := true | ||
checkNodes := true | ||
|
||
evaluateRoles(roles, type) { | ||
some role in roles | ||
pb.notNamespaced(role) | ||
some rule in role.rules | ||
pb.valueOrWildcard(rule.resources, "secrets") | ||
pb.valueOrWildcard(rule.verbs, "list") | ||
pb.valueOrWildcard(rule.apiGroups, "") | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package collect | ||
|
||
import ( | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// Discover control plane feature gates and admission controllers that protect against certain attacks, | ||
// and populate the cluster's metadata with them for policies to consume. | ||
// NOTE: Uses impersonation and dry-run write operations, which won't affect the cluster, but may be logged / audited on. | ||
func discoverRelevantControlPlaneFeatures(clientset *kubernetes.Clientset, clusterDb *ClusterDb, metadata *ClusterMetadata) { | ||
if legacyTokenSecretsReducted(clusterDb) { | ||
metadata.Features = append(metadata.Features, "LegacyTokenSecretsReducted") | ||
} | ||
} | ||
|
||
// Best effort test for whether serviceAccount tokens are stored as secrets | ||
func legacyTokenSecretsReducted(clusterDb *ClusterDb) bool { | ||
for _, serviceAccount := range clusterDb.ServiceAccounts { | ||
if serviceAccount.ObjectMeta.Namespace != "kube-system" { | ||
continue | ||
} | ||
// Arbitrarily chose the replicaset-controller for testing | ||
if serviceAccount.ObjectMeta.Name != "replicaset-controller" { | ||
continue | ||
} | ||
// Return true if there are no auto-generated secrets for the serviceAccount | ||
return len(serviceAccount.Secrets) == 0 | ||
} | ||
return false | ||
} |
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