News for hackers. Stuff that matters.
Re:My Amazon S3 Mistake by cheald on Tuesday December 30, 2014 @06:42PM (#8817419)
There are a few lessons here:

1. Use IAM roles. AWS keys should only have access to the specific functionality they need. Best practice is to never use your root credentials for anything; always use IAM users and use unique keys for each use case, so that you can invalidate and replace them easily. Every time documentation or a tutorial asks you to insert AWS keys, your response should be "let me go create a role for that" rather than "let me go look those up".

2. More importantly, if you ever accidentally publish or leak credentials, don't try to clean it up by deleting those commits. Invalidate the credentials immediately and re-issue them.

3. Always, always `git diff HEAD` before committing. Know what you're about to push up. This isn't just a security concern - the number of small, stupid things you'll catch that you'd otherwise end up fixing 15 seconds later is substantial. As a bonus, this incentivizes you to keep your commits small and atomic.

You might talk to Amazon directly - they've been known to forgive debts like these in these kinds of circumstances.

Re:My Amazon S3 Mistake by pktgen on Tuesday December 30, 2014 @06:43PM (#8817422)
> You might talk to Amazon directly - they've been known to forgive debts like these in these kinds of circumstances.

They did:

> Lucky for me, I explained my situation to Amazon customer support – and they knew I wasn’t bitcoin mining all night. Amazon was kind enough to drop the charges this time…

Re:My Amazon S3 Mistake by cheald on Tuesday December 30, 2014 @06:44PM (#8817427)
Whoops. I missed that. Glad the author was able to dodge that bullet!
Re:My Amazon S3 Mistake by jmiwhite on Tuesday December 30, 2014 @09:42PM (#8818029)
This was my initial reaction too, but I was pleased to find it's just a slightly misleading title :)
Re:My Amazon S3 Mistake by pbreit on Wednesday December 31, 2014 @12:59AM (#8818406)
On HN I recall the title originally including the $2300 (which matched the blog post's title). Now the HN title does not include the $ amount. Did the mods make that change? I would think preserving the source's title would generally take precedence even if a bit misleading.
Re:My Amazon S3 Mistake by jmiwhite on Wednesday December 31, 2014 @02:38AM (#8818543)
I'm nearly certain it did, which is in line with submission guidelines; certainly the title led to our mutual confusion. I do not know how/if titles can be edited.
Re:My Amazon S3 Mistake by JoshTriplett on Tuesday December 30, 2014 @06:55PM (#8817486)
> Always, always `git diff HEAD` before committing.

I prefer to always "git commit -v", which shows me the diff while I edit the commit message.

Re:My Amazon S3 Mistake by dperfect on Tuesday December 30, 2014 @07:04PM (#8817536)
Call me unsophisticated, but I personally find it extremely helpful to use a GUI (currently using SourceTree) to interactively review changes before committing. I use the command line for almost everything else, but this is one of those cases where a nice GUI really seems to shine.
Re:My Amazon S3 Mistake by csixty4 on Tuesday December 30, 2014 @07:12PM (#8817574)
That's how I work these days as well. SourceTree for commits, especially if I just want to stage hunks instead of whole files. Command line for everything else.
Re:My Amazon S3 Mistake by hrayr on Tuesday December 30, 2014 @07:26PM (#8817642)
This is exactly what I do also, all I use SourceTree for is to review my changes. I'll go back to the command line to commit and push.
Re:My Amazon S3 Mistake by balls187 on Tuesday December 30, 2014 @07:49PM (#8817723)
I'm with you on this as well. I attempt to make small localized changes, thus `git diff` usually suffices. However if I forget to commit often, or end up doing a big refactor, I will use SourceTree to aid in inspecting the diff. Additionally, I find staging hunks much more intuitive via a GUI than the command line.
Re:My Amazon S3 Mistake by moron4hire on Tuesday December 30, 2014 @08:46PM (#8817898)
That is literally the only reason I use Github for Windows. I'll have to check out SourceTree.
Re:My Amazon S3 Mistake by Immortalin on Tuesday December 30, 2014 @10:04PM (#8818077)
Tortoise git is also not bad.
Re:My Amazon S3 Mistake by fletchowns on Tuesday December 30, 2014 @07:17PM (#8817603)
SourceTree seems like such a complicated mess. `git gui` and `gitk` are my preference.
Re:My Amazon S3 Mistake by madeofpalk on Tuesday December 30, 2014 @09:42PM (#8818028)
Try the GitHub app (which works with non-github git repos as well). It's feature list is TINY compared to SourceTree, its pretty and has a very easy to use commit interface.

https://mac.github.com or https://windows.github.com

Re:My Amazon S3 Mistake by freehunter on Wednesday December 31, 2014 @01:00PM (#8820303)
I really really really wish that GitHub's application worked on Linux. Linux is seriously missing a lot of nice GUI applications that OSX and Windows get. Actually, Linux is missing a lot of nice convenient things that Windows and OSX have. It's all technically possible on Linux, but it's intentionally left difficult (or "advanced") for no reason that I can tell. Just the other day I was trying to install Lua on a Linux machine for the first time. Lua for Windows comes as a single installer that includes Lua, over a dozen batteries-included libraries, and a text editor. To get that on Linux, you have to yum install lua, install luarocks from source, then luarocks install every library you want to have.

The only reason Linux is nicer for certain kinds of programming is because Bash and the GNU utils are so great. But why bother when there's a world of people making things so easy and smooth for Windows?

Re:My Amazon S3 Mistake by fletchowns on Tuesday December 30, 2014 @09:53PM (#8818048)
I'm on Linux
Re:My Amazon S3 Mistake by Sammi on Wednesday December 31, 2014 @06:59AM (#8819026)
No Sourcetree either on Linux :~(
Re:My Amazon S3 Mistake by dasil003 on Tuesday December 30, 2014 @09:19PM (#8817988)
I use both in moderation.

My workflow is primarily raw CLI (no aliases, no github extensions, etc). I have vim configured as my primary editor and my .vimrc has the vim-git plugin (https://github.com/tpope/vim-git) loaded so I can enforce 50-char summary and 72-char line-wrapping.

I use other clients for special purposes:

Fugitive (https://github.com/tpope/vim-fugitive) primarily for git blame while working.

SourceTree for visualizing branches and for staging individual lines from a hunk in a finer grained fashion than `add -p` allows. Occasionally for branch maintenance when an interactive visual list is useful.

gitk for loading partial histories (eg. --author options, pickaxe option), visualizing complex branch arrangements that make SourceTree choke, anytime I need performance to search back many months.

Re:My Amazon S3 Mistake by tomphoolery on Wednesday December 31, 2014 @12:22AM (#8818346)
I also use Vim and Fugitive, but instead of using a GUI I use `vimdiff` as my Git mergetool and difftool. You can use `git difftool` instead of `git diff` and your diffs will open in `vimdiff`. This also goes for any other diff programs which take command-line arguments, like some GUI programs, FWIW...
Re:My Amazon S3 Mistake by shortstuffsushi on Tuesday December 30, 2014 @08:55PM (#8817916)
Funny, I ended up with SourceTree because it seemed like a clean and simple (well, at least when I started with it), but still having all the tools I needed, alternative. Sure, it has gotten a bit more complex, but the basic functionality (as I see it: diff, stage, commit, push, pull, branch management) feels simple to me.

Could you explain what parts of it you don't like? Also, could you link to git gui? I tried to Google it, but didn't really get good results (shockingly, all the other Git GUI programs came up...).

Re:My Amazon S3 Mistake by fletchowns on Tuesday December 30, 2014 @09:23PM (#8817993)
Here's the tool I was referencing: http://git-scm.com/docs/git-gui

It just seemed so confusing compared to the other tools I mentioned, and it would try to do all this extra stuff for you automatically (i.e. adding weird extra arguments to the git commands and I had no idea what they did)

Re:My Amazon S3 Mistake by shortstuffsushi on Tuesday December 30, 2014 @09:46PM (#8818040)
Ah, the weird extra arguments is something that I had noticed as well. And I have to admit, with some shame, that I have not taken the time to look into why.
Re:My Amazon S3 Mistake by lsaferite on Tuesday December 30, 2014 @10:00PM (#8818064)
As another commenter mentioned, tig is amazing.
Re:My Amazon S3 Mistake by xasos on Tuesday December 30, 2014 @07:49PM (#8817722)
tig[1] is another really nice tool to check the diff while on the working branch. It shows things like what branch different remotes are on and a nice tree of what has happened on the source tree (merges, pull requests, etc.)

[1] https://github.com/jonas/tig

Re:My Amazon S3 Mistake by lsaferite on Tuesday December 30, 2014 @09:58PM (#8818061)
I would also highly suggest people use 'git add -p' so they consciously add hunks to the commit.
Re:My Amazon S3 Mistake by koobz on Tuesday December 30, 2014 @07:36PM (#8817672)
This one right here. It's really useful for creating relevant commit messages, catching spurious whitespace changes, random debug code etc.

I like Sourcetree for history and diffs, but it's CLI all the way for commits.

Re:My Amazon S3 Mistake by rzimmerman on Wednesday December 31, 2014 @04:24AM (#8818705)
I use git commit -p for the same reason.
Re:My Amazon S3 Mistake by brianxq3 on Tuesday December 30, 2014 @06:52PM (#8817468)
Huge +1 for #3. Saves my ass all the time. I usually stage the changes I think I want to commit and use `git diff --staged` to confirm before I commit.
Re:My Amazon S3 Mistake by cheald on Tuesday December 30, 2014 @06:58PM (#8817511)
I like that better - I think I'll start using it. I usually end up staging the stuff I want to commit and reverting the stuff I don't, but that offers better flexibility. Thanks!
Re:My Amazon S3 Mistake by alecco on Tuesday December 30, 2014 @07:27PM (#8817646)
About IAM... I worked with that a LOT a couple of years ago. It's interesting but quite the rabbit hole of configurations and permissions.

I used to be an AWS fanatic and got burned. Unless you need to scale up on the spot (and have the time to code management of that) it's a huge waste of time for no good price. EC2 instances have dismal performance.

Just get decent servers somewhere. For most scenarios it's hard to max out a server nowadays, if you program decently. You have to do that for AWS 10x anyways, IMHE. The cloud is a black hole of developer time and problems.

On top of that it's stupid to put data in US when you are a foreign company, you are open game for 3 letter agencies no questions asked.

Re:My Amazon S3 Mistake by aceperry on Tuesday December 30, 2014 @08:50PM (#8817906)
I really have to wonder about the amount of time to setup your own servers. I like to setup and tweak hardware for fun. But the time and starting costs seems way too much compared to spinning up a few instances to get something going quickly. Looking around here, San Francisco bay area, I can't find any way to host a server as inexpensively and as quickly as I can on the cloud. Plus there are lots of alternatives to AWS which promise better performance.

BTW, tweaking around with servers can also be a major time sink.

Re:My Amazon S3 Mistake by alecco on Tuesday December 30, 2014 @09:15PM (#8817972)
I mean dedicated servers. Usually the provider installs the OS for you and then you take over.
Re:My Amazon S3 Mistake by nitrogen on Wednesday December 31, 2014 @02:16AM (#8818517)
In addition to git diff, I suggest git add -p and git diff --cached to enhance visibility of changes. I alias them to short mnemonics in my bash configs.
Re:My Amazon S3 Mistake by matchagaucho on Tuesday December 30, 2014 @07:08PM (#8817552)
Heroku doesn't require a public GitHub account.

Seems like the best lesson learned is keep personal work personal, use private repos if using GitHub.

Re:My Amazon S3 Mistake by serge2k on Tuesday December 30, 2014 @07:32PM (#8817661)
No, the lesson is don't commit credentials and if they leak then revoke them immediately.

and use least privilege to make sure that if you do screw up it's as minor as possible.

Re:My Amazon S3 Mistake by numbsafari on Tuesday December 30, 2014 @10:15PM (#8818101)
+1 - Even if you are using a private repo within your company, committing credentials is foolishness. It's trivial for someone to intentionally or unintentionally leak them, or abuse them.

And personally, I've found that it's just good practice to exercise those kinds of precautions for "throw-away" projects regardless of their "throw-away" status. It keeps you honest.

Re:My Amazon S3 Mistake by snuxoll on Tuesday December 30, 2014 @07:13PM (#8817582)
Or, if you don't want to pay for the privilege of not having your work public, go use Bitbucket.
Re:My Amazon S3 Mistake by cheald on Tuesday December 30, 2014 @07:15PM (#8817595)
Heroku doesn't require any Github account - that's the beauty of git :)

That said, I'd still argue that you should practice defense-in-depth; plan for "this is how I'll limit damage when someone gets ahold of these credentials" rather than "Nobody will get these, so I can do dangerous things with them".

It's the same argument behind "don't do things as root unless you have no other choice"; trading security for convenience works really nicely right up to the point where you get your teeth kicked in.

Re:My Amazon S3 Mistake by encoderer on Tuesday December 30, 2014 @07:18PM (#8817611)
*use bitbucket
Re:My Amazon S3 Mistake by Kiro on Wednesday December 31, 2014 @04:25AM (#8818706)
Sorry for OT but why do you need to add HEAD? I always just do git diff. I tried to google but didn't find any good answer.
Re:My Amazon S3 Mistake by coldpie on Wednesday December 31, 2014 @09:00AM (#8819348)
If you do just "git diff" it will show you the diff between the index (staging area) and your working tree. If you do "git diff HEAD" it will show you the difference between the latest commit and your working tree, that is, it includes the diff in the staging area.
Re:My Amazon S3 Mistake by inopinatus on Tuesday December 30, 2014 @08:40PM (#8817878)
Variant on #3: git diff master origin/master just before you git push.
Re:My Amazon S3 Mistake by fphilipe on Wednesday December 31, 2014 @05:53AM (#8818895)
Or, if your current branch has an upstream, `git diff @{u}`.