@cloud-copilot/iam-expand 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE.txt +68 -81
  2. package/README.md +80 -29
  3. package/dist/cjs/cli.js +70 -49
  4. package/dist/cjs/cli.js.map +1 -1
  5. package/dist/cjs/cli_utils.d.ts +4 -16
  6. package/dist/cjs/cli_utils.d.ts.map +1 -1
  7. package/dist/cjs/cli_utils.js +11 -44
  8. package/dist/cjs/cli_utils.js.map +1 -1
  9. package/dist/cjs/expand.d.ts.map +1 -1
  10. package/dist/cjs/expand.js +9 -7
  11. package/dist/cjs/expand.js.map +1 -1
  12. package/dist/cjs/expand_file.d.ts +1 -1
  13. package/dist/cjs/expand_file.d.ts.map +1 -1
  14. package/dist/cjs/expand_file.js +5 -2
  15. package/dist/cjs/expand_file.js.map +1 -1
  16. package/dist/cjs/index.d.ts.map +1 -1
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/invert.d.ts.map +1 -1
  19. package/dist/cjs/invert.js +10 -6
  20. package/dist/cjs/invert.js.map +1 -1
  21. package/dist/cjs/util.js +1 -1
  22. package/dist/cjs/util.js.map +1 -1
  23. package/dist/esm/cli.js +74 -53
  24. package/dist/esm/cli.js.map +1 -1
  25. package/dist/esm/cli_utils.d.ts +4 -16
  26. package/dist/esm/cli_utils.d.ts.map +1 -1
  27. package/dist/esm/cli_utils.js +12 -44
  28. package/dist/esm/cli_utils.js.map +1 -1
  29. package/dist/esm/expand.d.ts.map +1 -1
  30. package/dist/esm/expand.js +9 -7
  31. package/dist/esm/expand.js.map +1 -1
  32. package/dist/esm/expand_file.d.ts +1 -1
  33. package/dist/esm/expand_file.d.ts.map +1 -1
  34. package/dist/esm/expand_file.js +7 -4
  35. package/dist/esm/expand_file.js.map +1 -1
  36. package/dist/esm/index.d.ts.map +1 -1
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/invert.d.ts.map +1 -1
  39. package/dist/esm/invert.js +12 -8
  40. package/dist/esm/invert.js.map +1 -1
  41. package/dist/esm/util.js +1 -1
  42. package/dist/esm/util.js.map +1 -1
  43. package/package.json +72 -3
  44. package/dist/cjs/stdin.d.ts +0 -7
  45. package/dist/cjs/stdin.d.ts.map +0 -1
  46. package/dist/cjs/stdin.js +0 -36
  47. package/dist/cjs/stdin.js.map +0 -1
  48. package/dist/esm/stdin.d.ts +0 -7
  49. package/dist/esm/stdin.d.ts.map +0 -1
  50. package/dist/esm/stdin.js +0 -33
  51. package/dist/esm/stdin.js.map +0 -1
package/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
1
+ GNU AFFERO GENERAL PUBLIC LICENSE
2
+ Version 3, 19 November 2007
3
3
 
4
4
  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
5
  Everyone is permitted to copy and distribute verbatim copies
@@ -7,17 +7,15 @@
7
7
 
8
8
  Preamble
9
9
 
10
- The GNU General Public License is a free, copyleft license for
11
- software and other kinds of works.
10
+ The GNU Affero General Public License is a free, copyleft license for
11
+ software and other kinds of works, specifically designed to ensure
12
+ cooperation with the community in the case of network server software.
12
13
 
13
14
  The licenses for most software and other practical works are designed
14
15
  to take away your freedom to share and change the works. By contrast,
15
- the GNU General Public License is intended to guarantee your freedom to
16
+ our General Public Licenses are intended to guarantee your freedom to
16
17
  share and change all versions of a program--to make sure it remains free
