PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, December 18, 2022

[FIXED] How to decrypt windows administrator password in terraform?

 December 18, 2022     amazon-web-services, interpolation, syntax, terraform     No comments   

Issue

I'm provisioning a single windows server for testing with terraform in AWS. Every time i need to decrypt my windows password with my PEM file to connect. Instead, i chose the terraform argument get_password_data and stored my password_data in tfstate file. Now how do i decrypt the same with interpolation syntax rsadecrypt

Please find my below terraform code

### Resource for EC2 instance creation ###

resource "aws_instance" "ec2" {
  ami                   =   "${var.ami}"
  instance_type         =   "${var.instance_type}"
  key_name              =   "${var.key_name}"
  subnet_id             =   "${var.subnet_id}"
  security_groups       =  ["${var.security_groups}"]
  availability_zone     =   "${var.availability_zone}"
  private_ip            =   "x.x.x.x"
  get_password_data     =   "true"

  connection {
    password            =   "${rsadecrypt(self.password_data)}"
    }

  root_block_device {
              volume_type = "${var.volume_type}"
              volume_size = "${var.volume_size}"
    delete_on_termination = "true"
    }

  tags {
        "Cost Center"  =  "R1"
        "Name"         =  "AD-test"
        "Purpose"      =  "Task"
        "Server Name"  =  "Active Directory"
        "SME Name"     =  "Ravi"
    }

}


output "instance_id" {
  value = "${aws_instance.ec2.id}"
}


### Resource for EBS volume creation ###

  resource "aws_ebs_volume" "additional_vol" {
    availability_zone =  "${var.availability_zone}"
    size              =  "${var.size}"
    type              =  "${var.type}"
}

### Output of Volume ID ###

  output "vol_id" {
    value = "${aws_ebs_volume.additional_vol.id}"
}

### Resource for Volume attachment ###

   resource "aws_volume_attachment" "attach_vol" {
     device_name       = "${var.device_name}"
     volume_id         = "${aws_ebs_volume.additional_vol.id}"
     instance_id       = "${aws_instance.ec2.id}"
     skip_destroy      = "true"
}

Solution

The password is encrypted using the key_pair you specified when launching the instance, you still need to use it to decrypt as password_data is still just the base64 encoded encrypted password data.

You should use ${rsadecrypt(self.password_data,file("/path/to/private_key.pem"))}

This is for good reason. You really don't want just a base64 encoded password floating around in state.

Short version: You are missing the second argument in the interpolation function.



Answered By - mootpt
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing