如何使我的 Heroku 应用程序保持私密?

发布于 2024-10-14 11:37:05 字数 103 浏览 3 评论 0原文

有没有一种方法可以使我的应用程序完全保密,并且只允许开发人员访问?

当随机用户输入 URL 时,它应该类似于空白页面,但当开发人员输入 URL 时,他们应该能够访问该应用程序。

Is there a way that I could keep my application completely private, and only let the developers have access?

When a random user enters the URL, it should be something like a blank page, but when the developers enter the URL, they should be able to access the app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

躲猫猫 2024-10-21 11:37:05

我的廉价解决方案是实现 before_filter 来在执行每个操作之前请求 HTTP 身份验证。

该解决方案与其他身份验证层(Devise 或其他层)配合良好。

USERS = { "user" => "secret" }

before_filter :authenticate

def authenticate
  authenticate_or_request_with_http_digest("Application") do |name|
    USERS[name]
  end
end

每当其他对等方登陆 yourdomain.heroku.com 时,都会要求他们进行 HTTP 身份验证,然后再进行其他身份验证(如果有)。

My cheap solution has been implementing a before_filter to request an HTTP authentication before every action is executed.

This solution works well along other authentication layers – Devise or others.

USERS = { "user" => "secret" }

before_filter :authenticate

def authenticate
  authenticate_or_request_with_http_digest("Application") do |name|
    USERS[name]
  end
end

Whenever other peers land at yourdomain.heroku.com, they are asked for HTTP authentication, later for other authentication if in place.

回忆那么伤 2024-10-21 11:37:05

现在,您还可以使用 Heroku 插件,让您指定允许访问的用户的电子邮件应用程序并使用 Persona(又名 BrowserID)来验证用户身份(不需要站点特定密码)。

Now you can also use a Heroku add-on that let's you specify emails of users allowed to access an application and that uses Persona (aka BrowserID) to authenticate users (no site specific password needed).

妞丶爷亲个 2024-10-21 11:37:05

一个非常简单的解决方案是仅添加一个可以存储在用户计算机上的 cookie 中的密钥。这不是一个完美的解决方案,因为有人可以获得密钥,但它为您提供了基本的保护,防止有人无意中访问您的网站。您可以使用类似 http://www.yourdomain.com?access_key=random_string 的网址,然后将以下内容添加到您的应用程序控制器中。

class ApplicationController < ActionController::Base
  before_filter :check_redirect_key

  def check_redirect_key
    if request[:access_key] != 'random_string' && cookies[:access_key] != 'random_string'
      redirect_to "/404.html" 
    elsif request[:access_key] == 'random_string'
      cookies.permanent[:access_key] = 'random_string'
    end
  end

end

此代码将检查用户计算机上的 url 或 cookie 中的访问密钥,如果任一位置存在该访问密钥,则允许他们进入。这样,一旦他们使用密钥访问该网站,他们就可以直接访问该网址。

A really simple solution would be to just add a key that can be stored in a cookie on the users machine. This is not a perfect solution as someone could get the key but it gives you basic protection from someone stumbling across your site. You could use a url like http://www.yourdomain.com?access_key=random_string and then add the following to your application controller.

class ApplicationController < ActionController::Base
  before_filter :check_redirect_key

  def check_redirect_key
    if request[:access_key] != 'random_string' && cookies[:access_key] != 'random_string'
      redirect_to "/404.html" 
    elsif request[:access_key] == 'random_string'
      cookies.permanent[:access_key] = 'random_string'
    end
  end

end

This code will check for the access key in either the url or a cookie on the users machine and let them in if it exists in either place. That way once they've accessed the site with the key they can just access the url directly.

回忆躺在深渊里 2024-10-21 11:37:05

您可以使用 HTTP 基本身份验证作为一种简单的方法:

有没有办法为heroku上的应用程序设置简单的http身份验证?

不完全安全,但也许足够了。

您还可以尝试检查 heroku_user 并拒绝访问(如果未设置):

http://blog.heroku.com/archives/2008/ 1/14/heroku_user/

我找不到太多关于 heroku_user 的文档,所以我不知道它是否仍然受支持。

You could use HTTP basic authentication as an easy way:

Is there a way to set up simple http authentication for an app on heroku?

Not exactly bullet proof but maybe sufficient.

You could also try checking heroku_user and refusing access if it isn't set:

http://blog.heroku.com/archives/2008/1/14/heroku_user/

I can't find much documentation on heroku_user so I don't know if it is still supported.

一城柳絮吹成雪 2024-10-21 11:37:05

查看 authlogic gem,特别是单一访问令牌功能。

您可以向未将适当的单一访问令牌作为参数传递的任何人返回 404。

Check out authlogic gem, particularly the Single Access Token feature.

You can return a 404 to anyone who doesn't pass the appropriate single access token as an argument.

愿得七秒忆 2024-10-21 11:37:05

我构建了 rack_staging gem 来为自己处理这个用例,它可能对你也有用。

I built the rack_staging gem to handle this use case for myself, it might be of use for you too.

泼猴你往哪里跑 2024-10-21 11:37:05

我的(也很便宜)的解决方案(使用基于类的视图的 Django 应用程序)是在我所有基于类的视图中使用 SuperUserRequiredMixin ,如下所示:

class BlogPostDetailView(SuperuserRequiredMixin, DetailView):
    template_name = "blogpost-detail.html"
    model = BlogPost

添加/删除此 mixin 是我解决此问题的方法。

My (also cheap) solution (Django app that uses class based views) is to use SuperUserRequiredMixin in all my class based views like this:

class BlogPostDetailView(SuperuserRequiredMixin, DetailView):
    template_name = "blogpost-detail.html"
    model = BlogPost

Adding / removing this mixin is my way to go about this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文