17
- software for all its users. We, the Free Software Foundation, use the
18
- GNU General Public License for most of our software; it applies also to
19
- any other work released this way by its authors. You can apply it to
20
- your programs, too.
18
+ software for all its users.
21
19
 
22
20
  When we speak of free software, we are referring to freedom, not
23
21
  price. Our General Public Licenses are designed to make sure that you
@@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
26
24
  want it, that you can change the software or use pieces of it in new
27
25
  free programs, and that you know you can do these things.
28
26
 
29
- To protect your rights, we need to prevent others from denying you
30
- these rights or asking you to surrender the rights. Therefore, you have
31
- certain responsibilities if you distribute copies of the software, or if
32
- you modify it: responsibilities to respect the freedom of others.
33
-
34
- For example, if you distribute copies of such a program, whether
35
- gratis or for a fee, you must pass on to the recipients the same
36
- freedoms that you received. You must make sure that they, too, receive
37
- or can get the source code. And you must show them these terms so they
38
- know their rights.
39
-
40
- Developers that use the GNU GPL protect your rights with two steps:
41
- (1) assert copyright on the software, and (2) offer you this License
42
- giving you legal permission to copy, distribute and/or modify it.
43
-
44
- For the developers' and authors' protection, the GPL clearly explains
45
- that there is no warranty for this free software. For both users' and
46
- authors' sake, the GPL requires that modified versions be marked as
47
- changed, so that their problems will not be attributed erroneously to
48
- authors of previous versions.
49
-
50
- Some devices are designed to deny users access to install or run
51
- modified versions of the software inside them, although the manufacturer
52
- can do so. This is fundamentally incompatible with the aim of
53
- protecting users' freedom to change the software. The systematic
54
- pattern of such abuse occurs in the area of products for individuals to
55
- use, which is precisely where it is most unacceptable. Therefore, we
56
- have designed this version of the GPL to prohibit the practice for those
57
- products. If such problems arise substantially in other domains, we
58
- stand ready to extend this provision to those domains in future versions
59
- of the GPL, as needed to protect the freedom of users.
60
-
61
- Finally, every program is threatened constantly by software patents.
62
- States should not allow patents to restrict development and use of
63
- software on general-purpose computers, but in those that do, we wish to
64
- avoid the special danger that patents applied to a free program could
65
- make it effectively proprietary. To prevent this, the GPL assures that
66
- patents cannot be used to render the program non-free.
27
+ Developers that use our General Public Licenses protect your rights
28
+ with two steps: (1) assert copyright on the software, and (2) offer
29
+ you this License which gives you legal permission to copy, distribute
30
+ and/or modify the software.
31
+
32
+ A secondary benefit of defending all users' freedom is that
33
+ improvements made in alternate versions of the program, if they
34
+ receive widespread use, become available for other developers to
35
+ incorporate. Many developers of free software are heartened and
36
+ encouraged by the resulting cooperation. However, in the case of
37
+ software used on network servers, this result may fail to come about.
38
+ The GNU General Public License permits making a modified version and
39
+ letting the public access it on a server without ever releasing its
40
+ source code to the public.
41
+
42
+ The GNU Affero General Public License is designed specifically to
43
+ ensure that, in such cases, the modified source code becomes available
44
+ to the community. It requires the operator of a network server to
45
+ provide the source code of the modified version running there to the
46
+ users of that server. Therefore, public use of a modified version, on
47
+ a publicly accessible server, gives the public access to the source
48
+ code of the modified version.
49
+
50
+ An older license, called the Affero General Public License and
51
+ published by Affero, was designed to accomplish similar goals. This is
52
+ a different license, not a version of the Affero GPL, but Affero has
53
+ released a new version of the Affero GPL which permits relicensing under
54
+ this license.
67
55
 
68
56
  The precise terms and conditions for copying, distribution and
69
57
  modification follow.
@@ -72,7 +60,7 @@ modification follow.
72
60
 
73
61
  0. Definitions.
74
62
 
