himeko 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ec73d436456f48b981f861f43cd22940ec65864187515fa8da1e25c77d05437b
4
+ data.tar.gz: 57152737ab13f989ee00c057b2a34ce96569e042eab9d2130d73ef14cc15a090
5
+ SHA512:
6
+ metadata.gz: 90092bab2ef26bdf062a431370a2b003778765aa93c9e040bbfc63b3cab7ef802762a7145c7c28730dc2ed1c57b42d7061864ad1f254c520b83365844757cb54
7
+ data.tar.gz: 488debec5714a9f52f2f9ef0027c4dd94068bd8de4e018cb0d92a048b906608637c103c8b1201cec3d83e82e7858f9336bb17694dedb0d41c96b6d94c5277e50
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.6.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'omniauth'
5
+ gem 'omniauth-google-oauth2'
6
+ gem 'omniauth-github'
7
+
8
+ gem 'puma'
@@ -0,0 +1,98 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ himeko (0.1.0)
5
+ aws-sdk-core
6
+ aws-sdk-dynamodb
7
+ aws-sdk-iam
8
+ erubi
9
+ rack-protection
10
+ sinatra
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ aws-eventstream (1.0.1)
16
+ aws-partitions (1.104.0)
17
+ aws-sdk-core (3.27.0)
18
+ aws-eventstream (~> 1.0)
19
+ aws-partitions (~> 1.0)
20
+ aws-sigv4 (~> 1.0)
21
+ jmespath (~> 1.0)
22
+ aws-sdk-dynamodb (1.13.0)
23
+ aws-sdk-core (~> 3, >= 3.26.0)
24
+ aws-sigv4 (~> 1.0)
25
+ aws-sdk-iam (1.8.0)
26
+ aws-sdk-core (~> 3, >= 3.26.0)
27
+ aws-sigv4 (~> 1.0)
28
+ aws-sigv4 (1.0.3)
29
+ diff-lcs (1.3)
30
+ erubi (1.7.1)
31
+ faraday (0.12.2)
32
+ multipart-post (>= 1.2, < 3)
33
+ hashie (3.5.7)
34
+ jmespath (1.4.0)
35
+ jwt (1.5.6)
36
+ multi_json (1.13.1)
37
+ multi_xml (0.6.0)
38
+ multipart-post (2.0.0)
39
+ mustermann (1.0.3)
40
+ oauth2 (1.4.0)
41
+ faraday (>= 0.8, < 0.13)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (>= 1.2, < 3)
46
+ omniauth (1.8.1)
47
+ hashie (>= 3.4.6, < 3.6.0)
48
+ rack (>= 1.6.2, < 3)
49
+ omniauth-github (1.3.0)
50
+ omniauth (~> 1.5)
51
+ omniauth-oauth2 (>= 1.4.0, < 2.0)
52
+ omniauth-google-oauth2 (0.5.3)
53
+ jwt (>= 1.5)
54
+ omniauth (>= 1.1.1)
55
+ omniauth-oauth2 (>= 1.5)
56
+ omniauth-oauth2 (1.5.0)
57
+ oauth2 (~> 1.1)
58
+ omniauth (~> 1.2)
59
+ puma (3.12.0)
60
+ rack (2.0.5)
61
+ rack-protection (2.0.3)
62
+ rack
63
+ rake (12.3.1)
64
+ rspec (3.8.0)
65
+ rspec-core (~> 3.8.0)
66
+ rspec-expectations (~> 3.8.0)
67
+ rspec-mocks (~> 3.8.0)
68
+ rspec-core (3.8.0)
69
+ rspec-support (~> 3.8.0)
70
+ rspec-expectations (3.8.1)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.8.0)
73
+ rspec-mocks (3.8.0)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.8.0)
76
+ rspec-support (3.8.0)
77
+ sinatra (2.0.3)
78
+ mustermann (~> 1.0)
79
+ rack (~> 2.0)
80
+ rack-protection (= 2.0.3)
81
+ tilt (~> 2.0)
82
+ tilt (2.0.8)
83
+
84
+ PLATFORMS
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ bundler
89
+ himeko!
90
+ omniauth
91
+ omniauth-github
92
+ omniauth-google-oauth2
93
+ puma
94
+ rake
95
+ rspec (~> 3.0)
96
+
97
+ BUNDLED WITH
98
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sorah Fukumori
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,170 @@
1
+ # Himeko: AWS IAM access key self service & management console federated login
2
+
3
+ This web application provides self service of AWS IAM access keys (which belongs to an IAM user) and management console federated logging in via an auto generated IAM role which mimicked the IAM user.
4
+
5
+ 1. Prepare proper authentication method for this web application (Pass IAM username for the authenticated user as a Rack environment)
6
+ 2. This webapp creates an IAM role from the authenticated IAM user (when it hasn't existed yet)
7
+ 3. This webapp redirects the user to AWS management console via Federated Login https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_enable-console-custom-url.html
8
+
9
+ ## Prerequisites
10
+
11
+ - DynamoDB table for managing temporary IAM roles
12
+ - primary key: `username` (string)
13
+ - (optional, recommended) AWS IAM _user_ for calling `sts:AssumeRole`
14
+ - AWS restricts having more than an hour for session `DurationSeconds` when assuming a new role using an identity derived from IAM roles (["Role Chaining"](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html))
15
+ - At [Cookpad](https://info.cookpad.com/), we use [Vault AWS Secrets Engine](https://www.vaultproject.io/docs/secrets/aws/index.html) to rotate IAM user access key for `sts:AssumeRole` API calls.
16
+
17
+ ## Set up
18
+
19
+ This application is implemented as a Rack application.
20
+
21
+ ```ruby
22
+ # Gemfile
23
+ source 'https://rubygems.org'
24
+ gem 'himeko'
25
+ ```
26
+
27
+ ### Web app: Authentication
28
+
29
+ Make sure to set the following rack environment variable to a request before passing it to the application.
30
+
31
+ - `himeko.user`: IAM user name authenticated for the request
32
+
33
+ It is your responsibility to provide proper user data to this application.
34
+
35
+ Refer to [config.ru](./config.ru) for the example configuration. It uses OmniAuth for user authentication and the inline middleware ensures to set `himeko.user` for `Himeko::App`.
36
+
37
+ ### Batch tasks: Cleaning temporary IAM roles
38
+
39
+ Set up to run the following task periodically on your system:
40
+
41
+ ```
42
+ bundle exec himeko-clean-roles
43
+ ```
44
+
45
+ This command accepts the following environment variables:
46
+
47
+ - `HIMEKO_ROLE_PATH`
48
+ - `HIMEKO_ROLE_PREFIX`
49
+ - `HIMEKO_DYNAMODB_TABLE`
50
+
51
+ ### Docker Image
52
+
53
+ TODO:
54
+
55
+ But since the configuration above is required, you'll need to add your `config.ru` to the image or bind mount your `config.ru` on runtime.
56
+
57
+ ## Management
58
+
59
+ ### IAM Policy
60
+
61
+ #### Access Key Management
62
+
63
+ ``` json
64
+ {
65
+ "Version": "2012-10-17",
66
+ "Statement": [
67
+ {
68
+ "Action": [
69
+ "iam:CreateAccessKey",
70
+ "iam:DeleteAccessKey",
71
+ "iam:GetAccessKeyLastUsed",
72
+ "iam:ListAccessKeys",
73
+ "iam:UpdateAccessKey"
74
+ ],
75
+ "Effect": "Allow",
76
+ "Resource": [
77
+ "arn:aws:iam::*:user/*"
78
+ ]
79
+ }
80
+ ]
81
+ }
82
+ ```
83
+
84
+ #### Role creation and management for user console access
85
+
86
+ ``` json
87
+ {
88
+ "Version": "2012-10-17",
89
+ "Statement": [
90
+ {
91
+ "Action": [
92
+ "dynamodb:DescribeTable",
93
+ "dynamodb:Query",
94
+ "dynamodb:Scan",
95
+ "dynamodb:GetItem",
96
+ "dynamodb:BatchGetItem",
97
+ "dynamodb:PutItem",
98
+ "dynamodb:UpdateItem",
99
+ "dynamodb:DeleteItem"
100
+ ],
101
+ "Effect": "Allow",
102
+ "Resource": [
103
+ "arn:aws:dynamodb:REGION:ACCOUNT:table/TABLE",
104
+ "arn:aws:dynamodb:REGION:ACCOUNT:table/TABLE/index/*"
105
+ ]
106
+ },
107
+ {
108
+ "Action": [
109
+ "iam:CreateRole",
110
+ "iam:DeleteRole",
111
+ "iam:AttachRolePolicy",
112
+ "iam:DetachRolePolicy",
113
+ "iam:DeleteRolePolicy",
114
+ "iam:GetGroupPolicy",
115
+ "iam:GetUserPolicy",
116
+ "iam:GetUser",
117
+ "iam:ListAttachedGroupPolicies",
118
+ "iam:ListAttachedRolePolicies",
119
+ "iam:ListAttachedUserPolicies",
120
+ "iam:ListGroupPolicies",
121
+ "iam:ListGroupsForUser",
122
+ "iam:ListRolePolicies",
123
+ "iam:ListUserPolicies",
124
+ "iam:PutRolePolicy"
125
+ ],
126
+ "Effect": "Allow",
127
+ "Resource": [
128
+ "arn:aws:iam::ACCOUNT:user/*",
129
+ "arn:aws:iam::ACCOUNT:group/*",
130
+ "arn:aws:iam::ACCOUNT:role/user-role/*"
131
+ ]
132
+ }
133
+ ]
134
+ }
135
+ ```
136
+
137
+ (`/user-role/` is a default path for IAM roles which this webapp creates)
138
+
139
+ #### Console Login
140
+
141
+ ```json
142
+ {
143
+ "Version": "2012-10-17",
144
+ "Statement": [
145
+ {
146
+ "Effect": "Allow",
147
+ "Action": [
148
+ "sts:AssumeRole"
149
+ ],
150
+ "Resource": [
151
+ "arn:aws:iam::ACCOUNT:role/user-role/*"
152
+ ]
153
+ }
154
+ ]
155
+ }
156
+ ```
157
+
158
+ ## Development
159
+
160
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
161
+
162
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
163
+
164
+ ## Contributing
165
+
166
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/himeko.
167
+
168
+ ## License
169
+
170
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,257 @@
1
+ * {
2
+ font-family: 'Helvetica Neue', 'Arial', sans-serif;
3
+ }
4
+ input {
5
+ font-size: 16px;
6
+ }
7
+ pre, code {
8
+ font-family: 'Monaco', monospace;
9
+ }
10
+ pre, pre code {
11
+ width: 100%;
12
+ white-space: pre-wrap;
13
+ word-wrap: break-word;
14
+ font-size: 14px;
15
+ }
16
+ strong {
17
+ font-weight: bold;
18
+ }
19
+ small, small * {
20
+ font-size: 12px;
21
+ }
22
+
23
+ .center {
24
+ text-align: center;
25
+ }
26
+ .right {
27
+ text-align: right;
28
+ }
29
+ .text-muted, .text-muted * {
30
+ color: #767676;
31
+ }
32
+ .hidden {
33
+ display: none;
34
+ }
35
+ h1, h2, h3, h4, h5, h6 {
36
+ color: #212121;
37
+ }
38
+
39
+ a {
40
+ color: #337ab7;
41
+ text-decoration: none;
42
+ }
43
+
44
+ body {
45
+ text-align: center;
46
+ font-size: 16px;
47
+ color: #545454;
48
+ background-color: white;
49
+ }
50
+
51
+ .container {
52
+ margin-left: auto;
53
+ margin-right: auto;
54
+ width: 900px;
55
+ text-align: left;
56
+ padding-top: 12px;
57
+ }
58
+ @media all and (max-width: 900px) {
59
+ .container {
60
+ width: 100%;
61
+ }
62
+ }
63
+
64
+ .box, .form, .notice, .error {
65
+ border-radius: 3px;
66
+ margin-bottom: 12px;
67
+ padding: 8px 20px;
68
+ }
69
+
70
+ .box {
71
+ }
72
+
73
+ .notice {
74
+ border: 1px solid #D6E9C6;
75
+ background-color: #DFF0D8;
76
+ color: #3C763D;
77
+ }
78
+
79
+ .error {
80
+ border: 1px solid #EBCCD1;
81
+ background-color: #F2DEDE;
82
+ color: #A94442;
83
+ }
84
+
85
+ .btn-link {
86
+ -moz-box-sizing: border-box;
87
+ -webkit-box-sizing: border-box;
88
+ box-sizing: border-box;
89
+
90
+ padding: 3px 5px;
91
+
92
+ border: 1px solid #337ab7;
93
+ border-radius: 3px;
94
+
95
+ color: #337ab7;
96
+
97
+ text-decoration: none;
98
+ }
99
+ .btn-danger, button.btn-danger[type="submit"], button.btn-danger:hover[type="submit"] {
100
+ border: 1px solid #f2dede;
101
+ color: #fff;
102
+ background-color: #a94442;
103
+ }
104
+
105
+ .box input, .box button {
106
+ -moz-box-sizing: border-box;
107
+ -webkit-box-sizing: border-box;
108
+ box-sizing: border-box;
109
+
110
+ padding: 6px 10px;
111
+
112
+ border: 1px solid #e9e9e9;
113
+ border-radius: 3px;
114
+ }
115
+
116
+ input[type="submit"], button {
117
+ font-size: 16px;
118
+ padding: 6px 12px;
119
+ }
120
+ button.btn {
121
+ background-color: #6d757d;
122
+ color: white;
123
+ }
124
+ input[type="submit"], button.btn-primary {
125
+ background-color: #337AB7;
126
+ color: white;
127
+ }
128
+
129
+ input[type="submit"]:hover, button.btn-primary:hover {
130
+ background-color: #286090;
131
+ }
132
+
133
+ .form-row {
134
+ margin-bottom: 5px;
135
+ }
136
+ .form-row label {
137
+ display: inline-block;
138
+ width: 10%;
139
+ }
140
+ .form-row input {
141
+ width: 85%;
142
+ }
143
+
144
+ /* */
145
+
146
+ header.header {
147
+ font-size: 14px;
148
+ }
149
+ header.header h1 a {
150
+ color: black;
151
+ }
152
+ header.header a {
153
+ color: #545454;
154
+ text-decoration: none;
155
+ }
156
+ header.header a:hover {
157
+ color: #767676;
158
+ }
159
+ header.header h1.logo {
160
+ display: inline-block;
161
+ font-weight: bold;
162
+ font-size: 14px;
163
+ margin: 0;
164
+ padding: 0;
165
+ }
166
+ header.header nav {
167
+ float: right;
168
+ }
169
+ header.header nav a {
170
+ display: inline-block;
171
+ text-decoration: underline;
172
+ margin-left: 6px;
173
+ margin-right: 6px;
174
+ }
175
+
176
+ /* */
177
+
178
+ footer {
179
+ text-align: center;
180
+ }
181
+ footer a {
182
+ text-decoration: underline;
183
+ }
184
+
185
+ footer, footer * {
186
+ color: #767676;
187
+ font-size: 12px;
188
+ }
189
+
190
+ /* */
191
+
192
+ .iam-key-info {
193
+ width: 90%;
194
+ }
195
+ .iam-key-actions {
196
+ align-self: center;
197
+ text-align: center;
198
+ width: 10%;
199
+ }
200
+ .iam-key {
201
+ display: flex;
202
+ margin: 12px 0;
203
+ }
204
+ .iam-key h3 {
205
+ margin: 0;
206
+ }
207
+
208
+ /* */
209
+
210
+ .iam-secret-key {
211
+ text-align: center;
212
+ }
213
+ .iam-secret-key > div {
214
+ text-align: left;
215
+ margin-left: auto;
216
+ margin-right: auto;
217
+ width: 60%;
218
+ }
219
+ @media all and (max-width: 900px) {
220
+ .iam-secret-key > div {
221
+ width: 100%;
222
+ }
223
+ }
224
+
225
+ /* */
226
+
227
+ .access-console-form {
228
+ text-align: center;
229
+ margin: 30px 0;
230
+ }
231
+
232
+ .access-console-form form p {
233
+ margin: 5px 0;
234
+ }
235
+
236
+ .access-console-form form button {
237
+ font-size: 32px;
238
+ padding: 8px 18px;
239
+ }
240
+
241
+ div.access-console-form-loading {
242
+ display: none;
243
+ }
244
+ .access-console-form.access-console-form-submitted form {
245
+ display: none;
246
+ }
247
+ .access-console-form.access-console-form-submitted div.access-console-form-loading {
248
+ display: block;
249
+ }
250
+
251
+ .access-console-form-auto {
252
+ display: none;
253
+ }
254
+ .access-console-form-auto.access-console-form-auto-enabled {
255
+ display: block;
256
+ }
257
+