Skip to content
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

POL-918 Create Master Policy Permissions List #1674

Merged
merged 98 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
9bbd733
added policy permissions ruby script for parsing readmes for permissions
nia-vf1 Nov 24, 2023
7200a53
Merge branch 'master' of github-personal:flexera-public/policy_templa…
nia-vf1 Nov 24, 2023
af070a9
added github workflow yaml file to automate running ruby script to cr…
nia-vf1 Nov 24, 2023
3aa3c7a
minor update to syntax to support older versions of ruby
nia-vf1 Nov 24, 2023
8feb68d
adding fileutils library to create the directory for the json file
nia-vf1 Nov 24, 2023
186c4b3
added exclude in gitignore for policy permissions json
nia-vf1 Nov 24, 2023
9911091
try using dist
nia-vf1 Dec 7, 2023
2ffb2d9
Merge branch 'master' of github-personal:flexera-public/policy_templa…
nia-vf1 Dec 7, 2023
f08debb
removed generated json file
nia-vf1 Dec 7, 2023
e3ea3db
revert to ignoring the required "data/*" directory rather than dist
nia-vf1 Dec 7, 2023
3438225
test change
nia-vf1 Dec 7, 2023
35a5596
add pull request in workflow
nia-vf1 Dec 7, 2023
f709dbe
Update Master Policy Permissions List (#1675)
github-actions[bot] Dec 7, 2023
65b12c7
test revert back to original gitignore
nia-vf1 Dec 7, 2023
1ec63d9
reverting as addition to .gitignore file is required for now
nia-vf1 Dec 7, 2023
fd93327
Update Master Policy Permissions List (#1676)
github-actions[bot] Dec 8, 2023
2d95c91
Update Master Policy Permissions List (#1680)
github-actions[bot] Dec 8, 2023
51c5b23
Merge branch 'master' of github-personal:flexera-public/policy_templa…
nia-vf1 Dec 12, 2023
70459fc
Merge branch 'POL-918-create-master-policy-perm-list' of github-perso…
nia-vf1 Dec 12, 2023
e6bc186
Delete data/policy_permissions_list/master_policy_permissions_list.json
nia-vf1 Dec 12, 2023
ee923fe
changed name of workflow yaml file
nia-vf1 Dec 12, 2023
8065df0
Update Master Policy Permissions List (#1685)
github-actions[bot] Dec 12, 2023
e607dc9
Delete data/policy_permissions_list directory
nia-vf1 Dec 12, 2023
43dd118
updated name of workflow, and updated name of ruby script
nia-vf1 Dec 12, 2023
dcce39b
Merge branch 'POL-918-create-master-policy-perm-list' of github-perso…
nia-vf1 Dec 12, 2023
7d00502
fix
nia-vf1 Dec 12, 2023
c667cf7
Update Policy Master Permissions List (#1687)
github-actions[bot] Dec 12, 2023
97fd959
Merge branch 'master' of github-personal:flexera-public/policy_templa…
nia-vf1 Jan 4, 2024
91c5fb3
remove master_policy_permissions json
nia-vf1 Jan 4, 2024
032214f
update ruby script to capture read-only field for permissions and roles
nia-vf1 Jan 4, 2024
17d5387
add output to log
nia-vf1 Jan 4, 2024
d05ddd9
fix read-only field for permissions/roles
nia-vf1 Jan 5, 2024
76422b6
add logic to get description field, and correct boolean values for re…
nia-vf1 Jan 5, 2024
78de402
update json to not show "providers" field if no providers exist for a…
nia-vf1 Jan 5, 2024
1131213
Update Policy Master Permissions List (#1724)
github-actions[bot] Jan 22, 2024
d43aee3
task: use a statically defined list
bryankaraffa Jan 22, 2024
2070e6c
volumes (#1752)
XOmniverse Jan 22, 2024
4b21f66
task: add aws_rightsize_rds_instances.pt (#1754)
bryankaraffa Jan 22, 2024
912ba07
snapshot
XOmniverse Jan 22, 2024
539c73b
add aws_unused_ip_addresses.pt (#1757)
bryankaraffa Jan 22, 2024
ca3e625
done (#1758)
XOmniverse Jan 22, 2024
f0074d3
add aws_rightsize_ec2_instances.pt
bryankaraffa Jan 22, 2024
67193a5
done (#1759)
XOmniverse Jan 22, 2024
99302f0
POL-918 AWS RI Recommendations (#1760)
nia-vf1 Jan 22, 2024
0da1faa
unused volumes (#1761)
XOmniverse Jan 22, 2024
836a5bb
add azure_compute_rightsizing.pt (#1762)
bryankaraffa Jan 22, 2024
803f280
update (#1764)
XOmniverse Jan 22, 2024
e95672a
add azure unused sql to list (#1763)
nia-vf1 Jan 22, 2024
51e3e33
add azure_delete_old_snapshots.pt (#1765)
bryankaraffa Jan 22, 2024
bc9d507
push latest datasets
bryankaraffa Jan 22, 2024
2434d32
done (#1766)
XOmniverse Jan 22, 2024
4305f4f
good (#1768)
XOmniverse Jan 22, 2024
288b974
push latest dataset
bryankaraffa Jan 22, 2024
8a84f1e
add azure_savings_plan_recommendations.pt (#1769)
bryankaraffa Jan 22, 2024
866f861
push latest dataset
bryankaraffa Jan 22, 2024
9816edb
rightsize (#1771)
XOmniverse Jan 22, 2024
7e59fef
add permission json and yaml
nia-vf1 Jan 22, 2024
c863316
resolve merge conflict
nia-vf1 Jan 22, 2024
0e23b77
Merge branch 'master' of github-personal:flexera-public/policy_templa…
nia-vf1 Jan 22, 2024
7db29b7
google (#1773)
XOmniverse Jan 22, 2024
beb3c93
cloud sql (#1774)
XOmniverse Jan 22, 2024
3870ae3
feat: Add warning for new datasources and checking README for new per…
bryankaraffa Jan 22, 2024
985681f
update (#1776)
XOmniverse Jan 22, 2024
97fbe38
Add test new datasource
bryankaraffa Jan 22, 2024
a5d2c3d
fix test
bryankaraffa Jan 22, 2024
848b12f
add debug loggin
bryankaraffa Jan 22, 2024
b571924
done (#1777)
XOmniverse Jan 22, 2024
fc9197f
fix: update regex for new datasource blocks
bryankaraffa Jan 22, 2024
ff53594
feat: Add check for new datasources and a warning to check README
bryankaraffa Jan 29, 2024
b47ccfd
test: revert change to PT for testing
bryankaraffa Jan 29, 2024
4e14c32
feat: only check PT files
bryankaraffa Jan 29, 2024
be4974e
fix: install ruby using feature in devcontainer
bryankaraffa Jan 30, 2024
c0ce41c
move PT files list to separate file
bryankaraffa Jan 30, 2024
1aa3976
task: run ruby tools/policy_master_permission_generation/generate_po…
bryankaraffa Jan 30, 2024
51042fc
feat: sort output datasets using id
bryankaraffa Jan 30, 2024
be24d13
task: run ruby tools/policy_master_permission_generation/generate_p…
bryankaraffa Jan 30, 2024
2608ebb
fix: rm nvm from post commands
bryankaraffa Jan 30, 2024
6d777ca
feat: add error if PT not yet enabled
bryankaraffa Jan 30, 2024
8e868af
test: add tmp test datasource
bryankaraffa Jan 30, 2024
6108753
fix: use fail instead of error
bryankaraffa Jan 30, 2024
6260fc2
task: update error message
bryankaraffa Jan 30, 2024
d4b06be
task: update wording in fail
bryankaraffa Jan 30, 2024
3fa4bb5
test: rm temporary test trigger
bryankaraffa Jan 30, 2024
1134319
test: add tmp datasource to test warning trigger
bryankaraffa Jan 30, 2024
9767bd1
fix: use include? to check if file matches
bryankaraffa Jan 30, 2024
fd7af44
test: rm test trigger
bryankaraffa Jan 30, 2024
7494fad
docs: add README for policy permission generation
bryankaraffa Jan 30, 2024
988831e
docs: update branch name
bryankaraffa Jan 30, 2024
7837c69
Merge branch 'master' of github-personal:flexera-public/policy_templa…
nia-vf1 Feb 2, 2024
cfc3842
NVF/POL-918 1705958339 - Validate Google CUD Recommender permissions …
nia-vf1 Feb 2, 2024
caaac1c
Merge branch 'master' of github-personal:flexera-public/policy_templa…
nia-vf1 Feb 12, 2024
692ef24
updated json, yaml to reflect most recent repository changes
nia-vf1 Feb 12, 2024
76cdc86
Updated permissions list to include AWS Rightsize RDS Instances and A…
nia-vf1 Feb 12, 2024
4041770
Updated permissions list to include AWS Rightsize EBS Volumes and Azu…
nia-vf1 Feb 12, 2024
d13d5ed
Updated permissions list to include Azure Reserved Instances Utilizat…
nia-vf1 Feb 12, 2024
ee4e588
Updated permissions list to include AWS Untagged Resources and Azure …
nia-vf1 Feb 12, 2024
4ff1344
updated permissions Azure Rightsize Compute Instances README to remov…
nia-vf1 Feb 12, 2024
31f98ee
NVF/POL-918 Add Google Unlabeled Resources (#1814)
nia-vf1 Feb 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers/features/ruby:1": {},
"ghcr.io/eitsupi/devcontainer-features/jq-likes:1": {},
"ghcr.io/devcontainers/features/ruby:1": {
"version": "2.7"
},
"ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {},
"ghcr.io/devcontainers/features/aws-cli:1": {},
"ghcr.io/devcontainers/features/azure-cli:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
Expand All @@ -23,7 +25,7 @@
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "rvm install `cat /workspaces/policy_templates/.ruby-version` && git clone https://github.com/flexera-public/policy_sdk /tmp/policy_sdk && cd /tmp/policy_sdk/cmd/fpt && go build -o fpt && sudo mv fpt /usr/local/bin/fpt && rm -rf /tmp/policy_sdk",
"postCreateCommand": "npm install && bundle install --without documentation --path bundle && git clone https://github.com/flexera-public/policy_sdk /tmp/policy_sdk && cd /tmp/policy_sdk/cmd/fpt && go build -o fpt && sudo mv fpt /usr/local/bin/fpt && rm -rf /tmp/policy_sdk",

// Configure tool-specific properties.
"customizations": {
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/generate-policy-master-permissions-json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Generate Policy Master Permissions JSON

on:
# Trigger this workflow on pushes to master
push:
branches:
- master
- POL-918-create-master-policy-perm-list


# Workflow dispatch trigger allows manually running workflow
workflow_dispatch:
branches:
- master
- POL-918-create-master-policy-perm-list


jobs:
master-policy-permissions:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Speed up checkout by not fetching history

- name: Set up Ruby
uses: ruby/setup-ruby@v1

- name: Run Generate Policy Master Permissions Script
id: policy_permissions_json
run: |
ruby tools/policy_master_permission_generation/generate_policy_master_permissions.rb

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
commit-message: "Update Policy Master Permissions List"
title: "Update Policy Master Permissions List"
body: "Update Policy Master Permissions List from GitHub Actions Workflow [${{ github.workflow }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
branch: "task/update-policy-master-permissions"
delete-branch: true
labels: "automation"

- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dist/
.DS_Store
*.log
**/*.json
!.devcontainer/**
!.github/**
*.js
Expand All @@ -11,6 +10,12 @@ node_modules/
!package-lock.json
!.vscode/*.json

# Ignore all JSON files at this level of directory
**/*.json

# But exclude JSON files in this specific directory
!data/policy_permissions_list/*.json

# Bundler Artifacts
bundle/

Expand Down
33 changes: 33 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'uri'
require 'yaml'

require_relative 'tools/lib/policy_parser'
# DangerFile
# https://danger.systems/reference.html
Expand Down Expand Up @@ -192,3 +194,34 @@ changed_files.each do |file|
fail "Textlint failed on #{file}"
end
end

# check for new datasources
# print warning if new datasource is added to ensure the README permissions have been updated
permissions_verified_pt_file_yaml = YAML.load_file('tools/policy_master_permission_generation/validated_policy_templates.yaml')
has_app_changes.each do |file|
if file.end_with? ".pt"
# Get the diff to see only the new changes
diff = git.diff_for_file(file)

# Use regex to look for blocks that have a "datasource", "request", and "auth" sections of the datasource
# Example String:
# "diff --git a/cost/aws/rightsize_ec2_instances/aws_rightsize_ec2_instances.pt b/cost/aws/rightsize_ec2_instances/aws_rightsize_ec2_instances.pt\nindex 14b3236f..bf6a161d 100644\n--- a/cost/aws/rightsize_ec2_instances/aws_rightsize_ec2_instances.pt\n+++ b/cost/aws/rightsize_ec2_instances/aws_rightsize_ec2_instances.pt\n@@ -193,6 +193,16 @@ datasource \"ds_applied_policy\" do\n end\n end\n \n+datasource \"ds_applied_policy_test_will_be_removed_later\" do\n+ request do\n+ auth $auth_flexera\n+ host rs_governance_host\n+ path join([\"/api/governance/projects/\", rs_project_id, \"/applied_policies/\", policy_id])\n+ header \"Api-Version\", \"1.0\"\n+ header \"Test\", \"True\"\n+ end\n+end\n+\n # Get region-specific Flexera API endpoints\n datasource \"ds_flexera_api_hosts\" do\n run_script $js_flexera_api_hosts, rs_optima_host"
regex = /datasource.*do(\s)+.*request.*do(\s)+.*auth.*([\s\S])+end([\s\+])+end/

# Print some debug info about diff patch
# puts "Diff Patch:"
# puts diff.patch
# puts "---"

# First check if the PT file has been manually validated and enabled for permission generation
pt_file_enabled = permissions_verified_pt_file_yaml["validated_policy_templates"].select { |pt| pt.include?(file) }
if pt_file_enabled.empty?
# If the PT file has not been manually validated, then print an error message which will block the PR from being merged
# This will help improve coverage as we touch more PT files
fail "Policy Template file `#{file}` has **not** yet been enabled for automated permission generation. Please help us improve coverage by [following the steps documented in `tools/policy_master_permission_generation/`](https://github.com/flexera-public/policy_templates/tree/master/tools/policy_master_permission_generation) to resolve this"
elsif diff && diff.patch =~ regex
# If the PT file has been manually validated, but there are new datasources, then print a warning message
warn("Detected new request datasource in Policy Template file `#{file}`. Please verify the README.md has any new permissions that may be required.")
end
end
end
55 changes: 27 additions & 28 deletions compliance/google/unlabeled_resources/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Google Unlabeled Resources

## What it does
## What It does

Find all Google cloud resources(disks, images, instances, snapshots, buckets, vpnGateways) missing any of the user provided labels with the option to update the resources with the missing labels.

Expand All @@ -26,33 +26,32 @@ The following policy actions are taken on any resources found to be out of compl

## Prerequisites

This policy uses [credentials](https://docs.flexera.com/flexera/EN/Automation/ManagingCredentialsExternal.htm) for connecting to the cloud -- in order to apply this policy you must have a credential registered in the system that is compatible with this policy. If there are no credentials listed when you apply the policy, please contact your cloud admin and ask them to register a credential that is compatible with this policy. The information below should be consulted when creating the credential.

### Credential configuration

For administrators [creating and managing credentials](https://docs.flexera.com/flexera/EN/Automation/ManagingCredentialsExternal.htm) to use with this policy, the following information is needed:

Provider tag value to match this policy: `gce`

Required permissions in the provider:

- The `Monitoring Viewer` Role
- The `compute.disks.list` permission
- The `compute.instances.list` permission
- The `compute.disks.setLabels` permission
- The `compute.externalVpnGateways.list` permission
- The `compute.images.list` permission
- The `compute.externalVpnGateways.setLabels` permission
- The `compute.images.setLabels` permission
- The `compute.instances.setLabels` permission
- The `compute.snapshots.list` permission
- The `compute.snapshots.setLabels` permission
- The `compute.vpnGateways.list` permission
- The `compute.vpnGateways.setLabels` permission
- The `compute.images.setLabels` permission
- The `storage.buckets.list` permission
- The `storage.buckets.update` permission
- The `resourcemanager.projects.get` permission
This Policy Template requires that several APIs be enabled in your Google Cloud environment:

- [Cloud Resource Manager API](https://console.cloud.google.com/flows/enableapi?apiid=cloudresourcemanager.googleapis.com)
- [Compute Engine API](https://console.cloud.google.com/flows/enableapi?apiid=compute.googleapis.com)

This Policy Template uses [Credentials](https://docs.flexera.com/flexera/EN/Automation/ManagingCredentialsExternal.htm) for authenticating to datasources -- in order to apply this policy you must have a Credential registered in the system that is compatible with this policy. If there are no Credentials listed when you apply the policy, please contact your Flexera Org Admin and ask them to register a Credential that is compatible with this policy. The information below should be consulted when creating the credential(s).

- [**Google Cloud Credential**](https://docs.flexera.com/flexera/EN/Automation/ProviderCredentials.htm#automationadmin_4083446696_1121577) (*provider=gce*) which has the following:
- Permissions
- `compute.disks.list`
- `compute.disks.setLabels`
- `compute.externalVpnGateways.list`
- `compute.externalVpnGateways.setLabels`
- `compute.images.list`
- `compute.images.setLabels`
- `compute.instances.list`
- `compute.instances.setLabels`
- `compute.snapshots.list`
- `compute.snapshots.setLabels`
- `compute.vpnGateways.list`
- `compute.vpnGateways.setLabels`
- `resourcemanager.projects.get`
- `storage.buckets.list`
- `storage.buckets.update`

The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automation/ProviderCredentials.htm) page in the docs has detailed instructions for setting up Credentials for the most common providers.

## Supported Clouds

Expand Down
3 changes: 2 additions & 1 deletion cost/aws/unused_ip_addresses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The policy utilizes the AWS EC2 API to get a list of unattached IP addresses and

The policy includes the estimated monthly savings. The estimated monthly savings is recognized if the resource is terminated.

- The `Estimated Monthly Savings` is calculated using the per hour price of unused IPs, obtained from the AWS Pricing API, multiplied by 24 and then 30.44 to get an estimated monthly price.
- The `Estimated Monthly Savings` is calculated using the per hour price of unused IPs, obtained from the AWS Pricing API, multiplied by 24 and then 30.44 to get an estimated monthly price.
- Since the prices of individual resources are *not* obtained from Flexera CCO, they will *not* take into account any Flexera adjustment rules or cloud provider discounts present in the Flexera platform.
- The incident message detail includes the sum of each resource `Estimated Monthly Savings` as `Potential Monthly Savings`.
- If the Flexera organization is configured to use a currency other than USD, the savings values will be converted from USD using the exchange rate at the time that the policy executes.
Expand Down Expand Up @@ -50,6 +50,7 @@ This Policy Template uses [Credentials](https://docs.flexera.com/flexera/EN/Auto
- `ec2:ReleaseAddress`*
- `pricing:GetProducts`
- `sts:GetCallerIdentity`
- `cloudtrail:LookupEvents`

\* Only required for taking action (releasing an IP address); the policy will still function in a read-only capacity without these permissions.

Expand Down
3 changes: 3 additions & 0 deletions cost/azure/rightsize_compute_instances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ For administrators [creating and managing credentials](https://docs.flexera.com/
- [**Azure Resource Manager Credential**](https://docs.flexera.com/flexera/EN/Automation/ProviderCredentials.htm#automationadmin_109256743_1124668) (*provider=azure_rm*) which has the following permissions:
- `Microsoft.Compute/virtualMachines/read`
- `Microsoft.Compute/virtualMachines/write`*
- `Microsoft.Compute/virtualMachines/powerOff/action`*
- `Microsoft.Compute/virtualMachines/start/action`*
- `Microsoft.Compute/virtualMachines/delete`*
- `Microsoft.Compute/skus/read`
- `Microsoft.Insights/metrics/read`

Expand Down
5 changes: 5 additions & 0 deletions data/policy_permissions_list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Policy Permissions List

The files in this directory are generated automatically and should **NOT** be manually modified.

Please see [`tools/policy_master_permission_generation`](../../tools/policy_master_permission_generation/) for details
Loading
Loading