75
- "This License" refers to version 3 of the GNU General Public License.
63
+ "This License" refers to version 3 of the GNU Affero General Public License.
76
64
 
77
65
  "Copyright" also means copyright-like laws that apply to other kinds of
78
66
  works, such as semiconductor masks.
@@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
549
537
  the Program, the only way you could satisfy both those terms and this
550
538
  License would be to refrain entirely from conveying the Program.
551
539
 
552
- 13. Use with the GNU Affero General Public License.
540
+ 13. Remote Network Interaction; Use with the GNU General Public License.
541
+
542
+ Notwithstanding any other provision of this License, if you modify the
543
+ Program, your modified version must prominently offer all users
544
+ interacting with it remotely through a computer network (if your version
545
+ supports such interaction) an opportunity to receive the Corresponding
546
+ Source of your version by providing access to the Corresponding Source
547
+ from a network server at no charge, through some standard or customary
548
+ means of facilitating copying of software. This Corresponding Source
549
+ shall include the Corresponding Source for any work covered by version 3
550
+ of the GNU General Public License that is incorporated pursuant to the
551
+ following paragraph.
553
552
 
554
553
  Notwithstanding any other provision of this License, you have
555
554
  permission to link or combine any covered work with a work licensed
556
- under version 3 of the GNU Affero General Public License into a single
555
+ under version 3 of the GNU General Public License into a single
557
556
  combined work, and to convey the resulting work. The terms of this
558
557
  License will continue to apply to the part which is the covered work,
559
- but the special requirements of the GNU Affero General Public License,
560
- section 13, concerning interaction through a network will apply to the
561
- combination as such.
558
+ but the work with which it is combined will remain governed by version
559
+ 3 of the GNU General Public License.
562
560
 
563
561
  14. Revised Versions of this License.
564
562
 
565
563
  The Free Software Foundation may publish revised and/or new versions of
566
- the GNU General Public License from time to time. Such new versions will
567
- be similar in spirit to the present version, but may differ in detail to
564
+ the GNU Affero General Public License from time to time. Such new versions
565
+ will be similar in spirit to the present version, but may differ in detail to
568
566
  address new problems or concerns.
569
567
 
570
568
  Each version is given a distinguishing version number. If the
571
- Program specifies that a certain numbered version of the GNU General
569
+ Program specifies that a certain numbered version of the GNU Affero General
572
570
  Public License "or any later version" applies to it, you have the
573
571
  option of following the terms and conditions either of that numbered
574
572
  version or of any later version published by the Free Software
575
573
  Foundation. If the Program does not specify a version number of the
576
- GNU General Public License, you may choose any version ever published
574
+ GNU Affero General Public License, you may choose any version ever published
577
575
  by the Free Software Foundation.
578
576
 
579
577
  If the Program specifies that a proxy can decide which future
580
- versions of the GNU General Public License can be used, that proxy's
578
+ versions of the GNU Affero General Public License can be used, that proxy's
581
579
  public statement of acceptance of a version permanently authorizes you
582
580
  to choose that version for the Program.
583
581
 
@@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
635
633
  Copyright (C) <year> <name of author>
636
634
 
637
635
  This program is free software: you can redistribute it and/or modify
638
- it under the terms of the GNU General Public License as published by
636
+ it under the terms of the GNU Affero General Public License as published by
639
637
  the Free Software Foundation, either version 3 of the License, or
640
638
  (at your option) any later version.
641
639
 
642
640
  This program is distributed in the hope that it will be useful,
643
641
  but WITHOUT ANY WARRANTY; without even the implied warranty of
644
642
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
- GNU General Public License for more details.
643
+ GNU Affero General Public License for more details.
646
644
 
647
- You should have received a copy of the GNU General Public License
645
+ You should have received a copy of the GNU Affero General Public License
648
646
  along with this program. If not, see <https://www.gnu.org/licenses/>.
649
647
 
650
648
  Also add information on how to contact you by electronic and paper mail.
