knife-okta 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.travis.yml +28 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +16 -0
- data/Guardfile +9 -0
- data/LICENSE +202 -0
- data/README.md +114 -0
- data/Rakefile +6 -0
- data/knife-okta.gemspec +22 -0
- data/lib/chef/knife/data_bag_from_okta_group.rb +301 -0
- data/lib/knife-okta.rb +20 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5d7e4ffaba9c64d0ef8e33cf6a7964bb452c96e
|
4
|
+
data.tar.gz: 31e4e7dee416cf3b12b6e1269fdc9485ffce5404
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a38f61a65fa62b5b17934d0e9d7a2c6b889c96f5c97464e546affaf47ad80d1914fa126203579ee1d1f27f50da7355812de9b183d3d7e0d010ad03c2d51ab17b
|
7
|
+
data.tar.gz: c5e8a8e139584cede147796de773453ddd6573de9888f744ff1c49ea39843b0c7a57b2161fd215af55ea433bd9b86ba4e3da3ea2dbf5d0dbf9cde9530e561142
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.4.2
|
5
|
+
|
6
|
+
cache:
|
7
|
+
- bundler
|
8
|
+
|
9
|
+
notifications:
|
10
|
+
email:
|
11
|
+
on_success: change
|
12
|
+
on_failure: always
|
13
|
+
|
14
|
+
branches:
|
15
|
+
only:
|
16
|
+
- master
|
17
|
+
- /^v\d+\.\d+\.\d+$/
|
18
|
+
|
19
|
+
before_install: gem install bundler -v 1.16.0
|
20
|
+
|
21
|
+
deploy:
|
22
|
+
provider: rubygems
|
23
|
+
api_key:
|
24
|
+
secure: DKQGAQxv3wYY8dGYzwI0yeZjoIeGDx21MzHC0U3S65yNwfNSGVg+Tg3rAKZhuWe7IS+FUNqgKecWjfVUSD6BZgOB+tucCGsMG7e2R8T60fxSfpmChZl1DMVuEV7SbbV5MqM0qTIoqmxMYk2tVlhYfPY24SxKzhru8TAL1HjeyJhISdYS5sgn0+4ZUQ4GsgUC0VqEisETNfSt9LebHZb54t3neh4qGH9Qq1jKY/ePqS8PRAaaSQUIbKcIg6WBXSKpHXzKnpNxPeZ1ar9N8XRRdKA635PvLLYtLkDo4cGLYphIzR++k0WwHDrOBgA77GWsWMZvCCXHQNsdFs3GTmC1POS50xUMj8KIpzDVB3O2HpYGcXxwMWf3mAUPjvk1fi60iya3vxu6J0QhsvIOYqYlZ5OVdT9gBbhzSj6katBi+OGJ/IoUQfWN0JBhb+Fg+k2z3Ip/DKp1EZ2U+omofBhSFxUH90ZetH5zfL3UIMz0/7USo45Z+UA7svPCa7SHeKOASekMIuhhe8U1xdLnxXONjnHLAXD4QLR8e+podCLjHf2TDXY0NgrIr+wLc22I/7X1sNlEkcwRkRpDuKzLbiI4CC5BLdK8tMhpSO4fSlNIrgz75FaIZKXKSZMB813am9NVCyuD6Nubqr4oUVJ5VqfZuMTxZLP8CN3+z8TC1hcgUx8=
|
25
|
+
gem: knife-okta
|
26
|
+
on:
|
27
|
+
tags: true
|
28
|
+
repo: schubergphilis/knife-okta
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# knife-okta CHANGELOG
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
+
|
7
|
+
## 0.1.0 (2018-02-01)
|
8
|
+
|
9
|
+
First release.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at shoekstra@schubergphilis.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem "guard-rspec", require: false
|
5
|
+
gem "pry", require: false
|
6
|
+
gem "terminal-notifier-guard", require: false
|
7
|
+
end
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "bundler", "~> 1.16"
|
11
|
+
gem "chefstyle"
|
12
|
+
gem "rake", "~> 10.0"
|
13
|
+
gem "rspec", "~> 3.0"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec
|
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# knife-okta
|
2
|
+
|
3
|
+
knife-okta is a knife plugin to interact with the Okta API.
|
4
|
+
|
5
|
+
The initial use case is to create data bags based on Okta group membership.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
As with all knife plugins, just install the gem:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install knife-okta
|
13
|
+
```
|
14
|
+
|
15
|
+
Or if you use ChefDK:
|
16
|
+
|
17
|
+
```
|
18
|
+
chef gem install knife-okta
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This plugin works the same as the `knife data bag from file` sub command, but instead queries Okta for a group's active members:
|
24
|
+
|
25
|
+
```
|
26
|
+
knife data bag from okta group BAG ITEM GROUP [GROUP..] (options)
|
27
|
+
```
|
28
|
+
|
29
|
+
The following parameters are added with this sub command:
|
30
|
+
|
31
|
+
```
|
32
|
+
--max-change MAX_CHANGE Set the maximum amount of allowed changes
|
33
|
+
-a, --okta-attribute OKTA_ATTRIBUTE Specify the user profile attribute to return
|
34
|
+
-o, --okta-endpoint OKTA_ENDPOINT Set the Okta API endpoint (e.g. https://yourorg.okta.com/api/v1)
|
35
|
+
-t, --okta-token OKTA_TOKEN Set the Okta API token
|
36
|
+
--show-changes Show any changes when uploading a data bag item
|
37
|
+
--show-members Show data bag item members when uploading a data bag item
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
You can also add Okta options to your knife config file:
|
42
|
+
|
43
|
+
```
|
44
|
+
knife[:okta_attribute] = 'login'
|
45
|
+
knife[:okta_endpoint] = 'https://myorg.okta-emea.com/api/v1'
|
46
|
+
knife[:okta_token] = '004zNgntseobUzztBLSraij...'
|
47
|
+
```
|
48
|
+
|
49
|
+
## Examples
|
50
|
+
|
51
|
+
These examples assume the Okta configuration has been set in your knife config file.
|
52
|
+
|
53
|
+
### Create a data bag item from a single Okta group
|
54
|
+
|
55
|
+
To create a data bag called `users` with a data bag item called `linux_admins` that contains the display names of the group members:
|
56
|
+
|
57
|
+
```
|
58
|
+
knife data bag from okta group users linux_admins Linux-Admins -a displayName
|
59
|
+
```
|
60
|
+
|
61
|
+
* The `-a` option determines which profile attribute to populate the data bag with, at this time only `displayName`, `email` and `login` are supported.
|
62
|
+
|
63
|
+
### Create a data bag item from multiple Okta groups
|
64
|
+
|
65
|
+
You can specify multiple groups by providing a comma separated value:
|
66
|
+
|
67
|
+
```
|
68
|
+
knife data bag from okta group users admins Linux-Admins,Windows-Admins -a displayName
|
69
|
+
```
|
70
|
+
|
71
|
+
You can also provide Okta group names that contain spaces:
|
72
|
+
|
73
|
+
```
|
74
|
+
knife data bag from okta group users admins "Linux-Admins,Windows-Admins,Other Admins" -a displayName
|
75
|
+
```
|
76
|
+
|
77
|
+
### Limiting amount of changes
|
78
|
+
|
79
|
+
In the case where you want not upload a data bag if there more changes than expected (e.g. if running this plugin via a cron job), you can use the `--max-change` attribute:
|
80
|
+
|
81
|
+
```
|
82
|
+
knife data bag from okta group users linux_admins Linux-Admins -a displayName --max-change 5
|
83
|
+
```
|
84
|
+
|
85
|
+
This attribute watches for additions and removes, so using our example above if there were 3 additions and 2 removals then the data bag would not be uploaded as it met the threshold set (5).
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
```
|
90
|
+
Copyright 2018 Stephen Hoekstra <shoekstra@schubergphilis.com>
|
91
|
+
Copyright 2018 Schuberg Philis
|
92
|
+
|
93
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
94
|
+
you may not use this file except in compliance with the License.
|
95
|
+
You may obtain a copy of the License at
|
96
|
+
|
97
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
98
|
+
|
99
|
+
Unless required by applicable law or agreed to in writing, software
|
100
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
101
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
102
|
+
See the License for the specific language governing permissions and
|
103
|
+
limitations under the License.
|
104
|
+
```
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
We welcome contributed improvements and bug fixes via the usual work flow:
|
109
|
+
|
110
|
+
1. Fork this repository
|
111
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
113
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
114
|
+
1. Create a new pull request
|
data/Rakefile
ADDED
data/knife-okta.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/knife-okta"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "knife-okta"
|
5
|
+
spec.version = KnifeOkta::VERSION
|
6
|
+
spec.authors = ["Stephen Hoekstra"]
|
7
|
+
spec.email = ["shoekstra@schubergphilis.com"]
|
8
|
+
|
9
|
+
spec.description = %q{A knife plugin to interact with the Okta API.}
|
10
|
+
spec.summary = spec.description
|
11
|
+
spec.homepage = "https://github.com/shoekstra/knife-okta"
|
12
|
+
spec.license = "Apache-2.0"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = %w{lib}
|
19
|
+
|
20
|
+
spec.add_dependency "chef", ">= 12.0"
|
21
|
+
spec.add_dependency "oktakit", "~> 0.2.0"
|
22
|
+
end
|
@@ -0,0 +1,301 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2018 Stephen Hoekstra <shoekstra@schubergphilis.com>
|
3
|
+
# Copyright 2018 Schuberg Philis
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
class Chef
|
19
|
+
class Knife
|
20
|
+
class DataBagFromOktaGroup < Chef::Knife
|
21
|
+
deps do
|
22
|
+
require "chef/data_bag"
|
23
|
+
require "chef/knife/data_bag_from_file"
|
24
|
+
require "oktakit"
|
25
|
+
require "tempfile"
|
26
|
+
Chef::Knife::DataBagFromFile.load_deps
|
27
|
+
end
|
28
|
+
|
29
|
+
banner "knife data bag from okta group BAG ITEM GROUP [GROUP..] (options)"
|
30
|
+
category "data bag"
|
31
|
+
|
32
|
+
option :max_change,
|
33
|
+
long: "--max-change MAX_CHANGE",
|
34
|
+
description: "Set the maximum amount of allowed changes",
|
35
|
+
default: 0,
|
36
|
+
proc: proc { |key| key.to_i }
|
37
|
+
|
38
|
+
option :okta_attribute,
|
39
|
+
short: "-a OKTA_ATTRIBUTE",
|
40
|
+
long: "--okta-attribute OKTA_ATTRIBUTE",
|
41
|
+
description: "Specify the user profile attribute to return",
|
42
|
+
proc: proc { |key| Chef::Config[:knife][:okta_attribute] = key }
|
43
|
+
|
44
|
+
option :okta_endpoint,
|
45
|
+
short: "-o OKTA_ENDPOINT",
|
46
|
+
long: "--okta-endpoint OKTA_ENDPOINT",
|
47
|
+
description: "Set the Okta API endpoint (e.g. https://yourorg.okta.com/api/v1)",
|
48
|
+
proc: proc { |key| Chef::Config[:knife][:okta_endpoint] = key }
|
49
|
+
|
50
|
+
option :okta_token,
|
51
|
+
short: "-t OKTA_TOKEN",
|
52
|
+
long: "--okta-token OKTA_TOKEN",
|
53
|
+
description: "Set the Okta API token",
|
54
|
+
proc: proc { |key| Chef::Config[:knife][:okta_token] = key }
|
55
|
+
|
56
|
+
option :show_changes,
|
57
|
+
long: "--show-changes",
|
58
|
+
description: "Show any changes when uploading a data bag item",
|
59
|
+
boolean: true,
|
60
|
+
default: false
|
61
|
+
|
62
|
+
option :show_members,
|
63
|
+
long: "--show-members",
|
64
|
+
description: "Show data bag item members when uploading a data bag item",
|
65
|
+
boolean: true,
|
66
|
+
default: false
|
67
|
+
|
68
|
+
def run
|
69
|
+
validate_arguments
|
70
|
+
validate_okta_config
|
71
|
+
|
72
|
+
@data_bag_name = @name_args.shift
|
73
|
+
@data_bag_item_name = @name_args.shift
|
74
|
+
@okta_groups = @name_args
|
75
|
+
|
76
|
+
begin
|
77
|
+
Chef::DataBag.validate_name!(@data_bag_name)
|
78
|
+
rescue Chef::Exceptions::InvalidDataBagName => e
|
79
|
+
ui.fatal(e.message)
|
80
|
+
exit(1)
|
81
|
+
end
|
82
|
+
|
83
|
+
if same_as_existing_data_bag_item?
|
84
|
+
ui.info("Data bag item #{@data_bag_item_name} already exists and contains no changes, skipping upload")
|
85
|
+
exit(0)
|
86
|
+
end
|
87
|
+
|
88
|
+
create_data_bag_if_missing
|
89
|
+
create_data_bag_item_file
|
90
|
+
display_data_bag_item_changes
|
91
|
+
display_data_bag_item_members
|
92
|
+
check_changes_within_range
|
93
|
+
upload_data_bag_item
|
94
|
+
ensure
|
95
|
+
FileUtils.remove_entry tmpdir if tmpdir
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def validate_arguments
|
101
|
+
return unless @name_args.size < 3
|
102
|
+
ui.msg(opt_parser)
|
103
|
+
exit(1)
|
104
|
+
end
|
105
|
+
|
106
|
+
def validate_okta_config
|
107
|
+
config[:okta_attribute] ||= ENV["OKTA_ATTRIBUTE"] if ENV["OKTA_ATTRIBUTE"]
|
108
|
+
config[:okta_endpoint] ||= ENV["OKTA_ENDPOINT"] if ENV["OKTA_ENDPOINT"]
|
109
|
+
config[:okta_token] ||= ENV["OKTA_TOKEN"] if ENV["OKTA_TOKEN"]
|
110
|
+
|
111
|
+
unless config[:okta_attribute]
|
112
|
+
ui.fatal("You must use specify an Okta identity profile attribute, either using --okta-endpoint or knife[:okta_endpoint] in your config.")
|
113
|
+
exit(1)
|
114
|
+
end
|
115
|
+
|
116
|
+
# This should probably be more dynamic, e.g. later on once we have a user hash to look if
|
117
|
+
# the provided attribute matches a profile key and if not, fail, but for now we're OK with this.
|
118
|
+
unless %w{displayName email login}.include?(config[:okta_attribute])
|
119
|
+
ui.fatal('Unsupported value for --okta-attribute, please specify either "displayName", "email" or "login".')
|
120
|
+
exit(1)
|
121
|
+
end
|
122
|
+
|
123
|
+
unless config[:okta_endpoint]
|
124
|
+
ui.fatal("You must use specify an Okta API endpoint, either using --okta-endpoint or knife[:okta_endpoint] in your config.")
|
125
|
+
exit(1)
|
126
|
+
end
|
127
|
+
|
128
|
+
unless config[:okta_token]
|
129
|
+
ui.fatal("You must use specify an Okta API token, either using --okta-token or knife[:okta_token] in your config.")
|
130
|
+
exit(1)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def tmpdir
|
135
|
+
@tmpdir ||= Dir.mktmpdir
|
136
|
+
end
|
137
|
+
|
138
|
+
def attribute_key_values
|
139
|
+
@attribute_key_values ||= values_for_key(config[:okta_attribute]).sort
|
140
|
+
end
|
141
|
+
|
142
|
+
def check_changes_within_range
|
143
|
+
return if config[:max_change] == 0
|
144
|
+
|
145
|
+
changes = data_bag_item_additions.size + data_bag_item_removals.size
|
146
|
+
return if config[:max_change] > changes
|
147
|
+
|
148
|
+
ui.fatal("Data bag item #{@data_bag_item_name} has more changes than --max-change allows (#{config[:max_change]}).")
|
149
|
+
exit(1)
|
150
|
+
end
|
151
|
+
|
152
|
+
def values_for_key(key)
|
153
|
+
values = []
|
154
|
+
|
155
|
+
@okta_groups.each do |okta_group|
|
156
|
+
group_members = active_group_members(group_id(okta_group))
|
157
|
+
group_members.each do |group_member|
|
158
|
+
values << group_member[:profile][key.to_sym]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
values.compact.sort
|
163
|
+
end
|
164
|
+
|
165
|
+
def same_as_existing_data_bag_item?
|
166
|
+
return false if data_bag_item_data.nil?
|
167
|
+
data_bag_item_data[config[:okta_attribute]] == attribute_key_values
|
168
|
+
end
|
169
|
+
|
170
|
+
def data_bag_item_data
|
171
|
+
rest.get("data/#{@data_bag_name}/#{@data_bag_item_name}")
|
172
|
+
rescue Net::HTTPServerException
|
173
|
+
nil
|
174
|
+
end
|
175
|
+
|
176
|
+
def data_bag_item_exist?
|
177
|
+
@data_bag_item_exists ||= data_bag_item_data
|
178
|
+
@data_bag_item_exists.nil? ? false : true
|
179
|
+
rescue Net::HTTPServerException
|
180
|
+
false
|
181
|
+
end
|
182
|
+
|
183
|
+
def data_bag_item_file
|
184
|
+
@data_bag_item_file ||= "#{tmpdir}/#{@data_bag_item_name}.json"
|
185
|
+
end
|
186
|
+
|
187
|
+
def create_data_bag_if_missing
|
188
|
+
# Verify if the data bag exists
|
189
|
+
rest.get("data/#{@data_bag_name}")
|
190
|
+
ui.info("Data bag #{@data_bag_name} already exists")
|
191
|
+
rescue Net::HTTPServerException => e
|
192
|
+
raise unless e.to_s =~ /^404/
|
193
|
+
# if it doesn't exists, try to create it
|
194
|
+
rest.post("data", { "name" => @data_bag_name })
|
195
|
+
ui.info("Created data_bag[#{@data_bag_name}]")
|
196
|
+
end
|
197
|
+
|
198
|
+
def create_data_bag_item_file
|
199
|
+
hash = { "id" => @data_bag_item_name, config[:okta_attribute] => attribute_key_values }
|
200
|
+
File.open(data_bag_item_file, "w") { |f| f.write(JSON.pretty_generate(hash)) }
|
201
|
+
end
|
202
|
+
|
203
|
+
def data_bag_item_additions
|
204
|
+
return attribute_key_values if data_bag_item_data.nil?
|
205
|
+
attribute_key_values - data_bag_item_data[config[:okta_attribute].to_sym]
|
206
|
+
end
|
207
|
+
|
208
|
+
def data_bag_item_removals
|
209
|
+
return [] if data_bag_item_data.nil?
|
210
|
+
data_bag_item_data[config[:okta_attribute].to_sym] - attribute_key_values
|
211
|
+
end
|
212
|
+
|
213
|
+
def display_data_bag_item_additions
|
214
|
+
return if data_bag_item_additions.empty?
|
215
|
+
ui.info("The following will be added to the data bag item #{@data_bag_item_name}:")
|
216
|
+
data_bag_item_additions.each { |v| ui.info(" * #{v}") }
|
217
|
+
end
|
218
|
+
|
219
|
+
def display_data_bag_item_removals
|
220
|
+
return if data_bag_item_removals.empty?
|
221
|
+
ui.info("The following will be removed from the data bag item #{@data_bag_item_name}:")
|
222
|
+
data_bag_item_removals.each { |v| ui.info(" * #{v}") }
|
223
|
+
end
|
224
|
+
|
225
|
+
def display_data_bag_item_changes
|
226
|
+
return unless config[:show_changes]
|
227
|
+
|
228
|
+
if data_bag_item_data.nil?
|
229
|
+
display_data_bag_item_additions
|
230
|
+
elsif data_bag_item_data.keys.reject { |e| e == :id }.shift.to_s == config[:okta_attribute]
|
231
|
+
display_data_bag_item_removals
|
232
|
+
display_data_bag_item_additions
|
233
|
+
else
|
234
|
+
ui.info("A new Okta profile attribute has been specified, replacing existing data bag item with the following:")
|
235
|
+
attribute_key_values.each { |v| ui.info(" * #{v}") }
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def display_data_bag_item_members
|
240
|
+
return unless config[:show_members]
|
241
|
+
|
242
|
+
ui.info("The data bag item will be uploaded with the following contents:")
|
243
|
+
attribute_key_values.each { |v| ui.info(" * #{v}") }
|
244
|
+
end
|
245
|
+
|
246
|
+
def upload_data_bag_item
|
247
|
+
ui.confirm("Data bag item #{@data_bag_item_name} exists, overwrite it") if data_bag_item_exist?
|
248
|
+
|
249
|
+
knife_data_bag_from_file = Chef::Knife::DataBagFromFile.new
|
250
|
+
knife_data_bag_from_file.ui = ui
|
251
|
+
knife_data_bag_from_file.name_args = [@data_bag_name, data_bag_item_file]
|
252
|
+
knife_data_bag_from_file.run
|
253
|
+
end
|
254
|
+
|
255
|
+
# Okta
|
256
|
+
|
257
|
+
def okta_client
|
258
|
+
@okta_client ||= Oktakit.new(token: config[:okta_token], api_endpoint: config[:okta_endpoint])
|
259
|
+
end
|
260
|
+
|
261
|
+
def groups
|
262
|
+
@groups ||= okta_client.list_groups.shift
|
263
|
+
end
|
264
|
+
|
265
|
+
def group_hash(group_name)
|
266
|
+
group_hash = groups.select { |group| group[:profile][:name] =~ /^#{group_name}$/i }.shift
|
267
|
+
if group_hash.nil?
|
268
|
+
ui.fatal("Cannot find a group with the name \"#{group_name}\" in the specified Okta tenant")
|
269
|
+
exit(1)
|
270
|
+
end
|
271
|
+
group_hash
|
272
|
+
end
|
273
|
+
|
274
|
+
def group_id(group_name)
|
275
|
+
group_hash(group_name)[:id]
|
276
|
+
end
|
277
|
+
|
278
|
+
def active_group_members(group_id)
|
279
|
+
okta_client.list_group_members(group_id).shift.select { |user| user[:status] == "ACTIVE" }
|
280
|
+
end
|
281
|
+
|
282
|
+
def users
|
283
|
+
@users ||= okta_client.list_users.shift
|
284
|
+
end
|
285
|
+
|
286
|
+
def user_hash(user_name)
|
287
|
+
user_hash = users.select { |user| user.profile.displayName =~ /^#{user_name}$/i }.shift
|
288
|
+
if user_hash.nil?
|
289
|
+
ui.info("Cannot find a user with the name \"#{user_name}\" in the specified Okta tenant")
|
290
|
+
end
|
291
|
+
user_hash
|
292
|
+
end
|
293
|
+
|
294
|
+
def okta_user_active?(user_name)
|
295
|
+
user_hash(user_name).status == "ACTIVE"
|
296
|
+
rescue NoMethodError
|
297
|
+
false
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
data/lib/knife-okta.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2018 Stephen Hoekstra <shoekstra@schubergphilis.com>
|
3
|
+
# Copyright 2018 Schuberg Philis
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module KnifeOkta
|
19
|
+
VERSION = "0.1.0"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-okta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Hoekstra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chef
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oktakit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
description: A knife plugin to interact with the Okta API.
|
42
|
+
email:
|
43
|
+
- shoekstra@schubergphilis.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- CODE_OF_CONDUCT.md
|
53
|
+
- Gemfile
|
54
|
+
- Guardfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- knife-okta.gemspec
|
59
|
+
- lib/chef/knife/data_bag_from_okta_group.rb
|
60
|
+
- lib/knife-okta.rb
|
61
|
+
homepage: https://github.com/shoekstra/knife-okta
|
62
|
+
licenses:
|
63
|
+
- Apache-2.0
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.6.11
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: A knife plugin to interact with the Okta API.
|
85
|
+
test_files: []
|