Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > Guides > RightScale API 1.5 > Examples > Security Groups > Create Security Group Rules by CIDR IPS

Create Security Group Rules by CIDR IPS

Table of Contents

Add a security group rule to an existing security group, allowing SSH access (port 22) from any source IP.

Note:  You cannot specify multiple port ranges in one API call.  That is, had the example below specified a start/end port of 80, 22, and lastly 443, the security group rule would have been created, but only for port 443.  Essentially, the last port range specified wins out.  This applies when adding by source_type=group or source_type=cidr_ips.  You may however run the script below again, specifying a start_port and end_port of 80 to add the ability to browse, or 443 to permit SSL, etc.

Table of Contents

Curl

Prerequisite:  Example assumes you have previously authenticated, and your valid session cookie is in 'mycookie'.

Example Call

#!/bin/sh -e
CLOUD="2112"                   # Set the Cloud ID
SG="4ISBSPCJCG3CS"             # Set security group to which the rules should apply
curl -i -H X_API_VERSION:1.5 -b mycookie -X POST \
-d security_group_rule[protocol]=tcp \
-d security_group_rule[cidr_ips]='0.0.0.0/0' \                     # Open up for all IP addresses
-d security_group_rule[protocol_details][start_port]=22 \          # Enable SSH (port 22)
-d security_group_rule[protocol_details][end_port]=22 \            # Must set the start and end ports
-d security_group_rule[source_type]=cidr_ips \                     # Create by CIDR IP
https://my.rightscale.com/api/clouds/$CLOUD/security_groups/$SG/security_group_rules

Sample Output

No content, just header information.

HTTP/1.1 201 Created
Server: nginx/1.0.15
Date: Fri, 26 Oct 2012 19:06:09 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 201 Created
Location: /api/security_group_rules/358924001
X-Runtime: 1036
X-Request-Uuid: d4499e418f2a420594ac4b0ad4d3d387
Set-Cookie:
Cache-Control: no-cache
You must to post a comment.
Last modified
23:18, 16 May 2013

Tags

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.