651
649
 
652
- If the program does terminal interaction, make it output a short
653
- notice like this when it starts in an interactive mode:
654
-
655
- <program> Copyright (C) <year> <name of author>
656
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
- This is free software, and you are welcome to redistribute it
658
- under certain conditions; type `show c' for details.
659
-
660
- The hypothetical commands `show w' and `show c' should show the appropriate
661
- parts of the General Public License. Of course, your program's commands
662
- might be different; for a GUI interface, you would use an "about box".
650
+ If your software can interact with users remotely through a computer
651
+ network, you should also make sure that it provides a way for users to
652
+ get its source. For example, if your program is a web application, its
653
+ interface could display a "Source" link that leads users to an archive
654
+ of the code. There are many ways you could offer source, and different
655
+ solutions will be better for different programs; see section 13 for the
656
+ specific requirements.
663
657
 
664
658
  You should also get your employer (if you work as a programmer) or school,
665
659
  if any, to sign a "copyright disclaimer" for the program, if necessary.
666
- For more information on this, and how to apply and follow the GNU GPL, see
667
- <https://www.gnu.org/licenses/>.
668
-
669
- The GNU General Public License does not permit incorporating your program
670
- into proprietary programs. If your program is a subroutine library, you
671
- may consider it more useful to permit linking proprietary applications with
672
- the library. If this is what you want to do, use the GNU Lesser General
673
- Public License instead of this License. But first, please read
674
- <https://www.gnu.org/licenses/why-not-lgpl.html>.
660
+ For more information on this, and how to apply and follow the GNU AGPL, see
661
+ <https://www.gnu.org/licenses/>.
package/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # Expand IAM Actions
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@cloud-copilot/iam-expand.svg?logo=nodedotjs)](https://www.npmjs.com/package/@cloud-copilot/iam-expand) [![License: AGPL v3](https://img.shields.io/github/license/cloud-copilot/iam-expand)](LICENSE.txt) [![GuardDog](https://github.com/cloud-copilot/iam-expand/actions/workflows/guarddog.yml/badge.svg)](https://github.com/cloud-copilot/iam-expand/actions/workflows/guarddog.yml) [![Known Vulnerabilities](https://snyk.io/test/github/cloud-copilot/iam-expand/badge.svg?targetFile=package.json&style=flat-square)](https://snyk.io/test/github/cloud-copilot/iam-expand?targetFile=package.json)
4
+
2
5
  Built in the Unix philosophy, this is a small tool that does one thing well: explain IAM actions with wildcards.
3
6
 
4
7
  Use this to:
5
- 1) Expand wildcards when you are not allowed to use them in your policies.
6
- 2) Get an exhaustive list of actions that are included in a policy to quickly search it for interesting actions.
7
- 3) Investigate where interesting or dubious actions are being used in your policies.
8
+
9
+ 1. Expand wildcards when you are not allowed to use them in your policies.
10
+ 2. Get an exhaustive list of actions that are included in a policy to quickly search it for interesting actions.
11
+ 3. Investigate where interesting or dubious actions are being used in your policies.
8
12
 
9
13
  <!-- Image of demo.svg -->
14
+
10
15
  ![Demo](assets/demo.svg)
11
16
 
