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

Fix/sql allowed authorized networks.rego #126

Conversation

FanchenBao
Copy link
Contributor

The rego file "sql_allowed_authorized_networks.rego" has two issues.

  1. In the package statement, templates.gcp.GCPSQLAllowedAuthorizedNetworksV1 needs be changed into templates.gcp.GCPSQLAllowedAuthorizedNetworksConstraintV1 in order for the template file "gcp_sql_allowed_authorized_networks_v1.yaml" to work.
  2. data field needs to be added in between resource and settings to correctly retrieve info from authorizedNetworks.

I also modified the logic so that the rule can detect when authorizedNetworks does not exist or has no content.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@FanchenBao
Copy link
Contributor Author

I signed CLA.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@FanchenBao
Copy link
Contributor Author

FanchenBao commented Jul 23, 2019

Referencing #124
Though the issue is about another file, the problems fixed are related.

…into fix/sql_allowed_authorized_networks.rego
Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution - please make sure tests pass (using make test). Right now I see two potential issues:

  1. The package name for the constraint and its test must match
  2. The test fixtures also need to be updated to properly include the "data" field.

@FanchenBao
Copy link
Contributor Author

You are welcome. And thanks for the suggestion. I will work on it.

Merge branch 'master' of https://github.com/forseti-security/policy-library into fix/sql_allowed_authorized_networks.rego
…tworks/assets/data.json; modify package statement of validator/sql_allowed_authorized_networks_test.rego
@FanchenBao
Copy link
Contributor Author

FanchenBao commented Jul 26, 2019

test fixture and test rego file for sql_allowed_authorized_networks have been updated. All tests passed using make test.

@AdrienWalkowiak
Copy link
Contributor

@morgante any other comments on this?

@morgante morgante self-requested a review August 10, 2019 05:16
This reverts commit f2709a2.

Due to inability to install PyYaml, will revert this change and move work to my personal laptop
@AdrienWalkowiak
Copy link
Contributor

@morgante does this look good to you now?

@ocervell
Copy link
Contributor

@AdrienWalkowiak @FanchenBao we shouldn't edit the fixture data.json manually - IMHO it should come from a real environment, otherwise we end up with issues where CAI data is different than our test fixtures

@FanchenBao
Copy link
Contributor Author

If I remember correctly, the real environment CAI has data field, at least when I made the change last month. Therefore, I changed data.json file to reflect that fact.

@morgante
Copy link
Contributor

morgante commented Oct 3, 2019

@FanchenBao Can you rebase?

@FanchenBao
Copy link
Contributor Author

FanchenBao commented Oct 4, 2019

@morgante Just rebased my fork onto current master, but I am still seeing conflict files.

@morgante
Copy link
Contributor

morgante commented Oct 4, 2019

@FanchenBao You'll have to resolve the conflicts manually. Also probably worth looking at the current implementation on master and seeing if your change still makes sense.

@morgante
Copy link
Contributor

morgante commented Oct 4, 2019

@FanchenBao Looks like tests fail, likely due to the addition of data in the test data.

Can you please run a CAI export and verify that it actually has that structure? Then make sure make test passes.

@FanchenBao
Copy link
Contributor Author

@morgante Yes, at least from my end, the CAI file has "data" field. For example:

[ 
   { 
      "name":"//cloudsql.googleapis.com/projects/fanchen-sandbox/instances/private-instance",
      "asset_type":"sqladmin.googleapis.com/Instance",
      "ancestry_path":"project/fanchen-sandbox",
      "resource":{ 
         "version":"v1beta4",
         "discovery_document_uri":"https://www.googleapis.com/discovery/v1/apis/sqladmin/v1beta4/rest",
         "discovery_name":"DatabaseInstance",
         "parent":"//cloudresourcemanager.googleapis.com/projects/fanchen-sandbox",
         "data":{ 
            "databaseVersion":"MYSQL_5_7",
            "name":"private-instance",
            "project":"fanchen-sandbox",
            "region":"us-central1",
            "settings":{ 
               "ipConfiguration":{ 
                  "authorizedNetworks":[ 
                     { 
                        "name":"test_2",
                        "value":"199.27.25.0/24"
                     }
                  ],
                  "ipv4Enabled":false,
                  "requireSsl":true
               }
            }
         }
      }
   }
]

I also double-checked data.json files in other sql-related assets, and they all have "data" field. Furthermore, I found that my old logic of reporting violation when authorizedNetworks is not set is incorrect, because this field is optional. Therefore, I adopted the current code on master branch.

@morgante morgante merged commit 6ef880e into GoogleCloudPlatform:master Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants