adap 0.1.4 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +51 -0
- data/.github/workflows/ruby.yml +69 -0
- data/Gemfile +10 -5
- data/Gemfile.lock +15 -15
- data/README.md +0 -4
- data/lib/adap/adap.rb +37 -29
- data/lib/adap/version.rb +1 -1
- metadata +8 -7
- data/.circleci/config.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15cf0c457f1119adc8d5393c23791bf7033be7bc9c1afd8f1b157989cd1786b7
|
4
|
+
data.tar.gz: e39ccd38e93cb38d63a17368b9e481cb56977996a3cf401d100175b093fa667b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fc03fd6077f6f0b4961c5f5ca6e4b5ce97259463859c8f4d71ee5e087cf403f74c290677f2f5138a47395b533ed3fede89f1976b5010e0149f4ccabe9824174
|
7
|
+
data.tar.gz: 8a9195e6f81ae28dc7aa70b2d8ce51635f36fc89e087fc4cfdbd1e2b37e7f6e823cee40ee5dffd6e9277f4cf2881b38bb687bf88e37a9033c4df287401745a3b
|
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
name: Ruby
|
4
|
+
|
5
|
+
on:
|
6
|
+
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab or GitHub CLI(gh workflow run)
|
7
|
+
inputs:
|
8
|
+
otp:
|
9
|
+
description: "One-time password for RubyGems.org"
|
10
|
+
required: true
|
11
|
+
|
12
|
+
permissions:
|
13
|
+
contents: read
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
release:
|
17
|
+
strategy:
|
18
|
+
matrix:
|
19
|
+
os: [ubuntu-24.04]
|
20
|
+
ruby: ['3.3']
|
21
|
+
|
22
|
+
runs-on: ${{ matrix.os }}
|
23
|
+
env:
|
24
|
+
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
25
|
+
GEM_HOST_OTP_CODE: ${{ github.event.inputs.rubygems-otp-code }}
|
26
|
+
steps:
|
27
|
+
- name: Check out ${{ github.event.repository.owner.name }}/${{ github.event.repository.name }}
|
28
|
+
uses: actions/checkout@v4
|
29
|
+
with:
|
30
|
+
path: ${{ github.event.repository.name }}
|
31
|
+
|
32
|
+
- name: Set up Ruby
|
33
|
+
uses: ruby/setup-ruby@v1
|
34
|
+
with:
|
35
|
+
ruby-version: ${{ matrix.ruby }}
|
36
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
+
|
38
|
+
- name: Run tests
|
39
|
+
run: |
|
40
|
+
cd ${GITHUB_WORKSPACE}/${{ github.event.repository.name }}
|
41
|
+
bundle install --retry 3
|
42
|
+
bundle exec rake
|
43
|
+
|
44
|
+
- name: Push to rubygems.org
|
45
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
46
|
+
run: |
|
47
|
+
echo "Pushing to rubygems.org. You need update the version in lib/adap/version.rb before pushing it."
|
48
|
+
echo "Detected version is \"$(grep VERSION lib/adap/version.rb)\""
|
49
|
+
cd ${GITHUB_WORKSPACE}/${{ github.event.repository.name }}
|
50
|
+
bundle exec rake release
|
51
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
tags: ["v*"]
|
13
|
+
branches: [ "master", "develop" ]
|
14
|
+
pull_request:
|
15
|
+
branches: [ "master" ]
|
16
|
+
|
17
|
+
permissions:
|
18
|
+
contents: read
|
19
|
+
|
20
|
+
jobs:
|
21
|
+
test:
|
22
|
+
|
23
|
+
strategy:
|
24
|
+
fail-fast: false
|
25
|
+
matrix:
|
26
|
+
#os: [ubuntu-latest]
|
27
|
+
os: [ubuntu-24.04]
|
28
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
29
|
+
ruby: ['3.3']
|
30
|
+
runs-on: ${{ matrix.os }}
|
31
|
+
|
32
|
+
steps:
|
33
|
+
- name: Print variables that will be used
|
34
|
+
run: |
|
35
|
+
# You can list GitHub Actionses variables with a command below.
|
36
|
+
# $ grep -oP '\$\{\{.*?\}\}' .github/workflows/docker-image.yml | sort | uniq
|
37
|
+
echo env.dest_repository_name=${{ env.dest_repository_name }}
|
38
|
+
echo env.dest_repository_owner_name=${{ env.dest_repository_owner_name }}
|
39
|
+
echo github.event.repository.name=${{ github.event.repository.name }}
|
40
|
+
echo github.event.repository.owner.name=${{ github.event.repository.owner.name }}
|
41
|
+
|
42
|
+
- name: Check out ${{ github.event.repository.owner.name }}/${{ github.event.repository.name }}
|
43
|
+
uses: actions/checkout@v4
|
44
|
+
with:
|
45
|
+
path: ${{ github.event.repository.name }}
|
46
|
+
|
47
|
+
- name: Set up Ruby
|
48
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
49
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
50
|
+
uses: ruby/setup-ruby@v1
|
51
|
+
#uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
|
52
|
+
with:
|
53
|
+
ruby-version: ${{ matrix.ruby }}
|
54
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
55
|
+
|
56
|
+
- name: Run tests
|
57
|
+
run: |
|
58
|
+
cd ${GITHUB_WORKSPACE}/${{ github.event.repository.name }}
|
59
|
+
bundle install --retry 3
|
60
|
+
bundle exec rake
|
61
|
+
|
62
|
+
- name: Push to rubygems.org
|
63
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
64
|
+
run: |
|
65
|
+
echo "Pushing to rubygems.org. You need update the version in lib/adap/version.rb before pushing it."
|
66
|
+
echo "Detected version is \"$(grep VERSION lib/adap/version.rb)\""
|
67
|
+
cd ${GITHUB_WORKSPACE}/${{ github.event.repository.name }}
|
68
|
+
bundle exec rake release
|
69
|
+
|
data/Gemfile
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
#
|
4
|
-
gemspec
|
5
|
+
# gem "rails"
|
5
6
|
|
6
7
|
gem "unix-crypt", "~> 1.3"
|
7
8
|
|
8
|
-
gem "net-ldap", "~> 0.
|
9
|
+
gem "net-ldap", "~> 0.19.0"
|
10
|
+
|
11
|
+
gem "mocha", "~> 2.7"
|
12
|
+
|
13
|
+
gem "rake", "~> 13.2"
|
9
14
|
|
10
|
-
gem "
|
15
|
+
gem "base64", "~> 0.2.0"
|
11
16
|
|
12
|
-
gem "
|
17
|
+
gem "minitest", "~> 5.25"
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
adap (0.1.3)
|
5
|
-
|
6
1
|
GEM
|
7
2
|
remote: https://rubygems.org/
|
8
3
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
base64 (0.2.0)
|
5
|
+
minitest (5.25.4)
|
6
|
+
mocha (2.7.1)
|
7
|
+
ruby2_keywords (>= 0.0.5)
|
8
|
+
net-ldap (0.19.0)
|
9
|
+
rake (13.2.1)
|
10
|
+
ruby2_keywords (0.0.5)
|
11
|
+
unix-crypt (1.3.1)
|
13
12
|
|
14
13
|
PLATFORMS
|
15
14
|
ruby
|
15
|
+
x86_64-linux
|
16
16
|
|
17
17
|
DEPENDENCIES
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
base64 (~> 0.2.0)
|
19
|
+
minitest (~> 5.25)
|
20
|
+
mocha (~> 2.7)
|
21
|
+
net-ldap (~> 0.19.0)
|
22
|
+
rake (~> 13.2)
|
23
23
|
unix-crypt (~> 1.3)
|
24
24
|
|
25
25
|
BUNDLED WITH
|
26
|
-
2.
|
26
|
+
2.5.22
|
data/README.md
CHANGED
@@ -209,10 +209,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
209
209
|
|
210
210
|
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).
|
211
211
|
|
212
|
-
## Build
|
213
|
-
|
214
|
-
gem build adap.gemspec
|
215
|
-
|
216
212
|
## Contributing
|
217
213
|
|
218
214
|
Bug reports and pull requests are welcome on GitHub at https://github.com/TsutomuNakamura/adap.
|
data/lib/adap/adap.rb
CHANGED
@@ -19,8 +19,8 @@ class Adap
|
|
19
19
|
def initialize(params)
|
20
20
|
raise "Initialize Adap was failed. params must not be nil" if params == nil
|
21
21
|
|
22
|
-
[:ad_host, :ad_binddn, :
|
23
|
-
raise 'Adap requires keys in params ":ad_host", ":ad_binddn", ":
|
22
|
+
[:ad_host, :ad_binddn, :ad_user_basedn, :ad_group_basedn, :ldap_host, :ldap_binddn, :ldap_user_basedn, :ldap_group_basedn].each { |k|
|
23
|
+
raise 'Adap requires keys in params ":ad_host", ":ad_binddn", ":ad_user_basedn", ":ad_group_basedn", ":ldap_host", ":ldap_binddn", ":ldap_user_basedn", ":ldap_group_basedn"' if !params.key?(k)
|
24
24
|
}
|
25
25
|
|
26
26
|
# List of attributes for user in AD
|
@@ -42,14 +42,15 @@ class Adap
|
|
42
42
|
@ad_host = params[:ad_host]
|
43
43
|
@ad_port = (params[:ad_port] ? params[:ad_port] : 389)
|
44
44
|
@ad_binddn = params[:ad_binddn]
|
45
|
-
@
|
45
|
+
@ad_user_basedn = params[:ad_user_basedn]
|
46
|
+
@ad_group_basedn = params[:ad_group_basedn]
|
46
47
|
@ad_auth = (params.has_key?(:ad_password) ? { :method => :simple, :username => @ad_binddn, :password => params[:ad_password] } : nil)
|
47
48
|
@ldap_host = params[:ldap_host]
|
48
49
|
@ldap_port = (params[:ldap_port] ? params[:ldap_port] : 389)
|
49
50
|
@ldap_binddn = params[:ldap_binddn]
|
50
|
-
@ldap_suffix_ou = (params[:ldap_suffix_ou] ? params[:ldap_suffix_ou] : "ou=Users")
|
51
51
|
@ldap_basedn = params[:ldap_basedn]
|
52
52
|
@ldap_user_basedn = params[:ldap_user_basedn]
|
53
|
+
@ldap_group_basedn = params[:ldap_group_basedn]
|
53
54
|
@ldap_auth = (params.has_key?(:ldap_password) ? { :method => :simple, :username => @ldap_binddn, :password => params[:ldap_password] } : nil )
|
54
55
|
|
55
56
|
# A password-hash algorithm to sync to the LDAP.
|
@@ -99,12 +100,12 @@ class Adap
|
|
99
100
|
Net::LDAP.new(:host => ldap_host, :port => ldap_port, :auth => ldap_auth)
|
100
101
|
end
|
101
102
|
|
102
|
-
def
|
103
|
-
"CN=#{username}
|
103
|
+
def get_ad_user_dn(username)
|
104
|
+
"CN=#{username},#{@ad_user_basedn}"
|
104
105
|
end
|
105
106
|
|
106
|
-
def
|
107
|
-
"uid=#{username},#{@
|
107
|
+
def get_ldap_user_dn(username)
|
108
|
+
"uid=#{username},#{@ldap_user_basedn}"
|
108
109
|
end
|
109
110
|
|
110
111
|
def create_ldap_attributes(ad_entry)
|
@@ -159,13 +160,13 @@ class Adap
|
|
159
160
|
end
|
160
161
|
|
161
162
|
def sync_user(uid, password=nil)
|
162
|
-
ad_entry
|
163
|
-
ldap_entry
|
164
|
-
|
165
|
-
|
163
|
+
ad_entry = nil
|
164
|
+
ldap_entry = nil
|
165
|
+
ad_user_dn = get_ad_user_dn(uid)
|
166
|
+
ldap_user_dn = get_ldap_user_dn(uid)
|
166
167
|
|
167
168
|
# dn: CN=user-name,CN=Users,DC=mysite,DC=example,DC=com
|
168
|
-
@ad_client.search(:base =>
|
169
|
+
@ad_client.search(:base => ad_user_dn) do |entry|
|
169
170
|
ad_entry = entry
|
170
171
|
end
|
171
172
|
ret_code = @ad_client.get_operation_result.code
|
@@ -174,10 +175,10 @@ class Adap
|
|
174
175
|
return {
|
175
176
|
:code => ret_code,
|
176
177
|
:operations => nil,
|
177
|
-
:message => "Failed to get a user #{
|
178
|
+
:message => "Failed to get a user #{ad_user_dn} from AD - " + @ad_client.get_operation_result.error_message
|
178
179
|
} if ret_code != 0 && ret_code != 32
|
179
180
|
|
180
|
-
@ldap_client.search(:base =>
|
181
|
+
@ldap_client.search(:base => ldap_user_dn) do |entry|
|
181
182
|
ldap_entry = entry
|
182
183
|
end
|
183
184
|
ret_code = @ldap_client.get_operation_result.code
|
@@ -185,17 +186,17 @@ class Adap
|
|
185
186
|
return {
|
186
187
|
:code => ret_code,
|
187
188
|
:operations => nil,
|
188
|
-
:message => "Failed to get a user #{
|
189
|
+
:message => "Failed to get a user #{ldap_user_dn} from LDAP - " + @ldap_client.get_operation_result.error_message
|
189
190
|
} if ret_code != 0 && ret_code != 32
|
190
191
|
|
191
192
|
ret = nil
|
192
193
|
if !ad_entry.nil? and ldap_entry.nil? then
|
193
|
-
ret = add_user(
|
194
|
+
ret = add_user(ldap_user_dn, ad_entry, get_password_hash(uid, password))
|
194
195
|
elsif ad_entry.nil? and !ldap_entry.nil? then
|
195
|
-
ret = delete_user(
|
196
|
+
ret = delete_user(ldap_user_dn)
|
196
197
|
elsif !ad_entry.nil? and !ldap_entry.nil? then
|
197
198
|
ret = modify_user(
|
198
|
-
|
199
|
+
ldap_user_dn,
|
199
200
|
ad_entry,
|
200
201
|
ldap_entry,
|
201
202
|
( password.nil? and (@unsupported_hash_algorithms_in_ad.include?(@password_hash_algorithm)) ) ? nil : get_password_hash(uid, password)
|
@@ -341,21 +342,28 @@ class Adap
|
|
341
342
|
# Creating AD ldapsearch filter
|
342
343
|
|
343
344
|
ad_filter = if primary_gid_number == nil then
|
345
|
+
# TODO: Searching with filter `objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn}` is more accureate.
|
346
|
+
#Net::LDAP::Filter.construct(
|
347
|
+
# "(&(objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn})(member=CN=#{uid},CN=Users,#{@ad_basedn}))")
|
348
|
+
|
344
349
|
Net::LDAP::Filter.construct(
|
345
|
-
"(&(
|
350
|
+
"(&(objectClass=group)(member=CN=#{uid},#{@ad_user_basedn}))")
|
346
351
|
else
|
352
|
+
# TODO: Searching with filter `objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn}` is more accureate.
|
353
|
+
#Net::LDAP::Filter.construct(
|
354
|
+
# "(&(objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn})(|(member=CN=#{uid},CN=Users,#{@ad_basedn})(gidNumber=#{primary_gid_number})))")
|
355
|
+
|
347
356
|
Net::LDAP::Filter.construct(
|
348
|
-
"(&(
|
357
|
+
"(&(objectClass=group)(|(member=CN=#{uid},#{@ad_user_basedn})(gidNumber=#{primary_gid_number})))")
|
349
358
|
end
|
350
359
|
|
351
360
|
# Get groups from AD
|
352
361
|
# entry = {
|
353
362
|
# :gidnumber => xxx,
|
354
363
|
# }
|
355
|
-
|
356
|
-
|
357
|
-
ad_group_map[entry[:
|
358
|
-
#ad_group_map[entry[:name]] = nil
|
364
|
+
@ad_client.search(:base => @ad_group_basedn, :filter => ad_filter, :attributes => [:cn, :gidnumber]) do |entry|
|
365
|
+
ad_group_map[entry[:cn].first] = {:gidnumber => entry[:gidnumber]}
|
366
|
+
#ad_group_map[entry[:cn]] = nil
|
359
367
|
end
|
360
368
|
ret_code = @ad_client.get_operation_result.code
|
361
369
|
|
@@ -369,8 +377,8 @@ class Adap
|
|
369
377
|
ldap_filter = Net::LDAP::Filter.construct("(memberUid=#{uid})")
|
370
378
|
|
371
379
|
# Get groups from LDAP
|
372
|
-
@ldap_client.search(:base =>
|
373
|
-
# gidnumber is not necessary for LDAP entry
|
380
|
+
@ldap_client.search(:base => @ldap_group_basedn, :filter => ldap_filter, :attributes => [:cn]) do |entry|
|
381
|
+
# Capture common name of groups. gidnumber is not necessary for LDAP entry
|
374
382
|
ldap_group_map[entry[:cn].first] = nil
|
375
383
|
end
|
376
384
|
ret_code = @ldap_client.get_operation_result.code
|
@@ -408,7 +416,7 @@ class Adap
|
|
408
416
|
operation_pool = {}
|
409
417
|
|
410
418
|
ad_group_map.each_key do |key|
|
411
|
-
dn = "cn=#{key}
|
419
|
+
dn = "cn=#{key},#{@ldap_group_basedn}"
|
412
420
|
# Convert AD entries to LDAP entries to create operation to update LDAP data.
|
413
421
|
operation_pool[dn] = {
|
414
422
|
:cn => key,
|
@@ -418,7 +426,7 @@ class Adap
|
|
418
426
|
end
|
419
427
|
|
420
428
|
ldap_group_map.each_key do |key|
|
421
|
-
operation_pool["cn=#{key}
|
429
|
+
operation_pool["cn=#{key},#{@ldap_group_basedn}"] = {
|
422
430
|
# :cn and :gidnumber are not necessary
|
423
431
|
:operations => [[:delete, :memberuid, uid]]
|
424
432
|
} if !ad_group_map.has_key?(key)
|
data/lib/adap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tsutomu Nakamura
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -59,7 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".
|
62
|
+
- ".github/workflows/release.yml"
|
63
|
+
- ".github/workflows/ruby.yml"
|
63
64
|
- ".gitignore"
|
64
65
|
- Gemfile
|
65
66
|
- Gemfile.lock
|
@@ -79,7 +80,7 @@ homepage: https://github.com/TsutomuNakamura/adap
|
|
79
80
|
licenses: []
|
80
81
|
metadata:
|
81
82
|
homepage_uri: https://github.com/TsutomuNakamura/adap
|
82
|
-
post_install_message:
|
83
|
+
post_install_message:
|
83
84
|
rdoc_options: []
|
84
85
|
require_paths:
|
85
86
|
- lib
|
@@ -94,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
- !ruby/object:Gem::Version
|
95
96
|
version: '0'
|
96
97
|
requirements: []
|
97
|
-
rubygems_version: 3.
|
98
|
-
signing_key:
|
98
|
+
rubygems_version: 3.5.22
|
99
|
+
signing_key:
|
99
100
|
specification_version: 4
|
100
101
|
summary: LDAP migration tool from AD to NT schema
|
101
102
|
test_files: []
|
data/.circleci/config.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
version: 2.1
|
2
|
-
orbs:
|
3
|
-
ruby: circleci/ruby@0.1.2
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
docker:
|
8
|
-
- image: ruby:2.7
|
9
|
-
executor: ruby/default
|
10
|
-
steps:
|
11
|
-
- checkout
|
12
|
-
- run: bundle check || bundle install
|
13
|
-
- run:
|
14
|
-
command: bundle exec rake test
|
15
|
-
when: always
|
16
|
-
|