- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5
Replace haproxy+bind with tcpproxy #4
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
          
     Open
      
      
            quentinmit
  wants to merge
  11
  commits into
  ansible-realserver
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
ansible-proxy
  
      
      
   
  
    
  
  
  
 
  
      
    base: ansible-realserver
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      31002af
              
                Initial proxy that parses SNI and Host headers
              
              
                quentinmit f6cf9b7
              
                Route connections based on LDAP
              
              
                quentinmit 879aa10
              
                Spoof client source IP
              
              
                quentinmit 3bbbd8a
              
                Set IP_TRANSPARENT when binding a non-local address
              
              
                quentinmit 06ff98f
              
                Refactor dnf configuration so it can be used by proxies
              
              
                quentinmit 9b92c07
              
                Install mock build environment on proxy servers
              
              
                quentinmit 5c98021
              
                Package scripts-proxy for Fedora
              
              
                quentinmit 33dc19a
              
                Add dependencies for scripts-proxy
              
              
                quentinmit e0f8cfa
              
                Ansibilize scripts-proxy deployment
              
              
                quentinmit 31d1588
              
                Add a special vhost for health checking that uses /etc/nolvs
              
              
                quentinmit b76722d
              
                Change heartbeat vhost and path.
              
              
                miriam-rittenberg File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| dependencies: | ||
