Merge pull request #42 from pas256/add-statements
Adding a way to put in a policy as is into the kappa config file
Showing
2 changed files
with
44 additions
and
8 deletions
... | @@ -39,7 +39,7 @@ Installation | ... | @@ -39,7 +39,7 @@ Installation |
39 | The quickest way to get kappa is to install the latest stable version via pip: | 39 | The quickest way to get kappa is to install the latest stable version via pip: |
40 | 40 | ||
41 | pip install kappa | 41 | pip install kappa |
42 | - | 42 | + |
43 | Or for the development version: | 43 | Or for the development version: |
44 | 44 | ||
45 | pip install git+https://github.com/garnaat/kappa.git | 45 | pip install git+https://github.com/garnaat/kappa.git |
... | @@ -70,9 +70,9 @@ simple/ | ... | @@ -70,9 +70,9 @@ simple/ |
70 | 70 | ||
71 | Within the directory we see: | 71 | Within the directory we see: |
72 | 72 | ||
73 | -* kappa.yml.sample which is a sample YAML configuration file for the project | 73 | +* `kappa.yml.sample` which is a sample YAML configuration file for the project |
74 | -* _src which is a directory containing the source code for the Lambda function | 74 | +* `_src` which is a directory containing the source code for the Lambda function |
75 | -* _test which is a directory containing some test data | 75 | +* `_test` which is a directory containing some test data |
76 | 76 | ||
77 | The first step is to make a copy of the sample configuration file: | 77 | The first step is to make a copy of the sample configuration file: |
78 | 78 | ||
... | @@ -93,7 +93,7 @@ environments: | ... | @@ -93,7 +93,7 @@ environments: |
93 | resources: | 93 | resources: |
94 | - arn: arn:aws:logs:*:*:* | 94 | - arn: arn:aws:logs:*:*:* |
95 | actions: | 95 | actions: |
96 | - - "*" | 96 | + - "*" |
97 | prod: | 97 | prod: |
98 | profile: <your profile here> | 98 | profile: <your profile here> |
99 | region: <your region here> | 99 | region: <your region here> |
... | @@ -174,12 +174,12 @@ Lambda called kappa-simple-dev. | ... | @@ -174,12 +174,12 @@ Lambda called kappa-simple-dev. |
174 | To test this out, try this: | 174 | To test this out, try this: |
175 | 175 | ||
176 | ``` | 176 | ``` |
177 | -$ kappa invoke _tests/test_one.json | 177 | +$ kappa invoke _tests/test_one.json |
178 | invoking | 178 | invoking |
179 | START RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Version: $LATEST | 179 | START RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Version: $LATEST |
180 | [DEBUG] 2015-12-08T22:00:15.363Z 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f {u'foo': u'bar', u'fie': u'baz'} | 180 | [DEBUG] 2015-12-08T22:00:15.363Z 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f {u'foo': u'bar', u'fie': u'baz'} |
181 | END RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f | 181 | END RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f |
182 | -REPORT RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Duration: 0.40 ms Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 23 MB | 182 | +REPORT RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Duration: 0.40 ms Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 23 MB |
183 | 183 | ||
184 | Response: | 184 | Response: |
185 | {"status": "success"} | 185 | {"status": "success"} |
... | @@ -204,3 +204,36 @@ Kappa will figure out what has changed and make the necessary updates for you. | ... | @@ -204,3 +204,36 @@ Kappa will figure out what has changed and make the necessary updates for you. |
204 | 204 | ||
205 | That gives you a quick overview of kappa. To learn more about it, I recommend | 205 | That gives you a quick overview of kappa. To learn more about it, I recommend |
206 | you check out the tutorial. | 206 | you check out the tutorial. |
207 | + | ||
208 | +Policies | ||
209 | +-------- | ||
210 | + | ||
211 | +Hands up who loves writing IAM policies. Yeah, that's what I thought. With | ||
212 | +Kappa, there is a simplified way of writing policies and granting your Lambda | ||
213 | +function the permissions it needs. | ||
214 | + | ||
215 | +The simplified version allows you to specify, in your `kappa.yml` file, the | ||
216 | +ARN of the resource you want to access, and then a list of the API methods you | ||
217 | +want to allow. For example: | ||
218 | + | ||
219 | +``` | ||
220 | +policy: | ||
221 | + resources: | ||
222 | + - arn: arn:aws:logs:*:*:* | ||
223 | + actions: | ||
224 | + - "*" | ||
225 | +``` | ||
226 | + | ||
227 | +To express this using the official IAM policy format, you can instead use a | ||
228 | +statement: | ||
229 | + | ||
230 | +``` | ||
231 | +policy: | ||
232 | + statements: | ||
233 | + - Effect: Allow | ||
234 | + Resource: "*" | ||
235 | + Action: | ||
236 | + - "logs:*" | ||
237 | +``` | ||
238 | + | ||
239 | +Both of these do the same thing. | ... | ... |
... | @@ -44,7 +44,8 @@ class Policy(object): | ... | @@ -44,7 +44,8 @@ class Policy(object): |
44 | self.environment) | 44 | self.environment) |
45 | 45 | ||
46 | def document(self): | 46 | def document(self): |
47 | - if 'resources' not in self._config['policy']: | 47 | + if ('resources' not in self._config['policy'] and |
48 | + 'statements' not in self._config['policy']): | ||
48 | return None | 49 | return None |
49 | document = {"Version": "2012-10-17"} | 50 | document = {"Version": "2012-10-17"} |
50 | statements = [] | 51 | statements = [] |
... | @@ -59,6 +60,8 @@ class Policy(object): | ... | @@ -59,6 +60,8 @@ class Policy(object): |
59 | actions.append("{}:{}".format(service, action)) | 60 | actions.append("{}:{}".format(service, action)) |
60 | statement['Action'] = actions | 61 | statement['Action'] = actions |
61 | statements.append(statement) | 62 | statements.append(statement) |
63 | + for statement in self._config['policy'].get('statements', []): | ||
64 | + statements.append(statement) | ||
62 | return json.dumps(document, indent=2, sort_keys=True) | 65 | return json.dumps(document, indent=2, sort_keys=True) |
63 | 66 | ||
64 | @property | 67 | @property | ... | ... |
-
Please register or login to post a comment