Skip to content

Detect appropriate membership validator strategy by default #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 4, 2014

Conversation

mtodd
Copy link
Member

@mtodd mtodd commented Oct 24, 2014

This adds a meta strategy to detect the best strategy based on the server capabilities. The only real detection is whether the server is an ActiveDirectory supporting the "in chain" matching rule, otherwise we just default to the new recursive strategy.

Also adds a membership_validator configuration option to force a specific strategy (one of :detect, :classic, :recursive, or :active_directory).

See http://msdn.microsoft.com/en-us/library/cc223359.aspx for details on the ActiveDirectory capability detection. I'm struggling to find the reference now but from what I understand, the "in chain" matching rule is only supported as part of ActiveDirectory 2008 R2.

  • docs
  • tests (via mocks)
  • manual test

cc @jch @github/ldap

# defaults to `:detect`. Otherwise the configured strategy is selected.
#
# Returns the selected membership validator strategy Symbol.
def configure_membership_validation_strategy(strategy = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not default :detect in the method parameter?

def configure_membership_validation_strategy(strategy = :detect)
  @membership_validator ||= strategy.to_sym
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jch the method is always called with an argument, which will be nil or "" if no explicit option has been set, so the default here doesn't really kick in in practice. If anything, the default value could be removed, but here it's used to communicate that nil will be handled appropriately.

@jch
Copy link
Contributor

jch commented Oct 24, 2014

I like how you defined this as another concrete implementation of the strategy base class.

@mtodd
Copy link
Member Author

mtodd commented Oct 24, 2014

@jch added some tests and moved some things around. Thoughts?

@mtodd
Copy link
Member Author

mtodd commented Oct 25, 2014

@jch feel free to take this over while I'm out.

@jch jch self-assigned this Oct 27, 2014
@jch
Copy link
Contributor

jch commented Oct 27, 2014

Doing some manual testing, but noticing that AD is not returning the control string 1.2.840.113556.1.4.2080.

  1) Failure:
DetectActiveDirectoryTest#test_capabilities [test/active_directory_test.rb:19]:
Expected ["1.2.840.113556.1.4.319", "1.2.840.113556.1.4.801", "1.2.840.113556.1.4.473", "1.2.840.113556.1.4.528", "1.2.840.113556.1.4.417", "1.2.840.113556.1.4.619", "1.2.840.113556.1.4.841", "1.2.840.113556.1.4.529", "1.2.840.113556.1.4.805", "1.2.840.113556.1.4.521", "1.2.840.113556.1.4.970", "1.2.840.113556.1.4.1338", "1.2.840.113556.1.4.474", "1.2.840.113556.1.4.1339", "1.2.840.113556.1.4.1340", "1.2.840.113556.1.4.1413", "2.16.840.1.113730.3.4.9", "2.16.840.1.113730.3.4.10", "1.2.840.113556.1.4.1504", "1.2.840.113556.1.4.1852", "1.2.840.113556.1.4.802", "1.2.840.113556.1.4.1907", "1.2.840.113556.1.4.1948", "1.2.840.113556.1.4.1974", "1.2.840.113556.1.4.1341", "1.2.840.113556.1.4.2026", "1.2.840.113556.1.4.2064", "1.2.840.113556.1.4.2065", "1.2.840.113556.1.4.2066"] to include "1.2.840.113556.1.4.2080".

Since there's no AD integration test, I have a local test file with the following:

require_relative "./test_helper"

class DetectActiveDirectoryTest < Minitest::Test
  def setup
    @service = MockInstrumentationService.new
    @ldap = GitHub::Ldap.new(
      host: "172.28.128.3",
      port: "389",
      admin_user: "CN=Administrator,CN=Users,DC=ad,DC=ghe,DC=local",
      admin_password: "superp@ssw0rd",
      search_domains: ["CN=Users,DC=ad,DC=ghe,DC=local"],
      service: @service
    )
  end

  def test_capabilities
    assert_includes @ldap.capabilities["supportedcontrol"], GitHub::Ldap::MembershipValidators::Detect::ACTIVE_DIRECTORY_V61_R2_OID
  end

  def test_active_directory_capability
    validator = GitHub::Ldap::MembershipValidators::Detect.new(@ldap, [])
    assert_predicate validator, :active_directory_capability?
  end

  def test_connection
    result = @ldap.test_connection
    assert_equal 0, result.code
  end

  def test_search
    results = @ldap.search(base: "CN=Users,DC=ad,DC=ghe,DC=local")
    assert_equal 1094, results.size
  end
end

I'll poke further to see if it's the particular version of AD I'm running that's causing this issue.

cc @jameswhite

@jch
Copy link
Contributor

jch commented Oct 27, 2014

I do see that capability when I connect with Apache Directory Studio though:

2014-10-27 at 4 19 pm

@jch
Copy link
Contributor

jch commented Oct 27, 2014

Figured it out. net-ldap wasn't requesting supportedCapabilities when searching the root dse. Fix in ruby-ldap/ruby-net-ldap#150.

@jch
Copy link
Contributor

jch commented Oct 28, 2014

Depends on #59 to pull in latest changes from net-ldap.

@jch
Copy link
Contributor

jch commented Oct 28, 2014

I've started another branch to allow local activedirectory testing #61.

@jch
Copy link
Contributor

jch commented Nov 4, 2014

I've tested this manually, and have tests in #61. Unfortunately #61 isn't quite ready yet, so I'm going to merge this first.

jch added a commit that referenced this pull request Nov 4, 2014
Detect appropriate membership validator strategy by default
@jch jch merged commit 85781c4 into master Nov 4, 2014
@jch jch deleted the default-membership-validator branch November 4, 2014 00:55
@mtodd
Copy link
Member Author

mtodd commented Nov 11, 2014

@jch good catch RE: supportedCapabilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants