VM::EC...:Policy(3pm)

πŸ“¦
version 1.28 Β· 7 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸŽ€ VM::EC2::Security::Policy(3pm) πŸŽ€

okay bestie, pull up a chair because we're talking about VM::EC2::Security::Policy β€” it's a Simple IAM policy generator for EC2, and honestly? it's giving exactly what it says on the tin. no more, no less, and that's the vibe. πŸ’…


✨ SYNOPSIS ✨

my $policy = VM::EC2::Security::Policy->new;
$policy->allow('Describe*','CreateVolume','delete_volume');
$policy->deny('DescribeVolumes');
print $policy->as_string;

like. look at that. four lines. so clean, so iconic. 🌸


πŸ’– DESCRIPTION πŸ’–

So here's the tea: this is a very simple Identity and Access Management (IAM) policy statement generator. It works sufficiently well to create policies that control access to EC2 resources β€” and honestly, for that job, it ate. πŸ”₯

But let's be real for a sec: it is not fully general across all AWS services. It's an EC2 girlie through and through. no cap. πŸ’€


πŸ¦‹ METHODS πŸ¦‹

This section is all about the methods you get with VM::EC2::Security::Policy. The whole flow is:

  1. you create a new, empty policy with new(),
  2. you grant access to EC2 actions with allow(),
  3. you deny access to EC2 actions with deny().

Then when you're done, either call as_string(), or just use the policy object in a string context, and boom β€” you get a properly-formatted policy string. ✨

Now, the moment you've all been waiting for: allow() and deny() return the modified object, which means you can chain methods. main character API design, truly. for example:

my $p = VM::EC2::Security::Policy->new
            ->allow('Describe*')
            ->deny('DescribeImages','DescribeInstances');
print $p;

πŸ’œ $policy = VM::EC2::Security::Policy->new()

This class method creates a new, empty policy object. and here's the important part, bestie: the default policy object denies all access to EC2 resources. secure by default, we love to see it. πŸ”’

πŸ’œ $policy->allow('action1','action2','action3',...)

Grant access to the listed EC2 actions. and you've got options for how you write them, because she's flexible:

  • you can use Amazon's MixedCase notation (e.g. "DescribeInstances"), or
  • you can use VM::EC2's more Perlish underscore notation (e.g. "describe_instances").

You can find the list of actions in VM::EC2, or in the Amazon API documentation at http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/OperationList-query.html.

The "*" wildcard lets you indicate a series of matching operations. so like, to allow all Describe operations:

$policy->allow('Describe*')

and as we said earlier, allow() returns the object, which makes chaining methods easy. obsessed. 🫢

πŸ’œ $policy->deny('action1','action2','action3',...)

Similar to allow(), except this one denies access to certain actions. and listen carefully: Deny statements take precedence over allow statements. that's the rule, periodt. πŸ‘‘

And yes, as described earlier, deny() returns the object, so you can keep chaining. ✨

πŸ’œ $string = $policy->as_string

Converts the policy into a JSON string that can be passed to VM::EC2->get_federation_token(), or other AWS libraries. that's it, that's the method. slay. πŸ’…


🌈 STRING OVERLOADING 🌈

When used in a string context, this object will interpolate into the policy JSON string using as_string(). so you can just print her and she'll show up looking perfect. βœ¨πŸ‘‘


🌸 SEE ALSO 🌸

  • VM::EC2
  • VM::EC2::Generic

πŸ’– AUTHOR πŸ’–

Lincoln Stein <lincoln.stein@gmail.com>.

Copyright (c) 2011 Ontario Institute for Cancer Research

This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER.txt for disclaimers of warranty.


okay that's the whole page bestie, you're officially IAM-policy-pilled. go grant yourself some permissions (responsibly!!) πŸ¦‹βœ¨

this icon was brought to you by perl v5.38.2, dated 2024-08-10, filed under VM::EC...:Policy(3pm) β€” mwah, love you, bye πŸ’œ

πŸ“¦ where this page comes from