Read-Only and Read-Write SVN Repositories

Just got a comment on one of my posts from a while back about public SVN access wondering how to get it configured.  The basic idea is to have a single repository with anonymous read-only access, and have the same repository allow read-write access to authenticated users.  Further, you want to configure that on a per-directory basis (with inheritance, of course), so you can have different areas require different principals, and allow some sections to require authentication even for read access.

So without further ado, here's the magic configuration bits.

<Location /svn/barneyb>
    DAV             svn
    SVNPath         /path/to/svnroot/barneyb

    AuthType        Basic
    AuthName        "Subversion/Trac"
    AuthUserFile    /path/to/apache/conf/htpasswd

    AuthzSVNAccessFile  /path/to/apache/conf/authz.conf

    Satisfy     any
    Require     valid-user
</Location>

In this case I'm just using Basic auth with an htpasswd file for authentication.  The magic line is the "AuthzSVNAccessFile" line, which defines the file to use for authorization.  Here's a snippet:

[/]
barneyb = rw

[/bicycle_dashboard]
* = r
barneyb = rw

The first section says that for the root of the repository (/), only barneyb (me) is allowed access, and I'm allowed to read and write.  The second section says that for the /bicycle_dashboard path, I'm still allowed to read and write, but anyone is allowed to read.

The gotcha is that explicitly specified directories do not inherit from their parents.  At each specified level, you must define the full auth spec.  Full details on the authorization file can be found in the Subversion Book.  That link is for the nightly, so if you've got an old version of Subversion, you might want to go grab and older version of the book as well.  The general Apache docs can be found here.

18 responses to “Read-Only and Read-Write SVN Repositories”

  1. Nic Cottrell

    Would it be possible to have anonymous read-only access somehow? Or would I have to create an account in the passwords file called "anonymous" with a blank password or something to make this happen?

  2. Nic Cottrell

    Ok, so there's no need to have a username "*" in the specified AuthUserFile? I assumed that apache would authenticate against that file first before passing the request onto modsvn to check the per-directory authentication.

  3. TheElitist

    Hey Barney,

    Thanks a lot for this short guide, I was looking for this.
    If you don't mind I'll write a blog post on my own blog about this, But I'll note your url as the source.

    Regards, TheElitist

  4. Santhosh Kumar

    My subversion.conf file

    DAV svn
    SVNPath /var/www/svn/repos
    AuthType Basic
    AuthName "Authorization Realm"
    AuthUserFile /etc/svn-auth-conf
    # AuthUserFile /path/to/passwdfile
    # SVNParentPath /var/www/svn
    #
    AuthzSVNAccessFile /etc/svn-authz
    Satisfy any
    Require valid-user
    # # Limit write permission to list of valid users.
    #
    # # Require SSL connection for password protection.
    # # SSLRequireSSL
    #

    #

    My /etc/svn-authz File
    ———————————–

    [/]
    * = r
    [/]
    san = rw
    santhosh = rw
    ——————————-

    Only the santhosh and san are able to do commit. But if am trying from a differnt machine to my SVN server it's not asking for password or username. Please assit me

  5. Santhosh

    Yes , I agree with your words, The problem is only from one linux system it's not asking for password. I do not know why it is. Except this machine I tried from all other, it is working fine . While configuring for test purpose I used this particular machine as client, I had set ssl that time. I am not sure of the route cause of this.

    Now I want to configure SVN as follows..

    I have two svn server, if I am commiting from !st server it should reflect in the second server also. Is there any chance to execute this. If Yes, please assist me by telling how?

    Thanks for the reply… Waiting for your answer.

    Thanks a lot Barneyb……………..

    Santhosh Kumar K V

  6. Xeross

    @Santhosh

    Hmm for the syncing what you could do is this, you create a post-commit hook, in this post-commit hook script you execute a command on the remote server that pulls in all new changes, (svn export or something).

    Or you do something similar but with 10 minute (or more) intervals through a cron-job on the second server.

  7. Santhosh Kumar

    Hi barneyb and Xeross ..
    Thanks for your support. I have done it using rsync. But I have the problem existing still. Only from one client machine it's not asking for password. What could be the reason?

    I have used this particular machine while setting up the SVN Server.

  8. Santhosh Kumar

    Yes, It helped me!!!!!! Thanks a lot!!!!!!!!!!!

  9. Santhosh Kumar

    Hi barneyb

    Now I have another requirement… Please help me to solve this.
    The SVN User Should be able to change his own password.
    How to get this solved
    Thanks in advance!!!!

  10. Xeross

    @Santhosh: As you are using a passwd file to store users in you'd have to make that editable, but that would present a security risk, an alternative would be to use the MySQL auth module with Apache but I don't know how well that would work.

  11. Santhosh Kumar

    Yes! I am facing the same . Is there any alternative for it than MySQL

  12. Venugopal Prabhoo

    We have built a product (web application) , which helps you to manage a lot more in addition to user/user group authentication/authorization (htpasswd/path based authorization) , automatic backup scheduling etc for multiple project repositories. If anyone is interested, I can post the screencasts

Leave a Reply