azure-credentials 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 043fe11054aecc92ceba59808f4850cfb4eb0c88
4
- data.tar.gz: a95b3cb97fa7c124a142cade63d5e8bf90616ea6
2
+ SHA256:
3
+ metadata.gz: 41054f1415829e4fd56cac250fe8d16c273eca28a1b223fe5803d3a9f14f3356
4
+ data.tar.gz: 986b378c95b3fbfd7cfdad139f8c10df9c95fa12ca3eff87f65d061f8fce9982
5
5
  SHA512:
6
- metadata.gz: 0457229e97bd923d5fe1ce9a6e575d12a2e94a86f086e3ce50506598ce1dbd3344ed2ba578634b07b0489f590667142e4ed3d99fb4c970023f6f3e3a93be71a0
7
- data.tar.gz: 63d6ace23649ac547da91ce7d496f4d12235e0d9184f4ce43b6bb084fca9e18c7fb218114a41b7673df15caadcefb8aef0ea78690586f88aa8b9da2a62292ba2
6
+ metadata.gz: beabe69bbf92b11a2a5189ddf09678f95f312dbce07c8208b3baba8c8474bd7845b8cdf81d83debfeae94eabde2c51bb3987fe3f7f3b3c89c2f9527eb8f5f6a0
7
+ data.tar.gz: e327fcd93169b5b047150397fe8f295cfd74ff7d37113bc4f62a8ba7671790b9f65f96ec88b2ef37df4babd3d7ceaac617688c7bbaf04152c695e65697d88698
@@ -1,6 +1,14 @@
1
- #azure-credentials changelog
2
- ##v0.1.3 (2016-08-16)
3
- - Upgrading dependencies (@stuartpreston)
4
-
5
- ##v0.1.1 (2016-03-31)
6
- - Adding debug to authentication HTTP requests (@stuartpreston)
1
+ # azure-credentials changelog
2
+
3
+ ## v0.1.4 (2018-09-28)
4
+
5
+ - Adding bundler configuration, fix style issues (@stuartpreston)
6
+ - Require io/console module to avoid login failures (@blackknight36)
7
+
8
+ ## v0.1.3 (2016-08-16)
9
+
10
+ - Upgrading dependencies (@stuartpreston)
11
+
12
+ ## v0.1.1 (2016-03-31)
13
+
14
+ - Adding debug to authentication HTTP requests (@stuartpreston)
data/LICENSE CHANGED
@@ -1,14 +1,14 @@
1
-
2
- Copyright 2016 Pendrica Ltd
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
1
+
2
+ Copyright 2016 Pendrica Ltd
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
data/README.md CHANGED
@@ -1,204 +1,204 @@
1
- # azure-credentials
2
-
3
- A tool to provide assistance for those struggling to create Applications, Service Principals and perform Role Assignments in Azure Resource Manager.
4
- Generate your credentials file/helper for Chef, Puppet, Terraform and others!
5
-
6
- ## Background
7
-
8
- Automated access to Azure Resource Manager usually requires PowerShell or the Azure-CLI and to follow the (many) manual steps in [create and authenticate a service principal](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#authenticate-service-principal-with-password---azure-cli) to allow you to eventually retrieve 4 pieces of information:
9
-
10
- 1. **Subscription ID**
11
- 2. **Client ID**
12
- 3. **Client Secret/Password**
13
- 4. **Tenant ID**
14
-
15
- ... you then use this information to configure your provisioning system. This tool (created in Ruby) requires only the credentials of the user with global administrator privilege and does the rest of the work for you, making it easier and quicker to get started with the various provisioning and testing toolsets out there.
16
-
17
- ## Installation
18
-
19
- The tool is distributed as a [Ruby Gem](https://rubygems.org/gems/azure-credentials). To install it, run:
20
-
21
- ```gem install azure-credentials```
22
-
23
- ## Usage
24
-
25
- ```
26
- Usage: azure-credentials (options)
27
- -l, --log_level LEVEL Set the log level (debug, info, warn, error, fatal)
28
- -v, --verbose Display the credentials in STDOUT after creation? (warning: will contain secrets)
29
- -o, --output FILENAME Enter the filename to save the credentials to
30
- -p, --password PASSWORD Enter the password for the Azure AD user
31
- -r, --role ROLENAME Enter the built-in Azure role to add the service principal to on your subscription (default: Contributor)
32
- -s, --subscription ID Enter the Subscription ID to work against (default: process all subscriptions within the Azure tenant)
33
- -t, --type OUTPUTTYPE Set the output type (default: chef)
34
- -u, --username USERNAME Enter the username (must be an Azure AD user)
35
- -h, --help Show this message
36
- ```
37
-
38
- ## Default behaviour
39
-
40
- By default (providing no options), the utility will prompt for your Azure AD username and password interactively, connect to Azure, retrieve details of all the subscriptions in your tenant, create an Application/Service Principal for each subscription then create you a credentials file with the relevant details that you can start to use with other tools immediately.
41
-
42
- ### Example output *(nb: ```chef exec``` typically is only required on Windows systems with ChefDK and no Ruby in their system path)*
43
-
44
- ```
45
- PS C:\Users\StuartPreston\azure-credentials> chef exec azure-credentials
46
- Enter your Azure AD username (user@domain.com): stuart@pendrica.com
47
- Enter your password:
48
- INFO [2016-03-28 15:29:37] Authenticating to Azure Active Directory
49
- INFO [2016-03-28 15:29:39] Retrieving tenant info
50
- INFO [2016-03-28 15:29:40] Retrieving subscriptions info
51
- INFO [2016-03-28 15:29:41] Creating application azure_6b3a_b6e7eee9-e4cd-41ae-8432-03ab624df016 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
52
- INFO [2016-03-28 15:29:41] Creating service principal for application
53
- INFO [2016-03-28 15:29:43] Waiting for service principal to be available in directory (retry 1)
54
- INFO [2016-03-28 15:29:45] Attempting to assign service principal to role
55
- INFO [2016-03-28 15:29:45] Waiting for service principal to be available in directory (retry 2)
56
- INFO [2016-03-28 15:29:47] Attempting to assign service principal to role
57
- INFO [2016-03-28 15:29:48] Waiting for service principal to be available in directory (retry 3)
58
- INFO [2016-03-28 15:29:50] Attempting to assign service principal to role
59
- INFO [2016-03-28 15:29:52] Assigned service principal to role Contributor in subscription b6e7eee9-e4cd-41ae-8432-03ab624df016
60
- INFO [2016-03-28 15:29:52] Creating application azure_6b3a_bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
61
- INFO [2016-03-28 15:29:53] Creating service principal for application
62
- INFO [2016-03-28 15:29:54] Waiting for service principal to be available in directory (retry 1)
63
- INFO [2016-03-28 15:29:56] Attempting to assign service principal to role
64
- INFO [2016-03-28 15:29:56] Waiting for service principal to be available in directory (retry 2)
65
- INFO [2016-03-28 15:29:58] Attempting to assign service principal to role
66
- INFO [2016-03-28 15:29:58] Waiting for service principal to be available in directory (retry 3)
67
- INFO [2016-03-28 15:30:00] Attempting to assign service principal to role
68
- INFO [2016-03-28 15:30:04] Assigned service principal to role Contributor in subscription bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3
69
- INFO [2016-03-28 15:30:04] Creating credentials file at C:/Users/StuartPreston/azure-credentials/credentials
70
- INFO [2016-03-28 15:30:04] Done!
71
- ```
72
-
73
- You'll be able to see the output in the created credentials file (don't worry you can change the location using the -o switch)
74
-
75
- ```
76
- PS C:\Users\StuartPreston\azure-credentials> cat ./credentials
77
- [b6e7eee9-e4cd-41ae-8432-03ab624df016]
78
- client_id = "5a8758f2-a2b2-4eab-8203-28c0840ccd7f"
79
- client_secret = "ZSNdI5hQ9toavJNVgRjMjA=="
80
- tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
81
-
82
- [bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3]
83
- client_id = "2205cbcd-84dc-4b4a-9fcf-4a27d773a56d"
84
- client_secret = "KboMQ86BvMGR6vO7_fUd1A=="
85
- tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
86
- ```
87
-
88
- (don't worry these accounts don't exist any more!)
89
-
90
- If you look in the Azure Service Management portal and navigate to Active Directory > [directory name] > Applications (Show: Applications my company owns) you will see Applications created with the **azure_** prefix. New identifiers are generated each time so there will be no overlap with existing accounts:
91
-
92
- ![config](images/configuration_asm.png)
93
-
94
- You will also see the role assignment when looking in the Azure Resource Manager portal > Subscriptions, selecting one and viewing the users:
95
-
96
- ![config](images/configuration_arm.png)
97
-
98
- ## Some more advanced examples
99
-
100
- ### Chef quick config!
101
-
102
- ```azure-credentials -u username@domain.onmicrosoft.com -p "yourpassword" -o ~/.azure/credentials```
103
-
104
- ### Puppet-style output (note ```-v``` displays the file on screen after creation)
105
-
106
- ```azure-credentials -u username@domain.onmicrosoft.com -p "yourpassword" -o ./azure.conf -t puppet -v ```
107
-
108
- ```
109
- PS C:\Users\StuartPreston\azure-credentials> chef exec azure-credentials -u stuart@pendrica.com -p "mypassword" -o ./azure.conf -t puppet -v
110
- INFO [2016-03-28 16:01:58] Authenticating to Azure Active Directory
111
- INFO [2016-03-28 16:02:00] Retrieving tenant info
112
- INFO [2016-03-28 16:02:01] Retrieving subscriptions info
113
- INFO [2016-03-28 16:02:01] Creating application azure_5291_b6e7eee9-e4cd-41ae-8432-03ab624df016 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
114
- INFO [2016-03-28 16:02:02] Creating service principal for application
115
- INFO [2016-03-28 16:02:03] Waiting for service principal to be available in directory (retry 1)
116
- INFO [2016-03-28 16:02:05] Attempting to assign service principal to role
117
- INFO [2016-03-28 16:02:05] Waiting for service principal to be available in directory (retry 2)
118
- INFO [2016-03-28 16:02:07] Attempting to assign service principal to role
119
- INFO [2016-03-28 16:02:08] Waiting for service principal to be available in directory (retry 3)
120
- INFO [2016-03-28 16:02:10] Attempting to assign service principal to role
121
- INFO [2016-03-28 16:02:10] Waiting for service principal to be available in directory (retry 4)
122
- INFO [2016-03-28 16:02:12] Attempting to assign service principal to role
123
- INFO [2016-03-28 16:02:16] Assigned service principal to role Contributor in subscription b6e7eee9-e4cd-41ae-8432-03ab624df016
124
- INFO [2016-03-28 16:02:16] Creating application azure_5291_bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
125
- INFO [2016-03-28 16:02:17] Creating service principal for application
126
- INFO [2016-03-28 16:02:17] Waiting for service principal to be available in directory (retry 1)
127
- INFO [2016-03-28 16:02:19] Attempting to assign service principal to role
128
- INFO [2016-03-28 16:02:20] Waiting for service principal to be available in directory (retry 2)
129
- INFO [2016-03-28 16:02:22] Attempting to assign service principal to role
130
- INFO [2016-03-28 16:02:22] Waiting for service principal to be available in directory (retry 3)
131
- INFO [2016-03-28 16:02:24] Attempting to assign service principal to role
132
- INFO [2016-03-28 16:02:26] Assigned service principal to role Contributor in subscription bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3
133
- INFO [2016-03-28 16:02:26] Creating credentials file at C:/Users/StuartPreston/azure-credentials/azure.conf
134
- azure: {
135
- subscription_id: "b6e7eee9-e4cd-41ae-8432-03ab624df016"
136
- tenant_id: "9c117323-1f20-444d-82a9-9ee430723ba3"
137
- client_id: "8dfab0fc-65c5-46d0-be1d-d5d301b3cbc9"
138
- client_secret: "m_nh57rEZpGe5GFL8-Iceg=="
139
- }
140
-
141
- azure: {
142
- subscription_id: "bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3"
143
- tenant_id: "9c117323-1f20-444d-82a9-9ee430723ba3"
144
- client_id: "951eab1c-7e77-4931-bb68-15ca2d05e69e"
145
- client_secret: "vzl0haDXU51OukanIiRwJQ=="
146
- }
147
-
148
- INFO [2016-03-28 16:02:26] Done!
149
- ```
150
-
151
- ### Terraform-style output (note ```-v``` displays the file on screen after creation)
152
-
153
- ```azure-credentials -u username@domain.onmicrosoft.com -p "yourpassword" -o ./tf.creds -t terraform -v ```
154
-
155
- ```
156
- PS C:\Users\StuartPreston\azure-credentials> chef exec azure-credentials -u stuart@pendrica.com -p "mypassword" -o ./tf.creds -t terraform -v
157
- INFO [2016-03-28 16:04:32] Authenticating to Azure Active Directory
158
- INFO [2016-03-28 16:04:34] Retrieving tenant info
159
- INFO [2016-03-28 16:04:34] Retrieving subscriptions info
160
- INFO [2016-03-28 16:04:34] Creating application azure_c346_b6e7eee9-e4cd-41ae-8432-03ab624df016 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
161
- INFO [2016-03-28 16:04:35] Creating service principal for application
162
- INFO [2016-03-28 16:04:36] Waiting for service principal to be available in directory (retry 1)
163
- INFO [2016-03-28 16:04:38] Attempting to assign service principal to role
164
- INFO [2016-03-28 16:04:42] Assigned service principal to role Contributor in subscription b6e7eee9-e4cd-41ae-8432-03ab624df016
165
- INFO [2016-03-28 16:04:42] Creating application azure_c346_bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
166
- INFO [2016-03-28 16:04:42] Creating service principal for application
167
- INFO [2016-03-28 16:04:43] Waiting for service principal to be available in directory (retry 1)
168
- INFO [2016-03-28 16:04:45] Attempting to assign service principal to role
169
- INFO [2016-03-28 16:04:45] Waiting for service principal to be available in directory (retry 2)
170
- INFO [2016-03-28 16:04:47] Attempting to assign service principal to role
171
- INFO [2016-03-28 16:04:52] Assigned service principal to role Contributor in subscription bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3
172
- INFO [2016-03-28 16:04:52] Creating credentials file at C:/Users/StuartPreston/azure-credentials/tf.creds
173
- provider "azurerm" {
174
- subscription_id = "b6e7eee9-e4cd-41ae-8432-03ab624df016"
175
- client_id = "8a5b76c7-721f-4710-b491-8d657c9a7497"
176
- client_secret = "rGRLfflNSFo7O4t2vBU7pg=="
177
- tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
178
- }
179
-
180
- provider "azurerm" {
181
- subscription_id = "bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3"
182
- client_id = "0af58eee-25ce-467a-8e7c-05a35783385f"
183
- client_secret = "UvB-HJPoiOpujufeJjp5Ag=="
184
- tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
185
- }
186
-
187
- INFO [2016-03-28 16:04:52] Done!
188
- ```
189
-
190
- ## Not supported
191
-
192
- 1. Currently this tool does not support certificate-based authentication.
193
- 2. This tool will not work if MFA (multi-factor authentication) is set to **required** for administration of the Azure Active Directory domain.
194
- 3. This tool does not work if you sign in with an ADFS-federated account.
195
-
196
- ## Contributing
197
-
198
- I'm sure many improvements can be made to this tool! Contributions to the project are welcome via submitting Pull Requests.
199
-
200
- 1. Fork it ( https://github.com/pendrica/azure-credentials/fork )
201
- 2. Create your feature branch (`git checkout -b my-new-feature`)
202
- 3. Commit your changes (`git commit -am 'Add some feature'`)
203
- 4. Push to the branch (`git push origin my-new-feature`)
204
- 5. Create a new Pull Request
1
+ # azure-credentials
2
+
3
+ A tool to provide assistance for those struggling to create Applications, Service Principals and perform Role Assignments in Azure Resource Manager.
4
+ Generate your credentials file/helper for Chef, Puppet, Terraform and others!
5
+
6
+ ## Background
7
+
8
+ Automated access to Azure Resource Manager usually requires PowerShell or the Azure-CLI and to follow the (many) manual steps in [create and authenticate a service principal](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#authenticate-service-principal-with-password---azure-cli) to allow you to eventually retrieve 4 pieces of information:
9
+
10
+ 1. **Subscription ID**
11
+ 2. **Client ID**
12
+ 3. **Client Secret/Password**
13
+ 4. **Tenant ID**
14
+
15
+ ... you then use this information to configure your provisioning system. This tool (created in Ruby) requires only the credentials of the user with global administrator privilege and does the rest of the work for you, making it easier and quicker to get started with the various provisioning and testing toolsets out there.
16
+
17
+ ## Installation
18
+
19
+ The tool is distributed as a [Ruby Gem](https://rubygems.org/gems/azure-credentials). To install it, run:
20
+
21
+ ```gem install azure-credentials```
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ Usage: azure-credentials (options)
27
+ -l, --log_level LEVEL Set the log level (debug, info, warn, error, fatal)
28
+ -v, --verbose Display the credentials in STDOUT after creation? (warning: will contain secrets)
29
+ -o, --output FILENAME Enter the filename to save the credentials to
30
+ -p, --password PASSWORD Enter the password for the Azure AD user
31
+ -r, --role ROLENAME Enter the built-in Azure role to add the service principal to on your subscription (default: Contributor)
32
+ -s, --subscription ID Enter the Subscription ID to work against (default: process all subscriptions within the Azure tenant)
33
+ -t, --type OUTPUTTYPE Set the output type (default: chef)
34
+ -u, --username USERNAME Enter the username (must be an Azure AD user)
35
+ -h, --help Show this message
36
+ ```
37
+
38
+ ## Default behaviour
39
+
40
+ By default (providing no options), the utility will prompt for your Azure AD username and password interactively, connect to Azure, retrieve details of all the subscriptions in your tenant, create an Application/Service Principal for each subscription then create you a credentials file with the relevant details that you can start to use with other tools immediately.
41
+
42
+ ### Example output *(nb: ```chef exec``` typically is only required on Windows systems with ChefDK and no Ruby in their system path)*
43
+
44
+ ```
45
+ PS C:\Users\StuartPreston\azure-credentials> chef exec azure-credentials
46
+ Enter your Azure AD username (user@domain.com): stuart@pendrica.com
47
+ Enter your password:
48
+ INFO [2016-03-28 15:29:37] Authenticating to Azure Active Directory
49
+ INFO [2016-03-28 15:29:39] Retrieving tenant info
50
+ INFO [2016-03-28 15:29:40] Retrieving subscriptions info
51
+ INFO [2016-03-28 15:29:41] Creating application azure_6b3a_b6e7eee9-e4cd-41ae-8432-03ab624df016 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
52
+ INFO [2016-03-28 15:29:41] Creating service principal for application
53
+ INFO [2016-03-28 15:29:43] Waiting for service principal to be available in directory (retry 1)
54
+ INFO [2016-03-28 15:29:45] Attempting to assign service principal to role
55
+ INFO [2016-03-28 15:29:45] Waiting for service principal to be available in directory (retry 2)
56
+ INFO [2016-03-28 15:29:47] Attempting to assign service principal to role
57
+ INFO [2016-03-28 15:29:48] Waiting for service principal to be available in directory (retry 3)
58
+ INFO [2016-03-28 15:29:50] Attempting to assign service principal to role
59
+ INFO [2016-03-28 15:29:52] Assigned service principal to role Contributor in subscription b6e7eee9-e4cd-41ae-8432-03ab624df016
60
+ INFO [2016-03-28 15:29:52] Creating application azure_6b3a_bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
61
+ INFO [2016-03-28 15:29:53] Creating service principal for application
62
+ INFO [2016-03-28 15:29:54] Waiting for service principal to be available in directory (retry 1)
63
+ INFO [2016-03-28 15:29:56] Attempting to assign service principal to role
64
+ INFO [2016-03-28 15:29:56] Waiting for service principal to be available in directory (retry 2)
65
+ INFO [2016-03-28 15:29:58] Attempting to assign service principal to role
66
+ INFO [2016-03-28 15:29:58] Waiting for service principal to be available in directory (retry 3)
67
+ INFO [2016-03-28 15:30:00] Attempting to assign service principal to role
68
+ INFO [2016-03-28 15:30:04] Assigned service principal to role Contributor in subscription bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3
69
+ INFO [2016-03-28 15:30:04] Creating credentials file at C:/Users/StuartPreston/azure-credentials/credentials
70
+ INFO [2016-03-28 15:30:04] Done!
71
+ ```
72
+
73
+ You'll be able to see the output in the created credentials file (don't worry you can change the location using the -o switch)
74
+
75
+ ```
76
+ PS C:\Users\StuartPreston\azure-credentials> cat ./credentials
77
+ [b6e7eee9-e4cd-41ae-8432-03ab624df016]
78
+ client_id = "5a8758f2-a2b2-4eab-8203-28c0840ccd7f"
79
+ client_secret = "ZSNdI5hQ9toavJNVgRjMjA=="
80
+ tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
81
+
82
+ [bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3]
83
+ client_id = "2205cbcd-84dc-4b4a-9fcf-4a27d773a56d"
84
+ client_secret = "KboMQ86BvMGR6vO7_fUd1A=="
85
+ tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
86
+ ```
87
+
88
+ (don't worry these accounts don't exist any more!)
89
+
90
+ If you look in the Azure Service Management portal and navigate to Active Directory > [directory name] > Applications (Show: Applications my company owns) you will see Applications created with the **azure_** prefix. New identifiers are generated each time so there will be no overlap with existing accounts:
91
+
92
+ ![config](images/configuration_asm.png)
93
+
94
+ You will also see the role assignment when looking in the Azure Resource Manager portal > Subscriptions, selecting one and viewing the users:
95
+
96
+ ![config](images/configuration_arm.png)
97
+
98
+ ## Some more advanced examples
99
+
100
+ ### Chef quick config!
101
+
102
+ ```azure-credentials -u username@domain.onmicrosoft.com -p "yourpassword" -o ~/.azure/credentials```
103
+
104
+ ### Puppet-style output (note ```-v``` displays the file on screen after creation)
105
+
106
+ ```azure-credentials -u username@domain.onmicrosoft.com -p "yourpassword" -o ./azure.conf -t puppet -v ```
107
+
108
+ ```
109
+ PS C:\Users\StuartPreston\azure-credentials> chef exec azure-credentials -u stuart@pendrica.com -p "mypassword" -o ./azure.conf -t puppet -v
110
+ INFO [2016-03-28 16:01:58] Authenticating to Azure Active Directory
111
+ INFO [2016-03-28 16:02:00] Retrieving tenant info
112
+ INFO [2016-03-28 16:02:01] Retrieving subscriptions info
113
+ INFO [2016-03-28 16:02:01] Creating application azure_5291_b6e7eee9-e4cd-41ae-8432-03ab624df016 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
114
+ INFO [2016-03-28 16:02:02] Creating service principal for application
115
+ INFO [2016-03-28 16:02:03] Waiting for service principal to be available in directory (retry 1)
116
+ INFO [2016-03-28 16:02:05] Attempting to assign service principal to role
117
+ INFO [2016-03-28 16:02:05] Waiting for service principal to be available in directory (retry 2)
118
+ INFO [2016-03-28 16:02:07] Attempting to assign service principal to role
119
+ INFO [2016-03-28 16:02:08] Waiting for service principal to be available in directory (retry 3)
120
+ INFO [2016-03-28 16:02:10] Attempting to assign service principal to role
121
+ INFO [2016-03-28 16:02:10] Waiting for service principal to be available in directory (retry 4)
122
+ INFO [2016-03-28 16:02:12] Attempting to assign service principal to role
123
+ INFO [2016-03-28 16:02:16] Assigned service principal to role Contributor in subscription b6e7eee9-e4cd-41ae-8432-03ab624df016
124
+ INFO [2016-03-28 16:02:16] Creating application azure_5291_bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
125
+ INFO [2016-03-28 16:02:17] Creating service principal for application
126
+ INFO [2016-03-28 16:02:17] Waiting for service principal to be available in directory (retry 1)
127
+ INFO [2016-03-28 16:02:19] Attempting to assign service principal to role
128
+ INFO [2016-03-28 16:02:20] Waiting for service principal to be available in directory (retry 2)
129
+ INFO [2016-03-28 16:02:22] Attempting to assign service principal to role
130
+ INFO [2016-03-28 16:02:22] Waiting for service principal to be available in directory (retry 3)
131
+ INFO [2016-03-28 16:02:24] Attempting to assign service principal to role
132
+ INFO [2016-03-28 16:02:26] Assigned service principal to role Contributor in subscription bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3
133
+ INFO [2016-03-28 16:02:26] Creating credentials file at C:/Users/StuartPreston/azure-credentials/azure.conf
134
+ azure: {
135
+ subscription_id: "b6e7eee9-e4cd-41ae-8432-03ab624df016"
136
+ tenant_id: "9c117323-1f20-444d-82a9-9ee430723ba3"
137
+ client_id: "8dfab0fc-65c5-46d0-be1d-d5d301b3cbc9"
138
+ client_secret: "m_nh57rEZpGe5GFL8-Iceg=="
139
+ }
140
+
141
+ azure: {
142
+ subscription_id: "bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3"
143
+ tenant_id: "9c117323-1f20-444d-82a9-9ee430723ba3"
144
+ client_id: "951eab1c-7e77-4931-bb68-15ca2d05e69e"
145
+ client_secret: "vzl0haDXU51OukanIiRwJQ=="
146
+ }
147
+
148
+ INFO [2016-03-28 16:02:26] Done!
149
+ ```
150
+
151
+ ### Terraform-style output (note ```-v``` displays the file on screen after creation)
152
+
153
+ ```azure-credentials -u username@domain.onmicrosoft.com -p "yourpassword" -o ./tf.creds -t terraform -v ```
154
+
155
+ ```
156
+ PS C:\Users\StuartPreston\azure-credentials> chef exec azure-credentials -u stuart@pendrica.com -p "mypassword" -o ./tf.creds -t terraform -v
157
+ INFO [2016-03-28 16:04:32] Authenticating to Azure Active Directory
158
+ INFO [2016-03-28 16:04:34] Retrieving tenant info
159
+ INFO [2016-03-28 16:04:34] Retrieving subscriptions info
160
+ INFO [2016-03-28 16:04:34] Creating application azure_c346_b6e7eee9-e4cd-41ae-8432-03ab624df016 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
161
+ INFO [2016-03-28 16:04:35] Creating service principal for application
162
+ INFO [2016-03-28 16:04:36] Waiting for service principal to be available in directory (retry 1)
163
+ INFO [2016-03-28 16:04:38] Attempting to assign service principal to role
164
+ INFO [2016-03-28 16:04:42] Assigned service principal to role Contributor in subscription b6e7eee9-e4cd-41ae-8432-03ab624df016
165
+ INFO [2016-03-28 16:04:42] Creating application azure_c346_bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3 in tenant 9c117323-1f20-444d-82a9-9ee430723ba3
166
+ INFO [2016-03-28 16:04:42] Creating service principal for application
167
+ INFO [2016-03-28 16:04:43] Waiting for service principal to be available in directory (retry 1)
168
+ INFO [2016-03-28 16:04:45] Attempting to assign service principal to role
169
+ INFO [2016-03-28 16:04:45] Waiting for service principal to be available in directory (retry 2)
170
+ INFO [2016-03-28 16:04:47] Attempting to assign service principal to role
171
+ INFO [2016-03-28 16:04:52] Assigned service principal to role Contributor in subscription bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3
172
+ INFO [2016-03-28 16:04:52] Creating credentials file at C:/Users/StuartPreston/azure-credentials/tf.creds
173
+ provider "azurerm" {
174
+ subscription_id = "b6e7eee9-e4cd-41ae-8432-03ab624df016"
175
+ client_id = "8a5b76c7-721f-4710-b491-8d657c9a7497"
176
+ client_secret = "rGRLfflNSFo7O4t2vBU7pg=="
177
+ tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
178
+ }
179
+
180
+ provider "azurerm" {
181
+ subscription_id = "bcf669fc-98b4-4e51-8ab0-e2d1f9f4b1c3"
182
+ client_id = "0af58eee-25ce-467a-8e7c-05a35783385f"
183
+ client_secret = "UvB-HJPoiOpujufeJjp5Ag=="
184
+ tenant_id = "9c117323-1f20-444d-82a9-9ee430723ba3"
185
+ }
186
+
187
+ INFO [2016-03-28 16:04:52] Done!
188
+ ```
189
+
190
+ ## Not supported
191
+
192
+ 1. Currently this tool does not support certificate-based authentication.
193
+ 2. This tool will not work if MFA (multi-factor authentication) is set to **required** for administration of the Azure Active Directory domain.
194
+ 3. This tool does not work if you sign in with an ADFS-federated account.
195
+
196
+ ## Contributing
197
+
198
+ I'm sure many improvements can be made to this tool! Contributions to the project are welcome via submitting Pull Requests.
199
+
200
+ 1. Fork it ( https://github.com/pendrica/azure-credentials/fork )
201
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
202
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
203
+ 4. Push to the branch (`git push origin my-new-feature`)
204
+ 5. Create a new Pull Request
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'azure/utility/credentials'
4
5
  Azure::Utility::Credentials.new
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'io/console'
1
4
  require 'net/http'
2
5
  require 'uri'
3
6
  require 'json'
@@ -37,7 +40,7 @@ module Azure
37
40
  short: '-r',
38
41
  long: '--role ROLENAME',
39
42
  description: 'Enter the built-in Azure role to add the service principal to on your subscription (default: Contributor)',
40
- in: %w(Contributor Owner),
43
+ in: %w[Contributor Owner],
41
44
  default: 'Contributor',
42
45
  required: false
43
46
 
@@ -45,7 +48,7 @@ module Azure
45
48
  short: '-t',
46
49
  long: '--type OUTPUTTYPE',
47
50
  description: 'Set the output type (default: chef)',
48
- in: %w(chef puppet terraform generic),
51
+ in: %w[chef puppet terraform generic],
49
52
  required: false,
50
53
  default: 'chef'
51
54
 
@@ -55,7 +58,7 @@ module Azure
55
58
  description: 'Set the log level (debug, info, warn, error, fatal)',
56
59
  default: :info,
57
60
  required: false,
58
- in: %w(debug info warn error fatal),
61
+ in: %w[debug info warn error fatal],
59
62
  proc: proc { |l| l.to_sym }
60
63
 
61
64
  option :output_file,
@@ -102,15 +105,15 @@ module Azure
102
105
  def self.logger_level_for(sym)
103
106
  case sym
104
107
  when :debug
105
- return Logger::DEBUG
108
+ Logger::DEBUG
106
109
  when :info
107
- return Logger::INFO
110
+ Logger::INFO
108
111
  when :warn
109
- return Logger::WARN
112
+ Logger::WARN
110
113
  when :error
111
- return Logger::ERROR
114
+ Logger::ERROR
112
115
  when :fatal
113
- return Logger::FATAL
116
+ Logger::FATAL
114
117
  end
115
118
  end
116
119
  end
@@ -119,8 +122,8 @@ module Azure
119
122
  # Credentials
120
123
  #
121
124
  class Credentials
122
- AZURE_SERVICE_PRINCIPAL = '1950a258-227b-4e31-a9cf-717495945fc2'.freeze
123
- CONFIG_PATH = "#{ENV['HOME']}/.azure/credentials".freeze
125
+ AZURE_SERVICE_PRINCIPAL = '1950a258-227b-4e31-a9cf-717495945fc2'
126
+ CONFIG_PATH = "#{ENV['HOME']}/.azure/credentials"
124
127
 
125
128
  def initialize
126
129
  cli = Options.new
@@ -163,50 +166,50 @@ module Azure
163
166
  case style
164
167
  when 'chef' # ref: https://github.com/pendrica/chef-provisioning-azurerm#configuration
165
168
  created_credentials.each do |s|
166
- subscription_template = <<-EOH
167
- [#{s[:subscription_id]}]
168
- client_id = "#{s[:client_id]}"
169
- client_secret = "#{s[:client_secret]}"
170
- tenant_id = "#{s[:tenant_id]}"
169
+ subscription_template = <<~CHEFEOH
170
+ [#{s[:subscription_id]}]
171
+ client_id = "#{s[:client_id]}"
172
+ client_secret = "#{s[:client_secret]}"
173
+ tenant_id = "#{s[:tenant_id]}"
171
174
 
172
- EOH
175
+ CHEFEOH
173
176
  output += subscription_template
174
177
  end
175
178
  when 'terraform' # ref: https://www.terraform.io/docs/providers/azurerm/index.html
176
179
  created_credentials.each do |s|
177
- subscription_template = <<-EOH
178
- provider "azurerm" {
179
- subscription_id = "#{s[:subscription_id]}"
180
- client_id = "#{s[:client_id]}"
181
- client_secret = "#{s[:client_secret]}"
182
- tenant_id = "#{s[:tenant_id]}"
183
- }
184
-
185
- EOH
180
+ subscription_template = <<~TFEOH
181
+ provider "azurerm" {
182
+ subscription_id = "#{s[:subscription_id]}"
183
+ client_id = "#{s[:client_id]}"
184
+ client_secret = "#{s[:client_secret]}"
185
+ tenant_id = "#{s[:tenant_id]}"
186
+ }
187
+
188
+ TFEOH
186
189
  output += subscription_template
187
190
  end
188
191
  when 'puppet' # ref: https://github.com/puppetlabs/puppetlabs-azure#installing-the-azure-module
189
192
  created_credentials.each do |s|
190
- subscription_template = <<-EOH
191
- azure: {
192
- subscription_id: "#{s[:subscription_id]}"
193
- tenant_id: "#{s[:tenant_id]}"
194
- client_id: "#{s[:client_id]}"
195
- client_secret: "#{s[:client_secret]}"
196
- }
197
-
198
- EOH
193
+ subscription_template = <<~PPEOH
194
+ azure: {
195
+ subscription_id: "#{s[:subscription_id]}"
196
+ tenant_id: "#{s[:tenant_id]}"
197
+ client_id: "#{s[:client_id]}"
198
+ client_secret: "#{s[:client_secret]}"
199
+ }
200
+
201
+ PPEOH
199
202
  output += subscription_template
200
203
  end
201
204
  else # generic credentials output
202
205
  created_credentials.each do |s|
203
- subscription_template = <<-EOH
204
- azure_subscription_id = "#{s[:subscription_id]}"
205
- azure_tenant_id = "#{s[:tenant_id]}"
206
- azure_client_id = "#{s[:client_id]}"
207
- azure_client_secret = "#{s[:client_secret]}"
206
+ subscription_template = <<~GENERICEOH
207
+ azure_subscription_id = "#{s[:subscription_id]}"
208
+ azure_tenant_id = "#{s[:tenant_id]}"
209
+ azure_client_id = "#{s[:client_id]}"
210
+ azure_client_secret = "#{s[:client_secret]}"
208
211
 
209
- EOH
212
+ GENERICEOH
210
213
  output += subscription_template
211
214
  end
212
215
  end
@@ -270,7 +273,7 @@ azure_client_secret = "#{s[:client_secret]}"
270
273
  def create_application(tenant_id, token, new_application_name, new_client_secret)
271
274
  CustomLogger.log.info "Creating application #{new_application_name} in tenant #{tenant_id}"
272
275
  url = "https://graph.windows.net/#{tenant_id}/applications?api-version=1.42-previewInternal"
273
- payload_json = <<-EOH
276
+ payload_json = <<-JSONEOH
274
277
  {
275
278
  "availableToOtherTenants": false,
276
279
  "displayName": "#{new_application_name}",
@@ -287,33 +290,33 @@ azure_client_secret = "#{s[:client_secret]}"
287
290
  }
288
291
  ]
289
292
  }
290
- EOH
293
+ JSONEOH
291
294
  azure_call(:post, url, payload_json, token)
292
295
  end
293
296
 
294
297
  def create_service_principal(tenant_id, token, application_id)
295
298
  CustomLogger.log.info 'Creating service principal for application'
296
299
  url = "https://graph.windows.net/#{tenant_id}/servicePrincipals?api-version=1.42-previewInternal"
297
- payload_json = <<-EOH
300
+ payload_json = <<-PAYLOADEOH
298
301
  {
299
302
  "appId": "#{application_id}",
300
303
  "accountEnabled": true
301
304
  }
302
- EOH
305
+ PAYLOADEOH
303
306
  azure_call(:post, url, payload_json, token)
304
307
  end
305
308
 
306
309
  def assign_service_principal_to_role_id(subscription_id, token, service_principal_object_id, role_definition_id)
307
310
  CustomLogger.log.info 'Attempting to assign service principal to role'
308
311
  url = "https://management.azure.com/subscriptions/#{subscription_id}/providers/Microsoft.Authorization/roleAssignments/#{service_principal_object_id}?api-version=2015-07-01"
309
- payload_json = <<-EOH
312
+ payload_json = <<-PAYLOADEOH
310
313
  {
311
314
  "properties": {
312
315
  "roleDefinitionId": "#{role_definition_id}",
313
316
  "principalId": "#{service_principal_object_id}"
314
317
  }
315
318
  }
316
- EOH
319
+ PAYLOADEOH
317
320
  azure_call(:put, url, payload_json, token)
318
321
  end
319
322
 
metadata CHANGED
@@ -1,55 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-credentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Preston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-30 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: json
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.8'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.8.3
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.8'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.8.3
33
- - !ruby/object:Gem::Dependency
34
- name: mixlib-cli
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '1'
40
- - - '='
41
- - !ruby/object:Gem::Version
42
- version: 1.5.0
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '1'
50
- - - '='
51
- - !ruby/object:Gem::Version
52
- version: 1.5.0
53
13
  - !ruby/object:Gem::Dependency
54
14
  name: bundler
55
15
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +39,7 @@ dependencies:
79
39
  - !ruby/object:Gem::Version
80
40
  version: '10.0'
81
41
  - !ruby/object:Gem::Dependency
82
- name: rubocop
42
+ name: rspec
83
43
  requirement: !ruby/object:Gem::Requirement
84
44
  requirements:
85
45
  - - "~>"
@@ -93,7 +53,7 @@ dependencies:
93
53
  - !ruby/object:Gem::Version
94
54
  version: '0'
95
55
  - !ruby/object:Gem::Dependency
96
- name: rspec
56
+ name: rubocop
97
57
  requirement: !ruby/object:Gem::Requirement
98
58
  requirements:
99
59
  - - "~>"
@@ -140,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
100
  version: '0'
141
101
  requirements: []
142
102
  rubyforge_project:
143
- rubygems_version: 2.6.6
103
+ rubygems_version: 2.7.6
144
104
  signing_key:
145
105
  specification_version: 4
146
106
  summary: AzureRM credential generator