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

Add support for lockdowns in CIS resource #1201

Closed
pauljegouic opened this issue Mar 18, 2020 · 15 comments
Closed

Add support for lockdowns in CIS resource #1201

pauljegouic opened this issue Mar 18, 2020 · 15 comments
Assignees

Comments

@pauljegouic
Copy link

Hi there,

We would like to be able to manage CIS lockdowns rules through Terraform instead of using null_resource and bash scripts.

Thanks in advance

@pauljegouic pauljegouic changed the title Add support for lockdowns in cis resource Add support for lockdowns in CIS resource Mar 18, 2020
@hkantare
Copy link
Collaborator

Can you provide me some links to understand this feature and can you also provider us the null resource/bash script

@pauljegouic
Copy link
Author

pauljegouic commented Mar 30, 2020

Yep for sure.

Here is the IBM documentation: https://cloud.ibm.com/docs/cis?topic=cis-how-cis-keeps-your-work-secure

Here is a snippet we have made:

resource "local_file" "lockdown" {
  content  = jsonencode(local.lockdown_payload)
  filename = "${path.module}/lockdown.json"
}
resource "null_resource" "ip_filtering_lockdown" {
  depends_on = [local_file.lockdown]
  triggers = {
    build_number = "${timestamp()}"
  }
  provisioner "local-exec" {
    command = <<EOT
         ibmcloud login -r ${var.region} -g ${var.resource_group_id}
         existing_rules=$(ibmcloud cis firewalls -t lockdowns -i ${var.cis_id}  -d ${element(split(":", var.domain_id), 0)} --output json)
         for row in $(echo "$existing_rules" | jq -r '.[] | @base64'); do
                   _jq() {
                            echo $row | base64 -d | jq -r $1
                     }
                   if [ $(_jq '.urls[0]') == ${local.full_domain} ];then
                            ibmcloud cis firewall-delete $(_jq '.id') -t lockdowns -d ${element(split(":", var.domain_id), 0)} -i ${var.cis_id}
                   fi
          done
         ibmcloud cis firewall-create -t lockdowns -d ${element(split(":", var.domain_id), 0)} -i ${var.cis_id} -j "${path.module}/lockdown.json"
 EOT
  }
}

@pauljegouic
Copy link
Author

We would like to achieve the CRUD actions on cis_lockdown !

kavya498 added a commit to kavya498/terraform-provider-ibm that referenced this issue Apr 13, 2020
@pauljegouic
Copy link
Author

@hkantare seeing a lot of commit :) :)

When can we expect this feature to be released ?

@pauljegouic
Copy link
Author

image

@pauljegouic
Copy link
Author

@hkantare we definetly need the documentation !

@hkantare
Copy link
Collaborator

Docs will be update in couple of days....I'm rasining request against doc team

@ifs-saraqasmi
Copy link

@hkantare while waiting for the doc, can you give an example of using ibm_cis_firewall with lockdown param please

@hkantare
Copy link
Collaborator

doc file: https://github.com/IBM-Cloud/terraform-provider-ibm/blob/master/website/docs/r/cis_firewall.html.markdown

@pauljegouic
Copy link
Author

pauljegouic commented Apr 20, 2020

@hkantare & @kavya498 thanks for the update.

There is something that lead us to some 404 errors which is the inconsistency of usage of the IDs syntax, in all your documentation that refers to id.

In that case:

  • for ibm_cis_dns_record: The ID of the domain for which you want to add a DNS record.
  • for ibm_cis_firewall: The ID of the domain where you want to apply the firewall rules.

But in fact, the syntax of the expected ID is not the same.

  • ibm_cis_dns_record.domain_id expect this form of ID: 19364270fc6XXXXXX7f940fd292e:crn:v1:bluemix:public:internet-svcs:global:a/9e87f2cde0feXXXXXX056bdad79d285d:ad5b006d-0c7a-40ff-94e6-0f6a9a77ef7c:: (barely the domain_id:cis_id)
  • ibm_cis_firewall.domain_id: expect this for of ID of this type : 19364270fc6XXXXXX7f940fd292e

I would suggest, since IBM Cloud has multiple IDs syntax for resource, to provide a more accurated information/examples to the end-user.

I will close this issue after you see my message and suggest an enhancement.

@hkantare
Copy link
Collaborator

We will make changes to be inline with other CIS resources..as enhancement

@pauljegouic
Copy link
Author

Is it possible to have non-regression that you both support those two types of syntax ? @hkantare

@pauljegouic
Copy link
Author

I will create another case for this domain_id inconsistency between TF resources/datasources and the CLI.

@hkantare
Copy link
Collaborator

We will have inconsistency issues if we support both types...because we need to set back all the schema attributes to store in a statefile...If we support both types we will not be aware if user has passed which type ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants