{"id":1596,"date":"2015-07-03T16:01:50","date_gmt":"2015-07-03T14:01:50","guid":{"rendered":"http:\/\/www.moucha.cc\/charon\/?p=1596"},"modified":"2015-07-03T16:01:50","modified_gmt":"2015-07-03T14:01:50","slug":"subversion-repositories-with-apache-and-active-directory-centos7","status":"publish","type":"post","link":"http:\/\/www.moucha.cc\/charon\/subversion-repositories-with-apache-and-active-directory-centos7\/","title":{"rendered":"Subversion repositories with Apache and Active Directory [CentOS7]"},"content":{"rendered":"<p>Install necessary packages first.<\/p>\n<pre>\r\n$ yum install subversion mod_dav_svn mod_ldap python-ldap\r\n<\/pre>\n<p>Prepare configuration for Apache. Create a file <code>\/etc\/httpd\/conf.d\/subversion.conf<\/code> and put the\u00a0content bellow into it. Change location, physical path on disk, Active Directory LDAP server and bind credentials to your particular environment.<\/p>\n<pre>\r\n\r\nRewriteEngine on\r\nRewriteCond %{REQUEST_URI} ^\/$\r\nRewriteCond %{HTTP_USER_AGENT} !^SVN\/\r\nRewriteRule ^(.*\/)$ %0\/ [R=301,L]\r\n\r\n&lt;Location \/svn&gt;\r\n DAV svn\r\n\r\n SVNParentPath \/var\/www\/svn\r\n SVNListParentPath on\r\n SVNCacheTextDeltas off\r\n SVNCacheFullTexts off\r\n SVNAllowBulkUpdates on\r\n SVNIndexXSLT \"\/svnindex.xsl\"\r\n AuthzSVNAccessFile \/etc\/subversion\/access.conf\r\n\r\n Options Indexes\r\n\r\n AuthBasicProvider ldap\r\n AuthName \"Memos Subversion Repositories\"\r\n AuthType Basic\r\n AuthLDAPBindDN \"CN=svn_user,OU=Service Accounts,DC=domain,DC=com\"\r\n AuthLDAPBindPassword svn_user_password\r\n AuthLDAPURL \"ldap:\/\/global_catalog.domain.com:3268\/OU=People,DC=domain,DC=com?sAMAccountName?sub?(objectCategory=person)\"\r\n Require valid-user\r\n\r\n ExpiresActive on\r\n ExpiresDefault access\r\n&lt;\/Location&gt;\r\n<\/pre>\n<p>Create a directory where Subversion data will be stored if it does not already exist:<\/p>\n<pre>\r\n$ mkdir -p \/var\/www\/svn\r\n<\/pre>\n<p>Change the permissions of this directory to be owned (or at least writeable by Apache):<\/p>\n<pre>\r\n$ chown apache:apache \/var\/www\/svn\r\n<\/pre>\n<p>Start Apache<\/p>\n<pre>\r\n$ systemctl start httpd\r\n<\/pre>\n<p>Now you need to setup access permissions. There is a catch. There is no simple way how to use Active Directory groups, so we need to synchronize groups from AD to local authz configuration file which we have already configured in Apache confiuration before. To do it we will use <a href=\"http:\/\/thoughtspark.org\/2009\/01\/20\/using-ldap-groups-with-subversion-s-authz-file\/\">sync_ldap_groups_to_svn_authz<\/a>.<\/p>\n<p>Create authz file and put to the top users which will have access to all repositories (such administrators with read write access or continuos intergration user with read only access). Then put particular repositories permissions. You can already add groups from Active Directory. At the end will be part of the config file dedicated to groups definitions and at the very end the comment we will use to find out where the grous definition start. See:<\/p>\n<pre>\r\n[\/]\r\nadmin = rw\r\nci = r\r\n\r\n[repository1:\/]\r\nuser1 = rw\r\n@SVN_GROUP1 = rw\r\n\r\n[groups]\r\n### Start generated content: LDAP Groups to Subversion Authz Groups Bridge ###\r\n<\/pre>\n<p>Now dowload <a href=\"https:\/\/bitbucket.org\/whitlockjc\/jw-tools\/src\/e3396390e99b\/sync_ldap_groups_to_svn_authz\/?at=default\">sync_ldap_groups_to_svn_authz.py<\/a> and create synchronization script (adjust the details within).<\/p>\n<pre>\r\n#!\/bin\/sh\r\n\r\nSVN_CONF_DIR=\/etc\/subversion\r\nJW_TOOLS_DIR=\/opt\r\n\r\n# truncate the access file after the generated-content tag\r\nperl -0777 -pe 's\/\\n\\n\\n### Start generated content.*\/\/s' \\\r\n    < $SVN_CONF_DIR\/access.conf \\\r\n    > $SVN_CONF_DIR\/access.conf.tmp\r\n\r\necho \"### Start generated content: LDAP Groups to Subversion Authz Groups Bridge ###\" >> $SVN_CONF_DIR\/access.conf.tmp\r\n\r\n# append the latest LDAP group configuration\r\n$JW_TOOLS_DIR\/sync_ldap_groups_to_svn_authz.py \\\r\n    --quiet --url=\"ldap:\/\/dc1.memos.cz:3268\" \\\r\n    --bind-dn=\"CN=SVN,OU=Service Accounts,OU=People,DC=memos,DC=cz\" --bind-password=\"REV-Code-673\" --base-dn=\"OU=SVN Groups,OU=Groups,DC=memos,DC=cz\" \\\r\n    --userid_attribute=\"sAMAccountName\" | grep -v '^\\[groups\\]' | grep -v '^\\#' | grep -v '^$' | sort >> $SVN_CONF_DIR\/access.conf.tmp\r\n\r\nmv -f $SVN_CONF_DIR\/access.conf.tmp $SVN_CONF_DIR\/access.conf\r\n<\/pre>\n<p>Run this script manually or from cron.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install necessary packages first. $ yum install subversion mod_dav_svn mod_ldap python-ldap Prepare configuration for Apache. Create a file \/etc\/httpd\/conf.d\/subversion.conf and put the\u00a0content bellow into it. Change location, physical path on disk, Active Directory LDAP server and bind credentials to your particular environment. RewriteEngine on RewriteCond %{REQUEST_URI} ^\/$ RewriteCond %{HTTP_USER_AGENT} !^SVN\/ RewriteRule ^(.*\/)$ %0\/ [R=301,L] &lt;Location&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[],"class_list":["post-1596","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p20Iro-pK","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/posts\/1596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/comments?post=1596"}],"version-history":[{"count":5,"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/posts\/1596\/revisions"}],"predecessor-version":[{"id":1601,"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/posts\/1596\/revisions\/1601"}],"wp:attachment":[{"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/media?parent=1596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/categories?post=1596"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moucha.cc\/charon\/wp-json\/wp\/v2\/tags?post=1596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}