update-sg-ip
v1.0.0
Published
Updates a security group to use my current IP
Readme
UpdateSGIp
A CLI tool to easily authorize your current (or specified) IP address in an AWS Security Group for a given port. Useful for developers and DevOps who need to quickly allow access to cloud resources.
Prerequisites
- Node.js (v14 or higher recommended)
- AWS credentials configured (via
~/.aws/credentialsor environment variables) - AWS IAM user/role with permissions to modify Security Groups (
ec2:AuthorizeSecurityGroupIngress,ec2:RevokeSecurityGroupIngress,ec2:DescribeSecurityGroups)
Installation
git clone [email protected]:felipefleury/UpdateSGIp.git
cd UpdateIP
yarn install # or npm installUsage
Run the script with Node.js:
node update-sg.js \
--profile <aws-profile> \
--region <aws-region> \
--group-id <sg-id> \
[--ip <cidr> | --auto-ip] [--port <port>]Arguments
--profile: (Optional) AWS CLI profile to use. Default:default--region: (Optional) AWS region. Default:us-east-1--group-id: (Required) The Security Group ID to update (e.g.,sg-0abc1234def5678gh)--ip: (Optional) IP/CIDR to allow (e.g.,203.0.113.5/32)--auto-ip: (Optional) Automatically detect your public IP and use/32CIDR--port: (Optional) TCP port to allow. Default:22
Note: Either
--ipor--auto-ipmust be provided. If both are omitted,--auto-ipis assumed.
Example
Allow your current public IP to access port 1433 on a specific Security Group:
node update-sg.js --profile myservice --region us-east-1 \
--group-id sg-0abc1234def5678gh --auto-ip --port 1433Allow a specific IP/CIDR to access port 22:
node update-sg.js --group-id sg-0abc1234def5678gh --ip 203.0.113.5/32 --port 22Security Notes
- This tool will remove any previous rule for the same hostname/description before adding the new rule.
- Make sure your AWS credentials are protected and have the minimum required permissions.
- Use with caution in production environments.
License
MIT License