12
17
  Extended demo [on YouTube](https://www.youtube.com/watch?v=357-uGru7300).
@@ -16,23 +21,31 @@ Published as an [npm package](#typescriptnodejs-usage) in ESM and CommonJS plus
16
21
  All information is sourced from [@cloud-copilot/iam-data](https://github.com/cloud-copilot/iam-data) which is updated daily.
17
22
 
18
23
  ## Only Valid Values
24
+
19
25
  `iam-expand` intends to only return valid, actual actions, if any invalid values are passed in such as an invalid format or a service/action that does not exist, they will be left out of the output. There are options to override this behavior.
20
26
 
21
27
  ## Use In Browser
28
+
22
29
  [http://iam.cloudcopilot.io/tools/iam-expand](http://iam.cloudcopilot.io/tools/iam-expand)
23
30
 
24
31
  ## CLI
32
+
25
33
  There is a CLI! The [examples folder](examples/README.md) has examples showing how to use the CLI to find interesting actions in your IAM policies.
26
34
 
27
35
  ### Global CLI Installation
36
+
28
37
  You can install it globally. This also works in the default AWS CloudShell!
38
+
29
39
  ```bash
30
40
  npm install -g @cloud-copilot/iam-expand
31
41
  ```
32
- *Depending on your configuration sudo may be required to install globally.*
42
+
43
+ _Depending on your configuration sudo may be required to install globally._
33
44
 
34
45
  ### Install CLI In a Project
46
+
35
47
  You can also install the CLI in a project and run it with `npx`.
48
+
36
49
  ```bash
37
50
  npm install @cloud-copilot/iam-expand
38
51
  # Run with npx inside your project
@@ -40,7 +53,9 @@ npx @cloud-copilot/iam-expand
40
53
  ```
41
54
 
42
55
  ### Expand Actions
56
+
43
57
  The simplest usage is to pass in the actions you want to expand.
58
+
44
59
  ```bash
45
60
  iam-expand s3:Get*Tagging
46
61
  # Outputs all Get*Tagging actions
@@ -67,7 +82,9 @@ s3:PutStorageLensConfigurationTaggin
67
82
  ```
68
83
 
69
84
  ### Inverting Actions
85
+
70
86
  Use this to find all actions that are not in a set of patterns
87
+
71
88
  ```bash
72
89
  iam-expand --invert s3:Get*Tagging s3:Put*Tagging
73
90
  #Outputs all actions that are not Get*Tagging or Put*Tagging
@@ -81,7 +98,9 @@ a4b:AssociateContactWithAddressBook
81
98
  ```
82
99
 
83
100
  ### Help
101
+
84
102
  Run the command with no options to show usage:
103
+
85
104
  ```bash
86
105
  iam-expand
87
106
  ```
@@ -89,7 +108,9 @@ iam-expand
89
108
  ### Options
90
109
 
91
110
  #### `--expand-asterisk`
111
+
92
112
  By default, a single `*` will not be expanded. If you want to expand a single `*` you can set this flag.
113
+
93
114
  ```bash
94
115
  iam-expand "*"
95
116
  # Returns the asterisk
@@ -100,9 +121,11 @@ iam-expand --expand-asterisk "*"
100
121
  ```
101
122
 
102
123
  #### `--error-on-invalid-format`
124
+
103
125
  By default, if an invalid format is passed in, such as:
104
- * `s3Get*Tagging` (missing a separator) or
105
- * `s3:Get:Tagging*` (too many separators)
126
+
127
+ - `s3Get*Tagging` (missing a separator) or
128
+ - `s3:Get:Tagging*` (too many separators)
106
129
 
107
130
  it will be silenty ignored and left out of the output. If you want to throw an error when an invalid format is passed in you can set this flag.
108
131
 
@@ -116,6 +139,7 @@ iam-expand --error-on-invalid-format "s3Get*Tagging"
116
139
  ```
117
140
 
118
141
  #### `--error-on-invalid-service`
142
+
119
143
  By default, if a service is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. If you want to throw an error when a service is passed in that does not exist you can set this flag.
120
144
 
121
145
  ```bash
@@ -128,26 +152,29 @@ iam-expand --error-on-invalid-service "r2:Get*Tagging"
128
152
  ```
129
153
 
130
154
  #### `--invalid-action-behavior`
155
+
131
156
  By default, if an action is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. There are two options to override this behavior: `error` and `include`.
132
157
 
133
158
  ```bash
134
159
  iam-expand "ec2:DestroyAvailabilityZone"
135
160
  # Returns nothing
136
161
 
137
- iam-expand --invalid-action-behavior=remove "ec2:DestroyAvailabilityZone"
162
+ iam-expand --invalid-action-behavior remove "ec2:DestroyAvailabilityZone"
138
163
  # Returns nothing
139
164
 
140
- iam-expand --invalid-action-behavior=error "ec2:DestroyAvailabilityZone"
165
+ iam-expand --invalid-action-behavior error "ec2:DestroyAvailabilityZone"
141
166
  # Throws an error and returns a non zero exit code
142
167
  # Invalid action: ec2:DestroyAvailabilityZone
143
168
 
144
- iam-expand --invalid-action-behavior=include "ec2:DestroyAvailabilityZone"
169
+ iam-expand --invalid-action-behavior include "ec2:DestroyAvailabilityZone"
145
170
  # Returns the invalid action
146
171
  ec2:DestroyAvailabilityZone
147
172
  ```
148
173
 
149
174
  #### `--invert`
175
+
150
176
  Use this to find all actions that are not in a set of patterns. Only works for actions passed as arguments, or unstructured content from stdin.
177
+
151
178
  ```bash
152
179
  iam-expand --invert s3:Get*Tagging s3:Put*Tagging
153
180
  #Outputs all actions that are not Get*Tagging or Put*Tagging
@@ -161,13 +188,17 @@ a4b:AssociateContactWithAddressBook
161
188
  ```
162
189
 
163
190
  #### `--invert-not-actions`
164
- *This operates only on JSON input*. It will recursively search the JSON document for any `NotAction` that is a string or an array of strings. The `NotAction` will be replaced with an `Action` key that is the inverse of the `NotAction` actions or patterns.
191
+
192
+ _This operates only on JSON input_. It will recursively search the JSON document for any `NotAction` that is a string or an array of strings. The `NotAction` will be replaced with an `Action` key that is the inverse of the `NotAction` actions or patterns.
193
+
165
194
  ```bash
166
195
  cat policy.json | iam-expand --invert-not-actions
167
196
  ```
197
+
168
198
  See [Read from Stdin](#read-from-stdin) for more details
169
199
 
170
200
  #### `--show-data-version`
201
+
171
202
  Show the version of the data that is being used to expand the actions and exit.
172
203
 
173
204
  ```bash
@@ -180,26 +211,29 @@ Update with either:
180
211
  ```
181
212
 
182
213
  #### `--read-wait-ms`
214
+
183
215
  When reading from stdin (see [below](#read-from-stdin)) the CLI will wait 10 seconds for the first byte to be read before timing out. This is enough time for most operations. If you want to wait longer you can set this flag to the number of milliseconds you want to wait.
184
216
 
185
217
  ```bash
186
218
  cat policy.json | iam-expand
187
219
  # Will wait up to 10 seconds for input to start, which is plenty of time for a local file.
188
220
 
189
- curl "https://government-secrets.s3.amazonaws.com/secret-policy.json" | iam-expand --read-wait-ms=20_000
221
+ curl "https://government-secrets.s3.amazonaws.com/secret-policy.json" | iam-expand --read-wait-ms 20000
190
222
  # Will wait up to 20 seconds to receive first byte from curl before timing out. Adjust as needed
191
223
  ```
192
224
 
193
225
  ### Read from stdin
226
+
194
227
  If no actions are passed as arguments, the CLI will read from stdin.
195
228
 
196
229
  #### Expanding JSON input
230
+
197
231
  If the input is a valid json document, the CLI will find every instance of `Action` and `NotAction` that is a string or an array of strings and expand them. This is useful for finding all the actions in a policy document or set of documents.
198
232
 
199
233
  Given `policy.json`
200
- ```json
201
234
 
202
- {
235
+ ```json
236
+ {
203
237
  "Version": "2012-10-17",
204
238
  "Statement": [
205
239
  {
@@ -213,7 +247,7 @@ Given `policy.json`
213
247
  "Resource": "*"
214
248
  }
215
249
  ]
216
- }
250
+ }
217
251
  ```
218
252
 
219
253
  ```bash
@@ -221,6 +255,7 @@ cat policy.json | iam-expand > expanded-policy.json
221
255
  ```
222
256
 
223
257
  Gives this file in `expanded-policy.json`
258
+
224
259
  ```json
225
260
  {
226
261
  "Version": "2012-10-17",
@@ -255,15 +290,17 @@ Gives this file in `expanded-policy.json`
255
290
  "Resource": "*"
256
291
  }
257
292
  ]
258
- }
293
+ }
259
294
  ```
260
295
 
261
- You can also invert the `NotAction` using `--invert-not-actions`. This will replace the `NotAction` element with an `Action` element that is the inverse of actions listed in the `NotAction`.
296
+ You can also invert the `NotAction` using `--invert-not-actions`. This will replace the `NotAction` element with an `Action` element that is the inverse of actions listed in the `NotAction`.
297
+
262
298
  ```bash
263
299
  cat policy.json | iam-expand --invert-not-actions > inverted-policy.json
264
300
  ```
265
301
 
266
302
  Gives this file in `inverted-policy.json`
303
+
267
304
  ```json
268
305
  {
269
306
  "Version": "2012-10-17",
@@ -299,38 +336,44 @@ Gives this file in `inverted-policy.json`
299
336
  }
300
337
  ```
301
338
 
302
-
303
339
  You can also use this to expand the actions from the output of commands.
340
+
304
341
  ```bash
305
- aws iam get-account-authorization-details --output json | iam-expand --read-wait-ms=20_000 > expanded-authorization-details.json
342
+ aws iam get-account-authorization-details --output json | iam-expand --read-wait-ms 20000 > expanded-authorization-details.json
306
343
  # Now you can search the output for actions you are interested in
307
344
  grep -n "kms:DisableKey" expanded-authorization-details.json
308
345
  ```
309
346
 
310
347
  #### Expanding arbitrary input
348
+
311
349
  If the input from stdin is not json, the content is searched for IAM actions then expands them. Throw anything at it and it will find all the actions it can and expand them.
312
350
 
313
351
  You can echo content:
352
+
314
353
  ```bash
315
354
  echo "s3:Get*Tagging" | iam-expand
316
355
  ```
317
356
 
318
357
  You can pull out part of a json file and pipe it in:
358
+
319
359
  ```bash
320
360
  cat policy.json | jq '.Statement[].Action' | iam-expand
321
361
  ```
322
362
 
323
363
  Or some Terraform:
364
+
324
365
  ```bash
325
366
  cat main.tf | iam-expand
326
367
  ```
327
368
 
328
369
  Or some CloudFormation:
370
+
329
371
  ```bash
330
372
  cat template.yaml | iam-expand
331
373
  ```
332
374
 
333
375
  Or even some HTML:
376
+
334
377
  ```bash
335
378
  curl "https://docs.aws.amazon.com/aws-managed-policy/latest/reference/ReadOnlyAccess.html" | iam-expand
336
379
  ```
@@ -344,25 +387,24 @@ Please give this anything you can think of and open an issue if you see an oppor
344
387
  ## Typescript/NodeJS Usage
345
388
 
346
389
  ## Add to a project
390
+
347
391
  ```bash
348
392
  npm install @cloud-copilot/iam-expand
349
393
  ```
350
394
 
351
395
  ```typescript
352
- import { expandIamActions } from '@cloud-copilot/iam-expand';
396
+ import { expandIamActions } from '@cloud-copilot/iam-expand'
353
397
 
354
- expandIamActions('s3:Get*Tagging')
355
- [
356
- 's3:GetBucketTagging',
398
+ expandIamActions('s3:Get*Tagging')[
399
+ ('s3:GetBucketTagging',
357
400
  's3:GetJobTagging',
358
401
  's3:GetObjectTagging',
359
402
  's3:GetObjectVersionTagging',
360
- 's3:GetStorageLensConfigurationTagging'
403
+ 's3:GetStorageLensConfigurationTagging')
361
404
  ]
362
405
 
363
- expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])
364
- [
365
- 's3:GetBucketTagging',
406
+ expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])[
407
+ ('s3:GetBucketTagging',
366
408
  's3:GetJobTagging',
367
409
  's3:GetObjectTagging',
368
410
  's3:GetObjectVersionTagging',
@@ -371,24 +413,28 @@ expandIamActions(['s3:Get*Tagging', 's3:Put*Tagging'])
371
413
  's3:PutJobTagging',
372
414
  's3:PutObjectTagging',
373
415
  's3:PutObjectVersionTagging',
374
- 's3:PutStorageLensConfigurationTagging'
416
+ 's3:PutStorageLensConfigurationTagging')
375
417
  ]
376
418
  ```
377
419
 
378
420
  ## API Reference
379
421
 
380
422
  ## `expandIamActions`
423
+
381
424
  `expandIamActions(actionStringOrStrings: string | string[], overrideOptions?: Partial<ExpandIamActionsOptions>)` is the main function that will expand the actions of the IAM policy. Takes a string or array of strings and returns an array of strings that the input matches.
382
425
 
383
426
  ## Only Valid Values
427
+
384
428
  `expandIamActions` intends to only return valid actual actions, if any invalid values are passed in such as an invalid format or a service/action that does not exist, they will be left out of the output. There are options to override this behavior.
385
429
 
386
430
  Any escaped unicode characters will be converted to their original character as part of the process. So `s3:\\u0067et*` will be converted to `s3:Get*` before processing. Even something like `s3:\\u0067etBucket` will be converted to `s3:GetBucket` even though it has no wildcards..
387
431
 
388
432
  ## Options
433
+
389
434
  `expandIamActions` an optional second argument that is an object with the following options:
390
435
 
391
436
  ### `expandAsterisk`
437
+
392
438
  By default, a single `*` will not be expanded. If you want to expand a single `*` you can set this option to `true`.
393
439
 
394
440
  ```typescript
@@ -406,9 +452,11 @@ expandIamActions('*', { expandAsterisk: true })
406
452
  ```
407
453
 
408
454
  ### `errorOnInvalidFormat`
455
+
409
456
  By default, if an invalid format is passed in, such as:
410
- * `s3Get*Tagging` (missing a separator) or
411
- * `s3:Get:Tagging*` (too many separators)
457
+
458
+ - `s3Get*Tagging` (missing a separator) or
459
+ - `s3:Get:Tagging*` (too many separators)
412
460
 
413
461
  it will be silenty ignored and left out of the output. If you want to throw an error when an invalid format is passed in you can set this option to `true`.
414
462
 
@@ -425,6 +473,7 @@ expandIamActions('s3Get*Tagging', { errorOnInvalidFormat: true })
425
473
  ```
426
474
 
427
475
  ### `errorOnInvalidService`
476
+
428
477
  By default, if a service is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. If you want to throw an error when a service is passed in that does not exist you can set this option to `true`.
429
478
 
430
479
  ```typescript
@@ -440,6 +489,7 @@ expandIamActions('r2:Get*Tagging', { errorOnInvalidService: true })
440
489
  ```
441
490
 
442
491
  ### `invalidActionBehavior`
492
+
443
493
  By default, if an action is passed in that does not exist in the IAM data, it will be silently ignored and left out of the output. There are two options to override this behavior: `Error` and `Include`.
444
494
 
445
495
  ```typescript
@@ -463,4 +513,5 @@ expandIamActions('ec2:DestroyAvailabilityZone', { invalidActionBehavior: Invalid
463
513
  ```
464
514
 
465
515
  ## `invertIamActions`
516
+
466
517
  `invertIamActions(actionString: string): string` will take an action string and return all actions not matching . For example `s3:Get*Tagging` will return all actions from all services except those s3 actions that match the pattern `Get*Tagging`.