Skip to content
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

Allow basic auth to be optional in apache conf #11

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Attributes
* jenkins[:http_proxy][:host_name] - primary vhost name for the HTTP proxy to respond to (`node[:fqdn]` by default)
* jenkins[:http_proxy][:host_aliases] - optional list of other host aliases to respond to (empty by default)
* jenkins[:http_proxy][:client_max_body_size] - max client upload size ("1024m" by default, nginx only)
* jenkins[:http_proxy][:basic_auth_username],
* jenkins[:http_proxy][:basic_auth_password] - HTTP Basic Auth username/password. Defaults to jenkins/jenkins.
Setting either one to an empty string will disable basic auth.

Usage
=====
Expand Down
11 changes: 7 additions & 4 deletions recipes/proxy_apache2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,29 @@

host_name = node[:jenkins][:http_proxy][:host_name] || node[:fqdn]

skip_basic_auth = node['jenkins']['http_proxy']['basic_auth_username'].empty? || node['jenkins']['http_proxy']['basic_auth_password'].empty?

template "#{node.apache.dir}/htpasswd" do
variables( :username => node.jenkins.http_proxy.basic_auth_username,
:password => node.jenkins.http_proxy.basic_auth_password)
owner node.apache.user
group node.apache.user
mode 0600
not_if { skip_basic_auth }
end

template "#{node[:apache][:dir]}/sites-available/jenkins" do
source "apache_jenkins.erb"
owner 'root'
group 'root'
mode '0644'
variables(
variables({
:host_name => host_name,
:host_aliases => node[:jenkins][:http_proxy][:host_aliases],
:listen_ports => node[:jenkins][:http_proxy][:listen_ports],
:www_redirect => www_redirect
)

:www_redirect => www_redirect,
:skip_basic_auth => skip_basic_auth,
})
if File.exists?("#{node[:apache][:dir]}/sites-enabled/jenkins")
notifies :restart, 'service[apache2]'
end
Expand Down
2 changes: 2 additions & 0 deletions templates/default/apache_jenkins.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ProxyPreserveHost on
ProxyPass / http://localhost:<%= node[:jenkins][:server][:port] %>/
ProxyPassReverse / http://localhost:<%= node[:jenkins][:server][:port] %>/
<% unless @skip_basic_auth -%>

<Location />
AuthType basic
Expand All @@ -37,4 +38,5 @@
AuthUserFile <%= File.join(node.apache.dir, "htpasswd") %>
require valid-user
</Location>
<% end -%>
</VirtualHost>