| - rpm-repos | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| - name: restart scripts-proxy | ||
| service: | ||
| name: scripts-proxy | ||
| state: restarted | ||
| enabled: yes | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| - name: Disable haproxy-related services | ||
| service: | ||
| name: "{{ item }}" | ||
| state: stopped | ||
| enabled: no | ||
| failed_when: no | ||
| loop: | ||
| - named-scripts-proxy | ||
| - haproxy | ||
| - name: Remove haproxy-related configuration | ||
| file: | ||
| path: "{{ item }}" | ||
| state: absent | ||
| loop: | ||
| - /etc/named.scripts-proxy.conf | ||
| - /etc/systemd/system/named-scripts-proxy.service | ||
| - /etc/haproxy/haproxy.cfg | ||
| - /etc/rsyslog.d/haproxy.conf | ||
| - /etc/systemd/system/haproxy.service.d/10-scripts.conf | ||
| - /usr/local/bin/hatop | ||
| - name: Remove haproxy-related packages | ||
| dnf: | ||
| name: | ||
| - bind | ||
| - bind-dlz-ldap | ||
| - haproxy | ||
| state: absent | ||
| - name: Install scripts-proxy | ||
| dnf: | ||
| name: | ||
| - scripts-proxy | ||
| state: present | ||
| - name: Configure scripts-proxy | ||
| copy: | ||
| dest: /etc/sysconfig/scripts-proxy | ||
| content: | | ||
| OPTIONS="-ldap_servers={{ groups['scripts-ldap'] | join(':389,') }}:389" | ||
| notify: restart scripts-proxy | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| rpm_repos: | ||
| - key: scripts | ||
| name: Scripts | ||
| baseurl: https://web.mit.edu/scripts/yum-repos/rpm-fc{{ ansible_distribution_major_version }}/ | ||
| enabled: yes | ||
| - key: scripts-testing | ||
| name: Scripts Testing | ||
| baseurl: https://web.mit.edu/scripts/yum-repos/rpm-fc{{ ansible_distribution_major_version }}-testing/ | ||
| enabled: "{{ enable_testing_repo | default(False) }}" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| --- | ||
| - name: Configure scripts RPM repos | ||
| copy: | ||
| dest: /etc/yum.repos.d/scripts.repo | ||
| content: | | ||
| {% for repo in rpm_repos %} | ||
| [{{ repo.key }}] | ||
| name={{ repo.name }} | ||
| baseurl={{ repo.baseurl }} | ||
| enabled={{ 1 if repo.enabled else 0 }} | ||
| gpgcheck=0 | ||
| {% endfor %} | ||
| - name: Configure dnf.conf | ||
| ini_file: | ||
| path: /etc/dnf/dnf.conf | ||
| section: main | ||
| option: "{{ item.option }}" | ||
| value: "{{ item.value }}" | ||
| loop: | ||
| - option: installonly_limit | ||
| value: 0 | ||
| - option: installonlypkgs | ||
| value: kernel kernel-devel kernel-modules kmod-openafs ghc-cgi ghc-cgi-devel | ||
| - option: excludepkgs | ||
| value: fedora-obsolete-packages php-fpm nfs-utils | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package ldap | ||
|  | ||
| import ( | ||
| "fmt" | ||
| "log" | ||
| "sync" | ||
| "time" | ||
|  | ||
| ldap "gopkg.in/ldap.v3" | ||
| ) | ||
|  | ||
| type conn struct { | ||
| server, baseDn string | ||
| // mu protects conn during reconnect cycles | ||
| // TODO: The ldap package supports multiple in-flight queries; | ||
| // by using a Mutex we are only going to issue one at a | ||
| // time. We should figure out how to do retry/reconnect | ||
| // behavior with parallel queries. | ||
| mu sync.Mutex | ||
| conn *ldap.Conn | ||
| } | ||
|  | ||
| func (c *conn) reconnect() { | ||
| c.mu.Lock() | ||
| defer c.mu.Unlock() | ||
| if c.conn != nil { | ||
| c.conn.Close() | ||
| } | ||
| var err error | ||
| for { | ||
| log.Printf("connecting to %s", c.server) | ||
| c.conn, err = ldap.Dial("tcp", c.server) | ||
| if err == nil { | ||
| return | ||
| } | ||
| log.Printf("connecting to %s: %v", c.server, err) | ||
| time.Sleep(100 * time.Millisecond) | ||
| } | ||
| } | ||
|  | ||
| func (c *conn) resolvePool(hostname string) (string, error) { | ||
| c.mu.Lock() | ||
| defer c.mu.Unlock() | ||
|  | ||
| escapedHostname := ldap.EscapeFilter(hostname) | ||
| req := &ldap.SearchRequest{ | ||
| BaseDN: c.baseDn, | ||
| Scope: ldap.ScopeWholeSubtree, | ||
| Filter: fmt.Sprintf("(|(scriptsVhostName=%s)(scriptsVhostAlias=%s))", escapedHostname, escapedHostname), | ||
| Attributes: []string{"scriptsVhostPoolIPv4"}, | ||
| } | ||
| sr, err := c.conn.Search(req) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| for _, entry := range sr.Entries { | ||
| return entry.GetAttributeValue("scriptsVhostPoolIPv4"), nil | ||
| } | ||
| // Not found is not an error | ||
| return "", nil | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package ldap | ||
|  | ||
| import "log" | ||
|  | ||
| // Pool handles a concurrency-safe pool of connections to LDAP servers. | ||
| type Pool struct { | ||
| retries int | ||
| // connCh holds open connections to servers. | ||
| connCh chan *conn | ||
| } | ||
|  | ||
| // NewPool constructs a connection pool that queries for baseDn from servers. | ||
| func NewPool(servers []string, baseDn string, retries int) *Pool { | ||
| p := &Pool{ | ||
| retries: retries, | ||
| connCh: make(chan *conn, len(servers)), | ||
| } | ||
| for _, s := range servers { | ||
| c := &conn{ | ||
| server: s, | ||
| baseDn: baseDn, | ||
| } | ||
| go p.reconnect(c) | ||
| } | ||
| return p | ||
| } | ||
|  | ||
| func (p *Pool) reconnect(c *conn) { | ||
| c.reconnect() | ||
| p.connCh <- c | ||
| } | ||
|  | ||
| // ResolvePool attempts to resolve the pool for hostname to an IP address, returned as a string. | ||
| func (p *Pool) ResolvePool(hostname string) (string, error) { | ||
| var ip string | ||
| var err error | ||
| for i := 0; i < p.retries; i++ { | ||
| c := <-p.connCh | ||
| ip, err = c.resolvePool(hostname) | ||
| if err == nil { | ||
| p.connCh <- c | ||
| return ip, err | ||
| } | ||
| log.Printf("resolving %q on %s: %v", hostname, c.server, err) | ||
| go p.reconnect(c) | ||
|         
                  achernya marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| } | ||
| return ip, err | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.