<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Brent Kearney on Medium]]></title>
        <description><![CDATA[Stories by Brent Kearney on Medium]]></description>
        <link>https://medium.com/@brentkearney?source=rss-141f040125e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*eGziR30wChJ6pOMIivalig.png</url>
            <title>Stories by Brent Kearney on Medium</title>
            <link>https://medium.com/@brentkearney?source=rss-141f040125e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 14:59:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@brentkearney/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Changing Screen Resolution on a Raspberry Pi]]></title>
            <link>https://medium.com/@brentkearney/changing-screen-resolution-on-a-raspberry-pi-25eb47ee1402?source=rss-141f040125e------2</link>
            <guid isPermaLink="false">https://medium.com/p/25eb47ee1402</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Brent Kearney]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 00:02:00 GMT</pubDate>
            <atom:updated>2026-03-09T00:31:11.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mIwtNQpWt6BRDsqb51qdrw.jpeg" /><figcaption>Default 4K resolution on small monitor, possibly with on/off flashing</figcaption></figure><p>If you recently installed Raspberry Pi OS, and found yourself with 4K resolution on a small monitor, for which you need a magnifying glass to read text, and maybe in addition it is flashing on and off due to too much power draw, then this is the info you need to fix it. It will help if you have a magnifying glass to read the screen for a few clicks.</p><h4>Graphical Interface Resolution Change</h4><p>In the version of Raspberry Pi OS with Desktop as of the time of this writing, you change the resolution by <strong>right-clicking on the desktop</strong>, and select <strong>Desktop Preferences</strong><em>.</em></p><ul><li>Scroll down to <strong>Screens</strong>, and click it.</li><li>You should see <strong>HDMI-A-1</strong> or <strong>HDMI-A-2</strong>, depending on which HDMI port your monitor is plugged into.</li><li>Click the <strong>Screens</strong> drop-down menu along the bottom of the Screens display area</li><li>Hover over your screen name (i.e. HDMI-A-2), then you should see <strong>Resolution</strong> as an option in the resulting pop-up menu.</li><li>Hover over Resolution, and you get a list of resolutions. For my 4K monitor, <strong>1920x1080</strong> (aka 1080p) was the 4th option down.</li><li>Click the <strong>Apply</strong> button after selecting a resolution.</li><li>Click the <strong>OK</strong> button to confirm the new resolution.</li></ul><h4>Console Interface Resolution Change</h4><p>You can switch from the default UI interface to a console interface by pressing Control-Alt F3 (or F4, etc). To change its resolution from 4K to something readable on a small display, you need to edit the file, /boot/firmware/cmdline.txt to add this to the end (space separated arguments): video=HDMI-A-1:1920X1080M@60 or video=HDMI-A-2:1920X1080M@60 for the second HDMI port. Then reboot (sudo shutdown -r now), and it should come back up with the specified resolution.</p><p>Hopefully this saved you some time. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25eb47ee1402" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSON Web Token (JWT) and HTML logins with Devise and Ruby on Rails 5]]></title>
            <link>https://medium.com/@brentkearney/json-web-token-jwt-and-html-logins-with-devise-and-ruby-on-rails-5-9d5e8195193d?source=rss-141f040125e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d5e8195193d</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[devise]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Brent Kearney]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 19:21:05 GMT</pubDate>
            <atom:updated>2020-01-11T18:24:49.002Z</atom:updated>
            <content:encoded><![CDATA[<h3>JSON Web Token (JWT) and HTML Logins with Devise and Ruby on Rails 5</h3><p><em>July 2019</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Ldy9OI0zsj3lXCcu0fDXw.png" /></figure><p>Implementing <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">JWT logins</a> with Rails 5 in API mode <a href="https://medium.com/@mazik.wyry/rails-5-api-jwt-setup-in-minutes-using-devise-71670fd4ed03">is a breeze</a>, according to many blog posts. However, if you want to add JWT logins to an already functioning Rails 5 + Devise HTML app, that is an entirely different story. Here is one way to accomplish a “dual-login” setup. I hope it saves you some time.</p><h3>1. Install devise-jwt</h3><p>Add <a href="https://github.com/waiting-for-dev/devise-jwt">devise-jwt</a> to your Gemfile, as per <a href="https://github.com/waiting-for-dev/devise-jwt#installation">instructions</a>.</p><p>Be sure to add a <a href="https://github.com/waiting-for-dev/devise-jwt#secret-key-configuration">DEVISE_JWT_SECRET_KEY</a> variable to your environment, set to at least 128 random characters. This will be the seed for encrypting and decrypting the authentication tokens. There are several ways to add environment variables to Rails.</p><h3>2. Configure Devise &amp; Warden for JWT</h3><p>I’m using different login paths for API logins and HTML logins. This way, devise-jwt issues JWT auth tokens for API users but not for regular web users. Keeping the types of users separate allows me to add special requirements for API users — for example, that they be staff members. See below for some explanations of the configuration variables.</p><pre># config/initializers/devise.rb<br>config.jwt do |jwt|<br>    jwt.secret = ENV[&#39;DEVISE_JWT_SECRET_KEY&#39;]<br>    jwt.dispatch_requests = [ <br>          [&#39;POST&#39;, %r{^/api/login$}],<br>          [&#39;POST&#39;, %r{^/api/login.json$}]<br>    ]<br>    jwt.revocation_requests = [<br>          [&#39;DELETE&#39;, %r{^/api/logout$}],<br>          [&#39;DELETE&#39;, %r{^/api/logout.json$}]<br>    ]<br>    jwt.expiration_time = 1.day.to_i<br>    jwt.request_formats = { api_user: [:json] }<br>end</pre><pre>config.skip_session_storage = [:http_auth] <br>config.navigational_formats = [&#39;*/*&#39;, :html, :json]</pre><ul><li>dispatch_requests: the endpoint (URL/route) for logins, where devise-jwt will issue new authentication tokens. I want JSON users to visit /api/login to authenticate.</li><li>revocation_requests: the endpoint for logouts, where devise-jwt will revoke authentication tokens.</li><li>request_formats: the <em>format</em> of incoming requests that devise-jwt should pay attention to. In my app, I only want JSON web tokens to be issued for JSON requests (you could also add nilto the array, which means unspecified format). For HTML requests, I want users to go to the web interface at a different endpoint, “/signin”, so if someone visits /api/login with an <em>HTML</em> request instead of JSON, I want devise-jwt to ignore it.</li></ul><p>Likewise, configure warden:</p><pre># config/initializers/warden_auth.rb<br>Warden::JWTAuth.configure do |config|<br>  config.secret = ENV[&#39;DEVISE_JWT_SECRET_KEY&#39;]<br>  config.dispatch_requests = [<br>                               [&#39;POST&#39;, %r{^/api/login$}],<br>                               [&#39;POST&#39;, %r{^/api/login.json$}]<br>                             ]<br>  config.revocation_requests = [<br>                                 [&#39;DELETE&#39;, %r{^/api/logout$}],<br>                                 [&#39;DELETE&#39;, %r{^/api/logout.json$}]<br>                               ]<br>end</pre><h3>3. Configure API login/logout routes</h3><pre># config/routes.rb</pre><pre># Devise (login/logout) for HTML requests<br>  devise_for :users, defaults: { format: :html },<br>                         path: &#39;&#39;,<br>                   path_names: { sign_up: &#39;register&#39; },<br>                  controllers: {<br>                    sessions: &#39;sessions&#39;,<br>                    registrations: &#39;registrations&#39;,<br>                    confirmations: &#39;confirmations&#39;<br>                  }<br>  devise_scope :user do<br>    get &#39;sign_in&#39;, to: &#39;devise/sessions#new&#39;<br>    get &#39;register&#39;, to: &#39;devise/registrations#new&#39;<br>    post &#39;register&#39;, to: &#39;devise/registrations#create&#39;<br>    delete &#39;sign_out&#39;, to: &#39;devise/sessions#destroy&#39;<br>    get &#39;confirmation/sent&#39;, to: &#39;confirmations#sent&#39;<br>    get &#39;confirmation/:confirmation_token&#39;, to: &#39;confirmations#show&#39;<br>    patch &#39;confirmation&#39;, to: &#39;confirmations#create&#39;<br>  end</pre><pre># API namespace, for JSON requests at /api/sign_[in|out]<br>  namespace :api do<br>    devise_for :users, defaults: { format: :json },<br>                     class_name: &#39;ApiUser&#39;,<br>                           skip: [:registrations, :invitations,<br>                                  :passwords, :confirmations,<br>                                  :unlocks],<br>                           path: &#39;&#39;,<br>                     path_names: { sign_in: &#39;login&#39;,<br>                                  sign_out: &#39;logout&#39; }</pre><pre>    devise_scope :user do<br>      get &#39;login&#39;, to: &#39;devise/sessions#new&#39;<br>      delete &#39;logout&#39;, to: &#39;devise/sessions#destroy&#39;<br>    end</pre><pre>    ...<br>  end</pre><h3>4. Update the User table and model</h3><p>I choose to use the <a href="https://github.com/waiting-for-dev/devise-jwt#revocation-strategies">JTIMatcher revocation strategy</a>, which stores a string in a column in the User table, that acts as part of the seed for creating the authorization token. Revoking the token is then accomplished by simply updating the User.jtiattribute.</p><p>I followed the given advice, and set a unique index in the jti column, which meant updating all previously existing User records in my database migration:</p><pre># db/migrations/20190626011110_add_jti_to_users<br>class AddJtiToUsers &lt; ActiveRecord::Migration<br>  def change<br>    add_column :users, :jti, :string</pre><pre>    # populate jti so we can make it not nullable<br>    User.all.each do |user|<br>      user.update_column(:jti, SecureRandom.uuid)<br>    end</pre><pre>    change_column_null :users, :jti, false<br>    add_index :users, :jti, unique: true<br>  end<br>end</pre><p>Update the User model to ensure that the jti column is filled out at time of user creation:</p><pre># app/models/user.rb<br>class User &lt; ApplicationRecord<br>  devise :registerable, :database_authenticatable,<br>         :recoverable, :rememberable, :trackable, :validatable,<br>         :lockable, :confirmable, :invitable<br>  ...<br>  <br>  before_create :add_jti</pre><pre>  def add_jti<br>    self.jti ||= SecureRandom.uuid<br>  end</pre><pre>...<br>end</pre><h3>5. Add an ApiUser model, as a sub-class of User</h3><pre># app/models/api_user.rb<br>class ApiUser &lt; User<br>  include Devise::JWT::RevocationStrategies::JTIMatcher<br>  devise :jwt_authenticatable, jwt_revocation_strategy: self</pre><pre>  validates :jti, presence: true</pre><pre>  def generate_jwt<br>    JWT.encode({ id: id,<br>                exp: 5.days.from_now.to_i },<br>               Rails.env.devise.jwt.secret_key)<br>  end<br>end</pre><h3>6. Update ApplicationController</h3><p>You need special treatment for JSON requests, since they don’t have session cookies, and we want to use the api_user scope for authentication.</p><pre># app/controllers/application_controller.rb<br>class ApplicationController &lt; ActionController::Base<br>  protect_from_forgery with: :exception, unless: :json_request?<br>  protect_from_forgery with: :null_session, if: :json_request?<br>  skip_before_action :verify_authenticity_token, if: :json_request?</pre><pre>  rescue_from ActionController::InvalidAuthenticityToken,<br>              with: :invalid_auth_token</pre><pre>  before_action :set_current_user, if: :json_request?</pre><pre><br>  private</pre><pre>  def json_request?<br>    request.format.json?<br>  end</pre><pre>  # Use api_user Devise scope for JSON access<br>  def authenticate_user!(*args)<br>    super and return unless args.blank?<br>    json_request? ? authenticate_api_user! : super<br>  end</pre><pre>  def invalid_auth_token<br>    respond_to do |format|<br>      format.html { redirect_to sign_in_path, <br>                    error: &#39;Login invalid or expired&#39; }<br>      format.json { head 401 }<br>    end<br>  end</pre><pre>  # So we can use Pundit policies for api_users<br>  def set_current_user<br>    <a href="http://twitter.com/current_user">@current_user</a> ||= warden.authenticate(scope: :api_user)<br>  end</pre><p>The set_current_user method ensures that the global @current_user variable is set using the api_user scope, for JSON requests. I use <a href="https://github.com/varvet/pundit">Pundit</a> for access control in my app, which relies on that variable for its policies. This way, I have a single source of authorization policies for both JSON and HTML users.</p><h3>7. Override API SessionsController</h3><p>I override the default create method, because I have other conditions and custom responses.</p><pre># app/controllers/api/sessions_controller.rb<br>class Api::SessionsController &lt; Devise::SessionsController<br>  skip_before_action :verify_signed_out_user<br>  respond_to :json</pre><pre>  # POST /api/login<br>  def create<br>    unless request.format == :json<br>      sign_out<br>      render status: 406, <br>               json: { message: &quot;JSON requests only.&quot; } and return<br>    end</pre><pre>    # auth_options should have `scope: :api_user`<br>    resource = warden.authenticate!(auth_options)</pre><pre>    if resource.blank?<br>      render status: 401, <br>               json: { response: &quot;Access denied.&quot; } and return<br>    end</pre><pre>    sign_in(resource_name, resource)<br>    respond_with resource, location:<br>      after_sign_in_path_for(resource) do |format|<br>        format.json { render json: <br>                        { success: true,<br>                              jwt: current_token,<br>                         response: &quot;Authentication successful&quot;<br>                         }<br>                     }<br>    end<br>  end</pre><pre>private</pre><pre>  def current_token<br>    request.env[&#39;warden-jwt_auth.token&#39;]<br>  end<br>end</pre><p>I also overrideapp/controllers/sessions_controller.rb with customizations for HTML users. I changed it only to add:respond_to :html.</p><h3>8. Add “new” view in json format</h3><p>Create an empty file: app/views/devise/sessions/new.json. Devise blew up on me without it.</p><h3>Testing</h3><p>Use the curl command to test logins with*:</p><pre>curl -i -X POST -H &#39;Accept: application/json&#39; -H &#39;Content-Type: application/json&#39; --data &#39;{&quot;api_user&quot;: {&quot;email&quot;:&quot;user@email.com&quot;,&quot;password&quot;:&quot;the password&quot;}}&#39; http://127.0.0.1/api/login.json</pre><p><em>*See </em><a href="https://medium.com/@ryanwaldorf/great-guide-583a34d2a0bc"><em>this comment</em></a><em> if that doesn’t work for you. Also, if you are using port 3000 in your development environment, append</em> :3000 to these curl commands.</p><p>You should see a response that includes an Authorization header with the JWT “Bearer” token. Add it to a shell variable, then access protected resources like so:</p><pre>TOKEN=eyJhbGcJzdWIiOiIxIiwic2NwIjoiYXBpX3.eyJqdGkiOiI2MWEwMjUwMS03NWNiLTQ4N2EtODU3Zi04YzU0ZmJkOTU2ZWEiLCVzZXIiLCJhdWQiOm51bGwsImlhdCI6MTU2NDY5MjUxMSwiZXhwIjoxNTY0Nzc4OTExfQ.7YflMWzsmrrS7mYqUGeB2a83G3UlpbhHBwA-EmjSfsA</pre><pre>curl -H &#39;Accept: application/json&#39; -H &quot;Authorization: Bearer ${TOKEN}&quot; <a href="http://127.0.0.1/events/19w5179/memberships.json">http://127.0.0.1/events/19wF000/memberships.json</a></pre><h3>Conclusion</h3><p>There is probably room for improvement in my implementation of devise-jwt. If you have suggestions, I would love to hear them.</p><p>This setup came about through too much trial and error, and hunting for bits of documentation around the web for the JWT/Devise combination with HTML logins in the same app. There wasn’t much, which motivated me to write this article. I hope you found it useful.</p><h3>Resources</h3><ul><li><a href="https://github.com/waiting-for-dev/devise-jwt">Devise::JWT gem</a> &amp; the <a href="https://github.com/waiting-for-dev/warden-jwt_auth">Warden::JWTAuth gem</a></li><li><a href="https://github.com/waiting-for-dev/devise-jwt/wiki/Configuring-devise-for-APIs#responding-to-json">Configuring devise for APIs</a></li><li><a href="https://github.com/anusharanganathan/data2paper/wiki/Dual-authentication-using-Devise-and-JWT">Dual authentication using Devise and JWT</a></li><li><a href="https://github.com/talakoski/rails-devise-jwt">Rails 5 app having API authentication using Devise and JWT</a></li><li><a href="https://thinkster.io/tutorials/rails-json-api/setting-up-users-and-authentication-for-our-api">Setting up Users and Authentication for our API</a></li><li><a href="https://www.pluralsight.com/guides/token-based-authentication-with-ruby-on-rails-5-api">Token-based Authentication with Ruby on Rails 5 API</a></li><li>My app, <a href="https://github.com/brentkearney/workshops"><em>Workshops</em></a>, to see a working example of the above implementation</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d5e8195193d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ruby on Rails 4.2 with Docker & Devise: Case of the Disappearing Environment Variables]]></title>
            <link>https://medium.com/@brentkearney/ruby-on-rails-4-2-with-docker-case-of-the-disappearing-environment-variables-780c210190c5?source=rss-141f040125e------2</link>
            <guid isPermaLink="false">https://medium.com/p/780c210190c5</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devise]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Brent Kearney]]></dc:creator>
            <pubDate>Tue, 20 Jun 2017 22:03:54 GMT</pubDate>
            <atom:updated>2017-06-24T19:05:18.715Z</atom:updated>
            <content:encoded><![CDATA[<p>This is probably an extreme edge case that not many people run into. I run my Rails app in a Docker container, and inside the container, it runs with the privileges of a user account, instead of root. As such, in my entrypoint.sh script, I run a rake task via su — user_account rake...</p><p>That was working fine, until one day it wasn’t. Perhaps <a href="https://github.com/plataformatec/devise/commit/d56641f514f54da04f778b2a9b816561df7910c2">this change</a> to Devise is what exposed the problem. The enivronment variables that I use in config/secrets.yml and config/initializers/devise.rb files just seemed to stop being recognized.</p><pre>config/secrets.yml:<br>  production<br>    secret_key_base: &lt;%= ENV[&quot;SECRET_KEY_BASE&quot;] %&gt;<br>    secret_token: &lt;%= ENV[&quot;SECRET_TOKEN&quot;] %&gt;</pre><pre>config/initializers/devise.rb:<br>  config.secret_key = ENV[&#39;DEVISE_SECRET_KEY&#39;]</pre><p>After upgrading Devise, the error occurred when my app was starting up, when it got to this <strong>rake</strong> command in my entrypoint script:</p><pre>su - app -c &quot;cd /home/app/myapp; RAILS_ENV=production bundle exec <strong>rake</strong> assets:precompile --trace&quot;</pre><p>… it would crash with this message:</p><pre>** Execute environment</pre><pre>myapp | rake aborted!</pre><pre>myapp | Devise.secret_key was not set. Please add the following to your Devise initializer:</pre><pre>myapp |</pre><pre>myapp |   config.secret_key = &#39;95427860950704c84161efa35867cb00f5a113d30f44926db12b514ffb53fa19947f62893f72326336864bb12539728304bb0a0f716c2a4a9c6896cd9f45a389&#39;</pre><pre>myapp |</pre><pre>myapp | Please ensure you restarted your application after installing Devise or setting the key.</pre><p>As shown above, the Devise.secret_key <strong>was</strong> set, to ENV[&#39;DEVISE_SECRET_KEY&#39;] , which previously worked fine and now suddenly it doesn’t exist.</p><p>The problem is that by using su, I’m effectively opening a new shell, with a new environment, that doesn’t include the environment variables available to the root user inside the Docker container. Running rake initializes the config/initializers scripts, including the one for Devise. The new version of Devise checks for the existence of the Devise.secret_key , and failing to find it, throws an error. An easy solution is to insert a SECRET_KEY_BASE token into the shell environment in which rake runs. It doesn’t need to be the real devise secret key, since the rake task (compiling assets) doesn’t need to decrypt passwords.</p><pre>su - app -c &quot;cd /home/app/workshops; RAILS_ENV=production <strong>SECRET_KEY_BASE=token</strong> bundle exec rake assets:precompile --trace&quot;</pre><p>Hopefully this post helps someone else who has become lost in the Rails/Docker weeds. 🤔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=780c210190c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upgrade your Rails app, and now Devise passwords don’t work?]]></title>
            <link>https://medium.com/@brentkearney/upgrade-your-rails-app-and-now-devise-passwords-dont-work-6ca779b34237?source=rss-141f040125e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ca779b34237</guid>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[devise]]></category>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Brent Kearney]]></dc:creator>
            <pubDate>Sat, 11 Mar 2017 03:06:12 GMT</pubDate>
            <atom:updated>2017-06-24T18:46:01.353Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently rolled out an upgrade to a <a href="https://rubyonrails.org/">Rails</a> app that changed <a href="https://github.com/plataformatec/devise">Devise</a> from version 3.5 to version 4.2. I was surprised to discover that passwords for user accounts were no longer working. They worked fine after a password reset.</p><p>Naturally, I took to Google in search of an answer. None were to be found, which is why I’m writing this post.</p><p>Luckily the problem was a simple error on my part that was easy to fix. I had inadvertantly changed the config.secret_key setting in config/initializers/devise.rb. With a different crypto seed, Devise cannot decrypt the password hashes stored in the database. So the solution was simply to copy the config.secret_key string over from the old version. I copied the config.pepper string as well, for good measure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ca779b34237" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mac OS X 10.11 (El Capitan) Server: Update LDAP/OpenDirectory SSL Certificate]]></title>
            <link>https://medium.com/@brentkearney/mac-os-x-10-11-el-capitan-server-update-ldap-opendirectory-ssl-certificate-a3490a5a9f93?source=rss-141f040125e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3490a5a9f93</guid>
            <category><![CDATA[mac-os-x-server]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[el-capitan]]></category>
            <category><![CDATA[open-directory]]></category>
            <dc:creator><![CDATA[Brent Kearney]]></dc:creator>
            <pubDate>Fri, 12 Aug 2016 18:07:35 GMT</pubDate>
            <atom:updated>2018-01-19T18:44:10.434Z</atom:updated>
            <content:encoded><![CDATA[<p>I couldn’t find this information anywhere else, so here it is. This is how to add/update/replace an SSL certificate in Mac OS X 10.11 Server, for use with the Open Directory (dirserv) service.</p><h3>First Step: Add your new certificate</h3><p>To add a new SSL certificate to Open Directory, open the Server app (version 5), and go to the Certificates section to add your certificate. Drag &amp; drop your three certificates here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*DMy4F3Ub2at-2GV2mu0u1Q.png" /></figure><p>The three certificates are:</p><ol><li>The private key (i.e. privkey.pem).</li><li>The signed certificate (i.e. cert.pem).</li><li>The extra non-identity certificate is the “chain” (i.e. chain.pem).</li></ol><h3>Second Step: Disable the Open Directory Service</h3><p>Go to the Open Directory section of the Server app, and move the ON switch to the OFF position. Alternatively run “sudo serveradmin stop dirserv” on the command line.</p><h3>Third Step: Remove the Old Certificate (if applicable)</h3><p>If your directory service was previously using a certificate and you are replacing it with a new one that has the same primary CN name, i.e. “ldap.mydomain.com”, then you need to remove the old one in the Certificates section of the Server app. Simply click on it, then click the “-” button to remove it.</p><h3>Fourth Step: Update the System Keychain</h3><p>This is the non-obvious part. Open Directory searches the System Keychain for an “Identity Preference” item named OPENDIRECTORY_SSL_IDENTITY. You need to locate and edit that item to change it to your new certificate.</p><ol><li>Open the Keychain Access app. It’s in /Applications/Utilities.</li><li>Use the Search feature to find the OPENDIRECTORY_SSL_IDENTITY item, or scroll to find it in the System keychain.</li><li>Double-click it to edit, and from the “Preferred certificate” drop-down menu, select the new certificate that you added in the First Step.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*dUj9ngIxtQG7VKkGJwNUQg.png" /></figure><h3>Fifth and Final Step: Restart Open Directory</h3><p>Restart Open Directory by switching it to “ON” in the Server app, or running “sudo serveradmin start dirserv” on the command line, and <a href="https://en.wikipedia.org/wiki/Bob%27s_your_uncle">Bob’s your uncle</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3490a5a9f93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Development with Docker on Mac OS X]]></title>
            <link>https://medium.com/@brentkearney/docker-on-mac-os-x-9793ac024e94?source=rss-141f040125e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9793ac024e94</guid>
            <category><![CDATA[mac-os-x]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Brent Kearney]]></dc:creator>
            <pubDate>Wed, 10 Feb 2016 21:51:41 GMT</pubDate>
            <atom:updated>2017-06-26T23:32:35.423Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>February 10th, 2016</strong></p><p><a href="https://blog.docker.com/2016/02/docker-hub-two-billion-pulls/">Docker is taking off like a rocket-ship</a>, and for good reason. It’s a great way to develop apps with consistency between development and production environments, that can be easily moved between hardware environments. This article will describe, <em>as of February 10, 2016</em>, how to set up a productive development environment with Docker on Mac OS X.</p><blockquote><strong>2017 Update: </strong>you can now install <a href="https://www.docker.com/docker-mac">Docker for Mac</a>, which runs natively without the need for a separate virtual machine, like docker-machine. If you have recent Mac hardware, use Docker for Mac instead. I think the article is still relevant, from the “Volumes” section down.</blockquote><p>If you haven’t already, install <a href="https://www.docker.com/products/docker-toolbox">Docker Toolbox</a>. It has everything you need.</p><p>Much confusion arises with working on Docker on Mac OS X because of the three layers of operating system between you and the app:</p><ol><li>Mac OS X itself.</li><li>A virtual machine (VM) running Linux inside <a href="https://www.virtualbox.org/">VirtualBox</a>, which you will start via <a href="https://docs.docker.com/machine/">docker-machine</a>.</li><li>Another Linux instance inside the Docker container, which is inside the VM.</li></ol><p>Keeping these layers in mind is important because each layer has its own users, groups and file systems, which can result in permissions errors.</p><p>The current version of <a href="https://www.docker.com/products/docker-toolbox">Docker Toolbox</a> (Docker 1.10) will set up a VM named “default” that automatically mounts your Mac OS X “/Users” folder inside the (Linux) VM. If you already have an older installation of Boot2Docker that doesn’t automatically mount your Mac OS X “/Users” folder, make your life easier and <a href="https://docs.docker.com/machine/get-started#create-a-machine">create a new virtual machine</a>.</p><p>The “/Users” folder will be automatically mounted in the VM, and the mount will be owned by a user named “docker” with a uid number of 1000:</p><pre>$ docker-machine start default<br>Starting “default”…<br>(default) Check network to re-create if needed…<br>(default) Waiting for an IP…<br>Machine “default” was started.<br>Waiting for SSH to be available…<br>Detecting the provisioner…<br>Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.</pre><pre>$ eval &quot;$(docker-machine env default)&quot;</pre><pre>$ docker-machine ssh default &#39;df -h&#39;<br>Filesystem Size Used Available Use% Mounted on<br>tmpfs 1.8G 129.4M 1.6G 7% /<br>tmpfs 1001.3M 500.0K 1000.8M 0% /dev/shm<br>/dev/sda1 18.2G 1.9G 15.3G 11% /mnt/sda1<br>cgroup 1001.3M 0 1001.3M 0% /sys/fs/cgroup<br><strong>Users 464.8G 318.8G 146.0G 69% /Users<br></strong>/dev/sda1 18.2G 1.9G 15.3G 11% /mnt/sda1/var/lib/docker/aufs<br><strong># /Users is mounted from OS X, inside the VM</strong></pre><pre><br>$ docker-machine ssh default &#39;ls -l / | grep Users&#39;<br>drwxr-xr-x 1 <strong>docker</strong> staff 340 Oct 25 17:05 Users<br><strong># the /Users mount is owned by &quot;docker&quot;</strong></pre><pre>$ docker-machine ssh default &#39;id docker&#39;<br><strong>uid=1000(docker)</strong> gid=50(staff) groups=50(staff),100(docker)<br><strong># user &quot;docker&quot; has a uid number of 1000</strong></pre><p>If you want to access files within the /Users share from your Docker container, then you should do so <em>as a user with uid 1000</em>, otherwise you will likely have permissions errors.</p><p>Some Docker images c0me with a pre-made user for running the app in the image. That pre-made user may not have a uid of 1000, so it will not have permission to access the files in the /Users share. One way around this is to add an <a href="https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#entrypoint">ENTRYPOINT</a> script that changes the uid after the container starts up, or add a line to your Dockerfile to change the uid when the image is being built.</p><p>For example, I use the <a href="https://github.com/phusion/passenger-docker">Phusion Passenger image</a>, which comes with a user named “app” that has a uid of 9999. So I add this to my Dockerfile:</p><pre># Update app uid to match docker user uid<br>RUN /usr/sbin/usermod -u 1000 app</pre><p>Note that <em>usermod</em> will automatically change the permissions of the files in the given user’s home directory, so that they are owned by the new uid.</p><p>I also specify an entrypoint script, which executes a few commands (more on that below) and then launches my app.</p><pre><strong>ADD </strong>entrypoint.sh <strong>/</strong>sbin<strong>/</strong>entrypoint.sh<br><strong>RUN </strong>chmod 755 <strong>/</strong>sbin<strong>/</strong>entrypoint.sh<br><strong>ENTRYPOINT </strong>[&quot;/sbin/entrypoint.sh&quot;]</pre><p>I’m setting up Docker on OS X so that I can develop a <a href="http://rubyonrails.org/">Rails</a> app that runs in the Linux environment, from the comfort of my Mac OS X desktop environment. As such, I want “live” updates between my OS X filesystem and the one inside the container. That is done using Volumes.</p><h3>Volumes</h3><p>To allow your app to read and/or write files from your Mac OS X filesystem, use what Docker calls, <a href="https://docs.docker.com/engine/userguide/containers/dockervolumes/#mount-a-host-directory-as-a-data-volume"><em>mounting a host directory as a data volume</em></a><em>. </em>In this case, the “host” is the “default” VM. It has the /Users folder from Mac OS X mounted at /Users.</p><p>An easy way to mount a host volume is to make use of the <a href="https://docs.docker.com/compose/">Docker Compose</a> tool that was installed with Docker Toolbox. In the docker-compose.yml file, add a “volumes:” statement, in a like this:</p><pre>web:<br>  build: .<br>  ports:<br>    - &#39;80:3000&#39;<br>    - &#39;80:80&#39;<br>  volumes:<br>    - /Users/brent/source/my_app:/home/app/my_app<br>  links:<br>    - postgres<br>postgres:<br>  image: postgres:latest<br>  ports:<br>    - &#39;5432:5432&#39;</pre><p>This tells Docker to mount the “/Users/brent/source/my_app” directory from the VirtualBox VM at a mount point inside the docker container, at “/home/app/my_app”.</p><p>Since the user “app” now has uid 1000, and the “docker” user in the VM that owns the “/Users” mount also has uid 1000, the app user will have read/write permissions on my source code folder.</p><p>To build your container as specified in the Dockerfile, and then run it with the parameters specified in the docker-compose.yml file, run:</p><pre>$ docker-compose build<br>$ docker-compose up</pre><p>Or just ‘docker-compose up’ to do them both in one step. Add a “-d” switch if you want to run it in the background.</p><h4>Data Containers</h4><p>Mounted host directories fullfill the need of programmers working on Mac OS X, but you can also use <em>data containers</em> to store data that you want to keep and possibly share among different app containers, or move around to different hardware environments. I use data containers to store my database data, and my ruby gems (so I don’t have to rebuild them every time I build a new app container).</p><p>I recommend reading Adrian Mouat’s excellent article, <a href="http://container-solutions.com/understanding-volumes-docker/"><em>Understanding Volumes in Docker</em></a><em>. </em>It really helped me get my head around why they are useful and how they work. He links to <a href="http://container42.com/2014/11/18/data-only-container-madness/">this article</a>, which is also very helpful.</p><p>I use them like this. For my database files, I create a “pgdata-dev” data container, seeded from the “postgres” image, by running:</p><pre>$ docker run -v /var/lib/postgresql --name pgdata-dev postgres \<br>echo &quot;Data-only container for postgres&quot;</pre><p>For my ruby gems, I seed a data container from the image that my ruby app uses (phusion/passenger-ruby), by running:</p><pre>$ docker run -v /var/lib/gems --name rubygems “phusion/passenger-ruby22:0.9.18” echo “Data-only container for ruby gems”</pre><p>Then I attach them to my application containers using docker’s “ — volumes-from” argument, via my docker-compose.yml file:</p><pre><strong>web:<br>  build: </strong>.<br>  <strong>command: </strong>/sbin/entrypoint.sh<br>  <strong>ports:<br>    - </strong>&#39;80:3000&#39;<br>    <strong>- </strong>&#39;3000:3000&#39;<br>  <strong>volumes:<br>    - </strong>/Users/brent/source/my_app:/home/app/my_app<br>  <strong>volumes_from:<br>    - </strong>rubygems<br>  <strong>links:<br>    - </strong>postgres<br>postgres<strong>:<br>  image: </strong>postgres:latest<br>  <strong>volumes_from:<br>    - </strong>pgdata-dev<br>  <strong>ports:<br>    - </strong>&#39;5432:5432&#39;</pre><p>For <a href="http://rubyonrails.org/">Ruby on Rails</a>, I build and persist ruby gems by putting these statements in my “entrypoint.sh” script (described above):</p><pre>echo<br>echo &quot;Installing Bundler...&quot;<br>gem install bundler</pre><pre>echo<br>echo &quot;Changing /var/lib/gems permissions to the app user...&quot;<br>chown -R app:app /var/lib/gems</pre><pre>echo<br>echo &quot;Running bundle install (as app user)...&quot;<br>su - app -c &quot;<em>GEM_HOME=/var/lib/gems </em>/home/app/workshops/bin/bundle install&quot;</pre><p>Now I can attach my “rubygems” data container to any rails app container, and don’t need to wait for the gems to download and/or compile every time.</p><p><em>Update: YMMV with running bundler as the app user to install gems in /var/lib/gems. Running bundler as root seems to work consistently, although I would much prefer running it as a regular user.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9793ac024e94" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>